ArnLib  4.0.x
Active Registry Network
ArnDiscoverRemote Class Reference

Discover with remote setting. More...

#include <ArnDiscoverRemote.hpp>

Inheritance diagram for ArnDiscoverRemote:
Collaboration diagram for ArnDiscoverRemote:

Public Slots

virtual void setService (const QString &service)
 Set the service name. More...
 
- Public Slots inherited from ArnDiscoverAdvertise
virtual void setService (const QString &service)
 Set the service name. More...
 

Signals

void clientReadyToConnect (ArnClient *arnClient, const QString &id)
 Central signal for external client connection. More...
 
- Signals inherited from ArnDiscoverAdvertise
void serviceChanged (const QString &serviceName)
 Indicate successfull advertise of service. More...
 
void serviceChangeError (int code)
 Indicate unsuccessfull advertise of service. More...
 

Public Member Functions

 ArnDiscoverRemote (QObject *parent=arnNullptr)
 
 ~ArnDiscoverRemote ()
 
QString defaultService () const
 Return the default service name. More...
 
void setDefaultService (const QString &defaultService)
 Set the default service name. More...
 
int initialServiceTimeout () const
 Return the time for initial timeout processing. More...
 
void setInitialServiceTimeout (int initialServiceTimeout)
 Set the time for initial timeout processing. More...
 
void startUseServer (ArnServer *arnServer, ArnDiscover::Type discoverType=ArnDiscover::Type::Server)
 Start advertising the ArnServer as a service. More...
 
void startUseNewServer (ArnDiscover::Type discoverType, int port=-1)
 Start a new ArnServer and advertise as a service. More...
 
ArnDiscoverConnectornewConnector (ArnClient &client, const QString &id)
 Create and return an ArnDiscoverConnector for handling remote client. More...
 
- Public Member Functions inherited from ArnDiscoverAdvertise
 ArnDiscoverAdvertise (QObject *parent=arnNullptr)
 
 ~ArnDiscoverAdvertise ()
 
QStringList groups () const
 Return service discover groups used for filter browsing. More...
 
void setGroups (const QStringList &groups)
 Set service discover groups used for filter browsing. More...
 
void addGroup (const QString &group)
 Add a service discover group. More...
 
QString service () const
 Returns the requested service name for this Advertise. More...
 
QString currentService () const
 Returns the current service name for this Advertise. More...
 
State state () const
 Returns the state for this Advertise. More...
 
void advertiseService (ArnDiscover::Type discoverType, const QString &serviceName, int port=-1, const QString &hostName=QString())
 Start advertising the service. More...
 
Arn::XStringMap customProperties () const
 Return service custom properties. More...
 
void setCustomProperties (const Arn::XStringMap &customProperties)
 Set service custom properties. More...
 
void addCustomProperty (const QString &key, const QString &val)
 Add service custom property. More...
 

Detailed Description

Discover with remote setting.

About Arn Discover Remote

This class is the main class for handling discover with remote setting.

Following rules apply:

  • If service is set before start using server, this service will be used.
  • If no persist is active or it gives an empty service name, timeout-processing is done.
  • Timeout-processing can wait upto initialServiceTimeout(), after that defaultService() will be used as service.
  • If service is set by any method before timeout-processing has finnished, that service is used. Timeout-processing is then also aborted.
  • After initial advertise of the service, it can be changed by any method and the changed service will be used.
  • The used service will also be saved if using persist.
  • Methods to change service are ArnDiscoverRemote::setService() and corresponding Arn Data Objects which can be changed locally or remote.

For a complete example of advertisng a server, see the project ArnServer in ServerMain.hpp and ServerMain.cpp files.

Example usage

// In class declare
ArnDiscoverRemote* _discoverRemote;
ArnClient* _client;
// In class code
_client = new ArnClient;
_client->addMountPoint("//");
_client->setAutoConnect( true);
_discoverRemote = new ArnDiscoverRemote( this);
_discoverRemote->setDefaultService("My default service");
_discoverRemote->addGroup("myId/myProduct");
_discoverRemote->addCustomProperty("MyProtoVer", "1.0");
_discoverRemote->startUseNewServer( ArnDiscover::Type::Client, 0); // Dynamic server
ArnDiscoverConnector* connector = _discoverRemote->newConnector( *_client, "House");
connector->setResolver( new ArnDiscoverResolver());
connector->start();
ArnPersist* persist = new ArnPersist( this);
persist->setupDataBase();
Examples:
ArnDemoChatServer/MainWindow.cpp, and ArnDemoChatServer/MainWindow.hpp.

Definition at line 94 of file ArnDiscoverRemote.hpp.

