DeviceControl.h
Go to the documentation of this file.
1 /****
2  * DeviceControl.h
3  *
4  * Copyright 2020 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the Sming UPnP Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include "Device.h"
23 #include "ServiceControl.h"
24 #include <Data/CString.h>
25 #include <Data/Uuid.h>
26 
27 namespace UPnP
28 {
29 class ControlPoint;
30 
31 class DeviceControl : public Device
32 {
33 public:
34  using List = ObjectList<DeviceControl>;
35  using OwnedList = OwnedObjectList<DeviceControl>;
36 
37  struct Description {
38  CString udn;
45  };
46 
48  {
49  }
50 
52  {
53  }
54 
58  bool configureRoot(ControlPoint& controlPoint, const String& location, XML::Node* device);
59 
64  {
65  return reinterpret_cast<DeviceControl&>(Device::root());
66  }
67 
68  const DeviceControl& root() const
69  {
70  return static_cast<const DeviceControl&>(Device::root());
71  }
72 
76  String getUrl(const String& path) const override
77  {
78  return String(root().rootConfig->baseUrl) + path;
79  }
80 
84  String getUrlBasePath() const override
85  {
86  return root().rootConfig->basePath.c_str();
87  }
88 
92  ControlPoint& controlPoint() const
93  {
94  return root().rootConfig->controlPoint;
95  }
96 
102  template <typename T> ServiceControl* getService(const T& serviceType)
103  {
104  return Device::getService<ServiceControl>(serviceType);
105  }
106 
112  template <typename T> DeviceControl* getDevice(const T& deviceType)
113  {
114  return Device::getDevice<DeviceControl>(deviceType);
115  }
116 
117  String getField(Field desc) const override;
118 
122  const String udn() const
123  {
124  return String(description_.udn);
125  }
126 
130  bool configure(XML::Node* device);
131 
136  virtual void onConnected(HttpConnection& connection)
137  {
138  }
139 
141  {
142  return reinterpret_cast<DeviceControl*>(next());
143  }
144 
146  {
147  return reinterpret_cast<DeviceControl&>(Device::parent());
148  }
149 
154  {
155  return description_;
156  }
157 
158 protected:
160 
161  struct RootConfig {
163  CString baseUrl;
164  CString basePath;
165  };
166  std::unique_ptr<RootConfig> rootConfig;
167 };
168 
169 } // namespace UPnP
OwnedObjectList< DeviceControl > OwnedList
Definition: DeviceControl.h:52
Represents any kind of device, including a root device.
Definition: Libraries/UPnP/src/include/Network/UPnP/Device.h:57
bool configureRoot(ControlPoint &controlPoint, const String &location, XML::Node *device)
Called on root device only during discovery.
Provides http base used for client and server connections.
Definition: HttpConnection.h:27
ObjectList< DeviceControl > List
Definition: DeviceControl.h:51
String getField(Field desc) const override
Field
Definition: Libraries/UPnP/src/include/Network/UPnP/Device.h:60
rapidxml::xml_node< char > Node
Definition: RapidXML.h:37
Definition: DeviceControl.h:48
The String class.
Definition: WString.h:136
CString udn
Definition: DeviceControl.h:55
ControlPoint & controlPoint() const
Get managing control point for this device.
Definition: DeviceControl.h:109
Definition: ControlPoint.h:53
CString modelDescription
Definition: DeviceControl.h:60
Class to manage a NUL-terminated C-style string When storing persistent strings in RAM the regular St...
Definition: CString.h:26
LinkedItem * next() const override
Definition: LinkedItem.h:51
String getUrl(const String &path) const override
Get fully-qualified URL given a relative path.
Definition: DeviceControl.h:93
Device & root()
Definition: DeviceControl.h:178
CString serialNumber
Definition: DeviceControl.h:61
Device & parent()
Definition: Libraries/UPnP/src/include/Network/UPnP/Device.h:171
CString manufacturer
Definition: DeviceControl.h:57
CString baseUrl
e.g. "http://192.168.1.1:80"
Definition: DeviceControl.h:180
Definition: ActionRequest.h:24
DeviceControl & parent()
Definition: DeviceControl.h:162
CString basePath
Includes trailing path separator, e.g. "/devices/1/".
Definition: DeviceControl.h:181
ServiceControl * getService(const T &serviceType)
Find a service for this device given its class.
Definition: DeviceControl.h:119
std::unique_ptr< RootConfig > rootConfig
Definition: DeviceControl.h:183
ControlPoint & controlPoint
Definition: DeviceControl.h:179
Device(Device &parent)
Definition: Libraries/UPnP/src/include/Network/UPnP/Device.h:71
Description description_
Definition: DeviceControl.h:176
CString modelNumber
Definition: DeviceControl.h:59
CString friendlyName
Definition: DeviceControl.h:56
DeviceControl(DeviceControl &parent)
Definition: DeviceControl.h:64
const Description & description()
Get device description.
Definition: DeviceControl.h:170
const String udn() const
Get UDN for this device.
Definition: DeviceControl.h:139
bool configure(XML::Node *device)
Configure device using information from description document.
CString modelName
Definition: DeviceControl.h:58
DeviceControl * getDevice(const T &deviceType)
Find a child device given its class.
Definition: DeviceControl.h:129
virtual void onConnected(HttpConnection &connection)
Inherited classes may override this to pull out any additional information from received response hea...
Definition: DeviceControl.h:153
String getUrlBasePath() const override
Get relative path for this device.
Definition: DeviceControl.h:101
Definition: DeviceControl.h:54
DeviceControl * getNext()
Definition: DeviceControl.h:157
Definition: ServiceControl.h:47
DeviceControl & root()
Get the root device.
Definition: DeviceControl.h:80