cec: added GetActiveSource()/cec_get_active_source() and IsActiveSource()/cec_is_acti...
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 7 Dec 2011 21:48:32 +0000 (22:48 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 7 Dec 2011 21:48:32 +0000 (22:48 +0100)
include/cec.h
include/cecc.h
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/LibCECC.cpp
src/lib/devices/CECBusDevice.h
src/testclient/main.cpp

index c5f0522c20b22d7a255cafeb656e90913f45bef2..98adaf9309b7bc9119122b9eaf2419230deeb95a 100644 (file)
@@ -329,6 +329,19 @@ namespace CEC
      */
     virtual cec_osd_name GetOSDName(cec_logical_address iAddress) = 0;
 
+    /*!
+     * @brief Get the logical address of the device that is currently the active source on the CEC bus.
+     * @return The active source or CECDEVICE_UNKNOWN when unknown.
+     */
+    virtual cec_logical_address GetActiveSource(void) = 0;
+
+    /*!
+     * @brief Check whether a device is currently the active source on the CEC bus.
+     * @param iAddress The address to check.
+     * @return True when it is the active source, false otherwise.
+     */
+    virtual bool IsActiveSource(cec_logical_address iAddress) = 0;
+
     virtual const char *ToString(const cec_menu_state state) = 0;
     virtual const char *ToString(const cec_version version) = 0;
     virtual const char *ToString(const cec_power_status status) = 0;
index 65086068aee6cf76cd6346ad3a1203b216ecef41..f270df7737a53e80ed1e10c44a3f6588ab68cb2d 100644 (file)
@@ -179,6 +179,18 @@ extern DECLSPEC uint16_t cec_get_device_physical_address(CEC::cec_logical_addres
 extern DECLSPEC uint16_t cec_get_device_physical_address(cec_logical_address iLogicalAddress);
 #endif
 
+#ifdef __cplusplus
+extern DECLSPEC CEC::cec_logical_address cec_get_active_source(void);
+#else
+extern DECLSPEC cec_logical_address cec_get_active_source(void);
+#endif
+
+#ifdef __cplusplus
+extern DECLSPEC int cec_is_active_source(CEC::cec_logical_address iAddress);
+#else
+extern DECLSPEC int cec_is_active_source(cec_logical_address iAddress);
+#endif
+
 #ifdef __cplusplus
 extern DECLSPEC CEC::cec_power_status cec_get_device_power_status(CEC::cec_logical_address iLogicalAddress);
 #else
index 46e3419d484c38ddc2a8aea86b9cd99c5157ed92..b07f2ddc72bbfcc6c61d85c440b814bc4707ca20 100644 (file)
@@ -684,6 +684,22 @@ cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddres
   return CEC_POWER_STATUS_UNKNOWN;
 }
 
+cec_logical_address CCECProcessor::GetActiveSource(void)
+{
+  for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
+  {
+    if (m_busDevices[iPtr]->IsActiveSource())
+      return (cec_logical_address)iPtr;
+  }
+
+  return CECDEVICE_UNKNOWN;
+}
+
+bool CCECProcessor::IsActiveSource(cec_logical_address iAddress)
+{
+  return m_busDevices[iAddress]->IsActiveSource();
+}
+
 bool CCECProcessor::Transmit(const cec_command &data)
 {
   bool bReturn(false);
index bdf5233631b69400c5bcae03f9f27ac7eb3b6cf1..d2aa22206b046f3309e51ef22156df42686d10f6 100644 (file)
@@ -75,6 +75,8 @@ namespace CEC
       virtual uint16_t              GetPhysicalAddress(void) const;
       virtual uint64_t              GetLastTransmission(void) const { return m_iLastTransmission; }
       virtual bool                  IsStarted(void) const { return m_bStarted; }
+      virtual cec_logical_address   GetActiveSource(void);
+      virtual bool                  IsActiveSource(cec_logical_address iAddress);
 
       virtual bool SetActiveView(void);
       virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
index adf0132682213835563ba404429b8f1722a55f53..4156954e0acce84bf49f1d969e9c7cc06f9b0faf 100644 (file)
@@ -229,6 +229,18 @@ uint16_t CLibCEC::GetDevicePhysicalAddress(cec_logical_address iAddress)
   return 0;
 }
 
+cec_logical_address CLibCEC::GetActiveSource(void)
+{
+  return m_cec ? m_cec->GetActiveSource() : CECDEVICE_UNKNOWN;
+}
+
+bool CLibCEC::IsActiveSource(cec_logical_address iAddress)
+{
+  if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST)
+    return m_cec->IsActiveSource(iAddress);
+  return false;
+}
+
 cec_power_status CLibCEC::GetDevicePowerStatus(cec_logical_address iAddress)
 {
   if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST)
