libupnpp  0.16.0
A C++ wrapper for the Portable UPnP reference library
description.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 _UPNPDEV_HXX_INCLUDED_
19 #define _UPNPDEV_HXX_INCLUDED_
20 
26 #include <unordered_map>
27 #include <vector>
28 #include <string>
29 #include <sstream>
30 
31 #include "libupnpp/upnppexports.hxx"
32 
33 namespace UPnPClient {
34 
46 class UPNPP_API UPnPServiceDesc {
47 public:
49  std::string serviceType;
51  std::string serviceId;
53  std::string SCPDURL;
55  std::string controlURL;
57  std::string eventSubURL;
58 
60  void clear() {
61  serviceType.clear();
62  serviceId.clear();
63  SCPDURL.clear();
64  controlURL.clear();
65  eventSubURL.clear();
66  }
67 
69  std::string dump() const {
70  std::ostringstream os;
71  os << "SERVICE {serviceType [" << serviceType <<
72  "] serviceId [" << serviceId <<
73  "] SCPDURL [" << SCPDURL <<
74  "] controlURL [" << controlURL <<
75  "] eventSubURL [" << eventSubURL <<
76  "] }" << std::endl;
77  return os.str();
78  }
79 
82  struct Argument {
83  std::string name;
84  bool todevice;
85  std::string relatedVariable;
86  void clear() {
87  name.clear();
88  todevice = true;
89  relatedVariable.clear();
90  }
91  };
92 
94  struct Action {
95  std::string name;
96  std::vector<Argument> argList;
97  void clear() {
98  name.clear();
99  argList.clear();
100  }
101  };
102 
104  struct StateVariable {
105  std::string name;
106  bool sendEvents;
107  std::string dataType;
108  bool hasValueRange;
109  int minimum;
110  int maximum;
111  int step;
112  void clear() {
113  name.clear();
114  sendEvents = false;
115  dataType.clear();
116  hasValueRange = false;
117  }
118  };
119 
122  struct Parsed {
123  std::unordered_map<std::string, Action> actionList;
124  std::unordered_map<std::string, StateVariable> stateTable;
125  };
126 
132  bool fetchAndParseDesc(const std::string& urlbase, Parsed& parsed,
133  std::string *XMLText = 0) const;
134 };
135 
142 class UPNPP_API UPnPDeviceDesc {
143 public:
151  UPnPDeviceDesc(const std::string& url, const std::string& description);
152 
153  UPnPDeviceDesc() {}
154 
156  bool ok{false};
158  std::string deviceType;
160  std::string friendlyName;
163  std::string UDN;
165  std::string URLBase;
167  std::string manufacturer;
169  std::string modelName;
170 
172  std::string XMLText;
173 
175  std::vector<UPnPServiceDesc> services;
176 
180  std::vector<UPnPDeviceDesc> embedded;
181 
182  void clear() {
183  *this = UPnPDeviceDesc();
184  }
185  std::string dump() const {
186  std::ostringstream os;
187  os << "DEVICE " << " {deviceType [" << deviceType <<
188  "] friendlyName [" << friendlyName <<
189  "] UDN [" << UDN <<
190  "] URLBase [" << URLBase << "] Services:" << std::endl;
191  for (std::vector<UPnPServiceDesc>::const_iterator it = services.begin();
192  it != services.end(); it++) {
193  os << " " << it->dump();
194  }
195  for (const auto& it: embedded) {
196  os << it.dump();
197  }
198  os << "}" << std::endl;
199  return os.str();
200  }
201 };
202 
203 } // namespace
204 
205 #endif /* _UPNPDEV_HXX_INCLUDED_ */
Service description as parsed from the service XML document: actions and state variables.
Definition: description.hxx:122
std::vector< UPnPServiceDesc > services
Services provided by this device.
Definition: description.hxx:175
std::string UDN
Unique Device Number.
Definition: description.hxx:163
std::string controlURL
Service control URL.
Definition: description.hxx:55
std::vector< UPnPDeviceDesc > embedded
Embedded devices.
Definition: description.hxx:180
std::string dump() const
Debug: return the basic parsed data as a string.
Definition: description.hxx:69
void clear()
Reset all data.
Definition: description.hxx:60
std::string serviceType
Service Type e.g. urn:schemas-upnp-org:service:ConnectionManager:1.
Definition: description.hxx:49
std::string manufacturer
Manufacturer: e.g. D-Link, PacketVideo.
Definition: description.hxx:167
std::string modelName
Model name: e.g. MediaTomb, DNS-327L.
Definition: description.hxx:169
std::string eventSubURL
Service event URL.
Definition: description.hxx:57
std::string friendlyName
User-configurable name (usually), e.g. Lounge-streamer.
Definition: description.hxx:160
std::string XMLText
Raw downloaded document.
Definition: description.hxx:172
std::string serviceId
Service Id inside device: e.g. urn:upnp-org:serviceId:ConnectionManager.
Definition: description.hxx:51
Description of an action argument: name, direction, state variable it relates to (which will yield th...
Definition: description.hxx:82
Holder for all the attributes of an UPnP service state variable.
Definition: description.hxx:104
Data holder for a UPnP service, parsed from the device XML description.
Definition: description.hxx:46
std::string SCPDURL
Service description URL.
Definition: description.hxx:53
Data holder for a UPnP device, parsed from the XML description obtained during discovery.
Definition: description.hxx:142
UPnP Description phase: interpreting the device description which we downloaded from the URL obtained...
Definition: avlastchg.cxx:27
std::string deviceType
Device Type: e.g. urn:schemas-upnp-org:device:MediaServer:1.
Definition: description.hxx:158
UPnP service action descriptor, from the service description document.
Definition: description.hxx:94
std::string URLBase
Base for all relative URLs. e.g. http://192.168.4.4:49152/.
Definition: description.hxx:165