Help in "routing" events between classes
Posted: Tue Oct 16, 2018 9:53 am
I have a Serial class that manages the transmission of a RS232, and a listening thread to read that port.
It is declared like this:
When the listening thread detects a '\r' in the serial port it fires the wxEVT_MYTHREAD event (using wxPostEvent), handled by the OnSerialRxCompleted function, which stores the rx buffer and fires the wxEVT_SERIAL using QueueEvent.
Right now this event is handled on the main form. I'd like instead to have a class (let's call it "cDataHandler") that handle that wxEVT_SERIAL event, do protocol checks on the received message, prepare some data and finally fires an event for the main form (with a enumerated parameter), which will show the updated data (and only those thanks to that parameter) on the screen.
I'm confused on how should i declare that "cDataHandler" and how to "bind" the events.
Thnx
It is declared like this:
Code: Select all
wxDECLARE_EVENT(wxEVT_MYTHREAD, wxCommandEvent);
wxDECLARE_EVENT(wxEVT_SERIAL, wxCommandEvent);
class CommManager : public wxEvtHandler, public wxThreadHelper
{
public:
/** Default constructor */
CommManager() {
Bind(wxEVT_MYTHREAD, &CommManager::OnSerialRxCompleted, this);
};
/** Default destructor */
virtual ~CommManager();
// [...]
private:
void OnSerialRxCompleted(wxCommandEvent& SerialEvent);
// [...]
}
Right now this event is handled on the main form. I'd like instead to have a class (let's call it "cDataHandler") that handle that wxEVT_SERIAL event, do protocol checks on the received message, prepare some data and finally fires an event for the main form (with a enumerated parameter), which will show the updated data (and only those thanks to that parameter) on the screen.
I'm confused on how should i declare that "cDataHandler" and how to "bind" the events.
Thnx