ObjectClass.h
Go to the documentation of this file.
1 /****
2  * ObjectClass.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 <Network/SSDP/Urn.h>
23 #include <WString.h>
24 #include <FlashString/Vector.hpp>
25 #include <assert.h>
26 
27 namespace UPnP
28 {
29 class Object;
30 class DeviceControl;
31 class ServiceControl;
32 
36 struct ObjectClass {
38  using Kind = Urn::Kind;
39 
43  using Version = uint8_t;
44 
48  using CreateObject = Object* (*)(DeviceControl* owner);
49 
53  struct Device {
62  const FlashString* UDN;
63  };
64 
68  struct Service {
71  };
72 
78  // Both of these fields are optional and may be null
79  union {
80  const Device* device_;
81  const Service* service_;
82  };
83 
84  const FlashString& domain() const
85  {
86  return *domain_;
87  }
88 
89  const FlashString& type() const
90  {
91  return *type_;
92  }
93 
94  const Device* device() const
95  {
96  assert(kind() == Kind::device);
97  return device_;
98  }
99 
100  const Service* service() const
101  {
102  assert(kind() == Kind::service);
103  return service_;
104  }
105 
106  Version version() const
107  {
108  return FSTR::readValue(&version_);
109  }
110 
111  Kind kind() const
112  {
113  return FSTR::readValue(&kind_);
114  }
115 
117  {
118  assert(kind() == Kind::device);
119  return reinterpret_cast<DeviceControl*>(createObject_(nullptr));
120  }
121 
123  {
124  assert(kind() == Kind::device);
125  return reinterpret_cast<DeviceControl*>(createObject_(&owner));
126  }
127 
129  {
130  assert(kind() == Kind::service);
131  return reinterpret_cast<ServiceControl*>(createObject_(&owner));
132  }
133 
134  Urn objectType() const;
135  bool operator==(const ObjectClass& other) const;
136  bool typeIs(const Urn& objectType) const;
137  bool typeIs(Urn::Kind kind, const String& type, uint8_t version) const;
138 
139  explicit operator bool() const
140  {
141  // We're always valid :-)
142  return true;
143  }
144 };
145 
146 } // namespace UPnP
describes a counted string stored in flash memory
Definition: String.hpp:174
Class to access a Vector of objects stored in flash.
Definition: Vector.hpp:110
The String class.
Definition: WString.h:137
Definition: DeviceControl.h:32
Definition: Libraries/UPnP/src/include/Network/UPnP/Object.h:38
Definition: ServiceControl.h:31
Structure for UPnP URNs.
Definition: Urn.h:41
Kind
Definition: Urn.h:43
std::enable_if< sizeof(T)==1, T >::type readValue(const T *ptr)
Read a typed value from flash memory ensuring correct alignment of access.
Definition: Utility.hpp:126
Definition: ActionRequest.h:25
Device description fields.
Definition: ObjectClass.h:53
const FlashString * manufacturerURL
Definition: ObjectClass.h:56
const FlashString * modelDescription
Definition: ObjectClass.h:57
const FlashString * modelNumber
Definition: ObjectClass.h:59
const FlashString * UDN
Definition: ObjectClass.h:62
const FlashString * manufacturer
Definition: ObjectClass.h:55
const FlashString * serialNumber
Definition: ObjectClass.h:61
const FlashString * modelURL
Definition: ObjectClass.h:60
const FlashString * friendlyName
Definition: ObjectClass.h:54
const FlashString * modelName
Definition: ObjectClass.h:58
Service description fields.
Definition: ObjectClass.h:68
const FlashString * schema
Definition: ObjectClass.h:70
const FlashString * serviceId
Definition: ObjectClass.h:69
Describes device or service class.
Definition: ObjectClass.h:36
const Device * device_
Definition: ObjectClass.h:80
Kind kind() const
Definition: ObjectClass.h:111
ServiceControl * createService(DeviceControl &owner) const
Definition: ObjectClass.h:128
const CreateObject createObject_
Definition: ObjectClass.h:77
bool typeIs(Urn::Kind kind, const String &type, uint8_t version) const
Version version() const
Definition: ObjectClass.h:106
const Service * service_
Definition: ObjectClass.h:81
bool operator==(const ObjectClass &other) const
Object *(*)(DeviceControl *owner) CreateObject
Object constructor function.
Definition: ObjectClass.h:48
Kind kind_
Definition: ObjectClass.h:73
const Device * device() const
Definition: ObjectClass.h:94
DeviceControl * createDevice(DeviceControl &owner) const
Definition: ObjectClass.h:122
DeviceControl * createRootDevice() const
Definition: ObjectClass.h:116
bool typeIs(const Urn &objectType) const
const FlashString * type_
Definition: ObjectClass.h:76
const FlashString & type() const
Definition: ObjectClass.h:89
const FlashString * domain_
Definition: ObjectClass.h:75
Version version_
Definition: ObjectClass.h:74
const FlashString & domain() const
Definition: ObjectClass.h:84
const Service * service() const
Definition: ObjectClass.h:100
Urn objectType() const
uint8_t Version
Interface version number.
Definition: ObjectClass.h:43