- switch(msg.message())
- {
- case MSGCODE_TIMEOUT_ERROR:
- case MSGCODE_HIGH_ERROR:
- case MSGCODE_LOW_ERROR:
- {
- CStdString logStr;
- if (msg.message() == MSGCODE_TIMEOUT_ERROR)
- logStr = "MSGCODE_TIMEOUT";
- else if (msg.message() == MSGCODE_HIGH_ERROR)
- logStr = "MSGCODE_HIGH_ERROR";
- else
- logStr = "MSGCODE_LOW_ERROR";
-
- int iLine = (msg.size() >= 3) ? (msg[1] << 8) | (msg[2]) : 0;
- uint32_t iTime = (msg.size() >= 7) ? (msg[3] << 24) | (msg[4] << 16) | (msg[5] << 8) | (msg[6]) : 0;
- logStr.AppendFormat(" line:%i", iLine);
- logStr.AppendFormat(" time:%u", iTime);
- m_controller->AddLog(CEC_LOG_WARNING, logStr.c_str());
- *bError = true;
- }
- break;
- case MSGCODE_COMMAND_ACCEPTED:
- m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_COMMAND_ACCEPTED");
- iPacketsLeft--;
- break;
- case MSGCODE_TRANSMIT_SUCCEEDED:
- m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_TRANSMIT_SUCCEEDED");
- bTransmitSucceeded = (iPacketsLeft == 0);
- *bError = !bTransmitSucceeded;
- break;
- case MSGCODE_RECEIVE_FAILED:
- m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_RECEIVE_FAILED");
- *bError = true;
- break;
- case MSGCODE_COMMAND_REJECTED:
- m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_COMMAND_REJECTED");
- *bError = true;
- break;
- case MSGCODE_TRANSMIT_FAILED_LINE:
- m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_LINE");
- *bError = true;
- break;
- case MSGCODE_TRANSMIT_FAILED_ACK:
- m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_ACK");
- *bError = true;
- break;
- case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA:
- m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA");
- *bError = true;
- break;
- case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE:
- m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE");
- *bError = true;
- break;
- default:
- CCECAdapterMessagePtr msgPtr = CCECAdapterMessagePtr(new CCECAdapterMessage(msg));
- m_frameBuffer.Push(msgPtr);
- break;
- }
+ // unregister the client first if it's already been marked as registered
+ if (client->IsRegistered())
+ UnregisterClient(client);
+
+ // get the configuration from the client
+ m_libcec->AddLog(CEC_LOG_NOTICE, "registering new CEC client - v%s", ToString((cec_client_version)configuration.clientVersion));
+
+ // 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);
+ }