cec: added GetOSDName()/cec_get_osd_name(). only request the values we need in CCECPr...
authorLars Op den Kamp <lars@opdenkamp.eu>
Mon, 28 Nov 2011 00:27:49 +0000 (01:27 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Mon, 28 Nov 2011 00:34:21 +0000 (01:34 +0100)
include/cec.h
include/cecc.h
include/cectypes.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.cpp
src/lib/devices/CECBusDevice.h
src/testclient/main.cpp

index 70c17ce5693411d1092bd964521f628836eae89c..9aa944b04fd45e53001a0bc69b35b0229d5f2415 100644 (file)
@@ -307,6 +307,13 @@ namespace CEC
      * @return True when the keypress was acked, false otherwise.
      */
     virtual bool SendKeyRelease(cec_logical_address iDestination, bool bWait = false) = 0;
+
+    /*!
+     * @brief Get the OSD name of a device on the CEC bus.
+     * @param iAddress The device to get the OSD name for.
+     * @return The OSD name.
+     */
+    virtual cec_osd_name GetOSDName(cec_logical_address iAddress) = 0;
   };
 };
 
index 07050bcb5f577f1ee4146fe69bd086cc6bd429df..6c28506cbffa49f08f12db8b42ab8cd7b416b12e 100644 (file)
@@ -205,6 +205,11 @@ extern DECLSPEC int cec_send_key_release(CEC::cec_logical_address iDestination,
 extern DECLSPEC int cec_send_key_release(cec_logical_address iDestination, int bWait);
 #endif
 
+#ifdef __cplusplus
+extern DECLSPEC CEC::cec_osd_name cec_get_osd_name(CEC::cec_logical_address iAddress);
+#else
+extern DECLSPEC cec_osd_name cec_get_osd_name(cec_logical_address iAddress);
+#endif
 
 #ifdef __cplusplus
 };
index 96ac6035f60ee8b12caefe89a8c020a2e123bc94..ede11f4e2f47813f25a0e6cfefdef964f08692eb 100644 (file)
@@ -607,6 +607,12 @@ typedef struct cec_menu_language
   cec_logical_address device;
 } cec_menu_language;
 
+typedef struct cec_osd_name
+{
+  char                name[14];
+  cec_logical_address device;
+} cec_osd_name;
+
 typedef struct cec_log_message
 {
   char          message[1024];
index 7f688dd134295872bc710464921f121d669e5a66..8c95da7294a4fe866115ca6003947f7961fe173a 100644 (file)
@@ -396,9 +396,8 @@ void CCECProcessor::ScanCECBus(void)
     if (device && device->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
     {
       device->GetPhysicalAddress();
-      device->GetVendorId();
       device->GetCecVersion();
-      device->GetPowerStatus();
+      device->GetVendorId();
     }
   }
 }
@@ -580,6 +579,17 @@ cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
   return m_busDevices[iAddress]->GetCecVersion();
 }
 
+cec_osd_name CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress)
+{
+  CStdString strOSDName = m_busDevices[iAddress]->GetOSDName();
+  cec_osd_name retVal;
+
+  snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str());
+  retVal.device = iAddress;
+
+  return retVal;
+}
+
 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
 {
   if (m_busDevices[iAddress])
index 6cd9ba479538cc13c0edc181fe47cabd1a0b7fb8..08a21a6e77a9d9b47c734363b132e308b8d04843 100644 (file)
@@ -62,6 +62,7 @@ namespace CEC
       virtual cec_version           GetDeviceCecVersion(cec_logical_address iAddress);
       virtual bool                  GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language);
       virtual const std::string &   GetDeviceName(void) { return m_strDeviceName; }
+      virtual cec_osd_name          GetDeviceOSDName(cec_logical_address iAddress);
       virtual uint64_t              GetDeviceVendorId(cec_logical_address iAddress);
       virtual cec_power_status      GetDevicePowerStatus(cec_logical_address iAddress);
       virtual cec_logical_address   GetLogicalAddress(void) const { return m_logicalAddresses.primary; }
