Fawkes API
Fawkes Development Version
|
#include <netcomm/fawkes/client.h>
Public Member Functions | |
FawkesNetworkClient () | |
Constructor. More... | |
FawkesNetworkClient (const char *host, unsigned short int port) | |
Constructor. More... | |
FawkesNetworkClient (unsigned int id, const char *host, unsigned short int port) | |
Constructor. More... | |
~FawkesNetworkClient () | |
Destructor. More... | |
void | connect () |
Connect to remote. More... | |
void | disconnect () |
Disconnect socket. More... | |
void | connect (const char *host, unsigned short int port) |
Connect to new ip and port, and set hostname. More... | |
void | connect (const char *hostname, const struct sockaddr *addr, socklen_t addrlen) |
Connect to specific endpoint. More... | |
void | connect (const char *hostname, const struct sockaddr_storage &addr) |
Connect to specific endpoint. More... | |
void | enqueue (FawkesNetworkMessage *message) |
Enqueue message to send. More... | |
void | enqueue_and_wait (FawkesNetworkMessage *message, unsigned int timeout_sec=15) |
Enqueue message to send and wait for answer. More... | |
void | wait (unsigned int component_id, unsigned int timeout_sec=15) |
Wait for messages for component ID. More... | |
void | wake (unsigned int component_id) |
Wake a waiting thread. More... | |
void | interrupt_connect () |
Interrupt connect(). More... | |
void | register_handler (FawkesNetworkClientHandler *handler, unsigned int component_id) |
Register handler. More... | |
void | deregister_handler (unsigned int component_id) |
Deregister handler. More... | |
bool | connected () const throw () |
Check if connection is alive. More... | |
bool | has_id () const |
Check whether the client has an id. More... | |
unsigned int | id () const |
Get the client's ID. More... | |
const char * | get_hostname () const |
Get the client's hostname. More... | |
Simple Fawkes network client. Allows access to a remote instance via the network. Encapsulates all needed interaction with the network.
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 346 of file client.cpp.
fawkes::FawkesNetworkClient::FawkesNetworkClient | ( | const char * | host, |
unsigned short int | port | ||
) |
Constructor.
host | remote host to connect to. |
port | port to connect to. |
Definition at line 314 of file client.cpp.
fawkes::FawkesNetworkClient::FawkesNetworkClient | ( | unsigned int | id, |
const char * | host, | ||
unsigned short int | port | ||
) |
Constructor.
id | id of the client. |
host | remote host to connect to. |
port | port to connect to. |
Definition at line 379 of file client.cpp.
fawkes::FawkesNetworkClient::~FawkesNetworkClient | ( | ) |
Destructor.
Definition at line 408 of file client.cpp.
void fawkes::FawkesNetworkClient::connect | ( | ) |
Connect to remote.
SocketException | thrown by Socket::connect() |
NullPointerException | thrown if hostname has not been set |
Definition at line 430 of file client.cpp.
References disconnect().
Referenced by fawkes::ServiceSelectorCBE::on_btn_connect_clicked(), fawkes::ServiceSelectorCBE::on_service_selected(), and fawkes::ServiceChooserDialog::run_and_connect().
void fawkes::FawkesNetworkClient::connect | ( | const char * | host, |
unsigned short int | port | ||
) |
Connect to new ip and port, and set hostname.
host | remote host name |
port | new port to connect to |
Definition at line 497 of file client.cpp.
void fawkes::FawkesNetworkClient::connect | ( | const char * | hostname, |
const struct sockaddr * | addr, | ||
socklen_t | addr_len | ||
) |
Connect to specific endpoint.
hostname | hostname, informational only and not used for connecting |
addr | sockaddr structure of specific endpoint to connect to |
addr_len | length of addr |
Definition at line 512 of file client.cpp.
void fawkes::FawkesNetworkClient::connect | ( | const char * | hostname, |
const struct sockaddr_storage & | addr | ||
) |
Connect to specific endpoint.
hostname | hostname, informational only and not used for connecting |
addr | sockaddr_storage structure of specific endpoint to connect to |
Definition at line 530 of file client.cpp.
bool fawkes::FawkesNetworkClient::connected | ( | ) | const | |
throw | ( | |||
) |
Check if connection is alive.
Definition at line 834 of file client.cpp.
Referenced by fawkes::LogView::LogView(), fawkes::NetworkConfiguration::NetworkConfiguration(), fawkes::ServiceSelectorCBE::on_btn_connect_clicked(), fawkes::ServiceSelectorCBE::on_service_selected(), and fawkes::FawkesNetworkClientSendThread::once().
void fawkes::FawkesNetworkClient::deregister_handler | ( | unsigned int | component_id | ) |
Deregister handler.
Cannot be called while processing a message.
component_id | component ID |
Definition at line 682 of file client.cpp.
Referenced by fawkes::NetworkConfiguration::~NetworkConfiguration(), and fawkes::PluginTreeView::~PluginTreeView().
void fawkes::FawkesNetworkClient::disconnect | ( | ) |
Disconnect socket.
Definition at line 545 of file client.cpp.
References fawkes::FawkesNetworkClientSendThread::force_send().
Referenced by connect(), fawkes::ServiceSelectorCBE::on_btn_connect_clicked(), and fawkes::ServiceSelectorCBE::on_service_selected().
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:
Without extra referencing the message may not be used after enqueuing.
message | message to send |
Definition at line 602 of file client.cpp.
References fawkes::FawkesNetworkMessage::cid(), fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
Referenced by fawkes::NetworkConfiguration::set_mirror_mode(), 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.
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 620 of file client.cpp.
Referenced by fawkes::NetworkConfiguration::get_value().
const char * fawkes::FawkesNetworkClient::get_hostname | ( | ) | const |
bool fawkes::FawkesNetworkClient::has_id | ( | ) | const |
Check whether the client has an id.
Definition at line 843 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 582 of file client.cpp.
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.
handler | handler to register |
component_id | component ID to register the handler for. |
Definition at line 664 of file client.cpp.
Referenced by fawkes::NetworkConfiguration::NetworkConfiguration().
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.
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 791 of file client.cpp.
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.
component_id | component ID for threads to wake up |
Definition at line 820 of file client.cpp.