fawkes::FawkesNetworkClient Class Reference
[Fawkes Network Communication]
Simple Fawkes network client.
More...
#include <netcomm/fawkes/client.h>
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.
Definition at line 51 of file client.h.
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 323 of file client.cpp.
| fawkes::FawkesNetworkClient::FawkesNetworkClient | ( | const char * | hostname, | |
| unsigned short int | port, | |||
| const char * | ip = NULL | |||
| ) |
Constructor.
- Parameters:
-
hostname remote host to connect to. port port to connect to. ip optional: use ip to connect, and hostname for cosmetic purposes
Definition at line 291 of file client.cpp.
| fawkes::FawkesNetworkClient::FawkesNetworkClient | ( | unsigned int | id, | |
| const char * | hostname, | |||
| unsigned short int | port, | |||
| const char * | ip = NULL | |||
| ) |
Constructor.
- Parameters:
-
id id of the client. hostname remote host to connect to. port port to connect to. ip optional: use ip to connect, and hostname for cosmetic purposes
Definition at line 357 of file client.cpp.
| fawkes::FawkesNetworkClient::~FawkesNetworkClient | ( | ) |
Member Function Documentation
| void fawkes::FawkesNetworkClient::connect | ( | const char * | hostname, | |
| const char * | ip, | |||
| unsigned short int | port | |||
| ) |
Connect to new ip and port, and set hostname.
- Parameters:
-
hostname remote host name ip new ip to connect to port new port to connect to
- See also:
- connect() Look there for more documentation and notes about possible exceptions.
Definition at line 484 of file client.cpp.
References connect().
| void fawkes::FawkesNetworkClient::connect | ( | const char * | hostname, | |
| unsigned short int | port | |||
| ) |
Connect to new host and port.
- Parameters:
-
hostname new hostname to connect to port new port to connect to
- See also:
- connect() Look there for more documentation and notes about possible exceptions.
Definition at line 471 of file client.cpp.
References connect().
| void fawkes::FawkesNetworkClient::connect | ( | ) |
Connect to remote.
- Exceptions:
-
SocketException thrown by Socket::connect() NullPointerException thrown if hostname has not been set
Definition at line 408 of file client.cpp.
References fawkes::Thread::cancel(), fawkes::Socket::connect(), disconnect(), fawkes::Thread::join(), fawkes::Mutex::lock(), fawkes::Thread::start(), fawkes::Mutex::unlock(), and fawkes::WaitCondition::wait().
Referenced by connect(), SkillShellThread::loop(), fawkes::ServiceSelectorCBE::on_btn_connect_clicked(), fawkes::ServiceSelectorCBE::on_service_selected(), fawkes::RemoteBlackBoard::RemoteBlackBoard(), fawkes::ServiceChooserDialog::run_and_connect(), SkillShellThread::SkillShellThread(), and fawkes::RemoteBlackBoard::try_aliveness_restore().
| bool fawkes::FawkesNetworkClient::connected | ( | ) | const throw () |
Check if connection is alive.
- Returns:
- true if connection is alive at the moment, false otherwise
Definition at line 783 of file client.cpp.
Referenced by fawkes::RemoteBlackBoard::close(), fawkes::RemoteBlackBoard::is_alive(), SkillShellThread::loop(), fawkes::FawkesNetworkClientSendThread::loop(), fawkes::NetworkConfiguration::NetworkConfiguration(), fawkes::ServiceSelectorCBE::on_btn_connect_clicked(), LaserGuiHildonWindow::on_connection_clicked(), LaserGuiGtkWindow::on_connection_clicked(), fawkes::ServiceSelectorCBE::on_service_selected(), fawkes::ConnectionDispatcher::operator bool(), fawkes::RemoteBlackBoard::RemoteBlackBoard(), fawkes::ServiceChooserDialog::run_and_connect(), fawkes::LogView::set_client(), fawkes::RemoteBlackBoard::try_aliveness_restore(), and fawkes::LogView::~LogView().
| void fawkes::FawkesNetworkClient::deregister_handler | ( | unsigned int | component_id | ) |
Deregister handler.
Cannot be called while processing a message.
- Parameters:
-
component_id component ID
Definition at line 625 of file client.cpp.
References fawkes::Mutex::lock(), fawkes::LockMap< KeyType, ValueType, LessKey >::lock(), fawkes::Mutex::unlock(), fawkes::LockMap< KeyType, ValueType, LessKey >::unlock(), and fawkes::WaitCondition::wake_all().
Referenced by PluginTool::run(), fawkes::ConnectionDispatcher::set_cid(), fawkes::ConnectionDispatcher::set_client(), fawkes::NetworkConfiguration::~NetworkConfiguration(), fawkes::PluginTreeView::~PluginTreeView(), fawkes::RemoteBlackBoard::~RemoteBlackBoard(), and SkillShellThread::~SkillShellThread().
| void fawkes::FawkesNetworkClient::disconnect | ( | ) |
Disconnect socket.
Definition at line 496 of file client.cpp.
References fawkes::Thread::cancel(), fawkes::FawkesNetworkClientSendThread::force_send(), and fawkes::Thread::join().
Referenced by connect(), SkillShellThread::loop(), fawkes::ServiceSelectorCBE::on_btn_connect_clicked(), LaserGuiHildonWindow::on_connection_clicked(), LaserGuiGtkWindow::on_connection_clicked(), fawkes::ServiceSelectorCBE::on_service_selected(), ~FawkesNetworkClient(), fawkes::RemoteBlackBoard::~RemoteBlackBoard(), and SkillShellThread::~SkillShellThread().
| void fawkes::FawkesNetworkClient::enqueue | ( | FawkesNetworkMessage * | message | ) |
Enqueue message to send.
- Parameters:
-
message message to send
Definition at line 546 of file client.cpp.
References fawkes::FawkesNetworkClientSendThread::enqueue().
Referenced by fawkes::RemoteBlackBoard::close(), fawkes::RemoteBlackBoard::list_all(), fawkes::BlackBoardInterfaceProxy::notify_of_data_change(), fawkes::LogView::set_client(), fawkes::NetworkConfiguration::set_mirror_mode(), fawkes::BlackBoardInterfaceProxy::transmit(), fawkes::LogView::~LogView(), 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:
-
message message to send timeout_sec timeout for the waiting operation in seconds, 0 to wait forever (warning, this may result in a deadlock!)
Definition at line 564 of file client.cpp.
References fawkes::FawkesNetworkMessage::cid(), fawkes::FawkesNetworkClientSendThread::enqueue(), fawkes::Mutex::lock(), fawkes::FawkesNetworkMessage::msgid(), fawkes::WaitCondition::reltimed_wait(), fawkes::Mutex::unlock(), and fawkes::RefCount::unref().
Referenced by fawkes::NetworkConfiguration::get_value().
| const char * fawkes::FawkesNetworkClient::get_hostname | ( | ) | const |
| const char * fawkes::FawkesNetworkClient::get_ip | ( | ) | const |
| bool fawkes::FawkesNetworkClient::has_id | ( | ) | const |
Check whether the client has an id.
- Returns:
- true if client has an ID
Definition at line 793 of file client.cpp.
| unsigned int fawkes::FawkesNetworkClient::id | ( | ) | const |
| 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 533 of file client.cpp.
References fawkes::Mutex::lock(), fawkes::Mutex::unlock(), and fawkes::WaitCondition::wake_all().
| 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:
-
handler handler to register component_id component ID to register the handler for.
Definition at line 606 of file client.cpp.
References fawkes::LockMap< KeyType, ValueType, LessKey >::lock(), and fawkes::LockMap< KeyType, ValueType, LessKey >::unlock().
Referenced by fawkes::ConnectionDispatcher::ConnectionDispatcher(), fawkes::NetworkConfiguration::NetworkConfiguration(), fawkes::RemoteBlackBoard::RemoteBlackBoard(), PluginTool::run(), fawkes::ConnectionDispatcher::set_cid(), fawkes::ConnectionDispatcher::set_client(), and SkillShellThread::SkillShellThread().
| 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_id component ID to monitor timeout_sec timeout for the waiting operation in seconds, 0 to wait forever (warning, this may result in a deadlock!)
Definition at line 740 of file client.cpp.
References fawkes::Mutex::lock(), fawkes::WaitCondition::reltimed_wait(), and fawkes::Mutex::unlock().
Referenced by ConfigChangeWatcherTool::run().
| 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_id component ID for threads to wake up
Definition at line 768 of file client.cpp.
References fawkes::Mutex::lock(), fawkes::Mutex::unlock(), and fawkes::WaitCondition::wake_all().
Referenced by PluginTool::handle_signal().
The documentation for this class was generated from the following files:
- src/libs/netcomm/fawkes/client.h
- src/libs/netcomm/fawkes/client.cpp

