|
LUNCHBOX_API | Servus (const std::string &name) |
| Create a new service handle. More...
|
|
virtual LUNCHBOX_API | ~Servus () |
| Destruct this service. 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 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) |
|
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.
Example:
#include "test.h"
#include <lunchbox/servus.h>
#include <lunchbox/rng.h>
#ifdef LUNCHBOX_USE_DNSSD
# include <dns_sd.h>
#endif
int main( int, char** )
{
const uint16_t port = rng.
get< uint16_t >();
std::ostringstream os;
os << port;
#ifdef LUNCHBOX_USE_DNSSD
TEST( lunchbox::Result::SUCCESS == kDNSServiceErr_NoError );
if( result == kDNSServiceErr_Unknown )
{
std::cerr << "Bailing, got " << result
<< ": looks like a broken zeroconf setup" << std::endl;
return EXIT_SUCCESS;
}
TESTINFO( result, result );
service.withdraw();
service.set( "foo", "bar" );
TEST( service.announce( port, os.str( )));
if( hosts.empty() && getenv( "TRAVIS" ))
{
std::cerr << "Bailing, got no hosts on a Travis CI setup" << std::endl;
return EXIT_SUCCESS;
}
TESTINFO( hosts.size() == 1, hosts.size( ));
TESTINFO( hosts.front() == os.str(), hosts.front( ));
TEST( service.get( hosts.front(), "foo" ) == "bar" );
service.set( "foobar", "42" );
TEST( service.get( hosts.front(), "foobar" ) == "42" );
TEST( service.getKeys().size() == 2 );
#else
#endif
return EXIT_SUCCESS;
}
Definition at line 44 of file servus.h.