The ThreadDispatcher class coordinates other communication threads and handles start up and shut down procedures. More...
#include <threaddispatcher.h>
Public Member Functions | |
void | dequeueResponse (std::string &response) |
Pop a received command response from the response queue. More... | |
void | dequeueSensorGroupMessage (std::string &response) |
Pop a received sensor group message from the message queue. More... | |
void | enableDebugMessages (debugCallbackPtr debug) |
Enable pass through of every line in the input buffer. More... | |
void | enableRawCommunication () |
Enables the transmission of raw messages to the serial device. More... | |
const bool | IsMessageQueueEmpty () const |
Is there a message in the message queue? More... | |
const bool | IsResponseQueueEmpty () const |
Is there a response in the response queue? More... | |
void | registerErrorCallback (debugCallbackPtr error) |
Register a callback to handle transmission/communication errors. More... | |
void | registerTextCallback (debugCallbackPtr text) |
Register a callback to handle plain text messages from the serial device. More... | |
void | setCommunicationCondVar (std::condition_variable *condVar) |
Register the condition variable of the Communication object in order to wakeup a waiting command response thread. More... | |
void | setCommunicationWakeUp (bool wakeUp) |
Set wether there is a command response thread waiting or not. More... | |
void | setReadingThread (ReadingThread *rxThread) |
Register ReadingThread with the thread dispatcher. More... | |
void | setSensorGroupThread (SensorGroupThread *grpThread) |
Register SensorGroupThread with the thread dispatcher. More... | |
void | startThread () |
Start dispatching thread, SensorGroupThread and ReadingThread. More... | |
void | stopThread () |
Stop dispatching thread, SensorGroupThread and ReadingThread. More... | |
ThreadDispatcher (const std::shared_ptr< Syntax > &syntax) | |
ThreadDispatcher constructor. More... | |
![]() | |
CommunicationThread () | |
CommunicationThread default constructor. More... | |
CommunicationThread (CommunicationThread &&other)=delete | |
CommunicationThread default Move initialization. More... | |
CommunicationThread (const CommunicationThread &other)=delete | |
CommunicationThread default Copy initialization. More... | |
CommunicationThread & | operator= (CommunicationThread &&other)=delete |
CommunicationThread default Move assignment. More... | |
CommunicationThread & | operator= (const CommunicationThread &other) |
CommunicationThread default Copy assignment. More... | |
void | sleep () |
Locks the current worker thread until wakeUp() is called. More... | |
void | wakeUp () |
Unlocks the current worker thread. More... | |
Private Member Functions | |
void | workerFunction () |
Worker function, responsible for dispatching the correct thread and observing incoming messages from the serial device. More... | |
Private Attributes | |
std::condition_variable * | comCV |
std::queue< std::string > | commandResponse |
debugCallbackPtr | debug |
bool | debugMsgEnabled |
debugCallbackPtr | error |
bool | errorCBregistered |
bool | rawCommunicationEnabled |
ReadingThread * | readingThread |
std::queue< std::string > | sensorGroupMessage |
SensorGroupThread * | sensorGroupThread |
std::shared_ptr< Syntax > | syntax |
debugCallbackPtr | text |
bool | textCBregistered |
bool | wakeUpCommunication |
Additional Inherited Members | |
![]() | |
bool | active |
std::thread | worker |
The ThreadDispatcher class coordinates other communication threads and handles start up and shut down procedures.
Definition at line 34 of file threaddispatcher.h.
ThreadDispatcher::ThreadDispatcher | ( | const std::shared_ptr< Syntax > & | syntax | ) |
ThreadDispatcher constructor.
[in] | syntax | Syntax object |
Definition at line 9 of file threaddispatcher.cpp.
void ThreadDispatcher::dequeueResponse | ( | std::string & | response | ) |
Pop a received command response from the response queue.
[in] | response | response message from the serial device |
Definition at line 136 of file threaddispatcher.cpp.
void ThreadDispatcher::dequeueSensorGroupMessage | ( | std::string & | response | ) |
Pop a received sensor group message from the message queue.
[in] | response | sensor group message from the serial device |
Definition at line 142 of file threaddispatcher.cpp.
void ThreadDispatcher::enableDebugMessages | ( | debugCallbackPtr | debug | ) |
Enable pass through of every line in the input buffer.
This will call the registered callback whenever there is a new line in the input buffer. The callback decides what to do with that information.
[in] | debug | Function pointer of the debug callback. |
Definition at line 39 of file threaddispatcher.cpp.
void ThreadDispatcher::enableRawCommunication | ( | ) |
Enables the transmission of raw messages to the serial device.
Definition at line 45 of file threaddispatcher.cpp.
const bool ThreadDispatcher::IsMessageQueueEmpty | ( | ) | const |
Is there a message in the message queue?
Definition at line 153 of file threaddispatcher.cpp.
const bool ThreadDispatcher::IsResponseQueueEmpty | ( | ) | const |
Is there a response in the response queue?
Definition at line 148 of file threaddispatcher.cpp.
void ThreadDispatcher::registerErrorCallback | ( | debugCallbackPtr | error | ) |
Register a callback to handle transmission/communication errors.
The registered function will be called whenever an error during transmission of an outgoing, or parsing of an incoming message occurs. The callback decides what to do with that information.
[in] | error | Function pointer of the error callback. |
std::exception |
Definition at line 122 of file threaddispatcher.cpp.
void ThreadDispatcher::registerTextCallback | ( | debugCallbackPtr | text | ) |
Register a callback to handle plain text messages from the serial device.
The registered function will be called whenever a plain text message has been received from the serial device. The callback decides what to do with that information.
[in] | text | Function pointer of the text callback. |
std::exception |
Definition at line 130 of file threaddispatcher.cpp.
void ThreadDispatcher::setCommunicationCondVar | ( | std::condition_variable * | condVar | ) |
Register the condition variable of the Communication object in order to wakeup a waiting command response thread.
condVar | pointer to a condition variable |
Definition at line 117 of file threaddispatcher.cpp.
void ThreadDispatcher::setCommunicationWakeUp | ( | bool | wakeUp | ) |
Set wether there is a command response thread waiting or not.
wakeUp | true a command is waiting for response |
Definition at line 158 of file threaddispatcher.cpp.
void ThreadDispatcher::setReadingThread | ( | ReadingThread * | rxThread | ) |
Register ReadingThread with the thread dispatcher.
rxThread | pointer to a ReadingThread object |
Definition at line 101 of file threaddispatcher.cpp.
void ThreadDispatcher::setSensorGroupThread | ( | SensorGroupThread * | grpThread | ) |
Register SensorGroupThread with the thread dispatcher.
rxThread | pointer to a SensorGroupThread object |
Definition at line 109 of file threaddispatcher.cpp.
|
virtual |
Start dispatching thread, SensorGroupThread and ReadingThread.
Implements CommunicationThread.
Definition at line 21 of file threaddispatcher.cpp.
|
virtual |
Stop dispatching thread, SensorGroupThread and ReadingThread.
Implements CommunicationThread.
Definition at line 30 of file threaddispatcher.cpp.
|
privatevirtual |
Worker function, responsible for dispatching the correct thread and observing incoming messages from the serial device.
Implements CommunicationThread.
Definition at line 50 of file threaddispatcher.cpp.
|
private |
condition variable of the Communication object
Definition at line 136 of file threaddispatcher.h.
|
private |
Incoming command response queue
Definition at line 135 of file threaddispatcher.h.
|
private |
Pointer to the debug handling function
Definition at line 127 of file threaddispatcher.h.
|
private |
Is a debug callback available?
Definition at line 130 of file threaddispatcher.h.
|
private |
Pointer to the error handling function
Definition at line 128 of file threaddispatcher.h.
|
private |
Is an error callback available?
Definition at line 132 of file threaddispatcher.h.
|
private |
Is a raw communication enabled?
Definition at line 131 of file threaddispatcher.h.
|
private |
Pointer to the ReadingThread object
Definition at line 125 of file threaddispatcher.h.
|
private |
Incoming sensor message queue
Definition at line 137 of file threaddispatcher.h.
|
private |
Pointer to the SensorGroupThread object
Definition at line 126 of file threaddispatcher.h.
|
private |
Pointer to a Syntax object
Definition at line 134 of file threaddispatcher.h.
|
private |
Pointer to the text handling function
Definition at line 129 of file threaddispatcher.h.
|
private |
Is an text callback available?
Definition at line 133 of file threaddispatcher.h.
|
private |
Definition at line 144 of file threaddispatcher.h.