Public Member Functions | Protected Member Functions

fawkes::ConnectionDispatcher Class Reference

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

#include <>>

Inheritance diagram for fawkes::ConnectionDispatcher:
Inheritance graph
[legend]

List of all members.

Public Member Functions

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

Protected Member Functions

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

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

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

Constructor.

Parameters:
cid component 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().

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

Constructor.

Parameters:
cid component ID to register this dispatcher for. This is relevant if you want to use the message received signal!
hostname hostname to connect to
port port to connect to

Definition at line 58 of file connection_dispatcher.cpp.

References fawkes::FawkesNetworkClient::register_handler().

fawkes::ConnectionDispatcher::~ConnectionDispatcher (  )  [virtual]

Destructor.

Definition at line 71 of file connection_dispatcher.cpp.

References set_client().


Member Function Documentation

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:
id the id of the calling client

Implements fawkes::FawkesNetworkClientHandler.

Definition at line 196 of file connection_dispatcher.cpp.

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:
id the id of the calling client

Implements fawkes::FawkesNetworkClientHandler.

Definition at line 203 of file connection_dispatcher.cpp.

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:
id the id of the calling client

Implements fawkes::FawkesNetworkClientHandler.

Definition at line 180 of file connection_dispatcher.cpp.

FawkesNetworkClient * fawkes::ConnectionDispatcher::get_client (  ) 
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:
m Message to handle
id the id of the calling client

Implements fawkes::FawkesNetworkClientHandler.

Definition at line 187 of file connection_dispatcher.cpp.

void fawkes::ConnectionDispatcher::on_connection_died (  )  [protected, virtual]

Internal event handler.

Called by dispatcher to emit signal.

Definition at line 156 of file connection_dispatcher.cpp.

void fawkes::ConnectionDispatcher::on_connection_established (  )  [protected, virtual]

Internal event handler.

Called by dispatcher to emit signal.

Definition at line 146 of file connection_dispatcher.cpp.

void fawkes::ConnectionDispatcher::on_message_received (  )  [protected, virtual]

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().

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().

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:
cid component ID

Definition at line 93 of file connection_dispatcher.cpp.

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

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:
client Fawkes 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().

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

Get "connected" signal.

The "connected" signal is emitted when the connection has been established.

Returns:
"connected" signal

Definition at line 226 of file connection_dispatcher.cpp.

Referenced by fawkes::ServiceSelectorCBE::initialize(), fawkes::ServiceSelectorCBE::signal_connected(), and SkillGuiGtkWindow::SkillGuiGtkWindow().

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 fawkes::ServiceSelectorCBE::initialize(), fawkes::ServiceSelectorCBE::signal_disconnected(), and SkillGuiGtkWindow::SkillGuiGtkWindow().

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.


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