libupnpp  0.16.0
A C++ wrapper for the Portable UPnP reference library
upnpplib.hxx
1 /* Copyright (C) 2006-2016 J.F.Dockes
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16  * 02110-1301 USA
17  */
18 #ifndef _LIBUPNP_H_X_INCLUDED_
19 #define _LIBUPNP_H_X_INCLUDED_
20 
21 #include <upnp/upnp.h>
22 
23 #include <map>
24 #include <string>
25 
27 #define LIBUPNPP_VERSION_MAJOR 0
28 #define LIBUPNPP_VERSION_MINOR 16
29 #define LIBUPNPP_VERSION_REVISION 0
30 #define LIBUPNPP_AT_LEAST(A,B,C) \
32  (LIBUPNPP_VERSION_MAJOR > (A) || \
33  (LIBUPNPP_VERSION_MAJOR == (A) && \
34  (LIBUPNPP_VERSION_MINOR > (B) || \
35  (LIBUPNPP_VERSION_MINOR == (B) && LIBUPNPP_VERSION_REVISION >= (C)))))
36 
37 namespace UPnPP {
38 
45 class LibUPnP {
46 public:
47  ~LibUPnP();
48 
71  static LibUPnP* getLibUPnP(bool serveronly = false, std::string* hwaddr = 0,
72  const std::string ifname = std::string(),
73  const std::string ip = std::string(),
74  unsigned short port = 0);
75 
77  std::string host();
78 
80  static std::string versionString();
81 
84  enum LogLevel {LogLevelNone, LogLevelError, LogLevelDebug};
94  bool setLogFileName(const std::string& fn, LogLevel level = LogLevelError);
99  bool setLogLevel(LogLevel level);
100 
109  void setMaxContentLength(int bytes);
110 
112  bool ok() const;
113 
115  int getInitError() const;
116 
119  static std::string makeDevUUID(const std::string& name,
120  const std::string& hw);
121 
123  static std::string errAsString(const std::string& who, int code);
124 
126  /* The methods which follow are normally for use by the
127  * intermediate layers in libupnpp, such as the base device class
128  * or the server directory, end-user code should not need them in
129  * general.
130  */
131 
135  void registerHandler(Upnp_EventType et, Upnp_FunPtr handler, void *cookie);
136 
138  static std::string evTypeAsString(Upnp_EventType);
139 
140  int setupWebServer(const std::string& description, UpnpDevice_Handle *dvh);
141 
142  UpnpClient_Handle getclh();
143 
144 private:
145  class Internal;
146  Internal *m;
147 
148  LibUPnP(bool serveronly, std::string *hwaddr,
149  const std::string ifname, const std::string ip,
150  unsigned short port);
151  LibUPnP(const LibUPnP &);
152  LibUPnP& operator=(const LibUPnP &);
153 
154  static int o_callback(Upnp_EventType, void *, void *);
155 };
156 
157 } // namespace UPnPP
158 
159 #endif /* _LIBUPNP.H_X_INCLUDED_ */
static std::string makeDevUUID(const std::string &name, const std::string &hw)
Build a unique persistent UUID for a root device.
Definition: upnpplib.cxx:298
bool setLogFileName(const std::string &fn, LogLevel level=LogLevelError)
Set libupnp log file name and activate/deactivate logging.
Definition: upnpplib.cxx:209
std::string host()
Return the IP v4 address as dotted notation.
Definition: upnpplib.cxx:180
void registerHandler(Upnp_EventType et, Upnp_FunPtr handler, void *cookie)
Private: specify function to be called on given UPnP event.
Definition: upnpplib.cxx:250
int getInitError() const
Retrieve init error if state not ok.
Definition: upnpplib.cxx:106
LogLevel
libupnp (pupnp) logging: this is distinct from libupnpp logging
Definition: upnpplib.hxx:84
static std::string evTypeAsString(Upnp_EventType)
Private: translate libupnp event type to string.
Definition: upnpplib.cxx:315
void setMaxContentLength(int bytes)
Set max library buffer size for reading content from servers.
Definition: upnpplib.cxx:204
Definition: base64.cxx:26
Our link to libupnp.
Definition: upnpplib.hxx:45
static std::string versionString()
Returns something like "libupnpp 0.14.0 libupnp x.y.z".
Definition: upnpplib.cxx:89
bool setLogLevel(LogLevel level)
Set libupnp log level.
Definition: upnpplib.cxx:230
static std::string errAsString(const std::string &who, int code)
Translate libupnp integer error code (UPNP_E_XXX) to string.
Definition: upnpplib.cxx:262
Definition: upnpplib.cxx:55
bool ok() const
Check state after initialization.
Definition: upnpplib.cxx:101
static LibUPnP * getLibUPnP(bool serveronly=false, std::string *hwaddr=0, const std::string ifname=std::string(), const std::string ip=std::string(), unsigned short port=0)
Retrieve the singleton LibUPnP object.
Definition: upnpplib.cxx:75