cec: couple of cleanups. don't refresh the vendorid when not needed. refresh the...
authorLars Op den Kamp <lars@opdenkamp.eu>
Mon, 5 Dec 2011 22:45:44 +0000 (23:45 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Mon, 5 Dec 2011 22:45:44 +0000 (23:45 +0100)
src/LibCecSharp/LibCecSharp.cpp
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/devices/CECAudioSystem.cpp
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h
src/lib/implementations/CECCommandHandler.cpp
src/lib/implementations/CECCommandHandler.h

index 03c0009cea20e7bc51dd1d26449eb1ffac5417dd..707248a920a3e1464ee22ec6d679b93c979463c1 100644 (file)
@@ -666,14 +666,14 @@ public:
     return m_libCec->MuteAudio(wait);
   }
 
-  bool SendKeypress(CecLogicalAddress destination, CecUserControlCode key, bool wait)
+  bool TransmitKeypress(CecLogicalAddress destination, CecUserControlCode key, bool wait)
   {
-    return m_libCec->SendKeypress((cec_logical_address)destination, (cec_user_control_code)key, wait);
+    return m_libCec->TransmitKeypress((cec_logical_address)destination, (cec_user_control_code)key, wait);
   }
 
-  bool SendKeyRelease(CecLogicalAddress destination, bool wait)
+  bool TransmitKeyRelease(CecLogicalAddress destination, bool wait)
   {
-    return m_libCec->SendKeyRelease((cec_logical_address)destination, wait);
+    return m_libCec->TransmitKeyRelease((cec_logical_address)destination, wait);
   }
 
   String ^ GetOSDName(CecLogicalAddress logicalAddress)
index 81f501bf752c0183e906d31fd59ed6adb7818575..af45f9a653b04843f8f8c284b8e782527a186f49 100644 (file)
@@ -952,14 +952,14 @@ bool CCECProcessor::SetAckMask(uint16_t iMask)
   return bReturn;
 }
 
-bool CCECProcessor::SendKeypress(cec_logical_address iDestination, cec_user_control_code key)
+bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination, cec_user_control_code key)
 {
-  return m_busDevices[iDestination]->SendKeypress(key);
+  return m_busDevices[iDestination]->TransmitKeypress(key);
 }
 
-bool CCECProcessor::SendKeyRelease(cec_logical_address iDestination)
+bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination)
 {
-  return m_busDevices[iDestination]->SendKeyRelease();
+  return m_busDevices[iDestination]->TransmitKeyRelease();
 }
 
 const char *CCECProcessor::ToString(const cec_menu_state state)
@@ -1297,8 +1297,15 @@ void *CCECBusScan::Process(void)
         if (device && device->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT)
         {
           if (!IsStopped())
+          {
             device->GetVendorId();
-          Sleep(5);
+            Sleep(5);
+          }
+          if (!IsStopped())
+          {
+            device->GetPowerStatus(true);
+            Sleep(5);
+          }
         }
       }
     }
index 2a8a589f92108d057699e6e369cb342fa6d507e5..b725119ce4c707cddf07965193caa17eb7d70292 100644 (file)
@@ -89,8 +89,8 @@ namespace CEC
       virtual uint8_t VolumeUp(void);
       virtual uint8_t VolumeDown(void);
       virtual uint8_t MuteAudio(void);
-      virtual bool SendKeypress(cec_logical_address iDestination, cec_user_control_code key);
-      virtual bool SendKeyRelease(cec_logical_address iDestination);
+      virtual bool TransmitKeypress(cec_logical_address iDestination, cec_user_control_code key);
+      virtual bool TransmitKeyRelease(cec_logical_address iDestination);
       virtual bool EnablePhysicalAddressDetection(void) { return false; };
       void SetStandardLineTimeout(uint8_t iTimeout);
       void SetRetryLineTimeout(uint8_t iTimeout);
