From: Lars Op den Kamp Date: Thu, 12 Jan 2012 19:55:02 +0000 (+0100) Subject: cec: add a void* parameter to the callback methods, that can be set when enabling... X-Git-Tag: upstream/2.2.0~1^2~41^2~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=547b390d1c90e922b7c2191393ba12ec388750ca;p=deb_libcec.git cec: add a void* parameter to the callback methods, that can be set when enabling them and will be passed to each call --- diff --git a/include/cec.h b/include/cec.h index 0e463eb..9e09902 100644 --- a/include/cec.h +++ b/include/cec.h @@ -60,10 +60,11 @@ namespace CEC /*! * @brief Set and enable the callback methods. If this method is not called, the GetNext...() methods will have to be used. + * @param cbParam Parameter to pass to callback methods. * @param callbacks The callbacks to set. * @return True when enabled, false otherwise. */ - virtual bool EnableCallbacks(ICECCallbacks *callbacks) = 0; + virtual bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks) = 0; /*! * @brief Try to find all connected CEC adapters. Only implemented on Linux and Windows at the moment. diff --git a/include/cecc.h b/include/cecc.h index c8e0d0e..8c9bc93 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -60,9 +60,9 @@ extern DECLSPEC int cec_open(const char *strPort, uint32_t iTimeout); extern DECLSPEC void cec_close(void); #ifdef __cplusplus -extern DECLSPEC int cec_enable_callbacks(CEC::ICECCallbacks *callbacks); +extern DECLSPEC int cec_enable_callbacks(void *cbParam, CEC::ICECCallbacks *callbacks); #else -extern DECLSPEC int cec_enable_callbacks(ICECCallbacks *callbacks); +extern DECLSPEC int cec_enable_callbacks(void *cbParam, ICECCallbacks *callbacks); #endif #ifdef __cplusplus diff --git a/include/cectypes.h b/include/cectypes.h index 46b25e4..1c52cb7 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -874,9 +874,9 @@ typedef struct cec_logical_addresses } cec_logical_addresses; -typedef int (CDECL* CBCecLogMessageType)(const CEC::cec_log_message &); -typedef int (CDECL* CBCecKeyPressType)(const cec_keypress &key); -typedef int (CDECL* CBCecCommandType)(const cec_command &command); +typedef int (CDECL* CBCecLogMessageType)(void *param, const CEC::cec_log_message &); +typedef int (CDECL* CBCecKeyPressType)(void *param, const cec_keypress &key); +typedef int (CDECL* CBCecCommandType)(void *param, const cec_command &command); typedef struct ICECCallbacks { diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 55af180..52dfa51 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -46,7 +46,8 @@ CLibCEC::CLibCEC(const char *strDeviceName, cec_device_type_list types) : m_iStartTime(GetTimeMs()), m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN), m_buttontime(0), - m_callbacks(NULL) + m_callbacks(NULL), + m_cbParam(NULL) { m_cec = new CCECProcessor(this, strDeviceName, types); } @@ -55,7 +56,8 @@ CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress m_iStartTime(GetTimeMs()), m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN), m_buttontime(0), - m_callbacks(NULL) + m_callbacks(NULL), + m_cbParam(NULL) { m_cec = new CCECProcessor(this, strDeviceName, iLogicalAddress, iPhysicalAddress); } @@ -89,11 +91,14 @@ void CLibCEC::Close(void) m_cec->StopThread(); } -bool CLibCEC::EnableCallbacks(ICECCallbacks *callbacks) +bool CLibCEC::EnableCallbacks(void *cbParam, ICECCallbacks *callbacks) { CLockObject lock(&m_mutex); if (m_cec) + { + m_cbParam = cbParam; m_callbacks = callbacks; + } return false; } @@ -347,7 +352,7 @@ void CLibCEC::AddLog(cec_log_level level, const string &strMessage) snprintf(message.message, sizeof(message.message), "%s", strMessage.c_str()); if (m_callbacks) - m_callbacks->CBCecLogMessage(message); + m_callbacks->CBCecLogMessage(m_cbParam, message); else m_logBuffer.Push(message); } @@ -357,7 +362,7 @@ void CLibCEC::AddKey(cec_keypress &key) { CLockObject lock(&m_mutex); if (m_callbacks) - m_callbacks->CBCecKeyPress(key); + m_callbacks->CBCecKeyPress(m_cbParam, key); else m_keyBuffer.Push(key); m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN; @@ -375,7 +380,7 @@ void CLibCEC::AddKey(void) key.keycode = m_iCurrentButton; if (m_callbacks) - m_callbacks->CBCecKeyPress(key); + m_callbacks->CBCecKeyPress(m_cbParam, key); else m_keyBuffer.Push(key); m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN; @@ -388,7 +393,7 @@ void CLibCEC::AddCommand(const cec_command &command) CLockObject lock(&m_mutex); if (m_callbacks) { - m_callbacks->CBCecCommand(command); + m_callbacks->CBCecCommand(m_cbParam, command); } else if (m_commandBuffer.Push(command)) { diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index dde69f4..ef1ded2 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -53,7 +53,7 @@ namespace CEC virtual bool Open(const char *strPort, uint32_t iTimeout = 10000); virtual void Close(void); - virtual bool EnableCallbacks(ICECCallbacks *callbacks); + virtual bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks); virtual int8_t FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL); virtual bool PingAdapter(void); virtual bool StartBootloader(void); @@ -128,6 +128,7 @@ namespace CEC CecBuffer m_keyBuffer; CecBuffer m_commandBuffer; ICECCallbacks *m_callbacks; + void *m_cbParam; CMutex m_mutex; }; }; diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index 5ca2885..91ab395 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -74,10 +74,10 @@ void cec_close(void) cec_parser->Close(); } -int cec_enable_callbacks(ICECCallbacks *callbacks) +int cec_enable_callbacks(void *cbParam, ICECCallbacks *callbacks) { if (cec_parser) - return cec_parser->EnableCallbacks(callbacks) ? 1 : 0; + return cec_parser->EnableCallbacks(cbParam, callbacks) ? 1 : 0; return -1; } diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 5858eb6..256a484 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -123,7 +123,7 @@ bool GetWord(string& data, string& word) return true; } -int CecLogMessage(const cec_log_message &message) +int CecLogMessage(void *UNUSED(cbParam), const cec_log_message &message) { if ((message.level & g_cecLogLevel) == message.level) { @@ -165,12 +165,12 @@ int CecLogMessage(const cec_log_message &message) return 0; } -int CecKeyPress(const cec_keypress &UNUSED(key)) +int CecKeyPress(void *UNUSED(cbParam), const cec_keypress &UNUSED(key)) { return 0; } -int CecCommand(const cec_command &UNUSED(command)) +int CecCommand(void *UNUSED(cbParam), const cec_command &UNUSED(command)) { return 0; } @@ -180,7 +180,7 @@ void EnableCallbacks(ICECAdapter *adapter) g_callbacks.CBCecLogMessage = &CecLogMessage; g_callbacks.CBCecKeyPress = &CecKeyPress; g_callbacks.CBCecCommand = &CecCommand; - adapter->EnableCallbacks(&g_callbacks); + adapter->EnableCallbacks(NULL, &g_callbacks); } void ListDevices(ICECAdapter *parser)