ArnLib  4.0.x
Active Registry Network
ArnDiscoverConnector Class Reference

An automatic client discover connector. More...

#include <ArnDiscoverConnect.hpp>

Inheritance diagram for ArnDiscoverConnector:
Collaboration diagram for ArnDiscoverConnector:

Public Slots

void setService (const QString &service)
 Set the service name for the connection. More...
 

Signals

void clientReadyToConnect (ArnClient *arnClient, const QString &id)
 Signal for external client connection. More...
 

Public Member Functions

 ArnDiscoverConnector (ArnClient &client, const QString &id)
 
 ~ArnDiscoverConnector ()
 
void clearDirectHosts ()
 Clear the direct host connection list. More...
 
void addToDirectHosts (const QString &arnHost, quint16 port=0)
 Add an Arn Server to the direct host connection list. More...
 
void setResolver (ArnDiscoverResolver *resolver)
 Set the ArnDiscoverResolver to be used. More...
 
void start ()
 Start connector. More...
 
QString id () const
 Return the identifier for this connector. More...
 
QString service () const
 Returns the service name for this connection. More...
 
int directHostPrio () const
 Return the priority for direct hosts More...
 
void setDirectHostPrio (int directHostPrio)
 Set the priority for direct hosts More...
 
int discoverHostPrio () const
 Return the priority for discovered hosts More...
 
void setDiscoverHostPrio (int discoverHostPrio)
 Set the priority for discovered hosts More...
 
int resolveRefreshTimeout () const
 Return the resolv refresh period. More...
 
void setResolveRefreshTimeout (int resolveRefreshTimeout)
 Set the resolv refresh period. More...
 
bool externalClientConnect () const
 Return the external client connect mode. More...
 
void setExternalClientConnect (bool externalClientConnect)
 Set the external client connect mode. More...
 

Detailed Description

An automatic client discover connector.

About Arn Discover Remote

This connector class manages client connections. Both as a list of possible direct host addresses and using a service name for reolving into a discover host. The two methods can coexist and as standard the discover host has lowest priority number, i.e. tried first.

An id is assigned to every connector. The id should be chosen to describe the client target or its purpose. It's not a host address or necessarily a specific host, as there can be many possible addresses assigned to the ArnDiscoverConnector.

The id will appear as an Arn folder, e.g. when id is "WeatherData-XYZ" the connector folder path will be "Sys/Discover/Connect/WeatherData-XYZ/".

Example usage

// In class declare
ArnClient _arnClient;
// In class code
_arnClient.addMountPoint("//");
_arnClient.setAutoConnect(true);
_connector = new ArnDiscoverConnector( _arnClient, "MyConnectionId");
_connector->setResolver( new ArnDiscoverResolver());
_connector->setService("My Service");
_connector->addToDirectHosts("localhost");
_connector->start();
Examples:
ArnDemoChat/MainWindow.cpp.

Definition at line 75 of file ArnDiscoverConnect.hpp.

Constructor & Destructor Documentation

◆ ArnDiscoverConnector()

ArnDiscoverConnector::ArnDiscoverConnector ( ArnClient client,
const QString &  id 
)

Definition at line 70 of file ArnDiscoverConnect.cpp.

◆ ~ArnDiscoverConnector()

ArnDiscoverConnector::~ArnDiscoverConnector ( )

Definition at line 93 of file ArnDiscoverConnect.cpp.

Member Function Documentation

◆ addToDirectHosts()

void ArnDiscoverConnector::addToDirectHosts ( const QString &  arnHost,
quint16  port = 0 
)

Add an Arn Server to the direct host connection list.

Parameters
[in]arnHostis host name or ip address, e.g. "192.168.1.1".
[in]portis the host port, 0 gives Arn::defaultTcpPort.
See also
clearDirectHosts()
ArnClient

Definition at line 107 of file ArnDiscoverConnect.cpp.

◆ clearDirectHosts()

void ArnDiscoverConnector::clearDirectHosts ( )

Clear the direct host connection list.

Typically used to start making a new connection list.

See also
addToDirectHosts()
ArnClient

Definition at line 99 of file ArnDiscoverConnect.cpp.

◆ clientReadyToConnect

void ArnDiscoverConnector::clientReadyToConnect ( ArnClient arnClient,
const QString &  id 
)
signal

Signal for external client connection.

When activated external client connection by the method setExternalClientConnect(), this signal will be emitted when the client has been prepared to connect.

It's the responsibility of the receiver to do the actual client connect by ArnClient::connectToArnList().

Parameters
[in]arnClientbeing ready for connection
[in]idis the identifier used in ArnDiscoverRemote::newConnector(), e.g "WeatherData-XYZ"
See also
ArnDiscoverRemote::newConnector()
setExternalClientConnect()

◆ directHostPrio()

int ArnDiscoverConnector::directHostPrio ( ) const

Return the priority for direct hosts

Returns
direct host priority
See also
setDirectHostPrio()

