Network thread of example plugin. More...
#include <plugins/examples/basics/net_thread.h>
Public Member Functions | |
ExampleNetworkThread (const char *name) | |
Constructor. | |
virtual | ~ExampleNetworkThread () |
Destructor. | |
virtual void | init () |
Initialize thread. | |
virtual void | finalize () |
virtual void | loop () |
Thread loop. | |
virtual void | handle_network_message (fawkes::FawkesNetworkMessage *msg) |
Handle network message. | |
virtual void | client_connected (unsigned int clid) |
Client connected. | |
virtual void | client_disconnected (unsigned int clid) |
Client disconnected. | |
Protected Member Functions | |
virtual void | run () |
Stub to see name in backtrace for easier debugging. |
Network thread of example plugin.
Definition at line 31 of file net_thread.h.
ExampleNetworkThread::ExampleNetworkThread | ( | const char * | name | ) |
ExampleNetworkThread::~ExampleNetworkThread | ( | ) | [virtual] |
Destructor.
Definition at line 47 of file net_thread.cpp.
void ExampleNetworkThread::client_connected | ( | unsigned int | clid | ) | [virtual] |
Client connected.
Ignored.
clid | client ID |
Implements fawkes::FawkesNetworkHandler.
Definition at line 121 of file net_thread.cpp.
References fawkes::Logger::log_info(), and fawkes::LoggingAspect::logger.
void ExampleNetworkThread::client_disconnected | ( | unsigned int | clid | ) | [virtual] |
Client disconnected.
If the client was a subscriber it is removed.
clid | client ID |
Implements fawkes::FawkesNetworkHandler.
Definition at line 132 of file net_thread.cpp.
References fawkes::Logger::log_info(), and fawkes::LoggingAspect::logger.
void ExampleNetworkThread::handle_network_message | ( | fawkes::FawkesNetworkMessage * | msg | ) | [virtual] |
Handle network message.
The message is put into the inbound queue and processed in processAfterLoop().
msg | message |
Implements fawkes::FawkesNetworkHandler.
Definition at line 100 of file net_thread.cpp.
References fawkes::FawkesNetworkMessage::clid(), fawkes::FawkesNetworkAspect::fnethub, fawkes::Logger::log_error(), fawkes::Logger::log_info(), fawkes::LoggingAspect::logger, fawkes::FawkesNetworkMessage::msgid(), fawkes::FawkesNetworkMessage::payload(), fawkes::FawkesNetworkMessage::payload_size(), and fawkes::FawkesNetworkHub::send().
void ExampleNetworkThread::init | ( | ) | [virtual] |
Initialize thread.
This method is called just after all aspects have been initialized but before the thread is run. Here we add this thread as a handler to the Fawkes network hub. This cannot happen in the constructor as fnethandler has not been initialized at that time.
Definition at line 61 of file net_thread.cpp.
References fawkes::FawkesNetworkHub::add_handler(), and fawkes::FawkesNetworkAspect::fnethub.
void ExampleNetworkThread::loop | ( | ) | [virtual] |
Thread loop.
Nothing to do here since nobody will every wake us up (we do not have the BlockedTimingAspect nor does any other thread wake us up). This is ok because everything is done in the network handler call.
Note that in general incoming messages should be parsed and appropriate actions enqueued. Then in the next loop iteration you process these incoming messages. This is the best way to avoid strange behavior and low latencies in network message handling.
As an example for this see the FawkesConfigManager.
Definition at line 90 of file net_thread.cpp.
virtual void ExampleNetworkThread::run | ( | ) | [inline, protected, virtual] |
Stub to see name in backtrace for easier debugging.
Definition at line 52 of file net_thread.h.