A class that runs network thread and acts as a bridge between the server and clients. More...
#include <network_listener_client.hpp>
Classes | |
class | Observer |
Observer for network state changes. More... | |
Public Member Functions | |
void | addObserver (Observer *observer) |
Add observer to listen for network events. More... | |
string | getAdapterParameter (const string ¶meter) |
Retrieve parameter of currently used adapter. More... | |
string | getAdapterState (const string ¶meter) |
Retrieve state of currently used adapter. More... | |
string | getAdapterType () |
Retrieve currently used adapter type. More... | |
NetworkListenerClient () | |
Constructor. More... | |
MessageArray | receive () |
Retrieves incoming data packet from server. More... | |
void | registerConnectionAdapterProvider (ConnectionAdapterProvider *provider) |
void | removeObserver (Observer *observer) |
Remove observer. More... | |
void | start (const string &type, const ClientConnectionAdapter::Parameters ¶meters, Client *client=nullptr) |
Starts connecting to server using given network adapter and parameters. More... | |
void | stop () |
Stops networking activities and tears down the networking thread. More... | |
bool | transmit (const MessagePackage &message) |
Sends a data packet to server. More... | |
virtual | ~NetworkListenerClient () |
Destructor. More... | |
Protected Member Functions | |
void | notifyConnected () |
Notify observers about connection. More... | |
void | notifyDisconnected () |
Notify observers about loss of network connection. More... | |
void | notifyFailedToConnect () |
Notify observers about failed connection. More... | |
void | notifyReceive () |
Notify observers about received data. More... | |
void | run () |
Thread function. More... | |
void | wait (int ms=-1) |
Wait for network events to occur. More... | |
A class that runs network thread and acts as a bridge between the server and clients.
This class initializes connection adapter according to given parameters and starts a network thread. It is responsible of transmitting & receiving data through message translators and maintains connection to the server.
|
explicit |
Constructor.
|
virtual |
Destructor.
void kanzi::connect::NetworkListenerClient::addObserver | ( | Observer * | observer | ) |
Add observer to listen for network events.
This method must not be called from any of the observer callback methods or a deadlock will occur.
observer | Observer to add. |
string kanzi::connect::NetworkListenerClient::getAdapterParameter | ( | const string & | parameter | ) |
Retrieve parameter of currently used adapter.
parameter | Parameter to retrieve from adapter. |
string kanzi::connect::NetworkListenerClient::getAdapterState | ( | const string & | parameter | ) |
Retrieve state of currently used adapter.
parameter | Parameter to retrieve from adapter. |
string kanzi::connect::NetworkListenerClient::getAdapterType | ( | ) |
Retrieve currently used adapter type.
|
protected |
Notify observers about connection.
|
protected |
Notify observers about loss of network connection.
|
protected |
Notify observers about failed connection.
|
protected |
Notify observers about received data.
MessageArray kanzi::connect::NetworkListenerClient::receive | ( | ) |
Retrieves incoming data packet from server.
|
inline |
void kanzi::connect::NetworkListenerClient::removeObserver | ( | Observer * | observer | ) |
Remove observer.
This method must not be called from any of the observer callback methods or a deadlock will occur.
observer | Observer to remove. |
|
protected |
Thread function.
void kanzi::connect::NetworkListenerClient::start | ( | const string & | type, |
const ClientConnectionAdapter::Parameters & | parameters, | ||
Client * | client = nullptr |
||
) |
Starts connecting to server using given network adapter and parameters.
type | Type of the network adapter. |
parameters | Parameters for the network adapter. |
client | Optional pointer to Client instance. |
void kanzi::connect::NetworkListenerClient::stop | ( | ) |
Stops networking activities and tears down the networking thread.
bool kanzi::connect::NetworkListenerClient::transmit | ( | const MessagePackage & | message | ) |
Sends a data packet to server.
message | Message to be sent. |
|
protected |
Wait for network events to occur.