Lunchbox
1.10.0
|
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 | |
LUNCHBOX_API | Servus (const std::string &name) |
Create a new service handle. More... | |
LUNCHBOX_API | Servus (const Servus &from) |
Copy-construct a ZeroConf service. More... | |
virtual LUNCHBOX_API | ~Servus () |
Destruct this service. More... | |
LUNCHBOX_API Servus & | operator= (const Servus &rhs) |
Share the ZeroConf service with the rhs argument. More... | |
LUNCHBOX_API void | set (const std::string &key, const std::string &value) |
Set a key/value pair to be announced. More... | |
LUNCHBOX_API Strings | getKeys () const |
LUNCHBOX_API const std::string & | get (const std::string &key) const |
LUNCHBOX_API Result | announce (const unsigned short port, const std::string &instance) |
Start announcing the registered key/value pairs. More... | |
LUNCHBOX_API void | withdraw () |
Stop announcing the registered key/value pairs. More... | |
LUNCHBOX_API bool | isAnnounced () const |
LUNCHBOX_API Strings | discover (const Interface addr, const unsigned browseTime) |
Discover all announced key/value pairs. More... | |
LUNCHBOX_API Result | beginBrowsing (const lunchbox::Servus::Interface addr) |
Begin the discovery of announced key/value pairs. More... | |
LUNCHBOX_API Result | browse (int32_t timeout=-1) |
Browse and process discovered key/value pairs. More... | |
LUNCHBOX_API void | endBrowsing () |
Stop a discovery process and return all results. More... | |
LUNCHBOX_API bool | isBrowsing () const |
LUNCHBOX_API Strings | getInstances () const |
LUNCHBOX_API Strings | getKeys (const std::string &instance) const |
LUNCHBOX_API bool | containsKey (const std::string &instance, const std::string &key) const |
LUNCHBOX_API const std::string & | get (const std::string &instance, const std::string &key) const |
LUNCHBOX_API void | getData (Data &data) |
Static Public Member Functions | |
static LUNCHBOX_API bool | isAvailable () |
Friends | |
LUNCHBOX_API 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_API lunchbox::Servus::Servus | ( | const Servus & | from | ) |
Copy-construct a ZeroConf service.
Both objects will share the same underlying ZeroConf implementation.
|
virtual |
Destruct this service.
LUNCHBOX_API 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. |
LUNCHBOX_API Result lunchbox::Servus::beginBrowsing | ( | const lunchbox::Servus::Interface | addr | ) |
Begin the discovery of announced key/value pairs.
addr | the scope of the discovery |
LUNCHBOX_API Result lunchbox::Servus::browse | ( | int32_t | timeout = -1 | ) |
Browse and process discovered key/value pairs.
timeout | The time to spend browsing. |
LUNCHBOX_API 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. |
LUNCHBOX_API void lunchbox::Servus::endBrowsing | ( | ) |
Stop a discovery process and return all results.
LUNCHBOX_API const std::string& lunchbox::Servus::get | ( | const std::string & | key | ) | const |
LUNCHBOX_API const std::string& lunchbox::Servus::get | ( | const std::string & | instance, |
const std::string & | key | ||
) | const |
LUNCHBOX_API Strings lunchbox::Servus::getInstances | ( | ) | const |
LUNCHBOX_API Strings lunchbox::Servus::getKeys | ( | ) | const |
LUNCHBOX_API Strings lunchbox::Servus::getKeys | ( | const std::string & | instance | ) | const |
LUNCHBOX_API bool lunchbox::Servus::isAnnounced | ( | ) | const |
|
static |
LUNCHBOX_API bool lunchbox::Servus::isBrowsing | ( | ) | const |
Share the ZeroConf service with the rhs argument.
LUNCHBOX_API 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.
LUNCHBOX_API void lunchbox::Servus::withdraw | ( | ) |
Stop announcing the registered key/value pairs.
|
friend |
Output the servus instance in human-readable format.