Skip to content

Commit

Permalink
Added blocking receive methods to base communication clients
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Dec 13, 2024
1 parent 0a64641 commit 38c4e01
Show file tree
Hide file tree
Showing 14 changed files with 582 additions and 3 deletions.
57 changes: 57 additions & 0 deletions src/vscp/common/vscp-client-canal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
24 changes: 24 additions & 0 deletions src/vscp/common/vscp-client-canal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
59 changes: 58 additions & 1 deletion src/vscp/common/vscp-client-mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -2948,7 +3005,7 @@ win_usleep(__int64 usec)
#endif

///////////////////////////////////////////////////////////////////////////////
// Callback workerthread
// Workerthread
//
// This thread call the appropriate callback when events are received
//
Expand Down
30 changes: 30 additions & 0 deletions src/vscp/common/vscp-client-mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions src/vscp/common/vscp-client-multicast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
26 changes: 25 additions & 1 deletion src/vscp/common/vscp-client-multicast.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/*!
Expand Down
Loading

0 comments on commit 38c4e01

Please sign in to comment.