Lunchbox
1.13.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
|
Simple wrapper for ZeroConf key/value pairs. More...
#include <servus.h>
Classes | |
class | Result |
The ZeroConf operation result code. More... | |
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. More... | |
Servus (const Servus &from) | |
Copy-construct a ZeroConf service. More... | |
virtual | ~Servus () |
Destruct this service. More... | |
Servus & | operator= (const Servus &rhs) |
Share the ZeroConf service with the rhs argument. More... | |
void | set (const std::string &key, const std::string &value) |
Set a key/value pair to be announced. More... | |
Strings | getKeys () const |
const std::string & | get (const std::string &key) const |
Result | announce (const unsigned short port, const std::string &instance) |
Start announcing the registered key/value pairs. More... | |
void | withdraw () |
Stop announcing the registered key/value pairs. More... | |
bool | isAnnounced () const |
Strings | discover (const Interface addr, const unsigned browseTime) |
Discover all announced key/value pairs. More... | |
Result | beginBrowsing (const lunchbox::Servus::Interface addr) |
Begin the discovery of announced key/value pairs. More... | |
Result | browse (int32_t timeout=-1) |
Browse and process discovered key/value pairs. More... | |
void | endBrowsing () |
Stop a discovery process and return all results. More... | |
bool | isBrowsing () const |
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) |
Static Public Member Functions | |
static bool | isAvailable () |
Friends | |
std::ostream & | operator<< (std::ostream &, const Servus &) |
Output the servus instance in human-readable format. More... | |
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 (
Example:
|
explicit |
Create a new service handle.
name | the service descriptor, e.g., "_hwsd._tcp" |
lunchbox::Servus::Servus | ( | const Servus & | from | ) |
Copy-construct a ZeroConf service.
Both objects will share the same underlying ZeroConf implementation.
|
virtual |
Destruct this service.
Result 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. |
Result lunchbox::Servus::beginBrowsing | ( | const lunchbox::Servus::Interface | addr | ) |
Begin the discovery of announced key/value pairs.
addr | the scope of the discovery |
Result lunchbox::Servus::browse | ( | int32_t | timeout = -1 | ) |
Browse and process discovered key/value pairs.
timeout | The time to spend browsing. |
bool lunchbox::Servus::containsKey | ( | const std::string & | instance, |
const std::string & | key | ||
) | const |
Discover all announced key/value pairs.
addr | the scope of the discovery |
browseTime | the browse time, in milliseconds, to wait for new records. |
void lunchbox::Servus::endBrowsing | ( | ) |
Stop a discovery process and return all results.
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 |
|
static |
bool lunchbox::Servus::isBrowsing | ( | ) | const |
Share the ZeroConf service with the rhs argument.
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.
|
friend |
Output the servus instance in human-readable format.