Lunchbox  1.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
servus.h
1 
2 /* Copyright (c) 2012-2013, Stefan Eilemann <eile@eyescale.ch>
3  *
4  * This file is part of Lunchbox <https://github.com/Eyescale/Lunchbox>
5  *
6  * This library is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License version 2.1 as published
8  * by the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef LUNCHBOX_SERVUS_H
21 #define LUNCHBOX_SERVUS_H
22 
23 #include <lunchbox/api.h>
24 #include <lunchbox/result.h> // nested base class
25 #include <lunchbox/types.h>
26 #include <boost/noncopyable.hpp>
27 #include <map>
28 
29 namespace lunchbox
30 {
31 namespace detail { class Servus; }
32 
44 class Servus : public boost::noncopyable
45 {
46 public:
47  enum Interface
48  {
49  IF_ALL = 0,
50  // (uint32_t) -1 == kDNSServiceInterfaceIndexLocalOnly
51  IF_LOCAL = (unsigned)(-1)
52  };
53 
60  class Result : public lunchbox::Result
61  {
62  public:
63  explicit Result( const int32_t code ) : lunchbox::Result( code ){}
64  virtual ~Result(){}
65  LUNCHBOX_API std::string getString() const override;
66 
68  static const int32_t PENDING = -1;
70  static const int32_t NOT_SUPPORTED = -2;
71  };
72 
79  LUNCHBOX_API explicit Servus( const std::string& name );
80 
82  LUNCHBOX_API virtual ~Servus();
83 
96  LUNCHBOX_API void set( const std::string& key, const std::string& value );
97 
99  LUNCHBOX_API Strings getKeys() const;
100 
102  LUNCHBOX_API const std::string& get( const std::string& key ) const;
103 
112  LUNCHBOX_API Result announce( const unsigned short port,
113  const std::string& instance );
114 
116  LUNCHBOX_API void withdraw();
117 
119  LUNCHBOX_API bool isAnnounced() const;
120 
130  LUNCHBOX_API Strings discover( const Interface addr,
131  const unsigned browseTime );
132 
134  LUNCHBOX_API Strings getInstances() const;
135 
137  LUNCHBOX_API Strings getKeys( const std::string& instance ) const;
138 
140  LUNCHBOX_API bool containsKey( const std::string& instance,
141  const std::string& key ) const;
142 
144  LUNCHBOX_API const std::string& get( const std::string& instance,
145  const std::string& key ) const;
146 
148  typedef std::map< std::string, std::map< std::string, std::string > > Data;
149 
151  LUNCHBOX_API void getData( Data& data );
152 
153 private:
154  detail::Servus* const impl_;
155 };
156 
158 LUNCHBOX_API std::ostream& operator << ( std::ostream&, const Servus& );
159 }
160 
161 #endif // LUNCHBOX_SERVUS_H
LUNCHBOX_API Result announce(const unsigned short port, const std::string &instance)
Start announcing the registered key/value pairs.
Defines export visibility macros for Lunchbox.
Basic type definitions not provided by the operating system.
virtual LUNCHBOX_API ~Servus()
Destruct this service.
LUNCHBOX_API void withdraw()
Stop announcing the registered key/value pairs.
LUNCHBOX_API Strings discover(const Interface addr, const unsigned browseTime)
Discover all announced key/value pairs.
std::vector< std::string > Strings
A vector of std::strings.
Definition: types.h:221
LUNCHBOX_API Strings getKeys() const
LUNCHBOX_API bool isAnnounced() const
A result returns an error code and behaves like a boolean.
Definition: result.h:31
virtual ~Result()
Destruct the result.
Definition: servus.h:64
LUNCHBOX_API Servus(const std::string &name)
Create a new service handle.
static const int32_t PENDING
operation did not complete.
Definition: servus.h:68
std::ostream & operator<<(std::ostream &os, const Array< T > &array)
Pretty-print all members of the array.
Definition: array.h:47
static const int32_t NOT_SUPPORTED
Lunchbox compiled without ZeroConf support.
Definition: servus.h:70
The ZeroConf operation result code.
Definition: servus.h:60
LUNCHBOX_API std::string getString() const override
LUNCHBOX_API bool containsKey(const std::string &instance, const std::string &key) const
use all interfaces
Definition: servus.h:49
LUNCHBOX_API Strings getInstances() const
Simple wrapper for ZeroConf key/value pairs.
Definition: servus.h:44
only local interfaces
Definition: servus.h:51
LUNCHBOX_API void set(const std::string &key, const std::string &value)
Set a key/value pair to be announced.