index 3ed7ace2b6946491be9ad45ae9dfbe2f6dfcca17..ebaae2db4584f4f04693adced24a9fc3fdf2f8ee 100644 (file)
@@ -284,14 +284,14 @@ uint8_t CLibCEC::MuteAudio(bool bWait /* = true */)
 bool CLibCEC::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = false */)
 {
   if (m_cec)
-    return m_cec->SendKeypress(iDestination, key);
+    return m_cec->TransmitKeypress(iDestination, key);
   return false;
 }
 
 bool CLibCEC::SendKeyRelease(cec_logical_address iDestination, bool bWait /* = false */)
 {
   if (m_cec)
-    return m_cec->SendKeyRelease(iDestination);
+    return m_cec->TransmitKeyRelease(iDestination);
   return false;
 }
 
index 38bdb47cbea23becd2f89ab61ec0d7748baa4200..81a92c39a90707db6bb0e7afed9572b024bf01ab 100644 (file)
@@ -122,8 +122,8 @@ bool CCECAudioSystem::TransmitSystemAudioModeStatus(cec_logical_address dest)
 
 uint8_t CCECAudioSystem::VolumeUp(void)
 {
-  if (SendKeypress(CEC_USER_CONTROL_CODE_VOLUME_UP))
-    SendKeyRelease();
+  if (TransmitKeypress(CEC_USER_CONTROL_CODE_VOLUME_UP))
+    TransmitKeyRelease();
 
   CLockObject lock(&m_mutex);
   return m_audioStatus;
@@ -131,8 +131,8 @@ uint8_t CCECAudioSystem::VolumeUp(void)
 
 uint8_t CCECAudioSystem::VolumeDown(void)
 {
-  if (SendKeypress(CEC_USER_CONTROL_CODE_VOLUME_DOWN))
-    SendKeyRelease();
+  if (TransmitKeypress(CEC_USER_CONTROL_CODE_VOLUME_DOWN))
+    TransmitKeyRelease();
 
   CLockObject lock(&m_mutex);
   return m_audioStatus;
@@ -140,8 +140,8 @@ uint8_t CCECAudioSystem::VolumeDown(void)
 
 uint8_t CCECAudioSystem::MuteAudio(void)
 {
-  if (SendKeypress(CEC_USER_CONTROL_CODE_MUTE))
-    SendKeyRelease();
+  if (TransmitKeypress(CEC_USER_CONTROL_CODE_MUTE))
+    TransmitKeyRelease();
 
   CLockObject lock(&m_mutex);
   return m_audioStatus;
index a794dc0e407b4d5308bb725afd8d79b130cd406b..5deeddf0649c2b2a2622541959630b3dfbcd7673 100644 (file)
@@ -52,7 +52,6 @@ CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogi
   m_vendor(CEC_VENDOR_UNKNOWN),
   m_menuState(CEC_MENU_STATE_ACTIVATED),
   m_bActiveSource(false),
-  m_iLastCommandSent(0),
   m_iLastActive(0),
   m_cecVersion(CEC_VERSION_UNKNOWN),
   m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN)
@@ -79,13 +78,19 @@ void CCECBusDevice::AddLog(cec_log_level level, const CStdString &strMessage)
 
 bool CCECBusDevice::HandleCommand(const cec_command &command)
 {
+  bool bHandled(false);
+
+  /* update "last active" */
   {
     CLockObject lock(&m_writeMutex);
     m_iLastActive = GetTimeMs();
   }
 
-  m_handler->HandleCommand(command);
+  /* handle the command */
+  bHandled = m_handler->HandleCommand(command);
 
+  /* change status to present */
+  if (bHandled)
   {
     CLockObject lock(&m_writeMutex);
     if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC)
@@ -99,7 +104,8 @@ bool CCECBusDevice::HandleCommand(const cec_command &command)
       m_deviceStatus = CEC_DEVICE_STATUS_PRESENT;
     }
   }
-  return true;
+
+  return bHandled;
 }
 
 bool CCECBusDevice::PowerOn(void)
