Fawkes API  Fawkes Development Version
fawkes::ConnectionDispatcher Class Reference

Watches network client events and dispatches them as signals. More...

#include <>>

Inheritance diagram for fawkes::ConnectionDispatcher:

Public Member Functions

 ConnectionDispatcher (unsigned int cid=FAWKES_CID_OBSERVER_MODE)
 Constructor. More...
 
 ConnectionDispatcher (const char *hostname, unsigned short int port, unsigned int cid=FAWKES_CID_OBSERVER_MODE)
 Constructor. More...
 
virtual ~ConnectionDispatcher ()
 Destructor. More...
 
void set_cid (unsigned int cid)
 Set component ID. More...
 
void set_client (FawkesNetworkClient *client)
 Set Fawkes network client. More...
 
FawkesNetworkClientget_client ()
 Get client. More...
 
sigc::signal< void > signal_connected ()
 Get "connected" signal. More...
 
sigc::signal< void > signal_disconnected ()
 Get "disconnected" signal. More...
 
sigc::signal< void, FawkesNetworkMessage * > signal_message_received ()
 Get "message received" signal. More...
 
virtual void deregistered (unsigned int id) throw ()
 This handler has been deregistered. More...
 
virtual void inbound_received (FawkesNetworkMessage *m, unsigned int id) throw ()
 Called for incoming messages. More...
 
virtual void connection_died (unsigned int id) throw ()
 Client connection died. More...
 
virtual void connection_established (unsigned int id) throw ()
 Client has established a connection. More...
 
 operator bool ()
 Check if client is set and connection has been established. More...
 
- Public Member Functions inherited from fawkes::FawkesNetworkClientHandler
virtual ~FawkesNetworkClientHandler ()
 Empty virtual destructor. More...
 

Protected Member Functions

virtual void on_connection_established ()
 Internal event handler. More...
 
virtual void on_connection_died ()
 Internal event handler. More...
 
virtual void on_message_received ()
 Internal event handler. More...
 

Detailed Description

Watches network client events and dispatches them as signals.

Author
Tim Niemueller

Definition at line 37 of file connection_dispatcher.h.

Constructor & Destructor Documentation

◆ ConnectionDispatcher() [1/2]

fawkes::ConnectionDispatcher::ConnectionDispatcher ( unsigned int  cid = FAWKES_CID_OBSERVER_MODE)

Constructor.

Parameters
cidcomponent ID to register this dispatcher for. This is relevant if you want to use the message received signal!

Definition at line 41 of file connection_dispatcher.cpp.

References fawkes::FawkesNetworkClient::register_handler().

◆ ConnectionDispatcher() [2/2]

fawkes::ConnectionDispatcher::ConnectionDispatcher ( const char *  hostname,
unsigned short int  port,
unsigned int  cid = FAWKES_CID_OBSERVER_MODE 
)

Constructor.

Parameters
cidcomponent ID to register this dispatcher for. This is relevant if you want to use the message received signal!
hostnamehostname to connect to
portport to connect to

Definition at line 58 of file connection_dispatcher.cpp.

References fawkes::FawkesNetworkClient::register_handler().

◆ ~ConnectionDispatcher()

fawkes::ConnectionDispatcher::~ConnectionDispatcher ( )
virtual

Member Function Documentation

◆ connection_died()

void fawkes::ConnectionDispatcher::connection_died ( unsigned int  id)
throw (
)
virtual

Client connection died.

This method is used to inform handlers that the connection has died for any reason. No more data can be send and no more messages should be enqueued because it is unclear when they would be sent.

Parameters
idthe id of the calling client

Implements fawkes::FawkesNetworkClientHandler.

Definition at line 196 of file connection_dispatcher.cpp.

◆ connection_established()

void fawkes::ConnectionDispatcher::connection_established ( unsigned int  id)
throw (
)
virtual

Client has established a connection.

Whenever the client establishes a connection this is signaled to handlers with this method. You can register to a client at any time, you may even enqueue messages to a client while the connection is dead. If the client at some point gets connected again, the messages will then be send out in one go. You should use this in your application though to only send data if the connection is alive and you should let the user know about the connection status.

Parameters
idthe id of the calling client

Implements fawkes::FawkesNetworkClientHandler.

Definition at line 203 of file connection_dispatcher.cpp.

◆ deregistered()

void fawkes::ConnectionDispatcher::deregistered ( unsigned int  id)
throw (
)
virtual

This handler has been deregistered.

This is called when this handler is deregistered from the FawkesNetworkClient. Sometimes you may not want to allow this and post a big fat warning into the log.

Parameters
idthe id of the calling client

