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 "CECTypeUtils.h"
46 #include "platform/util/timeutils.h"
47 #include "platform/util/util.h"
51 using namespace PLATFORM
;
53 #define CEC_PROCESSOR_SIGNAL_WAIT_TIME 1000
54 #define ACTIVE_SOURCE_CHECK_INTERVAL 500
56 #define ToString(x) CCECTypeUtils::ToString(x)
58 CCECProcessor::CCECProcessor(CLibCEC
*libcec
) :
59 m_bInitialised(false),
60 m_communication(NULL
),
62 m_iStandardLineTimeout(3),
63 m_iRetryLineTimeout(3),
64 m_iLastTransmission(0)
66 m_busDevices
= new CCECDeviceMap(this);
69 CCECProcessor::~CCECProcessor(void)
72 DELETE_AND_NULL(m_busDevices
);
75 bool CCECProcessor::Start(const char *strPort
, uint16_t iBaudRate
/* = CEC_SERIAL_DEFAULT_BAUDRATE */, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
77 CLockObject
lock(m_mutex
);
79 if (!OpenConnection(strPort
, iBaudRate
, iTimeoutMs
))
82 // create the processor thread
87 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
95 void CCECProcessor::Close(void)
97 // mark as uninitialised
98 SetCECInitialised(false);
100 // stop the processor
103 // close the connection
104 DELETE_AND_NULL(m_communication
);
107 void CCECProcessor::ResetMembers(void)
109 // close the connection
110 DELETE_AND_NULL(m_communication
);
112 // reset the other members to the initial state
113 m_iStandardLineTimeout
= 3;
114 m_iRetryLineTimeout
= 3;
115 m_iLastTransmission
= 0;
116 m_busDevices
->ResetDeviceStatus();
119 bool CCECProcessor::OpenConnection(const char *strPort
, uint16_t iBaudRate
, uint32_t iTimeoutMs
, bool bStartListening
/* = true */)
122 CTimeout
timeout(iTimeoutMs
> 0 ? iTimeoutMs
: CEC_DEFAULT_TRANSMIT_WAIT
);
124 // ensure that a previous connection is closed
127 // reset all member to the initial state
130 // check whether the Close() method deleted any previous connection
133 m_libcec
->AddLog(CEC_LOG_ERROR
, "previous connection could not be closed");
137 // create a new connection
138 m_communication
= new CUSBCECAdapterCommunication(this, strPort
, iBaudRate
);
140 // open a new connection
141 unsigned iConnectTry(0);
142 while (timeout
.TimeLeft() > 0 && (bReturn
= m_communication
->Open((timeout
.TimeLeft() / CEC_CONNECT_TRIES
), false, bStartListening
)) == false)
144 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
145 m_communication
->Close();
146 CEvent::Sleep(CEC_DEFAULT_CONNECT_RETRY_WAIT
);
149 m_libcec
->AddLog(CEC_LOG_NOTICE
, "connection opened");
151 // mark as initialised
152 SetCECInitialised(true);
157 bool CCECProcessor::CECInitialised(void)
159 CLockObject
lock(m_threadMutex
);
160 return m_bInitialised
;
163 void CCECProcessor::SetCECInitialised(bool bSetTo
/* = true */)
166 CLockObject
lock(m_mutex
);
167 m_bInitialised
= bSetTo
;
173 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
176 CCECBusDevice
*device
= m_busDevices
->At(address
);
179 // check if it's already marked as present or used
180 if (device
->IsPresent() || device
->IsHandledByLibCEC())
183 // poll the LA if not
185 return device
->TryLogicalAddress();
191 void CCECProcessor::ReplaceHandlers(void)
193 if (!CECInitialised())
197 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
198 it
->second
->ReplaceHandler(true);
201 bool CCECProcessor::OnCommandReceived(const cec_command
&command
)
203 return m_inBuffer
.Push(command
);
206 void *CCECProcessor::Process(void)
208 m_libcec
->AddLog(CEC_LOG_DEBUG
, "processor thread started");
210 cec_command command
; command
.Clear();
211 CTimeout
activeSourceCheck(ACTIVE_SOURCE_CHECK_INTERVAL
);
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
228 // check whether we need to activate a source, if it failed before
229 if (activeSourceCheck
.TimeLeft() == 0)
231 if (CECInitialised())
232 TransmitPendingActiveSourceCommands();
233 activeSourceCheck
.Init(ACTIVE_SOURCE_CHECK_INTERVAL
);
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::PollDevice(cec_logical_address iAddress
)
307 // try to find the primary device
308 CCECBusDevice
*primary
= GetPrimaryDevice();
309 // poll the destination, with the primary as source
311 return primary
->TransmitPoll(iAddress
);
313 // try to find the destination
314 CCECBusDevice
*device
= m_busDevices
->At(iAddress
);
315 // and poll the destination, with the same LA as source
317 return device
->TransmitPoll(iAddress
);
322 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bSuppressUpdate
/* = true */)
324 return m_busDevices
?
325 m_busDevices
->GetDeviceByPhysicalAddress(iPhysicalAddress
, bSuppressUpdate
) :
329 CCECBusDevice
*CCECProcessor::GetDevice(cec_logical_address address
) const
331 return m_busDevices
?
332 m_busDevices
->At(address
) :
336 cec_logical_address
CCECProcessor::GetActiveSource(bool bRequestActiveSource
/* = true */)
338 // get the device that is marked as active source from the device map
339 CCECBusDevice
*activeSource
= m_busDevices
->GetActiveSource();
341 return activeSource
->GetLogicalAddress();
343 if (bRequestActiveSource
)
345 // request the active source from the bus
346 CCECBusDevice
*primary
= GetPrimaryDevice();
349 primary
->RequestActiveSource();
350 return GetActiveSource(false);
355 return CECDEVICE_UNKNOWN
;
358 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
360 CCECBusDevice
*device
= m_busDevices
->At(iAddress
);
361 return device
&& device
->IsActiveSource();
364 bool CCECProcessor::Transmit(const cec_command
&data
)
366 uint8_t iMaxTries(0);
370 // get the current timeout setting
371 uint8_t iLineTimeout(GetStandardLineTimeout());
373 // reset the state of this message to 'unknown'
374 cec_adapter_message_state adapterState
= ADAPTER_MESSAGE_STATE_UNKNOWN
;
378 // find the initiator device
379 CCECBusDevice
*initiator
= m_busDevices
->At(data
.initiator
);
382 m_libcec
->AddLog(CEC_LOG_WARNING
, "invalid initiator");
386 // find the destination device, if it's not the broadcast address
387 if (data
.destination
!= CECDEVICE_BROADCAST
)
389 // check if the device is marked as handled by libCEC
390 CCECBusDevice
*destination
= m_busDevices
->At(data
.destination
);
391 if (destination
&& destination
->IsHandledByLibCEC())
393 // and reject the command if it's trying to send data to a device that is handled by libCEC
394 m_libcec
->AddLog(CEC_LOG_WARNING
, "not sending data to myself!");
400 CLockObject
lock(m_mutex
);
401 m_iLastTransmission
= GetTimeMs();
402 // set the number of tries
403 iMaxTries
= initiator
->GetHandler()->GetTransmitRetries() + 1;
404 initiator
->MarkHandlerReady();
407 // and try to send the command
408 while (bRetry
&& ++iTries
< iMaxTries
)
410 if (initiator
->IsUnsupportedFeature(data
.opcode
))
413 adapterState
= !IsStopped() && m_communication
&& m_communication
->IsOpen() ?
414 m_communication
->Write(data
, bRetry
, iLineTimeout
) :
415 ADAPTER_MESSAGE_STATE_ERROR
;
416 iLineTimeout
= m_iRetryLineTimeout
;
419 return adapterState
== ADAPTER_MESSAGE_STATE_SENT_ACKED
;
422 void CCECProcessor::TransmitAbort(cec_logical_address source
, cec_logical_address destination
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
424 m_libcec
->AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
427 cec_command::Format(command
, source
, destination
, CEC_OPCODE_FEATURE_ABORT
);
428 command
.parameters
.PushBack((uint8_t)opcode
);
429 command
.parameters
.PushBack((uint8_t)reason
);
434 void CCECProcessor::ProcessCommand(const cec_command
&command
)
438 dataStr
.Format(">> %1x%1x", command
.initiator
, command
.destination
);
439 if (command
.opcode_set
== 1)
440 dataStr
.AppendFormat(":%02x", command
.opcode
);
441 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
442 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
443 m_libcec
->AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
445 // find the initiator
446 CCECBusDevice
*device
= m_busDevices
->At(command
.initiator
);
449 device
->HandleCommand(command
);
452 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
454 CCECBusDevice
*device
= m_busDevices
->At(address
);
455 return device
&& device
->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
458 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
460 CECDEVICEVEC devices
;
461 m_busDevices
->GetByType(type
, devices
);
462 CCECDeviceMap::FilterActive(devices
);
463 return !devices
.empty();
466 uint16_t CCECProcessor::GetDetectedPhysicalAddress(void) const
468 return m_communication
? m_communication
->GetPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS
;
471 bool CCECProcessor::SetAckMask(uint16_t iMask
)
473 return m_communication
? m_communication
->SetAckMask(iMask
) : false;
476 bool CCECProcessor::StandbyDevices(const cec_logical_address initiator
, const CECDEVICEVEC
&devices
)
479 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
480 bReturn
&= (*it
)->Standby(initiator
);
484 bool CCECProcessor::StandbyDevice(const cec_logical_address initiator
, cec_logical_address address
)
486 CCECBusDevice
*device
= m_busDevices
->At(address
);
487 return device
? device
->Standby(initiator
) : false;
490 bool CCECProcessor::PowerOnDevices(const cec_logical_address initiator
, const CECDEVICEVEC
&devices
)
493 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
494 bReturn
&= (*it
)->PowerOn(initiator
);
498 bool CCECProcessor::PowerOnDevice(const cec_logical_address initiator
, cec_logical_address address
)
500 CCECBusDevice
*device
= m_busDevices
->At(address
);
501 return device
? device
->PowerOn(initiator
) : false;
504 bool CCECProcessor::StartBootloader(const char *strPort
/* = NULL */)
507 // open a connection if no connection has been opened
508 if (!m_communication
&& strPort
)
510 IAdapterCommunication
*comm
= new CUSBCECAdapterCommunication(this, strPort
);
511 CTimeout
timeout(CEC_DEFAULT_CONNECT_TIMEOUT
);
513 while (timeout
.TimeLeft() > 0 && (bReturn
= comm
->Open(timeout
.TimeLeft() / CEC_CONNECT_TRIES
, true)) == false)
515 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
517 Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT
);
521 bReturn
= comm
->StartBootloader();
522 DELETE_AND_NULL(comm
);
528 m_communication
->StartBootloader();
536 bool CCECProcessor::PingAdapter(void)
538 return m_communication
->PingAdapter();
541 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
543 CCECBusDevice
*device
= m_busDevices
->At(destination
);
545 device
->HandlePollFrom(initiator
);
548 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator
)
550 CCECBusDevice
*device
= m_busDevices
->At(initiator
);
551 return !device
|| !device
->HandleReceiveFailed();
554 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress
)
556 // stream path changes are sent by the TV
557 bool bReturn
= GetTV()->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
);
558 GetTV()->MarkHandlerReady();
562 bool CCECProcessor::CanPersistConfiguration(void)
564 return m_communication
? m_communication
->GetFirmwareVersion() >= 2 : false;
567 bool CCECProcessor::PersistConfiguration(const libcec_configuration
&configuration
)
569 return m_communication
? m_communication
->PersistConfiguration(configuration
) : false;
572 void CCECProcessor::RescanActiveDevices(void)
574 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
575 it
->second
->GetStatus(true);
578 bool CCECProcessor::GetDeviceInformation(const char *strPort
, libcec_configuration
*config
, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
580 if (!OpenConnection(strPort
, CEC_SERIAL_DEFAULT_BAUDRATE
, iTimeoutMs
, false))
583 config
->iFirmwareVersion
= m_communication
->GetFirmwareVersion();
584 config
->iPhysicalAddress
= m_communication
->GetPhysicalAddress();
585 config
->iFirmwareBuildDate
= m_communication
->GetFirmwareBuildDate();
590 bool CCECProcessor::TransmitPendingActiveSourceCommands(void)
593 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
594 bReturn
&= it
->second
->TransmitPendingActiveSourceCommands();
598 CCECTV
*CCECProcessor::GetTV(void) const
600 return CCECBusDevice::AsTV(m_busDevices
->At(CECDEVICE_TV
));
603 CCECAudioSystem
*CCECProcessor::GetAudioSystem(void) const
605 return CCECBusDevice::AsAudioSystem(m_busDevices
->At(CECDEVICE_AUDIOSYSTEM
));
608 CCECPlaybackDevice
*CCECProcessor::GetPlaybackDevice(cec_logical_address address
) const
610 return CCECBusDevice::AsPlaybackDevice(m_busDevices
->At(address
));
613 CCECRecordingDevice
*CCECProcessor::GetRecordingDevice(cec_logical_address address
) const
615 return CCECBusDevice::AsRecordingDevice(m_busDevices
->At(address
));
618 CCECTuner
*CCECProcessor::GetTuner(cec_logical_address address
) const
620 return CCECBusDevice::AsTuner(m_busDevices
->At(address
));
623 bool CCECProcessor::RegisterClient(CCECClient
*client
)
628 libcec_configuration
&configuration
= *client
->GetConfiguration();
630 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_6_3
&& configuration
.bMonitorOnly
== 1)
633 if (!CECInitialised())
635 m_libcec
->AddLog(CEC_LOG_ERROR
, "failed to register a new CEC client: CEC processor is not initialised");
639 // ensure that we know the vendor id of the TV
640 GetTV()->GetVendorId(CECDEVICE_UNREGISTERED
);
642 // unregister the client first if it's already been marked as registered
643 if (client
->IsRegistered())
644 UnregisterClient(client
);
646 // get the configuration from the client
647 m_libcec
->AddLog(CEC_LOG_NOTICE
, "registering new CEC client - v%s", ToString((cec_client_version
)configuration
.clientVersion
));
649 // mark as uninitialised and unregistered
650 client
->SetRegistered(false);
651 client
->SetInitialised(false);
653 // get the current ackmask, so we can restore it if polling fails
654 uint16_t iPreviousMask(m_communication
->GetAckMask());
656 // find logical addresses for this client
657 if (!client
->AllocateLogicalAddresses())
659 m_libcec
->AddLog(CEC_LOG_ERROR
, "failed to register the new CEC client - cannot allocate the requested device types");
660 SetAckMask(iPreviousMask
);
664 // register this client on the new addresses
665 CECDEVICEVEC devices
;
666 m_busDevices
->GetByLogicalAddresses(devices
, configuration
.logicalAddresses
);
667 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
669 // set the physical address of the device at this LA
670 if (CLibCEC::IsValidPhysicalAddress(configuration
.iPhysicalAddress
))
671 (*it
)->SetPhysicalAddress(configuration
.iPhysicalAddress
);
673 // replace a previous client
674 CLockObject
lock(m_mutex
);
675 m_clients
.erase((*it
)->GetLogicalAddress());
676 m_clients
.insert(make_pair
<cec_logical_address
, CCECClient
*>((*it
)->GetLogicalAddress(), client
));
679 // get the settings from the rom
680 if (configuration
.bGetSettingsFromROM
== 1)
682 libcec_configuration config
; config
.Clear();
683 m_communication
->GetConfiguration(config
);
685 CLockObject
lock(m_mutex
);
686 if (!config
.deviceTypes
.IsEmpty())
687 configuration
.deviceTypes
= config
.deviceTypes
;
688 if (CLibCEC::IsValidPhysicalAddress(config
.iPhysicalAddress
))
689 configuration
.iPhysicalAddress
= config
.iPhysicalAddress
;
690 snprintf(configuration
.strDeviceName
, 13, "%s", config
.strDeviceName
);
693 // set the firmware version and build date
694 configuration
.serverVersion
= LIBCEC_VERSION_CURRENT
;
695 configuration
.iFirmwareVersion
= m_communication
->GetFirmwareVersion();
696 configuration
.iFirmwareBuildDate
= m_communication
->GetFirmwareBuildDate();
698 // mark the client as registered
699 client
->SetRegistered(true);
701 // set the new ack mask
702 bool bReturn
= SetAckMask(GetLogicalAddresses().AckMask()) &&
703 // and initialise the client
704 client
->OnRegister();
706 // log the new registration
708 strLog
.Format("%s: %s", bReturn
? "CEC client registered" : "failed to register the CEC client", client
->GetConnectionInfo().c_str());
709 m_libcec
->AddLog(bReturn
? CEC_LOG_NOTICE
: CEC_LOG_ERROR
, strLog
);
711 // display a warning if the firmware can be upgraded
712 if (bReturn
&& !IsRunningLatestFirmware())
714 const char *strUpgradeMessage
= "The firmware of this adapter can be upgraded. Please visit http://blog.pulse-eight.com/ for more information.";
715 m_libcec
->AddLog(CEC_LOG_WARNING
, strUpgradeMessage
);
716 libcec_parameter param
;
717 param
.paramData
= (void*)strUpgradeMessage
; param
.paramType
= CEC_PARAMETER_TYPE_STRING
;
718 client
->Alert(CEC_ALERT_SERVICE_DEVICE
, param
);
721 // ensure that the command handler for the TV is initialised
724 CCECCommandHandler
*handler
= GetTV()->GetHandler();
726 handler
->InitHandler();
727 GetTV()->MarkHandlerReady();
733 bool CCECProcessor::UnregisterClient(CCECClient
*client
)
738 if (client
->IsRegistered())
739 m_libcec
->AddLog(CEC_LOG_NOTICE
, "unregistering client: %s", client
->GetConnectionInfo().c_str());
741 // notify the client that it will be unregistered
742 client
->OnUnregister();
745 CLockObject
lock(m_mutex
);
746 // find all devices that match the LA's of this client
747 CECDEVICEVEC devices
;
748 m_busDevices
->GetByLogicalAddresses(devices
, client
->GetConfiguration()->logicalAddresses
);
749 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
752 map
<cec_logical_address
, CCECClient
*>::iterator entry
= m_clients
.find((*it
)->GetLogicalAddress());
753 // unregister the client
754 if (entry
!= m_clients
.end())
755 m_clients
.erase(entry
);
757 // reset the device status
758 (*it
)->ResetDeviceStatus();
762 // set the new ackmask
763 return SetAckMask(GetLogicalAddresses().AckMask());
766 void CCECProcessor::UnregisterClients(void)
768 m_libcec
->AddLog(CEC_LOG_NOTICE
, "unregistering all CEC clients");
770 vector
<CCECClient
*> clients
= m_libcec
->GetClients();
771 for (vector
<CCECClient
*>::iterator client
= clients
.begin(); client
!= clients
.end(); client
++)
772 UnregisterClient(*client
);
774 CLockObject
lock(m_mutex
);
778 CCECClient
*CCECProcessor::GetClient(const cec_logical_address address
)
780 CLockObject
lock(m_mutex
);
781 map
<cec_logical_address
, CCECClient
*>::const_iterator client
= m_clients
.find(address
);
782 if (client
!= m_clients
.end())
783 return client
->second
;
787 CCECClient
*CCECProcessor::GetPrimaryClient(void)
789 CLockObject
lock(m_mutex
);
790 map
<cec_logical_address
, CCECClient
*>::const_iterator client
= m_clients
.begin();
791 if (client
!= m_clients
.end())
792 return client
->second
;
796 CCECBusDevice
*CCECProcessor::GetPrimaryDevice(void)
798 return m_busDevices
->At(GetLogicalAddress());
801 cec_logical_address
CCECProcessor::GetLogicalAddress(void)
803 cec_logical_addresses addresses
= GetLogicalAddresses();
804 return addresses
.primary
;
807 cec_logical_addresses
CCECProcessor::GetLogicalAddresses(void)
809 CLockObject
lock(m_mutex
);
810 cec_logical_addresses addresses
;
812 for (map
<cec_logical_address
, CCECClient
*>::const_iterator client
= m_clients
.begin(); client
!= m_clients
.end(); client
++)
813 addresses
.Set(client
->first
);
818 bool CCECProcessor::IsHandledByLibCEC(const cec_logical_address address
) const
820 CCECBusDevice
*device
= GetDevice(address
);
821 return device
&& device
->IsHandledByLibCEC();
824 bool CCECProcessor::IsRunningLatestFirmware(void)
826 return m_communication
&& m_communication
->IsOpen() ?
827 m_communication
->IsRunningLatestFirmware() :