@@ -117,8 +123,13 @@ bool CCECBusDevice::PowerOn(void)
     cec_power_status status = GetPowerStatus();
     if (status == CEC_POWER_STATUS_STANDBY || status == CEC_POWER_STATUS_UNKNOWN)
     {
-      SendKeypress(CEC_USER_CONTROL_CODE_POWER);
-      return SendKeyRelease();
+      /* sending the normal power on command appears to have failed */
+      CStdString strLog;
+      strLog.Format("<< sending power on keypress to '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
+      AddLog(CEC_LOG_DEBUG, strLog.c_str());
+
+      TransmitKeypress(CEC_USER_CONTROL_CODE_POWER);
+      return TransmitKeyRelease();
     }
     return true;
   }
@@ -137,11 +148,11 @@ bool CCECBusDevice::Standby(void)
 
 /** @name Getters */
 //@{
-cec_version CCECBusDevice::GetCecVersion(void)
+cec_version CCECBusDevice::GetCecVersion(bool bUpdate /* = false */)
 {
   CLockObject lock(&m_mutex);
   if (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
-      m_cecVersion == CEC_VERSION_UNKNOWN)
+      (bUpdate || m_cecVersion == CEC_VERSION_UNKNOWN))
     RequestCecVersion();
 
   return m_cecVersion;
@@ -161,21 +172,16 @@ bool CCECBusDevice::RequestCecVersion(void)
   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)
+cec_menu_language &CCECBusDevice::GetMenuLanguage(bool bUpdate /* = false */)
 {
   CLockObject lock(&m_mutex);
   if (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
-      !strcmp(m_menuLanguage.language, "???"))
+      (bUpdate || !strcmp(m_menuLanguage.language, "???")))
     RequestMenuLanguage();
 
   return m_menuLanguage;
@@ -204,11 +210,11 @@ uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
   return m_processor->GetPhysicalAddress();
 }
 
-CStdString CCECBusDevice::GetOSDName(void)
+CStdString CCECBusDevice::GetOSDName(bool bUpdate /* = false */)
 {
   CLockObject lock(&m_mutex);
   if (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
-      m_strDeviceName.Equals(ToString(m_iLogicalAddress)) &&
+      (bUpdate || m_strDeviceName.Equals(ToString(m_iLogicalAddress))) &&
       m_type != CEC_DEVICE_TYPE_TV)
     RequestOSDName();
 
@@ -228,11 +234,11 @@ bool CCECBusDevice::RequestOSDName(void)
   return bReturn;
 }
 
-uint16_t CCECBusDevice::GetPhysicalAddress(bool bRefresh /* = true */)
+uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate /* = false */)
 {
   CLockObject lock(&m_mutex);
   if (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
-      (m_iPhysicalAddress == 0xFFFF || bRefresh))
+      (m_iPhysicalAddress == 0xFFFF || bUpdate))
   {
     if (!RequestPhysicalAddress())
       AddLog(CEC_LOG_ERROR, "failed to request the physical address");
@@ -254,11 +260,11 @@ bool CCECBusDevice::RequestPhysicalAddress(void)
   return bReturn;
 }
 
-cec_power_status CCECBusDevice::GetPowerStatus(void)
+cec_power_status CCECBusDevice::GetPowerStatus(bool bUpdate /* = false */)
 {
   CLockObject lock(&m_mutex);
   if (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
-      m_powerStatus == CEC_POWER_STATUS_UNKNOWN)
+      (bUpdate || m_powerStatus == CEC_POWER_STATUS_UNKNOWN))
     RequestPowerStatus();
 
   return m_powerStatus;
@@ -277,11 +283,11 @@ bool CCECBusDevice::RequestPowerStatus(void)
   return bReturn;
 }
 