Implements fawkes::FawkesNetworkClientHandler.

Definition at line 180 of file connection_dispatcher.cpp.

◆ get_client()

◆ inbound_received()

void fawkes::ConnectionDispatcher::inbound_received ( FawkesNetworkMessage m,
unsigned int  id 
)
throw (
)
virtual

Called for incoming messages.

This is called when an incoming message has been received. If this method was called one or more times then the a previously carried out wait(cid) call will continue.

Parameters
mMessage to handle
idthe id of the calling client

Implements fawkes::FawkesNetworkClientHandler.

Definition at line 187 of file connection_dispatcher.cpp.

References fawkes::LockQueue< Type >::push_locked().

◆ on_connection_died()

void fawkes::ConnectionDispatcher::on_connection_died ( )
protectedvirtual

Internal event handler.

Called by dispatcher to emit signal.

Definition at line 156 of file connection_dispatcher.cpp.

Referenced by ~ConnectionDispatcher().

◆ on_connection_established()

void fawkes::ConnectionDispatcher::on_connection_established ( )
protectedvirtual

Internal event handler.

Called by dispatcher to emit signal.

Definition at line 146 of file connection_dispatcher.cpp.

Referenced by ~ConnectionDispatcher().

◆ on_message_received()

void fawkes::ConnectionDispatcher::on_message_received ( )
protectedvirtual

Internal event handler.

Called by dispatcher to emit signal.

Definition at line 166 of file connection_dispatcher.cpp.

References fawkes::LockQueue< Type >::lock(), fawkes::LockQueue< Type >::unlock(), and fawkes::RefCount::unref().

Referenced by ~ConnectionDispatcher().

◆ operator bool()

fawkes::ConnectionDispatcher::operator bool ( )

Check if client is set and connection has been established.

Returns
true if a client exists and a connection is established, false otherwise.

Definition at line 136 of file connection_dispatcher.cpp.

References fawkes::FawkesNetworkClient::connected().

◆ set_cid()

void fawkes::ConnectionDispatcher::set_cid ( unsigned int  cid)

Set component ID.

Set the component ID you want to register this connection dispatcher on. By default the connection dispatcher uses the observer mode to only provide connection status signals. If you want to use the dispatcher to be signaled for incoming messages you have to set the appropriate component ID.

Parameters
cidcomponent ID

Definition at line 93 of file connection_dispatcher.cpp.

References fawkes::FawkesNetworkClient::deregister_handler(), and fawkes::FawkesNetworkClient::register_handler().

◆ set_client()

void fawkes::ConnectionDispatcher::set_client ( FawkesNetworkClient client)

Set Fawkes network client.

The instance you set is not owned by the ConnectionDispatcher, it's only used. You have to delete it when finished. Similarly you have to make sure that the client is valid as long as it is set on the dispatcher.

Parameters
clientFawkes network client to set.

Definition at line 110 of file connection_dispatcher.cpp.

References fawkes::FawkesNetworkClient::deregister_handler(), and fawkes::FawkesNetworkClient::register_handler().

Referenced by fawkes::LogView::set_client(), fawkes::PluginTreeView::set_network_client(), and ~ConnectionDispatcher().

◆ signal_connected()

sigc::signal< void > fawkes::ConnectionDispatcher::signal_connected ( )

◆ signal_disconnected()

sigc::signal< void > fawkes::ConnectionDispatcher::signal_disconnected ( )

Get "disconnected" signal.

The "disconnected" signal is emitted when the connection has died, for example because the other peer closed the connection.

Returns
"disconnected" signal

Definition at line 238 of file connection_dispatcher.cpp.

Referenced by Bumblebee2CalibGtkWindow::Bumblebee2CalibGtkWindow(), fawkes::ServiceSelectorCBE::initialize(), NaoGuiGtkWindow::NaoGuiGtkWindow(), fawkes::PluginTreeView::PluginTreeView(), fawkes::ServiceSelectorCBE::signal_disconnected(), SkillGuiGtkWindow::SkillGuiGtkWindow(), fawkes::LogView::~LogView(), and NetLogGuiGtkWindow::~NetLogGuiGtkWindow().

◆ signal_message_received()

sigc::signal< void, FawkesNetworkMessage * > fawkes::ConnectionDispatcher::signal_message_received ( )

Get "message received" signal.

The "message received" signal is emitted whenever a FawkesNetworkMessage has been received.

Returns
"message received" signal

Definition at line 215 of file connection_dispatcher.cpp.

Referenced by fawkes::PluginTreeView::PluginTreeView(), and fawkes::LogView::~LogView().


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