Fawkes API  Fawkes Development Version
fawkes::FawkesNetworkClient Class Reference

Simple Fawkes network client. More...

#include <netcomm/fawkes/client.h>

List of all members.

Public Member Functions

 FawkesNetworkClient ()
 Constructor.
 FawkesNetworkClient (const char *hostname, unsigned short int port, const char *ip=NULL)
 Constructor.
 FawkesNetworkClient (unsigned int id, const char *hostname, unsigned short int port, const char *ip=NULL)
 Constructor.
 ~FawkesNetworkClient ()
 Destructor.
void connect ()
 Connect to remote.
void disconnect ()
 Disconnect socket.
void connect (const char *hostname, unsigned short int port)
 Connect to new host and port.
void connect (const char *hostname, const char *ip, unsigned short int port)
 Connect to new ip and port, and set hostname.
void enqueue (FawkesNetworkMessage *message)
 Enqueue message to send.
void enqueue_and_wait (FawkesNetworkMessage *message, unsigned int timeout_sec=15)
 Enqueue message to send and wait for answer.
void wait (unsigned int component_id, unsigned int timeout_sec=15)
 Wait for messages for component ID.
void wake (unsigned int component_id)
 Wake a waiting thread.
void interrupt_connect ()
 Interrupt connect().
void register_handler (FawkesNetworkClientHandler *handler, unsigned int component_id)
 Register handler.
void deregister_handler (unsigned int component_id)
 Deregister handler.
bool connected () const throw ()
 Check if connection is alive.
bool has_id () const
 Check whether the client has an id.
unsigned int id () const
 Get the client's ID.
const char * get_hostname () const
 Get the client's hostname.
const char * get_ip () const
 Get the client's ip.

Friends

class FawkesNetworkClientSendThread
class FawkesNetworkClientRecvThread

Detailed Description

Simple Fawkes network client.

Allows access to a remote instance via the network. Encapsulates all needed interaction with the network.

Author:
Tim Niemueller

Constructor & Destructor Documentation

fawkes::FawkesNetworkClient::FawkesNetworkClient ( )

Constructor.

Note, you cannot call the connect() without parameters the first time you establish an connection when using this ctor!

Definition at line 330 of file client.cpp.

fawkes::FawkesNetworkClient::FawkesNetworkClient ( const char *  hostname,
unsigned short int  port,
const char *  ip = NULL 
)

Constructor.

Parameters:
hostnameremote host to connect to.
portport to connect to.
ipoptional: use ip to connect, and hostname for cosmetic purposes

Definition at line 298 of file client.cpp.

fawkes::FawkesNetworkClient::FawkesNetworkClient ( unsigned int  id,
const char *  hostname,
unsigned short int  port,
const char *  ip = NULL 
)

Constructor.

Parameters:
idid of the client.
hostnameremote host to connect to.
portport to connect to.
ipoptional: use ip to connect, and hostname for cosmetic purposes

Definition at line 364 of file client.cpp.

References id().

fawkes::FawkesNetworkClient::~FawkesNetworkClient ( )

Destructor.

Definition at line 394 of file client.cpp.

References disconnect().


Member Function Documentation

void fawkes::FawkesNetworkClient::connect ( const char *  hostname,
unsigned short int  port 
)

Connect to new host and port.

Parameters:
hostnamenew hostname to connect to
portnew port to connect to
See also:
connect() Look there for more documentation and notes about possible exceptions.

Definition at line 478 of file client.cpp.

References connect().

void fawkes::FawkesNetworkClient::connect ( const char *  hostname,
const char *  ip,
unsigned short int  port 
)

Connect to new ip and port, and set hostname.

Parameters:
hostnameremote host name
ipnew ip to connect to
portnew port to connect to
See also:
connect() Look there for more documentation and notes about possible exceptions.

Definition at line 491 of file client.cpp.

References connect().

void fawkes::FawkesNetworkClient::deregister_handler ( unsigned int  component_id)
void fawkes::FawkesNetworkClient::enqueue ( FawkesNetworkMessage message)

Enqueue message to send.

This method takes ownership of the message. If you want to use the message after enqueing you must reference:

 message->ref();
 fawkes_network_client->enqueue(message);
 // message can now still be used

Without extra referencing the message may not be used after enqueuing.

Parameters:
messagemessage to send

Definition at line 561 of file client.cpp.

References fawkes::FawkesNetworkClientSendThread::enqueue().

