LOM2M  0.8.0
Notify.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013-2021 LAAS-CNRS (www.laas.fr)
3  7 Colonel Roche 31077 Toulouse - France
4 
5  The use of this source code requires an agreement with the CNRS.
6 
7  Initial Contributors:
8  David Gauchard, Guillaume Garzone, Thierry Monteil.
9 */
10 
11 #ifndef __LOM2M_NOTIFY_H
12 #define __LOM2M_NOTIFY_H
13 
14 #include "configuration.h"
15 
16 #if SUBSCRIPTION_FEAT
17 
18 #include "Entity.h"
19 #include "Enum.h"
20 #include "Arduino.h"
21 
22 struct NotificationToSend;
23 struct Notification;
24 
25 // NOTIFY BUFFER
26 //std::list<Notification> notificationBuffer;
27 //std::list<RequestPrimitive> NotifyBuffer;
28 
29 class Notifier
30 {
31 public:
32  Notifier() {};
33  ~Notifier() {};
34  static void notify(std::list<Subscription*> subs, Entity* entity, NotificationEventType net, Operation operation);
35 };
36 
38 {
39 private:
40  Notification* notif;
41  int failed;
42  String url;
43  String contentType;
45 
46 
47 public:
49  {
50  return this->nct;
51  }
53  {
54  this->nct = nct;
55  }
57  {
58  failed++;
59  }
60  const String& getContentType()
61  {
62  return this->contentType;
63  }
64  void setContentType(const String& contentType)
65  {
66  this->contentType = contentType;
67  }
68  const String& getUrl()
69  {
70  return this->url;
71  }
72  void setUrl(const String& url)
73  {
74  this->url = url;
75  }
77  {
78  return this->notif;
79  }
80  void setNotif(Notification* notif)
81  {
82  this->notif = notif;
83  }
84  int getFailed()
85  {
86  return this->failed;
87  }
88  void setFailed(int failed)
89  {
90  this->failed = failed;
91  }
92 
94  {
95  failed = 0;
96  }
97 };
98 
99 // NOTIFY RESOURCE
101 {
105  String subReference;
106  String creator;
108  // Notification Envent
109  String resource;
110  // Operation Monitor
112  String Originator;
113 
114  Notification();
115 
117  {
118  return this->net;
119  }
121  {
122  this->net = net;
123  }
124 
126  {
127  return this->verificationRequest;
128  }
129  void setVerificationRequest(bool verificationRequest)
130  {
131  this->verificationRequest = verificationRequest;
132  }
133 
135  {
136  return this->subDeletion;
137  }
138  void setSubDeletion(bool subDeletion)
139  {
140  this->subDeletion = subDeletion;
141  }
142 
144  {
145  return this->subReference;
146  }
147  void setSubReference(const String& subReference)
148  {
149  this->subReference = subReference;
150  }
151 
152  const String& getCreator()
153  {
154  return this->creator;
155  }
156  void setCreator(const String& creator)
157  {
158  this->creator = creator;
159  }
160 
162  {
163  return this->notitificationForwardingUri;
164  }
166  {
167  this->notitificationForwardingUri = notitificationForwardingUri;
168  }
169 
170  String& getResource()
171  {
172  return this->resource;
173  }
174  void setResource(String& resource)
175  {
176  this->resource = resource;
177  }
178 
180  {
181  return this->operation;
182  }
184  {
185  this->operation = operation;
186  }
187 
188  const String& getOriginator()
189  {
190  return this->Originator;
191  }
192  void setOriginator(const String& Originator)
193  {
194  this->Originator = Originator;
195  }
196 };
197 
202 {
203  std::list<NotificationToSend*> notificationBuffer;
204  static NotifyBuffer* bufferInstance;
205 public:
206  NotifyBuffer();
207  ~NotifyBuffer();
208 
209  static void addNotification(NotificationToSend* notification)
210  {
211  getInstance()->notificationBuffer.push_back(notification);
212 #if DEBUG
213  printf("DEBUG: notification added from SUB %s\n", notification->getNotif()->getSubReference().c_str());
214 #endif
215  }
216 
217  static bool isEmpty()
218  {
219  return getInstance()->notificationBuffer.empty();
220  }
221 
223  {
224  if (!getInstance()->notificationBuffer.empty())
225  {
226  NotificationToSend* result = getInstance()->notificationBuffer.front();
227  getInstance()->notificationBuffer.remove(result);
228  //getInstance()->notificationBuffer.pop_front();
229  printf("DEBUG: notification buffer size: %d\n", getInstance()->notificationBuffer.size());
230  return result;
231  }
232 #if DEBUG
233  printf("DEBUG: nothing to pop\n");
234 #endif
235  return nullptr;
236  }
237 
238  static void removeNotification()
239  {
240  getInstance()->notificationBuffer.pop_front();
241  }
242 
243  static NotifyBuffer* getInstance() noexcept
244  {
245  if (!bufferInstance)
246  {
247  bufferInstance = new NotifyBuffer();
248  }
249  return bufferInstance;
250  }
251 };
252 
253 #endif // SUBSCRIPTION_FEAT
254 #endif // __LOM2M_NOTIFY_H
NotificationEventType
Definition: Enum.h:18
Operation
Definition: Enum.h:43
NotificationContentType
Definition: Enum.h:31
NotificationToSend * notif
Definition: Notify.cpp:97
const char * contentType(const String &filename)
Definition: bsp-esp8266.cpp:13
Definition: Notify.h:30
Notifier()
Definition: Notify.h:32
static void notify(std::list< Subscription * > subs, Entity *entity, NotificationEventType net, Operation operation)
Definition: Notify.cpp:51
~Notifier()
Definition: Notify.h:33
Definition: Notify.h:202
static void addNotification(NotificationToSend *notification)
Definition: Notify.h:209
NotifyBuffer()
Definition: Notify.cpp:31
static NotifyBuffer * getInstance() noexcept
Definition: Notify.h:243
~NotifyBuffer()
Definition: Notify.cpp:36
static void removeNotification()
Definition: Notify.h:238
static bool isEmpty()
Definition: Notify.h:217
static NotificationToSend * popNotification()
Definition: Notify.h:222
Definition: Entity.h:235
Definition: Notify.h:101
bool verificationRequest
Definition: Notify.h:103
void setNet(NotificationEventType &net)
Definition: Notify.h:120
void setOriginator(const String &Originator)
Definition: Notify.h:192
Notification()
Definition: Notify.cpp:24
bool getSubDeletion()
Definition: Notify.h:134
const String & getCreator()
Definition: Notify.h:152
void setSubReference(const String &subReference)
Definition: Notify.h:147
void setResource(String &resource)
Definition: Notify.h:174
String resource
Definition: Notify.h:109
bool subDeletion
Definition: Notify.h:104
void setOperation(Operation &operation)
Definition: Notify.h:183
Operation operation
Definition: Notify.h:111
void setNotitificationForwardingUri(const String &notitificationForwardingUri)
Definition: Notify.h:165
Operation & getOperation()
Definition: Notify.h:179
bool getVerificationRequest()
Definition: Notify.h:125
String creator
Definition: Notify.h:106
String Originator
Definition: Notify.h:112
const String & getNotitificationForwardingUri()
Definition: Notify.h:161
String & getResource()
Definition: Notify.h:170
String getSubReference()
Definition: Notify.h:143
void setSubDeletion(bool subDeletion)
Definition: Notify.h:138
String notitificationForwardingUri
Definition: Notify.h:107
void setCreator(const String &creator)
Definition: Notify.h:156
NotificationEventType net
Definition: Notify.h:102
String subReference
Definition: Notify.h:105
const String & getOriginator()
Definition: Notify.h:188
NotificationEventType & getNet()
Definition: Notify.h:116
void setVerificationRequest(bool verificationRequest)
Definition: Notify.h:129
Definition: Notify.h:38
const String & getUrl()
Definition: Notify.h:68
void setFailed(int failed)
Definition: Notify.h:88
NotificationContentType getNct()
Definition: Notify.h:48
Notification * getNotif()
Definition: Notify.h:76
void setUrl(const String &url)
Definition: Notify.h:72
void setNct(NotificationContentType nct)
Definition: Notify.h:52
void increaseFailed()
Definition: Notify.h:56
int getFailed()
Definition: Notify.h:84
void setNotif(Notification *notif)
Definition: Notify.h:80
NotificationToSend()
Definition: Notify.h:93
const String & getContentType()
Definition: Notify.h:60
void setContentType(const String &contentType)
Definition: Notify.h:64