Lunchbox  1.13.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lunchbox::Servus Class Reference

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

#include <servus.h>

+ Collaboration diagram for lunchbox::Servus:

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...
 
Servusoperator= (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...
 

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 (

See also
isAvailable()), this class does not do anything useful.

Example:

Definition at line 43 of file servus.h.

Member Enumeration Documentation

Enumerator
IF_ALL 

use all interfaces

IF_LOCAL 

only local interfaces

Definition at line 46 of file servus.h.

Constructor & Destructor Documentation

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

Create a new service handle.

Parameters
namethe service descriptor, e.g., "_hwsd._tcp"
Version
0.9
lunchbox::Servus::Servus ( const Servus from)

Copy-construct a ZeroConf service.

Both objects will share the same underlying ZeroConf implementation.

Version
1.9.2
virtual lunchbox::Servus::~Servus ( )
virtual

Destruct this service.

Member Function Documentation

Result 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.
Returns
the success status of the operation.
Version
0.9
Result lunchbox::Servus::beginBrowsing ( const lunchbox::Servus::Interface  addr)

Begin the discovery of announced key/value pairs.

Parameters
addrthe scope of the discovery
Returns
the success status of the operation.
Version
1.9.2
Result lunchbox::Servus::browse ( int32_t  timeout = -1)

Browse and process discovered key/value pairs.

Parameters
timeoutThe time to spend browsing.
Returns
the success status of the operation.
Version
1.9.2
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 milliseconds, to wait for new records.
Returns
all instance names found during discovery.
Version
0.9
See also
beginBrowsing(), browse(), endBrowsing()
void lunchbox::Servus::endBrowsing ( )

Stop a discovery process and return all results.

Version
1.9.2
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
static bool lunchbox::Servus::isAvailable ( )
static
Returns
true if a usable implementation is available.
Version
1.9.2
bool lunchbox::Servus::isBrowsing ( ) const
Returns
true if the local data is browsing.
Version
1.9.2
Servus& lunchbox::Servus::operator= ( const Servus rhs)

Share the ZeroConf service with the rhs argument.

Version
1.9.2
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

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  ,
const Servus  
)
friend

Output the servus instance in human-readable format.

Version
1.5.1

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