cec: fixed missing param
[deb_libcec.git] / src / lib / CECClient.cpp
1 /*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
6 *
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
8 *
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 *
23 *
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
26 *
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
31 */
32
33 #include "CECClient.h"
34 #include "CECProcessor.h"
35 #include "LibCEC.h"
36 #include "CECTypeUtils.h"
37 #include "devices/CECPlaybackDevice.h"
38 #include "devices/CECAudioSystem.h"
39 #include "devices/CECTV.h"
40 #include "implementations/CECCommandHandler.h"
41
42 using namespace CEC;
43 using namespace PLATFORM;
44
45 #define LIB_CEC m_processor->GetLib()
46 #define ToString(x) CCECTypeUtils::ToString(x)
47
48 CCECClient::CCECClient(CCECProcessor *processor, const libcec_configuration &configuration) :
49 m_processor(processor),
50 m_bInitialised(false),
51 m_bRegistered(false),
52 m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
53 m_buttontime(0)
54 {
55 // set the initial configuration
56 SetConfiguration(configuration);
57 }
58
59 CCECClient::~CCECClient(void)
60 {
61 // unregister the client
62 if (m_processor && IsRegistered())
63 m_processor->UnregisterClient(this);
64 }
65
66 bool CCECClient::IsInitialised(void)
67 {
68 CLockObject lock(m_mutex);
69 return m_bInitialised && m_processor;
70 }
71
72 void CCECClient::SetInitialised(bool bSetTo)
73 {
74 CLockObject lock(m_mutex);
75 m_bInitialised = bSetTo;
76 }
77
78 bool CCECClient::IsRegistered(void)
79 {
80 CLockObject lock(m_mutex);
81 return m_bRegistered && m_processor;
82 }
83
84 void CCECClient::SetRegistered(bool bSetTo)
85 {
86 CLockObject lock(m_mutex);
87 m_bRegistered = bSetTo;
88 }
89
90 bool CCECClient::OnRegister(void)
91 {
92 // return false if already initialised
93 if (IsInitialised())
94 return true;
95
96 // get all device we control
97 CECDEVICEVEC devices;
98 m_processor->GetDevices()->GetByLogicalAddresses(devices, m_configuration.logicalAddresses);
99
100 // return false when no devices were found
101 if (devices.empty())
102 {
103 LIB_CEC->AddLog(CEC_LOG_WARNING, "cannot find the primary device (logical address %x)", GetPrimaryLogicalAdddress());
104 return false;
105 }
106
107 // mark as initialised
108 SetInitialised(true);
109
110 // configure all devices
111 for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++)
112 {
113 // only set our OSD name for the primary device
114 if ((*it)->GetLogicalAddress() == GetPrimaryLogicalAdddress())
115 (*it)->SetOSDName(m_configuration.strDeviceName);
116
117 // set the default menu language for devices we control
118 (*it)->SetMenuLanguage(m_configuration.strDeviceLanguage);
119 }
120
121 // set the physical address
122 SetPhysicalAddress(m_configuration);
123
124 // make the primary device the active source if the option is set
125 if (m_configuration.bActivateSource == 1)
126 GetPrimaryDevice()->ActivateSource();
127
128 return true;
129 }
130
131 bool CCECClient::SetHDMIPort(const cec_logical_address iBaseDevice, const uint8_t iPort, bool bForce /* = false */)
132 {
133 bool bReturn(false);
134
135 // limit the HDMI port range to 1-15
136 if (iPort < CEC_MIN_HDMI_PORTNUMBER ||
137 iPort > CEC_MAX_HDMI_PORTNUMBER)
138 return bReturn;
139
140 LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice);
141
142 // update the configuration
143 {
144 CLockObject lock(m_mutex);
145 m_configuration.baseDevice = iBaseDevice;
146 m_configuration.iHDMIPort = iPort;
147 }
148
149 // don't continue if the connection isn't opened
150 if (!m_processor->CECInitialised() && !bForce)
151 return true;
152
153 // get the PA of the base device
154 uint16_t iPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS);
155 CCECBusDevice *baseDevice = m_processor->GetDevice(iBaseDevice);
156 if (baseDevice)
157 iPhysicalAddress = baseDevice->GetPhysicalAddress(GetPrimaryLogicalAdddress());
158
159 // add our port number
160 if (iPhysicalAddress <= CEC_MAX_PHYSICAL_ADDRESS)
161 {
162 if (iPhysicalAddress == 0)
163 iPhysicalAddress += 0x1000 * iPort;
164 else if (iPhysicalAddress % 0x1000 == 0)
165 iPhysicalAddress += 0x100 * iPort;
166 else if (iPhysicalAddress % 0x100 == 0)
167 iPhysicalAddress += 0x10 * iPort;
168 else if (iPhysicalAddress % 0x10 == 0)
169 iPhysicalAddress += iPort;
170
171 bReturn = true;
172 }
173
174 // set the default address when something went wrong
175 if (!bReturn)
176 {
177 LIB_CEC->AddLog(CEC_LOG_WARNING, "failed to set the physical address to %04X, setting it to the default value %04X", iPhysicalAddress, CEC_DEFAULT_PHYSICAL_ADDRESS);
178 iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS;
179 }
180
181 // and set the address
182 SetDevicePhysicalAddress(iPhysicalAddress);
183
184 ConfigurationChanged(m_configuration);
185
186 return bReturn;
187 }
188
189 void CCECClient::ResetPhysicalAddress(void)
190 {
191 SetPhysicalAddress(m_configuration);
192 }
193
194 void CCECClient::SetPhysicalAddress(const libcec_configuration &configuration)
195 {
196 bool bPASet(false);
197
198 // override the physical address from configuration.iPhysicalAddress if it's set
199 if (!bPASet && CLibCEC::IsValidPhysicalAddress(configuration.iPhysicalAddress))
200 bPASet = SetPhysicalAddress(configuration.iPhysicalAddress);
201
202 // try to autodetect the address
203 if (!bPASet && m_processor->CECInitialised())
204 {
205 bPASet = AutodetectPhysicalAddress();
206 m_configuration.bAutodetectAddress = bPASet ? 1 : 0;
207 }
208
209 // use the base device + hdmi port settings
210 if (!bPASet)
211 bPASet = SetHDMIPort(configuration.baseDevice, configuration.iHDMIPort);
212
213 // reset to defaults if something went wrong
214 if (!bPASet)
215 {
216 LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - resetting HDMI port and base device to defaults", __FUNCTION__);
217 m_configuration.baseDevice = CECDEVICE_UNKNOWN;
218 m_configuration.iHDMIPort = CEC_HDMI_PORTNUMBER_NONE;
219 }
220 }
221
222 bool CCECClient::SetPhysicalAddress(const uint16_t iPhysicalAddress)
223 {
224 // update the configuration
225 {
226 CLockObject lock(m_mutex);
227 if (m_configuration.iPhysicalAddress == iPhysicalAddress)
228 {
229 LIB_CEC->AddLog(CEC_LOG_DEBUG, "physical address unchanged (%04X)", iPhysicalAddress);
230 return true;
231 }
232 else
233 {
234 m_configuration.iPhysicalAddress = iPhysicalAddress;
235 LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting physical address to '%04X'", iPhysicalAddress);
236 }
237 }
238
239 // persist the new configuration
240 m_processor->PersistConfiguration(m_configuration);
241
242 // set the physical address for each device
243 SetDevicePhysicalAddress(iPhysicalAddress);
244
245 // and send back the updated configuration
246 ConfigurationChanged(m_configuration);
247
248 return true;
249 }
250
251 void CCECClient::SetSupportedDeviceTypes(void)
252 {
253 cec_device_type_list types;
254 types.Clear();
255
256 // get the command handler for the tv
257 CCECCommandHandler *tvHandler = m_processor->GetTV()->GetHandler();
258 if (!tvHandler)
259 return;
260
261 // check all device types
262 for (uint8_t iPtr = 0; iPtr < 5; iPtr++)
263 {
264 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
265 continue;
266
267 // get the supported device type. the handler will replace types it doesn't support by one it does support
268 cec_device_type type = tvHandler->GetReplacementDeviceType(m_configuration.deviceTypes.types[iPtr]);
269 if (!types.IsSet(type))
270 types.Add(type);
271 }
272 m_processor->GetTV()->MarkHandlerReady();
273
274 // set the new type list
275 m_configuration.deviceTypes = types;
276 }
277
278 bool CCECClient::AllocateLogicalAddresses(void)
279 {
280 // reset all previous LAs that were set
281 m_configuration.logicalAddresses.Clear();
282
283 // get the supported device types from the command handler of the TV
284 SetSupportedDeviceTypes();
285
286 // display an error if no device types are set
287 if (m_configuration.deviceTypes.IsEmpty())
288 {
289 LIB_CEC->AddLog(CEC_LOG_ERROR, "no device types given");
290 return false;
291 }
292
293 // check each entry of the list
294 for (uint8_t iPtr = 0; iPtr < 5; iPtr++)
295 {
296 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
297 continue;
298
299 // find an LA for this type
300 cec_logical_address address(CECDEVICE_UNKNOWN);
301 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE)
302 address = AllocateLogicalAddressRecordingDevice();
303 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_TUNER)
304 address = AllocateLogicalAddressTuner();
305 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
306 address = AllocateLogicalAddressPlaybackDevice();
307 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
308 address = AllocateLogicalAddressAudioSystem();
309
310 // display an error if no LA could be allocated
311 if (address == CECDEVICE_UNKNOWN)
312 {
313 LIB_CEC->AddLog(CEC_LOG_ERROR, "%s - failed to allocate device '%d', type '%s'", __FUNCTION__, iPtr, ToString(m_configuration.deviceTypes.types[iPtr]));
314 return false;
315 }
316
317 // display the registered LA
318 LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - device '%d', type '%s', LA '%X'", __FUNCTION__, iPtr, ToString(m_configuration.deviceTypes.types[iPtr]), address);
319 m_configuration.logicalAddresses.Set(address);
320 }
321
322 return true;
323 }
324
325 cec_logical_address CCECClient::AllocateLogicalAddressRecordingDevice(void)
326 {
327 cec_logical_address retVal(CECDEVICE_UNKNOWN);
328
329 LIB_CEC->AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'");
330 if (m_processor->TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1))
331 retVal = CECDEVICE_RECORDINGDEVICE1;
332 else if (m_processor->TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2))
333 retVal = CECDEVICE_RECORDINGDEVICE2;
334 else if (m_processor->TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3))
335 retVal = CECDEVICE_RECORDINGDEVICE3;
336
337 return retVal;
338 }
339
340 cec_logical_address CCECClient::AllocateLogicalAddressTuner(void)
341 {
342 cec_logical_address retVal(CECDEVICE_UNKNOWN);
343
344 LIB_CEC->AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'");
345 if (m_processor->TryLogicalAddress(CECDEVICE_TUNER1))
346 retVal = CECDEVICE_TUNER1;
347 else if (m_processor->TryLogicalAddress(CECDEVICE_TUNER2))
348 retVal = CECDEVICE_TUNER2;
349 else if (m_processor->TryLogicalAddress(CECDEVICE_TUNER3))
350 retVal = CECDEVICE_TUNER3;
351 else if (m_processor->TryLogicalAddress(CECDEVICE_TUNER4))
352 retVal = CECDEVICE_TUNER4;
353
354 return retVal;
355 }
356
357 cec_logical_address CCECClient::AllocateLogicalAddressPlaybackDevice(void)
358 {
359 cec_logical_address retVal(CECDEVICE_UNKNOWN);
360
361 LIB_CEC->AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'");
362 if (m_processor->TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1))
363 retVal = CECDEVICE_PLAYBACKDEVICE1;
364 else if (m_processor->TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2))
365 retVal = CECDEVICE_PLAYBACKDEVICE2;
366 else if (m_processor->TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3))
367 retVal = CECDEVICE_PLAYBACKDEVICE3;
368
369 return retVal;
370 }
371
372 cec_logical_address CCECClient::AllocateLogicalAddressAudioSystem(void)
373 {
374 cec_logical_address retVal(CECDEVICE_UNKNOWN);
375
376 LIB_CEC->AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audiosystem'");
377 if (m_processor->TryLogicalAddress(CECDEVICE_AUDIOSYSTEM))
378 retVal = CECDEVICE_AUDIOSYSTEM;
379
380 return retVal;
381 }
382
383 CCECBusDevice *CCECClient::GetDeviceByType(const cec_device_type type) const
384 {
385 // get all devices that match our logical addresses
386 CECDEVICEVEC devices;
387 m_processor->GetDevices()->GetByLogicalAddresses(devices, m_configuration.logicalAddresses);
388
389 // filter the type we need
390 CCECDeviceMap::FilterType(type, devices);
391
392 return devices.empty() ?
393 NULL :
394 *devices.begin();
395 }
396
397 bool CCECClient::ChangeDeviceType(const cec_device_type from, const cec_device_type to)
398 {
399 LIB_CEC->AddLog(CEC_LOG_NOTICE, "changing device type '%s' into '%s'", ToString(from), ToString(to));
400
401 CLockObject lock(m_mutex);
402
403 // get the previous device that was allocated
404 CCECBusDevice *previousDevice = GetDeviceByType(from);
405 if (!previousDevice)
406 return false;
407
408 // change the type in the device type list
409 bool bChanged(false);
410 for (uint8_t iPtr = 0; iPtr < 5; iPtr++)
411 {
412 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
413 continue;
414
415 if (m_configuration.deviceTypes.types[iPtr] == from)
416 {
417 bChanged = true;
418 m_configuration.deviceTypes.types[iPtr] = to;
419 }
420 else if (m_configuration.deviceTypes.types[iPtr] == to && bChanged)
421 {
422 // ensure that dupes are removed
423 m_configuration.deviceTypes.types[iPtr] = CEC_DEVICE_TYPE_RESERVED;
424 }
425 }
426
427 // re-register the client to set the new ackmask
428 if (!m_processor->RegisterClient(this))
429 return false;
430
431 return true;
432 }
433
434 bool CCECClient::SetLogicalAddress(const cec_logical_address iLogicalAddress)
435 {
436 CLockObject lock(m_mutex);
437 if (GetPrimaryLogicalAdddress() != iLogicalAddress)
438 {
439 {
440 CLockObject lock(m_mutex);
441 LIB_CEC->AddLog(CEC_LOG_NOTICE, "<< setting primary logical address to %1x", iLogicalAddress);
442 m_configuration.logicalAddresses.primary = iLogicalAddress;
443 m_configuration.logicalAddresses.Set(iLogicalAddress);
444 }
445 return m_processor->RegisterClient(this);
446 }
447
448 return true;
449 }
450
451 bool CCECClient::Transmit(const cec_command &data)
452 {
453 return m_processor ? m_processor->Transmit(data) : false;
454 }
455
456 bool CCECClient::SendPowerOnDevices(const cec_logical_address address /* = CECDEVICE_TV */)
457 {
458 // if the broadcast address if set as destination and the client version >=1.5.0, read the wakeDevices setting
459 if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
460 {
461 CECDEVICEVEC devices;
462 m_processor->GetDevices()->GetWakeDevices(m_configuration, devices);
463 return m_processor->PowerOnDevices(GetPrimaryLogicalAdddress(), devices);
464 }
465
466 return m_processor->PowerOnDevice(GetPrimaryLogicalAdddress(), address);
467 }
468
469 bool CCECClient::SendStandbyDevices(const cec_logical_address address /* = CECDEVICE_BROADCAST */)
470 {
471 // if the broadcast address if set as destination and the client version >=1.5.0, read the standbyDevices setting
472 if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
473 {
474 CECDEVICEVEC devices;
475 m_processor->GetDevices()->GetPowerOffDevices(m_configuration, devices);
476 return m_processor->StandbyDevices(GetPrimaryLogicalAdddress(), devices);
477 }
478
479 return m_processor->StandbyDevice(GetPrimaryLogicalAdddress(), address);
480 }
481
482 bool CCECClient::SendSetActiveSource(const cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
483 {
484 // get the devices that are controlled by us
485 CECDEVICEVEC devices;
486 m_processor->GetDevices()->GetByLogicalAddresses(devices, m_configuration.logicalAddresses);
487
488 // filter out the device that matches the given type
489 if (type != CEC_DEVICE_TYPE_RESERVED)
490 CCECDeviceMap::FilterType(type, devices);
491
492 // no devices left, re-fetch the list of devices that are controlled by us
493 if (devices.empty())
494 m_processor->GetDevices()->GetByLogicalAddresses(devices, m_configuration.logicalAddresses);
495
496 if (!devices.empty())
497 {
498 // get the first device from the list
499 CCECBusDevice *device = *devices.begin();
500
501 // and activate it
502 if (!m_processor->CECInitialised())
503 device->MarkAsActiveSource();
504 else if (device->HasValidPhysicalAddress())
505 return device->ActivateSource();
506 }
507
508 return false;
509 }
510
511 CCECPlaybackDevice *CCECClient::GetPlaybackDevice(void)
512 {
513 CCECPlaybackDevice *device(NULL);
514 CECDEVICEVEC devices;
515
516 // get the playback devices
517 m_processor->GetDevices()->GetByLogicalAddresses(devices, m_configuration.logicalAddresses);
518 CCECDeviceMap::FilterType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE, devices);
519
520 // no matches, get the recording devices
521 if (devices.empty())
522 {
523 m_processor->GetDevices()->GetByLogicalAddresses(devices, m_configuration.logicalAddresses);
524 CCECDeviceMap::FilterType(CEC_DEVICE_TYPE_RECORDING_DEVICE, devices);
525 }
526
527 // get the first device that matches, and cast it to CCECPlaybackDevice
528 if (!devices.empty())
529 device = (*devices.begin())->AsPlaybackDevice();
530
531 return device;
532 }
533
534 cec_logical_address CCECClient::GetPrimaryLogicalAdddress(void)
535 {
536 CLockObject lock(m_mutex);
537 return m_configuration.logicalAddresses.primary;
538 }
539
540 CCECBusDevice *CCECClient::GetPrimaryDevice(void)
541 {
542 return m_processor->GetDevice(GetPrimaryLogicalAdddress());
543 }
544
545 bool CCECClient::SendSetDeckControlMode(const cec_deck_control_mode mode, bool bSendUpdate /* = true */)
546 {
547 // find a playback device that we control
548 CCECPlaybackDevice *device = GetPlaybackDevice();
549 if (device)
550 {
551 // and set the deck control mode if there is a match
552 device->SetDeckControlMode(mode);
553 if (bSendUpdate)
554 return device->TransmitDeckStatus(CECDEVICE_TV);
555 return true;
556 }
557
558 // no match
559 return false;
560 }
561
562 bool CCECClient::SendSetDeckInfo(const cec_deck_info info, bool bSendUpdate /* = true */)
563 {
564 // find a playback device that we control
565 CCECPlaybackDevice *device = GetPlaybackDevice();
566 if (device)
567 {
568 // and set the deck status if there is a match
569 device->SetDeckStatus(info);
570 if (bSendUpdate)
571 return device->AsPlaybackDevice()->TransmitDeckStatus(CECDEVICE_TV);
572 return true;
573 }
574
575 // no match
576 return false;
577 }
578
579 bool CCECClient::SendSetMenuState(const cec_menu_state state, bool bSendUpdate /* = true */)
580 {
581 CECDEVICEVEC devices;
582
583 // set the menu state for all devices that are controlled by us
584 m_processor->GetDevices()->GetByLogicalAddresses(devices, m_configuration.logicalAddresses);
585 for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++)
586 {
587 (*it)->SetMenuState(state);
588 if (bSendUpdate)
589 (*it)->TransmitMenuState(CECDEVICE_TV);
590 }
591
592 return true;
593 }
594
595 bool CCECClient::SendSetInactiveView(void)
596 {
597 CECDEVICEVEC devices;
598
599 // mark all devices that are controlled by us as inactive source
600 m_processor->GetDevices()->GetByLogicalAddresses(devices, m_configuration.logicalAddresses);
601 for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++)
602 {
603 if ((*it)->IsActiveSource())
604 {
605 (*it)->MarkAsInactiveSource();
606 return (*it)->TransmitInactiveSource();
607 }
608 }
609
610 return true;
611 }
612
613 bool CCECClient::SendSetOSDString(const cec_logical_address iLogicalAddress, const cec_display_control duration, const char *strMessage)
614 {
615 CCECBusDevice *primary = GetPrimaryDevice();
616 if (primary)
617 return primary->TransmitOSDString(iLogicalAddress, duration, strMessage);
618
619 return false;
620 }
621
622 cec_version CCECClient::GetDeviceCecVersion(const cec_logical_address iAddress)
623 {
624 CCECBusDevice *device = m_processor->GetDevice(iAddress);
625 if (device)
626 return device->GetCecVersion(GetPrimaryLogicalAdddress());
627 return CEC_VERSION_UNKNOWN;
628 }
629
630 bool CCECClient::GetDeviceMenuLanguage(const cec_logical_address iAddress, cec_menu_language &language)
631 {
632 CCECBusDevice *device = m_processor->GetDevice(iAddress);
633 if (device)
634 {
635 language = device->GetMenuLanguage(GetPrimaryLogicalAdddress());
636 return (strcmp(language.language, "???") != 0);
637 }
638 return false;
639 }
640
641 cec_osd_name CCECClient::GetDeviceOSDName(const cec_logical_address iAddress)
642 {
643 cec_osd_name retVal;
644 retVal.device = iAddress;
645 retVal.name[0] = 0;
646
647 CCECBusDevice *device = m_processor->GetDevice(iAddress);
648 if (device)
649 {
650 CStdString strOSDName = device->GetOSDName(GetPrimaryLogicalAdddress());
651 snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str());
652 retVal.device = iAddress;
653 }
654
655 return retVal;
656 }
657
658 uint16_t CCECClient::GetDevicePhysicalAddress(const cec_logical_address iAddress)
659 {
660 CCECBusDevice *device = m_processor->GetDevice(iAddress);
661 if (device)
662 return device->GetPhysicalAddress(GetPrimaryLogicalAdddress());
663 return CEC_INVALID_PHYSICAL_ADDRESS;
664 }
665
666 cec_power_status CCECClient::GetDevicePowerStatus(const cec_logical_address iAddress)
667 {
668 CCECBusDevice *device = m_processor->GetDevice(iAddress);
669 if (device)
670 return device->GetPowerStatus(GetPrimaryLogicalAdddress());
671 return CEC_POWER_STATUS_UNKNOWN;
672 }
673
674 uint64_t CCECClient::GetDeviceVendorId(const cec_logical_address iAddress)
675 {
676 CCECBusDevice *device = m_processor->GetDevice(iAddress);
677 if (device)
678 return device->GetVendorId(GetPrimaryLogicalAdddress());
679 return CEC_VENDOR_UNKNOWN;
680 }
681
682 uint8_t CCECClient::SendVolumeUp(bool bSendRelease /* = true */)
683 {
684 CCECBusDevice *device = GetPrimaryDevice();
685 CCECAudioSystem *audio = m_processor->GetAudioSystem();
686
687 return device && audio && audio->IsPresent() ?
688 audio->VolumeUp(device->GetLogicalAddress(), bSendRelease) :
689 (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
690 }
691
692 uint8_t CCECClient::SendVolumeDown(bool bSendRelease /* = true */)
693 {
694 CCECBusDevice *device = GetPrimaryDevice();
695 CCECAudioSystem *audio = m_processor->GetAudioSystem();
696
697 return device && audio && audio->IsPresent() ?
698 audio->VolumeDown(device->GetLogicalAddress(), bSendRelease) :
699 (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
700 }
701
702 uint8_t CCECClient::SendMuteAudio(void)
703 {
704 CCECBusDevice *device = GetPrimaryDevice();
705 CCECAudioSystem *audio = m_processor->GetAudioSystem();
706
707 return device && audio && audio->IsPresent() ?
708 audio->MuteAudio(device->GetLogicalAddress()) :
709 (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
710 }
711
712 bool CCECClient::SendKeypress(const cec_logical_address iDestination, const cec_user_control_code key, bool bWait /* = true */)
713 {
714 CCECBusDevice *dest = m_processor->GetDevice(iDestination);
715
716 return dest ?
717 dest->TransmitKeypress(GetPrimaryLogicalAdddress(), key, bWait) :
718 false;
719 }
720
721 bool CCECClient::SendKeyRelease(const cec_logical_address iDestination, bool bWait /* = true */)
722 {
723 CCECBusDevice *dest = m_processor->GetDevice(iDestination);
724
725 return dest ?
726 dest->TransmitKeyRelease(GetPrimaryLogicalAdddress(), bWait) :
727 false;
728 }
729
730 bool CCECClient::GetCurrentConfiguration(libcec_configuration &configuration)
731 {
732 CLockObject lock(m_mutex);
733
734 // client version 1.5.0
735 snprintf(configuration.strDeviceName, 13, "%s", m_configuration.strDeviceName);
736 configuration.deviceTypes = m_configuration.deviceTypes;
737 configuration.bAutodetectAddress = m_configuration.bAutodetectAddress;
738 configuration.iPhysicalAddress = m_configuration.iPhysicalAddress;
739 configuration.baseDevice = m_configuration.baseDevice;
740 configuration.iHDMIPort = m_configuration.iHDMIPort;
741 configuration.clientVersion = m_configuration.clientVersion;
742 configuration.serverVersion = m_configuration.serverVersion;
743 configuration.tvVendor = m_configuration.tvVendor;
744
745 configuration.bGetSettingsFromROM = m_configuration.bGetSettingsFromROM;
746 configuration.bUseTVMenuLanguage = m_configuration.bUseTVMenuLanguage;
747 configuration.bActivateSource = m_configuration.bActivateSource;
748 configuration.wakeDevices = m_configuration.wakeDevices;
749 configuration.powerOffDevices = m_configuration.powerOffDevices;
750 configuration.bPowerOffScreensaver = m_configuration.bPowerOffScreensaver;
751 configuration.bPowerOffOnStandby = m_configuration.bPowerOffOnStandby;
752
753 // client version 1.5.1
754 if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_1)
755 configuration.bSendInactiveSource = m_configuration.bSendInactiveSource;
756
757 // client version 1.5.3
758 if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_3)
759 configuration.logicalAddresses = m_configuration.logicalAddresses;
760
761 // client version 1.6.0
762 if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_6_0)
763 {
764 configuration.iFirmwareVersion = m_configuration.iFirmwareVersion;
765 configuration.bPowerOffDevicesOnStandby = m_configuration.bPowerOffDevicesOnStandby;
766 configuration.bShutdownOnStandby = m_configuration.bShutdownOnStandby;
767 }
768
769 // client version 1.6.2
770 if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_6_2)
771 {
772 memcpy(configuration.strDeviceLanguage, m_configuration.strDeviceLanguage, 3);
773 configuration.iFirmwareBuildDate = m_configuration.iFirmwareBuildDate;
774 }
775
776 // client version 1.6.3
777 if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_6_3)
778 {
779 configuration.bMonitorOnly = m_configuration.bMonitorOnly;
780 }
781
782 return true;
783 }
784
785 bool CCECClient::SetConfiguration(const libcec_configuration &configuration)
786 {
787 bool bIsRunning(m_processor && m_processor->CECInitialised());
788 CCECBusDevice *primary = bIsRunning ? GetPrimaryDevice() : NULL;
789 uint16_t iPA = primary ? primary->GetCurrentPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS;
790
791 // update the callbacks
792 if (configuration.callbacks)
793 EnableCallbacks(configuration.callbackParam, configuration.callbacks);
794
795 // update the client version
796 SetClientVersion((cec_client_version)configuration.clientVersion);
797
798 // update the OSD name
799 CStdString strOSDName(configuration.strDeviceName);
800 SetOSDName(strOSDName);
801
802 // update the TV vendor override
803 SetTVVendorOverride((cec_vendor_id)configuration.tvVendor);
804
805 // just copy these
806 {
807 CLockObject lock(m_mutex);
808 m_configuration.bUseTVMenuLanguage = configuration.bUseTVMenuLanguage;
809 m_configuration.bActivateSource = configuration.bActivateSource;
810 m_configuration.bGetSettingsFromROM = configuration.bGetSettingsFromROM;
811 m_configuration.wakeDevices = configuration.wakeDevices;
812 m_configuration.powerOffDevices = configuration.powerOffDevices;
813 m_configuration.bPowerOffScreensaver = configuration.bPowerOffScreensaver;
814 m_configuration.bPowerOffOnStandby = configuration.bPowerOffOnStandby;
815
816 // client version 1.5.1
817 if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_1)
818 m_configuration.bSendInactiveSource = configuration.bSendInactiveSource;
819
820 // client version 1.6.0
821 if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_6_0)
822 {
823 m_configuration.bPowerOffDevicesOnStandby = configuration.bPowerOffDevicesOnStandby;
824 m_configuration.bShutdownOnStandby = configuration.bShutdownOnStandby;
825 }
826
827 // client version 1.6.2
828 if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_6_2)
829 {
830 memcpy(m_configuration.strDeviceLanguage, configuration.strDeviceLanguage, 3);
831 }
832
833 // client version 1.6.3
834 if (configuration.clientVersion >= CEC_CLIENT_VERSION_1_6_3)
835 {
836 m_configuration.bMonitorOnly = configuration.bMonitorOnly;
837 }
838
839 // ensure that there is at least 1 device type set
840 if (m_configuration.deviceTypes.IsEmpty())
841 m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
842 }
843
844 bool bNeedReinit(false);
845
846 // device types
847 if (SetDeviceTypes(configuration.deviceTypes))
848 {
849 // the device type changed. just copy the rest, and re-register
850 {
851 CLockObject lock(m_mutex);
852 m_configuration.iPhysicalAddress = configuration.iPhysicalAddress;
853 m_configuration.baseDevice = configuration.baseDevice;
854 m_configuration.iHDMIPort = configuration.iHDMIPort;
855 bNeedReinit = true;
856 }
857 }
858 else
859 {
860 // set the physical address
861 SetPhysicalAddress(configuration);
862 }
863
864 m_processor->PersistConfiguration(m_configuration);
865
866 if (!primary)
867 primary = GetPrimaryDevice();
868
869 if (bNeedReinit || !primary || primary->GetCurrentPhysicalAddress() != iPA)
870 {
871 // PA or device type changed
872 m_processor->RegisterClient(this);
873 }
874 else if (primary && configuration.bActivateSource == 1 && bIsRunning && !primary->IsActiveSource())
875 {
876 // activate the source if we're not already the active source
877 primary->ActivateSource();
878 }
879
880 return true;
881 }
882
883 void CCECClient::AddCommand(const cec_command &command)
884 {
885 CLockObject lock(m_mutex);
886
887 LIB_CEC->AddLog(CEC_LOG_NOTICE, ">> %s (%X) -> %s (%X): %s (%2X)", ToString(command.initiator), command.initiator, ToString(command.destination), command.destination, ToString(command.opcode), command.opcode);
888
889 if (m_configuration.callbacks && m_configuration.callbacks->CBCecCommand)
890 m_configuration.callbacks->CBCecCommand(m_configuration.callbackParam, command);
891 else if (!m_commandBuffer.Push(command))
892 LIB_CEC->AddLog(CEC_LOG_WARNING, "command buffer is full");
893 }
894
895 int CCECClient::MenuStateChanged(const cec_menu_state newState)
896 {
897 CLockObject lock(m_mutex);
898
899 LIB_CEC->AddLog(CEC_LOG_NOTICE, ">> %s: %s", ToString(CEC_OPCODE_MENU_REQUEST), ToString(newState));
900
901 if (m_configuration.callbacks &&
902 m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_6_2 &&
903 m_configuration.callbacks->CBCecMenuStateChanged)
904 return m_configuration.callbacks->CBCecMenuStateChanged(m_configuration.callbackParam, newState);
905
906 return 0;
907 }
908
909 void CCECClient::Alert(const libcec_alert type, const libcec_parameter &param)
910 {
911 CLockObject lock(m_mutex);
912
913 if (m_configuration.callbacks &&
914 m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_6_0 &&
915 m_configuration.callbacks->CBCecAlert)
916 m_configuration.callbacks->CBCecAlert(m_configuration.callbackParam, type, param);
917 }
918
919 void CCECClient::AddLog(const cec_log_message &message)
920 {
921 CLockObject lock(m_logMutex);
922 if (m_configuration.callbacks && m_configuration.callbacks->CBCecLogMessage)
923 m_configuration.callbacks->CBCecLogMessage(m_configuration.callbackParam, message);
924 else
925 m_logBuffer.Push(message);
926 }
927
928 void CCECClient::AddKey(void)
929 {
930 CLockObject lock(m_mutex);
931
932 if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN)
933 {
934 cec_keypress key;
935
936 key.duration = (unsigned int) (GetTimeMs() - m_buttontime);
937 key.keycode = m_iCurrentButton;
938 LIB_CEC->AddLog(CEC_LOG_DEBUG, "key released: %1x", key.keycode);
939
940 if (m_configuration.callbacks && m_configuration.callbacks->CBCecKeyPress)
941 m_configuration.callbacks->CBCecKeyPress(m_configuration.callbackParam, key);
942 else
943 m_keyBuffer.Push(key);
944 m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
945 }
946
947 m_buttontime = 0;
948 }
949
950 void CCECClient::AddKey(const cec_keypress &key)
951 {
952 CLockObject lock(m_mutex);
953
954 LIB_CEC->AddLog(CEC_LOG_DEBUG, "key pressed: %1x", key.keycode);
955
956 if (m_configuration.callbacks && m_configuration.callbacks->CBCecKeyPress)
957 m_configuration.callbacks->CBCecKeyPress(m_configuration.callbackParam, key);
958 else
959 m_keyBuffer.Push(key);
960
961 m_iCurrentButton = key.duration > 0 ? CEC_USER_CONTROL_CODE_UNKNOWN : key.keycode;
962 m_buttontime = key.duration > 0 ? 0 : GetTimeMs();
963 }
964
965 void CCECClient::SetCurrentButton(const cec_user_control_code iButtonCode)
966 {
967 // push a keypress to the buffer with 0 duration and another with the duration set when released
968 cec_keypress key;
969 key.duration = 0;
970 key.keycode = iButtonCode;
971
972 AddKey(key);
973 }
974
975 void CCECClient::CheckKeypressTimeout(void)
976 {
977 if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN && GetTimeMs() - m_buttontime > CEC_BUTTON_TIMEOUT)
978 {
979 AddKey();
980 m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
981 }
982 }
983
984 void CCECClient::ConfigurationChanged(const libcec_configuration &config)
985 {
986 CLockObject lock(m_mutex);
987
988 if (m_configuration.callbacks &&
989 m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0 &&
990 m_configuration.callbacks->CBCecConfigurationChanged &&
991 m_processor->CECInitialised())
992 m_configuration.callbacks->CBCecConfigurationChanged(m_configuration.callbackParam, config);
993 }
994
995 bool CCECClient::EnableCallbacks(void *cbParam, ICECCallbacks *callbacks)
996 {
997 CLockObject lock(m_mutex);
998 m_configuration.callbackParam = cbParam;
999 m_configuration.callbacks = callbacks;
1000 return true;
1001 }
1002
1003 bool CCECClient::PingAdapter(void)
1004 {
1005 return m_processor ? m_processor->PingAdapter() : false;
1006 }
1007
1008 bool CCECClient::GetNextLogMessage(cec_log_message *message)
1009 {
1010 return (m_logBuffer.Pop(*message));
1011 }
1012
1013 bool CCECClient::GetNextKeypress(cec_keypress *key)
1014 {
1015 return m_keyBuffer.Pop(*key);
1016 }
1017
1018 bool CCECClient::GetNextCommand(cec_command *command)
1019 {
1020 return m_commandBuffer.Pop(*command);
1021 }
1022
1023 CStdString CCECClient::GetConnectionInfo(void)
1024 {
1025 CStdString strLog;
1026 strLog.Format("libCEC version = %s, client version = %s, firmware version = %d", ToString((cec_server_version)m_configuration.serverVersion), ToString((cec_client_version)m_configuration.clientVersion), m_configuration.iFirmwareVersion);
1027 if (m_configuration.iFirmwareBuildDate != CEC_FW_BUILD_UNKNOWN)
1028 {
1029 time_t buildTime = (time_t)m_configuration.iFirmwareBuildDate;
1030 strLog.AppendFormat(", firmware build date: %s", asctime(gmtime(&buildTime)));
1031 strLog = strLog.Left((int)strLog.length() - 1); // strip \n added by asctime
1032 strLog.append(" +0000");
1033 }
1034
1035 // log the addresses that are being used
1036 if (!m_configuration.logicalAddresses.IsEmpty())
1037 {
1038 strLog.append(", logical address(es) = ");
1039 CECDEVICEVEC devices;
1040 m_processor->GetDevices()->GetByLogicalAddresses(devices, m_configuration.logicalAddresses);
1041 for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++)
1042 strLog.AppendFormat("%s (%X) ", (*it)->GetLogicalAddressName(), (*it)->GetLogicalAddress());
1043 }
1044
1045 if (!CLibCEC::IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
1046 strLog.AppendFormat(", base device: %s (%X), HDMI port number: %d", ToString(m_configuration.baseDevice), m_configuration.baseDevice, m_configuration.iHDMIPort);
1047 else
1048 strLog.AppendFormat(", physical address: %04x", m_configuration.iPhysicalAddress);
1049
1050 return strLog;
1051 }
1052
1053 void CCECClient::SetTVVendorOverride(const cec_vendor_id id)
1054 {
1055 {
1056 CLockObject lock(m_mutex);
1057 m_configuration.tvVendor = id;
1058 }
1059
1060 if (id != CEC_VENDOR_UNKNOWN)
1061 {
1062 LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - vendor id '%s'", __FUNCTION__, ToString(id));
1063
1064 CCECBusDevice *tv = m_processor ? m_processor->GetTV() : NULL;
1065 if (tv)
1066 tv->SetVendorId((uint64_t)id);
1067 }
1068 }
1069
1070 cec_vendor_id CCECClient::GetTVVendorOverride(void)
1071 {
1072 CLockObject lock(m_mutex);
1073 return (cec_vendor_id)m_configuration.tvVendor;
1074 }
1075
1076 void CCECClient::SetOSDName(const CStdString &strDeviceName)
1077 {
1078 {
1079 CLockObject lock(m_mutex);
1080 snprintf(m_configuration.strDeviceName, 13, "%s", strDeviceName.c_str());
1081 }
1082
1083 LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - using OSD name '%s'", __FUNCTION__, strDeviceName.c_str());
1084
1085 CCECBusDevice *primary = GetPrimaryDevice();
1086 if (primary && !primary->GetCurrentOSDName().Equals(strDeviceName))
1087 {
1088 primary->SetOSDName(strDeviceName);
1089 if (m_processor && m_processor->CECInitialised())
1090 primary->TransmitOSDName(CECDEVICE_TV);
1091 }
1092 }
1093
1094 CStdString CCECClient::GetOSDName(void)
1095 {
1096 CLockObject lock(m_mutex);
1097 CStdString strOSDName(m_configuration.strDeviceName);
1098 return strOSDName;
1099 }
1100
1101 void CCECClient::SetWakeDevices(const cec_logical_addresses &addresses)
1102 {
1103 CLockObject lock(m_mutex);
1104 m_configuration.wakeDevices = addresses;
1105 }
1106
1107 cec_logical_addresses CCECClient::GetWakeDevices(void)
1108 {
1109 CLockObject lock(m_mutex);
1110 return m_configuration.wakeDevices;
1111 }
1112
1113 bool CCECClient::AutodetectPhysicalAddress(void)
1114 {
1115 bool bPhysicalAutodetected(false);
1116 uint16_t iPhysicalAddress = m_processor ? m_processor->GetDetectedPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS;
1117
1118 if (CLibCEC::IsValidPhysicalAddress(iPhysicalAddress))
1119 {
1120 LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%04X'", __FUNCTION__, iPhysicalAddress);
1121
1122 CLockObject lock(m_mutex);
1123 m_configuration.iPhysicalAddress = iPhysicalAddress;
1124 m_configuration.iHDMIPort = CEC_HDMI_PORTNUMBER_NONE;
1125 m_configuration.baseDevice = CECDEVICE_UNKNOWN;
1126 bPhysicalAutodetected = true;
1127 }
1128
1129 SetDevicePhysicalAddress(iPhysicalAddress);
1130
1131 return bPhysicalAutodetected;
1132 }
1133
1134 void CCECClient::SetClientVersion(const cec_client_version version)
1135 {
1136 LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - using client version '%s'", __FUNCTION__, ToString(version));
1137
1138 CLockObject lock(m_mutex);
1139 m_configuration.clientVersion = (uint32_t)version;
1140 }
1141
1142 cec_client_version CCECClient::GetClientVersion(void)
1143 {
1144 CLockObject lock(m_mutex);
1145 return (cec_client_version)m_configuration.clientVersion;
1146 }
1147
1148 bool CCECClient::SetDeviceTypes(const cec_device_type_list &deviceTypes)
1149 {
1150 bool bNeedReinit(false);
1151
1152 {
1153 CLockObject lock(m_mutex);
1154 bNeedReinit = m_processor && m_processor->CECInitialised() &&
1155 (m_configuration.deviceTypes != deviceTypes);
1156 m_configuration.deviceTypes = deviceTypes;
1157 }
1158
1159 if (bNeedReinit)
1160 LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - using primary device type '%s'", __FUNCTION__, ToString(deviceTypes[0]));
1161
1162 return bNeedReinit;
1163 }
1164
1165 cec_device_type_list CCECClient::GetDeviceTypes(void)
1166 {
1167 cec_device_type_list retVal;
1168 CLockObject lock(m_mutex);
1169 retVal = m_configuration.deviceTypes;
1170 return retVal;
1171 }
1172
1173 bool CCECClient::SetDevicePhysicalAddress(const uint16_t iPhysicalAddress)
1174 {
1175 if (!CLibCEC::IsValidPhysicalAddress(iPhysicalAddress))
1176 {
1177 LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - not setting invalid physical address %04x", __FUNCTION__, iPhysicalAddress);
1178 return false;
1179 }
1180
1181 // reconfigure all devices
1182 cec_logical_address reactivateSource(CECDEVICE_UNKNOWN);
1183 CECDEVICEVEC devices;
1184 m_processor->GetDevices()->GetByLogicalAddresses(devices, m_configuration.logicalAddresses);
1185 for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++)
1186 {
1187 // if this device was the active source, reactivate it afterwards
1188 if ((*it)->IsActiveSource())
1189 reactivateSource = (*it)->GetLogicalAddress();
1190
1191 // mark the device as inactive source
1192 if (IsInitialised())
1193 (*it)->MarkAsInactiveSource();
1194
1195 // set the new physical address
1196 (*it)->SetPhysicalAddress(iPhysicalAddress);
1197
1198 // and transmit it
1199 if (IsInitialised())
1200 (*it)->TransmitPhysicalAddress();
1201 }
1202
1203 // reactivate the previous active source
1204 if (reactivateSource != CECDEVICE_UNKNOWN &&
1205 m_processor->CECInitialised() &&
1206 IsInitialised())
1207 {
1208 CCECBusDevice *device = m_processor->GetDevice(reactivateSource);
1209 if (device)
1210 device->ActivateSource();
1211 }
1212
1213 return true;
1214 }
1215
1216 bool CCECClient::SwitchMonitoring(bool bEnable)
1217 {
1218 LIB_CEC->AddLog(CEC_LOG_NOTICE, "== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
1219
1220 if (m_processor)
1221 {
1222 if (bEnable)
1223 return m_processor->UnregisterClient(this);
1224 else
1225 {
1226 m_configuration.bMonitorOnly = false;
1227 return m_processor->RegisterClient(this);
1228 }
1229 }
1230
1231 return false;
1232 }
1233
1234 bool CCECClient::PollDevice(const cec_logical_address iAddress)
1235 {
1236 // try to find the primary device
1237 CCECBusDevice *primary = GetPrimaryDevice();
1238 // poll the destination, with the primary as source
1239 if (primary)
1240 return primary->TransmitPoll(iAddress);
1241
1242 return m_processor ? m_processor->PollDevice(iAddress) : false;
1243 }
1244
1245 cec_logical_addresses CCECClient::GetActiveDevices(void)
1246 {
1247 CECDEVICEVEC activeDevices;
1248 if (m_processor)
1249 m_processor->GetDevices()->GetActive(activeDevices);
1250 return CCECDeviceMap::ToLogicalAddresses(activeDevices);
1251 }
1252
1253 bool CCECClient::IsActiveDevice(const cec_logical_address iAddress)
1254 {
1255 cec_logical_addresses activeDevices = GetActiveDevices();
1256 return activeDevices.IsSet(iAddress);
1257 }
1258
1259 bool CCECClient::IsActiveDeviceType(const cec_device_type type)
1260 {
1261 CECDEVICEVEC activeDevices;
1262 if (m_processor)
1263 m_processor->GetDevices()->GetActive(activeDevices);
1264 CCECDeviceMap::FilterType(type, activeDevices);
1265 return !activeDevices.empty();
1266 }
1267
1268 cec_logical_address CCECClient::GetActiveSource(void)
1269 {
1270 return m_processor ? m_processor->GetActiveSource() : CECDEVICE_UNKNOWN;
1271 }
1272
1273 bool CCECClient::IsActiveSource(const cec_logical_address iAddress)
1274 {
1275 return m_processor ? m_processor->IsActiveSource(iAddress) : false;
1276 }
1277
1278 bool CCECClient::SetStreamPath(const cec_logical_address iAddress)
1279 {
1280 uint16_t iPhysicalAddress = GetDevicePhysicalAddress(iAddress);
1281 if (iPhysicalAddress != CEC_INVALID_PHYSICAL_ADDRESS)
1282 return SetStreamPath(iPhysicalAddress);
1283 return false;
1284 }
1285
1286 bool CCECClient::SetStreamPath(const uint16_t iPhysicalAddress)
1287 {
1288 return m_processor ? m_processor->SetStreamPath(iPhysicalAddress) : false;
1289 }
1290
1291 cec_logical_addresses CCECClient::GetLogicalAddresses(void)
1292 {
1293 cec_logical_addresses addresses;
1294 CLockObject lock(m_mutex);
1295 addresses = m_configuration.logicalAddresses;
1296 return addresses;
1297 }
1298
1299 bool CCECClient::CanPersistConfiguration(void)
1300 {
1301 return m_processor ? m_processor->CanPersistConfiguration() : false;
1302 }
1303
1304 bool CCECClient::PersistConfiguration(const libcec_configuration &configuration)
1305 {
1306 return m_processor ? m_processor->PersistConfiguration(configuration) : false;
1307 }
1308
1309 void CCECClient::RescanActiveDevices(void)
1310 {
1311 if (m_processor)
1312 m_processor->RescanActiveDevices();
1313 }
1314
1315 bool CCECClient::IsLibCECActiveSource(void)
1316 {
1317 bool bReturn(false);
1318 if (m_processor)
1319 {
1320 cec_logical_address activeSource = m_processor->GetActiveSource();
1321 CCECBusDevice *device = m_processor->GetDevice(activeSource);
1322 if (device)
1323 bReturn = device->IsHandledByLibCEC();
1324 }
1325 return bReturn;
1326 }