Public Member Functions | Protected Member Functions

ExampleNetworkThread Class Reference

Network thread of example plugin. More...

#include <plugins/examples/basics/net_thread.h>

Inheritance diagram for ExampleNetworkThread:
Inheritance graph
[legend]

List of all members.

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.

Detailed Description

Network thread of example plugin.

Author:
Tim Niemueller

Definition at line 31 of file net_thread.h.


Constructor & Destructor Documentation

ExampleNetworkThread::ExampleNetworkThread ( const char *  name  ) 

Constructor.

Parameters:
name thread name

Definition at line 39 of file net_thread.cpp.

ExampleNetworkThread::~ExampleNetworkThread (  )  [virtual]

Destructor.

Definition at line 47 of file net_thread.cpp.


Member Function Documentation

void ExampleNetworkThread::client_connected ( unsigned int  clid  )  [virtual]

Client connected.

Ignored.

Parameters:
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.

Parameters:
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]
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.

See also:
Thread::init()
Fawkes Thread Aspects

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.

See also:
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.

See also:
Thread::run()

Definition at line 52 of file net_thread.h.


The documentation for this class was generated from the following files: