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);
- }
-}
-
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;
+ cec_command command;
+ cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_IMAGE_VIEW_ON);
+ if (m_processor->Transmit(command))
+ {
+ RequestPowerStatus();
+ return true;
}
return false;
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;
}
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 (!strcmp(m_menuLanguage.language, "???"))
- {
- lock.Leave();
+ if (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
+ !strcmp(m_menuLanguage.language, "???"))
RequestMenuLanguage();
- lock.Lock();
- }
+
return m_menuLanguage;
}
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)))
+ RequestOSDName();
+
return m_strDeviceName;
}
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;
}
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;
}
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;
}
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();
void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
if (language.device == m_iLogicalAddress)
{
CStdString strLog;
void CCECBusDevice::SetOSDName(CStdString strName)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
if (m_strDeviceName != strName)
{
CStdString strLog;
void CCECBusDevice::SetMenuState(const cec_menu_state state)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
if (m_menuState != state)
{
CStdString strLog;
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)
void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
switch (newStatus)
{
case CEC_DEVICE_STATUS_UNKNOWN:
void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
if (iNewAddress > 0 && m_iPhysicalAddress != iNewAddress)
{
CStdString strLog;
void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
if (iNewAddress > 0)
{
CStdString strLog;
void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
if (m_powerStatus != powerStatus)
{
CStdString strLog;
void CCECBusDevice::SetVendorId(uint64_t iVendorId)
{
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
m_vendor = (cec_vendor_id)iVendorId;
switch (iVendorId)
}
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());
}
//@}
//@{
bool CCECBusDevice::TransmitActiveSource(void)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
if (m_powerStatus != CEC_POWER_STATUS_ON)
{
CStdString strLog;
bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest)
{
- CLockObject lock(&m_mutex);
+ 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);
bool CCECBusDevice::TransmitOSDName(cec_logical_address dest)
{
- CLockObject lock(&m_mutex);
+ 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());
bool CCECBusDevice::TransmitOSDString(cec_logical_address dest, cec_display_control duration, const char *strMessage)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
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());
bool CCECBusDevice::TransmitPhysicalAddress(void)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
CStdString strLog;
strLog.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress);
AddLog(CEC_LOG_NOTICE, strLog.c_str());
if (bReturn)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
m_iLastActive = GetTimeMs();
}
bool CCECBusDevice::TransmitPowerState(cec_logical_address dest)
{
- CLockObject lock(&m_mutex);
+ 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());
bool CCECBusDevice::TransmitVendorID(cec_logical_address dest)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(&m_writeMutex);
if (m_vendor == CEC_VENDOR_UNKNOWN)
{
CStdString strLog;
bool CCECBusDevice::SendKeypress(cec_user_control_code key, bool bWait /* = false */)
{
- {
- 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;
- }
+ 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);
- return m_processor->Transmit(command);
+ if (bWait)
+ {
+ if (m_processor->Transmit(command))
+ return m_condition.Wait(&m_transmitMutex, 1000);
+ return false;
}
+
+ return m_processor->Transmit(command);
}
bool CCECBusDevice::SendKeyRelease(bool bWait /* = false */)
{
- {
- CLockObject lock(&m_transmitMutex);
- cec_command command;
- cec_command::Format(command, m_processor->GetLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_USER_CONTROL_RELEASE);
+ 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);
- }
+ if (bWait)
+ {
+ if (m_processor->Transmit(command))
+ return m_condition.Wait(&m_transmitMutex, 1000);
+ return false;
+ }
+ else
+ {
+ return m_processor->Transmit(command);
}
}
//@}