Lunchbox  1.8.0
Public Types | Public Member Functions | List of all members
lunchbox::Servus Class Reference

Simple wrapper for ZeroConf key/value pairs. More...

#include <servus.h>

+ Inheritance diagram for lunchbox::Servus:
+ Collaboration diagram for lunchbox::Servus:

Public Types

enum  Interface { IF_ALL = 0, IF_LOCAL = (unsigned)(-1) }
typedef std::map< std::string,
std::map< std::string,
std::string > > 
Data

Public Member Functions

 Servus (const std::string &name)
 Create a new service handle.
virtual ~Servus ()
 Destruct this service.
void set (const std::string &key, const std::string &value)
 Set a key/value pair to be announced.
Strings getKeys () const
const std::string & get (const std::string &key) const
bool announce (const unsigned short port, const std::string &instance)
 Start announcing the registered key/value pairs.
void withdraw ()
 Stop announcing the registered key/value pairs.
bool isAnnounced () const
Strings discover (const Interface addr, const unsigned browseTime)
 Discover all announced key/value pairs.
Strings getInstances () const
Strings getKeys (const std::string &instance) const
bool containsKey (const std::string &instance, const std::string &key) const
const std::string & get (const std::string &instance, const std::string &key) const
void getData (Data &data)

Detailed Description

Simple wrapper for ZeroConf key/value pairs.

The servus class allows simple announcement and discovery of key/value pairs using ZeroConf networking. The same instance can be used to announce and/or to browse a ZeroConf service. If the Lunchbox library is compiled without zeroconf support (LUNCHBOX_USE_DNSSD is not set), this class does not do anything useful.

Definition at line 41 of file servus.h.

Member Enumeration Documentation

Enumerator:
IF_ALL 

use all interfaces

IF_LOCAL 

only local interfaces

Definition at line 44 of file servus.h.

Constructor & Destructor Documentation

lunchbox::Servus::Servus ( const std::string &  name)

Create a new service handle.

Parameters
namethe service descriptor, e.g., "_gpu-sd._tcp"
Version
0.9
virtual lunchbox::Servus::~Servus ( )
virtual

Destruct this service.

Member Function Documentation

bool lunchbox::Servus::announce ( const unsigned short  port,
const std::string &  instance 
)

Start announcing the registered key/value pairs.

Parameters
portthe service IP port in host byte order.
instancea host-unique instance name, hostname is used if empty.
Version
0.9
bool lunchbox::Servus::containsKey ( const std::string &  instance,
const std::string &  key 
) const
Returns
true if the given key was discovered.
Version
0.9
Strings lunchbox::Servus::discover ( const Interface  addr,
const unsigned  browseTime 
)

Discover all announced key/value pairs.

Parameters
addrthe scope of the discovery
browseTimethe browse time, in millisecond, for discovery.
Returns
all instance names found during discovery.
Version
0.9
const std::string& lunchbox::Servus::get ( const std::string &  key) const
Returns
the value to the given (to be) announced key.
Version
1.5.1
const std::string& lunchbox::Servus::get ( const std::string &  instance,
const std::string &  key 
) const
Returns
the value of the given key and instance.
Version
0.9
Strings lunchbox::Servus::getInstances ( ) const
Returns
all instances found during the last discovery.
Version
0.9
Strings lunchbox::Servus::getKeys ( ) const
Returns
all (to be) announced keys.
Version
1.5.1
Strings lunchbox::Servus::getKeys ( const std::string &  instance) const
Returns
all keys discovered on the given instance.
Version
0.9
bool lunchbox::Servus::isAnnounced ( ) const
Returns
true if the local data is announced.
Version
0.9
void lunchbox::Servus::set ( const std::string &  key,
const std::string &  value 
)

Set a key/value pair to be announced.

Keys should be at most eight characters, and values are truncated to 255 characters. The total length of all keys and values cannot exceed 65535 characters. Setting a value on an announced service causes an update which needs some time to propagate after this function returns, that is, calling discover() immediately afterwards will very likely not contain the new key/value pair.

Version
0.9
void lunchbox::Servus::withdraw ( )

Stop announcing the registered key/value pairs.

Version
0.9

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