X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fdevices%2FCECBusDevice.cpp;h=a794dc0e407b4d5308bb725afd8d79b130cd406b;hb=8fa354734e6dd2fd2e6fae68f7bbaf7ea84cbdfd;hp=702b561c1016611bb9999484dac28537dd0a2bb1;hpb=9fd73dd492819cc18bac465d2a98f31019378886;p=deb_libcec.git diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 702b561..a794dc0 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -40,7 +40,7 @@ using namespace CEC; -#define ToString(p) CCECCommandHandler::ToString(p) +#define ToString(p) m_processor->ToString(p) CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) : m_type(CEC_DEVICE_TYPE_RESERVED), @@ -69,7 +69,6 @@ CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogi CCECBusDevice::~CCECBusDevice(void) { - m_condition.Broadcast(); delete m_handler; } @@ -80,47 +79,48 @@ void CCECBusDevice::AddLog(cec_log_level level, const CStdString &strMessage) bool CCECBusDevice::HandleCommand(const cec_command &command) { - CLockObject lock(&m_transmitMutex); - m_iLastActive = GetTimeMs(); + { + CLockObject lock(&m_writeMutex); + m_iLastActive = GetTimeMs(); + } + m_handler->HandleCommand(command); - if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) - m_deviceStatus = CEC_DEVICE_STATUS_PRESENT; - m_condition.Signal(); - return true; -} -void CCECBusDevice::PollVendorId(void) -{ - CLockObject lock(&m_transmitMutex); - if (m_iLastActive > 0 && m_iLogicalAddress != CECDEVICE_BROADCAST && - m_vendor == CEC_VENDOR_UNKNOWN && - GetTimeMs() - m_iLastCommandSent > 5000 && - !m_processor->IsMonitoring()) { - CStdString strLog; - strLog.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_NOTICE, strLog); - m_iLastCommandSent = GetTimeMs(); - - cec_command command; - cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); - if (m_processor->Transmit(command)) - m_condition.Wait(&m_transmitMutex, 1000); + CLockObject lock(&m_writeMutex); + 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; + } } + return true; } bool CCECBusDevice::PowerOn(void) { - CStdString strLog; - strLog.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_DEBUG, strLog.c_str()); + 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); - if (m_processor->Transmit(command)) - { - GetPowerStatus(); - return true; + if (m_handler->TransmitPowerOn(GetMyLogicalAddress(), m_iLogicalAddress)) + { + { + 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); + return SendKeyRelease(); + } + return true; } return false; @@ -132,10 +132,7 @@ bool CCECBusDevice::Standby(void) 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); - - return m_processor->Transmit(command); + return m_handler->TransmitStandby(GetMyLogicalAddress(), m_iLogicalAddress); } /** @name Getters */ @@ -143,12 +140,9 @@ bool CCECBusDevice::Standby(void) cec_version CCECBusDevice::GetCecVersion(void) { CLockObject lock(&m_mutex); - if (m_cecVersion == CEC_VERSION_UNKNOWN) - { - lock.Leave(); + if (GetStatus() == CEC_DEVICE_STATUS_PRESENT && + m_cecVersion == CEC_VERSION_UNKNOWN) RequestCecVersion(); - lock.Lock(); - } return m_cecVersion; } @@ -161,15 +155,17 @@ bool CCECBusDevice::RequestCecVersion(void) 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); - CLockObject lock(&m_transmitMutex); - if (m_processor->Transmit(command)) - bReturn = m_condition.Wait(&m_transmitMutex, 1000); + + bReturn = m_handler->TransmitRequestCecVersion(GetMyLogicalAddress(), m_iLogicalAddress); } return bReturn; } +uint64_t CCECBusDevice::GetLastCommandSent(void) const +{ + return GetTimeMs() - m_iLastCommandSent; +} + const char* CCECBusDevice::GetLogicalAddressName(void) const { return ToString(m_iLogicalAddress); @@ -178,12 +174,10 @@ const char* CCECBusDevice::GetLogicalAddressName(void) const cec_menu_language &CCECBusDevice::GetMenuLanguage(void) { CLockObject lock(&m_mutex); - if (!strcmp(m_menuLanguage.language, "???")) - { - lock.Leave(); + if (GetStatus() == CEC_DEVICE_STATUS_PRESENT && + !strcmp(m_menuLanguage.language, "???")) RequestMenuLanguage(); - lock.Lock(); - } + return m_menuLanguage; } @@ -195,11 +189,7 @@ bool CCECBusDevice::RequestMenuLanguage(void) 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); - CLockObject lock(&m_transmitMutex); - if (m_processor->Transmit(command)) - bReturn = m_condition.Wait(&m_transmitMutex, 1000); + bReturn = m_handler->TransmitRequestMenuLanguage(GetMyLogicalAddress(), m_iLogicalAddress); } return bReturn; } @@ -216,18 +206,12 @@ uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const CStdString CCECBusDevice::GetOSDName(void) { - if (GetStatus() == CEC_DEVICE_STATUS_PRESENT) - { - CLockObject lock(&m_mutex); - if (m_strDeviceName.Equals(ToString(m_iLogicalAddress))) - { - lock.Leave(); - RequestOSDName(); - lock.Lock(); - } - } - CLockObject lock(&m_mutex); + if (GetStatus() == CEC_DEVICE_STATUS_PRESENT && + m_strDeviceName.Equals(ToString(m_iLogicalAddress)) && + m_type != CEC_DEVICE_TYPE_TV) + RequestOSDName(); + return m_strDeviceName; } @@ -239,30 +223,21 @@ bool CCECBusDevice::RequestOSDName(void) CStdString strLog; strLog.Format("<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); AddLog(CEC_LOG_NOTICE, strLog); - cec_command command; - cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_OSD_NAME); - CLockObject lock(&m_transmitMutex); - if (m_processor->Transmit(command)) - bReturn = m_condition.Wait(&m_transmitMutex, 1000); + bReturn = m_handler->TransmitRequestOSDName(GetMyLogicalAddress(), m_iLogicalAddress); } return bReturn; } uint16_t CCECBusDevice::GetPhysicalAddress(bool bRefresh /* = true */) { - if (GetStatus() == CEC_DEVICE_STATUS_PRESENT) + CLockObject lock(&m_mutex); + if (GetStatus() == CEC_DEVICE_STATUS_PRESENT && + (m_iPhysicalAddress == 0xFFFF || bRefresh)) { - CLockObject lock(&m_mutex); - if (m_iPhysicalAddress == 0xFFFF || bRefresh) - { - lock.Leave(); - if (!RequestPhysicalAddress()) - AddLog(CEC_LOG_ERROR, "failed to request the physical address"); - lock.Lock(); - } + if (!RequestPhysicalAddress()) + AddLog(CEC_LOG_ERROR, "failed to request the physical address"); } - CLockObject lock(&m_mutex); return m_iPhysicalAddress; } @@ -274,11 +249,7 @@ bool CCECBusDevice::RequestPhysicalAddress(void) CStdString strLog; strLog.Format("<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); AddLog(CEC_LOG_NOTICE, strLog); - cec_command command; - cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS); - CLockObject lock(&m_transmitMutex); - if (m_processor->Transmit(command)) - bReturn = m_condition.Wait(&m_transmitMutex, 1000); + bReturn = m_handler->TransmitRequestPhysicalAddress(GetMyLogicalAddress(), m_iLogicalAddress); } return bReturn; } @@ -286,12 +257,10 @@ bool CCECBusDevice::RequestPhysicalAddress(void) cec_power_status CCECBusDevice::GetPowerStatus(void) { CLockObject lock(&m_mutex); - if (m_powerStatus == CEC_POWER_STATUS_UNKNOWN) - { - lock.Leave(); + if (GetStatus() == CEC_DEVICE_STATUS_PRESENT && + m_powerStatus == CEC_POWER_STATUS_UNKNOWN) RequestPowerStatus(); - lock.Lock(); - } + return m_powerStatus; } @@ -303,11 +272,7 @@ bool CCECBusDevice::RequestPowerStatus(void) CStdString strLog; strLog.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); AddLog(CEC_LOG_NOTICE, strLog); - cec_command command; - cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS); - CLockObject lock(&m_transmitMutex); - if (m_processor->Transmit(command)) - bReturn = m_condition.Wait(&m_transmitMutex, 1000); + bReturn = m_handler->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress); } return bReturn; } @@ -315,12 +280,10 @@ bool CCECBusDevice::RequestPowerStatus(void) cec_vendor_id CCECBusDevice::GetVendorId(void) { CLockObject lock(&m_mutex); - if (m_vendor == CEC_VENDOR_UNKNOWN) - { - lock.Leave(); + if (GetStatus() == CEC_DEVICE_STATUS_PRESENT && + m_vendor == CEC_VENDOR_UNKNOWN) RequestVendorId(); - lock.Lock(); - } + return m_vendor; } @@ -332,12 +295,7 @@ bool CCECBusDevice::RequestVendorId(void) CStdString strLog; strLog.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); AddLog(CEC_LOG_NOTICE, strLog); - cec_command command; - cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); - - CLockObject lock(&m_transmitMutex); - if (m_processor->Transmit(command)) - bReturn = m_condition.Wait(&m_transmitMutex, 1000); + bReturn = m_handler->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress); } return bReturn; } @@ -401,7 +359,7 @@ bool CCECBusDevice::NeedsPoll(void) cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */) { - CLockObject lock(&m_mutex); + CLockObject lock(&m_writeMutex); if (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || bForcePoll) { lock.Leave(); @@ -431,7 +389,7 @@ void CCECBusDevice::SetCecVersion(const cec_version newVersion) void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language) { - CLockObject lock(&m_mutex); + CLockObject lock(&m_writeMutex); if (language.device == m_iLogicalAddress) { CStdString strLog; @@ -443,7 +401,7 @@ void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language) void CCECBusDevice::SetOSDName(CStdString strName) { - CLockObject lock(&m_mutex); + CLockObject lock(&m_writeMutex); if (m_strDeviceName != strName) { CStdString strLog; @@ -455,7 +413,7 @@ void CCECBusDevice::SetOSDName(CStdString strName) void CCECBusDevice::SetMenuState(const cec_menu_state state) { - CLockObject lock(&m_mutex); + CLockObject lock(&m_writeMutex); if (m_menuState != state) { CStdString strLog; @@ -467,13 +425,13 @@ void CCECBusDevice::SetMenuState(const cec_menu_state state) void CCECBusDevice::SetInactiveDevice(void) { - CLockObject lock(&m_mutex); + CLockObject lock(&m_writeMutex); m_bActiveSource = false; } void CCECBusDevice::SetActiveDevice(void) { - CLockObject lock(&m_mutex); + CLockObject lock(&m_writeMutex); for (int iPtr = 0; iPtr < 16; iPtr++) if (iPtr != m_iLogicalAddress) @@ -507,7 +465,7 @@ bool CCECBusDevice::TryLogicalAddress(void) void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus) { - CLockObject lock(&m_mutex); + CLockObject lock(&m_writeMutex); switch (newStatus) { case CEC_DEVICE_STATUS_UNKNOWN: @@ -541,7 +499,7 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus) void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress) { - CLockObject lock(&m_mutex); + CLockObject lock(&m_writeMutex); if (iNewAddress > 0 && m_iPhysicalAddress != iNewAddress) { CStdString strLog; @@ -554,7 +512,7 @@ void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress) void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */) { - CLockObject lock(&m_mutex); + CLockObject lock(&m_writeMutex); if (iNewAddress > 0) { CStdString strLog; @@ -573,7 +531,7 @@ void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus) { - CLockObject lock(&m_mutex); + CLockObject lock(&m_writeMutex); if (m_powerStatus != powerStatus) { CStdString strLog; @@ -583,48 +541,47 @@ void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus) } } -void CCECBusDevice::SetVendorId(uint64_t iVendorId) +bool CCECBusDevice::SetVendorId(uint64_t iVendorId, bool bInitHandler /* = true */) { + bool bVendorChanged(false); + { - CLockObject lock(&m_mutex); + CLockObject lock(&m_writeMutex); + bVendorChanged = (m_vendor != (cec_vendor_id)iVendorId); m_vendor = (cec_vendor_id)iVendorId; + if (bVendorChanged) + delete m_handler; + switch (iVendorId) { case CEC_VENDOR_SAMSUNG: - if (m_handler->GetVendorId() != CEC_VENDOR_SAMSUNG) - { - delete m_handler; + if (bVendorChanged) m_handler = new CANCommandHandler(this); - } break; case CEC_VENDOR_LG: - if (m_handler->GetVendorId() != CEC_VENDOR_LG) - { - delete m_handler; + if (bVendorChanged) m_handler = new CSLCommandHandler(this); - } break; case CEC_VENDOR_PANASONIC: - if (m_handler->GetVendorId() != CEC_VENDOR_PANASONIC) - { - delete m_handler; + if (bVendorChanged) m_handler = new CVLCommandHandler(this); - } break; default: - if (m_handler->GetVendorId() != CEC_VENDOR_UNKNOWN) - { - delete m_handler; + if (bVendorChanged) m_handler = new CCECCommandHandler(this); - } break; } } + if (bVendorChanged && bInitHandler) + m_handler->InitHandler(); + CStdString strLog; - strLog.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, GetVendorName(), m_vendor); + strLog.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_vendor), m_vendor); m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str()); + + return bVendorChanged; } //@} @@ -632,131 +589,117 @@ void CCECBusDevice::SetVendorId(uint64_t iVendorId) //@{ bool CCECBusDevice::TransmitActiveSource(void) { - CLockObject lock(&m_mutex); - if (m_powerStatus != CEC_POWER_STATUS_ON) - { - CStdString strLog; - strLog.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_DEBUG, strLog); - } - else if (m_bActiveSource) - { - CStdString strLog; - strLog.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); - AddLog(CEC_LOG_NOTICE, strLog); - - cec_command command; - cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); - command.parameters.PushBack((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); - command.parameters.PushBack((uint8_t) (m_iPhysicalAddress & 0xFF)); + bool bSendActiveSource(false); - lock.Leave(); - return m_processor->Transmit(command); - } - else { - CStdString strLog; - strLog.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_DEBUG, strLog); + CLockObject lock(&m_writeMutex); + if (m_powerStatus != CEC_POWER_STATUS_ON) + { + CStdString strLog; + strLog.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress); + AddLog(CEC_LOG_DEBUG, strLog); + } + else if (m_bActiveSource) + { + CStdString strLog; + strLog.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); + AddLog(CEC_LOG_NOTICE, strLog); + bSendActiveSource = true; + } + else + { + CStdString strLog; + strLog.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress); + AddLog(CEC_LOG_DEBUG, strLog); + } } - return false; + return bSendActiveSource ? m_handler->TransmitActiveSource(m_iLogicalAddress, m_iPhysicalAddress) : false; } bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest) { - CLockObject lock(&m_mutex); - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_cecVersion)); - AddLog(CEC_LOG_NOTICE, strLog); - - cec_command command; - cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_CEC_VERSION); - command.parameters.PushBack((uint8_t)m_cecVersion); + cec_version version; + { + CLockObject lock(&m_writeMutex); + CStdString strLog; + strLog.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_cecVersion)); + AddLog(CEC_LOG_NOTICE, strLog); + version = m_cecVersion; + } - lock.Leave(); - return m_processor->Transmit(command); + return m_handler->TransmitCECVersion(m_iLogicalAddress, dest, version); } -bool CCECBusDevice::TransmitInactiveView(void) +bool CCECBusDevice::TransmitInactiveSource(void) { - CStdString strLog; - strLog.Format("<< %s (%X) -> broadcast (F): inactive view", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_NOTICE, strLog); - - cec_command command; - cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_INACTIVE_SOURCE); - command.parameters.PushBack((m_iPhysicalAddress >> 8) & 0xFF); - command.parameters.PushBack(m_iPhysicalAddress & 0xFF); + uint16_t iPhysicalAddress; + { + CLockObject lock(&m_writeMutex); + CStdString strLog; + strLog.Format("<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress); + AddLog(CEC_LOG_NOTICE, strLog); + iPhysicalAddress = m_iPhysicalAddress; + } - return m_processor->Transmit(command); + return m_handler->TransmitInactiveSource(m_iLogicalAddress, iPhysicalAddress); } bool CCECBusDevice::TransmitMenuState(cec_logical_address dest) { - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState)); - AddLog(CEC_LOG_NOTICE, strLog); - - cec_command command; - cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_MENU_STATUS); - command.parameters.PushBack((uint8_t)m_menuState); + cec_menu_state menuState; + { + CLockObject lock(&m_writeMutex); + CStdString strLog; + strLog.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState)); + AddLog(CEC_LOG_NOTICE, strLog); + menuState = m_menuState; + } - return m_processor->Transmit(command); + return m_handler->TransmitMenuState(m_iLogicalAddress, dest, menuState); } bool CCECBusDevice::TransmitOSDName(cec_logical_address dest) { - CLockObject lock(&m_mutex); - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, m_strDeviceName.c_str()); - AddLog(CEC_LOG_NOTICE, strLog.c_str()); - - cec_command command; - cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_SET_OSD_NAME); - for (unsigned int iPtr = 0; iPtr < m_strDeviceName.length(); iPtr++) - command.parameters.PushBack(m_strDeviceName.at(iPtr)); + CStdString strDeviceName; + { + CLockObject lock(&m_writeMutex); + CStdString strLog; + strLog.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, m_strDeviceName.c_str()); + AddLog(CEC_LOG_NOTICE, strLog.c_str()); + strDeviceName = m_strDeviceName; + } - lock.Leave(); - return m_processor->Transmit(command); + return m_handler->TransmitOSDName(m_iLogicalAddress, dest, strDeviceName); } bool CCECBusDevice::TransmitOSDString(cec_logical_address dest, cec_display_control duration, const char *strMessage) { - CLockObject lock(&m_mutex); CStdString strLog; strLog.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, strMessage); AddLog(CEC_LOG_NOTICE, strLog.c_str()); - cec_command command; - cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_SET_OSD_STRING); - command.parameters.PushBack((uint8_t)duration); - - unsigned int iLen = strlen(strMessage); - if (iLen > 13) iLen = 13; - - for (unsigned int iPtr = 0; iPtr < iLen; iPtr++) - command.parameters.PushBack(strMessage[iPtr]); - - lock.Leave(); - return m_processor->Transmit(command); + return m_handler->TransmitOSDString(m_iLogicalAddress, dest, duration, strMessage); } bool CCECBusDevice::TransmitPhysicalAddress(void) { - CLockObject lock(&m_mutex); - CStdString strLog; - strLog.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); - AddLog(CEC_LOG_NOTICE, strLog.c_str()); + uint16_t iPhysicalAddress; + cec_device_type type; + { + CLockObject lock(&m_writeMutex); + if (m_iPhysicalAddress == 0xffff) + return false; - cec_command command; - cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); - command.parameters.PushBack((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF)); - command.parameters.PushBack((uint8_t) (m_iPhysicalAddress & 0xFF)); - command.parameters.PushBack((uint8_t) (m_type)); + CStdString strLog; + strLog.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); + AddLog(CEC_LOG_NOTICE, strLog.c_str()); - lock.Leave(); - return m_processor->Transmit(command); + iPhysicalAddress = m_iPhysicalAddress; + type = m_type; + } + + return m_handler->TransmitPhysicalAddress(m_iLogicalAddress, iPhysicalAddress, type); } bool CCECBusDevice::TransmitPoll(cec_logical_address dest) @@ -768,20 +711,12 @@ bool CCECBusDevice::TransmitPoll(cec_logical_address dest) CStdString strLog; strLog.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest); AddLog(CEC_LOG_NOTICE, strLog.c_str()); - - cec_command command; - cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_NONE); - - { - CLockObject lock(&m_transmitMutex); - bReturn = m_processor->Transmit(command); - } - + bReturn = m_handler->TransmitPoll(m_iLogicalAddress, dest); AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent"); if (bReturn) { - CLockObject lock(&m_mutex); + CLockObject lock(&m_writeMutex); m_iLastActive = GetTimeMs(); } @@ -790,86 +725,52 @@ bool CCECBusDevice::TransmitPoll(cec_logical_address dest) bool CCECBusDevice::TransmitPowerState(cec_logical_address dest) { - CLockObject lock(&m_mutex); - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus)); - AddLog(CEC_LOG_NOTICE, strLog.c_str()); - - cec_command command; - cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_REPORT_POWER_STATUS); - command.parameters.PushBack((uint8_t) m_powerStatus); + cec_power_status state; + { + CLockObject lock(&m_writeMutex); + CStdString strLog; + strLog.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus)); + AddLog(CEC_LOG_NOTICE, strLog.c_str()); + state = m_powerStatus; + } - lock.Leave(); - return m_processor->Transmit(command); + return m_handler->TransmitPowerState(m_iLogicalAddress, dest, state); } bool CCECBusDevice::TransmitVendorID(cec_logical_address dest) { - CLockObject lock(&m_mutex); - if (m_vendor == CEC_VENDOR_UNKNOWN) + uint64_t iVendorId; + { + CLockObject lock(&m_writeMutex); + iVendorId = (uint64_t)m_vendor; + } + + if (iVendorId == CEC_VENDOR_UNKNOWN) { CStdString strLog; strLog.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest); AddLog(CEC_LOG_NOTICE, strLog); - lock.Leave(); m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); return false; } else { CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_vendor), (uint64_t)m_vendor); + strLog.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString((cec_vendor_id)iVendorId), iVendorId); AddLog(CEC_LOG_NOTICE, strLog); - cec_command command; - cec_command::Format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_DEVICE_VENDOR_ID); - - command.parameters.PushBack((uint8_t) (((uint64_t)m_vendor >> 16) & 0xFF)); - command.parameters.PushBack((uint8_t) (((uint64_t)m_vendor >> 8) & 0xFF)); - command.parameters.PushBack((uint8_t) ((uint64_t)m_vendor & 0xFF)); - - lock.Leave(); - return m_processor->Transmit(command); + return m_handler->TransmitVendorID(m_iLogicalAddress, iVendorId); } } -bool CCECBusDevice::SendKeypress(cec_user_control_code key, bool bWait /* = false */) +bool CCECBusDevice::SendKeypress(cec_user_control_code key) { - { - CLockObject lock(&m_transmitMutex); - cec_command command; - cec_command::Format(command, m_processor->GetLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_USER_CONTROL_PRESSED); - command.parameters.PushBack((uint8_t)key); - - if (bWait) - { - if (m_processor->Transmit(command)) - return m_condition.Wait(&m_transmitMutex, 1000); - return false; - } - - return m_processor->Transmit(command); - } + return m_handler->SendKeypress(m_processor->GetLogicalAddress(), m_iLogicalAddress, key); } -bool CCECBusDevice::SendKeyRelease(bool bWait /* = false */) +bool CCECBusDevice::SendKeyRelease(void) { - { - CLockObject lock(&m_transmitMutex); - cec_command command; - cec_command::Format(command, m_processor->GetLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_USER_CONTROL_RELEASE); - - if (bWait) - { - if (m_processor->Transmit(command)) - return m_condition.Wait(&m_transmitMutex, 1000); - return false; - } - else - { - return m_processor->Transmit(command); - } - } + return m_handler->SendKeyRelease(m_processor->GetLogicalAddress(), m_iLogicalAddress); } //@}