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
85 m_libcec
->AddLog(CEC_LOG_DEBUG
, "processor thread started");
88 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
93 // mark as initialised
94 SetCECInitialised(true);
99 void CCECProcessor::Close(void)
101 // mark as uninitialised
102 SetCECInitialised(false);
104 // stop the processor
107 // close the connection
110 delete m_communication
;
111 m_communication
= NULL
;
115 void CCECProcessor::ResetMembers(void)
117 // close the connection
120 delete m_communication
;
121 m_communication
= NULL
;
124 // reset the other members to the initial state
126 m_iPreviousAckMask
= 0;
127 m_iStandardLineTimeout
= 3;
128 m_iRetryLineTimeout
= 3;
129 m_iLastTransmission
= 0;
130 m_busDevices
->ResetDeviceStatus();
133 bool CCECProcessor::OpenConnection(const char *strPort
, uint16_t iBaudRate
, uint32_t iTimeoutMs
, bool bStartListening
/* = true */)
136 CTimeout
timeout(iTimeoutMs
> 0 ? iTimeoutMs
: CEC_DEFAULT_TRANSMIT_WAIT
);
138 // ensure that a previous connection is closed
141 // reset all member to the initial state
144 // check whether the Close() method deleted any previous connection
147 m_libcec
->AddLog(CEC_LOG_ERROR
, "previous connection could not be closed");
151 // create a new connection
152 m_communication
= new CUSBCECAdapterCommunication(this, strPort
, iBaudRate
);
154 // open a new connection
155 unsigned iConnectTry(0);
156 while (timeout
.TimeLeft() > 0 && (bReturn
= m_communication
->Open((timeout
.TimeLeft() / CEC_CONNECT_TRIES
), false, bStartListening
)) == false)
158 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
159 m_communication
->Close();
160 CEvent::Sleep(CEC_DEFAULT_CONNECT_RETRY_WAIT
);
163 m_libcec
->AddLog(CEC_LOG_NOTICE
, "connection opened");
168 bool CCECProcessor::CECInitialised(void)
170 CLockObject
lock(m_threadMutex
);
171 return m_bInitialised
;
174 void CCECProcessor::SetCECInitialised(bool bSetTo
/* = true */)
177 CLockObject
lock(m_mutex
);
178 m_bInitialised
= bSetTo
;
184 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
187 CCECBusDevice
*device
= m_busDevices
->At(address
);
190 // check if it's already marked as present or used
191 if (device
->IsPresent() || device
->IsHandledByLibCEC())
194 // poll the LA if not
196 return device
->TryLogicalAddress();
202 void CCECProcessor::ReplaceHandlers(void)
204 if (!CECInitialised())
208 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
209 it
->second
->ReplaceHandler(true);
212 bool CCECProcessor::OnCommandReceived(const cec_command
&command
)
214 return m_inBuffer
.Push(command
);
217 void *CCECProcessor::Process(void)
219 m_libcec
->AddLog(CEC_LOG_DEBUG
, "processor thread started");
223 // as long as we're not being stopped and the connection is open
224 while (!IsStopped() && m_communication
->IsOpen())
226 // wait for a new incoming command, and process it
227 if (m_inBuffer
.Pop(command
, CEC_PROCESSOR_SIGNAL_WAIT_TIME
))
228 ProcessCommand(command
);
230 if (CECInitialised())
232 // check clients for keypress timeouts
233 m_libcec
->CheckKeypressTimeout();
235 // check if we need to replace handlers
243 bool CCECProcessor::ActivateSource(uint16_t iStreamPath
)
247 // find the device with the given PA
248 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
249 // and make it the active source when found
251 bReturn
= device
->ActivateSource();
253 m_libcec
->AddLog(CEC_LOG_DEBUG
, "device with PA '%04x' not found", iStreamPath
);
258 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout
)
260 CLockObject
lock(m_mutex
);
261 m_iStandardLineTimeout
= iTimeout
;
264 uint8_t CCECProcessor::GetStandardLineTimeout(void)
266 CLockObject
lock(m_mutex
);
267 return m_iStandardLineTimeout
;
270 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout
)
272 CLockObject
lock(m_mutex
);
273 m_iRetryLineTimeout
= iTimeout
;
276 uint8_t CCECProcessor::GetRetryLineTimeout(void)
278 CLockObject
lock(m_mutex
);
279 return m_iRetryLineTimeout
;
282 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress
)
284 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iPhysicalAddress
);
285 return device
!= NULL
;
288 void CCECProcessor::LogOutput(const cec_command
&data
)
292 // initiator and destination
293 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
297 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
299 // append the parameters
300 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
301 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
304 m_libcec
->AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
307 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
309 m_libcec
->AddLog(CEC_LOG_NOTICE
, "== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
312 CLockObject
lock(m_mutex
);
313 // switch to monitoring mode, which will stop processing of incoming messages
314 m_bMonitor
= bEnable
;
315 // and store the current ackmask
316 m_iPreviousAckMask
= m_communication
->GetAckMask();
319 // set the mask to 0 when enabling monitor mode
321 return SetAckMask(0);
322 // and restore the previous mask otherwise
324 return SetAckMask(m_iPreviousAckMask
);
327 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
329 // try to find the primary device
330 CCECBusDevice
*primary
= GetPrimaryDevice();
331 // poll the destination, with the primary as source
333 return primary
->TransmitPoll(iAddress
);
335 // try to find the destination
336 CCECBusDevice
*device
= m_busDevices
->At(iAddress
);
337 // and poll the destination, with the same LA as source
339 return device
->TransmitPoll(iAddress
);
344 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bSuppressUpdate
/* = true */)
346 return m_busDevices
?
347 m_busDevices
->GetDeviceByPhysicalAddress(iPhysicalAddress
, bSuppressUpdate
) :
351 CCECBusDevice
*CCECProcessor::GetDevice(cec_logical_address address
) const
353 return m_busDevices
?
354 m_busDevices
->At(address
) :
358 cec_logical_address
CCECProcessor::GetActiveSource(bool bRequestActiveSource
/* = true */)
360 // get the device that is marked as active source from the device map
361 CCECBusDevice
*activeSource
= m_busDevices
->GetActiveSource();
363 return activeSource
->GetLogicalAddress();
365 if (bRequestActiveSource
)
367 // request the active source from the bus
368 CCECBusDevice
*primary
= GetPrimaryDevice();
371 primary
->RequestActiveSource();
372 return GetActiveSource(false);
377 return CECDEVICE_UNKNOWN
;
380 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
382 CCECBusDevice
*device
= m_busDevices
->At(iAddress
);
383 return device
&& device
->IsActiveSource();
386 bool CCECProcessor::Transmit(const cec_command
&data
)
388 uint8_t iMaxTries(0);
392 // get the current timeout setting
393 uint8_t iLineTimeout(GetStandardLineTimeout());
395 // reset the state of this message to 'unknown'
396 cec_adapter_message_state adapterState
= ADAPTER_MESSAGE_STATE_UNKNOWN
;
400 // find the initiator device
401 CCECBusDevice
*initiator
= m_busDevices
->At(data
.initiator
);
404 m_libcec
->AddLog(CEC_LOG_WARNING
, "invalid initiator");
408 // find the destination device, if it's not the broadcast address
409 if (data
.destination
!= CECDEVICE_BROADCAST
)
411 // check if the device is marked as handled by libCEC
412 CCECBusDevice
*destination
= m_busDevices
->At(data
.destination
);
413 if (destination
&& destination
->IsHandledByLibCEC())
415 // and reject the command if it's trying to send data to a device that is handled by libCEC
416 m_libcec
->AddLog(CEC_LOG_WARNING
, "not sending data to myself!");
422 CLockObject
lock(m_mutex
);
423 m_iLastTransmission
= GetTimeMs();
424 // set the number of tries
425 iMaxTries
= initiator
->GetHandler()->GetTransmitRetries() + 1;
428 // and try to send the command
429 while (bRetry
&& ++iTries
< iMaxTries
)
431 if (initiator
->IsUnsupportedFeature(data
.opcode
))
434 adapterState
= !IsStopped() && m_communication
&& m_communication
->IsOpen() ?
435 m_communication
->Write(data
, bRetry
, iLineTimeout
) :
436 ADAPTER_MESSAGE_STATE_ERROR
;
437 iLineTimeout
= m_iRetryLineTimeout
;
440 return adapterState
== ADAPTER_MESSAGE_STATE_SENT_ACKED
;
443 void CCECProcessor::TransmitAbort(cec_logical_address source
, cec_logical_address destination
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
445 m_libcec
->AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
448 cec_command::Format(command
, source
, destination
, CEC_OPCODE_FEATURE_ABORT
);
449 command
.parameters
.PushBack((uint8_t)opcode
);
450 command
.parameters
.PushBack((uint8_t)reason
);
455 void CCECProcessor::ProcessCommand(const cec_command
&command
)
459 dataStr
.Format(">> %1x%1x", command
.initiator
, command
.destination
);
460 if (command
.opcode_set
== 1)
461 dataStr
.AppendFormat(":%02x", command
.opcode
);
462 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
463 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
464 m_libcec
->AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
466 // if we're not in monitor mode
469 // find the initiator
470 CCECBusDevice
*device
= m_busDevices
->At(command
.initiator
);
471 // and "handle" the command
473 device
->HandleCommand(command
);
477 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
479 CCECBusDevice
*device
= m_busDevices
->At(address
);
480 return device
&& device
->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
483 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
485 CECDEVICEVEC devices
;
486 m_busDevices
->GetByType(type
, devices
);
487 CCECDeviceMap::FilterActive(devices
);
488 return !devices
.empty();
491 uint16_t CCECProcessor::GetDetectedPhysicalAddress(void) const
493 return m_communication
? m_communication
->GetPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS
;
496 bool CCECProcessor::SetAckMask(uint16_t iMask
)
498 return m_communication
? m_communication
->SetAckMask(iMask
) : false;
501 bool CCECProcessor::StandbyDevices(const cec_logical_address initiator
, const CECDEVICEVEC
&devices
)
504 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
505 bReturn
&= (*it
)->Standby(initiator
);
509 bool CCECProcessor::StandbyDevice(const cec_logical_address initiator
, cec_logical_address address
)
511 CCECBusDevice
*device
= m_busDevices
->At(address
);
512 return device
? device
->Standby(initiator
) : false;
515 bool CCECProcessor::PowerOnDevices(const cec_logical_address initiator
, const CECDEVICEVEC
&devices
)
518 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
519 bReturn
&= (*it
)->PowerOn(initiator
);
523 bool CCECProcessor::PowerOnDevice(const cec_logical_address initiator
, cec_logical_address address
)
525 CCECBusDevice
*device
= m_busDevices
->At(address
);
526 return device
? device
->PowerOn(initiator
) : false;
529 bool CCECProcessor::StartBootloader(const char *strPort
/* = NULL */)
532 // open a connection if no connection has been opened
533 if (!m_communication
&& strPort
)
535 IAdapterCommunication
*comm
= new CUSBCECAdapterCommunication(this, strPort
);
536 CTimeout
timeout(CEC_DEFAULT_CONNECT_TIMEOUT
);
538 while (timeout
.TimeLeft() > 0 && (bReturn
= comm
->Open(timeout
.TimeLeft() / CEC_CONNECT_TRIES
, true)) == false)
540 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
542 Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT
);
546 bReturn
= comm
->StartBootloader();
553 m_communication
->StartBootloader();
561 bool CCECProcessor::PingAdapter(void)
563 return m_communication
->PingAdapter();
566 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
568 CCECBusDevice
*device
= m_busDevices
->At(destination
);
570 device
->HandlePollFrom(initiator
);
573 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator
)
575 CCECBusDevice
*device
= m_busDevices
->At(initiator
);
576 return !device
|| !device
->HandleReceiveFailed();
579 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress
)
581 // stream path changes are sent by the TV
582 return GetTV()->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
);
585 bool CCECProcessor::CanPersistConfiguration(void)
587 return m_communication
? m_communication
->GetFirmwareVersion() >= 2 : false;
590 bool CCECProcessor::PersistConfiguration(const libcec_configuration
&configuration
)
592 return m_communication
? m_communication
->PersistConfiguration(configuration
) : false;
595 void CCECProcessor::RescanActiveDevices(void)
597 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
598 it
->second
->GetStatus(true);
601 bool CCECProcessor::GetDeviceInformation(const char *strPort
, libcec_configuration
*config
, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
603 if (!OpenConnection(strPort
, CEC_SERIAL_DEFAULT_BAUDRATE
, iTimeoutMs
, false))
606 config
->iFirmwareVersion
= m_communication
->GetFirmwareVersion();
607 config
->iPhysicalAddress
= m_communication
->GetPhysicalAddress();
608 config
->iFirmwareBuildDate
= m_communication
->GetFirmwareBuildDate();
613 bool CCECProcessor::TransmitPendingActiveSourceCommands(void)
616 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
617 bReturn
&= it
->second
->TransmitPendingActiveSourceCommands();
621 CCECTV
*CCECProcessor::GetTV(void) const
623 return CCECBusDevice::AsTV(m_busDevices
->At(CECDEVICE_TV
));
626 CCECAudioSystem
*CCECProcessor::GetAudioSystem(void) const
628 return CCECBusDevice::AsAudioSystem(m_busDevices
->At(CECDEVICE_AUDIOSYSTEM
));
631 CCECPlaybackDevice
*CCECProcessor::GetPlaybackDevice(cec_logical_address address
) const
633 return CCECBusDevice::AsPlaybackDevice(m_busDevices
->At(address
));
636 CCECRecordingDevice
*CCECProcessor::GetRecordingDevice(cec_logical_address address
) const
638 return CCECBusDevice::AsRecordingDevice(m_busDevices
->At(address
));
641 CCECTuner
*CCECProcessor::GetTuner(cec_logical_address address
) const
643 return CCECBusDevice::AsTuner(m_busDevices
->At(address
));
646 bool CCECProcessor::RegisterClient(CCECClient
*client
)
651 // unregister the client first if it's already been marked as registered
652 if (client
->IsRegistered())
653 UnregisterClient(client
);
655 // get the configuration from the client
656 libcec_configuration
&configuration
= *client
->GetConfiguration();
657 m_libcec
->AddLog(CEC_LOG_NOTICE
, "registering new CEC client - v%s", ToString((cec_client_version
)configuration
.clientVersion
));
659 // mark as uninitialised and unregistered
660 client
->SetRegistered(false);
661 client
->SetInitialised(false);
663 // get the current ackmask, so we can restore it if polling fails
664 uint16_t iPreviousMask(m_communication
->GetAckMask());
666 // find logical addresses for this client
667 if (!client
->AllocateLogicalAddresses())
669 m_libcec
->AddLog(CEC_LOG_ERROR
, "failed to register the new CEC client - cannot allocate the requested device types");
670 SetAckMask(iPreviousMask
);
674 // register this client on the new addresses
675 CECDEVICEVEC devices
;
676 m_busDevices
->GetByLogicalAddresses(devices
, configuration
.logicalAddresses
);
677 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
679 // replace a previous client
680 CLockObject
lock(m_mutex
);
681 m_clients
.erase((*it
)->GetLogicalAddress());
682 m_clients
.insert(make_pair
<cec_logical_address
, CCECClient
*>((*it
)->GetLogicalAddress(), client
));
685 // get the settings from the rom
686 if (configuration
.bGetSettingsFromROM
== 1)
688 libcec_configuration config
;
689 m_communication
->GetConfiguration(config
);
691 CLockObject
lock(m_mutex
);
692 if (!config
.deviceTypes
.IsEmpty())
693 configuration
.deviceTypes
= config
.deviceTypes
;
694 if (CLibCEC::IsValidPhysicalAddress(config
.iPhysicalAddress
))
695 configuration
.iPhysicalAddress
= config
.iPhysicalAddress
;
696 snprintf(configuration
.strDeviceName
, 13, "%s", config
.strDeviceName
);
699 // set the firmware version and build date
700 configuration
.serverVersion
= LIBCEC_VERSION_CURRENT
;
701 configuration
.iFirmwareVersion
= m_communication
->GetFirmwareVersion();
702 configuration
.iFirmwareBuildDate
= m_communication
->GetFirmwareBuildDate();
704 // mark the client as registered
705 client
->SetRegistered(true);
707 // set the new ack mask
708 bool bReturn
= SetAckMask(GetLogicalAddresses().AckMask()) &&
709 // and initialise the client
710 client
->OnRegister();
712 // log the new registration
714 strLog
.Format("%s: %s", bReturn
? "CEC client registered" : "failed to register the CEC client", client
->GetConnectionInfo().c_str());
715 m_libcec
->AddLog(bReturn
? CEC_LOG_NOTICE
: CEC_LOG_ERROR
, strLog
);
717 // display a warning if the firmware can be upgraded
718 if (bReturn
&& !IsRunningLatestFirmware())
720 const char *strUpgradeMessage
= "The firmware of this adapter can be upgraded. Please visit http://blog.pulse-eight.com/ for more information.";
721 m_libcec
->AddLog(CEC_LOG_WARNING
, strUpgradeMessage
);
722 libcec_parameter param
;
723 param
.paramData
= (void*)strUpgradeMessage
; param
.paramType
= CEC_PARAMETER_TYPE_STRING
;
724 client
->Alert(CEC_ALERT_SERVICE_DEVICE
, param
);
730 void CCECProcessor::UnregisterClient(CCECClient
*client
)
735 m_libcec
->AddLog(CEC_LOG_NOTICE
, "unregistering client: %s", client
->GetConnectionInfo().c_str());
737 // notify the client that it will be unregistered
738 client
->OnUnregister();
741 CLockObject
lock(m_mutex
);
742 // find all devices that match the LA's of this client
743 CECDEVICEVEC devices
;
744 m_busDevices
->GetByLogicalAddresses(devices
, client
->GetConfiguration()->logicalAddresses
);
745 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
748 map
<cec_logical_address
, CCECClient
*>::iterator entry
= m_clients
.find((*it
)->GetLogicalAddress());
749 // unregister the client
750 if (entry
!= m_clients
.end())
751 m_clients
.erase(entry
);
753 // reset the device status
754 (*it
)->ResetDeviceStatus();
758 // set the new ackmask
759 SetAckMask(GetLogicalAddresses().AckMask());
762 void CCECProcessor::UnregisterClients(void)
764 m_libcec
->AddLog(CEC_LOG_NOTICE
, "unregistering all CEC clients");
766 vector
<CCECClient
*> clients
= m_libcec
->GetClients();
767 for (vector
<CCECClient
*>::iterator client
= clients
.begin(); client
!= clients
.end(); client
++)
768 UnregisterClient(*client
);
770 CLockObject
lock(m_mutex
);
774 CCECClient
*CCECProcessor::GetClient(const cec_logical_address address
)
776 CLockObject
lock(m_mutex
);
777 map
<cec_logical_address
, CCECClient
*>::const_iterator client
= m_clients
.find(address
);
778 if (client
!= m_clients
.end())
779 return client
->second
;
783 CCECClient
*CCECProcessor::GetPrimaryClient(void)
785 CLockObject
lock(m_mutex
);
786 map
<cec_logical_address
, CCECClient
*>::const_iterator client
= m_clients
.begin();
787 if (client
!= m_clients
.end())
788 return client
->second
;
792 CCECBusDevice
*CCECProcessor::GetPrimaryDevice(void)
794 return m_busDevices
->At(GetLogicalAddress());
797 cec_logical_address
CCECProcessor::GetLogicalAddress(void)
799 cec_logical_addresses addresses
= GetLogicalAddresses();
800 return addresses
.primary
;
803 cec_logical_addresses
CCECProcessor::GetLogicalAddresses(void)
805 CLockObject
lock(m_mutex
);
806 cec_logical_addresses addresses
;
808 for (map
<cec_logical_address
, CCECClient
*>::const_iterator client
= m_clients
.begin(); client
!= m_clients
.end(); client
++)
809 addresses
.Set(client
->first
);
814 bool CCECProcessor::IsHandledByLibCEC(const cec_logical_address address
) const
816 CCECBusDevice
*device
= GetDevice(address
);
817 return device
&& device
->IsHandledByLibCEC();
820 bool CCECProcessor::IsRunningLatestFirmware(void)
822 return m_communication
&& m_communication
->IsOpen() ?
823 m_communication
->IsRunningLatestFirmware() :