cec: added SetActiveSource()/cec_set_active_source() to the interface. deprecated...
authorLars Op den Kamp <lars@opdenkamp.eu>
Thu, 10 Nov 2011 17:30:00 +0000 (18:30 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Thu, 10 Nov 2011 18:00:40 +0000 (19:00 +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/testclient/main.cpp

index 5c8ce125e9cbe5012d7b26426530d9932d3d69fe..84cd7e6ee92c7d35eb0826f4c826a8493cecf0a6 100644 (file)
@@ -152,9 +152,15 @@ namespace CEC
     virtual bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST) = 0;
 
     /*!
-     * @brief Broadcast a message that notifies connected CEC capable devices that this device is the active source.
+     * @brief Change the active source.
+     * @param type The new active source. Leave empty to use the primary type
      * @return True when the command was sent succesfully, false otherwise.
      */
+    virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED) = 0;
+
+    /*!
+     * @deprecated Use SetActiveSource() instead
+     */
     virtual bool SetActiveView(void) = 0;
 
     /*!
index d8fef4424d4e6426912071b4d989d8fc11c12fff..e4f5fd054d2749511cf9c6184bdeea8b3be73399 100644 (file)
@@ -89,6 +89,12 @@ extern DECLSPEC int cec_standby_devices(cec_logical_address address = CECDEVICE_
 
 extern DECLSPEC int cec_set_active_view(void);
 
+#ifdef __cplusplus
+extern DECLSPEC int cec_set_active_source(CEC::cec_device_type type = CEC::CEC_DEVICE_TYPE_RESERVED);
+#else
+extern DECLSPEC int cec_set_active_source(cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
+#endif
+
 extern DECLSPEC int cec_set_inactive_view(void);
 
 #ifdef __cplusplus
index 6259dae8ef0d6e116035e7f509479a09a3a50373..07592587d6a4134e216bac82540d70bc0bfb3822 100644 (file)
@@ -290,17 +290,33 @@ void *CCECProcessor::Process(void)
   return NULL;
 }
 
-bool CCECProcessor::SetActiveView(void)
+bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
 {
   bool bReturn(false);
 
   if (!IsRunning())
     return bReturn;
 
-  if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary])
-    bReturn = SetStreamPath(m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress());
+  cec_logical_address addr = m_logicalAddresses.primary;
 
-  return bReturn;
+  if (type != CEC_DEVICE_TYPE_RESERVED)
+  {
+    for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+    {
+      if (m_logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
+      {
+        addr = (cec_logical_address) iPtr;
+        break;
+      }
+    }
+  }
+
+  return SetStreamPath(m_busDevices[addr]->GetPhysicalAddress());
+}
+
+bool CCECProcessor::SetActiveView(void)
+{
+  return SetActiveSource();
 }
 
 bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
index 75651d7b5cce73fe667ad6fe43d7e86f4416e1a9..b73b1bbb0995f5c439cf38d90de35e072b9b6cd4 100644 (file)
@@ -69,6 +69,7 @@ namespace CEC
       virtual uint16_t              GetPhysicalAddress(void) const;
 
       virtual bool SetActiveView(void);
+      virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
       virtual bool SetInactiveView(void);
       virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress);
       virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress);
index 7fd3e6c5da3c62948564c04a7d87175da1aa40e0..0959beb57ec98adc3801769e8b56da4fa33b26fa 100644 (file)
@@ -176,6 +176,11 @@ bool CLibCEC::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAS
   return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->m_busDevices[(uint8_t)address]->Standby() : false;
 }
 
+bool CLibCEC::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
+{
+  return m_cec ? m_cec->SetActiveSource(type) : false;
+}
+
 bool CLibCEC::SetActiveView(void)
 {
   return m_cec ? m_cec->SetActiveView() : false;
index 69c5b1890f78488c5838de3ad0711c85feaeb2db..b3477e1068d166c648be485aed6a6aeec9f2ccc8 100644 (file)
@@ -72,6 +72,7 @@ namespace CEC
       virtual bool PowerOnDevices(cec_logical_address address = CECDEVICE_TV);
       virtual bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST);
       virtual bool SetActiveView(void);
+      virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
       virtual bool SetInactiveView(void);
       virtual bool SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage);
       virtual bool SwitchMonitoring(bool bEnable);
index a2e58c509434ce5a4fb37a8408b15b306bcec340..c1250cba7a953aa6432e13b59d4442d92872bf27 100644 (file)
@@ -179,6 +179,13 @@ int cec_set_active_view(void)
   return -1;
 }
 
+int cec_set_active_source(cec_device_type type)
+{
+  if (cec_parser)
+    return cec_parser->SetActiveSource(type) ? 1 : 0;
+  return -1;
+}
+
 int cec_set_inactive_view(void)
 {
   if (cec_parser)
index f16bcbf0404eb8baaacec0cef18662af921530a5..3e67723328f4de77b2590caa794c6159566cc2c5 100644 (file)
@@ -430,7 +430,7 @@ int main (int argc, char *argv[])
   parser->PowerOnDevices(CECDEVICE_TV);
   flush_log(parser);
 
-  parser->SetActiveView();
+  parser->SetActiveSource();
   flush_log(parser);
 
   bool bContinue(true);
@@ -666,8 +666,8 @@ int main (int argc, char *argv[])
           parser->Open(g_strPort.c_str());
           flush_log(parser);
 
-          cout << "setting active view" << endl;
-          parser->SetActiveView();
+          cout << "setting active source" << endl;
+          parser->SetActiveSource();
         }
         else if (command == "h" || command == "help")
         {