+ if (g_libCEC_instance)
+ delete g_libCEC_instance;
+ g_libCEC_instance = instance;
+}
+
+void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types, uint16_t UNUSED(iPhysicalAddress) /* = 0 */)
+{
+ CLibCEC *lib = new CLibCEC(strDeviceName, types);
+ CLibCEC::SetInstance(lib);
+ return static_cast< void* > (lib);
+}
+
+void * CECInitialise(libcec_configuration *configuration)
+{
+ CLibCEC *lib = new CLibCEC(configuration);
+ CLibCEC::SetInstance(lib);
+ return static_cast< void* > (lib);
+}
+
+bool CECStartBootloader(void)
+{
+ bool bReturn(false);
+ cec_adapter deviceList[1];
+ if (CUSBCECAdapterDetection::FindAdapters(deviceList, 1) > 0)
+ {
+ CUSBCECAdapterCommunication comm(NULL, deviceList[0].comm);
+ CTimeout timeout(10000);
+ while (timeout.TimeLeft() > 0 && (bReturn = comm.Open(NULL, (timeout.TimeLeft() / CEC_CONNECT_TRIES)), true) == false)
+ {
+ comm.Close();
+ CEvent::Sleep(500);
+ }
+ if (comm.IsOpen())
+ bReturn = comm.StartBootloader();
+ }
+
+ return bReturn;
+}
+
+void CECDestroy(CEC::ICECAdapter *UNUSED(instance))
+{
+ CLibCEC::SetInstance(NULL);
+}
+
+const char *CLibCEC::ToString(const cec_menu_state state)
+{
+ return m_cec->ToString(state);
+}
+
+const char *CLibCEC::ToString(const cec_version version)
+{
+ return m_cec->ToString(version);
+}
+
+const char *CLibCEC::ToString(const cec_power_status status)
+{
+ return m_cec->ToString(status);
+}
+
+const char *CLibCEC::ToString(const cec_logical_address address)
+{
+ return m_cec->ToString(address);
+}
+
+const char *CLibCEC::ToString(const cec_deck_control_mode mode)
+{
+ return m_cec->ToString(mode);
+}
+
+const char *CLibCEC::ToString(const cec_deck_info status)
+{
+ return m_cec->ToString(status);
+}
+
+const char *CLibCEC::ToString(const cec_opcode opcode)
+{
+ return m_cec->ToString(opcode);
+}
+
+const char *CLibCEC::ToString(const cec_system_audio_status mode)
+{
+ return m_cec->ToString(mode);
+}
+
+const char *CLibCEC::ToString(const cec_audio_status status)
+{
+ return m_cec->ToString(status);
+}
+
+const char *CLibCEC::ToString(const cec_vendor_id vendor)
+{
+ return m_cec->ToString(vendor);
+}
+
+const char *CLibCEC::ToString(const cec_client_version version)
+{
+ return m_cec->ToString(version);
+}
+
+const char *CLibCEC::ToString(const cec_server_version version)
+{
+ return m_cec->ToString(version);
+}
+
+bool CLibCEC::GetCurrentConfiguration(libcec_configuration *configuration)
+{
+ return m_cec->IsInitialised() && m_cec->GetCurrentConfiguration(configuration);
+}
+
+bool CLibCEC::SetConfiguration(const libcec_configuration *configuration)
+{
+ return m_cec->SetConfiguration(configuration);
+}
+
+bool CLibCEC::CanPersistConfiguration(void)
+{
+ return m_cec->CanPersistConfiguration();
+}
+
+bool CLibCEC::PersistConfiguration(libcec_configuration *configuration)
+{
+ return m_cec->PersistConfiguration(configuration);
+}
+
+void CLibCEC::RescanActiveDevices(void)
+{
+ return m_cec->RescanActiveDevices();
+}
+
+bool CLibCEC::IsLibCECActiveSource(void)
+{
+ bool bReturn(false);
+ if (m_cec)
+ {
+ cec_logical_address activeSource = m_cec->GetActiveSource();
+ if (activeSource != CECDEVICE_UNKNOWN)
+ bReturn = m_cec->m_busDevices[activeSource]->GetStatus(false) == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC;
+ }
+ return bReturn;
+}
+
+cec_device_type CLibCEC::GetType(cec_logical_address address)
+{
+ switch (address)
+ {
+ case CECDEVICE_AUDIOSYSTEM:
+ return CEC_DEVICE_TYPE_AUDIO_SYSTEM;
+ case CECDEVICE_PLAYBACKDEVICE1:
+ case CECDEVICE_PLAYBACKDEVICE2:
+ case CECDEVICE_PLAYBACKDEVICE3:
+ return CEC_DEVICE_TYPE_PLAYBACK_DEVICE;
+ case CECDEVICE_RECORDINGDEVICE1:
+ case CECDEVICE_RECORDINGDEVICE2:
+ case CECDEVICE_RECORDINGDEVICE3:
+ return CEC_DEVICE_TYPE_RECORDING_DEVICE;
+ case CECDEVICE_TUNER1:
+ case CECDEVICE_TUNER2:
+ case CECDEVICE_TUNER3:
+ case CECDEVICE_TUNER4:
+ return CEC_DEVICE_TYPE_TUNER;
+ case CECDEVICE_TV:
+ return CEC_DEVICE_TYPE_TV;
+ default:
+ return CEC_DEVICE_TYPE_RESERVED;
+ }
+}
+
+uint16_t CLibCEC::GetMaskForType(cec_logical_address address)
+{
+ return GetMaskForType(GetType(address));
+}
+
+uint16_t CLibCEC::GetMaskForType(cec_device_type type)
+{
+ switch (type)
+ {
+ case CEC_DEVICE_TYPE_AUDIO_SYSTEM:
+ {
+ cec_logical_addresses addr;
+ addr.Clear();
+ addr.Set(CECDEVICE_AUDIOSYSTEM);
+ return addr.AckMask();
+ }
+ case CEC_DEVICE_TYPE_PLAYBACK_DEVICE:
+ {
+ cec_logical_addresses addr;
+ addr.Clear();
+ addr.Set(CECDEVICE_PLAYBACKDEVICE1);
+ addr.Set(CECDEVICE_PLAYBACKDEVICE2);
+ addr.Set(CECDEVICE_PLAYBACKDEVICE3);
+ return addr.AckMask();
+ }
+ case CEC_DEVICE_TYPE_RECORDING_DEVICE:
+ {
+ cec_logical_addresses addr;
+ addr.Clear();
+ addr.Set(CECDEVICE_RECORDINGDEVICE1);
+ addr.Set(CECDEVICE_RECORDINGDEVICE2);
+ addr.Set(CECDEVICE_RECORDINGDEVICE3);
+ return addr.AckMask();
+ }
+ case CEC_DEVICE_TYPE_TUNER:
+ {
+ cec_logical_addresses addr;
+ addr.Clear();
+ addr.Set(CECDEVICE_TUNER1);
+ addr.Set(CECDEVICE_TUNER2);
+ addr.Set(CECDEVICE_TUNER3);
+ addr.Set(CECDEVICE_TUNER4);
+ return addr.AckMask();
+ }
+ case CEC_DEVICE_TYPE_TV:
+ {
+ cec_logical_addresses addr;
+ addr.Clear();
+ addr.Set(CECDEVICE_TV);
+ return addr.AckMask();
+ }
+ default:
+ return 0;
+ }