cec: store the status of a bus device: present, not present or handled by libcec
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 25 Nov 2011 09:34:07 +0000 (10:34 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 25 Nov 2011 09:34:07 +0000 (10:34 +0100)
include/cectypes.h
src/lib/CECProcessor.cpp
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h

index ce042cc94ca212eb06394ca6dcf0cdaaa75b5edb..bc661a8d2d7e1840462af64357337a02cb4de8ec 100644 (file)
@@ -582,6 +582,14 @@ typedef enum cec_adapter_messagecode
   MSGCODE_FRAME_ACK = 0x40,
 } cec_adapter_messagecode;
 
+typedef enum cec_bus_device_status
+{
+  CEC_DEVICE_STATUS_UNKNOWN,
+  CEC_DEVICE_STATUS_PRESENT,
+  CEC_DEVICE_STATUS_NOT_PRESENT,
+  CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
+} cec_bus_device_status;
+
 typedef enum cec_vendor_id
 {
   CEC_VENDOR_SAMSUNG   = 0x00F0,
index a7ff64ca09ea8c42357242b5125c6615b389d14d..cf6405370b1dce2390d7c1b0ba7fc4a843598c24 100644 (file)
@@ -158,6 +158,7 @@ bool CCECProcessor::TryLogicalAddress(cec_logical_address address, unsigned int
     }
     m_busDevices[address]->m_powerStatus = CEC_POWER_STATUS_STANDBY;
     m_busDevices[address]->m_cecVersion =  CEC_VERSION_1_3A;
+    m_busDevices[address]->m_deviceStatus = CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC;
 
     m_logicalAddresses.Set(address);
 
index 1227f8d749c6515f193bcd64fd3bb3fce8042ffd..20fe43b33179b2bf9fd23d3a669ff9a1c50df339 100644 (file)
@@ -54,7 +54,8 @@ CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogi
   m_bActiveSource(false),
   m_iLastCommandSent(0),
   m_iLastActive(0),
-  m_cecVersion(CEC_VERSION_UNKNOWN)
+  m_cecVersion(CEC_VERSION_UNKNOWN),
+  m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN)
 {
   m_handler = new CCECCommandHandler(this);
 
@@ -240,6 +241,20 @@ bool CCECBusDevice::MyLogicalAddressContains(cec_logical_address address) const
   return m_processor->HasLogicalAddress(address);
 }
 
+cec_bus_device_status CCECBusDevice::GetStatus(void)
+{
+  CLockObject lock(&m_mutex);
+  if (m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN)
+  {
+    if (m_processor->PollDevice(m_iLogicalAddress))
+      m_deviceStatus = CEC_DEVICE_STATUS_PRESENT;
+    else
+      m_deviceStatus = CEC_DEVICE_STATUS_NOT_PRESENT;
+  }
+
+  return m_deviceStatus;
+}
+
 //@}
 
 /** @name Setters */
index 748758c0ffdef6c905172674fb74fd7e5aab9a09..d7f4e27460b4b2f1cc8e4c14e1f386bafef49c1b 100644 (file)
@@ -54,22 +54,23 @@ namespace CEC
     virtual bool PowerOn(void);
     virtual bool Standby(void);
 
-    virtual cec_version         GetCecVersion(void);
-    virtual CCECCommandHandler *GetHandler(void) const { return m_handler; };
-    virtual uint64_t            GetCommandSent(void) const { return m_iLastCommandSent; }
-    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_logical_address GetMyLogicalAddress(void) const;
-    virtual uint16_t            GetMyPhysicalAddress(void) const;
-    virtual uint16_t            GetPhysicalAddress(void) const { return m_iPhysicalAddress; }
-    virtual cec_power_status    GetPowerStatus(void);
-    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 bool                MyLogicalAddressContains(cec_logical_address address) const;
+    virtual cec_version           GetCecVersion(void);
+    virtual CCECCommandHandler *  GetHandler(void) const { return m_handler; };
+    virtual uint64_t              GetCommandSent(void) const { return m_iLastCommandSent; }
+    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_logical_address   GetMyLogicalAddress(void) const;
+    virtual uint16_t              GetMyPhysicalAddress(void) const;
+    virtual uint16_t              GetPhysicalAddress(void) const { return m_iPhysicalAddress; }
+    virtual cec_power_status      GetPowerStatus(void);
+    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 bool                  MyLogicalAddressContains(cec_logical_address address) const;
+    virtual cec_bus_device_status GetStatus(void);
 
     virtual void SetInactiveDevice(void);
     virtual void SetActiveDevice(void);
@@ -95,23 +96,24 @@ namespace CEC
     virtual bool TransmitVendorID(cec_logical_address dest);
 
   protected:
-    cec_device_type     m_type;
-    CStdString          m_strDeviceName;
-    uint16_t            m_iPhysicalAddress;
-    uint16_t            m_iStreamPath;
-    cec_logical_address m_iLogicalAddress;
-    cec_power_status    m_powerStatus;
-    cec_menu_language   m_menuLanguage;
-    CCECProcessor      *m_processor;
-    CCECCommandHandler *m_handler;
-    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;
-    CMutex              m_transmitMutex;
-    CMutex              m_mutex;
-    CCondition          m_condition;
+    cec_device_type       m_type;
+    CStdString            m_strDeviceName;
+    uint16_t              m_iPhysicalAddress;
+    uint16_t              m_iStreamPath;
+    cec_logical_address   m_iLogicalAddress;
+    cec_power_status      m_powerStatus;
+    cec_menu_language     m_menuLanguage;
+    CCECProcessor      *  m_processor;
+    CCECCommandHandler *  m_handler;
+    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;
+    CMutex                m_transmitMutex;
+    CMutex                m_mutex;
+    CCondition            m_condition;
   };
 };