p2p::P2PClient::NetworkListenerRegistrationΒΆ

class kanzi::connect::p2p::P2PClient::NetworkListenerRegistration : public NetworkListenerClient::Observer, public MessageDispatcher

Class to facade a network listener client and message dispatching.

Public Types

enum State

Values:

enumerator StateDisconnected

Disconnected.

enumerator StateConnecting

Connecting started but not yet established.

enumerator StateConnected

Connected.

enumerator StateWaitingReconnect

After unsuccesfull connect a wait state after which next reconnect attempt is made.

Public Functions

NetworkListenerRegistration(NetworkListenerClientSharedPtr networkListener, ClientSharedPtr client, int serverclientid, bool verboseLogging)

Constructor.

Parameters
  • networkListener: The listener that this registration represents.

  • client: Client instance. Ownerhip is not transfered.

  • serverclientid: The identifier number that this client has on a server.

  • verboseLogging: When set to true, the information is printed in verbose manner.

~NetworkListenerRegistration()

Destructor.

inline void addStateChangeCallback(ConnectionStateChangedFunctionType callback)

Insert callback to listen to registration changes.

Parameters
  • callback: The method to invoke for changes. You can set only one callback.

bool canHandleEndpoint(shared_ptr<p2p::RoutingRules::Endpoint> endpoint)

Checks whether this paritucular network listener can handle the particular endpoint.

Return

true if this listener can handle provided endpoint

Parameters
  • endpoint: the endpoint to check.

size_t countEndpoints() const

Return amount of endpoints the class has.

Return

amount of endpoints

inline void enableVerboseLogging(bool enable)

Controls logging verbosity.

Parameters
  • enable: true to enable verbose logging from the class.

void insertEndpoint(shared_ptr<p2p::RoutingRules::Endpoint> endpoint)

Inserts a new endpoint.

Parameters
  • endpoint: the endpoint to insert

inline bool isConnected() const

Connection state retrieval.

Return

true if connected currently.

inline bool isDisconnected() const

Connection state retrieval.

Return

true if disconnected currently.

virtual void onConnected () KZ_OVERRIDE

Listener thread has established connection to server.

virtual void onDisconnected () KZ_OVERRIDE

Listener thread has terminated connection from server.

virtual void onFailedToConnect () KZ_OVERRIDE

Listener thread failed to connect.

virtual void onReceive () KZ_OVERRIDE

Listener thread received data.

bool refersToEndpoint(shared_ptr<p2p::RoutingRules::Endpoint> endpoint) const

Checks whether this registration refers to a specified endpoint.

Return

true if refers to endpoint.

Parameters
  • endpoint: the endpoint to check

bool removeEndpoint(shared_ptr<p2p::RoutingRules::Endpoint> endpoint)

Removes a endpoint.

Return

true if endpoint was referenced and got removed.

Parameters
  • endpoint: the endpoint to remove.

bool startConnect()

Starts connection establishment.

Return

true if successfully started.

void stop()

Stops the operation including the worker thread.

string toString()

Get stringular representation of the network connection.

mainly for debugging purposes

Return

stringular representation of the network connection.

bool unreliableLink()

Describe the link type whether it is reliable or unreliable.

By default, all the links are assumed to be reliable unless otherwise explicitly stated by the network adapter

Return

true if link is considered unreliable.

void work()

To be invoked to process incoming messages from the network listener.