BaseObject.h
Go to the documentation of this file.
1 /****
2  * BaseObject.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 "LinkedItem.h"
23 #include "ObjectClass.h"
24 #include <WString.h>
25 #include <Delegate.h>
31 #include <Network/SSDP/Urn.h>
32 
33 namespace UPnP
34 {
35 using namespace SSDP;
36 
37 class BaseObject;
38 
39 struct SearchFilter {
40  using Callback = Delegate<void(BaseObject* object, SearchMatch match)>;
41 
42  SearchFilter(const MessageSpec& ms, uint32_t delayMs) : ms(ms), delayMs(delayMs)
43  {
44  }
45 
46  const MessageSpec& ms;
47  uint32_t delayMs;
48  String targetString;
49  Callback callback;
50 };
51 
55 class BaseObject : public LinkedItem
56 {
57 public:
66  virtual bool formatMessage(Message& msg, MessageSpec& ms) = 0;
67 
73  virtual void sendMessage(Message& msg, MessageSpec& ms);
74 };
75 
79 template <typename ObjectType, typename BaseObjectType> class ObjectTemplate : public BaseObjectType
80 {
81 public:
82  class Iterator : public std::iterator<std::forward_iterator_tag, ObjectType>
83  {
84  public:
85  Iterator(ObjectType* x) : o(x)
86  {
87  }
88 
89  Iterator(ObjectType& x) : o(&x)
90  {
91  }
92 
93  Iterator(const Iterator& other) : o(other.o)
94  {
95  }
96 
98  {
99  o = o->getNext();
100  return *this;
101  }
102 
103  Iterator operator++(int)
104  {
105  Iterator tmp(*this);
107  return tmp;
108  }
109 
110  bool operator==(const Iterator& rhs) const
111  {
112  return o == rhs.o;
113  }
114 
115  bool operator!=(const Iterator& rhs) const
116  {
117  return o != rhs.o;
118  }
119 
121  {
122  return *o;
123  }
124 
125  ObjectType* operator->()
126  {
127  return o;
128  }
129 
130  operator ObjectType*()
131  {
132  return o;
133  }
134 
135  private:
136  ObjectType* o;
137  };
138 
139  ObjectType* getNext() const
140  {
141  return reinterpret_cast<ObjectType*>(this->next());
142  }
143 
144  Iterator begin() const
145  {
146  return Iterator(this);
147  }
148 
149  Iterator end() const
150  {
151  return Iterator(nullptr);
152  }
153 };
154 
155 } // namespace UPnP
Message using regular HTTP header management class.
Definition: SSDP/src/include/Network/SSDP/Message.h:71
Definition: BaseObject.h:99
The String class.
Definition: WString.h:136
SerializationFormat operator++(SerializationFormat &fmt)
Definition: ArduinoJson.h:120
Defines the information used to create an outgoing message.
Definition: MessageSpec.h:74
Definition: SSDP/src/include/Network/SSDP/Message.h:31
constexpr TPoint< T > operator*(TPoint< T > pt, const Q &other)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:271
Definition: ActionRequest.h:24
std::function< void(size_t current)> Callback
Callback function type.
Definition: malloc_count.h:103
ObjectType
Definition: Libraries/jerryscript/src/include/Jerryscript/Types.h:44
SearchMatch
Determines the kind of match obtained when scanning incoming packets.
Definition: MessageSpec.h:61
Base class template for linked items with type casting.
Definition: BaseObject.h:96
Definition: Delegate.h:20
bool begin()