From df7339c665f732faedee7c1d3cde816cc41e3302 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Thu, 29 Sep 2011 14:32:04 +0200 Subject: [PATCH] cec: added optional logical and physical address parameters to LoadLibCec()/cec_init() on the interface. fixed wrongly placed namespace close tag in CECExports.h. updated interface documentation. bumped interface version to 2. --- include/CECExports.h | 8 +++++-- include/CECExportsC.h | 39 +++++++++++++++++++++++++++------- include/CECExportsCpp.h | 46 ++++++++++++++++++++++++++++++++++------- include/CECTypes.h | 2 -- src/lib/CECParser.cpp | 10 ++++----- src/lib/CECParser.h | 2 +- src/lib/CECParserC.cpp | 4 ++-- 7 files changed, 85 insertions(+), 26 deletions(-) diff --git a/include/CECExports.h b/include/CECExports.h index 3a72aea..c257570 100644 --- a/include/CECExports.h +++ b/include/CECExports.h @@ -56,7 +56,7 @@ extern "C" { namespace CEC { #endif #define CEC_MIN_VERSION 1 - #define CEC_LIB_VERSION 1 + #define CEC_LIB_VERSION 2 #define CEC_SETTLE_DOWN_TIME 1000 typedef std::vector cec_frame; @@ -192,9 +192,13 @@ namespace CEC { std::string path; std::string comm; } cec_device; -}; + + //default physical address 1.0.0.0 + #define CEC_DEFAULT_PHYSICAL_ADDRESS 0x1000 #ifdef __cplusplus +}; + #include "CECExportsCpp.h" #include "CECExportsC.h" }; diff --git a/include/CECExportsC.h b/include/CECExportsC.h index 04ce11a..79409b7 100644 --- a/include/CECExportsC.h +++ b/include/CECExportsC.h @@ -39,14 +39,21 @@ extern "C" { #endif /*! - * @brief Initialise the cec device. + * @brief Load the CEC adapter library. * @param strDeviceName How to present this device to other devices. + * @param iLogicalAddress The logical of this device. PLAYBACKDEVICE1 by default. + * @param iPhysicalAddress The physical address of this device. 0x1000 by default. * @return True when initialised, false otherwise. */ -extern DECLSPEC bool cec_init(const char *strDeviceName); + +#ifdef __cplusplus +extern DECLSPEC bool cec_init(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); +#else +extern DECLSPEC bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); +#endif /*! - * @brief Close the cec device. + * @brief Close the CEC adapter connection. * @return True when the device was closed, false otherwise. */ extern DECLSPEC bool cec_close(void); @@ -73,6 +80,7 @@ extern DECLSPEC bool cec_start_bootloader(void); /*! * @brief Power off connected CEC capable devices. + * @param address The logical address to power off. * @return True when the command was sent succesfully, false otherwise. */ #ifdef __cplusplus @@ -83,6 +91,7 @@ extern DECLSPEC bool cec_power_off_devices(cec_logical_address address = CECDEVI /*! * @brief Power on the connected CEC capable devices. + * @param address The logical address to power on. * @return True when the command was sent succesfully, false otherwise. */ #ifdef __cplusplus @@ -93,6 +102,7 @@ extern DECLSPEC bool cec_power_on_devices(cec_logical_address address = CECDEVIC /*! * @brief Put connected CEC capable devices in standby mode. + * @brief address The logical address of the device to put in standby. * @return True when the command was sent succesfully, false otherwise. */ #ifdef __cplusplus @@ -102,13 +112,13 @@ extern DECLSPEC bool cec_standby_devices(cec_logical_address address = CECDEVICE #endif /*! - * @brief Set this device as the active source on connected CEC capable devices. + * @brief Broadcast a message that notifies connected CEC capable devices that this device is the active source. * @return True when the command was sent succesfully, false otherwise. */ extern DECLSPEC bool cec_set_active_view(void); /*! - * @brief Mark this device as inactive on connected CEC capable devices. + * @brief Broadcast a message that notifies connected CEC capable devices that this device is no longer the active source. * @return True when the command was sent succesfully, false otherwise. */ extern DECLSPEC bool cec_set_inactive_view(void); @@ -126,7 +136,7 @@ extern DECLSPEC bool cec_get_next_log_message(cec_log_message *message); /*! * @brief Get the next keypress in the queue, if there is one. - * @param key The next keypress + * @param key The next keypress. * @return True if a key was passed, false otherwise. */ #ifdef __cplusplus @@ -136,8 +146,10 @@ extern DECLSPEC bool cec_get_next_keypress(cec_keypress *key); #endif /*! - * @brief Transmit a frame and wait for ACK. + * @brief Transmit a frame on the CEC line. * @param data The frame to send. + * @param bWaitForAck Wait for an ACK message for 1 second after this frame has been sent. + * @param iTimeout Timeout if the message could not be sent for this amount of ms. Does not influence the timeout of the wait for the ACK message. That timeout is specified by the CEC standard. * @return True when the data was sent and acked, false otherwise. */ #ifdef __cplusplus @@ -153,9 +165,22 @@ extern DECLSPEC bool cec_transmit(const cec_frame &data, bool bWaitForAck = true */ extern DECLSPEC bool cec_set_ack_mask(uint16_t ackmask); +/*! + * @return Get the minimal version of libcec that this version of libcec can interface with. + */ extern DECLSPEC int cec_get_min_version(void); + +/*! + * @return Get the version of libcec. + */ extern DECLSPEC int cec_get_lib_version(void); +/*! + * @brief Try to find all connected CEC adapters. Only implemented on Linux at the moment. + * @param deviceList The vector to store device descriptors in. + * @param strDevicePath Optional device path. Only adds device descriptors that match the given device path. + * @return The number of devices that were found, or -1 when an error occured. + */ #ifdef __cplusplus extern DECLSPEC int cec_find_devices(std::vector &deviceList, const char *strDevicePath = NULL); #else diff --git a/include/CECExportsCpp.h b/include/CECExportsCpp.h index 195ddf5..b49b1ab 100644 --- a/include/CECExportsCpp.h +++ b/include/CECExportsCpp.h @@ -101,12 +101,19 @@ namespace CEC */ virtual bool SetAckMask(cec_logical_address ackmask) = 0; + /*! + * @see cec_get_min_version + */ virtual int GetMinVersion(void) = 0; + + /*! + * @see cec_get_lib_version + */ virtual int GetLibVersion(void) = 0; }; }; -extern DECLSPEC void * CECCreate(const char *strDeviceName); +extern DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); #if !defined(DLL_EXPORT) #if defined(_WIN32) || defined(_WIN64) @@ -114,32 +121,57 @@ extern DECLSPEC void * CECCreate(const char *strDeviceName); #include static HINSTANCE g_libCEC = NULL; -inline CEC::ICECDevice *LoadLibCec(const char *strName) +static int g_iLibCECInstanceCount = 0; + +/*! + * @see cec_init + */ +inline CEC::ICECDevice *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS) { typedef void* (__cdecl*_CreateLibCec)(const char *); _CreateLibCec CreateLibCec; - g_libCEC = LoadLibrary("libcec.dll"); + if (!g_libCEC) + g_libCEC = LoadLibrary("libcec.dll"); if (!g_libCEC) return NULL; + + ++g_iLibCECInstanceCount; CreateLibCec = (_CreateLibCec) (GetProcAddress(g_libCEC, "CECCreate")); if (!CreateLibCec) return NULL; - return static_cast< CEC::ICECDevice* > (CreateLibCec(strName)); + return static_cast< CEC::ICECDevice* > (CreateLibCec(strName, iLogicalAddress, iPhysicalAddress)); } +/*! + * @brief Unload the given libcec instance. + * @param device The instance to unload. + */ inline void UnloadLibCec(CEC::ICECDevice *device) { delete device; - FreeLibrary(g_libCEC); + + if (--g_iLibCECInstanceCount == 0) + { + FreeLibrary(g_libCEC); + g_libCEC = NULL; + } }; #else -inline CEC::ICECDevice *LoadLibCec(const char *strName) + +/*! + * @see cec_init + */ +inline CEC::ICECDevice *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS) { - return (CEC::ICECDevice*) CECCreate(strName); + return (CEC::ICECDevice*) CECCreate(strName, iLogicalAddress, iPhysicalAddress); }; +/*! + * @brief Unload the given libcec instance. + * @param device The instance to unload. + */ inline void UnloadLibCec(CEC::ICECDevice *device) { delete device; diff --git a/include/CECTypes.h b/include/CECTypes.h index dcc4c72..5b8ef2b 100644 --- a/include/CECTypes.h +++ b/include/CECTypes.h @@ -426,8 +426,6 @@ typedef enum MSGCODE_FRAME_ACK = 0x40, } ECecMessageCode; -//default physical address 1.0.0.0 -#define CEC_DEFAULT_PHYSICAL_ADDRESS 0x1000 #define MSGSTART 0xFF #define MSGEND 0xFE #define MSGESC 0xFD diff --git a/src/lib/CECParser.cpp b/src/lib/CECParser.cpp index 06a1715..af86abe 100644 --- a/src/lib/CECParser.cpp +++ b/src/lib/CECParser.cpp @@ -52,13 +52,13 @@ using namespace std; * ICECDevice implementation */ //@{ -CCECParser::CCECParser(const char *strDeviceName) : +CCECParser::CCECParser(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) : m_inbuf(NULL), m_iInbufSize(0), m_iInbufUsed(0), m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN), - m_physicaladdress(CEC_DEFAULT_PHYSICAL_ADDRESS), - m_iLogicalAddress(CECDEVICE_PLAYBACKDEVICE1), + m_physicaladdress(iPhysicalAddress), + m_iLogicalAddress(iLogicalAddress), m_strDeviceName(strDeviceName), m_bRunning(false) { @@ -866,7 +866,7 @@ int CCECParser::FindDevices(std::vector &deviceList, const char *str return CCECDetect::FindDevices(deviceList, strDevicePath); } -DECLSPEC void * CECCreate(const char *strDeviceName) +DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /* = CEC::CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) { - return static_cast< void* > (new CCECParser(strDeviceName)); + return static_cast< void* > (new CCECParser(strDeviceName, iLogicalAddress, iPhysicalAddress)); } diff --git a/src/lib/CECParser.h b/src/lib/CECParser.h index 3ad6cf0..6f0caa4 100644 --- a/src/lib/CECParser.h +++ b/src/lib/CECParser.h @@ -48,7 +48,7 @@ namespace CEC * ICECDevice implementation */ //@{ - CCECParser(const char *strDeviceName); + CCECParser(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); virtual ~CCECParser(void); virtual bool Open(const char *strPort, int iTimeout = 10000); diff --git a/src/lib/CECParserC.cpp b/src/lib/CECParserC.cpp index 84d5410..1aae849 100644 --- a/src/lib/CECParserC.cpp +++ b/src/lib/CECParserC.cpp @@ -41,9 +41,9 @@ using namespace std; //@{ ICECDevice *cec_parser; -bool cec_init(const char *strDeviceName) +bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) { - cec_parser = (ICECDevice *) CECCreate(strDeviceName); + cec_parser = (ICECDevice *) CECCreate(strDeviceName, iLogicalAddress, iPhysicalAddress); return (cec_parser != NULL); } -- 2.34.1