AbstractSession

class kanzi::connect::AbstractSession : public enable_shared_from_this<AbstractSession>

A class that is used to deliver interface network messages between client and server.

In order to use a service, client needs always first to establish a session to interface.

Subclassed by ClientStreamSession, ExternalClientSession, ExternalServiceSession

Public Types

typedef function<bool(const MessagePackage &message)> MessageReceivedFunction

Message subscription callback.

Returns

True if message was handled and framework does not need to process it further.

typedef shared_ptr<void> MessageSubscriptionToken

Public Functions

AbstractSession(const string &interfaceId, int clientId, int sessionId, MessageDispatcher *dispatcher)

Constructor.

Parameters
  • interfaceId – Id of the interface.

  • clientId – Id of the client.

  • sessionId – Id of the session.

  • dispatcher – Message dispatcher that can be used to deliver network messages.

virtual ~AbstractSession()

Destructor.

MessageSubscriptionToken addMessageSubscription(const string &messageType, MessageReceivedFunction function)

Subscribe all messages of type.

Parameters
  • messageType – Type of the messages to subscribe callbacks.

  • function – Callback to pass the subscribed messages.

Returns

Subscription token which is needed to unsubscribe callbacks.

void changeMessageDispatcher(MessageDispatcher *dispatcher)

Changes message dispatcher on the fly.

Parameters

dispatcher – the new dispatcher to take into use.

void enableVerboseLogging(bool enable)

Enables verbose logging for the functionality.

Parameters

enable – true to enable. defaults to false.

ClientDescriptorSharedPtr getClientDescriptor() const

Retrieve client descriptor.

Returns

client descriptor

int getClientId() const

Retrieve client id of the session.

Returns

Network id of the client.

int getId() const

Retrieve id of the session.

Returns

Id of the session, unique for this client.

const string &getInterfaceId() const

Retrieve id of the interface.

Returns

Id of the connected interface.

int getServerClientId() const

Retrieve server client identifier of the session.

Returns

the server identifier for this client inside the server.

virtual void initialize()

Initializes this session.

void receive(const MessagePackage &message)

Asks session to process received message.

Parameters

message – Message that was received.

void removeMessageSubscription(const string &messageType, MessageSubscriptionToken token)

Remove message subscription.

Parameters
  • messageType – Type of the messages to unsubscribe callbacks.

  • token – Subscription token.

void setClientDescriptor(ClientDescriptorSharedPtr clientDescriptor)

Saves a client descriptor of the client who created this session.

Parameters

clientDescriptor

void setClientP2PRoutingInstructions(shared_ptr<p2p::P2PClient::RoutingHandler> routingHandler)

Configure P2P routing instructions for the client.

Parameters

routingHandler – the instructions to apply.

void setGenericInvoker(GenericInvoker *invoker)

Setups generic invocation mechanism.

Parameters

invoker – generic invocation mechanism.

void setServerClientId(int id)

Sets servers identifier of the client this session belongs to.

Parameters

id – the identifier.

void setServerP2PRouter(p2p::P2PServerSharedPtr serverRouter)

Configure P2P routing for server scope.

Parameters

serverRouter – routing functionality for server.

void terminate()

Terminates the session.

bool transmit(const MessagePackage &message)

Sends outgoing message to network.

Parameters

message – Message to send.

bool transmit(MessagePackageSharedPtr message, uint32_t call_handle = 0)

Sends outgoing message to network.

Parameters

message – Message to send.

virtual void uninitialize()

Un-initializes this session.

void updateEnabledState(bool newEnabledState)

Update the enabled state of this session.

Parameters

newEnabledState – The new status.