46#if LWM2M_QUEUE_MODE_ENABLED
60#define LOG_MODULE "lwm2m-notification-queue"
61#define LOG_LEVEL LOG_LEVEL_LWM2M
63#ifdef LWM2M_NOTIFICATION_QUEUE_CONF_LENGTH
64#define LWM2M_NOTIFICATION_QUEUE_LENGTH LWM2M_NOTIFICATION_QUEUE_CONF_LENGTH
66#define LWM2M_NOTIFICATION_QUEUE_LENGTH COAP_MAX_OBSERVERS
71MEMB(notification_memb, notification_path_t, LWM2M_NOTIFICATION_QUEUE_LENGTH);
72LIST(notification_paths_queue);
75lwm2m_notification_queue_init(
void)
81extend_path(notification_path_t *path_object,
char *path,
int path_size)
83 switch(path_object->level) {
85 snprintf(path, path_size,
"%u", path_object->reduced_path[0]);
88 snprintf(path, path_size,
"%u/%u", path_object->reduced_path[0], path_object->reduced_path[1]);
91 snprintf(path, path_size,
"%u/%u/%u", path_object->reduced_path[0], path_object->reduced_path[1], path_object->reduced_path[2]);
97is_notification_path_present(uint16_t object_id, uint16_t instance_id, uint16_t resource_id)
99 notification_path_t *iteration_path = (notification_path_t *)
list_head(notification_paths_queue);
100 while(iteration_path != NULL) {
101 if(iteration_path->reduced_path[0] == object_id && iteration_path->reduced_path[1] == instance_id
102 && iteration_path->reduced_path[2] == resource_id) {
105 iteration_path = iteration_path->next;
111remove_notification_path(notification_path_t *path)
118lwm2m_notification_queue_add_notification_path(uint16_t object_id, uint16_t instance_id, uint16_t resource_id)
120 if(is_notification_path_present(object_id, instance_id, resource_id)) {
121 LOG_DBG(
"Notification path already present, not queueing it\n");
124 notification_path_t *path_object =
memb_alloc(¬ification_memb);
125 if(path_object == NULL) {
126 LOG_DBG(
"Queue is full, could not allocate new notification\n");
129 path_object->reduced_path[0] = object_id;
130 path_object->reduced_path[1] = instance_id;
131 path_object->reduced_path[2] = resource_id;
132 path_object->level = 3;
133 list_add(notification_paths_queue, path_object);
134 LOG_DBG(
"Notification path added to the list: %u/%u/%u\n", object_id, instance_id, resource_id);
138lwm2m_notification_queue_send_notifications()
141 notification_path_t *iteration_path = (notification_path_t *)
list_head(notification_paths_queue);
142 notification_path_t *aux = iteration_path;
144 while(iteration_path != NULL) {
145 extend_path(iteration_path, path,
sizeof(path));
146#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION
147 if(lwm2m_queue_mode_get_dynamic_adaptation_flag()) {
148 lwm2m_queue_mode_set_handler_from_notification();
151 LOG_DBG(
"Sending stored notification with path: %s\n", path);
152 coap_notify_observers_sub(NULL, path);
153 aux = iteration_path;
154 iteration_path = iteration_path->next;
155 remove_notification_path(aux);
CoAP engine implementation.
static void list_init(list_t list)
Initialize a list.
#define LIST(name)
Declare a linked list.
void list_add(list_t list, void *item)
Add an item at the end of a list.
void list_remove(list_t list, const void *item)
Remove a specific element from a list.
static void * list_head(const_list_t list)
Get a pointer to the first element of a list.
int memb_free(struct memb *m, void *ptr)
Deallocate a memory block from a memory block previously declared with MEMB().
void * memb_alloc(struct memb *m)
Allocate a memory block from a block of memory declared with MEMB().
#define MEMB(name, structure, num)
Declare a memory block.
Linked list manipulation routines.
Header file for the Contiki OMA LWM2M engine.
Header file for functions to manage the queue to store notifications when waiting for the response to...
Header file for the Contiki OMA LWM2M Queue Mode implementation to manage the parameters.
Memory block allocation routines.