Lunchbox  1.8.0
servus.h
1 
2 /* Copyright (c) 2012, 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/types.h>
25 #include <lunchbox/nonCopyable.h>
26 #include <map>
27 
28 namespace lunchbox
29 {
30 namespace detail { class Servus; }
31 
41 class Servus : public NonCopyable
42 {
43 public:
44  enum Interface
45  {
46  IF_ALL = 0,
47  // (uint32_t) -1 == kDNSServiceInterfaceIndexLocalOnly
48  IF_LOCAL = (unsigned)(-1)
49  };
50 
57  LUNCHBOX_API Servus( const std::string& name );
58 
60  LUNCHBOX_API virtual ~Servus();
61 
74  LUNCHBOX_API void set( const std::string& key, const std::string& value );
75 
77  LUNCHBOX_API Strings getKeys() const;
78 
80  LUNCHBOX_API const std::string& get( const std::string& key ) const;
81 
89  LUNCHBOX_API bool announce( const unsigned short port,
90  const std::string& instance );
91 
93  LUNCHBOX_API void withdraw();
94 
96  LUNCHBOX_API bool isAnnounced() const;
97 
106  LUNCHBOX_API Strings discover( const Interface addr,
107  const unsigned browseTime );
108 
110  LUNCHBOX_API Strings getInstances() const;
111 
113  LUNCHBOX_API Strings getKeys( const std::string& instance ) const;
114 
116  LUNCHBOX_API bool containsKey( const std::string& instance,
117  const std::string& key ) const;
118 
120  LUNCHBOX_API const std::string& get( const std::string& instance,
121  const std::string& key ) const;
122 
124  typedef std::map< std::string, std::map< std::string, std::string > > Data;
125 
127  LUNCHBOX_API void getData( Data& data );
128 
129 private:
130  detail::Servus* const impl_;
131 };
132 
134 LUNCHBOX_API std::ostream& operator << ( std::ostream&, const Servus& );
135 }
136 
137 #endif // LUNCHBOX_SERVUS_H