Friendly LWM2M client
AudioClip.cpp
Go to the documentation of this file.
1 /*
2  * AudioClip
3  * Generated on: 2024-03-11 13:52:27
4  * Created by: Sinai RnD
5  */
6 
8 
9 #include "Resource.h"
10 #include "ItemOp.h"
11 #include "WppTypes.h"
12 #include "WppLogs.h"
13 #include "WppClient.h"
14 
15 /* --------------- Code_cpp block 0 start --------------- */
16 /* --------------- Code_cpp block 0 end --------------- */
17 
18 #define TAG "AudioClip"
19 
20 namespace wpp {
21 
22 AudioClip::AudioClip(lwm2m_context_t &context, const OBJ_LINK_T &id): Instance(context, id) {
23 
24  /* --------------- Code_cpp block 1 start --------------- */
25  /* --------------- Code_cpp block 1 end --------------- */
26 
27  resourcesCreate();
28  resourcesInit();
29 
30  /* --------------- Code_cpp block 2 start --------------- */
31  /* --------------- Code_cpp block 2 end --------------- */
32 }
33 
35  /* --------------- Code_cpp block 3 start --------------- */
36  /* --------------- Code_cpp block 3 end --------------- */
37 }
38 
40  return ctx.registry().audioClip();
41 }
42 
44  Instance *inst = ctx.registry().audioClip().instance(instId);
45  if (!inst) return NULL;
46  return static_cast<AudioClip*>(inst);
47 }
48 
50  Instance *inst = ctx.registry().audioClip().createInstance(instId);
51  if (!inst) return NULL;
52  return static_cast<AudioClip*>(inst);
53 }
54 
55 bool AudioClip::removeInst(WppClient &ctx, ID_T instId) {
56  return ctx.registry().audioClip().remove(instId);
57 }
58 
59 void AudioClip::serverOperationNotifier(Instance *securityInst, ItemOp::TYPE type, const ResLink &resLink) {
60  /* --------------- Code_cpp block 4 start --------------- */
61  /* --------------- Code_cpp block 4 end --------------- */
62 
63  operationNotify(*this, resLink, type);
64 
65  /* --------------- Code_cpp block 5 start --------------- */
66  switch (type) {
67  case ItemOp::WRITE:
68  WPP_LOGD(TAG, "Server WRITE -> resId: %d, resInstId: %d", resLink.resId, resLink.resInstId);
69  break;
70  case ItemOp::EXECUTE:
71  WPP_LOGD(TAG, "Server EXECUTE -> resId: %d, resInstId: %d", resLink.resId, resLink.resInstId);
72  break;
73  default: break;
74  }
75  /* --------------- Code_cpp block 5 end --------------- */
76 }
77 
79  if (type == ItemOp::WRITE || type == ItemOp::DELETE) notifyResChanged(resLink.resId, resLink.resInstId);
80 
81  /* --------------- Code_cpp block 6 start --------------- */
82  switch (type) {
83  case ItemOp::WRITE:
84  WPP_LOGD(TAG, "User WRITE -> resId: %d, resInstId: %d", resLink.resId, resLink.resInstId);
85  break;
86  case ItemOp::DELETE:
87  WPP_LOGD(TAG, "User DELETE -> resId: %d, resInstId: %d", resLink.resId, resLink.resInstId);
88  break;
89  default: break;
90  }
91  /* --------------- Code_cpp block 6 end --------------- */
92 }
93 
94 void AudioClip::resourcesCreate() {
95  std::vector<Resource> resources = {
97  #if RES_3339_5523
99  #endif
100  #if RES_3339_5548
102  #endif
103  #if RES_3339_5524
105  #endif
106  #if RES_3339_5750
108  #endif
109  };
110  setupResources(std::move(resources));
111 }
112 
113 void AudioClip::resourcesInit() {
114  /* --------------- Code_cpp block 7 start --------------- */
116  #if RES_3339_5523
117  resource(TRIGGER_5523)->set<EXECUTE_T>([](Instance& inst, ID_T resId, const OPAQUE_T& data) { return true; });
118  #endif
119  #if RES_3339_5548
120  resource(LEVEL_5548)->set<EXECUTE_T>([](Instance& inst, ID_T resId, const OPAQUE_T& data) { return true; });
121  #endif
122  #if RES_3339_5524
123  resource(DURATION_5524)->set<EXECUTE_T>([](Instance& inst, ID_T resId, const OPAQUE_T& data) { return true; });
124  #endif
125  #if RES_3339_5750
126  resource(APPLICATION_TYPE_5750)->set<STRING_T>("");
127  #endif
128  /* --------------- Code_cpp block 7 end --------------- */
129 }
130 
131 /* --------------- Code_cpp block 8 start --------------- */
132 /* --------------- Code_cpp block 8 end --------------- */
133 
134 } /* namespace wpp */
#define TAG
Definition: AudioClip.cpp:18
#define WPP_LOGD(TAG, FMT,...)
Definition: WppLogs.h:31
AudioClip(lwm2m_context_t &context, const OBJ_LINK_T &id)
Definition: AudioClip.cpp:22
void serverOperationNotifier(Instance *securityInst, ItemOp::TYPE type, const ResLink &resLink) override
This method must be implemented by the derived class, and handle information about resource operation...
Definition: AudioClip.cpp:59
static bool removeInst(WppClient &ctx, ID_T instId)
Removes an instance of the object.
Definition: AudioClip.cpp:55
void userOperationNotifier(ItemOp::TYPE type, const ResLink &resLink) override
This method must be implemented by the derived class, and handle information about resource operation...
Definition: AudioClip.cpp:78
static AudioClip * instance(WppClient &ctx, ID_T instId=ID_T_MAX_VAL)
Gets an instance of the object.
Definition: AudioClip.cpp:43
static Object & object(WppClient &ctx)
Gets the Object reference.
Definition: AudioClip.cpp:39
static AudioClip * createInst(WppClient &ctx, ID_T instId=ID_T_MAX_VAL)
Creates an instance of the object.
Definition: AudioClip.cpp:49
void operationNotify(Instance &inst, const ResLink &resLink, ItemOp::TYPE type)
Notifies the observers about an operation on an instance resource.
Definition: InstSubject.h:78
Instance is interface class that implements manipulation with derived class resources....
Definition: Instance.h:40
void notifyResChanged(ID_T resId, ID_T resInstId=ID_T_MAX_VAL)
Notify server about resource value change.
Definition: Instance.cpp:17
Instance(lwm2m_context_t &context, const OBJ_LINK_T &id)
Definition: Instance.h:42
The Object class implements manipulation with Instance interface class and its inheritors.
Definition: Object.h:32
void setupResources(const std::vector< Resource > &resources)
This methods setup resources list.
Resource * resource(ID_T resId)
This method return resource ptr if it exists. If resources does not exist then return NULL.
std::vector< Resource > & resources()
This method return list with all resources that has been defined.
bool set(const T &value, ID_T resInstId=SINGLE_INSTANCE_ID)
Set data value by copy for the resource (instance)
Definition: Resource.h:253
Represents a client interface for Wpp library.
Definition: WppClient.h:37
WppRegistry & registry()
Gets the WppRegistry associated with the WppClient.
Definition: WppClient.cpp:93
The WppConnection class represents a connection interface for the Wpp library.
Definition: WppClient.cpp:14
std::function< bool(Instance &, ID_T, const OPAQUE_T &)> EXECUTE_T
Definition: WppTypes.h:72
uint16_t ID_T
Definition: WppTypes.h:15
std::string STRING_T
Definition: WppTypes.h:45
std::vector< uint8_t > OPAQUE_T
Opaque - represent buffer or string as lwm2m_data_t.value.asBuffer.
Definition: WppTypes.h:49
The ItemOp struct represents the operations that can be performed on a instance/resource.
Definition: ItemOp.h:24
TYPE
Enum representing the different types of operations.
Definition: ItemOp.h:29
@ DELETE
Definition: ItemOp.h:36
@ EXECUTE
Definition: ItemOp.h:33