index 50239bc7e5a6529dfedf7e0d20f8f88b45bb4daa..92f00c32ed855247b8282db441229ae8aed9e8d0 100644 (file)
@@ -316,6 +316,18 @@ bool CLibCEC::SendKeyRelease(cec_logical_address iDestination, bool bWait /* = f
   return false;
 }
 
+cec_osd_name CLibCEC::GetOSDName(cec_logical_address iAddress)
+{
+  cec_osd_name retVal;
+  retVal.device = iAddress;
+  retVal.name[0] = 0;
+
+  if (m_cec)
+    retVal = m_cec->GetDeviceOSDName(iAddress);
+
+  return retVal;
+}
+
 void CLibCEC::AddLog(cec_log_level level, const string &strMessage)
 {
   if (m_cec)
index 050fcc194ab47a403d2ae628a6662a0b19ed0e0a..3d468738107ea1b337111a32e53695b2d45c00a2 100644 (file)
@@ -93,6 +93,7 @@ namespace CEC
       virtual uint8_t MuteAudio(bool bWait = true);
       virtual bool SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = false);
       virtual bool SendKeyRelease(cec_logical_address iDestination, bool bWait = false);
+      virtual cec_osd_name GetOSDName(cec_logical_address iAddress);
     //@}
 
       virtual void AddLog(cec_log_level level, const std::string &strMessage);
index f1e80fa57df5af4491a2b607a6561fe219188717..54b82f9fa6eaca31fce73bda8608ad1bf7ef92fb 100644 (file)
@@ -306,4 +306,16 @@ int cec_send_key_release(cec_logical_address iDestination, int bWait)
   return -1;
 }
 
+cec_osd_name cec_get_osd_name(cec_logical_address iAddress)
+{
+  cec_osd_name retVal;
+  retVal.device = iAddress;
+  retVal.name[0] = 0;
+
+  if (cec_parser)
+    retVal = cec_parser->GetOSDName(iAddress);
+
+  return retVal;
+}
+
 //@}
index b4c11f198e703a6e853ae23e2c551264ff1fa502..52d71df7f245ebf3365105d39a1b5e18f09eb0b0 100644 (file)
@@ -214,6 +214,40 @@ uint16_t CCECBusDevice::GetMyPhysicalAddress(void) const
   return m_processor->GetPhysicalAddress();
 }
 
+CStdString CCECBusDevice::GetOSDName(void)
+{
+  if (GetStatus() == CEC_DEVICE_STATUS_PRESENT)
+  {
+    CLockObject lock(&m_mutex);
+    if (m_strDeviceName.Equals(ToString(m_iLogicalAddress)))
+    {
+      lock.Leave();
+      RequestOSDName();
+      lock.Lock();
+    }
+  }
+
+  CLockObject lock(&m_mutex);
+  return m_strDeviceName;
+}
+
+bool CCECBusDevice::RequestOSDName(void)
+{
+  bool bReturn(false);
+  if (!MyLogicalAddressContains(m_iLogicalAddress))
+  {
+    CStdString strLog;
+    strLog.Format("<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress);
+    AddLog(CEC_LOG_NOTICE, strLog);
+    cec_command command;
+    cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_GIVE_OSD_NAME);
+    CLockObject lock(&m_transmitMutex);
+    if (m_processor->Transmit(command))
+      bReturn = m_condition.Wait(&m_transmitMutex, 1000);
+  }
+  return bReturn;
+}
+
 uint16_t CCECBusDevice::GetPhysicalAddress(bool bRefresh /* = true */)
 {
   if (GetStatus() == CEC_DEVICE_STATUS_PRESENT)
index c86a1f2c8f1f57ad0b0cb1212ebc23e00daa51ed..d8d751cca8fcb120f7774a2119927cab7c51d239 100644 (file)
@@ -63,6 +63,7 @@ namespace CEC
     virtual cec_menu_language &   GetMenuLanguage(void);
     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 CCECProcessor *       GetProcessor(void) const { return m_processor; }
@@ -77,6 +78,7 @@ namespace CEC
     bool RequestPowerStatus(void);
     bool RequestVendorId(void);
     bool RequestPhysicalAddress(void);
+    bool RequestOSDName(void);
 
     virtual void SetInactiveDevice(void);
     virtual void SetActiveDevice(void);
index d9ad277d3e68cb4fd3deeab6fd5deafde0c81d8e..d8daa8d7d8dc5691f89e486e1007958059fd9c48 100644 (file)
@@ -233,6 +233,7 @@ void ShowHelpConsole(void)
   "[ven] {addr}              get the vendor ID of the specified device." << endl <<
   "[lang] {addr}             get the menu language of the specified device." << endl <<
   "[pow] {addr}              get the power status of the specified device." << endl <<
+  "[name] {addr}             get the OSD name of the specified device." << endl <<
   "[poll] {addr}             poll the specified device." << endl <<
   "[lad]                     lists active devices on the bus" << endl <<
   "[ad] {addr}               checks whether the specified device is active." << endl <<
@@ -720,6 +721,19 @@ int main (int argc, char *argv[])
             }
           }
         }
+        else if (command == "name")
+        {
+          CStdString strDev;
+          if (GetWord(input, strDev))
+          {
+            int iDev = atoi(strDev);
+            if (iDev >= 0 && iDev < 15)
+            {
+              cec_osd_name name = parser->GetOSDName((cec_logical_address)iDev);
+              cout << "OSD name of device " << iDev << " is '" << name.name << "'" << endl;
+            }
+          }
+        }
         else if (command == "lad")
         {
           cout << "listing active devices:" << endl;