Lunchbox  1.6.0
servus.h
00001 
00002 /* Copyright (c) 2012, Stefan Eilemann <eile@eyescale.ch> 
00003  *
00004  * This file is part of Lunchbox <https://github.com/Eyescale/Lunchbox>
00005  *
00006  * This library is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU Lesser General Public License version 2.1 as published
00008  * by the Free Software Foundation.
00009  *  
00010  * This library is distributed in the hope that it will be useful, but WITHOUT
00011  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00013  * details.
00014  * 
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this library; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 
00020 #ifndef LUNCHBOX_SERVUS_H
00021 #define LUNCHBOX_SERVUS_H
00022 
00023 #include <lunchbox/api.h>
00024 #include <lunchbox/types.h>
00025 #include <map>
00026 
00027 namespace lunchbox
00028 {
00029 namespace detail { class Servus; }
00030 
00040 class Servus
00041 {
00042 public:
00043     enum Interface
00044     {
00045         IF_ALL = 0, 
00046         // (uint32_t) -1 == kDNSServiceInterfaceIndexLocalOnly
00047         IF_LOCAL = (unsigned)(-1) 
00048     };
00049 
00056     LUNCHBOX_API Servus( const std::string& name );
00057 
00059     LUNCHBOX_API virtual ~Servus();
00060 
00073     LUNCHBOX_API void set( const std::string& key, const std::string& value );
00074 
00076     LUNCHBOX_API Strings getKeys() const;
00077 
00079     LUNCHBOX_API const std::string& get( const std::string& key ) const;
00080 
00088     LUNCHBOX_API bool announce( const unsigned short port,
00089                                 const std::string& instance );
00090 
00092     LUNCHBOX_API void withdraw();
00093 
00095     LUNCHBOX_API bool isAnnounced() const;
00096 
00105     LUNCHBOX_API Strings discover( const Interface interface,
00106                                    const unsigned browseTime );
00107 
00109     LUNCHBOX_API Strings getInstances() const;
00110 
00112     LUNCHBOX_API Strings getKeys( const std::string& instance ) const;
00113 
00115     LUNCHBOX_API bool containsKey( const std::string& instance,
00116                                  const std::string& key ) const;
00117 
00119     LUNCHBOX_API const std::string& get( const std::string& instance,
00120                                          const std::string& key ) const;
00121 
00123     typedef std::map< std::string, std::map< std::string, std::string > > Data;
00124 
00126     LUNCHBOX_API void getData( Data& data );
00127 
00128 private:
00129     detail::Servus* const impl_;
00130 };
00131 
00133 LUNCHBOX_API std::ostream& operator << ( std::ostream&, const Servus& );
00134 }
00135 
00136 #endif // LUNCHBOX_SERVUS_H