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"
49 using namespace PLATFORM
;
51 #define CEC_PROCESSOR_SIGNAL_WAIT_TIME 1000
53 #define ToString(x) m_libcec->ToString(x)
55 CCECProcessor::CCECProcessor(CLibCEC
*libcec
) :
56 m_bInitialised(false),
57 m_communication(NULL
),
60 m_iPreviousAckMask(0),
61 m_iStandardLineTimeout(3),
62 m_iRetryLineTimeout(3),
63 m_iLastTransmission(0)
65 m_busDevices
= new CCECDeviceMap(this);
68 CCECProcessor::~CCECProcessor(void)
74 bool CCECProcessor::Start(const char *strPort
, uint16_t iBaudRate
/* = CEC_SERIAL_DEFAULT_BAUDRATE */, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
76 CLockObject
lock(m_mutex
);
78 if (!OpenConnection(strPort
, iBaudRate
, iTimeoutMs
))
81 // create the processor thread
86 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
91 // mark as initialised
92 SetCECInitialised(true);
97 void CCECProcessor::Close(void)
99 // mark as uninitialised
100 SetCECInitialised(false);
102 // stop the processor
105 // close the connection
108 delete m_communication
;
109 m_communication
= NULL
;
113 void CCECProcessor::ResetMembers(void)
115 // close the connection
118 delete m_communication
;
119 m_communication
= NULL
;
122 // reset the other members to the initial state
124 m_iPreviousAckMask
= 0;
125 m_iStandardLineTimeout
= 3;
126 m_iRetryLineTimeout
= 3;
127 m_iLastTransmission
= 0;
128 m_busDevices
->ResetDeviceStatus();
131 bool CCECProcessor::OpenConnection(const char *strPort
, uint16_t iBaudRate
, uint32_t iTimeoutMs
, bool bStartListening
/* = true */)
134 CTimeout
timeout(iTimeoutMs
> 0 ? iTimeoutMs
: CEC_DEFAULT_TRANSMIT_WAIT
);
136 // ensure that a previous connection is closed
139 // reset all member to the initial state
142 // check whether the Close() method deleted any previous connection
145 m_libcec
->AddLog(CEC_LOG_ERROR
, "previous connection could not be closed");
149 // create a new connection
150 m_communication
= new CUSBCECAdapterCommunication(this, strPort
, iBaudRate
);
152 // open a new connection
153 unsigned iConnectTry(0);
154 while (timeout
.TimeLeft() > 0 && (bReturn
= m_communication
->Open((timeout
.TimeLeft() / CEC_CONNECT_TRIES
), false, bStartListening
)) == false)
156 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
157 m_communication
->Close();
158 CEvent::Sleep(CEC_DEFAULT_CONNECT_RETRY_WAIT
);
161 m_libcec
->AddLog(CEC_LOG_NOTICE
, "connection opened");
166 bool CCECProcessor::CECInitialised(void)
168 CLockObject
lock(m_threadMutex
);
169 return m_bInitialised
;
172 void CCECProcessor::SetCECInitialised(bool bSetTo
/* = true */)
175 CLockObject
lock(m_mutex
);
176 m_bInitialised
= bSetTo
;
182 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
185 CCECBusDevice
*device
= m_busDevices
->At(address
);
188 // check if it's already marked as present or used
189 if (device
->IsPresent() || device
->IsHandledByLibCEC())
192 // poll the LA if not
194 return device
->TryLogicalAddress();
200 void CCECProcessor::ReplaceHandlers(void)
202 if (!CECInitialised())
206 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
207 it
->second
->ReplaceHandler(true);
210 bool CCECProcessor::OnCommandReceived(const cec_command
&command
)
212 return m_inBuffer
.Push(command
);
215 void *CCECProcessor::Process(void)
217 m_libcec
->AddLog(CEC_LOG_DEBUG
, "processor thread started");
221 // as long as we're not being stopped and the connection is open
222 while (!IsStopped() && m_communication
->IsOpen())
224 // wait for a new incoming command, and process it
225 if (m_inBuffer
.Pop(command
, CEC_PROCESSOR_SIGNAL_WAIT_TIME
))
226 ProcessCommand(command
);
228 if (CECInitialised())
230 // check clients for keypress timeouts
231 m_libcec
->CheckKeypressTimeout();
233 // check if we need to replace handlers
241 bool CCECProcessor::ActivateSource(uint16_t iStreamPath
)
245 // find the device with the given PA
246 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
247 // and make it the active source when found
249 bReturn
= device
->ActivateSource();
251 m_libcec
->AddLog(CEC_LOG_DEBUG
, "device with PA '%04x' not found", iStreamPath
);
256 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout
)
258 CLockObject
lock(m_mutex
);
259 m_iStandardLineTimeout
= iTimeout
;
262 uint8_t CCECProcessor::GetStandardLineTimeout(void)
264 CLockObject
lock(m_mutex
);
265 return m_iStandardLineTimeout
;
268 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout
)
270 CLockObject
lock(m_mutex
);
271 m_iRetryLineTimeout
= iTimeout
;
274 uint8_t CCECProcessor::GetRetryLineTimeout(void)
276 CLockObject
lock(m_mutex
);
277 return m_iRetryLineTimeout
;
280 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress
)
282 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iPhysicalAddress
);
283 return device
!= NULL
;
286 void CCECProcessor::LogOutput(const cec_command
&data
)
290 // initiator and destination
291 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
295 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
297 // append the parameters
298 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
299 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
302 m_libcec
->AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
305 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
307 m_libcec
->AddLog(CEC_LOG_NOTICE
, "== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
310 CLockObject
lock(m_mutex
);
311 // switch to monitoring mode, which will stop processing of incoming messages
312 m_bMonitor
= bEnable
;
313 // and store the current ackmask
314 m_iPreviousAckMask
= m_communication
->GetAckMask();
317 // set the mask to 0 when enabling monitor mode
319 return SetAckMask(0);
320 // and restore the previous mask otherwise
322 return SetAckMask(m_iPreviousAckMask
);
325 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
327 // try to find the primary device
328 CCECBusDevice
*primary
= GetPrimaryDevice();
329 // poll the destination, with the primary as source
331 return primary
->TransmitPoll(iAddress
);
333 // try to find the destination
334 CCECBusDevice
*device
= m_busDevices
->At(iAddress
);
335 // and poll the destination, with the same LA as source
337 return device
->TransmitPoll(iAddress
);
342 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bSuppressUpdate
/* = true */)
344 return m_busDevices
?
345 m_busDevices
->GetDeviceByPhysicalAddress(iPhysicalAddress
, bSuppressUpdate
) :
349 CCECBusDevice
*CCECProcessor::GetDevice(cec_logical_address address
) const
351 return m_busDevices
?
352 m_busDevices
->At(address
) :
356 cec_logical_address
CCECProcessor::GetActiveSource(bool bRequestActiveSource
/* = true */)
358 // get the device that is marked as active source from the device map
359 CCECBusDevice
*activeSource
= m_busDevices
->GetActiveSource();
361 return activeSource
->GetLogicalAddress();
363 if (bRequestActiveSource
)
365 // request the active source from the bus
366 CCECBusDevice
*primary
= GetPrimaryDevice();
369 primary
->RequestActiveSource();
370 return GetActiveSource(false);
375 return CECDEVICE_UNKNOWN
;
378 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
380 CCECBusDevice
*device
= m_busDevices
->At(iAddress
);
381 return device
&& device
->IsActiveSource();
384 bool CCECProcessor::Transmit(const cec_command
&data
)
386 uint8_t iMaxTries(0);
390 // get the current timeout setting
391 uint8_t iLineTimeout(GetStandardLineTimeout());
393 // reset the state of this message to 'unknown'
394 cec_adapter_message_state adapterState
= ADAPTER_MESSAGE_STATE_UNKNOWN
;
398 // find the initiator device
399 CCECBusDevice
*initiator
= m_busDevices
->At(data
.initiator
);
402 m_libcec
->AddLog(CEC_LOG_WARNING
, "invalid initiator");
406 // find the destination device, if it's not the broadcast address
407 if (data
.destination
!= CECDEVICE_BROADCAST
)
409 // check if the device is marked as handled by libCEC
410 CCECBusDevice
*destination
= m_busDevices
->At(data
.destination
);
411 if (destination
&& destination
->IsHandledByLibCEC())
413 // and reject the command if it's trying to send data to a device that is handled by libCEC
414 m_libcec
->AddLog(CEC_LOG_WARNING
, "not sending data to myself!");
420 CLockObject
lock(m_mutex
);
421 m_iLastTransmission
= GetTimeMs();
422 // set the number of tries
423 iMaxTries
= initiator
->GetHandler()->GetTransmitRetries() + 1;
426 // and try to send the command
427 while (bRetry
&& ++iTries
< iMaxTries
)
429 if (initiator
->IsUnsupportedFeature(data
.opcode
))
432 adapterState
= !IsStopped() && m_communication
&& m_communication
->IsOpen() ?
433 m_communication
->Write(data
, bRetry
, iLineTimeout
) :
434 ADAPTER_MESSAGE_STATE_ERROR
;
435 iLineTimeout
= m_iRetryLineTimeout
;
438 return adapterState
== ADAPTER_MESSAGE_STATE_SENT_ACKED
;
441 void CCECProcessor::TransmitAbort(cec_logical_address source
, cec_logical_address destination
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
443 m_libcec
->AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
446 cec_command::Format(command
, source
, destination
, CEC_OPCODE_FEATURE_ABORT
);
447 command
.parameters
.PushBack((uint8_t)opcode
);
448 command
.parameters
.PushBack((uint8_t)reason
);
453 void CCECProcessor::ProcessCommand(const cec_command
&command
)
457 dataStr
.Format(">> %1x%1x", command
.initiator
, command
.destination
);
458 if (command
.opcode_set
== 1)
459 dataStr
.AppendFormat(":%02x", command
.opcode
);
460 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
461 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
462 m_libcec
->AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
464 // if we're not in monitor mode
467 // find the initiator
468 CCECBusDevice
*device
= m_busDevices
->At(command
.initiator
);
469 // and "handle" the command
471 device
->HandleCommand(command
);
475 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
477 CCECBusDevice
*device
= m_busDevices
->At(address
);
478 return device
&& device
->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
481 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
483 CECDEVICEVEC devices
;
484 m_busDevices
->GetByType(type
, devices
);
485 CCECDeviceMap::FilterActive(devices
);
486 return !devices
.empty();
489 uint16_t CCECProcessor::GetDetectedPhysicalAddress(void) const
491 return m_communication
? m_communication
->GetPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS
;
494 bool CCECProcessor::SetAckMask(uint16_t iMask
)
496 return m_communication
? m_communication
->SetAckMask(iMask
) : false;
499 bool CCECProcessor::StandbyDevices(const cec_logical_address initiator
, const CECDEVICEVEC
&devices
)
502 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
503 bReturn
&= (*it
)->Standby(initiator
);
507 bool CCECProcessor::StandbyDevice(const cec_logical_address initiator
, cec_logical_address address
)
509 CCECBusDevice
*device
= m_busDevices
->At(address
);
510 return device
? device
->Standby(initiator
) : false;
513 bool CCECProcessor::PowerOnDevices(const cec_logical_address initiator
, const CECDEVICEVEC
&devices
)
516 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
517 bReturn
&= (*it
)->PowerOn(initiator
);
521 bool CCECProcessor::PowerOnDevice(const cec_logical_address initiator
, cec_logical_address address
)
523 CCECBusDevice
*device
= m_busDevices
->At(address
);
524 return device
? device
->PowerOn(initiator
) : false;
527 bool CCECProcessor::StartBootloader(const char *strPort
/* = NULL */)
530 // open a connection if no connection has been opened
531 if (!m_communication
&& strPort
)
533 IAdapterCommunication
*comm
= new CUSBCECAdapterCommunication(this, strPort
);
534 CTimeout
timeout(CEC_DEFAULT_CONNECT_TIMEOUT
);
536 while (timeout
.TimeLeft() > 0 && (bReturn
= comm
->Open(timeout
.TimeLeft() / CEC_CONNECT_TRIES
, true)) == false)
538 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
540 Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT
);
544 bReturn
= comm
->StartBootloader();
551 m_communication
->StartBootloader();
559 bool CCECProcessor::PingAdapter(void)
561 return m_communication
->PingAdapter();
564 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
566 CCECBusDevice
*device
= m_busDevices
->At(destination
);
568 device
->HandlePollFrom(initiator
);
571 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator
)
573 CCECBusDevice
*device
= m_busDevices
->At(initiator
);
574 return !device
|| !device
->HandleReceiveFailed();
577 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress
)
579 // stream path changes are sent by the TV
580 return GetTV()->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
);
583 bool CCECProcessor::CanPersistConfiguration(void)
585 return m_communication
? m_communication
->GetFirmwareVersion() >= 2 : false;
588 bool CCECProcessor::PersistConfiguration(const libcec_configuration
&configuration
)
590 return m_communication
? m_communication
->PersistConfiguration(configuration
) : false;
593 void CCECProcessor::RescanActiveDevices(void)
595 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
596 it
->second
->GetStatus(true);
599 bool CCECProcessor::GetDeviceInformation(const char *strPort
, libcec_configuration
*config
, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
601 if (!OpenConnection(strPort
, CEC_SERIAL_DEFAULT_BAUDRATE
, iTimeoutMs
, false))
604 config
->iFirmwareVersion
= m_communication
->GetFirmwareVersion();
605 config
->iPhysicalAddress
= m_communication
->GetPhysicalAddress();
606 config
->iFirmwareBuildDate
= m_communication
->GetFirmwareBuildDate();
611 bool CCECProcessor::TransmitPendingActiveSourceCommands(void)
614 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
615 bReturn
&= it
->second
->TransmitPendingActiveSourceCommands();
619 CCECTV
*CCECProcessor::GetTV(void) const
621 return CCECBusDevice::AsTV(m_busDevices
->At(CECDEVICE_TV
));
624 CCECAudioSystem
*CCECProcessor::GetAudioSystem(void) const
626 return CCECBusDevice::AsAudioSystem(m_busDevices
->At(CECDEVICE_AUDIOSYSTEM
));
629 CCECPlaybackDevice
*CCECProcessor::GetPlaybackDevice(cec_logical_address address
) const
631 return CCECBusDevice::AsPlaybackDevice(m_busDevices
->At(address
));
634 CCECRecordingDevice
*CCECProcessor::GetRecordingDevice(cec_logical_address address
) const
636 return CCECBusDevice::AsRecordingDevice(m_busDevices
->At(address
));
639 CCECTuner
*CCECProcessor::GetTuner(cec_logical_address address
) const
641 return CCECBusDevice::AsTuner(m_busDevices
->At(address
));
644 bool CCECProcessor::RegisterClient(CCECClient
*client
)
646 if (!client
|| !IsRunning())
649 // unregister the client first if it's already been marked as registered
650 if (client
->IsRegistered())
651 UnregisterClient(client
);
653 // get the configuration from the client
654 libcec_configuration
&configuration
= *client
->GetConfiguration();
655 m_libcec
->AddLog(CEC_LOG_NOTICE
, "registering new CEC client - v%s", ToString((cec_client_version
)configuration
.clientVersion
));
657 // mark as uninitialised and unregistered
658 client
->SetRegistered(false);
659 client
->SetInitialised(false);
661 // get the current ackmask, so we can restore it if polling fails
662 uint16_t iPreviousMask(m_communication
->GetAckMask());
664 // find logical addresses for this client
665 if (!client
->AllocateLogicalAddresses())
667 m_libcec
->AddLog(CEC_LOG_ERROR
, "failed to register the new CEC client - cannot allocate the requested device types");
668 SetAckMask(iPreviousMask
);
672 // register this client on the new addresses
673 CECDEVICEVEC devices
;
674 m_busDevices
->GetByLogicalAddresses(devices
, configuration
.logicalAddresses
);
675 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
677 // replace a previous client
678 CLockObject
lock(m_mutex
);
679 m_clients
.erase((*it
)->GetLogicalAddress());
680 m_clients
.insert(make_pair
<cec_logical_address
, CCECClient
*>((*it
)->GetLogicalAddress(), client
));
683 // get the settings from the rom
684 if (configuration
.bGetSettingsFromROM
== 1)
686 libcec_configuration config
;
687 m_communication
->GetConfiguration(config
);
689 CLockObject
lock(m_mutex
);
690 if (!config
.deviceTypes
.IsEmpty())
691 configuration
.deviceTypes
= config
.deviceTypes
;
692 if (CLibCEC::IsValidPhysicalAddress(config
.iPhysicalAddress
))
693 configuration
.iPhysicalAddress
= config
.iPhysicalAddress
;
694 snprintf(configuration
.strDeviceName
, 13, "%s", config
.strDeviceName
);
697 // set the firmware version and build date
698 configuration
.serverVersion
= LIBCEC_VERSION_CURRENT
;
699 configuration
.iFirmwareVersion
= m_communication
->GetFirmwareVersion();
700 configuration
.iFirmwareBuildDate
= m_communication
->GetFirmwareBuildDate();
702 // mark the client as registered
703 client
->SetRegistered(true);
705 // set the new ack mask
706 bool bReturn
= SetAckMask(GetLogicalAddresses().AckMask()) &&
707 // and initialise the client
708 client
->OnRegister();
710 // log the new registration
712 strLog
.Format("%s: %s", bReturn
? "CEC client registered" : "failed to register the CEC client", client
->GetConnectionInfo().c_str());
713 m_libcec
->AddLog(bReturn
? CEC_LOG_NOTICE
: CEC_LOG_ERROR
, strLog
);
715 // display a warning if the firmware can be upgraded
716 if (bReturn
&& !IsRunningLatestFirmware())
718 const char *strUpgradeMessage
= "The firmware of this adapter can be upgraded. Please visit http://blog.pulse-eight.com/ for more information.";
719 m_libcec
->AddLog(CEC_LOG_WARNING
, strUpgradeMessage
);
720 libcec_parameter param
;
721 param
.paramData
= (void*)strUpgradeMessage
; param
.paramType
= CEC_PARAMETER_TYPE_STRING
;
722 client
->Alert(CEC_ALERT_SERVICE_DEVICE
, param
);
728 void CCECProcessor::UnregisterClient(CCECClient
*client
)
733 if (client
->IsRegistered())
734 m_libcec
->AddLog(CEC_LOG_NOTICE
, "unregistering client: %s", client
->GetConnectionInfo().c_str());
736 // notify the client that it will be unregistered
737 client
->OnUnregister();
740 CLockObject
lock(m_mutex
);
741 // find all devices that match the LA's of this client
742 CECDEVICEVEC devices
;
743 m_busDevices
->GetByLogicalAddresses(devices
, client
->GetConfiguration()->logicalAddresses
);
744 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
747 map
<cec_logical_address
, CCECClient
*>::iterator entry
= m_clients
.find((*it
)->GetLogicalAddress());
748 // unregister the client
749 if (entry
!= m_clients
.end())
750 m_clients
.erase(entry
);
752 // reset the device status
753 (*it
)->ResetDeviceStatus();
757 // set the new ackmask
758 SetAckMask(GetLogicalAddresses().AckMask());
761 void CCECProcessor::UnregisterClients(void)
763 m_libcec
->AddLog(CEC_LOG_NOTICE
, "unregistering all CEC clients");
765 vector
<CCECClient
*> clients
= m_libcec
->GetClients();
766 for (vector
<CCECClient
*>::iterator client
= clients
.begin(); client
!= clients
.end(); client
++)
767 UnregisterClient(*client
);
769 CLockObject
lock(m_mutex
);
773 CCECClient
*CCECProcessor::GetClient(const cec_logical_address address
)
775 CLockObject
lock(m_mutex
);
776 map
<cec_logical_address
, CCECClient
*>::const_iterator client
= m_clients
.find(address
);
777 if (client
!= m_clients
.end())
778 return client
->second
;
782 CCECClient
*CCECProcessor::GetPrimaryClient(void)
784 CLockObject
lock(m_mutex
);
785 map
<cec_logical_address
, CCECClient
*>::const_iterator client
= m_clients
.begin();
786 if (client
!= m_clients
.end())
787 return client
->second
;
791 CCECBusDevice
*CCECProcessor::GetPrimaryDevice(void)
793 return m_busDevices
->At(GetLogicalAddress());
796 cec_logical_address
CCECProcessor::GetLogicalAddress(void)
798 cec_logical_addresses addresses
= GetLogicalAddresses();
799 return addresses
.primary
;
802 cec_logical_addresses
CCECProcessor::GetLogicalAddresses(void)
804 CLockObject
lock(m_mutex
);
805 cec_logical_addresses addresses
;
807 for (map
<cec_logical_address
, CCECClient
*>::const_iterator client
= m_clients
.begin(); client
!= m_clients
.end(); client
++)
808 addresses
.Set(client
->first
);
813 bool CCECProcessor::IsHandledByLibCEC(const cec_logical_address address
) const
815 CCECBusDevice
*device
= GetDevice(address
);
816 return device
&& device
->IsHandledByLibCEC();
819 bool CCECProcessor::IsRunningLatestFirmware(void)
821 return m_communication
&& m_communication
->IsOpen() ?
822 m_communication
->IsRunningLatestFirmware() :