2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
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/
33 #include "CECProcessor.h"
35 #include "adapter/USBCECAdapterCommunication.h"
36 #include "devices/CECBusDevice.h"
37 #include "devices/CECAudioSystem.h"
38 #include "devices/CECPlaybackDevice.h"
39 #include "devices/CECRecordingDevice.h"
40 #include "devices/CECTuner.h"
41 #include "devices/CECTV.h"
42 #include "implementations/CECCommandHandler.h"
44 #include "CECClient.h"
45 #include "platform/util/timeutils.h"
46 #include "platform/util/util.h"
50 using namespace PLATFORM
;
52 #define CEC_PROCESSOR_SIGNAL_WAIT_TIME 1000
54 #define ToString(x) m_libcec->ToString(x)
56 CCECProcessor::CCECProcessor(CLibCEC
*libcec
) :
57 m_bInitialised(false),
58 m_communication(NULL
),
60 m_iStandardLineTimeout(3),
61 m_iRetryLineTimeout(3),
62 m_iLastTransmission(0)
64 m_busDevices
= new CCECDeviceMap(this);
67 CCECProcessor::~CCECProcessor(void)
70 DELETE_AND_NULL(m_busDevices
);
73 bool CCECProcessor::Start(const char *strPort
, uint16_t iBaudRate
/* = CEC_SERIAL_DEFAULT_BAUDRATE */, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
75 CLockObject
lock(m_mutex
);
77 if (!OpenConnection(strPort
, iBaudRate
, iTimeoutMs
))
80 // create the processor thread
85 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
93 void CCECProcessor::Close(void)
95 // mark as uninitialised
96 SetCECInitialised(false);
101 // close the connection
102 DELETE_AND_NULL(m_communication
);
105 void CCECProcessor::ResetMembers(void)
107 // close the connection
108 DELETE_AND_NULL(m_communication
);
110 // reset the other members to the initial state
111 m_iStandardLineTimeout
= 3;
112 m_iRetryLineTimeout
= 3;
113 m_iLastTransmission
= 0;
114 m_busDevices
->ResetDeviceStatus();
117 bool CCECProcessor::OpenConnection(const char *strPort
, uint16_t iBaudRate
, uint32_t iTimeoutMs
, bool bStartListening
/* = true */)
120 CTimeout
timeout(iTimeoutMs
> 0 ? iTimeoutMs
: CEC_DEFAULT_TRANSMIT_WAIT
);
122 // ensure that a previous connection is closed
125 // reset all member to the initial state
128 // check whether the Close() method deleted any previous connection
131 m_libcec
->AddLog(CEC_LOG_ERROR
, "previous connection could not be closed");
135 // create a new connection
136 m_communication
= new CUSBCECAdapterCommunication(this, strPort
, iBaudRate
);
138 // open a new connection
139 unsigned iConnectTry(0);
140 while (timeout
.TimeLeft() > 0 && (bReturn
= m_communication
->Open((timeout
.TimeLeft() / CEC_CONNECT_TRIES
), false, bStartListening
)) == false)
142 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
143 m_communication
->Close();
144 CEvent::Sleep(CEC_DEFAULT_CONNECT_RETRY_WAIT
);
147 m_libcec
->AddLog(CEC_LOG_NOTICE
, "connection opened");
149 // always start by setting the ackmask to 0, to clear previous values
152 // mark as initialised
153 SetCECInitialised(true);
158 bool CCECProcessor::CECInitialised(void)
160 CLockObject
lock(m_threadMutex
);
161 return m_bInitialised
;
164 void CCECProcessor::SetCECInitialised(bool bSetTo
/* = true */)
167 CLockObject
lock(m_mutex
);
168 m_bInitialised
= bSetTo
;
174 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
177 CCECBusDevice
*device
= m_busDevices
->At(address
);
180 // check if it's already marked as present or used
181 if (device
->IsPresent() || device
->IsHandledByLibCEC())
184 // poll the LA if not
186 return device
->TryLogicalAddress();
192 void CCECProcessor::ReplaceHandlers(void)
194 if (!CECInitialised())
198 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
199 it
->second
->ReplaceHandler(true);
202 bool CCECProcessor::OnCommandReceived(const cec_command
&command
)
204 return m_inBuffer
.Push(command
);
207 void *CCECProcessor::Process(void)
209 m_libcec
->AddLog(CEC_LOG_DEBUG
, "processor thread started");
213 // as long as we're not being stopped and the connection is open
214 while (!IsStopped() && m_communication
->IsOpen())
216 // wait for a new incoming command, and process it
217 if (m_inBuffer
.Pop(command
, CEC_PROCESSOR_SIGNAL_WAIT_TIME
))
218 ProcessCommand(command
);
220 if (CECInitialised())
222 // check clients for keypress timeouts
223 m_libcec
->CheckKeypressTimeout();
225 // check if we need to replace handlers
233 bool CCECProcessor::ActivateSource(uint16_t iStreamPath
)
237 // find the device with the given PA
238 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
239 // and make it the active source when found
241 bReturn
= device
->ActivateSource();
243 m_libcec
->AddLog(CEC_LOG_DEBUG
, "device with PA '%04x' not found", iStreamPath
);
248 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout
)
250 CLockObject
lock(m_mutex
);
251 m_iStandardLineTimeout
= iTimeout
;
254 uint8_t CCECProcessor::GetStandardLineTimeout(void)
256 CLockObject
lock(m_mutex
);
257 return m_iStandardLineTimeout
;
260 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout
)
262 CLockObject
lock(m_mutex
);
263 m_iRetryLineTimeout
= iTimeout
;
266 uint8_t CCECProcessor::GetRetryLineTimeout(void)
268 CLockObject
lock(m_mutex
);
269 return m_iRetryLineTimeout
;
272 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress
)
274 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iPhysicalAddress
);
275 return device
!= NULL
;
278 void CCECProcessor::LogOutput(const cec_command
&data
)
282 // initiator and destination
283 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
287 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
289 // append the parameters
290 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
291 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
294 m_libcec
->AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
297 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
299 // try to find the primary device
300 CCECBusDevice
*primary
= GetPrimaryDevice();
301 // poll the destination, with the primary as source
303 return primary
->TransmitPoll(iAddress
);
305 // try to find the destination
306 CCECBusDevice
*device
= m_busDevices
->At(iAddress
);
307 // and poll the destination, with the same LA as source
309 return device
->TransmitPoll(iAddress
);
314 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bSuppressUpdate
/* = true */)
316 return m_busDevices
?
317 m_busDevices
->GetDeviceByPhysicalAddress(iPhysicalAddress
, bSuppressUpdate
) :
321 CCECBusDevice
*CCECProcessor::GetDevice(cec_logical_address address
) const
323 return m_busDevices
?
324 m_busDevices
->At(address
) :
328 cec_logical_address
CCECProcessor::GetActiveSource(bool bRequestActiveSource
/* = true */)
330 // get the device that is marked as active source from the device map
331 CCECBusDevice
*activeSource
= m_busDevices
->GetActiveSource();
333 return activeSource
->GetLogicalAddress();
335 if (bRequestActiveSource
)
337 // request the active source from the bus
338 CCECBusDevice
*primary
= GetPrimaryDevice();
341 primary
->RequestActiveSource();
342 return GetActiveSource(false);
347 return CECDEVICE_UNKNOWN
;
350 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
352 CCECBusDevice
*device
= m_busDevices
->At(iAddress
);
353 return device
&& device
->IsActiveSource();
356 bool CCECProcessor::Transmit(const cec_command
&data
)
358 uint8_t iMaxTries(0);
362 // get the current timeout setting
363 uint8_t iLineTimeout(GetStandardLineTimeout());
365 // reset the state of this message to 'unknown'
366 cec_adapter_message_state adapterState
= ADAPTER_MESSAGE_STATE_UNKNOWN
;
370 // find the initiator device
371 CCECBusDevice
*initiator
= m_busDevices
->At(data
.initiator
);
374 m_libcec
->AddLog(CEC_LOG_WARNING
, "invalid initiator");
378 // find the destination device, if it's not the broadcast address
379 if (data
.destination
!= CECDEVICE_BROADCAST
)
381 // check if the device is marked as handled by libCEC
382 CCECBusDevice
*destination
= m_busDevices
->At(data
.destination
);
383 if (destination
&& destination
->IsHandledByLibCEC())
385 // and reject the command if it's trying to send data to a device that is handled by libCEC
386 m_libcec
->AddLog(CEC_LOG_WARNING
, "not sending data to myself!");
392 CLockObject
lock(m_mutex
);
393 m_iLastTransmission
= GetTimeMs();
394 // set the number of tries
395 iMaxTries
= initiator
->GetHandler()->GetTransmitRetries() + 1;
398 // and try to send the command
399 while (bRetry
&& ++iTries
< iMaxTries
)
401 if (initiator
->IsUnsupportedFeature(data
.opcode
))
404 adapterState
= !IsStopped() && m_communication
&& m_communication
->IsOpen() ?
405 m_communication
->Write(data
, bRetry
, iLineTimeout
) :
406 ADAPTER_MESSAGE_STATE_ERROR
;
407 iLineTimeout
= m_iRetryLineTimeout
;
410 return adapterState
== ADAPTER_MESSAGE_STATE_SENT_ACKED
;
413 void CCECProcessor::TransmitAbort(cec_logical_address source
, cec_logical_address destination
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
415 m_libcec
->AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
418 cec_command::Format(command
, source
, destination
, CEC_OPCODE_FEATURE_ABORT
);
419 command
.parameters
.PushBack((uint8_t)opcode
);
420 command
.parameters
.PushBack((uint8_t)reason
);
425 void CCECProcessor::ProcessCommand(const cec_command
&command
)
429 dataStr
.Format(">> %1x%1x", command
.initiator
, command
.destination
);
430 if (command
.opcode_set
== 1)
431 dataStr
.AppendFormat(":%02x", command
.opcode
);
432 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
433 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
434 m_libcec
->AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
436 // find the initiator
437 CCECBusDevice
*device
= m_busDevices
->At(command
.initiator
);
440 device
->HandleCommand(command
);
443 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
445 CCECBusDevice
*device
= m_busDevices
->At(address
);
446 return device
&& device
->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
449 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
451 CECDEVICEVEC devices
;
452 m_busDevices
->GetByType(type
, devices
);
453 CCECDeviceMap::FilterActive(devices
);
454 return !devices
.empty();
457 uint16_t CCECProcessor::GetDetectedPhysicalAddress(void) const
459 return m_communication
? m_communication
->GetPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS
;
462 bool CCECProcessor::SetAckMask(uint16_t iMask
)
464 return m_communication
? m_communication
->SetAckMask(iMask
) : false;
467 bool CCECProcessor::StandbyDevices(const cec_logical_address initiator
, const CECDEVICEVEC
&devices
)
470 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
471 bReturn
&= (*it
)->Standby(initiator
);
475 bool CCECProcessor::StandbyDevice(const cec_logical_address initiator
, cec_logical_address address
)
477 CCECBusDevice
*device
= m_busDevices
->At(address
);
478 return device
? device
->Standby(initiator
) : false;
481 bool CCECProcessor::PowerOnDevices(const cec_logical_address initiator
, const CECDEVICEVEC
&devices
)
484 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
485 bReturn
&= (*it
)->PowerOn(initiator
);
489 bool CCECProcessor::PowerOnDevice(const cec_logical_address initiator
, cec_logical_address address
)
491 CCECBusDevice
*device
= m_busDevices
->At(address
);
492 return device
? device
->PowerOn(initiator
) : false;
495 bool CCECProcessor::StartBootloader(const char *strPort
/* = NULL */)
498 // open a connection if no connection has been opened
499 if (!m_communication
&& strPort
)
501 IAdapterCommunication
*comm
= new CUSBCECAdapterCommunication(this, strPort
);
502 CTimeout
timeout(CEC_DEFAULT_CONNECT_TIMEOUT
);
504 while (timeout
.TimeLeft() > 0 && (bReturn
= comm
->Open(timeout
.TimeLeft() / CEC_CONNECT_TRIES
, true)) == false)
506 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
508 Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT
);
512 bReturn
= comm
->StartBootloader();
513 DELETE_AND_NULL(comm
);
519 m_communication
->StartBootloader();
527 bool CCECProcessor::PingAdapter(void)
529 return m_communication
->PingAdapter();
532 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
534 CCECBusDevice
*device
= m_busDevices
->At(destination
);
536 device
->HandlePollFrom(initiator
);
539 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator
)
541 CCECBusDevice
*device
= m_busDevices
->At(initiator
);
542 return !device
|| !device
->HandleReceiveFailed();
545 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress
)
547 // stream path changes are sent by the TV
548 return GetTV()->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
);
551 bool CCECProcessor::CanPersistConfiguration(void)
553 return m_communication
? m_communication
->GetFirmwareVersion() >= 2 : false;
556 bool CCECProcessor::PersistConfiguration(const libcec_configuration
&configuration
)
558 return m_communication
? m_communication
->PersistConfiguration(configuration
) : false;
561 void CCECProcessor::RescanActiveDevices(void)
563 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
564 it
->second
->GetStatus(true);
567 bool CCECProcessor::GetDeviceInformation(const char *strPort
, libcec_configuration
*config
, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
569 if (!OpenConnection(strPort
, CEC_SERIAL_DEFAULT_BAUDRATE
, iTimeoutMs
, false))
572 config
->iFirmwareVersion
= m_communication
->GetFirmwareVersion();
573 config
->iPhysicalAddress
= m_communication
->GetPhysicalAddress();
574 config
->iFirmwareBuildDate
= m_communication
->GetFirmwareBuildDate();
579 bool CCECProcessor::TransmitPendingActiveSourceCommands(void)
582 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
583 bReturn
&= it
->second
->TransmitPendingActiveSourceCommands();
587 CCECTV
*CCECProcessor::GetTV(void) const
589 return CCECBusDevice::AsTV(m_busDevices
->At(CECDEVICE_TV
));
592 CCECAudioSystem
*CCECProcessor::GetAudioSystem(void) const
594 return CCECBusDevice::AsAudioSystem(m_busDevices
->At(CECDEVICE_AUDIOSYSTEM
));
597 CCECPlaybackDevice
*CCECProcessor::GetPlaybackDevice(cec_logical_address address
) const
599 return CCECBusDevice::AsPlaybackDevice(m_busDevices
->At(address
));
602 CCECRecordingDevice
*CCECProcessor::GetRecordingDevice(cec_logical_address address
) const
604 return CCECBusDevice::AsRecordingDevice(m_busDevices
->At(address
));
607 CCECTuner
*CCECProcessor::GetTuner(cec_logical_address address
) const
609 return CCECBusDevice::AsTuner(m_busDevices
->At(address
));
612 bool CCECProcessor::RegisterClient(CCECClient
*client
)
617 libcec_configuration
&configuration
= *client
->GetConfiguration();
619 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_6_3
&& configuration
.bMonitorOnly
== 1)
622 if (!CECInitialised())
624 m_libcec
->AddLog(CEC_LOG_ERROR
, "failed to register a new CEC client: CEC processor is not initialised");
628 // unregister the client first if it's already been marked as registered
629 if (client
->IsRegistered())
630 UnregisterClient(client
);
632 // get the configuration from the client
633 m_libcec
->AddLog(CEC_LOG_NOTICE
, "registering new CEC client - v%s", ToString((cec_client_version
)configuration
.clientVersion
));
635 // mark as uninitialised and unregistered
636 client
->SetRegistered(false);
637 client
->SetInitialised(false);
639 // get the current ackmask, so we can restore it if polling fails
640 uint16_t iPreviousMask(m_communication
->GetAckMask());
642 // find logical addresses for this client
643 if (!client
->AllocateLogicalAddresses())
645 m_libcec
->AddLog(CEC_LOG_ERROR
, "failed to register the new CEC client - cannot allocate the requested device types");
646 SetAckMask(iPreviousMask
);
650 // register this client on the new addresses
651 CECDEVICEVEC devices
;
652 m_busDevices
->GetByLogicalAddresses(devices
, configuration
.logicalAddresses
);
653 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
655 // replace a previous client
656 CLockObject
lock(m_mutex
);
657 m_clients
.erase((*it
)->GetLogicalAddress());
658 m_clients
.insert(make_pair
<cec_logical_address
, CCECClient
*>((*it
)->GetLogicalAddress(), client
));
661 // get the settings from the rom
662 if (configuration
.bGetSettingsFromROM
== 1)
664 libcec_configuration config
;
665 m_communication
->GetConfiguration(config
);
667 CLockObject
lock(m_mutex
);
668 if (!config
.deviceTypes
.IsEmpty())
669 configuration
.deviceTypes
= config
.deviceTypes
;
670 if (CLibCEC::IsValidPhysicalAddress(config
.iPhysicalAddress
))
671 configuration
.iPhysicalAddress
= config
.iPhysicalAddress
;
672 snprintf(configuration
.strDeviceName
, 13, "%s", config
.strDeviceName
);
675 // set the firmware version and build date
676 configuration
.serverVersion
= LIBCEC_VERSION_CURRENT
;
677 configuration
.iFirmwareVersion
= m_communication
->GetFirmwareVersion();
678 configuration
.iFirmwareBuildDate
= m_communication
->GetFirmwareBuildDate();
680 // mark the client as registered
681 client
->SetRegistered(true);
683 // set the new ack mask
684 bool bReturn
= SetAckMask(GetLogicalAddresses().AckMask()) &&
685 // and initialise the client
686 client
->OnRegister();
688 // log the new registration
690 strLog
.Format("%s: %s", bReturn
? "CEC client registered" : "failed to register the CEC client", client
->GetConnectionInfo().c_str());
691 m_libcec
->AddLog(bReturn
? CEC_LOG_NOTICE
: CEC_LOG_ERROR
, strLog
);
693 // display a warning if the firmware can be upgraded
694 if (bReturn
&& !IsRunningLatestFirmware())
696 const char *strUpgradeMessage
= "The firmware of this adapter can be upgraded. Please visit http://blog.pulse-eight.com/ for more information.";
697 m_libcec
->AddLog(CEC_LOG_WARNING
, strUpgradeMessage
);
698 libcec_parameter param
;
699 param
.paramData
= (void*)strUpgradeMessage
; param
.paramType
= CEC_PARAMETER_TYPE_STRING
;
700 client
->Alert(CEC_ALERT_SERVICE_DEVICE
, param
);
706 bool CCECProcessor::UnregisterClient(CCECClient
*client
)
711 if (client
->IsRegistered())
712 m_libcec
->AddLog(CEC_LOG_NOTICE
, "unregistering client: %s", client
->GetConnectionInfo().c_str());
714 // notify the client that it will be unregistered
715 client
->OnUnregister();
718 CLockObject
lock(m_mutex
);
719 // find all devices that match the LA's of this client
720 CECDEVICEVEC devices
;
721 m_busDevices
->GetByLogicalAddresses(devices
, client
->GetConfiguration()->logicalAddresses
);
722 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
725 map
<cec_logical_address
, CCECClient
*>::iterator entry
= m_clients
.find((*it
)->GetLogicalAddress());
726 // unregister the client
727 if (entry
!= m_clients
.end())
728 m_clients
.erase(entry
);
730 // reset the device status
731 (*it
)->ResetDeviceStatus();
735 // set the new ackmask
736 return SetAckMask(GetLogicalAddresses().AckMask());
739 void CCECProcessor::UnregisterClients(void)
741 m_libcec
->AddLog(CEC_LOG_NOTICE
, "unregistering all CEC clients");
743 vector
<CCECClient
*> clients
= m_libcec
->GetClients();
744 for (vector
<CCECClient
*>::iterator client
= clients
.begin(); client
!= clients
.end(); client
++)
745 UnregisterClient(*client
);
747 CLockObject
lock(m_mutex
);
751 CCECClient
*CCECProcessor::GetClient(const cec_logical_address address
)
753 CLockObject
lock(m_mutex
);
754 map
<cec_logical_address
, CCECClient
*>::const_iterator client
= m_clients
.find(address
);
755 if (client
!= m_clients
.end())
756 return client
->second
;
760 CCECClient
*CCECProcessor::GetPrimaryClient(void)
762 CLockObject
lock(m_mutex
);
763 map
<cec_logical_address
, CCECClient
*>::const_iterator client
= m_clients
.begin();
764 if (client
!= m_clients
.end())
765 return client
->second
;
769 CCECBusDevice
*CCECProcessor::GetPrimaryDevice(void)
771 return m_busDevices
->At(GetLogicalAddress());
774 cec_logical_address
CCECProcessor::GetLogicalAddress(void)
776 cec_logical_addresses addresses
= GetLogicalAddresses();
777 return addresses
.primary
;
780 cec_logical_addresses
CCECProcessor::GetLogicalAddresses(void)
782 CLockObject
lock(m_mutex
);
783 cec_logical_addresses addresses
;
785 for (map
<cec_logical_address
, CCECClient
*>::const_iterator client
= m_clients
.begin(); client
!= m_clients
.end(); client
++)
786 addresses
.Set(client
->first
);
791 bool CCECProcessor::IsHandledByLibCEC(const cec_logical_address address
) const
793 CCECBusDevice
*device
= GetDevice(address
);
794 return device
&& device
->IsHandledByLibCEC();
797 bool CCECProcessor::IsRunningLatestFirmware(void)
799 return m_communication
&& m_communication
->IsOpen() ?
800 m_communication
->IsRunningLatestFirmware() :