cec: added SetActiveSource()/cec_set_active_source() to the interface. deprecated...
[deb_libcec.git] / src / lib / LibCEC.cpp
index 0c4b89de220d0a7ebff81bc0f4e5189d20a84718..0959beb57ec98adc3801769e8b56da4fa33b26fa 100644 (file)
 #include "AdapterCommunication.h"
 #include "AdapterDetection.h"
 #include "CECProcessor.h"
+#include "devices/CECBusDevice.h"
 #include "util/StdString.h"
 #include "platform/timeutils.h"
 
 using namespace std;
 using namespace CEC;
 
+CLibCEC::CLibCEC(const char *strDeviceName, cec_device_type_list types) :
+    m_iStartTime(GetTimeMs()),
+    m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
+    m_buttontime(0)
+{
+  m_comm = new CAdapterCommunication(this);
+  m_cec = new CCECProcessor(this, m_comm, strDeviceName, types);
+}
+
 CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) :
     m_iStartTime(GetTimeMs()),
     m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
@@ -54,14 +64,7 @@ CLibCEC::~CLibCEC(void)
 {
   Close();
   delete m_cec;
-  m_cec = NULL;
-
   delete m_comm;
-  m_comm = NULL;
-
-  m_logBuffer.Clear();
-  m_keyBuffer.Clear();
-  m_commandBuffer.Clear();
 }
 
 bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = 10000 */)
@@ -133,16 +136,6 @@ bool CLibCEC::StartBootloader(void)
   return m_comm ? m_comm->StartBootloader() : false;
 }
 
-int8_t CLibCEC::GetMinVersion(void)
-{
-  return CEC_MIN_VERSION;
-}
-
-int8_t CLibCEC::GetLibVersion(void)
-{
-  return CEC_LIB_VERSION;
-}
-
 bool CLibCEC::GetNextLogMessage(cec_log_message *message)
 {
   return (m_logBuffer.Pop(*message));
@@ -158,9 +151,9 @@ bool CLibCEC::GetNextCommand(cec_command *command)
   return m_commandBuffer.Pop(*command);
 }
 
-bool CLibCEC::Transmit(const cec_command &data, bool bWaitForAck /* = true */)
+bool CLibCEC::Transmit(const cec_command &data)
 {
-  return m_cec ? m_cec->Transmit(data, bWaitForAck) : false;
+  return m_cec ? m_cec->Transmit(data) : false;
 }
 
 bool CLibCEC::SetLogicalAddress(cec_logical_address iLogicalAddress)
@@ -168,14 +161,24 @@ bool CLibCEC::SetLogicalAddress(cec_logical_address iLogicalAddress)
   return m_cec ? m_cec->SetLogicalAddress(iLogicalAddress) : false;
 }
 
+bool CLibCEC::SetPhysicalAddress(uint16_t iPhysicalAddress)
+{
+  return m_cec ? m_cec->SetPhysicalAddress(iPhysicalAddress) : false;
+}
+
 bool CLibCEC::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */)
 {
-  return m_cec ? m_cec->PowerOnDevices(address) : false;
+  return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->m_busDevices[(uint8_t)address]->PowerOn() : false;
 }
 
 bool CLibCEC::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
 {
-  return m_cec ? m_cec->StandbyDevices(address) : false;
+  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)
@@ -188,6 +191,53 @@ bool CLibCEC::SetInactiveView(void)
   return m_cec ? m_cec->SetInactiveView() : false;
 }
 
+bool CLibCEC::SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage)
+{
+  return m_cec && iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST ?
+      m_cec->m_busDevices[m_cec->GetLogicalAddress()]->TransmitOSDString(iLogicalAddress, duration, strMessage) :
+      false;
+}
+
+bool CLibCEC::SwitchMonitoring(bool bEnable)
+{
+  return m_cec ? m_cec->SwitchMonitoring(bEnable) : false;
+}
+
+cec_version CLibCEC::GetDeviceCecVersion(cec_logical_address iAddress)
+{
+  if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST)
+    return m_cec->GetDeviceCecVersion(iAddress);
+  return CEC_VERSION_UNKNOWN;
+}
+
+bool CLibCEC::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
+{
+  if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST)
+    return m_cec->GetDeviceMenuLanguage(iAddress, language);
+  return false;
+}
+
+uint64_t CLibCEC::GetDeviceVendorId(cec_logical_address iAddress)
+{
+  if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST)
+    return m_cec->GetDeviceVendorId(iAddress);
+  return 0;
+}
+
+cec_power_status CLibCEC::GetDevicePowerStatus(cec_logical_address iAddress)
+{
+  if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST)
+    return m_cec->GetDevicePowerStatus(iAddress);
+  return CEC_POWER_STATUS_UNKNOWN;
+}
+
+bool CLibCEC::PollDevice(cec_logical_address iAddress)
+{
+  if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST)
+    return m_cec->PollDevice(iAddress);
+  return false;
+}
+
 void CLibCEC::AddLog(cec_log_level level, const string &strMessage)
 {
   if (m_cec)
@@ -200,6 +250,13 @@ void CLibCEC::AddLog(cec_log_level level, const string &strMessage)
   }
 }
 
+void CLibCEC::AddKey(cec_keypress &key)
+{
+  m_keyBuffer.Push(key);
+  m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
+  m_buttontime = 0;
+}
+
 void CLibCEC::AddKey(void)
 {
   if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN)
@@ -210,11 +267,11 @@ void CLibCEC::AddKey(void)
     key.keycode = m_iCurrentButton;
     m_keyBuffer.Push(key);
     m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
-    m_buttontime = 0;
   }
+  m_buttontime = 0;
 }
 
-void CLibCEC::AddCommand(cec_command &command)
+void CLibCEC::AddCommand(const cec_command &command)
 {
   if (m_commandBuffer.Push(command))
   {
@@ -241,6 +298,13 @@ void CLibCEC::SetCurrentButton(cec_user_control_code iButtonCode)
 {
   m_iCurrentButton = iButtonCode;
   m_buttontime = GetTimeMs();
+
+  /* push keypress to the keybuffer with 0 duration.
+     push another press to the keybuffer with the duration set when the button is released */
+  cec_keypress key;
+  key.duration = 0;
+  key.keycode = m_iCurrentButton;
+  m_keyBuffer.Push(key);
 }
 
 void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /*= CEC::CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
@@ -248,6 +312,11 @@ void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAdd
   return static_cast< void* > (new CLibCEC(strDeviceName, iLogicalAddress, iPhysicalAddress));
 }
 
+void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types)
+{
+  return static_cast< void* > (new CLibCEC(strDeviceName, types));
+}
+
 void CECDestroy(CEC::ICECAdapter *instance)
 {
   CLibCEC *lib = static_cast< CLibCEC* > (instance);