diff --git a/CMakeLists.txt b/CMakeLists.txt index bc7798453..1fdee6c1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -252,103 +252,103 @@ endif() if (WIN32) add_executable(vscpd - src/vscp/daemon/vscpd.cpp - src/vscp/daemon/controlobject.h - src/vscp/daemon/controlobject.cpp - src/vscp/daemon/devicethread.h - src/vscp/daemon/devicethread.cpp - src/vscp/daemon/devicelist.h - src/vscp/daemon/devicelist.cpp - src/vscp/common/version.h - src/vscp/common/vscp.h - src/vscp/common/vscpremotetcpif.h - src/vscp/common/vscpremotetcpif.cpp - src/vscp/common/vscpdatetime.h - src/vscp/common/vscpdatetime.cpp - src/vscp/common/guid.h - src/vscp/common/guid.cpp - src/vscp/common/vscphelper.h - src/vscp/common/vscphelper.cpp - src/vscp/common/canal.h - src/vscp/common/canaldlldef.h - src/vscp/common/vscpcanaldeviceif.h - src/vscp/common/vscpcanaldeviceif.cpp - src/vscp/common/canal_xmlconfig.h - src/vscp/common/canal_xmlconfig.cpp - src/vscp/common/vscp_client_base.h - src/vscp/common/vscp_client_base.cpp - src/vscp/common/vscp_client_mqtt.h - src/vscp/common/vscp_client_mqtt.cpp - ./third_party/mustache/mustache.hpp - ./third_party/sqlite3/sqlite3.h - ./third_party/sqlite3/sqlite3.c - src/common/windows/getopt.c - src/common/configfile.h - src/common/configfile.cpp - src/common/sockettcp.h - src/common/sockettcp.c - src/common/vscpbase64.h - src/common/vscpbase64.c - src/common/vscp_aes.h - src/common/vscp_aes.c - src/common/crc.h - src/common/crc.c - src/common/crc8.h - src/common/crc8.c - src/common/vscpmd5.h - src/common/vscpmd5.c - src/common/randpassword.h - src/common/randpassword.cpp - ) + src/vscp/daemon/vscpd.cpp + src/vscp/daemon/controlobject.h + src/vscp/daemon/controlobject.cpp + src/vscp/daemon/devicethread.h + src/vscp/daemon/devicethread.cpp + src/vscp/daemon/devicelist.h + src/vscp/daemon/devicelist.cpp + src/vscp/common/version.h + src/vscp/common/vscp.h + src/vscp/common/vscpremotetcpif.h + src/vscp/common/vscpremotetcpif.cpp + src/vscp/common/vscpdatetime.h + src/vscp/common/vscpdatetime.cpp + src/vscp/common/guid.h + src/vscp/common/guid.cpp + src/vscp/common/vscphelper.h + src/vscp/common/vscphelper.cpp + src/vscp/common/canal.h + src/vscp/common/canaldlldef.h + src/vscp/common/vscpcanaldeviceif.h + src/vscp/common/vscpcanaldeviceif.cpp + src/vscp/common/canal_xmlconfig.h + src/vscp/common/canal_xmlconfig.cpp + src/vscp/common/vscp_client_base.h + src/vscp/common/vscp_client_base.cpp + src/vscp/common/vscp_client_mqtt.h + src/vscp/common/vscp_client_mqtt.cpp + ./third_party/mustache/mustache.hpp + ./third_party/sqlite3/sqlite3.h + ./third_party/sqlite3/sqlite3.c + src/common/windows/getopt.c + src/common/configfile.h + src/common/configfile.cpp + src/common/sockettcp.h + src/common/sockettcp.c + src/common/vscpbase64.h + src/common/vscpbase64.c + src/common/vscp_aes.h + src/common/vscp_aes.c + src/common/crc.h + src/common/crc.c + src/common/crc8.h + src/common/crc8.c + src/common/vscpmd5.h + src/common/vscpmd5.c + src/common/randpassword.h + src/common/randpassword.cpp + ) else() add_executable(vscpd - src/vscp/daemon/vscpd.cpp - src/vscp/daemon/controlobject.h - src/vscp/daemon/controlobject.cpp - src/vscp/daemon/devicethread.h - src/vscp/daemon/devicethread.cpp - src/vscp/daemon/devicelist.h - src/vscp/daemon/devicelist.cpp - src/vscp/common/version.h - src/vscp/common/vscp.h - src/vscp/common/vscpremotetcpif.h - src/vscp/common/vscpremotetcpif.cpp - src/vscp/common/vscpdatetime.h - src/vscp/common/vscpdatetime.cpp - src/vscp/common/guid.h - src/vscp/common/guid.cpp - src/vscp/common/vscphelper.h - src/vscp/common/vscphelper.cpp - src/vscp/common/canal.h - src/vscp/common/canaldlldef.h - src/vscp/common/vscpcanaldeviceif.h - src/vscp/common/vscpcanaldeviceif.cpp - src/vscp/common/canal_xmlconfig.h - src/vscp/common/canal_xmlconfig.cpp - src/vscp/common/vscp_client_base.h - src/vscp/common/vscp_client_base.cpp - src/vscp/common/vscp_client_mqtt.h - src/vscp/common/vscp_client_mqtt.cpp - ./third_party/mustache/mustache.hpp - ./third_party/sqlite3/sqlite3.h - ./third_party/sqlite3/sqlite3.c - src/common/configfile.h - src/common/configfile.cpp - src/common/sockettcp.h - src/common/sockettcp.c - src/common/vscpbase64.h - src/common/vscpbase64.c - src/common/vscp_aes.h - src/common/vscp_aes.c - src/common/crc.h - src/common/crc.c - src/common/crc8.h - src/common/crc8.c - src/common/vscpmd5.h - src/common/vscpmd5.c - src/common/randpassword.h - src/common/randpassword.cpp - ) + src/vscp/daemon/vscpd.cpp + src/vscp/daemon/controlobject.h + src/vscp/daemon/controlobject.cpp + src/vscp/daemon/devicethread.h + src/vscp/daemon/devicethread.cpp + src/vscp/daemon/devicelist.h + src/vscp/daemon/devicelist.cpp + src/vscp/common/version.h + src/vscp/common/vscp.h + src/vscp/common/vscpremotetcpif.h + src/vscp/common/vscpremotetcpif.cpp + src/vscp/common/vscpdatetime.h + src/vscp/common/vscpdatetime.cpp + src/vscp/common/guid.h + src/vscp/common/guid.cpp + src/vscp/common/vscphelper.h + src/vscp/common/vscphelper.cpp + src/vscp/common/canal.h + src/vscp/common/canaldlldef.h + src/vscp/common/vscpcanaldeviceif.h + src/vscp/common/vscpcanaldeviceif.cpp + src/vscp/common/canal_xmlconfig.h + src/vscp/common/canal_xmlconfig.cpp + src/vscp/common/vscp_client_base.h + src/vscp/common/vscp_client_base.cpp + src/vscp/common/vscp_client_mqtt.h + src/vscp/common/vscp_client_mqtt.cpp + ./third_party/mustache/mustache.hpp + ./third_party/sqlite3/sqlite3.h + ./third_party/sqlite3/sqlite3.c + src/common/configfile.h + src/common/configfile.cpp + src/common/sockettcp.h + src/common/sockettcp.c + src/common/vscpbase64.h + src/common/vscpbase64.c + src/common/vscp_aes.h + src/common/vscp_aes.c + src/common/crc.h + src/common/crc.c + src/common/crc8.h + src/common/crc8.c + src/common/vscpmd5.h + src/common/vscpmd5.c + src/common/randpassword.h + src/common/randpassword.cpp + ) endif() # * * * Includes * * * diff --git a/src/vscp/common/vscp_client_base.cpp b/src/vscp/common/vscp_client_base.cpp index 36ae2aab4..d0b627727 100644 --- a/src/vscp/common/vscp_client_base.cpp +++ b/src/vscp/common/vscp_client_base.cpp @@ -43,8 +43,8 @@ CVscpClient::CVscpClient() { - m_evcallback = nullptr; - m_excallback = nullptr; + m_bActiveCallbackEv = false; + m_bActiveCallbackEx = false; m_callbackObject = nullptr; m_bFullLevel2 = false; // This is not a full level II communication client } @@ -63,22 +63,25 @@ CVscpClient::~CVscpClient() // int -CVscpClient::setCallback(LPFNDLL_EV_CALLBACK evcallback, void *pData) +CVscpClient::setCallbackEv(std::function callback, void *pData) { - m_evcallback = evcallback; + m_callbackev = callback; m_callbackObject = pData; + m_bActiveCallbackEv = true; return VSCP_ERROR_SUCCESS; }; /////////////////////////////////////////////////////////////////////////////// -// setCallback +// setCallbackEx // int -CVscpClient::setCallback(LPFNDLL_EX_CALLBACK excallback, void *pData) +CVscpClient::setCallbackEx(std::function callback, void *pData) { - m_excallback = excallback; + m_callbackex = callback; m_callbackObject = pData; + m_bActiveCallbackEv = true; + return VSCP_ERROR_SUCCESS; }; \ No newline at end of file diff --git a/src/vscp/common/vscp_client_base.h b/src/vscp/common/vscp_client_base.h index 23b2cca47..7ca5fba72 100644 --- a/src/vscp/common/vscp_client_base.h +++ b/src/vscp/common/vscp_client_base.h @@ -42,11 +42,13 @@ using json = nlohmann::json; // as it wants. #ifdef WIN32 -typedef void(__stdcall *LPFNDLL_EV_CALLBACK)(vscpEvent *pev, void *pobj); // Event callback -typedef void(__stdcall *LPFNDLL_EX_CALLBACK)(vscpEventEx *pex, void *pobj); // Event ex callbac +// std::function +// std::function +// typedef void(__stdcall *CALLBACK_EV)(vscpEvent *pev, void *pobj); // Event callback +// typedef void(__stdcall *CALLBACK_EX)(vscpEventEx *pex, void *pobj); // Event ex callbac #else -typedef void (*LPFNDLL_EV_CALLBACK)(vscpEvent *pev, void *pobj); // Event callback -typedef void (*LPFNDLL_EX_CALLBACK)(vscpEventEx *pex, void *pobj); // Event ex callback +// typedef void (*CALLBACK_EV)(vscpEvent *pev, void *pobj); // Event callback +// typedef void (*CALLBACK_EX)(vscpEventEx *pex, void *pobj); // Event ex callback #endif class CVscpClient { @@ -192,7 +194,7 @@ class CVscpClient { @param pData User defined data to pass in callback call @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ - virtual int setCallback(LPFNDLL_EV_CALLBACK evcallback, void *pData = nullptr); + virtual int setCallbackEv(std::function callback, void *pData = nullptr); /*! Set (and enable) receive callback ex events @@ -200,7 +202,7 @@ class CVscpClient { @param pData User defined data to pass in callback call @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ - virtual int setCallback(LPFNDLL_EX_CALLBACK excallback, void *pData = nullptr); + virtual int setCallbackEx(std::function callback, void *pData = nullptr); /*! Getter/setters for connection timeout @@ -220,13 +222,25 @@ class CVscpClient { Check if ev callback is defined @return true if callback is defined */ - bool isEvCallback(void) { return (nullptr != m_evcallback); } + bool isCallbackEvActive(void) { return m_bActiveCallbackEv; } /*! Check if ex callback is defined @return true if callback is defined */ - bool isExCallback(void) { return (nullptr != m_excallback); } + bool isCallbackExActive(void) { return m_bActiveCallbackEx; } + + /*! + Activate or deactivate Ev callback + @param b Set to true (default) to activate. + */ + void setCallbackEvActive(bool b = true) { m_bActiveCallbackEv = b; }; + + /*! + Activate or deactivate Ex callback + @param b Set to true (default) to activate. + */ + void setCallbackExActive(bool b = true) { m_bActiveCallbackEx = b; }; /*! Return a JSON representation of connection @@ -263,7 +277,7 @@ class CVscpClient { Mark as full level II or not @param b Set to true to mark as full level II working client */ - void setFullLevel2(bool b=true) { m_bFullLevel2 = b; }; + void setFullLevel2(bool b = true) { m_bFullLevel2 = b; }; /*! Check if client is afull level II client @@ -271,16 +285,45 @@ class CVscpClient { */ bool isFullLevel2(void) { return m_bFullLevel2; }; + /*! + Set callback object + @param Pointer to object to set + */ + + void setCallbackObj(void *pobj) { m_callbackObject = pobj; }; + + /*! + Return Callback object + @return Pointer to object + */ + void *getCallbackObj(void) { return m_callbackObject; }; + public: + /*! Callback for events */ - LPFNDLL_EV_CALLBACK m_evcallback; + std::function m_callbackev; /*! Callback for ex events */ - LPFNDLL_EX_CALLBACK m_excallback; + std::function m_callbackex; + +protected: + + /// Type of connection object + connType m_type = CVscpClient::connType::NONE; + + /*! + Flag that is true when an ev callback is installed + */ + bool m_bActiveCallbackEv; + + /*! + Flag that is true when an ex callback is installed + */ + bool m_bActiveCallbackEx; /*! This data pointer is set by the callback @@ -288,8 +331,7 @@ class CVscpClient { */ void *m_callbackObject; - /// Type of connection object - connType m_type = CVscpClient::connType::NONE; + /// Name for connection object std::string m_name; diff --git a/src/vscp/common/vscp_client_canal.cpp b/src/vscp/common/vscp_client_canal.cpp index 34834253b..bb2b5a5e3 100644 --- a/src/vscp/common/vscp_client_canal.cpp +++ b/src/vscp/common/vscp_client_canal.cpp @@ -201,7 +201,7 @@ vscpClientCanal::connect(void) } // Start worker thread if a callback has been defined - if ((NULL != m_evcallback) || (NULL != m_excallback)) { + if (isCallbackEvActive() || isCallbackExActive()) { rv = pthread_create(&m_tid, NULL, workerThread, this); } @@ -225,16 +225,12 @@ vscpClientCanal::disconnect(void) #endif pthread_mutex_unlock(&m_mutexif); - if ((NULL != m_evcallback) || (NULL != m_excallback)) { + if (isCallbackEvActive() || isCallbackExActive()) { pthread_join(m_tid, NULL); } pthread_mutex_destroy(&m_mutexif); m_bConnected = false; - - // Disable callbacks - // m_evcallback = nullptr; - // m_excallback = nullptr; spdlog::debug("CANAL CLIENT: Disconnect"); return m_canalif.CanalClose(); @@ -407,7 +403,7 @@ vscpClientCanal::getcount(uint16_t *pcount) { int cnt; - if ((NULL == m_evcallback) && (NULL == m_excallback)) { + if (isCallbackEvActive() && isCallbackExActive()) { pthread_mutex_lock(&m_mutexif); cnt = m_canalif.CanalDataAvailable(); pthread_mutex_unlock(&m_mutexif); @@ -507,11 +503,11 @@ vscpClientCanal::getResponseTimeout(void) } /////////////////////////////////////////////////////////////////////////////// -// setCallback +// setCallbackEv // int -vscpClientCanal::setCallback(LPFNDLL_EV_CALLBACK evcallback) +vscpClientCanal::setCallbackEv(std::function callback) { // Can not be called when connected if (m_bConnected) { @@ -520,7 +516,7 @@ vscpClientCanal::setCallback(LPFNDLL_EV_CALLBACK evcallback) } spdlog::debug("CANAL CLIENT: ev callback set."); - m_evcallback = evcallback; + CVscpClient::setCallbackEv(callback); return VSCP_ERROR_SUCCESS; } @@ -529,7 +525,7 @@ vscpClientCanal::setCallback(LPFNDLL_EV_CALLBACK evcallback) // int -vscpClientCanal::setCallback(LPFNDLL_EX_CALLBACK excallback) +vscpClientCanal::setCallbackEx(std::function callback) { // Can not be called when connected if (m_bConnected) { @@ -538,7 +534,7 @@ vscpClientCanal::setCallback(LPFNDLL_EX_CALLBACK excallback) } spdlog::debug("CANAL CLIENT: ex callback set."); - m_excallback = excallback; + CVscpClient::setCallbackEx(callback); return VSCP_ERROR_SUCCESS; } @@ -590,18 +586,18 @@ workerThread(void *pObj) canalMsg msg; if (CANAL_ERROR_SUCCESS == pClient->m_canalif.CanalReceive(&msg)) { spdlog::debug("CANAL CLIENT: workthread. Event recived"); - if (NULL != pClient->m_evcallback) { + if (pClient->isCallbackEvActive()) { vscpEvent ev; if (vscp_convertCanalToEvent(&ev, &msg, guid)) { spdlog::trace("CANAL CLIENT: workthread. Event sent to ev callback"); - pClient->m_evcallback(&ev, pClient->m_callbackObject); + pClient->m_callbackev(ev, pClient->getCallbackObj()); } } - if (NULL != pClient->m_excallback) { + if (pClient->isCallbackExActive()) { vscpEventEx ex; if (vscp_convertCanalToEventEx(&ex, &msg, guid)) { spdlog::trace("CANAL CLIENT: workthread. Event sent to ex callback"); - pClient->m_excallback(&ex, pClient->m_callbackObject); + pClient->m_callbackex(ex, pClient->getCallbackObj()); } } } diff --git a/src/vscp/common/vscp_client_canal.h b/src/vscp/common/vscp_client_canal.h index e61d943de..e972615ed 100644 --- a/src/vscp/common/vscp_client_canal.h +++ b/src/vscp/common/vscp_client_canal.h @@ -161,13 +161,13 @@ class vscpClientCanal : public CVscpClient { Set (and enable) receive callback for events @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ - virtual int setCallback(LPFNDLL_EV_CALLBACK m_evcallback); + virtual int setCallbackEv(std::function callback); /*! Set (and enable) receive callback ex events @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ - virtual int setCallback(LPFNDLL_EX_CALLBACK m_excallback); + virtual int setCallbackEx(std::function callback); /*! Return a JSON representation of connection diff --git a/src/vscp/common/vscp_client_mqtt.cpp b/src/vscp/common/vscp_client_mqtt.cpp index 81f9698fa..790cdf37f 100644 --- a/src/vscp/common/vscp_client_mqtt.cpp +++ b/src/vscp/common/vscp_client_mqtt.cpp @@ -1492,11 +1492,11 @@ vscpClientMqtt::handleMessage(const struct mosquitto_message *pmsg) } // If callback is defined send event - if (nullptr != m_evcallback) { - m_evcallback(&ev, m_callbackObject); + if (isCallbackEvActive()) { + m_callbackev(ev, getCallbackObj()); } - else if (nullptr != m_excallback) { - m_excallback(&ex, m_callbackObject); + else if (isCallbackExActive()) { + m_callbackex(ex, getCallbackObj()); } else { // Put event in input queue @@ -1531,11 +1531,11 @@ vscpClientMqtt::handleMessage(const struct mosquitto_message *pmsg) } // If callback is defined send event - if (nullptr != m_evcallback) { - m_evcallback(&ev, m_callbackObject); + if (isCallbackEvActive()) { + m_callbackev(ev, getCallbackObj()); } - else if (nullptr != m_excallback) { - m_excallback(&ex, m_callbackObject); + else if (isCallbackExActive()) { + m_callbackex(ex, getCallbackObj()); } else { // Put event in input queue @@ -1570,11 +1570,11 @@ vscpClientMqtt::handleMessage(const struct mosquitto_message *pmsg) } // If callback is defined send event - if (nullptr != m_evcallback) { - m_evcallback(&ev, m_callbackObject); + if (isCallbackEvActive()) { + m_callbackev(ev, getCallbackObj()); } - else if (nullptr != m_excallback) { - m_excallback(&ex, m_callbackObject); + else if (isCallbackExActive()) { + m_callbackex(ex, getCallbackObj()); } else { // Put event in input queue @@ -1611,11 +1611,11 @@ vscpClientMqtt::handleMessage(const struct mosquitto_message *pmsg) } // If callback is defined send event - if (nullptr != m_evcallback) { - m_evcallback(&ev, m_callbackObject); + if (isCallbackEvActive()) { + m_callbackev(ev, getCallbackObj()); } - else if (nullptr != m_excallback) { - m_excallback(&ex, m_callbackObject); + else if (isCallbackExActive()) { + m_callbackex(ex, getCallbackObj()); } else { // Put event in input queue @@ -2075,7 +2075,7 @@ vscpClientMqtt::connect(void) } // Start worker thread if a callback has been defined - if ((nullptr != m_evcallback) || (nullptr != m_excallback)) { + if (isCallbackEvActive()|| isCallbackExActive()) { int rv = pthread_create(&m_tid, nullptr, workerThread, this); switch (rv) { @@ -2114,7 +2114,7 @@ vscpClientMqtt::disconnect(void) spdlog::debug("MQTT CLIENT: Enter disconnect."); - if ((nullptr == m_evcallback) && (nullptr == m_excallback)) { + if (isCallbackEvActive() && isCallbackExActive()) { pthread_join(m_tid, nullptr); } @@ -2879,14 +2879,14 @@ vscpClientMqtt::getwcyd(uint64_t &wcyd) // int -vscpClientMqtt::setCallback(LPFNDLL_EV_CALLBACK m_evcallback, void *pData) +vscpClientMqtt::setCallbackEv(std::function callback, void *pData) { // Can not be called when connected if (m_bConnected) { return VSCP_ERROR_ERROR; } - CVscpClient::setCallback(m_evcallback, pData); + CVscpClient::setCallbackEv(callback, pData); return VSCP_ERROR_SUCCESS; } @@ -2896,14 +2896,14 @@ vscpClientMqtt::setCallback(LPFNDLL_EV_CALLBACK m_evcallback, void *pData) // int -vscpClientMqtt::setCallback(LPFNDLL_EX_CALLBACK m_excallback, void *pData) +vscpClientMqtt::setCallbackEx(std::function callback, void *pData) { // Can not be called when connected if (m_bConnected) { return VSCP_ERROR_ERROR; } - CVscpClient::setCallback(m_excallback, pData); + CVscpClient::setCallbackEx(callback, pData); return VSCP_ERROR_SUCCESS; } diff --git a/src/vscp/common/vscp_client_mqtt.h b/src/vscp/common/vscp_client_mqtt.h index 5e44c24bd..26d887683 100644 --- a/src/vscp/common/vscp_client_mqtt.h +++ b/src/vscp/common/vscp_client_mqtt.h @@ -461,7 +461,7 @@ class vscpClientMqtt : public CVscpClient { @param pData Pointer to optional user data. @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ - virtual int setCallback(LPFNDLL_EV_CALLBACK m_evcallback, void *pData = nullptr); + virtual int setCallbackEv(std::function callback, void *pData = nullptr); /*! Set (and enable) receive callback ex events @@ -469,7 +469,7 @@ class vscpClientMqtt : public CVscpClient { @param pData Pointer to optional user data. @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ - virtual int setCallback(LPFNDLL_EX_CALLBACK m_excallback, void *pData = nullptr); + virtual int setCallbackEx(std::function callback, void *pData = nullptr); /*! Return a JSON representation of connection diff --git a/src/vscp/common/vscp_client_socketcan.cpp b/src/vscp/common/vscp_client_socketcan.cpp index fb6170a1e..f0c2567be 100644 --- a/src/vscp/common/vscp_client_socketcan.cpp +++ b/src/vscp/common/vscp_client_socketcan.cpp @@ -749,46 +749,47 @@ vscpClientSocketCan::getResponseTimeout(void) void vscpClientSocketCan::sendToCallbacks(vscpEvent *pev) { - printf("sendToCallbacks\n"); - if (nullptr != m_evcallback) { - printf("----->\n"); - m_evcallback(pev, m_callbackObject); + if (isCallbackEvActive()) { + m_callbackev(*pev, getCallbackObj()); } - if (nullptr != m_excallback) { + if (isCallbackExActive()) { vscpEventEx ex; vscp_convertEventToEventEx(&ex, pev); - m_excallback(&ex, m_callbackObject); + m_callbackex(ex, getCallbackObj()); } } /////////////////////////////////////////////////////////////////////////////// -// setCallback +// setCallbackEv // int -vscpClientSocketCan::setCallback(LPFNDLL_EV_CALLBACK m_evcallback) +vscpClientSocketCan::setCallbackEv(std::function callback) { // Can not be called when connected if (m_bConnected) { return VSCP_ERROR_ERROR; } - m_evcallback = m_evcallback; + + CVscpClient::setCallbackEv(callback); + return VSCP_ERROR_SUCCESS; } /////////////////////////////////////////////////////////////////////////////// -// setCallback +// setCallbackEx // int -vscpClientSocketCan::setCallback(LPFNDLL_EX_CALLBACK m_excallback) +vscpClientSocketCan::setCallbackEx(std::function callback) { // Can not be called when connected if (m_bConnected) { return VSCP_ERROR_ERROR; } - m_excallback = m_excallback; + + CVscpClient::setCallbackEx(callback); return VSCP_ERROR_SUCCESS; } @@ -978,21 +979,21 @@ workerThread(void *pData) if (vscp_doLevel2Filter(pEvent, &pObj->m_filterIn)) { - if (nullptr != pObj->m_evcallback) { - pObj->m_evcallback(pEvent, pObj->m_callbackObject); + if (pObj->isCallbackEvActive()) { + pObj->m_callbackev(*pEvent, pObj->getCallbackObj()); } - if (nullptr != pObj->m_excallback) { + if (pObj->isCallbackExActive()) { vscpEventEx ex; if (vscp_convertEventToEventEx(&ex, pEvent)) { - pObj->m_excallback(&ex, pObj->m_callbackObject); + pObj->m_callbackex(ex, pObj->getCallbackObj()); } } // printf("Socketcan event: %X:%X\n", pEvent->vscp_class, pEvent->vscp_type); // Add to input queue only if no callback set - if ((nullptr == pObj->m_evcallback) && (nullptr == pObj->m_excallback)) { + if (pObj->isCallbackEvActive() && pObj->isCallbackExActive()) { // std::cout << "add to receive queue" << std::endl; pthread_mutex_lock(&pObj->m_mutexReceiveQueue); pObj->m_receiveList.push_back(pEvent); diff --git a/src/vscp/common/vscp_client_socketcan.h b/src/vscp/common/vscp_client_socketcan.h index ec4394716..4ad5ac460 100644 --- a/src/vscp/common/vscp_client_socketcan.h +++ b/src/vscp/common/vscp_client_socketcan.h @@ -205,13 +205,13 @@ class vscpClientSocketCan : public CVscpClient { Set (and enable) receive callback for events @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ - virtual int setCallback(LPFNDLL_EV_CALLBACK m_evcallback); + virtual int setCallbackEv(std::function callback); /*! Set (and enable) receive callback ex events @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ - virtual int setCallback(LPFNDLL_EX_CALLBACK m_excallback); + virtual int setCallbackEx(std::function callback); /*! Return a JSON representation of connection diff --git a/src/vscp/common/vscp_client_tcp.cpp b/src/vscp/common/vscp_client_tcp.cpp index 2daaa44aa..3115147c1 100644 --- a/src/vscp/common/vscp_client_tcp.cpp +++ b/src/vscp/common/vscp_client_tcp.cpp @@ -527,14 +527,14 @@ vscpClientTcp::getResponseTimeout(void) void vscpClientTcp::sendToCallbacks(vscpEvent *pev) { - if (nullptr != m_evcallback) { - m_evcallback(pev, m_callbackObject); + if (isCallbackEvActive()) { + m_callbackev(*pev, m_callbackObject); } - if (nullptr != m_excallback) { + if (isCallbackExActive()) { vscpEventEx ex; vscp_convertEventToEventEx(&ex, pev); - m_excallback(&ex, m_callbackObject); + m_callbackex(ex, m_callbackObject); } } diff --git a/src/vscp/common/vscp_client_ws1.cpp b/src/vscp/common/vscp_client_ws1.cpp index cb737e5c3..ee23697f0 100644 --- a/src/vscp/common/vscp_client_ws1.cpp +++ b/src/vscp/common/vscp_client_ws1.cpp @@ -509,7 +509,7 @@ vscpClientWs1::receive(vscpEvent &ev) } // only valid if no callback is defined - if ((nullptr != m_evcallback) || (nullptr != m_excallback)) { + if (m_bActiveCallbackEv || m_bActiveCallbackEx) { return VSCP_ERROR_NOT_SUPPORTED; } @@ -543,7 +543,7 @@ vscpClientWs1::receive(vscpEventEx &ex) } // only valid if no callback is defined - if ((nullptr != m_evcallback) || (nullptr != m_excallback)) { + if (m_bActiveCallbackEv || m_bActiveCallbackEx) { return VSCP_ERROR_NOT_SUPPORTED; } diff --git a/src/vscp/common/vscp_client_ws2.cpp b/src/vscp/common/vscp_client_ws2.cpp index 095f18366..fe7a3ed0f 100644 --- a/src/vscp/common/vscp_client_ws2.cpp +++ b/src/vscp/common/vscp_client_ws2.cpp @@ -558,7 +558,7 @@ vscpClientWs2::receive(vscpEvent &ev) } // only valid if no callback is defined - if ((nullptr != m_evcallback) || (nullptr != m_excallback)) { + if (isCallbackEvActive() || isCallbackExActive()) { return VSCP_ERROR_NOT_SUPPORTED; } @@ -592,7 +592,7 @@ vscpClientWs2::receive(vscpEventEx &ex) } // only valid if no callback is defined - if ((nullptr != m_evcallback) || (nullptr != m_excallback)) { + if (isCallbackEvActive() || isCallbackExActive()) { return VSCP_ERROR_NOT_SUPPORTED; }