ArnLib  4.0.x
Active Registry Network
ArnDiscoverAdvertise Class Reference

Advertise an Arn service. More...

#include <ArnDiscover.hpp>

Inheritance diagram for ArnDiscoverAdvertise:
Collaboration diagram for ArnDiscoverAdvertise:

Classes

struct  State
 States of DiscoverAdvertise / These values must be synced with: ArnZeroConf::State. More...
 

Public Slots

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

Signals

void serviceChanged (const QString &serviceName)
 Indicate successfull advertise of service. More...
 
void serviceChangeError (int code)
 Indicate unsuccessfull advertise of service. More...
 

Public Member Functions

 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

Advertise an Arn service.

About Arn Discover

Arn Discover is the mid level support for advertising services on an local network. For higher level support, use ArnDiscoverRemote.

Example usage

// In class declare
ArnDiscoverAdvertise* _serviceAdvertiser;
ArnServer* _server;
// In class code
_server = new ArnServer( ArnServer::Type::NetSync, this);
_server->start(0); // Start server on dynamic port
int serverPort = _server->port();
_serviceAdvertiser = new ArnDiscoverAdvertise( this);
_serviceAdvertiser->addGroup("myId/myProduct");
_serviceAdvertiser->addCustomProperty("MyProtoVer", "1.0");
_serviceAdvertiser->advertiseService( ArnDiscover::Type::Server, "My service", serverPort);

Definition at line 629 of file ArnDiscover.hpp.

Constructor & Destructor Documentation

◆ ArnDiscoverAdvertise()

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

Definition at line 831 of file ArnDiscover.cpp.

◆ ~ArnDiscoverAdvertise()

ArnDiscoverAdvertise::~ArnDiscoverAdvertise ( )

Definition at line 847 of file ArnDiscover.cpp.

Member Function Documentation

◆ addCustomProperty()

void ArnDiscoverAdvertise::addCustomProperty ( const QString &  key,
const QString &  val 
)

Add service custom property.

The custom property are advised to have a key starting with a capital letter to avoid name collision with the system.

Parameters
[in]keyproperty key (Start with capital letter) e.g. "MyProp"
[in]valproperty value kan be any text e.g. "my data"
Note
Properties must be set before calling advertiseService().
See also
setCustomProperties()

Definition at line 932 of file ArnDiscover.cpp.

◆ addGroup()

void ArnDiscoverAdvertise::addGroup ( const QString &  group)

Add a service discover group.

Parameters
[in]groupe.g. "Any Group ID"
Note
Groups must be set before calling advertiseService().
See also
setGroups()

Definition at line 1014 of file ArnDiscover.cpp.

◆ advertiseService()

void ArnDiscoverAdvertise::advertiseService ( ArnDiscover::Type  discoverType,
const QString &  serviceName,
int  port = -1,
const QString &  hostName = QString() 
)

Start advertising the service.

Tries to advertise the service on the local network. Result is indicated by serviceChanged() and serviceChangeError() signals.

Empty serviceName will be ignored, no advertising until using setService() with non empty name.

Parameters
[in]discoverTypeis used for discover filtering
[in]serviceNameis requested name e.g. "My House Registry"
[in]portis the port of the service, -1 gives default Arn port number
[in]hostNameis the host doing the service, empty gives this advertising host
See also
setService()
serviceChanged()
serviceChangeError()

Definition at line 854 of file ArnDiscover.cpp.

◆ currentService()

QString ArnDiscoverAdvertise::currentService ( ) const

Returns the current service name for this Advertise.

This is the realy advertised name when it's available otherwise it's the requested service name.

Returns
service namen (se above) e.g. "My House Registry (2)"
See also
setService()
service()
advertiseService()

Definition at line 964 of file ArnDiscover.cpp.

◆ customProperties()

XStringMap ArnDiscoverAdvertise::customProperties ( ) const

Return service custom properties.

This is only the customer (application) properties, as there also are some Arn system properties.

Returns
custom properties
See also
setCustomProperties()

Definition at line 916 of file ArnDiscover.cpp.

◆ groups()

QStringList ArnDiscoverAdvertise::groups ( ) const

Return service discover groups used for filter browsing.

Returns
groups e.g. ("mydomain.se", "mydomain.se/House", "Any Group ID")
See also
setGroups()

Definition at line 998 of file ArnDiscover.cpp.

◆ service()

QString ArnDiscoverAdvertise::service ( ) const

Returns the requested service name for this Advertise.

This is always the requested service name, the realy used name comes with the serviceChanged() signal and currentService().

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

Definition at line 956 of file ArnDiscover.cpp.

◆ serviceChanged

void ArnDiscoverAdvertise::serviceChanged ( const QString &  serviceName)
signal

Indicate successfull advertise of service.

Parameters
[in]serviceNameis the realy advertised name e.g. "My House Registry (2)"
See also
advertiseService()
setService()

◆ serviceChangeError

void ArnDiscoverAdvertise::serviceChangeError ( int  code)
signal

Indicate unsuccessfull advertise of service.

Parameters
[in]codeerror code.
See also
advertiseService()

◆ setCustomProperties()

void ArnDiscoverAdvertise::setCustomProperties ( const Arn::XStringMap customProperties)

Set service custom properties.

This is only the customer (application) properties, as there also are some Arn system properties.

These custom properties are advised to have a key starting with a capital letter to avoid name collision with the system.

Parameters
[in]customPropertiese.g. Arn::XStringMap().add("MyProp", "my data")
Note
Properties must be set before calling advertiseService().
See also
customProperties()
addCustomProperty()
ArnDiscoverInfo::properties()

Definition at line 924 of file ArnDiscover.cpp.

◆ setGroups()

void ArnDiscoverAdvertise::setGroups ( const QStringList &  groups)

Set service discover groups used for filter browsing.

Groups are used for filtering discovered services. They will also be availabe as properties with naming as "group0", "group1" ...

Parameters
[in]groupse.g. ("mydomain.se", "mydomain.se/House", "Any Group ID")
Note
Groups must be set before calling advertiseService().
See also
groups()
ArnDiscoverBrowser::setFilter()

Definition at line 1006 of file ArnDiscover.cpp.

◆ setService

void ArnDiscoverAdvertise::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.

Service names can be any human readable id. It should be easy to understand, without any cryptic coding, and can usually be modified by the end user

Empty name is ignored. The requested service name is not guaranted to be used for advertise, as it has to be unique within this local network. The realy used name comes with the serviceChanged() signal and currentService().

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

Definition at line 980 of file ArnDiscover.cpp.

◆ state()

ArnDiscoverAdvertise::State ArnDiscoverAdvertise::state ( ) const

Returns the state for this Advertise.

Returns
current state
See also
State

Definition at line 972 of file ArnDiscover.cpp.


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