From b4b1b49b0904e9c0cdeaa466f21ed61ccf41cb92 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Wed, 7 Dec 2011 22:48:32 +0100 Subject: [PATCH] cec: added GetActiveSource()/cec_get_active_source() and IsActiveSource()/cec_is_active_source() --- include/cec.h | 13 +++++++++++++ include/cecc.h | 12 ++++++++++++ src/lib/CECProcessor.cpp | 16 ++++++++++++++++ src/lib/CECProcessor.h | 2 ++ src/lib/LibCEC.cpp | 12 ++++++++++++ src/lib/LibCEC.h | 2 ++ src/lib/LibCECC.cpp | 14 ++++++++++++++ src/lib/devices/CECBusDevice.h | 2 ++ src/testclient/main.cpp | 14 ++++++++------ 9 files changed, 81 insertions(+), 6 deletions(-) diff --git a/include/cec.h b/include/cec.h index c5f0522..98adaf9 100644 --- a/include/cec.h +++ b/include/cec.h @@ -329,6 +329,19 @@ namespace CEC */ virtual cec_osd_name GetOSDName(cec_logical_address iAddress) = 0; + /*! + * @brief Get the logical address of the device that is currently the active source on the CEC bus. + * @return The active source or CECDEVICE_UNKNOWN when unknown. + */ + virtual cec_logical_address GetActiveSource(void) = 0; + + /*! + * @brief Check whether a device is currently the active source on the CEC bus. + * @param iAddress The address to check. + * @return True when it is the active source, false otherwise. + */ + virtual bool IsActiveSource(cec_logical_address iAddress) = 0; + virtual const char *ToString(const cec_menu_state state) = 0; virtual const char *ToString(const cec_version version) = 0; virtual const char *ToString(const cec_power_status status) = 0; diff --git a/include/cecc.h b/include/cecc.h index 6508606..f270df7 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -179,6 +179,18 @@ extern DECLSPEC uint16_t cec_get_device_physical_address(CEC::cec_logical_addres extern DECLSPEC uint16_t cec_get_device_physical_address(cec_logical_address iLogicalAddress); #endif +#ifdef __cplusplus +extern DECLSPEC CEC::cec_logical_address cec_get_active_source(void); +#else +extern DECLSPEC cec_logical_address cec_get_active_source(void); +#endif + +#ifdef __cplusplus +extern DECLSPEC int cec_is_active_source(CEC::cec_logical_address iAddress); +#else +extern DECLSPEC int cec_is_active_source(cec_logical_address iAddress); +#endif + #ifdef __cplusplus extern DECLSPEC CEC::cec_power_status cec_get_device_power_status(CEC::cec_logical_address iLogicalAddress); #else diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 46e3419..b07f2dd 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -684,6 +684,22 @@ cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddres return CEC_POWER_STATUS_UNKNOWN; } +cec_logical_address CCECProcessor::GetActiveSource(void) +{ + for (uint8_t iPtr = 0; iPtr <= 11; iPtr++) + { + if (m_busDevices[iPtr]->IsActiveSource()) + return (cec_logical_address)iPtr; + } + + return CECDEVICE_UNKNOWN; +} + +bool CCECProcessor::IsActiveSource(cec_logical_address iAddress) +{ + return m_busDevices[iAddress]->IsActiveSource(); +} + bool CCECProcessor::Transmit(const cec_command &data) { bool bReturn(false); diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index bdf5233..d2aa222 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -75,6 +75,8 @@ namespace CEC virtual uint16_t GetPhysicalAddress(void) const; virtual uint64_t GetLastTransmission(void) const { return m_iLastTransmission; } virtual bool IsStarted(void) const { return m_bStarted; } + virtual cec_logical_address GetActiveSource(void); + virtual bool IsActiveSource(cec_logical_address iAddress); virtual bool SetActiveView(void); virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index adf0132..4156954 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -229,6 +229,18 @@ uint16_t CLibCEC::GetDevicePhysicalAddress(cec_logical_address iAddress) return 0; } +cec_logical_address CLibCEC::GetActiveSource(void) +{ + return m_cec ? m_cec->GetActiveSource() : CECDEVICE_UNKNOWN; +} + +bool CLibCEC::IsActiveSource(cec_logical_address iAddress) +{ + if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) + return m_cec->IsActiveSource(iAddress); + return false; +} + cec_power_status CLibCEC::GetDevicePowerStatus(cec_logical_address iAddress) { if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 9bff00f..02ea9c2 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -96,6 +96,8 @@ namespace CEC virtual bool SendKeyRelease(cec_logical_address iDestination, bool bWait = false); virtual cec_osd_name GetOSDName(cec_logical_address iAddress); virtual bool EnablePhysicalAddressDetection(void); + virtual cec_logical_address GetActiveSource(void); + virtual bool IsActiveSource(cec_logical_address iAddress); const char *ToString(const cec_menu_state state); const char *ToString(const cec_version version); diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index ffa8f55..28658cd 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -254,6 +254,20 @@ uint16_t cec_get_device_physical_address(cec_logical_address iLogicalAddress) return 0; } +cec_logical_address cec_get_active_source(void) +{ + if (cec_parser) + return cec_parser->GetActiveSource(); + return CECDEVICE_UNKNOWN; +} + +int cec_is_active_source(cec_logical_address iAddress) +{ + if (cec_parser) + return cec_parser->IsActiveSource(iAddress); + return false; +} + cec_power_status cec_get_device_power_status(cec_logical_address iLogicalAddress) { if (cec_parser) diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index 80576b4..14f3302 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -72,6 +72,8 @@ namespace CEC virtual const char * GetVendorName(bool bUpdate = false); virtual bool MyLogicalAddressContains(cec_logical_address address) const; virtual cec_bus_device_status GetStatus(bool bForcePoll = false); + virtual bool IsActiveSource(void) const { return m_bActiveSource; } + virtual void SetInactiveDevice(void); virtual void SetActiveDevice(void); diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index c1f3bf7..e1d0ec8 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -720,6 +720,7 @@ bool ProcessCommandSCAN(ICECAdapter *parser, const string &command, string &argu { if (addresses[iPtr]) { + bool bActive = parser->IsActiveSource((cec_logical_address)iPtr); uint16_t iPhysicalAddress = parser->GetDevicePhysicalAddress((cec_logical_address)iPtr); uint64_t iVendorId = parser->GetDeviceVendorId((cec_logical_address)iPtr); cec_version iCecVersion = parser->GetDeviceCecVersion((cec_logical_address)iPtr); @@ -732,13 +733,14 @@ bool ProcessCommandSCAN(ICECAdapter *parser, const string &command, string &argu parser->GetDeviceMenuLanguage((cec_logical_address)iPtr, &lang); cout << "device #" << (int)iPtr << ": " << parser->ToString((cec_logical_address)iPtr) << endl; - cout << "address: " << strAddr.c_str() << endl; - cout << "vendor: " << parser->ToString((cec_vendor_id)iVendorId) << endl; - cout << "osd string: " << osdName.name << endl; - cout << "CEC version: " << parser->ToString(iCecVersion) << endl; - cout << "power status: " << parser->ToString(power) << endl; + cout << "address: " << strAddr.c_str() << endl; + cout << "active source: " << (bActive ? "yes" : "no") << endl; + cout << "vendor: " << parser->ToString((cec_vendor_id)iVendorId) << endl; + cout << "osd string: " << osdName.name << endl; + cout << "CEC version: " << parser->ToString(iCecVersion) << endl; + cout << "power status: " << parser->ToString(power) << endl; if ((uint8_t)lang.device == iPtr) - cout << "language: " << lang.language << endl; + cout << "language: " << lang.language << endl; cout << endl; } } -- 2.34.1