-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathcommon.h
515 lines (484 loc) · 21.3 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
/*
* Copyright (C) 2021 HAW Hamburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup pkg_wakaama
* @defgroup lwm2m_objects_common Common LwM2M Object functionalities
* @brief Common functionalities to interact with LwM2M objects
* @{
*
* @file
*
* @author Leandro Lanzieri <[email protected]>
*/
#ifndef OBJECTS_COMMON_H
#define OBJECTS_COMMON_H
#ifdef __cplusplus
extern "C" {
#endif
#include "liblwm2m.h"
#include "lwm2m_client.h"
/**
* @brief Get the handle for an object type of the client by its ID.
*
* @note This is not a single instance of a given object, but the object type
* representation.
*
* @param[in] client_data Pointer to the client data
* @param[in] id ID of the object to get
*
* @return Pointer to the object type
*/
static inline lwm2m_object_t *lwm2m_get_object_by_id(lwm2m_client_data_t *client_data, uint16_t id)
{
return (lwm2m_object_t *)LWM2M_LIST_FIND(client_data->lwm2m_ctx->objectList, id);
}
/**
* @brief Get the value of a string-type resource, specified by @p uri.
*
* @pre `(client_data != NULL) && (uri != NULL) && (out != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] uri Initialized URI structure specifying the resource to get.
* @param[out] out Buffer to place the resource in. Must not be NULL.
* @param[in, out] out_len Available space in @p out, returns the amount of read bytes.
*
* @retval 0 on success
* @retval -ENOMEM when there is not enough space in buffer or can not allocate a data structure
* @retval -ENOENT when the resource is not found
* @retval -EINVAL when the resource cannot be read or has an unexpected type
*/
int lwm2m_get_string(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri, char *out,
size_t *out_len);
/**
* @brief Get the value of a string-type resource, specified by a path @p path.
*
* Convenience function to call @ref lwm2m_get_string with a string representing the resource's
* path.
*
* @pre `(client_data != NULL) && (path != NULL) && (out != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] path Array containing the path to the resource to get.
* @param[in] path_len Length of @p path.
* @param[out] out Buffer to place the resource in. Must not be NULL.
* @param[in, out] out_len Available space in @p out, returns the amount of read bytes.
*
* @retval 0 on success
* @retval -ENOMEM when there is not enough space in buffer or can not allocate a data structure
* @retval -ENOENT when the resource is not found
* @retval -EINVAL if the path is malformed, the resource cannot be read or has an unexpected type
*/
int lwm2m_get_string_by_path(lwm2m_client_data_t *client_data, const char *path, size_t path_len,
char *out, size_t *out_len);
/**
* @brief Get the value of an opaque-type resource, specified by @p uri.
*
* @pre `(client_data != NULL) && (uri != NULL) && (out != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] uri Initialized URI structure specifying the resource to get.
* @param[out] out Buffer to place the resource in. Must not be NULL.
* @param[in, out] out_len Available space in @p out, returns the amount of read bytes.
*
* @retval 0 on success
* @retval -ENOMEM when there is not enough space in buffer or can not allocate a data structure
* @retval -ENOENT when the resource is not found
* @retval -EINVAL when the resource cannot be read or has an unexpected type
*/
int lwm2m_get_opaque(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri, uint8_t *out,
size_t *out_len);
/**
* @brief Get the value of an opaque-type resource, specified by a path @p path.
*
* Convenience function to call @ref lwm2m_get_opaque with a string representing the resource's
* path.
*
* @pre `(client_data != NULL) && (path != NULL) && (out != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] path Array containing the path to the resource to get.
* @param[in] path_len Length of @p path.
* @param[out] out Buffer to place the resource in. Must not be NULL.
* @param[in, out] out_len Available space in @p out, returns the amount of read bytes.
*
* @retval 0 on success
* @retval -ENOMEM when there is not enough space in buffer or can not allocate a data structure
* @retval -ENOENT when the resource is not found
* @retval -EINVAL if the path is malformed, the resource cannot be read or has an unexpected type
*/
int lwm2m_get_opaque_by_path(lwm2m_client_data_t *client_data, const char *path, size_t path_len,
uint8_t *out, size_t *out_len);
/**
* @brief Get the value of an integer-type resource, specified by @p uri.
*
* @pre `(client_data != NULL) && (uri != NULL) && (out != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] uri Initialized URI structure specifying the resource to get.
* @param[out] out Pointer where to place the value.
*
* @retval 0 on success
* @retval -ENOMEM when there is not enough space in buffer or can not allocate a data structure
* @retval -ENOENT when the resource is not found
* @retval -EINVAL when the resource cannot be read or has an unexpected type
*/
int lwm2m_get_int(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri, int64_t *out);
/**
* @brief Get the value of an integer-type resource, specified by a path @p path.
*
* Convenience function to call @ref lwm2m_get_int with a string representing the resource's
* path.
*
* @pre `(client_data != NULL) && (path != NULL) && (out != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] path Array containing the path to the resource to get.
* @param[in] path_len Length of @p path.
* @param[out] out Pointer where to place the value.
*
* @retval 0 on success
* @retval -ENOMEM when there is not enough space in buffer or can not allocate a data structure
* @retval -ENOENT when the resource is not found
* @retval -EINVAL if the path is malformed, the resource cannot be read or has an unexpected type
*/
int lwm2m_get_int_by_path(lwm2m_client_data_t *client_data, const char *path, size_t path_len,
int64_t *out);
/**
* @brief Get the value of an float-type resource, specified by @p uri.
*
* @pre `(client_data != NULL) && (uri != NULL) && (out != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] uri Initialized URI structure specifying the resource to get.
* @param[out] out Pointer where to place the value.
*
* @retval 0 on success
* @retval -ENOMEM when there is not enough space in buffer or can not allocate a data structure
* @retval -ENOENT when the resource is not found
* @retval -EINVAL when the resource cannot be read or has an unexpected type
*/
int lwm2m_get_float(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri, double *out);
/**
* @brief Get the value of an float-type resource, specified by a path @p path.
*
* Convenience function to call @ref lwm2m_get_float with a string representing the resource's
* path.
*
* @pre `(client_data != NULL) && (path != NULL) && (out != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] path Array containing the path to the resource to get.
* @param[in] path_len Length of @p path.
* @param[out] out Pointer where to place the value.
*
* @retval 0 on success
* @retval -ENOMEM when there is not enough space in buffer or can not allocate a data structure
* @retval -ENOENT when the resource is not found
* @retval -EINVAL if the path is malformed, the resource cannot be read or has an unexpected type
*/
int lwm2m_get_float_by_path(lwm2m_client_data_t *client_data, const char *path, size_t path_len,
double *out);
/**
* @brief Get the value of an boolean-type resource, specified by @p uri.
*
* @pre `(client_data != NULL) && (uri != NULL) && (out != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] uri Initialized URI structure specifying the resource to get.
* @param[out] out Pointer where to place the value.
*
* @retval 0 on success
* @retval -ENOMEM when there is not enough space in buffer or can not allocate a data structure
* @retval -ENOENT when the resource is not found
* @retval -EINVAL when the resource cannot be read or has an unexpected type
*/
int lwm2m_get_bool(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri, bool *out);
/**
* @brief Get the value of an float-type resource, specified by a path @p path.
*
* Convenience function to call @ref lwm2m_get_bool with a string representing the resource's
* path.
*
* @pre `(client_data != NULL) && (path != NULL) && (out != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] path Array containing the path to the resource to get.
* @param[in] path_len Length of @p path.
* @param[out] out Pointer where to place the value.
*
* @retval 0 on success
* @retval -ENOMEM when there is not enough space in buffer or can not allocate a data structure
* @retval -ENOENT when the resource is not found
* @retval -EINVAL if the path is malformed, the resource cannot be read or has an unexpected type
*/
int lwm2m_get_bool_by_path(lwm2m_client_data_t *client_data, const char *path, size_t path_len,
bool *out);
/**
* @brief Get the value of an objectlink-type resource, specified by @p uri.
*
* @pre `(client_data != NULL) && (uri != NULL) && (object_id_out != NULL) &&
* (instance_id_out != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] uri Initialized URI structure specifying the resource to get.
* @param[out] object_id_out Pointer where to place the object ID.
* @param[out] instance_id_out Pointer where to place the instance ID.
*
* @retval 0 on success
* @retval -ENOMEM when there is not enough space in buffer or can not allocate a data structure
* @retval -ENOENT when the resource is not found
* @retval -EINVAL when the resource cannot be read or has an unexpected type
*/
int lwm2m_get_objlink(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri,
uint16_t *object_id_out, uint16_t *instance_id_out);
/**
* @brief Get the value of an objectlink-type resource, specified by a path @p path.
*
* Convenience function to call @ref lwm2m_get_objlink with a string representing the resource's
* path.
*
* @pre `(client_data != NULL) && (path != NULL) && (object_id_out != NULL) &&
* (instance_id_out != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] path Array containing the path to the resource to get.
* @param[in] path_len Length of @p path.
* @param[out] object_id_out Pointer where to place the object ID.
* @param[out] instance_id_out Pointer where to place the instance ID.
*
* @retval 0 on success
* @retval -ENOMEM when there is not enough space in buffer or can not allocate a data structure
* @retval -ENOENT when the resource is not found
* @retval -EINVAL if the path is malformed, the resource cannot be read or has an unexpected type
*/
int lwm2m_get_objlink_by_path(lwm2m_client_data_t *client_data, const char *path, size_t path_len,
uint16_t *object_id_out, uint16_t *instance_id_out);
/**
* @brief Set the value of a string-type resource, specified by @p uri.
*
* @pre `(client_data != NULL) && (uri != NULL) && (val != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] uri Initialized URI structure specifying the resource to set.
* @param[in] val Buffer with the value to set. Must not be NULL.
* @param[in] val_len Length of @p val.
*
* @retval 0 on success
* @retval -ENOMEM when data structure can not be allocated
* @retval -ENOENT when the resource is not found
* @retval -EINVAL when the value can not be set
*/
int lwm2m_set_string(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri, char *val,
size_t val_len);
/**
* @brief Set the value of a string-type resource, specified by a path @p path.
*
* Convenience function to call @ref lwm2m_set_string with a string representing the resource's
* path.
*
* @pre `(client_data != NULL) && (path != NULL) && (val != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] path Array containing the path to the resource to set.
* @param[in] path_len Length of @p path.
* @param[in] val Buffer with the value to set. Must not be NULL.
* @param[in] val_len Length of @p val.
*
* @retval 0 on success
* @retval -EINVAL when the path is malformed, the value can not be set
* @retval -ENOENT when the resource is not found
* @retval -ENOMEM when data structure can not be allocated
*/
int lwm2m_set_string_by_path(lwm2m_client_data_t *client_data, const char *path, size_t path_len,
char *val, size_t val_len);
/**
* @brief Set the value of an opaque-type resource, specified by @p uri.
*
* @pre `(client_data != NULL) && (uri != NULL) && (val != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] uri Initialized URI structure specifying the resource to set.
* @param[in] val Buffer with the value to set. Must not be NULL.
* @param[in] val_len Length of @p val.
*
* @retval 0 on success
* @retval -ENOMEM when data structure can not be allocated
* @retval -ENOENT when the resource is not found
* @retval -EINVAL when the value can not be set
*/
int lwm2m_set_opaque(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri, uint8_t *val,
size_t val_len);
/**
* @brief Set the value of an opaque-type resource, specified by a path @p path.
*
* Convenience function to call @ref lwm2m_set_opaque with a string representing the resource's
* path.
*
* @pre `(client_data != NULL) && (path != NULL) && (val != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] path Array containing the path to the resource to set.
* @param[in] path_len Length of @p path.
* @param[in] val Buffer with the value to set. Must not be NULL.
* @param[in] val_len Length of @p val.
*
* @retval 0 on success
* @retval -EINVAL when the path is malformed, the value can not be set
* @retval -ENOENT when the resource is not found
* @retval -ENOMEM when data structure can not be allocated
*/
int lwm2m_set_opaque_by_path(lwm2m_client_data_t *client_data, const char *path, size_t path_len,
uint8_t *val, size_t val_len);
/**
* @brief Set the value of an integer-type resource, specified by @p uri.
*
* @pre `(client_data != NULL) && (uri != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] uri Initialized URI structure specifying the resource to set.
* @param[in] val Value to set.
*
* @retval 0 on success
* @retval -ENOMEM when data structure can not be allocated
* @retval -ENOENT when the resource is not found
* @retval -EINVAL when the value can not be set
*/
int lwm2m_set_int(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri, int64_t val);
/**
* @brief Set the value of an integer-type resource, specified by a path @p path.
*
* Convenience function to call @ref lwm2m_set_int with a string representing the resource's
* path.
*
* @pre `(client_data != NULL) && (path != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] path Array containing the path to the resource to set.
* @param[in] path_len Length of @p path.
* @param[in] val Value to set.
*
* @retval 0 on success
* @retval -EINVAL when the path is malformed, the value can not be set
* @retval -ENOENT when the resource is not found
* @retval -ENOMEM when data structure can not be allocated
*/
int lwm2m_set_int_by_path(lwm2m_client_data_t *client_data, const char *path, size_t path_len,
int64_t val);
/**
* @brief Set the value of an float-type resource, specified by @p uri.
*
* @pre `(client_data != NULL) && (uri != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] uri Initialized URI structure specifying the resource to set.
* @param[in] val Value to set.
*
* @retval 0 on success
* @retval -ENOMEM when data structure can not be allocated
* @retval -ENOENT when the resource is not found
* @retval -EINVAL when the value can not be set
*/
int lwm2m_set_float(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri, double val);
/**
* @brief Set the value of an float-type resource, specified by a path @p path.
*
* Convenience function to call @ref lwm2m_set_float with a string representing the resource's
* path.
*
* @pre `(client_data != NULL) && (path != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] path Array containing the path to the resource to set.
* @param[in] path_len Length of @p path.
* @param[in] val Value to set.
*
* @retval 0 on success
* @retval -EINVAL when the path is malformed, the value can not be set
* @retval -ENOENT when the resource is not found
* @retval -ENOMEM when data structure can not be allocated
*/
int lwm2m_set_float_by_path(lwm2m_client_data_t *client_data, const char *path, size_t path_len,
double val);
/**
* @brief Set the value of an boolean-type resource, specified by @p uri.
*
* @pre `(client_data != NULL) && (uri != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] uri Initialized URI structure specifying the resource to set.
* @param[in] val Value to set.
*
* @retval 0 on success
* @retval -ENOMEM when data structure can not be allocated
* @retval -ENOENT when the resource is not found
* @retval -EINVAL when the value can not be set
*/
int lwm2m_set_bool(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri, bool val);
/**
* @brief Set the value of an float-type resource, specified by a path @p path.
*
* Convenience function to call @ref lwm2m_set_bool with a string representing the resource's
* path.
*
* @pre `(client_data != NULL) && (path != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] path Array containing the path to the resource to set.
* @param[in] path_len Length of @p path.
* @param[in] val Value to set.
*
* @retval 0 on success
* @retval -EINVAL when the path is malformed, the value can not be set
* @retval -ENOENT when the resource is not found
* @retval -ENOMEM when data structure can not be allocated
*/
int lwm2m_set_bool_by_path(lwm2m_client_data_t *client_data, const char *path, size_t path_len,
bool val);
/**
* @brief Set the value of an objectlink-type resource, specified by @p uri.
*
* @pre `(client_data != NULL) && (uri != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] uri Initialized URI structure specifying the resource to set.
* @param[in] object_id_in Object ID value to set.
* @param[in] instance_id_in Instance ID value to set.
*
* @retval 0 on success
* @retval -ENOMEM when data structure can not be allocated
* @retval -ENOENT when the resource is not found
* @retval -EINVAL when the value can not be set
*/
int lwm2m_set_objlink(lwm2m_client_data_t *client_data, const lwm2m_uri_t *uri,
uint16_t object_id_in, uint16_t instance_id_in);
/**
* @brief Set the value of an objectlink-type resource, specified by a path @p path.
*
* Convenience function to call @ref lwm2m_set_objlink with a string representing the resource's
* path.
*
* @pre `(client_data != NULL) && (path != NULL)`
*
* @param[in] client_data Pointer to the LwM2M client data.
* @param[in] path Array containing the path to the resource to set.
* @param[in] path_len Length of @p path.
* @param[in] object_id_in Object ID value to set.
* @param[in] instance_id_in Instance ID value to set.
*
* @retval 0 on success
* @retval -EINVAL when the path is malformed, the value can not be set
* @retval -ENOENT when the resource is not found
* @retval -ENOMEM when data structure can not be allocated
*/
int lwm2m_set_objlink_by_path(lwm2m_client_data_t *client_data, const char *path, size_t path_len,
uint16_t object_id_in, uint16_t instance_id_in);
#ifdef __cplusplus
}
#endif
#endif /* OBJECTS_COMMON_H */
/** @} */