+ m_clients.insert(make_pair((*it)->GetLogicalAddress(), client));
+ }
+
+ // set the new ackmask
+ SetLogicalAddresses(GetLogicalAddresses());
+
+ // resume outgoing communication
+ m_bStallCommunication = false;
+
+ return true;
+}
+
+uint16_t CCECProcessor::GetPhysicalAddressFromEeprom(void)
+{
+ libcec_configuration config; config.Clear();
+ if (m_communication)
+ m_communication->GetConfiguration(config);
+ return config.iPhysicalAddress;
+}
+
+bool CCECProcessor::RegisterClient(CCECClient *client)
+{
+ if (!client)
+ return false;
+
+ libcec_configuration &configuration = *client->GetConfiguration();
+
+ if (configuration.clientVersion < CEC_CLIENT_VERSION_2_0_0)
+ {
+ m_libcec->AddLog(CEC_LOG_ERROR, "failed to register a new CEC client: client version %s is no longer supported", ToString((cec_client_version)configuration.clientVersion));
+ return false;
+ }
+
+ if (configuration.bMonitorOnly == 1)
+ return true;
+
+ if (!CECInitialised())
+ {
+ m_libcec->AddLog(CEC_LOG_ERROR, "failed to register a new CEC client: CEC processor is not initialised");
+ return false;
+ }
+
+ // unregister the client first if it's already been marked as registered
+ if (client->IsRegistered())
+ UnregisterClient(client);
+
+ // ensure that controlled mode is enabled
+ m_communication->SetControlledMode(true);
+ m_bMonitor = false;
+
+ // source logical address for requests
+ cec_logical_address sourceAddress(CECDEVICE_UNREGISTERED);
+ if (!m_communication->SupportsSourceLogicalAddress(CECDEVICE_UNREGISTERED))
+ {
+ if (m_communication->SupportsSourceLogicalAddress(CECDEVICE_FREEUSE))
+ sourceAddress = CECDEVICE_FREEUSE;
+ else
+ {
+ m_libcec->AddLog(CEC_LOG_ERROR, "failed to register a new CEC client: both unregistered and free use are not supported by the device");
+ return false;
+ }
+ }
+
+ // ensure that we know the vendor id of the TV
+ CCECBusDevice *tv = GetTV();
+ cec_vendor_id tvVendor(tv->GetVendorId(sourceAddress));
+
+ // wait until the handler is replaced, to avoid double registrations
+ if (tvVendor != CEC_VENDOR_UNKNOWN &&
+ CCECCommandHandler::HasSpecificHandler(tvVendor))
+ {
+ while (!tv->ReplaceHandler(false))
+ CEvent::Sleep(5);
+ }
+
+ // get the configuration from the client
+ m_libcec->AddLog(CEC_LOG_NOTICE, "registering new CEC client - v%s", ToString((cec_client_version)configuration.clientVersion));
+
+ // get the current ackmask, so we can restore it if polling fails
+ cec_logical_addresses previousMask = GetLogicalAddresses();
+
+ // mark as uninitialised
+ client->SetInitialised(false);
+
+ // find logical addresses for this client
+ if (!AllocateLogicalAddresses(client))
+ {
+ m_libcec->AddLog(CEC_LOG_ERROR, "failed to register the new CEC client - cannot allocate the requested device types");
+ SetLogicalAddresses(previousMask);
+ return false;