Kanzi Connect  3.9.8
Kanzi Connect C++ API
kanzi::connect::NetworkListenerClient Class Reference

A class that runs network thread and acts as a bridge between the server and clients. More...

#include <network_listener_client.hpp>

Inheritance diagram for kanzi::connect::NetworkListenerClient:
kanzi::connect::ClientConnectionAdapter::Observer

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 &parameter)
 Retrieve parameter of currently used adapter. More...
 
string getAdapterState (const string &parameter)
 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 &parameters, 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ NetworkListenerClient()

kanzi::connect::NetworkListenerClient::NetworkListenerClient ( )
explicit

Constructor.

◆ ~NetworkListenerClient()

virtual kanzi::connect::NetworkListenerClient::~NetworkListenerClient ( )
virtual

Destructor.

Member Function Documentation

◆ addObserver()

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.

Parameters
observerObserver to add.

◆ getAdapterParameter()

string kanzi::connect::NetworkListenerClient::getAdapterParameter ( const string &  parameter)

Retrieve parameter of currently used adapter.

Parameters
parameterParameter to retrieve from adapter.
Returns
State of given parameter.

◆ getAdapterState()

string kanzi::connect::NetworkListenerClient::getAdapterState ( const string &  parameter)

Retrieve state of currently used adapter.

Parameters
parameterParameter to retrieve from adapter.
Returns
State of given parameter.

◆ getAdapterType()

string kanzi::connect::NetworkListenerClient::getAdapterType ( )

Retrieve currently used adapter type.

Returns
Adapter type.

◆ notifyConnected()

void kanzi::connect::NetworkListenerClient::notifyConnected ( )
protected

Notify observers about connection.

◆ notifyDisconnected()

void kanzi::connect::NetworkListenerClient::notifyDisconnected ( )
protected

Notify observers about loss of network connection.

◆ notifyFailedToConnect()

void kanzi::connect::NetworkListenerClient::notifyFailedToConnect ( )
protected

Notify observers about failed connection.

◆ notifyReceive()

void kanzi::connect::NetworkListenerClient::notifyReceive ( )
protected

Notify observers about received data.

◆ receive()

MessageArray kanzi::connect::NetworkListenerClient::receive ( )

Retrieves incoming data packet from server.

Returns
Messages that were received from the server.

◆ registerConnectionAdapterProvider()

void kanzi::connect::NetworkListenerClient::registerConnectionAdapterProvider ( ConnectionAdapterProvider provider)
inline

◆ removeObserver()

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.

Parameters
observerObserver to remove.

◆ run()

void kanzi::connect::NetworkListenerClient::run ( )
protected

Thread function.

◆ start()

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.

Parameters
typeType of the network adapter.
parametersParameters for the network adapter.
clientOptional pointer to Client instance.

◆ stop()

void kanzi::connect::NetworkListenerClient::stop ( )

Stops networking activities and tears down the networking thread.

◆ transmit()

bool kanzi::connect::NetworkListenerClient::transmit ( const MessagePackage message)

Sends a data packet to server.

Parameters
messageMessage to be sent.

◆ wait()

void kanzi::connect::NetworkListenerClient::wait ( int  ms = -1)
protected

Wait for network events to occur.


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