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_TIMEOUT 10000
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 // always start by setting the ackmask to 0, to clear previous values
154 // mark as initialised
155 SetCECInitialised(true);
160 bool CCECProcessor::CECInitialised(void)
162 CLockObject
lock(m_threadMutex
);
163 return m_bInitialised
;
166 void CCECProcessor::SetCECInitialised(bool bSetTo
/* = true */)
169 CLockObject
lock(m_mutex
);
170 m_bInitialised
= bSetTo
;
176 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
179 CCECBusDevice
*device
= m_busDevices
->At(address
);
182 // check if it's already marked as present or used
183 if (device
->IsPresent() || device
->IsHandledByLibCEC())
186 // poll the LA if not
188 return device
->TryLogicalAddress();
194 void CCECProcessor::ReplaceHandlers(void)
196 if (!CECInitialised())
200 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
201 it
->second
->ReplaceHandler(true);
204 void CCECProcessor::CheckPendingActiveSource(void)
206 if (!CECInitialised())
210 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
212 if (it
->second
->GetHandler()->ActiveSourcePending())
213 it
->second
->ActivateSource();
217 bool CCECProcessor::OnCommandReceived(const cec_command
&command
)
219 return m_inBuffer
.Push(command
);
222 void *CCECProcessor::Process(void)
224 m_libcec
->AddLog(CEC_LOG_DEBUG
, "processor thread started");
227 CTimeout
activeSourceCheck(ACTIVE_SOURCE_CHECK_TIMEOUT
);
229 // as long as we're not being stopped and the connection is open
230 while (!IsStopped() && m_communication
->IsOpen())
232 // wait for a new incoming command, and process it
233 if (m_inBuffer
.Pop(command
, CEC_PROCESSOR_SIGNAL_WAIT_TIME
))
234 ProcessCommand(command
);
236 if (CECInitialised())
238 // check clients for keypress timeouts
239 m_libcec
->CheckKeypressTimeout();
241 // check if we need to replace handlers
244 // check whether we need to activate a source, if it failed before
245 if (activeSourceCheck
.TimeLeft() == 0)
247 CheckPendingActiveSource();
248 activeSourceCheck
.Init(ACTIVE_SOURCE_CHECK_TIMEOUT
);
256 bool CCECProcessor::ActivateSource(uint16_t iStreamPath
)
260 // find the device with the given PA
261 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
262 // and make it the active source when found
264 bReturn
= device
->ActivateSource();
266 m_libcec
->AddLog(CEC_LOG_DEBUG
, "device with PA '%04x' not found", iStreamPath
);
271 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout
)
273 CLockObject
lock(m_mutex
);
274 m_iStandardLineTimeout
= iTimeout
;
277 uint8_t CCECProcessor::GetStandardLineTimeout(void)
279 CLockObject
lock(m_mutex
);
280 return m_iStandardLineTimeout
;
283 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout
)
285 CLockObject
lock(m_mutex
);
286 m_iRetryLineTimeout
= iTimeout
;
289 uint8_t CCECProcessor::GetRetryLineTimeout(void)
291 CLockObject
lock(m_mutex
);
292 return m_iRetryLineTimeout
;
295 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress
)
297 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iPhysicalAddress
);
298 return device
!= NULL
;
301 void CCECProcessor::LogOutput(const cec_command
&data
)
305 // initiator and destination
306 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
310 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
312 // append the parameters
313 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
314 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
317 m_libcec
->AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
320 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
322 // try to find the primary device
323 CCECBusDevice
*primary
= GetPrimaryDevice();
324 // poll the destination, with the primary as source
326 return primary
->TransmitPoll(iAddress
);
328 // try to find the destination
329 CCECBusDevice
*device
= m_busDevices
->At(iAddress
);
330 // and poll the destination, with the same LA as source
332 return device
->TransmitPoll(iAddress
);
337 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bSuppressUpdate
/* = true */)
339 return m_busDevices
?
340 m_busDevices
->GetDeviceByPhysicalAddress(iPhysicalAddress
, bSuppressUpdate
) :
344 CCECBusDevice
*CCECProcessor::GetDevice(cec_logical_address address
) const
346 return m_busDevices
?
347 m_busDevices
->At(address
) :
351 cec_logical_address
CCECProcessor::GetActiveSource(bool bRequestActiveSource
/* = true */)
353 // get the device that is marked as active source from the device map
354 CCECBusDevice
*activeSource
= m_busDevices
->GetActiveSource();
356 return activeSource
->GetLogicalAddress();
358 if (bRequestActiveSource
)
360 // request the active source from the bus
361 CCECBusDevice
*primary
= GetPrimaryDevice();
364 primary
->RequestActiveSource();
365 return GetActiveSource(false);
370 return CECDEVICE_UNKNOWN
;
373 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
375 CCECBusDevice
*device
= m_busDevices
->At(iAddress
);
376 return device
&& device
->IsActiveSource();
379 bool CCECProcessor::Transmit(const cec_command
&data
)
381 uint8_t iMaxTries(0);
385 // get the current timeout setting
386 uint8_t iLineTimeout(GetStandardLineTimeout());
388 // reset the state of this message to 'unknown'
389 cec_adapter_message_state adapterState
= ADAPTER_MESSAGE_STATE_UNKNOWN
;
393 // find the initiator device
394 CCECBusDevice
*initiator
= m_busDevices
->At(data
.initiator
);
397 m_libcec
->AddLog(CEC_LOG_WARNING
, "invalid initiator");
401 // find the destination device, if it's not the broadcast address
402 if (data
.destination
!= CECDEVICE_BROADCAST
)
404 // check if the device is marked as handled by libCEC
405 CCECBusDevice
*destination
= m_busDevices
->At(data
.destination
);
406 if (destination
&& destination
->IsHandledByLibCEC())
408 // and reject the command if it's trying to send data to a device that is handled by libCEC
409 m_libcec
->AddLog(CEC_LOG_WARNING
, "not sending data to myself!");
415 CLockObject
lock(m_mutex
);
416 m_iLastTransmission
= GetTimeMs();
417 // set the number of tries
418 iMaxTries
= initiator
->GetHandler()->GetTransmitRetries() + 1;
421 // and try to send the command
422 while (bRetry
&& ++iTries
< iMaxTries
)
424 if (initiator
->IsUnsupportedFeature(data
.opcode
))
427 adapterState
= !IsStopped() && m_communication
&& m_communication
->IsOpen() ?
428 m_communication
->Write(data
, bRetry
, iLineTimeout
) :
429 ADAPTER_MESSAGE_STATE_ERROR
;
430 iLineTimeout
= m_iRetryLineTimeout
;
433 return adapterState
== ADAPTER_MESSAGE_STATE_SENT_ACKED
;
436 void CCECProcessor::TransmitAbort(cec_logical_address source
, cec_logical_address destination
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
438 m_libcec
->AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
441 cec_command::Format(command
, source
, destination
, CEC_OPCODE_FEATURE_ABORT
);
442 command
.parameters
.PushBack((uint8_t)opcode
);
443 command
.parameters
.PushBack((uint8_t)reason
);
448 void CCECProcessor::ProcessCommand(const cec_command
&command
)
452 dataStr
.Format(">> %1x%1x", command
.initiator
, command
.destination
);
453 if (command
.opcode_set
== 1)
454 dataStr
.AppendFormat(":%02x", command
.opcode
);
455 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
456 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
457 m_libcec
->AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
459 // find the initiator
460 CCECBusDevice
*device
= m_busDevices
->At(command
.initiator
);
463 device
->HandleCommand(command
);
466 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
468 CCECBusDevice
*device
= m_busDevices
->At(address
);
469 return device
&& device
->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
472 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
474 CECDEVICEVEC devices
;
475 m_busDevices
->GetByType(type
, devices
);
476 CCECDeviceMap::FilterActive(devices
);
477 return !devices
.empty();
480 uint16_t CCECProcessor::GetDetectedPhysicalAddress(void) const
482 return m_communication
? m_communication
->GetPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS
;
485 bool CCECProcessor::SetAckMask(uint16_t iMask
)
487 return m_communication
? m_communication
->SetAckMask(iMask
) : false;
490 bool CCECProcessor::StandbyDevices(const cec_logical_address initiator
, const CECDEVICEVEC
&devices
)
493 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
494 bReturn
&= (*it
)->Standby(initiator
);
498 bool CCECProcessor::StandbyDevice(const cec_logical_address initiator
, cec_logical_address address
)
500 CCECBusDevice
*device
= m_busDevices
->At(address
);
501 return device
? device
->Standby(initiator
) : false;
504 bool CCECProcessor::PowerOnDevices(const cec_logical_address initiator
, const CECDEVICEVEC
&devices
)
507 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
508 bReturn
&= (*it
)->PowerOn(initiator
);
512 bool CCECProcessor::PowerOnDevice(const cec_logical_address initiator
, cec_logical_address address
)
514 CCECBusDevice
*device
= m_busDevices
->At(address
);
515 return device
? device
->PowerOn(initiator
) : false;
518 bool CCECProcessor::StartBootloader(const char *strPort
/* = NULL */)
521 // open a connection if no connection has been opened
522 if (!m_communication
&& strPort
)
524 IAdapterCommunication
*comm
= new CUSBCECAdapterCommunication(this, strPort
);
525 CTimeout
timeout(CEC_DEFAULT_CONNECT_TIMEOUT
);
527 while (timeout
.TimeLeft() > 0 && (bReturn
= comm
->Open(timeout
.TimeLeft() / CEC_CONNECT_TRIES
, true)) == false)
529 m_libcec
->AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
531 Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT
);
535 bReturn
= comm
->StartBootloader();
536 DELETE_AND_NULL(comm
);
542 m_communication
->StartBootloader();
550 bool CCECProcessor::PingAdapter(void)
552 return m_communication
->PingAdapter();
555 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
557 CCECBusDevice
*device
= m_busDevices
->At(destination
);
559 device
->HandlePollFrom(initiator
);
562 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator
)
564 CCECBusDevice
*device
= m_busDevices
->At(initiator
);
565 return !device
|| !device
->HandleReceiveFailed();
568 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress
)
570 // stream path changes are sent by the TV
571 return GetTV()->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
);
574 bool CCECProcessor::CanPersistConfiguration(void)
576 return m_communication
? m_communication
->GetFirmwareVersion() >= 2 : false;
579 bool CCECProcessor::PersistConfiguration(const libcec_configuration
&configuration
)
581 return m_communication
? m_communication
->PersistConfiguration(configuration
) : false;
584 void CCECProcessor::RescanActiveDevices(void)
586 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
587 it
->second
->GetStatus(true);
590 bool CCECProcessor::GetDeviceInformation(const char *strPort
, libcec_configuration
*config
, uint32_t iTimeoutMs
/* = CEC_DEFAULT_CONNECT_TIMEOUT */)
592 if (!OpenConnection(strPort
, CEC_SERIAL_DEFAULT_BAUDRATE
, iTimeoutMs
, false))
595 config
->iFirmwareVersion
= m_communication
->GetFirmwareVersion();
596 config
->iPhysicalAddress
= m_communication
->GetPhysicalAddress();
597 config
->iFirmwareBuildDate
= m_communication
->GetFirmwareBuildDate();
602 bool CCECProcessor::TransmitPendingActiveSourceCommands(void)
605 for (CECDEVICEMAP::iterator it
= m_busDevices
->Begin(); it
!= m_busDevices
->End(); it
++)
606 bReturn
&= it
->second
->TransmitPendingActiveSourceCommands();
610 CCECTV
*CCECProcessor::GetTV(void) const
612 return CCECBusDevice::AsTV(m_busDevices
->At(CECDEVICE_TV
));
615 CCECAudioSystem
*CCECProcessor::GetAudioSystem(void) const
617 return CCECBusDevice::AsAudioSystem(m_busDevices
->At(CECDEVICE_AUDIOSYSTEM
));
620 CCECPlaybackDevice
*CCECProcessor::GetPlaybackDevice(cec_logical_address address
) const
622 return CCECBusDevice::AsPlaybackDevice(m_busDevices
->At(address
));
625 CCECRecordingDevice
*CCECProcessor::GetRecordingDevice(cec_logical_address address
) const
627 return CCECBusDevice::AsRecordingDevice(m_busDevices
->At(address
));
630 CCECTuner
*CCECProcessor::GetTuner(cec_logical_address address
) const
632 return CCECBusDevice::AsTuner(m_busDevices
->At(address
));
635 bool CCECProcessor::RegisterClient(CCECClient
*client
)
640 libcec_configuration
&configuration
= *client
->GetConfiguration();
642 if (configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_6_3
&& configuration
.bMonitorOnly
== 1)
645 if (!CECInitialised())
647 m_libcec
->AddLog(CEC_LOG_ERROR
, "failed to register a new CEC client: CEC processor is not initialised");
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 m_libcec
->AddLog(CEC_LOG_NOTICE
, "registering new CEC client - v%s", ToString((cec_client_version
)configuration
.clientVersion
));
658 // mark as uninitialised and unregistered
659 client
->SetRegistered(false);
660 client
->SetInitialised(false);
662 // get the current ackmask, so we can restore it if polling fails
663 uint16_t iPreviousMask(m_communication
->GetAckMask());
665 // find logical addresses for this client
666 if (!client
->AllocateLogicalAddresses())
668 m_libcec
->AddLog(CEC_LOG_ERROR
, "failed to register the new CEC client - cannot allocate the requested device types");
669 SetAckMask(iPreviousMask
);
673 // register this client on the new addresses
674 CECDEVICEVEC devices
;
675 m_busDevices
->GetByLogicalAddresses(devices
, configuration
.logicalAddresses
);
676 for (CECDEVICEVEC::const_iterator it
= devices
.begin(); it
!= devices
.end(); it
++)
678 // replace a previous client
679 CLockObject
lock(m_mutex
);
680 m_clients
.erase((*it
)->GetLogicalAddress());
681 m_clients
.insert(make_pair
<cec_logical_address
, CCECClient
*>((*it
)->GetLogicalAddress(), client
));
684 // get the settings from the rom
685 if (configuration
.bGetSettingsFromROM
== 1)
687 libcec_configuration config
;
688 m_communication
->GetConfiguration(config
);
690 CLockObject
lock(m_mutex
);
691 if (!config
.deviceTypes
.IsEmpty())
692 configuration
.deviceTypes
= config
.deviceTypes
;
693 if (CLibCEC::IsValidPhysicalAddress(config
.iPhysicalAddress
))
694 configuration
.iPhysicalAddress
= config
.iPhysicalAddress
;
695 snprintf(configuration
.strDeviceName
, 13, "%s", config
.strDeviceName
);
698 // set the firmware version and build date
699 configuration
.serverVersion
= LIBCEC_VERSION_CURRENT
;
700 configuration
.iFirmwareVersion
= m_communication
->GetFirmwareVersion();
701 configuration
.iFirmwareBuildDate
= m_communication
->GetFirmwareBuildDate();
703 // mark the client as registered
704 client
->SetRegistered(true);
706 // set the new ack mask
707 bool bReturn
= SetAckMask(GetLogicalAddresses().AckMask()) &&
708 // and initialise the client
709 client
->OnRegister();
711 // log the new registration
713 strLog
.Format("%s: %s", bReturn
? "CEC client registered" : "failed to register the CEC client", client
->GetConnectionInfo().c_str());
714 m_libcec
->AddLog(bReturn
? CEC_LOG_NOTICE
: CEC_LOG_ERROR
, strLog
);
716 // display a warning if the firmware can be upgraded
717 if (bReturn
&& !IsRunningLatestFirmware())
719 const char *strUpgradeMessage
= "The firmware of this adapter can be upgraded. Please visit http://blog.pulse-eight.com/ for more information.";
720 m_libcec
->AddLog(CEC_LOG_WARNING
, strUpgradeMessage
);
721 libcec_parameter param
;
722 param
.paramData
= (void*)strUpgradeMessage
; param
.paramType
= CEC_PARAMETER_TYPE_STRING
;
723 client
->Alert(CEC_ALERT_SERVICE_DEVICE
, param
);
729 bool CCECProcessor::UnregisterClient(CCECClient
*client
)
734 if (client
->IsRegistered())
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 return 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() :