|
service_discovery
|
A wrapper class for the avahi service discovery. More...
#include <ServiceDiscovery.hpp>
Public Member Functions | |
| ServiceDiscovery () | |
| virtual | ~ServiceDiscovery () |
| void | start (const ServiceConfiguration &conf) |
| void | listenOn (const std::vector< std::string > &types) |
| void | update (const ServiceDescription &desc) |
| virtual void | update (const ClientObserver::Event &event) |
| void | stop () |
| std::vector< ServiceDescription > | findServices (const SearchPattern &pattern=SearchPattern()) const |
| std::vector< ServiceDescription > | findServices (const ServicePattern &pattern, const std::string &name_space="*") const |
| std::vector< std::string > | getServiceNames () |
| bool | isRunning () const |
| ServiceConfiguration | getConfiguration () const |
| void | addedComponentConnect (const sigc::slot< void, ServiceEvent > &slot) |
| void | removedComponentConnect (const sigc::slot< void, ServiceEvent > &slot) |
Public Member Functions inherited from servicediscovery::avahi::ClientObserver | |
| virtual | ~ClientObserver () |
Static Public Member Functions | |
| static bool | update (const std::string &servicename, const ServiceDescription &description) |
| static ServiceDescription | getServiceDescription (const std::string &servicename) |
| static std::vector< ServiceDescription > | getUpdateableServices () |
| static std::map< std::string, ServiceDescription > | getVisibleServices (const SearchPattern &pattern=SearchPattern("")) |
| static void | registerCallbacks (const std::string &serviceName, const sigc::slot< void, ServiceEvent > &serviceAdded, const sigc::slot< void, ServiceEvent > &serviceRemoved) |
Additional Inherited Members | |
Public Types inherited from servicediscovery::avahi::ClientObserver | |
| enum | EventType { UNKNOWN, DISCONNECTED, RECOVERED } |
A wrapper class for the avahi service discovery.
* namespace sd = servicediscovery;
* void removeCallback(dc::ServiceEvent e)
* {
*
* // what to perform when component has been added
* sd::ServiceConfiguration configuration = e.getServiceConfiguration();
*
* std::string serviceName = configuration.getName();
* std::string labelData = configuration.getDescription("my-label");
* ...
* }
* void addCallback(sd::ServiceEvent e)
* {
* // what to perform when a component has been added
* }
* std::string someServiceData;
* ServiceDiscovery::ServiceDiscovery service;
* std::string serviceName = "ModuleA";
* std::string serviceType = "_module._tcp"
* sd::ServiceConfiguration conf(someName, serviceType);
* conf.setDescription("my-label","data-associated-with-label");
* service.addedComponentConnect(sigc::mem_fun(*this, &addCallback));
* service.removedComponentConnect(sigc::mem_fun(*this, &removeCallback));
* service.start(conf);
*
* std::vector<sd::ServiceDescription> services =
* service.findServices(SearchPattern("my-component-name"));
*
* The service discovery takes advantage of the features of avahi and allows you to publish and browse for services based on existing or newly created types.
Depending on the need, the service discovery can be used in a listening mode only or in publishing mode. However, for each service you intend to publish, you have to create a new ServiceDiscovery instance.
This implementation support a avahi-daemon restart after you service discovery instances have been created. At startup of the service discovery a running avahi-daemon is required. Nevertheless, if you need to restart the avahi-daemon after a successful start, all service browsers will be registered. Any attached application has to deal with the newly emitted ServiceEvents.
Implementation details: All service discovery objects within the same process will access the avahi daemon through a single client connection. Thus synchronization is needed and performed using a unique lock on the client instance.
| servicediscovery::avahi::ServiceDiscovery::ServiceDiscovery | ( | ) |
|
virtual |
Default deconstructor – will cleanup all underlying resolvers and browsers created for this instance
|
inline |
| std::vector< ServiceDescription > servicediscovery::avahi::ServiceDiscovery::findServices | ( | const SearchPattern & | pattern = SearchPattern() | ) | const |
Search Services using a standard search pattern
| std::vector< ServiceDescription > servicediscovery::avahi::ServiceDiscovery::findServices | ( | const ServicePattern & | pattern, |
| const std::string & | name_space = "*" |
||
| ) | const |
Search services using a predefined set of service pattern
| ServiceConfiguration servicediscovery::avahi::ServiceDiscovery::getConfiguration | ( | ) | const |
Get the current configuration of this service discovery if in PUBLISH mode and when the service is running
| if | the service discovery is in LISTEN_ONLY mode, where no service configuration exists |
|
static |
Retrieve the service description for a given service
| servicename |
| std::vector< std::string > servicediscovery::avahi::ServiceDiscovery::getServiceNames | ( | ) |
Get list of names of services currently seen by this service discovery instance
|
static |
Get a list of service descriptions for services that can be updated via the update(const std::string&, const ServiceDescription& ) method.
|
static |
Relying on all running Servicediscovery within a process, this function allows to search for visible services an all existing domains - search pattern allows to limit the search if required
| bool servicediscovery::avahi::ServiceDiscovery::isRunning | ( | ) | const |
Check if service discovery is running
| void servicediscovery::avahi::ServiceDiscovery::listenOn | ( | const std::vector< std::string > & | types | ) |
Use the service discovery object only to listen for a list of given service types
| types | list of types, e.g. whereas types is of format _test._tcp |
|
static |
Register callbacks on a specific ServiceDiscovery object running in the current process
|
inline |
| void servicediscovery::avahi::ServiceDiscovery::start | ( | const ServiceConfiguration & | conf | ) |
Associate the service discovery object with a local service
| conf | Service configuration |
|
virtual |
Stop the listening and publishing activities of the service discovery object
Implements servicediscovery::avahi::ClientObserver.
| void servicediscovery::avahi::ServiceDiscovery::update | ( | const ServiceDescription & | desc | ) |
Update a service description that has been associated with the current service discovery
| description | New service description that will be published |
|
virtual |
Implementation of the observer function in order to react to underlying client connection changes This update is called from the Client and with an acquire avahi client lock
Implements servicediscovery::avahi::ClientObserver.
|
static |
Update all known services of the given name using the associated description
| servicename | Name of the service |
| description | New description of the service |
1.8.13