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

A class implements basis related to integrating of Kanzi workloop into kanziconnect workloop. More...

#include <workerbase.hpp>

Inheritance diagram for kanzi::connect::WorkerBase:
kanzi::connect::Connection::WorkNotifyCallback kanzi::connect::Worker

Public Member Functions

void configure (Domain &domain, ConnectionConfigurationParser &parser, const ConnectionConfigurationReadIf::Configuration &config, const string &serverName)
 Configure the worker with parsed connection configuration. More...
 
const string getActiveAddress ()
 Retrieve the IP Address of the host that is to be connected next. More...
 
string getFileServerAddress () const
 Retrieve file server address. More...
 
const string & getIdentity ()
 Returns the identity of this client, usually describing the owner of the device (ie. More...
 
const string & getName ()
 Returns the name of this client (ie. More...
 
const string getServerName ()
 Retrieve the IP Address of the host that is to be connected next. More...
 
void start ()
 Starts the worker, connects to server and starts operation. More...
 
void stop ()
 Stops the worker, disconnects from server and stops operation. More...
 
 WorkerBase (ClientSharedPtr client, const string filename)
 Constructor. More...
 
virtual ~WorkerBase ()
 Destructor. More...
 
- Public Member Functions inherited from kanzi::connect::Connection::WorkNotifyCallback
virtual ~WorkNotifyCallback ()
 Virtual destructor for cleanup. More...
 

Protected Types

enum  TaskState { Startup, Connect, Connecting, Running }
 

Protected Member Functions

string buildFilenameFromAttribute (const string attributeName)
 Constructs a filename from a defined attribute. More...
 
bool cacheReferredFile (const string attributeName)
 Check whether specific attribute points to a valid path. More...
 
bool connect ()
 
void disconnect ()
 
string getSSLAttributeValue (const string name)
 Retrieve SSL attribute with specific name. More...
 
bool hasSSLAttribute (const string &name, unordered_map< string, string > &map)
 Checks whether there is SSL attribute with specific name. More...
 
bool hasSSLAttribute (const string &name, map< string, string > &map)
 Checks whether there is SSL attribute with specific name. More...
 
virtual void onConnectionStateChanged (Connection::State state)
 Virtual method - inherited classes must invoke the base class method. More...
 
bool readAndStoreFile (const string filename, const string filenameBase)
 Reads specific file and stores contents into local variable. More...
 
string readReferredFile (const string attributeName)
 Read the referred attribute value. More...
 
void seekToNextAddress ()
 In case multiple addresses configured, advances to the next address after a unsuccessful connect. More...
 
void setPollTimerState (bool running, int interval=0)
 Controls the poll timer state and interval. More...
 
void taskWork (int interval)
 
void workAvailable ()
 Invoked to notify that work is available. More...
 

Protected Attributes

DiagnosticsServiceClient::DiagnosticsSubscriptionToken m_addLinkLatencyMeasureRequestSubscriptionToken
 
vector< string > m_addresses
 List of addresses to try sequentially. More...
 
size_t m_addressIndex
 Index of address to be used next. More...
 
string m_bearer
 
ClientSharedPtr m_client
 Connection to a server. More...
 
ConnectionConfigurationReadIf::Configuration m_config
 
string m_configurationFilename
 The configuration file. More...
 
shared_ptr< ConnectionInterfaceClient > m_connectionInterface
 
ClientConnectionObserverm_connectionObserver
 
shared_ptr< ClientConnectionSession > m_connectionSession
 
Connection::ConnectionStateSubscriptionToken m_connectionSubscription
 
int m_connectionTimeout
 
DiagnosticsServiceClientSharedPtr m_diagnostics
 
Domain * m_domain
 
unordered_map< string, unique_ptr< char[]> > m_fileContents
 Map that caches file contents. More...
 
string m_fileServerAddress
 Remote file server IP address. More...
 
string m_identity
 
MainLoopTimerToken m_mainloopTimerToken
 Handle for timer registration. More...
 
string m_name
 
string m_resourcePath
 
string m_serverName
 
RPCResult< int > m_serverWatchdog
 
RPCTypes::CallbackFunctionSubscriptionToken m_serverWatchdogCallbackToken
 
unordered_map< string, string > m_sslAttributes
 map holding SSL attributes. More...
 
TaskState m_state
 
unsigned int m_watchdogTimeout = 5000
 

Friends

class ClientConnectionObserver
 

Detailed Description

A class implements basis related to integrating of Kanzi workloop into kanziconnect workloop.

Member Enumeration Documentation

◆ TaskState

Enumerator
Startup 
Connect 
Connecting 
Running 

Constructor & Destructor Documentation

◆ WorkerBase()

kanzi::connect::WorkerBase::WorkerBase ( ClientSharedPtr  client,
const string  filename 
)

Constructor.

Parameters
clientKanzi Connect client instance that is managed by this worker.

◆ ~WorkerBase()

virtual kanzi::connect::WorkerBase::~WorkerBase ( )
virtual

Destructor.

Member Function Documentation

◆ buildFilenameFromAttribute()

string kanzi::connect::WorkerBase::buildFilenameFromAttribute ( const string  attributeName)
protected

Constructs a filename from a defined attribute.

Adds optional path information

Parameters
attributeNamethe name of the attribute
Returns
filename with possible path

◆ cacheReferredFile()

bool kanzi::connect::WorkerBase::cacheReferredFile ( const string  attributeName)
protected

Check whether specific attribute points to a valid path.

Parameters
attributeNamename of the attribute where to read the filename of the file to check
Returns
true if referred file exists and is readable

◆ configure()

void kanzi::connect::WorkerBase::configure ( Domain &  domain,
ConnectionConfigurationParser parser,
const ConnectionConfigurationReadIf::Configuration config,
const string &  serverName 
)

Configure the worker with parsed connection configuration.

Parameters
domainThe UI domain
parserconfiguration parser holding all the configurations.
configContains the connection configuration to use

◆ connect()

bool kanzi::connect::WorkerBase::connect ( )
protected
Returns
true if connection establishment started ( does not mean connection estabilished already ).

◆ disconnect()

void kanzi::connect::WorkerBase::disconnect ( )
protected

◆ getActiveAddress()

const string kanzi::connect::WorkerBase::getActiveAddress ( )

Retrieve the IP Address of the host that is to be connected next.

Returns
IP address

◆ getFileServerAddress()

string kanzi::connect::WorkerBase::getFileServerAddress ( ) const

Retrieve file server address.

Returns
the address

◆ getIdentity()

const string& kanzi::connect::WorkerBase::getIdentity ( )
inline

Returns the identity of this client, usually describing the owner of the device (ie.

'John').

Returns
Identity of this client.

◆ getName()

const string& kanzi::connect::WorkerBase::getName ( )
inline

Returns the name of this client (ie.

'Cluster', 'HUD').

Returns
Name of this client.

◆ getServerName()

const string kanzi::connect::WorkerBase::getServerName ( )
inline

Retrieve the IP Address of the host that is to be connected next.

Returns
IP address

◆ getSSLAttributeValue()

string kanzi::connect::WorkerBase::getSSLAttributeValue ( const string  name)
protected

Retrieve SSL attribute with specific name.

Parameters
namethe name of the attribute to retrieve.
Returns
attribute value

◆ hasSSLAttribute() [1/2]

bool kanzi::connect::WorkerBase::hasSSLAttribute ( const string &  name,
unordered_map< string, string > &  map 
)
protected

Checks whether there is SSL attribute with specific name.

Parameters
namethe name of the attribute to check.
mapthe map where to inspect the attribute.
Returns
true attribute value

◆ hasSSLAttribute() [2/2]

bool kanzi::connect::WorkerBase::hasSSLAttribute ( const string &  name,
map< string, string > &  map 
)
protected

Checks whether there is SSL attribute with specific name.

Parameters
namethe name of the attribute to check.
mapthe map where to inspect the attribute.
Returns
true attribute value

◆ onConnectionStateChanged()

virtual void kanzi::connect::WorkerBase::onConnectionStateChanged ( Connection::State  state)
protectedvirtual

Virtual method - inherited classes must invoke the base class method.

Parameters
statenew state.

Reimplemented in kanzi::connect::Worker.

◆ readAndStoreFile()

bool kanzi::connect::WorkerBase::readAndStoreFile ( const string  filename,
const string  filenameBase 
)
protected

Reads specific file and stores contents into local variable.

Parameters
filenamethe filename
filenameBasebase name for file (i.e. without path). this is used as key to cache the file.
Returns
true if file got cached.

◆ readReferredFile()

string kanzi::connect::WorkerBase::readReferredFile ( const string  attributeName)
protected

Read the referred attribute value.

Parameters
attributeNamethe name of the attribute where to read from
Returns
contents of the file.

◆ seekToNextAddress()

void kanzi::connect::WorkerBase::seekToNextAddress ( )
protected

In case multiple addresses configured, advances to the next address after a unsuccessful connect.

◆ setPollTimerState()

void kanzi::connect::WorkerBase::setPollTimerState ( bool  running,
int  interval = 0 
)
protected

Controls the poll timer state and interval.

Parameters
runningif true then ensures timer is running. With false stops the timer.
intervalwhen should the timer to trigger. Value relevant only when starting a timer.

◆ start()

void kanzi::connect::WorkerBase::start ( )

Starts the worker, connects to server and starts operation.

◆ stop()

void kanzi::connect::WorkerBase::stop ( )

Stops the worker, disconnects from server and stops operation.

◆ taskWork()

void kanzi::connect::WorkerBase::taskWork ( int  interval)
protected

◆ workAvailable()

void kanzi::connect::WorkerBase::workAvailable ( )
protectedvirtual

Invoked to notify that work is available.

Generally invoked in context other than the application "main thread".

Implements kanzi::connect::Connection::WorkNotifyCallback.

Friends And Related Function Documentation

◆ ClientConnectionObserver

friend class ClientConnectionObserver
friend

Member Data Documentation

◆ m_addLinkLatencyMeasureRequestSubscriptionToken

DiagnosticsServiceClient::DiagnosticsSubscriptionToken kanzi::connect::WorkerBase::m_addLinkLatencyMeasureRequestSubscriptionToken
protected

◆ m_addresses

vector<string> kanzi::connect::WorkerBase::m_addresses
protected

List of addresses to try sequentially.

◆ m_addressIndex

size_t kanzi::connect::WorkerBase::m_addressIndex
protected

Index of address to be used next.

◆ m_bearer

string kanzi::connect::WorkerBase::m_bearer
protected

◆ m_client

ClientSharedPtr kanzi::connect::WorkerBase::m_client
protected

Connection to a server.

◆ m_config

ConnectionConfigurationReadIf::Configuration kanzi::connect::WorkerBase::m_config
protected

◆ m_configurationFilename

string kanzi::connect::WorkerBase::m_configurationFilename
protected

The configuration file.

◆ m_connectionInterface

shared_ptr<ConnectionInterfaceClient> kanzi::connect::WorkerBase::m_connectionInterface
protected

◆ m_connectionObserver

ClientConnectionObserver* kanzi::connect::WorkerBase::m_connectionObserver
protected

◆ m_connectionSession

shared_ptr<ClientConnectionSession> kanzi::connect::WorkerBase::m_connectionSession
protected

◆ m_connectionSubscription

Connection::ConnectionStateSubscriptionToken kanzi::connect::WorkerBase::m_connectionSubscription
protected

◆ m_connectionTimeout

int kanzi::connect::WorkerBase::m_connectionTimeout
protected

◆ m_diagnostics

DiagnosticsServiceClientSharedPtr kanzi::connect::WorkerBase::m_diagnostics
protected

◆ m_domain

Domain* kanzi::connect::WorkerBase::m_domain
protected

◆ m_fileContents

unordered_map<string, unique_ptr<char[]> > kanzi::connect::WorkerBase::m_fileContents
protected

Map that caches file contents.

◆ m_fileServerAddress

string kanzi::connect::WorkerBase::m_fileServerAddress
protected

Remote file server IP address.

◆ m_identity

string kanzi::connect::WorkerBase::m_identity
protected

◆ m_mainloopTimerToken

MainLoopTimerToken kanzi::connect::WorkerBase::m_mainloopTimerToken
protected

Handle for timer registration.

◆ m_name

string kanzi::connect::WorkerBase::m_name
protected

◆ m_resourcePath

string kanzi::connect::WorkerBase::m_resourcePath
protected

◆ m_serverName

string kanzi::connect::WorkerBase::m_serverName
protected

◆ m_serverWatchdog

RPCResult<int> kanzi::connect::WorkerBase::m_serverWatchdog
protected

◆ m_serverWatchdogCallbackToken

RPCTypes::CallbackFunctionSubscriptionToken kanzi::connect::WorkerBase::m_serverWatchdogCallbackToken
protected

◆ m_sslAttributes

unordered_map<string, string> kanzi::connect::WorkerBase::m_sslAttributes
protected

map holding SSL attributes.

◆ m_state

TaskState kanzi::connect::WorkerBase::m_state
protected

◆ m_watchdogTimeout

unsigned int kanzi::connect::WorkerBase::m_watchdogTimeout = 5000
protected

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