namespace CEC
{
- class ICECDevice
+ class ICECAdapter
{
public:
+ /*! @name Adapter methods */
+ //@{
/*!
* @see cec_open
*/
- virtual bool Open(const char *strPort, int iTimeoutMs = 10000) = 0;
+ virtual bool Open(const char *strPort, uint32_t iTimeoutMs = 10000) = 0;
/*!
- * @see cec_find_devices
+ * @see cec_close
*/
- virtual int FindDevices(std::vector<cec_device> &deviceList, const char *strDevicePath = NULL) = 0;
+ virtual void Close(void) = 0;
/*!
- * @see cec_ping
+ * @see cec_find_adapters
*/
- virtual bool Ping(void) = 0;
+ virtual int8_t FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL) = 0;
+
+ /*!
+ * @see cec_ping_adapters
+ */
+ virtual bool PingAdapter(void) = 0;
/*!
* @see cec_start_bootloader
*/
virtual bool StartBootloader(void) = 0;
+ //@}
/*!
- * @see cec_power_off_devices
+ * @see cec_get_min_version
*/
- virtual bool PowerOffDevices(cec_logical_address address = CECDEVICE_BROADCAST) = 0;
+ virtual int8_t GetMinVersion(void) = 0;
/*!
- * @see cec_power_on_devices
+ * @see cec_get_lib_version
*/
- virtual bool PowerOnDevices(cec_logical_address address = CECDEVICE_BROADCAST) = 0;
+ virtual int8_t GetLibVersion(void) = 0;
/*!
- * @see cec_standby_devices
+ * @see cec_get_next_log_message
*/
- virtual bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST) = 0;
+ virtual bool GetNextLogMessage(cec_log_message *message) = 0;
/*!
- * @see cec_set_active_view
+ * @see cec_get_next_keypress
*/
- virtual bool SetActiveView(void) = 0;
+ virtual bool GetNextKeypress(cec_keypress *key) = 0;
/*!
- * @see cec_set_inactive_view
+ * @see cec_get_next_command
*/
- virtual bool SetInactiveView(void) = 0;
+ virtual bool GetNextCommand(cec_command *command) = 0;
/*!
- * @see cec_get_next_log_message
+ * @see cec_transmit
*/
- virtual bool GetNextLogMessage(cec_log_message *message) = 0;
+ virtual bool Transmit(const cec_frame &data, bool bWaitForAck = true) = 0;
/*!
- * @see cec_get_next_keypress
+ * @see cec_set_logical_address
*/
- virtual bool GetNextKeypress(cec_keypress *key) = 0;
+ virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress) = 0;
/*!
- * @see cec_transmit
+ * @see cec_power_on_devices
+ */
+ virtual bool PowerOnDevices(cec_logical_address address = CECDEVICE_TV) = 0;
+
+ /*!
+ * @see cec_standby_devices
*/
- virtual bool Transmit(const cec_frame &data, bool bWaitForAck = true, int64_t iTimeout = (int64_t) 5000) = 0;
+ virtual bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST) = 0;
/*!
- * @see cec_set_ack_mask
+ * @see cec_set_active_view
*/
- virtual bool SetAckMask(cec_logical_address ackmask) = 0;
+ virtual bool SetActiveView(void) = 0;
+
+ /*!
+ * @see cec_set_inactive_view
+ */
+ virtual bool SetInactiveView(void) = 0;
- virtual int GetMinVersion(void) = 0;
- 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, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+
+extern DECLSPEC void CECDestroy(CEC::ICECAdapter *instance);
#if !defined(DLL_EXPORT)
#if defined(_WIN32) || defined(_WIN64)
#include <conio.h>
static HINSTANCE g_libCEC = NULL;
-inline CEC::ICECDevice *LoadLibCec(const char *strName)
+static int g_iLibCECInstanceCount = 0;
+
+/*!
+ * @see cec_init
+ */
+inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS)
{
- typedef void* (__cdecl*_CreateLibCec)(const char *);
+ typedef void* (__cdecl*_CreateLibCec)(const char *, uint8_t, uint16_t);
_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::ICECAdapter* > (CreateLibCec(strName, (uint8_t) iLogicalAddress, iPhysicalAddress));
}
-inline void UnloadLibCec(CEC::ICECDevice *device)
+/*!
+ * @brief Unload the given libcec instance.
+ * @param device The instance to unload.
+ */
+inline void UnloadLibCec(CEC::ICECAdapter *device)
{
- delete device;
- FreeLibrary(g_libCEC);
+ typedef void (__cdecl*_DestroyLibCec)(void * device);
+ _DestroyLibCec DestroyLibCec;
+ DestroyLibCec = (_DestroyLibCec) (GetProcAddress(g_libCEC, "CECDestroy"));
+ if (DestroyLibCec)
+ DestroyLibCec(device);
+
+ if (--g_iLibCECInstanceCount == 0)
+ {
+ FreeLibrary(g_libCEC);
+ g_libCEC = NULL;
+ }
};
#else
-inline CEC::ICECDevice *LoadLibCec(const char *strName)
+
+/*!
+ * @see cec_init
+ */
+inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS)
{
- return (CEC::ICECDevice*) CECCreate(strName);
+ return (CEC::ICECAdapter*) CECCreate(strName, iLogicalAddress, iPhysicalAddress);
};
-inline void UnloadLibCec(CEC::ICECDevice *device)
+/*!
+ * @brief Unload the given libcec instance.
+ * @param device The instance to unload.
+ */
+inline void UnloadLibCec(CEC::ICECAdapter *device)
{
- delete device;
+ device->Close();
+ CECDestroy(device);
};
#endif