cec: ensure that the vendor id is requested first when requesting info from a device...
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 17 Feb 2012 10:23:12 +0000 (11:23 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 17 Feb 2012 10:39:30 +0000 (11:39 +0100)
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h

index 3c393716d0270e81be0265106d8d176b8465eb30..33d472f7acc685f0adadbaf213b51fea867ac06f 100644 (file)
@@ -60,7 +60,8 @@ CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogi
   m_cecVersion(CEC_VERSION_UNKNOWN),
   m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN),
   m_iHandlerUseCount(0),
-  m_bAwaitingReceiveFailed(false)
+  m_bAwaitingReceiveFailed(false),
+  m_bVendorIdRequested(false)
 {
   m_handler = new CCECCommandHandler(this);
 
@@ -160,7 +161,10 @@ cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */)
   }
 
   if (bRequestUpdate)
+  {
+    CheckVendorIdRequested();
     RequestCecVersion();
+  }
 
   CLockObject lock(m_mutex);
   return m_cecVersion;
@@ -198,7 +202,10 @@ cec_menu_language &CCECBusDevice::GetMenuLanguage(bool bUpdate /* = false */)
   }
 
   if (bRequestUpdate)
+  {
+    CheckVendorIdRequested();
     RequestMenuLanguage();
+  }
 
   CLockObject lock(m_mutex);
   return m_menuLanguage;
@@ -247,7 +254,10 @@ CStdString CCECBusDevice::GetOSDName(bool bUpdate /* = false */)
   }
 
   if (bRequestUpdate)
+  {
+    CheckVendorIdRequested();
     RequestOSDName();
+  }
 
   CLockObject lock(m_mutex);
   return m_strDeviceName;
@@ -278,8 +288,12 @@ uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate /* = false */)
       (m_iPhysicalAddress == 0xFFFF || bUpdate);
   }
 
-  if (bRequestUpdate && !RequestPhysicalAddress())
-    CLibCEC::AddLog(CEC_LOG_ERROR, "failed to request the physical address");
+  if (bRequestUpdate)
+  {
+    CheckVendorIdRequested();
+    if (!RequestPhysicalAddress())
+      CLibCEC::AddLog(CEC_LOG_ERROR, "failed to request the physical address");
+  }
 
   CLockObject lock(m_mutex);
   return m_iPhysicalAddress;
@@ -313,7 +327,10 @@ cec_power_status CCECBusDevice::GetPowerStatus(bool bUpdate /* = false */)
   }
 
   if (bRequestUpdate)
+  {
+    CheckVendorIdRequested();
     RequestPowerStatus();
+  }
 
   CLockObject lock(m_mutex);
   return m_powerStatus;
@@ -975,4 +992,20 @@ bool CCECBusDevice::HandleReceiveFailed(void)
   return bReturn;
 }
 
+void CCECBusDevice::CheckVendorIdRequested(void)
+{
+  bool bRequestVendorId(false);
+  {
+    CLockObject lock(m_mutex);
+    bRequestVendorId = !m_bVendorIdRequested;
+    m_bVendorIdRequested = true;
+  }
+
+  if (bRequestVendorId)
+  {
+    ReplaceHandler(false);
+    GetVendorId();
+  }
+}
+
 //@}
index a4350da4bc7f93162d78fc0e5c2c682f7ae8e8ae..5428ec1c8ddbf7f35ed415f5fd159bc742f9bb25 100644 (file)
@@ -109,6 +109,7 @@ namespace CEC
     virtual bool TransmitKeyRelease(bool bWait = true);
 
   protected:
+    void CheckVendorIdRequested(void);
     bool ReplaceHandler(bool bActivateSource = true);
     void MarkBusy(void);
     void MarkReady(void);
@@ -145,5 +146,6 @@ namespace CEC
     PLATFORM::CEvent      m_replacing;
     unsigned              m_iHandlerUseCount;
     bool                  m_bAwaitingReceiveFailed;
+    bool                  m_bVendorIdRequested;
   };
 };