libupnpp  0.16.0
A C++ wrapper for the Portable UPnP reference library
upnpp_p.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 _UPNPP_H_X_INCLUDED_
19 #define _UPNPP_H_X_INCLUDED_
20 
21 /* Private shared defs for the library. Clients need not and should
22  not include this */
23 #include <sys/types.h>
24 
25 #include <upnp.h>
26 
27 #include <time.h>
28 
29 #include <string>
30 #include <mutex>
31 #include <unordered_map>
32 #include <vector>
33 #include <utility>
34 
35 #include "libupnpp/config.h"
36 #include "libupnpp/upnpplib.hxx"
37 #include "libupnpp/soaphelp.hxx"
38 
39 // define this for testing setting the description document as memory
40 // buffer Note: this does not work well for embedded devices (npupnp
41 // issue?), did not try to debug. Also does not work for multiple
42 // roots (would need a way to specify a different doc name).
43 #undef SETUP_DESCRIPTION_BY_BUFFER
44 
45 namespace UPnPP {
46 
48 public:
49  std::string name;
50  std::unordered_map<std::string, std::string> args;
51 };
52 
54 public:
55  std::string serviceType;
56  std::string name;
57  std::vector<std::pair<std::string, std::string> > data;
58 };
59 
60 // Concatenate paths. Caller should make sure it makes sense.
61 extern std::string caturl(const std::string& s1, const std::string& s2);
62 // Return the scheme://host:port[/] part of input, or input if it is weird
63 extern std::string baseurl(const std::string& url);
64 extern std::string path_getfather(const std::string &s);
65 extern std::string path_getsimple(const std::string &s);
66 template <class T> bool csvToStrings(const std::string& s, T &tokens);
67 
68 // @return false if s does not look like a bool at all (does not begin
69 // with [FfNnYyTt01]
70 extern bool stringToBool(const std::string& s, bool *v);
71 
73 extern std::string evTypeAsString(Upnp_EventType);
74 
76 public:
77 
78  int getSubsTimeout();
79 
83  void registerHandler(Upnp_EventType et, Upnp_FunPtr handler, void *cookie);
84 
85  // A Handler object records the data from registerHandler.
86  class Handler {
87  public:
88  Handler()
89  : handler(0), cookie(0) {}
90  Handler(Upnp_FunPtr h, void *c)
91  : handler(h), cookie(c) {}
92  Upnp_FunPtr handler;
93  void *cookie;
94  };
95 
96  int setupWebServer(const std::string& description, UpnpDevice_Handle *dvh);
97  UpnpClient_Handle getclh();
98 
99  bool ok;
100  static int init_error;
101  UpnpClient_Handle clh;
102  std::mutex mutex;
103  std::map<Upnp_EventType, Handler> handlers;
104 };
105 
106 } // namespace
107 
108 #endif /* _UPNPP_H_X_INCLUDED_ */
Definition: upnpp_p.hxx:47
Definition: base64.cxx:26
Definition: upnpp_p.hxx:86
Definition: upnpp_p.hxx:75
Definition: upnpp_p.hxx:53