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:
36 
37  struct Description {
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 
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 {
165  };
166  std::unique_ptr<RootConfig> rootConfig;
167 };
168 
169 } // namespace UPnP
Class to manage a NUL-terminated C-style string When storing persistent strings in RAM the regular St...
Definition: CString.h:27
Provides http base used for client and server connections.
Definition: HttpConnection.h:28
The String class.
Definition: WString.h:137
Definition: ControlPoint.h:36
Definition: DeviceControl.h:32
DeviceControl(DeviceControl *parent=nullptr)
Definition: DeviceControl.h:51
bool configure(XML::Node *device)
Configure device using information from description document.
DeviceControl & root()
Get the root device.
Definition: DeviceControl.h:63
virtual void onConnected(HttpConnection &connection)
Inherited classes may override this to pull out any additional information from received response hea...
Definition: DeviceControl.h:136
DeviceControl(DeviceControl &parent)
Definition: DeviceControl.h:47
String getUrl(const String &path) const override
Get fully-qualified URL given a relative path.
Definition: DeviceControl.h:76
const String udn() const
Get UDN for this device.
Definition: DeviceControl.h:122
Description description_
Definition: DeviceControl.h:159
String getUrlBasePath() const override
Get relative path for this device.
Definition: DeviceControl.h:84
DeviceControl * getNext()
Definition: DeviceControl.h:140
bool configureRoot(ControlPoint &controlPoint, const String &location, XML::Node *device)
Called on root device only during discovery.
std::unique_ptr< RootConfig > rootConfig
Definition: DeviceControl.h:166
ControlPoint & controlPoint() const
Get managing control point for this device.
Definition: DeviceControl.h:92
const Description & description()
Get device description.
Definition: DeviceControl.h:153
const DeviceControl & root() const
Definition: DeviceControl.h:68
ServiceControl * getService(const T &serviceType)
Find a service for this device given its class.
Definition: DeviceControl.h:102
DeviceControl * getDevice(const T &deviceType)
Find a child device given its class.
Definition: DeviceControl.h:112
DeviceControl & parent()
Definition: DeviceControl.h:145
String getField(Field desc) const override
Represents any kind of device, including a root device.
Definition: Libraries/UPnP/src/include/Network/UPnP/Device.h:58
Device & parent()
Definition: Libraries/UPnP/src/include/Network/UPnP/Device.h:171
Field
Definition: Libraries/UPnP/src/include/Network/UPnP/Device.h:60
Device & root()
Item * next() const override
Definition: LinkedItem.h:34
Definition: ServiceControl.h:31
Definition: ActionRequest.h:25
rapidxml::xml_node< char > Node
Definition: RapidXML.h:37
Definition: DeviceControl.h:37
CString serialNumber
Definition: DeviceControl.h:44
CString modelName
Definition: DeviceControl.h:41
CString modelDescription
Definition: DeviceControl.h:43
CString friendlyName
Definition: DeviceControl.h:39
CString udn
Definition: DeviceControl.h:38
CString modelNumber
Definition: DeviceControl.h:42
CString manufacturer
Definition: DeviceControl.h:40
Definition: DeviceControl.h:161
CString baseUrl
e.g. "http://192.168.1.1:80"
Definition: DeviceControl.h:163
ControlPoint & controlPoint
Definition: DeviceControl.h:162
CString basePath
Includes trailing path separator, e.g. "/devices/1/".
Definition: DeviceControl.h:164