Search.h
Go to the documentation of this file.
1 /****
2  * Search.h
3  *
4  * Copyright 2019 mikee47 <mike@sillyhouse.net>
5  * Copyright 2020 slaff <slaff@attachix.com>
6  *
7  * This file is part of the Sming UPnP Library
8  *
9  * This library is free software: you can redistribute it and/or modify it under the terms of the
10  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this library.
17  * If not, see <https://www.gnu.org/licenses/>.
18  *
19  ****/
20 
21 #pragma once
22 
23 #include "DeviceControl.h"
24 #include "ServiceControl.h"
25 
26 namespace UPnP
27 {
31 struct Search {
32  enum class Kind {
33  none,
34  ssdp,
35  desc,
36  device,
37  service,
38  };
39 
40  Search() = default;
41 
42  Search(const Search&) = delete;
43 
45  {
46  }
47 
49  {
50  }
51 
52  virtual ~Search()
53  {
54  }
55 
56  virtual explicit operator bool() const = 0;
57 
59  {
60  switch(kind) {
61  case Kind::ssdp:
62  return F("SSDP");
63  case Kind::desc:
64  return F("Description");
65  case Kind::device:
66  return F("Device");
67  case Kind::service:
68  return F("Service");
69  default:
70  assert(false);
71  return nullptr;
72  }
73  }
74 
75  String toString() const
76  {
77  String s = toString(kind);
78  s += " {";
79  s += urn;
80  s += '}';
81  return s;
82  }
83 
86 };
87 
88 struct SsdpSearch : public Search {
92  using Callback = Delegate<void(SSDP::BasicMessage& message)>;
93 
95  {
96  }
97 
98  explicit operator bool() const override
99  {
100  return bool(callback);
101  }
102 
104 };
105 
106 struct DescriptionSearch : public Search {
111  using Callback = Delegate<void(HttpConnection& connection, XML::Document* description)>;
112 
114  {
115  }
116 
117  explicit operator bool() const override
118  {
119  return bool(callback);
120  }
121 
123 };
124 
125 struct DeviceSearch : public Search {
132  using Callback = Delegate<bool(DeviceControl& device)>;
133 
135  : Search(Kind::device, cls.objectType()), cls(cls), callback(callback)
136  {
137  }
138 
139  explicit operator bool() const override
140  {
141  return bool(callback);
142  }
143 
144  const ObjectClass& cls;
146 };
147 
148 struct ServiceSearch : public Search {
156  using Callback = Delegate<bool(DeviceControl& device, ServiceControl& service)>;
157 
159  : Search(Kind::service, cls.objectType()), cls(cls), callback(callback)
160  {
161  }
162 
163  explicit operator bool() const override
164  {
165  return bool(callback);
166  }
167 
168  const ObjectClass& cls;
170 };
171 
172 } // namespace UPnP
#define F(string_literal)
Wrap a string literal stored in flash and access it using a String object.
Definition: WString.h:113
Provides http base used for client and server connections.
Definition: HttpConnection.h:28
Handles incoming messages.
Definition: SSDP/src/include/Network/SSDP/Message.h:62
The String class.
Definition: WString.h:137
Definition: DeviceControl.h:32
Definition: ServiceControl.h:31
Structure for UPnP URNs.
Definition: Urn.h:41
Definition: ActionRequest.h:25
rapidxml::xml_document< char > Document
Definition: RapidXML.h:36
Definition: Search.h:106
DescriptionSearch(const Urn &urn, Callback callback)
Definition: Search.h:113
Callback callback
Definition: Search.h:122
Definition: Search.h:125
const ObjectClass & cls
Definition: Search.h:144
DeviceSearch(const ObjectClass &cls, Callback callback)
Definition: Search.h:134
Callback callback
Definition: Search.h:145
Describes device or service class.
Definition: ObjectClass.h:36
This is a helper class used by ControlPoint to manage different search types.
Definition: Search.h:31
Kind
Definition: Search.h:32
@ ssdp
SSDP response.
@ desc
Fetch description for any matching urn.
@ none
No search active.
@ device
Searching for pre-defined device class.
@ service
Searching for pre-defined service class.
virtual ~Search()
Definition: Search.h:52
String toString() const
Definition: Search.h:75
String urn
Definition: Search.h:85
Search()=default
Search(Kind kind, const Urn &urn)
Definition: Search.h:48
String toString(Search::Kind kind) const
Definition: Search.h:58
Kind kind
Definition: Search.h:84
Search(const Search &)=delete
Search(Kind kind, const String &urn)
Definition: Search.h:44
Definition: Search.h:148
const ObjectClass & cls
Definition: Search.h:168
Callback callback
Definition: Search.h:169
ServiceSearch(const ObjectClass &cls, Callback callback)
Definition: Search.h:158
Definition: Search.h:88
SsdpSearch(const Urn &urn, Callback callback)
Definition: Search.h:94
Callback callback
Definition: Search.h:103