cec: don't hold a lock in CCECBusDevice when calling GetStatus()
[deb_libcec.git] / src / lib / devices / CECBusDevice.cpp
index ce0c0869173207df92a639a2b1d06de57a503d3c..59dcb4662d40ba9d813973e8713546a04325f242 100644 (file)
@@ -114,28 +114,13 @@ bool CCECBusDevice::HandleCommand(const cec_command &command)
 bool CCECBusDevice::PowerOn(void)
 {
   bool bReturn(false);
-  GetVendorId(); // ensure that we got the vendor id
+  GetVendorId(); // ensure that we got the vendor id, because the implementations vary per vendor
 
   MarkBusy();
   CLibCEC::AddLog(CEC_LOG_NOTICE, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
   if (m_handler->PowerOn(GetMyLogicalAddress(), m_iLogicalAddress))
   {
-    {
-//      CLockObject lock(m_mutex);
-//      m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
-      SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
-    }
-//    cec_power_status status = GetPowerStatus();
-//    if (status == CEC_POWER_STATUS_STANDBY || status == CEC_POWER_STATUS_UNKNOWN)
-//    {
-//      /* sending the normal power on command appears to have failed */
-//      CStdString strLog;
-//      strLog.Format("<< sending power on keypress to '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
-//      CLibCEC::AddLog(CEC_LOG_DEBUG, strLog.c_str());
-//
-//      TransmitKeypress(CEC_USER_CONTROL_CODE_POWER);
-//      return TransmitKeyRelease();
-//    }
+    SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON);
     bReturn = true;
   }
 
@@ -156,11 +141,12 @@ bool CCECBusDevice::Standby(void)
 //@{
 cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */)
 {
+       bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
   bool bRequestUpdate(false);
   {
     CLockObject lock(m_mutex);
-    bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
-      (bUpdate || m_cecVersion == CEC_VERSION_UNKNOWN));
+    bRequestUpdate = bIsPresent &&
+                       (bUpdate || m_cecVersion == CEC_VERSION_UNKNOWN);
   }
 
   if (bRequestUpdate)
@@ -192,10 +178,11 @@ const char* CCECBusDevice::GetLogicalAddressName(void) const
 
 cec_menu_language &CCECBusDevice::GetMenuLanguage(bool bUpdate /* = false */)
 {
+       bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
   bool bRequestUpdate(false);
   {
     CLockObject lock(m_mutex);
-    bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
+    bRequestUpdate = (bIsPresent &&
         (bUpdate || !strcmp(m_menuLanguage.language, "???")));
   }
 
@@ -239,12 +226,13 @@ uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
 
 CStdString CCECBusDevice::GetOSDName(bool bUpdate /* = false */)
 {
+       bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
   bool bRequestUpdate(false);
   {
     CLockObject lock(m_mutex);
-    bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
+    bRequestUpdate = bIsPresent &&
         (bUpdate || m_strDeviceName.Equals(ToString(m_iLogicalAddress))) &&
-        m_type != CEC_DEVICE_TYPE_TV);
+        m_type != CEC_DEVICE_TYPE_TV;
   }
 
   if (bRequestUpdate)
@@ -271,11 +259,12 @@ bool CCECBusDevice::RequestOSDName(void)
 
 uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate /* = false */)
 {
+       bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
   bool bRequestUpdate(false);
   {
     CLockObject lock(m_mutex);
-    bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
-        (m_iPhysicalAddress == 0xFFFF || bUpdate));
+    bRequestUpdate = bIsPresent &&
+      (m_iPhysicalAddress == 0xFFFF || bUpdate);
   }
 
   if (bRequestUpdate && !RequestPhysicalAddress())
@@ -301,10 +290,11 @@ bool CCECBusDevice::RequestPhysicalAddress(void)
 
 cec_power_status CCECBusDevice::GetPowerStatus(bool bUpdate /* = false */)
 {
+       bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
   bool bRequestUpdate(false);
   {
     CLockObject lock(m_mutex);
-    bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
+    bRequestUpdate = (bIsPresent &&
         (bUpdate || m_powerStatus == CEC_POWER_STATUS_UNKNOWN ||
             m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON ||
             m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY ||
@@ -335,10 +325,11 @@ bool CCECBusDevice::RequestPowerStatus(void)
 
 cec_vendor_id CCECBusDevice::GetVendorId(bool bUpdate /* = false */)
 {
+       bool bIsPresent(GetStatus() == CEC_DEVICE_STATUS_PRESENT);
   bool bRequestUpdate(false);
   {
     CLockObject lock(m_mutex);
-    bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
+    bRequestUpdate = (bIsPresent &&
         (bUpdate || m_vendor == CEC_VENDOR_UNKNOWN));
   }
 
@@ -941,14 +932,12 @@ bool CCECBusDevice::ActivateSource(void)
 
 void CCECBusDevice::HandlePoll(cec_logical_address iDestination)
 {
-  CLockObject lock(m_mutex);
   CLibCEC::AddLog(CEC_LOG_DEBUG, "<< POLL: %s (%x) -> %s (%x)", ToString(m_iLogicalAddress), m_iLogicalAddress, ToString(iDestination), iDestination);
   m_bAwaitingReceiveFailed = true;
 }
 
 bool CCECBusDevice::HandleReceiveFailed(void)
 {
-  CLockObject lock(m_mutex);
   bool bReturn = m_bAwaitingReceiveFailed;
   m_bAwaitingReceiveFailed = false;
   return bReturn;