Constructor & Destructor Documentation

◆ ArnDiscoverRemote()

ArnDiscoverRemote::ArnDiscoverRemote ( QObject *  parent = arnNullptr)
explicit

Definition at line 63 of file ArnDiscoverRemote.cpp.

◆ ~ArnDiscoverRemote()

ArnDiscoverRemote::~ArnDiscoverRemote ( )

Definition at line 75 of file ArnDiscoverRemote.cpp.

Member Function Documentation

◆ clientReadyToConnect

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

Central signal for external client connection.

When activated external client connection by the connector method ArnDiscoverConnector::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 newConnector(), e.g "WeatherData-XYZ"
See also
newConnector()
ArnDiscoverConnector::setExternalClientConnect()

◆ defaultService()

QString ArnDiscoverRemote::defaultService ( ) const

Return the default service name.

Returns
default service name, e.g. "Arn Default Service"
See also
setDefaultService()

Definition at line 238 of file ArnDiscoverRemote.cpp.

◆ initialServiceTimeout()

int ArnDiscoverRemote::initialServiceTimeout ( ) const

Return the time for initial timeout processing.

Returns
time in seconds
See also
setInitialServiceTimeout()

Definition at line 255 of file ArnDiscoverRemote.cpp.

◆ newConnector()

ArnDiscoverConnector * ArnDiscoverRemote::newConnector ( ArnClient client,
const QString &  id 
)

Create and return an ArnDiscoverConnector for handling remote client.

The ArnDiscoverConnector is internally connected to this ArnDiscoverRemote.

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 folder path will be "Sys/Discover/Connect/WeatherData-XYZ/".

Parameters
[in]client
[in]ididentifies the target of the client connection, e.g "WeatherData-XYZ"
Returns
The ArnDiscoverConnector

Definition at line 141 of file ArnDiscoverRemote.cpp.

◆ setDefaultService()

void ArnDiscoverRemote::setDefaultService ( const QString &  defaultService)

Set the default service name.

This default service name will be used when no service has been set before timeout. If calling with defaultService empty, it's ignored.

Parameters
[in]defaultServicee.g. "My Default Service"
See also
defaultService()

Definition at line 246 of file ArnDiscoverRemote.cpp.

◆ setInitialServiceTimeout()

void ArnDiscoverRemote::setInitialServiceTimeout ( int  initialServiceTimeout)

Set the time for initial timeout processing.

Initial timeout-processing can wait upto this time, after that defaultService() will be used as service.

Parameters
[in]initialServiceTimeoutin seconds
See also
initialServiceTimeout()

Definition at line 263 of file ArnDiscoverRemote.cpp.

◆ setService

void ArnDiscoverRemote::setService ( const QString &  service)
virtualslot

Set the service name.

Will update current advertised service name if this advertiser has been setup, otherwise the service name is stored for future use.

For remote control the service name is also available as an Arn Data Object at local path "Sys/Discover/This/Service/value".

All the functionaly from ArnDiscoverAdvertise::setService() apply.

Parameters
[in]serviceis the requested service name e.g. "My House Registry"
See also
ArnDiscoverAdvertise::setService()
currentService()
advertiseService()

Definition at line 221 of file ArnDiscoverRemote.cpp.

◆ startUseNewServer()

void ArnDiscoverRemote::startUseNewServer ( ArnDiscover::Type  discoverType,
int  port = -1 
)

Start a new ArnServer and advertise as a service.

Handle advertising an internally created ArnServer as a service on the local network.

This method is typically used when there is no need to access the ArnServer class, which usually is the case in an client application. The ArnServer is then merely used to make the discover functionality remote controlled.

All the functionaly from startUseServer() do apply.

Parameters
[in]discoverTypeis used for discover filtering
[in]portis the port of the service, -1 gives Arn::defaultTcpPort, 0 gives dynamic port
See also
setService()
setDefaultService()
startUseServer()

Definition at line 128 of file ArnDiscoverRemote.cpp.

◆ startUseServer()

void ArnDiscoverRemote::startUseServer ( ArnServer arnServer,
ArnDiscover::Type  discoverType = ArnDiscover::Type::Server 
)

Start advertising the ArnServer as a service.

Handle advertising of an existing ArnServer as a service on the local network. Everything is fully automatic, including remote setting service name and support for persistent storage of the name. Status can be accessed via Arn Data Objects.

Parameters
[in]arnServeris the ArnServer to be advertised
[in]discoverTypeis used for discover filtering
See also
setService()
setDefaultService()
startUseNewServer()

Definition at line 80 of file ArnDiscoverRemote.cpp.


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