Lunchbox
1.6.0
|
Simple wrapper for ZeroConf key/value pairs. More...
#include <servus.h>
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 interface, 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) |
Public Types | |
enum | Interface { IF_ALL = 0, IF_LOCAL = (unsigned)(-1) } |
typedef std::map< std::string, std::map< std::string, std::string > > | Data |
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.
lunchbox::Servus::Servus | ( | const std::string & | name | ) |
Create a new service handle.
name | the service descriptor, e.g., "_gpu-sd._tcp" |
virtual lunchbox::Servus::~Servus | ( | ) | [virtual] |
Destruct this service.
bool lunchbox::Servus::announce | ( | const unsigned short | port, |
const std::string & | instance | ||
) |
Start announcing the registered key/value pairs.
port | the service IP port in host byte order. |
instance | a host-unique instance name, hostname is used if empty. |
bool lunchbox::Servus::containsKey | ( | const std::string & | instance, |
const std::string & | key | ||
) | const |
Strings lunchbox::Servus::discover | ( | const Interface | interface, |
const unsigned | browseTime | ||
) |
Discover all announced key/value pairs.
interface | the scope of the discovery |
browseTime | the browse time, in millisecond, for discovery. |
const std::string& lunchbox::Servus::get | ( | const std::string & | key | ) | const |
const std::string& lunchbox::Servus::get | ( | const std::string & | instance, |
const std::string & | key | ||
) | const |
Strings lunchbox::Servus::getInstances | ( | ) | const |
Strings lunchbox::Servus::getKeys | ( | ) | const |
Strings lunchbox::Servus::getKeys | ( | const std::string & | instance | ) | const |
bool lunchbox::Servus::isAnnounced | ( | ) | const |
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.
void lunchbox::Servus::withdraw | ( | ) |
Stop announcing the registered key/value pairs.