- switch(msg.message())
- {
- case MSGCODE_COMMAND_ACCEPTED:
- iPacketsLeft--;
- break;
- case MSGCODE_TRANSMIT_SUCCEEDED:
- bTransmitSucceeded = (iPacketsLeft == 0);
- bError = !bTransmitSucceeded;
- break;
- default:
- CStdString strLog;
- strLog.Format("received unexpected reply '%1x' instead of ack", msg.message());
- m_controller->AddLog(CEC_LOG_WARNING, strLog);
- bError = true;
- break;
- }
+ // mark as uninitialised and unregistered
+ client->SetRegistered(false);
+ client->SetInitialised(false);
+
+ // get the current ackmask, so we can restore it if polling fails
+ uint16_t iPreviousMask(m_communication->GetAckMask());
+
+ // find logical addresses for this client
+ if (!client->AllocateLogicalAddresses())
+ {
+ m_libcec->AddLog(CEC_LOG_ERROR, "failed to register the new CEC client - cannot allocate the requested device types");
+ SetAckMask(iPreviousMask);
+ return false;
+ }
+
+ // register this client on the new addresses
+ CECDEVICEVEC devices;
+ m_busDevices->GetByLogicalAddresses(devices, configuration.logicalAddresses);
+ for (CECDEVICEVEC::const_iterator it = devices.begin(); it != devices.end(); it++)
+ {
+ // replace a previous client
+ CLockObject lock(m_mutex);
+ m_clients.erase((*it)->GetLogicalAddress());
+ m_clients.insert(make_pair<cec_logical_address, CCECClient *>((*it)->GetLogicalAddress(), client));
+ }
+
+ // get the settings from the rom
+ if (configuration.bGetSettingsFromROM == 1)
+ {
+ libcec_configuration config;
+ m_communication->GetConfiguration(config);
+
+ CLockObject lock(m_mutex);
+ if (!config.deviceTypes.IsEmpty())
+ configuration.deviceTypes = config.deviceTypes;
+ if (CLibCEC::IsValidPhysicalAddress(config.iPhysicalAddress))
+ configuration.iPhysicalAddress = config.iPhysicalAddress;
+ snprintf(configuration.strDeviceName, 13, "%s", config.strDeviceName);
+ }
+
+ // set the firmware version and build date
+ configuration.serverVersion = LIBCEC_VERSION_CURRENT;
+ configuration.iFirmwareVersion = m_communication->GetFirmwareVersion();
+ configuration.iFirmwareBuildDate = m_communication->GetFirmwareBuildDate();