pick up wakaama files from https://github.com/eclipse/wakaama

Committer:
terencez
Date:
Wed Apr 19 11:27:34 2017 +0000
Revision:
0:c2dff8cbb91a
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
terencez 0:c2dff8cbb91a 1 /*******************************************************************************
terencez 0:c2dff8cbb91a 2 *
terencez 0:c2dff8cbb91a 3 * Copyright (c) 2013 Intel Corporation and others.
terencez 0:c2dff8cbb91a 4 * All rights reserved. This program and the accompanying materials
terencez 0:c2dff8cbb91a 5 * are made available under the terms of the Eclipse Public License v1.0
terencez 0:c2dff8cbb91a 6 * and Eclipse Distribution License v1.0 which accompany this distribution.
terencez 0:c2dff8cbb91a 7 *
terencez 0:c2dff8cbb91a 8 * The Eclipse Public License is available at
terencez 0:c2dff8cbb91a 9 * http://www.eclipse.org/legal/epl-v10.html
terencez 0:c2dff8cbb91a 10 * The Eclipse Distribution License is available at
terencez 0:c2dff8cbb91a 11 * http://www.eclipse.org/org/documents/edl-v10.php.
terencez 0:c2dff8cbb91a 12 *
terencez 0:c2dff8cbb91a 13 * Contributors:
terencez 0:c2dff8cbb91a 14 * David Navarro, Intel Corporation - initial API and implementation
terencez 0:c2dff8cbb91a 15 *
terencez 0:c2dff8cbb91a 16 *******************************************************************************/
terencez 0:c2dff8cbb91a 17
terencez 0:c2dff8cbb91a 18 #include "internals.h"
terencez 0:c2dff8cbb91a 19
terencez 0:c2dff8cbb91a 20
terencez 0:c2dff8cbb91a 21 lwm2m_list_t * lwm2m_list_add(lwm2m_list_t * head,
terencez 0:c2dff8cbb91a 22 lwm2m_list_t * node)
terencez 0:c2dff8cbb91a 23 {
terencez 0:c2dff8cbb91a 24 lwm2m_list_t * target;
terencez 0:c2dff8cbb91a 25
terencez 0:c2dff8cbb91a 26 if (NULL == head) return node;
terencez 0:c2dff8cbb91a 27
terencez 0:c2dff8cbb91a 28 if (head->id > node->id)
terencez 0:c2dff8cbb91a 29 {
terencez 0:c2dff8cbb91a 30 node->next = head;
terencez 0:c2dff8cbb91a 31 return node;
terencez 0:c2dff8cbb91a 32 }
terencez 0:c2dff8cbb91a 33
terencez 0:c2dff8cbb91a 34 target = head;
terencez 0:c2dff8cbb91a 35 while (NULL != target->next && target->next->id < node->id)
terencez 0:c2dff8cbb91a 36 {
terencez 0:c2dff8cbb91a 37 target = target->next;
terencez 0:c2dff8cbb91a 38 }
terencez 0:c2dff8cbb91a 39
terencez 0:c2dff8cbb91a 40 node->next = target->next;
terencez 0:c2dff8cbb91a 41 target->next = node;
terencez 0:c2dff8cbb91a 42
terencez 0:c2dff8cbb91a 43 return head;
terencez 0:c2dff8cbb91a 44 }
terencez 0:c2dff8cbb91a 45
terencez 0:c2dff8cbb91a 46
terencez 0:c2dff8cbb91a 47 lwm2m_list_t * lwm2m_list_find(lwm2m_list_t * head,
terencez 0:c2dff8cbb91a 48 uint16_t id)
terencez 0:c2dff8cbb91a 49 {
terencez 0:c2dff8cbb91a 50 while (NULL != head && head->id < id)
terencez 0:c2dff8cbb91a 51 {
terencez 0:c2dff8cbb91a 52 head = head->next;
terencez 0:c2dff8cbb91a 53 }
terencez 0:c2dff8cbb91a 54
terencez 0:c2dff8cbb91a 55 if (NULL != head && head->id == id) return head;
terencez 0:c2dff8cbb91a 56
terencez 0:c2dff8cbb91a 57 return NULL;
terencez 0:c2dff8cbb91a 58 }
terencez 0:c2dff8cbb91a 59
terencez 0:c2dff8cbb91a 60
terencez 0:c2dff8cbb91a 61 lwm2m_list_t * lwm2m_list_remove(lwm2m_list_t * head,
terencez 0:c2dff8cbb91a 62 uint16_t id,
terencez 0:c2dff8cbb91a 63 lwm2m_list_t ** nodeP)
terencez 0:c2dff8cbb91a 64 {
terencez 0:c2dff8cbb91a 65 lwm2m_list_t * target;
terencez 0:c2dff8cbb91a 66
terencez 0:c2dff8cbb91a 67 if (head == NULL)
terencez 0:c2dff8cbb91a 68 {
terencez 0:c2dff8cbb91a 69 if (nodeP) *nodeP = NULL;
terencez 0:c2dff8cbb91a 70 return NULL;
terencez 0:c2dff8cbb91a 71 }
terencez 0:c2dff8cbb91a 72
terencez 0:c2dff8cbb91a 73 if (head->id == id)
terencez 0:c2dff8cbb91a 74 {
terencez 0:c2dff8cbb91a 75 if (nodeP) *nodeP = head;
terencez 0:c2dff8cbb91a 76 return head->next;
terencez 0:c2dff8cbb91a 77 }
terencez 0:c2dff8cbb91a 78
terencez 0:c2dff8cbb91a 79 target = head;
terencez 0:c2dff8cbb91a 80 while (NULL != target->next && target->next->id < id)
terencez 0:c2dff8cbb91a 81 {
terencez 0:c2dff8cbb91a 82 target = target->next;
terencez 0:c2dff8cbb91a 83 }
terencez 0:c2dff8cbb91a 84
terencez 0:c2dff8cbb91a 85 if (NULL != target->next && target->next->id == id)
terencez 0:c2dff8cbb91a 86 {
terencez 0:c2dff8cbb91a 87 if (nodeP) *nodeP = target->next;
terencez 0:c2dff8cbb91a 88 target->next = target->next->next;
terencez 0:c2dff8cbb91a 89 }
terencez 0:c2dff8cbb91a 90 else
terencez 0:c2dff8cbb91a 91 {
terencez 0:c2dff8cbb91a 92 if (nodeP) *nodeP = NULL;
terencez 0:c2dff8cbb91a 93 }
terencez 0:c2dff8cbb91a 94
terencez 0:c2dff8cbb91a 95 return head;
terencez 0:c2dff8cbb91a 96 }
terencez 0:c2dff8cbb91a 97
terencez 0:c2dff8cbb91a 98 uint16_t lwm2m_list_newId(lwm2m_list_t * head)
terencez 0:c2dff8cbb91a 99 {
terencez 0:c2dff8cbb91a 100 uint16_t id;
terencez 0:c2dff8cbb91a 101 lwm2m_list_t * target;
terencez 0:c2dff8cbb91a 102
terencez 0:c2dff8cbb91a 103 id = 0;
terencez 0:c2dff8cbb91a 104 target = head;
terencez 0:c2dff8cbb91a 105
terencez 0:c2dff8cbb91a 106 while (target != NULL && id == target->id)
terencez 0:c2dff8cbb91a 107 {
terencez 0:c2dff8cbb91a 108 id = target->id + 1;
terencez 0:c2dff8cbb91a 109 target = target->next;
terencez 0:c2dff8cbb91a 110 }
terencez 0:c2dff8cbb91a 111
terencez 0:c2dff8cbb91a 112 return id;
terencez 0:c2dff8cbb91a 113 }
terencez 0:c2dff8cbb91a 114
terencez 0:c2dff8cbb91a 115 void lwm2m_list_free(lwm2m_list_t * head)
terencez 0:c2dff8cbb91a 116 {
terencez 0:c2dff8cbb91a 117 if (head != NULL)
terencez 0:c2dff8cbb91a 118 {
terencez 0:c2dff8cbb91a 119 lwm2m_list_t * nextP;
terencez 0:c2dff8cbb91a 120
terencez 0:c2dff8cbb91a 121 nextP = head->next;
terencez 0:c2dff8cbb91a 122 lwm2m_free(head);
terencez 0:c2dff8cbb91a 123 lwm2m_list_free(nextP);
terencez 0:c2dff8cbb91a 124 }
terencez 0:c2dff8cbb91a 125 }