Referenced by fawkes::BlackBoardInterfaceProxy::notify_of_data_change(), fawkes::BlackBoardInterfaceProxy::transmit(), fawkes::RemoteBlackBoard::close(), fawkes::RemoteBlackBoard::list_all(), fawkes::RemoteBlackBoard::list(), fawkes::NetworkConfiguration::set_mirror_mode(), fawkes::LogView::~LogView(), fawkes::LogView::set_client(), and fawkes::PluginTreeView::~PluginTreeView().

void fawkes::FawkesNetworkClient::enqueue_and_wait ( FawkesNetworkMessage message,
unsigned int  timeout_sec = 15 
)

Enqueue message to send and wait for answer.

It is guaranteed that an answer cannot be missed. However, if the component sends another message (which is not the answer to the query) this will also trigger the wait condition to be woken up. The component ID to wait for is taken from the message. This message also calls unref() on the message. If you want to use it after enqueuing make sure you ref() before calling this method.

Parameters:
messagemessage to send
timeout_sectimeout for the waiting operation in seconds, 0 to wait forever (warning, this may result in a deadlock!)

Definition at line 579 of file client.cpp.

References fawkes::Mutex::lock(), fawkes::FawkesNetworkMessage::cid(), fawkes::Mutex::unlock(), fawkes::FawkesNetworkClientSendThread::enqueue(), fawkes::WaitCondition::reltimed_wait(), and fawkes::FawkesNetworkMessage::msgid().

Referenced by fawkes::NetworkConfiguration::get_value().

const char * fawkes::FawkesNetworkClient::get_hostname ( ) const

Get the client's hostname.

Returns:
hostname or NULL

Definition at line 830 of file client.cpp.

const char * fawkes::FawkesNetworkClient::get_ip ( ) const

Get the client's ip.

Returns:
ip or NULL

Definition at line 839 of file client.cpp.

bool fawkes::FawkesNetworkClient::has_id ( ) const

Check whether the client has an id.

Returns:
true if client has an ID

Definition at line 807 of file client.cpp.

unsigned int fawkes::FawkesNetworkClient::id ( ) const

Get the client's ID.

Returns:
the ID

Definition at line 817 of file client.cpp.

Referenced by FawkesNetworkClient().

void fawkes::FawkesNetworkClient::interrupt_connect ( )

Interrupt connect().

This is for example handy to interrupt in connection_died() before a connection_established() event has been received.

Definition at line 540 of file client.cpp.

References fawkes::Mutex::lock(), fawkes::WaitCondition::wake_all(), and fawkes::Mutex::unlock().

void fawkes::FawkesNetworkClient::register_handler ( FawkesNetworkClientHandler handler,
unsigned int  component_id 
)

Register handler.

Handlers are used to handle incoming packets. There may only be one handler per component! Cannot be called while processing a message.

Parameters:
handlerhandler to register
component_idcomponent ID to register the handler for.

Definition at line 620 of file client.cpp.

References fawkes::LockMap::lock(), and fawkes::LockMap::unlock().

Referenced by fawkes::RemoteBlackBoard::RemoteBlackBoard(), fawkes::NetworkConfiguration::NetworkConfiguration(), fawkes::ConnectionDispatcher::ConnectionDispatcher(), fawkes::ConnectionDispatcher::set_cid(), and fawkes::ConnectionDispatcher::set_client().

void fawkes::FawkesNetworkClient::wait ( unsigned int  component_id,
unsigned int  timeout_sec = 15 
)

Wait for messages for component ID.

This will wait for messages of the given component ID to arrive. The calling thread is blocked until messages are available.

Parameters:
component_idcomponent ID to monitor
timeout_sectimeout for the waiting operation in seconds, 0 to wait forever (warning, this may result in a deadlock!)

Definition at line 754 of file client.cpp.

References fawkes::Mutex::lock(), fawkes::Mutex::unlock(), and fawkes::WaitCondition::reltimed_wait().

void fawkes::FawkesNetworkClient::wake ( unsigned int  component_id)

Wake a waiting thread.

This will wakeup all threads currently waiting for the specified component ID. This can be helpful to wake a sleeping thread if you received a signal.

Parameters:
component_idcomponent ID for threads to wake up

Definition at line 782 of file client.cpp.

References fawkes::Mutex::lock(), fawkes::WaitCondition::wake_all(), and fawkes::Mutex::unlock().


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