+
+ return false;
+}
+
+void CCECProcessor::UnregisterClients(void)
+{
+ m_libcec->AddLog(CEC_LOG_NOTICE, "unregistering all CEC clients");
+
+ vector<CCECClient *> clients = m_libcec->GetClients();
+ for (vector<CCECClient *>::iterator client = clients.begin(); client != clients.end(); client++)
+ UnregisterClient(*client);
+
+ CLockObject lock(m_mutex);
+ m_clients.clear();
+}
+
+CCECClient *CCECProcessor::GetClient(const cec_logical_address address)
+{
+ CLockObject lock(m_mutex);
+ map<cec_logical_address, CCECClient *>::const_iterator client = m_clients.find(address);
+ if (client != m_clients.end())
+ return client->second;
+ return NULL;
+}
+
+CCECClient *CCECProcessor::GetPrimaryClient(void)
+{
+ CLockObject lock(m_mutex);
+ map<cec_logical_address, CCECClient *>::const_iterator client = m_clients.begin();
+ if (client != m_clients.end())
+ return client->second;
+ return NULL;
+}
+
+CCECBusDevice *CCECProcessor::GetPrimaryDevice(void)
+{
+ return m_busDevices->At(GetLogicalAddress());
+}
+
+cec_logical_address CCECProcessor::GetLogicalAddress(void)
+{
+ cec_logical_addresses addresses = GetLogicalAddresses();
+ return addresses.primary;
+}
+
+cec_logical_addresses CCECProcessor::GetLogicalAddresses(void)
+{
+ CLockObject lock(m_mutex);
+ cec_logical_addresses addresses;
+ addresses.Clear();
+ for (map<cec_logical_address, CCECClient *>::const_iterator client = m_clients.begin(); client != m_clients.end(); client++)
+ addresses.Set(client->first);
+
+ return addresses;
+}
+
+bool CCECProcessor::IsHandledByLibCEC(const cec_logical_address address) const
+{
+ CCECBusDevice *device = GetDevice(address);
+ return device && device->IsHandledByLibCEC();
+}
+
+bool CCECProcessor::IsRunningLatestFirmware(void)
+{
+ return m_communication && m_communication->IsOpen() ?
+ m_communication->IsRunningLatestFirmware() :
+ true;
+}
+
+void CCECProcessor::SwitchMonitoring(bool bSwitchTo)
+{
+ {
+ CLockObject lock(m_mutex);
+ m_bMonitor = bSwitchTo;
+ }
+ if (bSwitchTo)
+ UnregisterClients();
+}
+
+void CCECProcessor::HandleLogicalAddressLost(cec_logical_address oldAddress)
+{
+ // stall outgoing messages until we know our new LA
+ m_bStallCommunication = true;
+
+ m_libcec->AddLog(CEC_LOG_NOTICE, "logical address %x was taken by another device, allocating a new address", oldAddress);
+ CCECClient* client = GetClient(oldAddress);
+ if (client)
+ {
+ if (m_addrAllocator)
+ while (m_addrAllocator->IsRunning()) Sleep(5);
+ delete m_addrAllocator;
+
+ m_addrAllocator = new CCECAllocateLogicalAddress(this, client);
+ m_addrAllocator->CreateThread();
+ }
+}
+
+CCECAllocateLogicalAddress::CCECAllocateLogicalAddress(CCECProcessor* processor, CCECClient* client) :
+ m_processor(processor),
+ m_client(client) { }
+
+void* CCECAllocateLogicalAddress::Process(void)
+{
+ m_processor->AllocateLogicalAddresses(m_client);
+ return NULL;