From 38c4e01d317648953ebe194587864196b51ff354 Mon Sep 17 00:00:00 2001 From: Ake Hedman Date: Fri, 13 Dec 2024 10:59:01 +0100 Subject: [PATCH] Added blocking receive methods to base communication clients --- src/vscp/common/vscp-client-canal.cpp | 57 ++++++++++++++++++++++ src/vscp/common/vscp-client-canal.h | 24 +++++++++ src/vscp/common/vscp-client-mqtt.cpp | 59 ++++++++++++++++++++++- src/vscp/common/vscp-client-mqtt.h | 30 ++++++++++++ src/vscp/common/vscp-client-multicast.cpp | 57 ++++++++++++++++++++++ src/vscp/common/vscp-client-multicast.h | 26 +++++++++- src/vscp/common/vscp-client-tcp.cpp | 57 ++++++++++++++++++++++ src/vscp/common/vscp-client-tcp.h | 32 +++++++++++- src/vscp/common/vscp-client-udp.cpp | 57 ++++++++++++++++++++++ src/vscp/common/vscp-client-udp.h | 24 +++++++++ src/vscp/common/vscp-client-ws1.cpp | 57 ++++++++++++++++++++++ src/vscp/common/vscp-client-ws1.h | 24 +++++++++ src/vscp/common/vscp-client-ws2.cpp | 57 ++++++++++++++++++++++ src/vscp/common/vscp-client-ws2.h | 24 +++++++++ 14 files changed, 582 insertions(+), 3 deletions(-) diff --git a/src/vscp/common/vscp-client-canal.cpp b/src/vscp/common/vscp-client-canal.cpp index dfaa43c87..dbaf4900f 100644 --- a/src/vscp/common/vscp-client-canal.cpp +++ b/src/vscp/common/vscp-client-canal.cpp @@ -374,6 +374,63 @@ vscpClientCanal::receive(canalMsg &msg) return (rv ? VSCP_ERROR_SUCCESS : VSCP_ERROR_ERROR); } +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientCanal::receiveBlocking(vscpEvent &ev, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(ev); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientCanal::receiveBlocking(vscpEventEx &ex, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(ex); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientCanal::receiveBlocking(canalMsg &msg, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(msg); +} + /////////////////////////////////////////////////////////////////////////////// // setfilter // diff --git a/src/vscp/common/vscp-client-canal.h b/src/vscp/common/vscp-client-canal.h index e89a08c50..fdce00b8e 100644 --- a/src/vscp/common/vscp-client-canal.h +++ b/src/vscp/common/vscp-client-canal.h @@ -101,18 +101,42 @@ class vscpClientCanal : public CVscpClient { */ virtual int receive(vscpEvent &ev); + /*! + Blocking receive of VSCP event ex from remote host + @param ev VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEvent &ev, long timeout = 100 ); + /*! Receive VSCP event ex from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(vscpEventEx &ex); + /*! + Blocking receive of VSCP event ex from remote host + @param ex VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEventEx &ex, long timeout = 100 ); + /*! Receive CAN(AL) message from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(canalMsg &msg); + /*! + Receive blocking CAN(AL) message from remote host + @param msg CANAL message that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(canalMsg &msg, long timeout = 100); + /*! Set interface filter @param filter VSCP Filter to set. diff --git a/src/vscp/common/vscp-client-mqtt.cpp b/src/vscp/common/vscp-client-mqtt.cpp index a1b185b07..fe2e8c887 100644 --- a/src/vscp/common/vscp-client-mqtt.cpp +++ b/src/vscp/common/vscp-client-mqtt.cpp @@ -2782,6 +2782,63 @@ vscpClientMqtt::receive(canalMsg &msg) return VSCP_ERROR_SUCCESS; } +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientMqtt::receiveBlocking(vscpEvent &ev, long timeout) +{ + if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + if (errno == ETIMEDOUT) { + return VSCP_ERROR_TIMEOUT; + } + else { + return VSCP_ERROR_ERROR; + } + } + + return receive(ev); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientMqtt::receiveBlocking(vscpEventEx &ex, long timeout) +{ + if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + if (errno == ETIMEDOUT) { + return VSCP_ERROR_TIMEOUT; + } + else { + return VSCP_ERROR_ERROR; + } + } + + return receive(ex); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientMqtt::receiveBlocking(canalMsg &msg, long timeout) +{ + if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + if (errno == ETIMEDOUT) { + return VSCP_ERROR_TIMEOUT; + } + else { + return VSCP_ERROR_ERROR; + } + } + + return receive(msg); +} + /////////////////////////////////////////////////////////////////////////////// // setfilter // @@ -2948,7 +3005,7 @@ win_usleep(__int64 usec) #endif /////////////////////////////////////////////////////////////////////////////// -// Callback workerthread +// Workerthread // // This thread call the appropriate callback when events are received // diff --git a/src/vscp/common/vscp-client-mqtt.h b/src/vscp/common/vscp-client-mqtt.h index 85429852a..2fcc5b997 100644 --- a/src/vscp/common/vscp-client-mqtt.h +++ b/src/vscp/common/vscp-client-mqtt.h @@ -399,18 +399,42 @@ class vscpClientMqtt : public CVscpClient { */ virtual int receive(vscpEvent &ev); + /*! + Blocking receive of VSCP event ex from remote host + @param ev VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEvent &ev, long timeout = 100 ); + /*! Receive VSCP event ex from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(vscpEventEx &ex); + /*! + Blocking receive of VSCP event ex from remote host + @param ex VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEventEx &ex, long timeout = 100 ); + /*! Receive CAN(AL) message from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(canalMsg &msg); + /*! + Receive blocking CAN(AL) message from remote host + @param msg CANAL message that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(canalMsg &msg, long timeout = 100); + /*! Set interface filter @param filter VSCP Filter to set. @@ -705,6 +729,12 @@ class vscpClientMqtt : public CVscpClient { */ pthread_mutex_t m_mutexif; + /*! + Event object to indicate that there is an event in the + output queue + */ + sem_t m_semReceiveQueue; + /*! If no callback is defined received events are connected in this queue diff --git a/src/vscp/common/vscp-client-multicast.cpp b/src/vscp/common/vscp-client-multicast.cpp index b8912aafa..56a94f319 100644 --- a/src/vscp/common/vscp-client-multicast.cpp +++ b/src/vscp/common/vscp-client-multicast.cpp @@ -171,6 +171,63 @@ vscpClientMulticast::receive(canalMsg &msg) return VSCP_ERROR_SUCCESS; } +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientMulticast::receiveBlocking(vscpEvent &ev, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(ev); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientMulticast::receiveBlocking(vscpEventEx &ex, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(ex); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientMulticast::receiveBlocking(canalMsg &msg, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(msg); +} + ////////////////////////////////////////////////////////////////////////////// // setfilter // diff --git a/src/vscp/common/vscp-client-multicast.h b/src/vscp/common/vscp-client-multicast.h index 7f6f8ecf9..748d4e398 100644 --- a/src/vscp/common/vscp-client-multicast.h +++ b/src/vscp/common/vscp-client-multicast.h @@ -78,16 +78,40 @@ class vscpClientMulticast : public CVscpClient { */ virtual int receive(vscpEvent &ev); + /*! + Blocking receive of VSCP event ex from remote host + @param ev VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEvent &ev, long timeout = 100); + /*! Receive VSCP event ex from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(vscpEventEx &ex); + /*! + Blocking receive of VSCP event ex from remote host + @param ex VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEventEx &ex, long timeout = 100); + + /*! + Receive blocking CAN(AL) message from remote host + @param msg CANAL message that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(canalMsg &msg, long timeout = 100); + /*! Receive CAN(AL) message from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. -*/ + */ virtual int receive(canalMsg &msg); /*! diff --git a/src/vscp/common/vscp-client-tcp.cpp b/src/vscp/common/vscp-client-tcp.cpp index 9111cccc3..577f23537 100644 --- a/src/vscp/common/vscp-client-tcp.cpp +++ b/src/vscp/common/vscp-client-tcp.cpp @@ -409,6 +409,63 @@ vscpClientTcp::receive(canalMsg &msg) return VSCP_ERROR_SUCCESS; } +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientTcp::receiveBlocking(vscpEvent &ev, long timeout) +{ + if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + if (errno == ETIMEDOUT) { + return VSCP_ERROR_TIMEOUT; + } + else { + return VSCP_ERROR_ERROR; + } + } + + return receive(ev); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientTcp::receiveBlocking(vscpEventEx &ex, long timeout) +{ + if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + if (errno == ETIMEDOUT) { + return VSCP_ERROR_TIMEOUT; + } + else { + return VSCP_ERROR_ERROR; + } + } + + return receive(ex); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientTcp::receiveBlocking(canalMsg &msg, long timeout) +{ + if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + if (errno == ETIMEDOUT) { + return VSCP_ERROR_TIMEOUT; + } + else { + return VSCP_ERROR_ERROR; + } + } + + return receive(msg); +} + /////////////////////////////////////////////////////////////////////////////// // setfilter // diff --git a/src/vscp/common/vscp-client-tcp.h b/src/vscp/common/vscp-client-tcp.h index af59e9593..576d9f627 100644 --- a/src/vscp/common/vscp-client-tcp.h +++ b/src/vscp/common/vscp-client-tcp.h @@ -98,18 +98,42 @@ class vscpClientTcp : public CVscpClient { */ virtual int receive(vscpEvent &ev); + /*! + Blocking receive of VSCP event ex from remote host + @param ev VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEvent &ev, long timeout = 100); + /*! Receive VSCP event ex from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(vscpEventEx &ex); + /*! + Blocking receive of VSCP event ex from remote host + @param ex VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEventEx &ex, long timeout = 100); + /*! Receive CAN(AL) message from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(canalMsg &msg); + /*! + Receive blocking CAN(AL) message from remote host + @param msg CANAL message that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(canalMsg &msg, long timeout = 100); + /*! Set interface filter @param filter VSCP Filter to set. @@ -236,9 +260,15 @@ class vscpClientTcp : public CVscpClient { /// Flag for workerthread run as long it's true bool m_bRun; - /// Mutex to protect receive tcop/ip object + /// Mutex to protect receive tcp/ip object std::mutex m_mutexReceive; + /*! + Event object to indicate that there is an event in the + output queue + */ + sem_t m_semReceiveQueue; + /// Used for channel id (prevent sent events from being received) uint32_t m_obid; diff --git a/src/vscp/common/vscp-client-udp.cpp b/src/vscp/common/vscp-client-udp.cpp index 44a65f875..6462ce215 100644 --- a/src/vscp/common/vscp-client-udp.cpp +++ b/src/vscp/common/vscp-client-udp.cpp @@ -170,6 +170,63 @@ vscpClientUdp::receive(canalMsg &msg) return VSCP_ERROR_SUCCESS; } +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientUdp::receiveBlocking(vscpEvent &ev, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(ev); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientUdp::receiveBlocking(vscpEventEx &ex, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(ex); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientUdp::receiveBlocking(canalMsg &msg, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(msg); +} + ////////////////////////////////////////////////////////////////////////////// // setfilter // diff --git a/src/vscp/common/vscp-client-udp.h b/src/vscp/common/vscp-client-udp.h index 20a435399..d542fa6dd 100644 --- a/src/vscp/common/vscp-client-udp.h +++ b/src/vscp/common/vscp-client-udp.h @@ -78,18 +78,42 @@ class vscpClientUdp : public CVscpClient { */ virtual int receive(vscpEvent &ev); + /*! + Blocking receive of VSCP event ex from remote host + @param ev VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEvent &ev, long timeout = 100 ); + /*! Receive VSCP event ex from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(vscpEventEx &ex); + /*! + Blocking receive of VSCP event ex from remote host + @param ex VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEventEx &ex, long timeout = 100 ); + /*! Receive CAN(AL) message from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(canalMsg &msg); + /*! + Receive blocking CAN(AL) message from remote host + @param msg CANAL message that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(canalMsg &msg, long timeout = 100); + /*! Set interface filter @param filter VSCP Filter to set. diff --git a/src/vscp/common/vscp-client-ws1.cpp b/src/vscp/common/vscp-client-ws1.cpp index 52fdd3379..a6d25a8e4 100644 --- a/src/vscp/common/vscp-client-ws1.cpp +++ b/src/vscp/common/vscp-client-ws1.cpp @@ -582,6 +582,63 @@ vscpClientWs1::receive(canalMsg &msg) return VSCP_ERROR_SUCCESS; } +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientWs1::receiveBlocking(vscpEvent &ev, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(ev); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientWs1::receiveBlocking(vscpEventEx &ex, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(ex); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientWs1::receiveBlocking(canalMsg &msg, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(msg); +} + /////////////////////////////////////////////////////////////////////////////// // setfilter // diff --git a/src/vscp/common/vscp-client-ws1.h b/src/vscp/common/vscp-client-ws1.h index dbc15d7cb..a6eca54ab 100644 --- a/src/vscp/common/vscp-client-ws1.h +++ b/src/vscp/common/vscp-client-ws1.h @@ -110,18 +110,42 @@ class vscpClientWs1 : public CVscpClient { */ virtual int receive(vscpEvent &ev); + /*! + Blocking receive of VSCP event ex from remote host + @param ev VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEvent &ev, long timeout = 100 ); + /*! Receive VSCP event ex from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(vscpEventEx &ex); + /*! + Blocking receive of VSCP event ex from remote host + @param ex VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEventEx &ex, long timeout = 100 ); + /*! Receive CAN(AL) message from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(canalMsg &msg); + /*! + Receive blocking CAN(AL) message from remote host + @param msg CANAL message that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(canalMsg &msg, long timeout = 100); + /*! Set interface filter @param filter VSCP Filter to set. diff --git a/src/vscp/common/vscp-client-ws2.cpp b/src/vscp/common/vscp-client-ws2.cpp index e7e8bbbe9..d1de728fa 100644 --- a/src/vscp/common/vscp-client-ws2.cpp +++ b/src/vscp/common/vscp-client-ws2.cpp @@ -633,6 +633,63 @@ vscpClientWs2::receive(canalMsg &msg) return VSCP_ERROR_SUCCESS; } +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientWs2::receiveBlocking(vscpEvent &ev, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(ev); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientWs2::receiveBlocking(vscpEventEx &ex, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(ex); +} + +/////////////////////////////////////////////////////////////////////////////// +// receiveBlocking +// + +int +vscpClientWs2::receiveBlocking(canalMsg &msg, long timeout) +{ + // if (-1 == vscp_sem_wait(&m_semReceiveQueue, timeout)) { + // if (errno == ETIMEDOUT) { + // return VSCP_ERROR_TIMEOUT; + // } + // else { + // return VSCP_ERROR_ERROR; + // } + // } + + return receive(msg); +} + /////////////////////////////////////////////////////////////////////////////// // setfilter // diff --git a/src/vscp/common/vscp-client-ws2.h b/src/vscp/common/vscp-client-ws2.h index 685ee2426..170eea97c 100644 --- a/src/vscp/common/vscp-client-ws2.h +++ b/src/vscp/common/vscp-client-ws2.h @@ -110,18 +110,42 @@ class vscpClientWs2 : public CVscpClient { */ virtual int receive(vscpEvent &ev); + /*! + Blocking receive of VSCP event ex from remote host + @param ev VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEvent &ev, long timeout = 100 ); + /*! Receive VSCP event ex from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(vscpEventEx &ex); + /*! + Blocking receive of VSCP event ex from remote host + @param ex VSCP event ex that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(vscpEventEx &ex, long timeout = 100 ); + /*! Receive CAN(AL) message from remote host @return Return VSCP_ERROR_SUCCESS of OK and error code else. */ virtual int receive(canalMsg &msg); + /*! + Receive blocking CAN(AL) message from remote host + @param msg CANAL message that will get the result. + @param timeout Timeout in milliseconds. Default is 100 ms. + @return Return VSCP_ERROR_SUCCESS of OK and error code else. + */ + virtual int receiveBlocking(canalMsg &msg, long timeout = 100); + /*! Set interface filter @param filter VSCP Filter to set.