-cec_vendor_id CCECBusDevice::GetVendorId(void)
+cec_vendor_id CCECBusDevice::GetVendorId(bool bUpdate /* = false */)
 {
   CLockObject lock(&m_mutex);
   if (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
-      m_vendor == CEC_VENDOR_UNKNOWN)
+      (bUpdate || m_vendor == CEC_VENDOR_UNKNOWN))
     RequestVendorId();
 
   return m_vendor;
@@ -300,9 +306,9 @@ bool CCECBusDevice::RequestVendorId(void)
   return bReturn;
 }
 
-const char *CCECBusDevice::GetVendorName(void)
+const char *CCECBusDevice::GetVendorName(bool bUpdate /* = false */)
 {
-  return ToString(GetVendorId());
+  return ToString(GetVendorId(bUpdate));
 }
 
 bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address) const
@@ -474,7 +480,6 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
     m_vendor           = CEC_VENDOR_UNKNOWN;
     m_menuState        = CEC_MENU_STATE_ACTIVATED;
     m_bActiveSource    = false;
-    m_iLastCommandSent = 0;
     m_iLastActive      = 0;
     m_cecVersion       = CEC_VERSION_UNKNOWN;
     m_deviceStatus     = newStatus;
@@ -485,7 +490,6 @@ void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
     m_vendor           = CEC_VENDOR_UNKNOWN;
     m_menuState        = CEC_MENU_STATE_ACTIVATED;
     m_bActiveSource    = false;
-    m_iLastCommandSent = 0;
     m_iLastActive      = 0;
     m_cecVersion       = CEC_VERSION_1_3A;
     m_deviceStatus     = newStatus;
@@ -764,13 +768,13 @@ bool CCECBusDevice::TransmitVendorID(cec_logical_address dest)
   }
 }
 
-bool CCECBusDevice::SendKeypress(cec_user_control_code key)
+bool CCECBusDevice::TransmitKeypress(cec_user_control_code key)
 {
-  return m_handler->SendKeypress(m_processor->GetLogicalAddress(), m_iLogicalAddress, key);
+  return m_handler->TransmitKeypress(m_processor->GetLogicalAddress(), m_iLogicalAddress, key);
 }
 
-bool CCECBusDevice::SendKeyRelease(void)
+bool CCECBusDevice::TransmitKeyRelease(void)
 {
-  return m_handler->SendKeyRelease(m_processor->GetLogicalAddress(), m_iLogicalAddress);
+  return m_handler->TransmitKeyRelease(m_processor->GetLogicalAddress(), m_iLogicalAddress);
 }
 //@}
index 98e9431aa8adee0487feb120708cd03da0233f50..6806df07adf35c7756a554379afe674946227eed 100644 (file)
@@ -53,32 +53,24 @@ namespace CEC
     virtual bool PowerOn(void);
     virtual bool Standby(void);
 
-    virtual cec_version           GetCecVersion(void);
+    virtual cec_version           GetCecVersion(bool bUpdate = false);
     virtual CCECCommandHandler *  GetHandler(void) const { return m_handler; };
-    virtual uint64_t              GetLastCommandSent(void) const;
     virtual uint64_t              GetLastActive(void) const { return m_iLastActive; }
     virtual cec_logical_address   GetLogicalAddress(void) const { return m_iLogicalAddress; }
     virtual const char*           GetLogicalAddressName(void) const;
-    virtual cec_menu_language &   GetMenuLanguage(void);
+    virtual cec_menu_language &   GetMenuLanguage(bool bUpdate = false);
     virtual cec_logical_address   GetMyLogicalAddress(void) const;
     virtual uint16_t              GetMyPhysicalAddress(void) const;
-    virtual CStdString            GetOSDName(void);
-    virtual uint16_t              GetPhysicalAddress(bool bRefresh = true);
-    virtual cec_power_status      GetPowerStatus(void);
+    virtual CStdString            GetOSDName(bool bUpdate = false);
+    virtual uint16_t              GetPhysicalAddress(bool bUpdate = false);
+    virtual cec_power_status      GetPowerStatus(bool bUpdate = false);
     virtual CCECProcessor *       GetProcessor(void) const { return m_processor; }
     virtual cec_device_type       GetType(void) const { return m_type; }
