+void CCECBusDevice::AddLog(cec_log_level level, const CStdString &strMessage)
+{
+ m_processor->AddLog(level, strMessage);
+}
+
+bool CCECBusDevice::HandleCommand(const cec_command &command)
+{
+ CLockObject lock(&m_transmitMutex);
+ m_iLastActive = GetTimeMs();
+ m_handler->HandleCommand(command);
+ if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC)
+ {
+ if (m_deviceStatus != CEC_DEVICE_STATUS_PRESENT)
+ {
+ CStdString strLog;
+ strLog.Format("device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command.opcode));
+ AddLog(CEC_LOG_DEBUG, strLog);
+ }
+ m_deviceStatus = CEC_DEVICE_STATUS_PRESENT;
+ }
+ m_condition.Signal();
+ return true;
+}
+
+bool CCECBusDevice::PowerOn(void)
+{
+ CStdString strLog;
+ strLog.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
+ AddLog(CEC_LOG_DEBUG, strLog.c_str());
+
+ cec_command command;
+ cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_IMAGE_VIEW_ON, m_iTransmitTimeout);
+ if (m_processor->Transmit(command))
+ {
+ {
+ CLockObject lock(&m_mutex);
+ m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
+ }
+ cec_power_status status = GetPowerStatus();
+ if (status == CEC_POWER_STATUS_STANDBY || status == CEC_POWER_STATUS_UNKNOWN)
+ {
+ SendKeypress(CEC_USER_CONTROL_CODE_POWER, true);
+ return SendKeyRelease(false);
+ }
+ return true;
+ }
+
+ return false;
+}
+
+bool CCECBusDevice::Standby(void)
+{
+ CStdString strLog;
+ strLog.Format("<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress);
+ AddLog(CEC_LOG_DEBUG, strLog.c_str());
+
+ cec_command command;
+ cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_STANDBY, m_iTransmitTimeout);
+
+ return m_processor->Transmit(command);
+}
+
+/** @name Getters */
+//@{
+cec_version CCECBusDevice::GetCecVersion(void)
+{
+ CLockObject lock(&m_mutex);
+ if (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
+ m_cecVersion == CEC_VERSION_UNKNOWN)
+ RequestCecVersion();
+
+ return m_cecVersion;
+}
+
+bool CCECBusDevice::RequestCecVersion(void)
+{
+ bool bReturn(false);
+ if (!MyLogicalAddressContains(m_iLogicalAddress))
+ {
+ CStdString strLog;
+ strLog.Format("<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
+ AddLog(CEC_LOG_NOTICE, strLog);
+ cec_command command;
+ cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_CEC_VERSION, m_iTransmitTimeout);
+ CLockObject lock(&m_transmitMutex);
+ if (m_processor->Transmit(command))
+ bReturn = m_condition.Wait(&m_transmitMutex, 1000);
+ }
+ return bReturn;
+}
+
+uint64_t CCECBusDevice::GetLastCommandSent(void) const
+{
+ return GetTimeMs() - m_iLastCommandSent;
+}
+
+const char* CCECBusDevice::GetLogicalAddressName(void) const
+{
+ return ToString(m_iLogicalAddress);
+}
+
+cec_menu_language &CCECBusDevice::GetMenuLanguage(void)
+{
+ CLockObject lock(&m_mutex);
+ if (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
+ !strcmp(m_menuLanguage.language, "???"))
+ RequestMenuLanguage();
+
+ return m_menuLanguage;
+}
+
+bool CCECBusDevice::RequestMenuLanguage(void)
+{
+ bool bReturn(false);
+ if (!MyLogicalAddressContains(m_iLogicalAddress))
+ {
+ CStdString strLog;
+ strLog.Format("<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
+ AddLog(CEC_LOG_NOTICE, strLog);
+ cec_command command;
+ cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GET_MENU_LANGUAGE, m_iTransmitTimeout);
+ CLockObject lock(&m_transmitMutex);
+ if (m_processor->Transmit(command))
+ bReturn = m_condition.Wait(&m_transmitMutex, 1000);
+ }
+ return bReturn;
+}
+