Friendly LWM2M client
ObjSubject.h
Go to the documentation of this file.
1 #ifndef WPP_OBJ_SUBJECT_H_
2 #define WPP_OBJ_SUBJECT_H_
3 
4 #include "ItemOp.h"
5 #include "ObjOpObserver.h"
6 
7 namespace wpp {
8 
9 class Object;
10 
21 class ObjSubject {
22 public:
28  void opSubscribe(ObjOpObserver *observer) {
29  if (!observer) return;
30  if (std::find(_opObservers.begin(), _opObservers.end(), observer) == _opObservers.end())
31  _opObservers.push_back(observer);
32  }
33 
39  void opUnsubscribe(ObjOpObserver *observer) {
40  _opObservers.erase(std::find(_opObservers.begin(), _opObservers.end(), observer));
41  }
42 
43 protected:
53  void operationNotify(Object &obj, ID_T instanceId, ItemOp::TYPE type) {
54  for(ObjOpObserver* observer : _opObservers) {
55  if (type == ItemOp::CREATE) {
56  observer->instanceCreated(obj, instanceId);
57  } else if (type == ItemOp::DELETE) {
58  observer->instanceDeleting(obj, instanceId);
59  }
60  }
61  }
62 
63 private:
64  std::vector<ObjOpObserver *> _opObservers;
65 };
66 
67 }
68 
69 #endif //WPP_OBJ_SUBJECT_H_
The ObjOpObserver class is an abstract base class that defines the interface for observing object ope...
Definition: ObjOpObserver.h:17
The ObjSubject class represents a subject that notifies observers about object operations and actions...
Definition: ObjSubject.h:21
void opUnsubscribe(ObjOpObserver *observer)
Unsubscribes an observer from receiving notifications about object operations.
Definition: ObjSubject.h:39
void opSubscribe(ObjOpObserver *observer)
Subscribes an observer to receive notifications about object operations.
Definition: ObjSubject.h:28
void operationNotify(Object &obj, ID_T instanceId, ItemOp::TYPE type)
Notifies observers about object operations.
Definition: ObjSubject.h:53
The Object class implements manipulation with Instance interface class and its inheritors.
Definition: Object.h:32
The WppConnection class represents a connection interface for the Wpp library.
Definition: WppClient.cpp:14
uint16_t ID_T
Definition: WppTypes.h:15
TYPE
Enum representing the different types of operations.
Definition: ItemOp.h:29
@ DELETE
Definition: ItemOp.h:36
@ CREATE
Definition: ItemOp.h:35