index 9bff00f28fd4dd5dde5ecdab64182bbcf30971f6..02ea9c29a0f751eee1484b0c8ef46780bfd87fa0 100644 (file)
@@ -96,6 +96,8 @@ namespace CEC
       virtual bool SendKeyRelease(cec_logical_address iDestination, bool bWait = false);
       virtual cec_osd_name GetOSDName(cec_logical_address iAddress);
       virtual bool EnablePhysicalAddressDetection(void);
+      virtual cec_logical_address GetActiveSource(void);
+      virtual bool IsActiveSource(cec_logical_address iAddress);
 
       const char *ToString(const cec_menu_state state);
       const char *ToString(const cec_version version);
index ffa8f5561dfc7fd3c4755c1ac1bf652a5148c0a5..28658cd2697636b4b4899f467ed36f62638f8e80 100644 (file)
@@ -254,6 +254,20 @@ uint16_t cec_get_device_physical_address(cec_logical_address iLogicalAddress)
   return 0;
 }
 
+cec_logical_address cec_get_active_source(void)
+{
+  if (cec_parser)
+    return cec_parser->GetActiveSource();
+  return CECDEVICE_UNKNOWN;
+}
+
+int cec_is_active_source(cec_logical_address iAddress)
+{
+  if (cec_parser)
+    return cec_parser->IsActiveSource(iAddress);
+  return false;
+}
+
 cec_power_status cec_get_device_power_status(cec_logical_address iLogicalAddress)
 {
   if (cec_parser)
index 80576b4b003b81a8c416653d0ff47e20d5fda89d..14f3302952b6cdefcd85a10e943ab2786af6cc21 100644 (file)
@@ -72,6 +72,8 @@ namespace CEC
     virtual const char *          GetVendorName(bool bUpdate = false);
     virtual bool                  MyLogicalAddressContains(cec_logical_address address) const;
     virtual cec_bus_device_status GetStatus(bool bForcePoll = false);
+    virtual bool                  IsActiveSource(void) const { return m_bActiveSource; }
+
 
     virtual void SetInactiveDevice(void);
     virtual void SetActiveDevice(void);
index c1f3bf7536952edcd7f95de304bea5c4012f7d22..e1d0ec849afae866d19c0f29fd62f9649c7d28a7 100644 (file)
@@ -720,6 +720,7 @@ bool ProcessCommandSCAN(ICECAdapter *parser, const string &command, string &argu
     {
       if (addresses[iPtr])
       {
+        bool     bActive          = parser->IsActiveSource((cec_logical_address)iPtr);
         uint16_t iPhysicalAddress = parser->GetDevicePhysicalAddress((cec_logical_address)iPtr);
         uint64_t iVendorId        = parser->GetDeviceVendorId((cec_logical_address)iPtr);
         cec_version iCecVersion   = parser->GetDeviceCecVersion((cec_logical_address)iPtr);
@@ -732,13 +733,14 @@ bool ProcessCommandSCAN(ICECAdapter *parser, const string &command, string &argu
         parser->GetDeviceMenuLanguage((cec_logical_address)iPtr, &lang);
 
         cout << "device #" << (int)iPtr << ": " << parser->ToString((cec_logical_address)iPtr) << endl;
-        cout << "address:      " << strAddr.c_str() << endl;
-        cout << "vendor:       " << parser->ToString((cec_vendor_id)iVendorId) << endl;
-        cout << "osd string:   " << osdName.name << endl;
-        cout << "CEC version:  " << parser->ToString(iCecVersion) << endl;
-        cout << "power status: " << parser->ToString(power) << endl;
+        cout << "address:       " << strAddr.c_str() << endl;
+        cout << "active source: " << (bActive ? "yes" : "no") << endl;
+        cout << "vendor:        " << parser->ToString((cec_vendor_id)iVendorId) << endl;
+        cout << "osd string:    " << osdName.name << endl;
+        cout << "CEC version:   " << parser->ToString(iCecVersion) << endl;
+        cout << "power status:  " << parser->ToString(power) << endl;
         if ((uint8_t)lang.device == iPtr)
-          cout << "language:     " << lang.language << endl;
+          cout << "language:      " << lang.language << endl;
         cout << endl;
       }
     }