cec: add GetDevicePhysicalAddress()/cec_get_device_physical_address()
[deb_libcec.git] / src / lib / LibCEC.cpp
index 118be7def567f54c2b3b4d2585b169e1d12c7483..adf0132682213835563ba404429b8f1722a55f53 100644 (file)
@@ -47,8 +47,7 @@ CLibCEC::CLibCEC(const char *strDeviceName, cec_device_type_list types) :
     m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
     m_buttontime(0)
 {
-  m_comm = new CAdapterCommunication(this);
-  m_cec = new CCECProcessor(this, m_comm, strDeviceName, types);
+  m_cec = new CCECProcessor(this, strDeviceName, types);
 }
 
 CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) :
@@ -56,48 +55,24 @@ CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress
     m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
     m_buttontime(0)
 {
-  m_comm = new CAdapterCommunication(this);
-  m_cec = new CCECProcessor(this, m_comm, strDeviceName, iLogicalAddress, iPhysicalAddress);
+  m_cec = new CCECProcessor(this, strDeviceName, iLogicalAddress, iPhysicalAddress);
 }
 
 CLibCEC::~CLibCEC(void)
 {
   Close();
   delete m_cec;
-  delete m_comm;
 }
 
 bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = 10000 */)
 {
-  if (!m_comm)
-  {
-    AddLog(CEC_LOG_ERROR, "no comm port");
-    return false;
-  }
-
-  if (m_comm->IsOpen())
+  if (m_cec->IsRunning())
   {
     AddLog(CEC_LOG_ERROR, "connection already open");
     return false;
   }
 
-  int64_t iNow = GetTimeMs();
-  int64_t iTarget = iNow + iTimeoutMs;
-
-  bool bOpened(false);
-  while (!bOpened && iNow < iTarget)
-  {
-    bOpened = m_comm->Open(strPort, 38400, iTimeoutMs);
-    iNow = GetTimeMs();
-  }
-
-  if (!bOpened)
-  {
-    AddLog(CEC_LOG_ERROR, "could not open a connection");
-    return false;
-  }
-
-  if (!m_cec->Start())
+  if (!m_cec->Start(strPort, 38400, iTimeoutMs))
   {
     AddLog(CEC_LOG_ERROR, "could not start CEC communications");
     return false;
@@ -110,8 +85,6 @@ void CLibCEC::Close(void)
 {
   if (m_cec)
     m_cec->StopThread();
-  if (m_comm)
-    m_comm->Close();
 }
 
 int8_t CLibCEC::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */)
@@ -128,12 +101,12 @@ int8_t CLibCEC::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const ch
 
 bool CLibCEC::PingAdapter(void)
 {
-  return m_comm ? m_comm->PingAdapter() : false;
+  return m_cec ? m_cec->PingAdapter() : false;
 }
 
 bool CLibCEC::StartBootloader(void)
 {
-  return m_comm ? m_comm->StartBootloader() : false;
+  return m_cec ? m_cec->StartBootloader() : false;
 }
 
 bool CLibCEC::GetNextLogMessage(cec_log_message *message)
@@ -171,6 +144,11 @@ bool CLibCEC::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort /* = CE
   return m_cec ? m_cec->SetHDMIPort(iBaseDevice, iPort) : false;
 }
 
+bool CLibCEC::EnablePhysicalAddressDetection(void)
+{
+  return m_cec ? m_cec->EnablePhysicalAddressDetection() : false;
+}
+
 bool CLibCEC::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */)
 {
   return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->m_busDevices[(uint8_t)address]->PowerOn() : false;
@@ -244,6 +222,13 @@ uint64_t CLibCEC::GetDeviceVendorId(cec_logical_address iAddress)
   return 0;
 }
 
+uint16_t CLibCEC::GetDevicePhysicalAddress(cec_logical_address iAddress)
+{
+  if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST)
+    return m_cec->GetDevicePhysicalAddress(iAddress);
+  return 0;
+}
+
 cec_power_status CLibCEC::GetDevicePowerStatus(cec_logical_address iAddress)
 {
   if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST)
@@ -284,14 +269,14 @@ bool CLibCEC::IsActiveDeviceType(cec_device_type type)
 uint8_t CLibCEC::VolumeUp(bool bWait /* = true */)
 {
   if (m_cec)
-    return m_cec->VolumeUp(bWait);
+    return m_cec->VolumeUp();
   return 0;
 }
 
 uint8_t CLibCEC::VolumeDown(bool bWait /* = true */)
 {
   if (m_cec)
-    return m_cec->VolumeDown(bWait);
+    return m_cec->VolumeDown();
   return 0;
 }
 
@@ -299,21 +284,21 @@ uint8_t CLibCEC::VolumeDown(bool bWait /* = true */)
 uint8_t CLibCEC::MuteAudio(bool bWait /* = true */)
 {
   if (m_cec)
-    return m_cec->MuteAudio(bWait);
+    return m_cec->MuteAudio();
   return 0;
 }
 
 bool CLibCEC::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = false */)
 {
   if (m_cec)
-    return m_cec->SendKeypress(iDestination, key, bWait);
+    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, bWait);
+    return m_cec->TransmitKeyRelease(iDestination);
   return false;
 }