/*!
* @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.
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
} 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
{
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);
}
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);
}
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;
}
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);
}
{
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;
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;
CLockObject lock(&m_mutex);
if (m_callbacks)
{
- m_callbacks->CBCecCommand(command);
+ m_callbacks->CBCecCommand(m_cbParam, command);
}
else if (m_commandBuffer.Push(command))
{
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);
CecBuffer<cec_keypress> m_keyBuffer;
CecBuffer<cec_command> m_commandBuffer;
ICECCallbacks *m_callbacks;
+ void *m_cbParam;
CMutex m_mutex;
};
};
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;
}
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)
{
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;
}
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)