Definition at line 177 of file ArnDiscoverConnect.cpp.

◆ discoverHostPrio()

int ArnDiscoverConnector::discoverHostPrio ( ) const

Return the priority for discovered hosts

Returns
discoverHostPrio is the priority.
See also
setDiscoverHostPrio()

Definition at line 161 of file ArnDiscoverConnect.cpp.

◆ externalClientConnect()

bool ArnDiscoverConnector::externalClientConnect ( ) const

Return the external client connect mode.

Returns
true when active.
See also
setExternalClientConnect()

Definition at line 193 of file ArnDiscoverConnect.cpp.

◆ id()

QString ArnDiscoverConnector::id ( ) const

Return the identifier for this connector.

Returns
the identifier, e.g "WeatherData-XYZ"
See also
ArnDiscoverRemote::newConnector()

Definition at line 137 of file ArnDiscoverConnect.cpp.

◆ resolveRefreshTimeout()

int ArnDiscoverConnector::resolveRefreshTimeout ( ) const

Return the resolv refresh period.

Returns
resolve refresh timeout in seconds.
See also
setResolveRefreshTimeout()

Definition at line 145 of file ArnDiscoverConnect.cpp.

◆ service()

QString ArnDiscoverConnector::service ( ) const

Returns the service name for this connection.

Returns
service name, e.g. "My House Registry"
See also
setService()

Definition at line 209 of file ArnDiscoverConnect.cpp.

◆ setDirectHostPrio()

void ArnDiscoverConnector::setDirectHostPrio ( int  directHostPrio)

Set the priority for direct hosts

This priority controls order between direct hosts and discover host. Low priority number give earlier try for its hosts.

Parameters
[in]directHostPriois the priority.
Note
The priority for direct hosts and discover hosts must be different.
See also
directHostPrio()

Definition at line 185 of file ArnDiscoverConnect.cpp.

◆ setDiscoverHostPrio()

void ArnDiscoverConnector::setDiscoverHostPrio ( int  discoverHostPrio)

Set the priority for discovered hosts

This priority controls order between direct hosts and discover host. Low priority number give earlier try for its hosts.

Parameters
[in]discoverHostPriois the priority.
Note
The priority for direct hosts and discover hosts must be different.
See also
discoverHostPrio()

Definition at line 169 of file ArnDiscoverConnect.cpp.

◆ setExternalClientConnect()

void ArnDiscoverConnector::setExternalClientConnect ( bool  externalClientConnect)

Set the external client connect mode.

This mode is used when there is a need to do special processing when connecting a client. Then QObject::connect() should be used for the signal clientReadyToConnect() and a receiver doing the special processing.

It's the responsibility of the receiver to do the actual client connect by ArnClient::connectToArnList().

Parameters
[in]externalClientConnecttrue to activate.
See also
externalClientConnect()

Definition at line 201 of file ArnDiscoverConnect.cpp.

◆ setResolver()

void ArnDiscoverConnector::setResolver ( ArnDiscoverResolver resolver)

Set the ArnDiscoverResolver to be used.

The resolver handles resolving a known service name into a host name.

Ownership is taken of this resolver. Any previos set resolver will be deleted.

Parameters
[in]resolveris the used ArnDiscoverResolver. Use 0 (null) to set none.
Examples:
ArnDemoChat/MainWindow.cpp.

Definition at line 115 of file ArnDiscoverConnect.cpp.

◆ setResolveRefreshTimeout()

void ArnDiscoverConnector::setResolveRefreshTimeout ( int  resolveRefreshTimeout)

Set the resolv refresh period.

The refresh period is used when there is a failure to connect to a discover host.

The rationale is that the current resolv might be outdated as there is an error when connecting to the resolved host. A refreshed resolv will be done at an intervall of resolveRefreshTimeout until connection to resolved host is successful.

Parameters
[in]resolveRefreshTimeoutis the period in seconds.
See also
resolveRefreshTimeout()

Definition at line 153 of file ArnDiscoverConnect.cpp.

◆ setService

void ArnDiscoverConnector::setService ( const QString &  service)
slot

Set the service name for the connection.

This is only functional if using ArnDiscoverResolver, see setResolver().

Will update connection service name if the resolver has been setup, otherwise the service name is only stored for future use.

For remote control the service name is also available as an Arn Data Object at local path: connector folder path + "Service/value", e.g. "Sys/Discover/Connect/WeatherData-XYZ/Service/value".

Parameters
[in]serviceis the requested connection service name e.g. "My House Registry"
See also
ArnDiscoverAdvertise::setService()
Examples:
ArnDemoChat/MainWindow.cpp.

Definition at line 217 of file ArnDiscoverConnect.cpp.

◆ start()

void ArnDiscoverConnector::start ( )

Start connector.

See also
addToDirectHosts()
setResolver()
Examples:
ArnDemoChat/MainWindow.cpp.

Definition at line 228 of file ArnDiscoverConnect.cpp.


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