-    virtual cec_vendor_id         GetVendorId(void);
-    virtual const char *          GetVendorName(void);
+    virtual cec_vendor_id         GetVendorId(bool bUpdate = false);
+    virtual const char *          GetVendorName(bool bUpdate = false);
     virtual bool                  MyLogicalAddressContains(cec_logical_address address) const;
     virtual cec_bus_device_status GetStatus(bool bForcePoll = false);
 
-    bool RequestCecVersion(void);
-    bool RequestMenuLanguage(void);
-    bool RequestPowerStatus(void);
-    bool RequestVendorId(void);
-    bool RequestPhysicalAddress(void);
-    bool RequestOSDName(void);
-
     virtual void SetInactiveDevice(void);
     virtual void SetActiveDevice(void);
     virtual bool TryLogicalAddress(void);
@@ -103,10 +95,17 @@ namespace CEC
     virtual bool TransmitPowerState(cec_logical_address dest);
     virtual bool TransmitPoll(cec_logical_address dest);
     virtual bool TransmitVendorID(cec_logical_address dest);
-    virtual bool SendKeypress(cec_user_control_code key);
-    virtual bool SendKeyRelease(void);
+    virtual bool TransmitKeypress(cec_user_control_code key);
+    virtual bool TransmitKeyRelease(void);
 
   protected:
+    bool RequestCecVersion(void);
+    bool RequestMenuLanguage(void);
+    bool RequestPowerStatus(void);
+    bool RequestVendorId(void);
+    bool RequestPhysicalAddress(void);
+    bool RequestOSDName(void);
+
     bool NeedsPoll(void);
 
     cec_device_type       m_type;
@@ -121,7 +120,6 @@ namespace CEC
     cec_vendor_id         m_vendor;
     cec_menu_state        m_menuState;
     bool                  m_bActiveSource;
-    uint64_t              m_iLastCommandSent;
     uint64_t              m_iLastActive;
     cec_version           m_cecVersion;
     cec_bus_device_status m_deviceStatus;
index 8e62eaa2c7be982c96e504255de9faa99b1f2ee9..47a0b0ec0fe5a4ed5d35fc27d79ac1ab19e840cf 100644 (file)
@@ -874,7 +874,7 @@ bool CCECCommandHandler::TransmitDeckStatus(const cec_logical_address iInitiator
   return Transmit(command);
 }
 
-bool CCECCommandHandler::SendKeypress(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_user_control_code key)
+bool CCECCommandHandler::TransmitKeypress(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_user_control_code key)
 {
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_PRESSED, m_iTransmitTimeout);
@@ -883,7 +883,7 @@ bool CCECCommandHandler::SendKeypress(const cec_logical_address iInitiator, cons
   return Transmit(command);
 }
 
-bool CCECCommandHandler::SendKeyRelease(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+bool CCECCommandHandler::TransmitKeyRelease(const cec_logical_address iInitiator, const cec_logical_address iDestination)
 {
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_RELEASE, m_iTransmitTimeout);
index 58dc67e2cd73cf90b783d9a00ce8ce375cb845f4..15ab55278deebb70f2ada61392ae42bf7c29e1af 100644 (file)
@@ -76,8 +76,8 @@ namespace CEC
     virtual bool TransmitSetSystemAudioMode(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state);
     virtual bool TransmitSystemAudioModeStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state);
     virtual bool TransmitDeckStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_deck_info state);
-    virtual bool SendKeypress(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_user_control_code key);
-    virtual bool SendKeyRelease(const cec_logical_address iInitiator, const cec_logical_address iDestination);
+    virtual bool TransmitKeypress(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_user_control_code key);
+    virtual bool TransmitKeyRelease(const cec_logical_address iInitiator, const cec_logical_address iDestination);
 
   protected:
     virtual bool HandleActiveSource(const cec_command &command);