A modelling and serializer library for Microsoft Azure IoTHub client applications
Dependents: sht15_remote_monitoring f767zi_mqtt remote_monitoring simplesample_amqp ... more
This library implements a serializer library to be used in projects involving Microsoft Azure IoT Hub connectivity. The code is replicated from https://github.com/Azure/azure-iot-sdks
multitree.c@10:c2aee3965a83, 2016-04-08 (annotated)
- Committer:
- Azure.IoT Build
- Date:
- Fri Apr 08 13:25:09 2016 -0700
- Revision:
- 10:c2aee3965a83
- Parent:
- 0:1f9b2707ec7d
- Child:
- 11:b1327861f5e0
1.0.4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AzureIoTClient | 0:1f9b2707ec7d | 1 | // Copyright (c) Microsoft. All rights reserved. |
AzureIoTClient | 0:1f9b2707ec7d | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
AzureIoTClient | 0:1f9b2707ec7d | 3 | |
AzureIoTClient | 0:1f9b2707ec7d | 4 | #include <stdlib.h> |
AzureIoTClient | 0:1f9b2707ec7d | 5 | #ifdef _CRTDBG_MAP_ALLOC |
AzureIoTClient | 0:1f9b2707ec7d | 6 | #include <crtdbg.h> |
AzureIoTClient | 0:1f9b2707ec7d | 7 | #endif |
Azure.IoT Build | 10:c2aee3965a83 | 8 | #include "azure_c_shared_utility/gballoc.h" |
AzureIoTClient | 0:1f9b2707ec7d | 9 | |
AzureIoTClient | 0:1f9b2707ec7d | 10 | #include "multitree.h" |
AzureIoTClient | 0:1f9b2707ec7d | 11 | #include <string.h> |
Azure.IoT Build | 10:c2aee3965a83 | 12 | #include "azure_c_shared_utility/crt_abstractions.h" |
Azure.IoT Build | 10:c2aee3965a83 | 13 | #include "azure_c_shared_utility/iot_logging.h" |
AzureIoTClient | 0:1f9b2707ec7d | 14 | |
AzureIoTClient | 0:1f9b2707ec7d | 15 | /*assume a name cannot be longer than 100 characters*/ |
AzureIoTClient | 0:1f9b2707ec7d | 16 | #define INNER_NODE_NAME_SIZE 128 |
AzureIoTClient | 0:1f9b2707ec7d | 17 | |
AzureIoTClient | 0:1f9b2707ec7d | 18 | DEFINE_ENUM_STRINGS(MULTITREE_RESULT, MULTITREE_RESULT_VALUES); |
AzureIoTClient | 0:1f9b2707ec7d | 19 | |
AzureIoTClient | 0:1f9b2707ec7d | 20 | typedef struct MULTITREE_NODE_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 21 | { |
AzureIoTClient | 0:1f9b2707ec7d | 22 | char* name; |
AzureIoTClient | 0:1f9b2707ec7d | 23 | void* value; |
AzureIoTClient | 0:1f9b2707ec7d | 24 | MULTITREE_CLONE_FUNCTION cloneFunction; |
AzureIoTClient | 0:1f9b2707ec7d | 25 | MULTITREE_FREE_FUNCTION freeFunction; |
AzureIoTClient | 0:1f9b2707ec7d | 26 | size_t nChildren; |
AzureIoTClient | 0:1f9b2707ec7d | 27 | struct MULTITREE_NODE_TAG** children; /*an array of nChildren count of MULTITREE_NODE* */ |
AzureIoTClient | 0:1f9b2707ec7d | 28 | }MULTITREE_NODE; |
AzureIoTClient | 0:1f9b2707ec7d | 29 | |
AzureIoTClient | 0:1f9b2707ec7d | 30 | |
AzureIoTClient | 0:1f9b2707ec7d | 31 | MULTITREE_HANDLE MultiTree_Create(MULTITREE_CLONE_FUNCTION cloneFunction, MULTITREE_FREE_FUNCTION freeFunction) |
AzureIoTClient | 0:1f9b2707ec7d | 32 | { |
AzureIoTClient | 0:1f9b2707ec7d | 33 | MULTITREE_NODE* result; |
AzureIoTClient | 0:1f9b2707ec7d | 34 | |
AzureIoTClient | 0:1f9b2707ec7d | 35 | /* Codes_SRS_MULTITREE_99_052:[If any of the arguments passed to MultiTree_Create is NULL, the call shall return NULL.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 36 | if ((cloneFunction == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 37 | (freeFunction == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 38 | { |
AzureIoTClient | 0:1f9b2707ec7d | 39 | LogError("CloneFunction or FreeFunction is Null.\r\n"); |
AzureIoTClient | 0:1f9b2707ec7d | 40 | result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 41 | } |
AzureIoTClient | 0:1f9b2707ec7d | 42 | else |
AzureIoTClient | 0:1f9b2707ec7d | 43 | { |
AzureIoTClient | 0:1f9b2707ec7d | 44 | /*Codes_SRS_MULTITREE_99_005:[ MultiTree_Create creates a new tree.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 45 | /*Codes_SRS_MULTITREE_99_006:[MultiTree_Create returns a non - NULL pointer if the tree has been successfully created.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 46 | /*Codes_SRS_MULTITREE_99_007:[MultiTree_Create returns NULL if the tree has not been successfully created.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 47 | result = (MULTITREE_NODE*)malloc(sizeof(MULTITREE_NODE)); |
AzureIoTClient | 0:1f9b2707ec7d | 48 | if (result != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 49 | { |
AzureIoTClient | 0:1f9b2707ec7d | 50 | result->name = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 51 | result->value = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 52 | result->cloneFunction = cloneFunction; |
AzureIoTClient | 0:1f9b2707ec7d | 53 | result->freeFunction = freeFunction; |
AzureIoTClient | 0:1f9b2707ec7d | 54 | result->value = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 55 | result->nChildren = 0; |
AzureIoTClient | 0:1f9b2707ec7d | 56 | result->children = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 57 | } |
AzureIoTClient | 0:1f9b2707ec7d | 58 | else |
AzureIoTClient | 0:1f9b2707ec7d | 59 | { |
AzureIoTClient | 0:1f9b2707ec7d | 60 | LogError("MultiTree_Create failed because malloc failed\r\n"); |
AzureIoTClient | 0:1f9b2707ec7d | 61 | } |
AzureIoTClient | 0:1f9b2707ec7d | 62 | } |
AzureIoTClient | 0:1f9b2707ec7d | 63 | |
AzureIoTClient | 0:1f9b2707ec7d | 64 | return (MULTITREE_HANDLE)result; |
AzureIoTClient | 0:1f9b2707ec7d | 65 | } |
AzureIoTClient | 0:1f9b2707ec7d | 66 | |
AzureIoTClient | 0:1f9b2707ec7d | 67 | |
AzureIoTClient | 0:1f9b2707ec7d | 68 | /*return NULL if a child with the name "name" doesn't exists*/ |
AzureIoTClient | 0:1f9b2707ec7d | 69 | /*returns a pointer to the existing child (if any)*/ |
AzureIoTClient | 0:1f9b2707ec7d | 70 | static MULTITREE_NODE* getChildByName(MULTITREE_NODE* node, const char* name) |
AzureIoTClient | 0:1f9b2707ec7d | 71 | { |
AzureIoTClient | 0:1f9b2707ec7d | 72 | MULTITREE_NODE* result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 73 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 74 | for (i = 0; i < node->nChildren; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 75 | { |
AzureIoTClient | 0:1f9b2707ec7d | 76 | if (strcmp(node->children[i]->name, name) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 77 | { |
AzureIoTClient | 0:1f9b2707ec7d | 78 | result = node->children[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 79 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 80 | } |
AzureIoTClient | 0:1f9b2707ec7d | 81 | } |
AzureIoTClient | 0:1f9b2707ec7d | 82 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 83 | } |
AzureIoTClient | 0:1f9b2707ec7d | 84 | |
AzureIoTClient | 0:1f9b2707ec7d | 85 | /*helper function to create a child immediately under this node*/ |
AzureIoTClient | 0:1f9b2707ec7d | 86 | /*return 0 if it created it, any other number is error*/ |
AzureIoTClient | 0:1f9b2707ec7d | 87 | |
AzureIoTClient | 0:1f9b2707ec7d | 88 | typedef enum CREATELEAF_RESULT_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 89 | { |
AzureIoTClient | 0:1f9b2707ec7d | 90 | CREATELEAF_OK, |
AzureIoTClient | 0:1f9b2707ec7d | 91 | CREATELEAF_ALREADY_EXISTS, |
AzureIoTClient | 0:1f9b2707ec7d | 92 | CREATELEAF_EMPTY_NAME, |
AzureIoTClient | 0:1f9b2707ec7d | 93 | CREATELEAF_ERROR, |
AzureIoTClient | 0:1f9b2707ec7d | 94 | CREATELEAF_RESULT_COUNT // Used to track the number of elements in the enum |
AzureIoTClient | 0:1f9b2707ec7d | 95 | // Do not remove, or add new enum values below this one |
AzureIoTClient | 0:1f9b2707ec7d | 96 | }CREATELEAF_RESULT; |
AzureIoTClient | 0:1f9b2707ec7d | 97 | |
AzureIoTClient | 0:1f9b2707ec7d | 98 | static const char* CreateLeaf_ResultAsString[CREATELEAF_RESULT_COUNT] = |
AzureIoTClient | 0:1f9b2707ec7d | 99 | { |
AzureIoTClient | 0:1f9b2707ec7d | 100 | STRINGIFY(CREATELEAF_OK), |
AzureIoTClient | 0:1f9b2707ec7d | 101 | STRINGIFY(CREATELEAF_ALREADY_EXISTS), |
AzureIoTClient | 0:1f9b2707ec7d | 102 | STRINGIFY(CREATELEAF_EMPTY_NAME), |
AzureIoTClient | 0:1f9b2707ec7d | 103 | STRINGIFY(CREATELEAF_ERROR) |
AzureIoTClient | 0:1f9b2707ec7d | 104 | }; |
AzureIoTClient | 0:1f9b2707ec7d | 105 | |
AzureIoTClient | 0:1f9b2707ec7d | 106 | /*name cannot be empty, value can be empty or NULL*/ |
AzureIoTClient | 0:1f9b2707ec7d | 107 | #ifdef _MSC_VER |
AzureIoTClient | 0:1f9b2707ec7d | 108 | #pragma warning(disable: 4701) /* potentially uninitialized local variable 'result' used */ /* the scanner cannot track linked "newNode" and "result" therefore the warning*/ |
AzureIoTClient | 0:1f9b2707ec7d | 109 | #endif |
AzureIoTClient | 0:1f9b2707ec7d | 110 | static CREATELEAF_RESULT createLeaf(MULTITREE_NODE* node, const char*name, const char*value, MULTITREE_NODE** childNode) |
AzureIoTClient | 0:1f9b2707ec7d | 111 | { |
AzureIoTClient | 0:1f9b2707ec7d | 112 | CREATELEAF_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 113 | /*can only create it if it doesn't exist*/ |
AzureIoTClient | 0:1f9b2707ec7d | 114 | if (strlen(name) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 115 | { |
AzureIoTClient | 0:1f9b2707ec7d | 116 | /*Codes_SRS_MULTITREE_99_024:[ if a child name is empty (such as in "/child1//child12"), MULTITREE_EMPTY_CHILD_NAME shall be returned.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 117 | result = CREATELEAF_EMPTY_NAME; |
AzureIoTClient | 0:1f9b2707ec7d | 118 | LogError("(result = %s)\r\n", CreateLeaf_ResultAsString[result]); |
AzureIoTClient | 0:1f9b2707ec7d | 119 | } |
AzureIoTClient | 0:1f9b2707ec7d | 120 | else if (getChildByName(node, name) != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 121 | { |
AzureIoTClient | 0:1f9b2707ec7d | 122 | result = CREATELEAF_ALREADY_EXISTS; |
AzureIoTClient | 0:1f9b2707ec7d | 123 | LogError("(result = %s)\r\n", CreateLeaf_ResultAsString[result]); |
AzureIoTClient | 0:1f9b2707ec7d | 124 | } |
AzureIoTClient | 0:1f9b2707ec7d | 125 | else |
AzureIoTClient | 0:1f9b2707ec7d | 126 | { |
AzureIoTClient | 0:1f9b2707ec7d | 127 | MULTITREE_NODE* newNode = (MULTITREE_NODE*)malloc(sizeof(MULTITREE_NODE)); |
AzureIoTClient | 0:1f9b2707ec7d | 128 | if (newNode == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 129 | { |
AzureIoTClient | 0:1f9b2707ec7d | 130 | result = CREATELEAF_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 131 | LogError("(result = %s)\r\n", CreateLeaf_ResultAsString[result]); |
AzureIoTClient | 0:1f9b2707ec7d | 132 | } |
AzureIoTClient | 0:1f9b2707ec7d | 133 | else |
AzureIoTClient | 0:1f9b2707ec7d | 134 | { |
AzureIoTClient | 0:1f9b2707ec7d | 135 | newNode->nChildren = 0; |
AzureIoTClient | 0:1f9b2707ec7d | 136 | newNode->children = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 137 | if (mallocAndStrcpy_s(&(newNode->name), name) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 138 | { |
AzureIoTClient | 0:1f9b2707ec7d | 139 | /*not nice*/ |
AzureIoTClient | 0:1f9b2707ec7d | 140 | free(newNode); |
AzureIoTClient | 0:1f9b2707ec7d | 141 | newNode = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 142 | result = CREATELEAF_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 143 | LogError("(result = %s)\r\n", CreateLeaf_ResultAsString[result]); |
AzureIoTClient | 0:1f9b2707ec7d | 144 | } |
AzureIoTClient | 0:1f9b2707ec7d | 145 | else |
AzureIoTClient | 0:1f9b2707ec7d | 146 | { |
AzureIoTClient | 0:1f9b2707ec7d | 147 | newNode->cloneFunction = node->cloneFunction; |
AzureIoTClient | 0:1f9b2707ec7d | 148 | newNode->freeFunction = node->freeFunction; |
AzureIoTClient | 0:1f9b2707ec7d | 149 | |
AzureIoTClient | 0:1f9b2707ec7d | 150 | if (value == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 151 | { |
AzureIoTClient | 0:1f9b2707ec7d | 152 | newNode->value = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 153 | } |
AzureIoTClient | 0:1f9b2707ec7d | 154 | else if (node->cloneFunction(&(newNode->value), value) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 155 | { |
AzureIoTClient | 0:1f9b2707ec7d | 156 | free(newNode->name); |
AzureIoTClient | 0:1f9b2707ec7d | 157 | newNode->name = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 158 | free(newNode); |
AzureIoTClient | 0:1f9b2707ec7d | 159 | newNode = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 160 | result = CREATELEAF_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 161 | LogError("(result = %s)\r\n", CreateLeaf_ResultAsString[result]); |
AzureIoTClient | 0:1f9b2707ec7d | 162 | } |
AzureIoTClient | 0:1f9b2707ec7d | 163 | else |
AzureIoTClient | 0:1f9b2707ec7d | 164 | { |
AzureIoTClient | 0:1f9b2707ec7d | 165 | /*all is fine until now*/ |
AzureIoTClient | 0:1f9b2707ec7d | 166 | } |
AzureIoTClient | 0:1f9b2707ec7d | 167 | } |
AzureIoTClient | 0:1f9b2707ec7d | 168 | |
AzureIoTClient | 0:1f9b2707ec7d | 169 | |
AzureIoTClient | 0:1f9b2707ec7d | 170 | if (newNode!=NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 171 | { |
AzureIoTClient | 0:1f9b2707ec7d | 172 | /*allocate space in the father node*/ |
AzureIoTClient | 0:1f9b2707ec7d | 173 | MULTITREE_NODE** newChildren = (MULTITREE_NODE**)realloc(node->children, (node->nChildren + 1)*sizeof(MULTITREE_NODE*)); |
AzureIoTClient | 0:1f9b2707ec7d | 174 | if (newChildren == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 175 | { |
AzureIoTClient | 0:1f9b2707ec7d | 176 | /*no space for the new node*/ |
AzureIoTClient | 0:1f9b2707ec7d | 177 | newNode->value = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 178 | free(newNode->name); |
AzureIoTClient | 0:1f9b2707ec7d | 179 | newNode->name = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 180 | free(newNode); |
AzureIoTClient | 0:1f9b2707ec7d | 181 | newNode = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 182 | result = CREATELEAF_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 183 | LogError("(result = %s)\r\n", CreateLeaf_ResultAsString[result]); |
AzureIoTClient | 0:1f9b2707ec7d | 184 | } |
AzureIoTClient | 0:1f9b2707ec7d | 185 | else |
AzureIoTClient | 0:1f9b2707ec7d | 186 | { |
AzureIoTClient | 0:1f9b2707ec7d | 187 | node->children = newChildren; |
AzureIoTClient | 0:1f9b2707ec7d | 188 | node->children[node->nChildren] = newNode; |
AzureIoTClient | 0:1f9b2707ec7d | 189 | node->nChildren++; |
AzureIoTClient | 0:1f9b2707ec7d | 190 | if (childNode != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 191 | { |
AzureIoTClient | 0:1f9b2707ec7d | 192 | *childNode = newNode; |
AzureIoTClient | 0:1f9b2707ec7d | 193 | } |
AzureIoTClient | 0:1f9b2707ec7d | 194 | result = CREATELEAF_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 195 | } |
AzureIoTClient | 0:1f9b2707ec7d | 196 | } |
AzureIoTClient | 0:1f9b2707ec7d | 197 | } |
AzureIoTClient | 0:1f9b2707ec7d | 198 | } |
AzureIoTClient | 0:1f9b2707ec7d | 199 | |
AzureIoTClient | 0:1f9b2707ec7d | 200 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 201 | #ifdef _MSC_VER |
AzureIoTClient | 0:1f9b2707ec7d | 202 | #pragma warning(default: 4701) /* potentially uninitialized local variable 'result' used */ /* the scanner cannot track linked "newNode" and "result" therefore the warning*/ |
AzureIoTClient | 0:1f9b2707ec7d | 203 | #endif |
AzureIoTClient | 0:1f9b2707ec7d | 204 | } |
AzureIoTClient | 0:1f9b2707ec7d | 205 | |
AzureIoTClient | 0:1f9b2707ec7d | 206 | MULTITREE_RESULT MultiTree_AddLeaf(MULTITREE_HANDLE treeHandle, const char* destinationPath, const void* value) |
AzureIoTClient | 0:1f9b2707ec7d | 207 | { |
AzureIoTClient | 0:1f9b2707ec7d | 208 | /*codes_SRS_MULTITREE_99_018:[ If the treeHandle parameter is NULL, MULTITREE_INVALID_ARG shall be returned.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 209 | MULTITREE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 210 | if (treeHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 211 | { |
AzureIoTClient | 0:1f9b2707ec7d | 212 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 213 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 214 | } |
AzureIoTClient | 0:1f9b2707ec7d | 215 | /*Codes_SRS_MULTITREE_99_019:[ If parameter destinationPath is NULL, MULTITREE_INVALID_ARG shall be returned.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 216 | else if (destinationPath == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 217 | { |
AzureIoTClient | 0:1f9b2707ec7d | 218 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 219 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 220 | } |
AzureIoTClient | 0:1f9b2707ec7d | 221 | /*Codes_SRS_MULTITREE_99_020:[ If parameter value is NULL, MULTITREE_INVALID_ARG shall be returned.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 222 | else if (value == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 223 | { |
AzureIoTClient | 0:1f9b2707ec7d | 224 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 225 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 226 | } |
AzureIoTClient | 0:1f9b2707ec7d | 227 | /*Codes_SRS_MULTITREE_99_050:[ If destinationPath a string with zero characters, MULTITREE_INVALID_ARG shall be returned.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 228 | else if (strlen(destinationPath) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 229 | { |
AzureIoTClient | 0:1f9b2707ec7d | 230 | result = MULTITREE_EMPTY_CHILD_NAME; |
AzureIoTClient | 0:1f9b2707ec7d | 231 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 232 | } |
AzureIoTClient | 0:1f9b2707ec7d | 233 | else |
AzureIoTClient | 0:1f9b2707ec7d | 234 | { |
AzureIoTClient | 0:1f9b2707ec7d | 235 | /*break the path into components*/ |
AzureIoTClient | 0:1f9b2707ec7d | 236 | /*find the first child name*/ |
AzureIoTClient | 0:1f9b2707ec7d | 237 | MULTITREE_NODE * node = (MULTITREE_NODE *)treeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 238 | char * whereIsDelimiter; |
AzureIoTClient | 0:1f9b2707ec7d | 239 | /*if first character is / then skip it*/ |
AzureIoTClient | 0:1f9b2707ec7d | 240 | /*Codes_SRS_MULTITREE_99_014:[DestinationPath is a string in the following format: /child1/child12 or child1/child12] */ |
AzureIoTClient | 0:1f9b2707ec7d | 241 | if (destinationPath[0] == '/') |
AzureIoTClient | 0:1f9b2707ec7d | 242 | { |
AzureIoTClient | 0:1f9b2707ec7d | 243 | destinationPath++; |
AzureIoTClient | 0:1f9b2707ec7d | 244 | } |
AzureIoTClient | 0:1f9b2707ec7d | 245 | /*if there's just a string, it needs to be created here*/ |
AzureIoTClient | 0:1f9b2707ec7d | 246 | whereIsDelimiter = (char*)strchr(destinationPath, '/'); |
AzureIoTClient | 0:1f9b2707ec7d | 247 | if (whereIsDelimiter == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 248 | { |
AzureIoTClient | 0:1f9b2707ec7d | 249 | /*Codes_SRS_MULTITREE_99_017:[ Subsequent names designate hierarchical children in the tree. The last child designates the child that will receive the value.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 250 | CREATELEAF_RESULT res = createLeaf(node, destinationPath, (const char*)value, NULL); |
AzureIoTClient | 0:1f9b2707ec7d | 251 | switch (res) |
AzureIoTClient | 0:1f9b2707ec7d | 252 | { |
AzureIoTClient | 0:1f9b2707ec7d | 253 | default: |
AzureIoTClient | 0:1f9b2707ec7d | 254 | { |
AzureIoTClient | 0:1f9b2707ec7d | 255 | /*Codes_SRS_MULTITREE_99_025:[The function shall return MULTITREE_ERROR to indicate any other error not specified here.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 256 | result = MULTITREE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 257 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 258 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 259 | } |
AzureIoTClient | 0:1f9b2707ec7d | 260 | case CREATELEAF_ALREADY_EXISTS: |
AzureIoTClient | 0:1f9b2707ec7d | 261 | { |
AzureIoTClient | 0:1f9b2707ec7d | 262 | /*Codes_SRS_MULTITREE_99_021:[ If the node already has a value assigned to it, MULTITREE_ALREADY_HAS_A_VALUE shall be returned and the existing value shall not be changed.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 263 | result = MULTITREE_ALREADY_HAS_A_VALUE; |
AzureIoTClient | 0:1f9b2707ec7d | 264 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 265 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 266 | } |
AzureIoTClient | 0:1f9b2707ec7d | 267 | case CREATELEAF_OK: |
AzureIoTClient | 0:1f9b2707ec7d | 268 | { |
AzureIoTClient | 0:1f9b2707ec7d | 269 | /*Codes_SRS_MULTITREE_99_034:[ The function returns MULTITREE_OK when data has been stored in the tree.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 270 | result = MULTITREE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 271 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 272 | } |
AzureIoTClient | 0:1f9b2707ec7d | 273 | case CREATELEAF_EMPTY_NAME: |
AzureIoTClient | 0:1f9b2707ec7d | 274 | { |
AzureIoTClient | 0:1f9b2707ec7d | 275 | /*Codes_SRS_MULTITREE_99_024:[ if a child name is empty (such as in "/child1//child12"), MULTITREE_EMPTY_CHILD_NAME shall be returned.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 276 | result = MULTITREE_EMPTY_CHILD_NAME; |
AzureIoTClient | 0:1f9b2707ec7d | 277 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 278 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 279 | } |
AzureIoTClient | 0:1f9b2707ec7d | 280 | } |
AzureIoTClient | 0:1f9b2707ec7d | 281 | } |
AzureIoTClient | 0:1f9b2707ec7d | 282 | else |
AzureIoTClient | 0:1f9b2707ec7d | 283 | { |
AzureIoTClient | 0:1f9b2707ec7d | 284 | /*if there's more or 1 delimiter in the path... */ |
AzureIoTClient | 0:1f9b2707ec7d | 285 | /*Codes_SRS_MULTITREE_99_017:[ Subsequent names designate hierarchical children in the tree. The last child designates the child that will receive the value.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 286 | char firstInnerNodeName[INNER_NODE_NAME_SIZE]; |
AzureIoTClient | 0:1f9b2707ec7d | 287 | if (strncpy_s(firstInnerNodeName, INNER_NODE_NAME_SIZE, destinationPath, whereIsDelimiter - destinationPath) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 288 | { |
AzureIoTClient | 0:1f9b2707ec7d | 289 | /*Codes_SRS_MULTITREE_99_025:[ The function shall return MULTITREE_ERROR to indicate any other error not specified here.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 290 | result = MULTITREE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 291 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 292 | } |
AzureIoTClient | 0:1f9b2707ec7d | 293 | else |
AzureIoTClient | 0:1f9b2707ec7d | 294 | { |
AzureIoTClient | 0:1f9b2707ec7d | 295 | MULTITREE_NODE *child = getChildByName(node, firstInnerNodeName); |
AzureIoTClient | 0:1f9b2707ec7d | 296 | if (child == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 297 | { |
AzureIoTClient | 0:1f9b2707ec7d | 298 | /*Codes_SRS_MULTITREE_99_022:[ If a child along the path does not exist, it shall be created.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 299 | /*Codes_SRS_MULTITREE_99_023:[ The newly created children along the path shall have a NULL value by default.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 300 | CREATELEAF_RESULT res = createLeaf(node, firstInnerNodeName, NULL, NULL); |
AzureIoTClient | 0:1f9b2707ec7d | 301 | switch (res) |
AzureIoTClient | 0:1f9b2707ec7d | 302 | { |
AzureIoTClient | 0:1f9b2707ec7d | 303 | default: |
AzureIoTClient | 0:1f9b2707ec7d | 304 | { |
AzureIoTClient | 0:1f9b2707ec7d | 305 | result = MULTITREE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 306 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 307 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 308 | } |
AzureIoTClient | 0:1f9b2707ec7d | 309 | case(CREATELEAF_EMPTY_NAME): |
AzureIoTClient | 0:1f9b2707ec7d | 310 | { |
AzureIoTClient | 0:1f9b2707ec7d | 311 | /*Codes_SRS_MULTITREE_99_024:[ if a child name is empty (such as in "/child1//child12"), MULTITREE_EMPTY_CHILD_NAME shall be returned.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 312 | result = MULTITREE_EMPTY_CHILD_NAME; |
AzureIoTClient | 0:1f9b2707ec7d | 313 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 314 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 315 | } |
AzureIoTClient | 0:1f9b2707ec7d | 316 | case(CREATELEAF_OK): |
AzureIoTClient | 0:1f9b2707ec7d | 317 | { |
AzureIoTClient | 0:1f9b2707ec7d | 318 | MULTITREE_NODE *createdChild = getChildByName(node, firstInnerNodeName); |
AzureIoTClient | 0:1f9b2707ec7d | 319 | result = MultiTree_AddLeaf(createdChild, whereIsDelimiter, value); |
AzureIoTClient | 0:1f9b2707ec7d | 320 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 321 | } |
AzureIoTClient | 0:1f9b2707ec7d | 322 | }; |
AzureIoTClient | 0:1f9b2707ec7d | 323 | } |
AzureIoTClient | 0:1f9b2707ec7d | 324 | else |
AzureIoTClient | 0:1f9b2707ec7d | 325 | { |
AzureIoTClient | 0:1f9b2707ec7d | 326 | result = MultiTree_AddLeaf(child, whereIsDelimiter, value); |
AzureIoTClient | 0:1f9b2707ec7d | 327 | } |
AzureIoTClient | 0:1f9b2707ec7d | 328 | } |
AzureIoTClient | 0:1f9b2707ec7d | 329 | } |
AzureIoTClient | 0:1f9b2707ec7d | 330 | } |
AzureIoTClient | 0:1f9b2707ec7d | 331 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 332 | } |
AzureIoTClient | 0:1f9b2707ec7d | 333 | |
AzureIoTClient | 0:1f9b2707ec7d | 334 | /* Codes_SRS_MULTITREE_99_053:[ MultiTree_AddChild shall add a new node with the name childName to the multi tree node identified by treeHandle] */ |
AzureIoTClient | 0:1f9b2707ec7d | 335 | MULTITREE_RESULT MultiTree_AddChild(MULTITREE_HANDLE treeHandle, const char* childName, MULTITREE_HANDLE* childHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 336 | { |
AzureIoTClient | 0:1f9b2707ec7d | 337 | MULTITREE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 338 | /* Codes_SRS_MULTITREE_99_055:[ If any argument is NULL, MultiTree_AddChild shall return MULTITREE_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 339 | if ((treeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 340 | (childName == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 341 | (childHandle == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 342 | { |
AzureIoTClient | 0:1f9b2707ec7d | 343 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 344 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 345 | } |
AzureIoTClient | 0:1f9b2707ec7d | 346 | else |
AzureIoTClient | 0:1f9b2707ec7d | 347 | { |
AzureIoTClient | 0:1f9b2707ec7d | 348 | MULTITREE_NODE* childNode; |
AzureIoTClient | 0:1f9b2707ec7d | 349 | |
AzureIoTClient | 0:1f9b2707ec7d | 350 | /* Codes_SRS_MULTITREE_99_060:[ The value associated with the new node shall be NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 351 | CREATELEAF_RESULT res = createLeaf((MULTITREE_NODE*)treeHandle, childName, NULL, &childNode); |
AzureIoTClient | 0:1f9b2707ec7d | 352 | switch (res) |
AzureIoTClient | 0:1f9b2707ec7d | 353 | { |
AzureIoTClient | 0:1f9b2707ec7d | 354 | default: |
AzureIoTClient | 0:1f9b2707ec7d | 355 | { |
AzureIoTClient | 0:1f9b2707ec7d | 356 | result = MULTITREE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 357 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 358 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 359 | } |
AzureIoTClient | 0:1f9b2707ec7d | 360 | case CREATELEAF_ALREADY_EXISTS: |
AzureIoTClient | 0:1f9b2707ec7d | 361 | { |
AzureIoTClient | 0:1f9b2707ec7d | 362 | /* Codes_SRS_MULTITREE_99_061:[ If a child node with the same name already exists, MultiTree_AddChild shall return MULTITREE_ALREADY_HAS_A_VALUE.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 363 | result = MULTITREE_ALREADY_HAS_A_VALUE; |
AzureIoTClient | 0:1f9b2707ec7d | 364 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 365 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 366 | } |
AzureIoTClient | 0:1f9b2707ec7d | 367 | case CREATELEAF_OK: |
AzureIoTClient | 0:1f9b2707ec7d | 368 | { |
AzureIoTClient | 0:1f9b2707ec7d | 369 | /* Codes_SRS_MULTITREE_99_062:[ The new node handle shall be returned in the childHandle argument.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 370 | *childHandle = childNode; |
AzureIoTClient | 0:1f9b2707ec7d | 371 | |
AzureIoTClient | 0:1f9b2707ec7d | 372 | /* Codes_SRS_MULTITREE_99_054:[ On success, MultiTree_AddChild shall return MULTITREE_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 373 | result = MULTITREE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 374 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 375 | } |
AzureIoTClient | 0:1f9b2707ec7d | 376 | case CREATELEAF_EMPTY_NAME: |
AzureIoTClient | 0:1f9b2707ec7d | 377 | { |
AzureIoTClient | 0:1f9b2707ec7d | 378 | /* Tests_SRS_MULTITREE_99_066:[ If the childName argument is an empty string, MultiTree_AddChild shall return MULTITREE_EMPTY_CHILD_NAME.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 379 | result = MULTITREE_EMPTY_CHILD_NAME; |
AzureIoTClient | 0:1f9b2707ec7d | 380 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 381 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 382 | } |
AzureIoTClient | 0:1f9b2707ec7d | 383 | } |
AzureIoTClient | 0:1f9b2707ec7d | 384 | } |
AzureIoTClient | 0:1f9b2707ec7d | 385 | |
AzureIoTClient | 0:1f9b2707ec7d | 386 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 387 | } |
AzureIoTClient | 0:1f9b2707ec7d | 388 | |
AzureIoTClient | 0:1f9b2707ec7d | 389 | MULTITREE_RESULT MultiTree_GetChildCount(MULTITREE_HANDLE treeHandle, size_t* count) |
AzureIoTClient | 0:1f9b2707ec7d | 390 | { |
AzureIoTClient | 0:1f9b2707ec7d | 391 | MULTITREE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 392 | /*Codes_SRS_MULTITREE_99_027:[If treeHandle is NULL, the function returns MULTITREE_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 393 | if (treeHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 394 | { |
AzureIoTClient | 0:1f9b2707ec7d | 395 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 396 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 397 | } |
AzureIoTClient | 0:1f9b2707ec7d | 398 | /*Codes_SRS_MULTITREE_99_028:[ If parameter count is NULL, the function returns MULTITREE_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 399 | else if (count == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 400 | { |
AzureIoTClient | 0:1f9b2707ec7d | 401 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 402 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 403 | } |
AzureIoTClient | 0:1f9b2707ec7d | 404 | else |
AzureIoTClient | 0:1f9b2707ec7d | 405 | { |
AzureIoTClient | 0:1f9b2707ec7d | 406 | /*Codes_SRS_MULTITREE_99_029:[ This function writes in *count the number of direct children for a tree node specified by the parameter treeHandle]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 407 | *count = ((MULTITREE_NODE*)treeHandle)->nChildren; |
AzureIoTClient | 0:1f9b2707ec7d | 408 | /*Codes_SRS_MULTITREE_99_035:[ The function shall return MULTITREE_OK when *count contains the number of children of the node pointed to be parameter treeHandle.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 409 | result = MULTITREE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 410 | } |
AzureIoTClient | 0:1f9b2707ec7d | 411 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 412 | } |
AzureIoTClient | 0:1f9b2707ec7d | 413 | |
AzureIoTClient | 0:1f9b2707ec7d | 414 | MULTITREE_RESULT MultiTree_GetChild(MULTITREE_HANDLE treeHandle, size_t index, MULTITREE_HANDLE *childHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 415 | { |
AzureIoTClient | 0:1f9b2707ec7d | 416 | MULTITREE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 417 | /*Codes_SRS_MULTITREE_99_031:[ If parameter treeHandle is NULL, the function returns MULTITREE_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 418 | if (treeHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 419 | { |
AzureIoTClient | 0:1f9b2707ec7d | 420 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 421 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 422 | } |
AzureIoTClient | 0:1f9b2707ec7d | 423 | /*Codes_SRS_MULTITREE_99_033:[ If parameter childHandle is NULL, the function shall return MULTITREE_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 424 | else if (childHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 425 | { |
AzureIoTClient | 0:1f9b2707ec7d | 426 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 427 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 428 | } |
AzureIoTClient | 0:1f9b2707ec7d | 429 | else |
AzureIoTClient | 0:1f9b2707ec7d | 430 | { |
AzureIoTClient | 0:1f9b2707ec7d | 431 | MULTITREE_NODE * node = (MULTITREE_NODE *)treeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 432 | /*Codes_SRS_MULTITREE_99_032:[If parameter index is out of range, the function shall return MULTITREE_OUT_OF_RANGE_INDEX]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 433 | if (node->nChildren <= index) |
AzureIoTClient | 0:1f9b2707ec7d | 434 | { |
AzureIoTClient | 0:1f9b2707ec7d | 435 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 436 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 437 | } |
AzureIoTClient | 0:1f9b2707ec7d | 438 | else |
AzureIoTClient | 0:1f9b2707ec7d | 439 | { |
AzureIoTClient | 0:1f9b2707ec7d | 440 | /*Codes_SRS_MULTITREE_99_030:[ This function writes in *childHandle parameter the "index"th child of the node pointed to by parameter treeHandle]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 441 | /*Codes_SRS_MULTITREE_99_035:[ The function returns MULTITREE_OK when *childHandle contains a handle to the "index"th child of the tree designated by parameter treeHandle.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 442 | *childHandle = node->children[index]; |
AzureIoTClient | 0:1f9b2707ec7d | 443 | result = MULTITREE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 444 | } |
AzureIoTClient | 0:1f9b2707ec7d | 445 | } |
AzureIoTClient | 0:1f9b2707ec7d | 446 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 447 | } |
AzureIoTClient | 0:1f9b2707ec7d | 448 | |
AzureIoTClient | 0:1f9b2707ec7d | 449 | MULTITREE_RESULT MultiTree_GetName(MULTITREE_HANDLE treeHandle, STRING_HANDLE destination) |
AzureIoTClient | 0:1f9b2707ec7d | 450 | { |
AzureIoTClient | 0:1f9b2707ec7d | 451 | MULTITREE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 452 | /*Codes_SRS_MULTITREE_99_037:[ If treeHandle is NULL, the function shall return MULTITREE_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 453 | if (treeHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 454 | { |
AzureIoTClient | 0:1f9b2707ec7d | 455 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 456 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 457 | } |
AzureIoTClient | 0:1f9b2707ec7d | 458 | /*Codes_SRS_MULTITREE_99_038:[If destination is NULL, the function shall return MULTITREE_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 459 | else if (destination == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 460 | { |
AzureIoTClient | 0:1f9b2707ec7d | 461 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 462 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 463 | } |
AzureIoTClient | 0:1f9b2707ec7d | 464 | else |
AzureIoTClient | 0:1f9b2707ec7d | 465 | { |
AzureIoTClient | 0:1f9b2707ec7d | 466 | MULTITREE_NODE *node = (MULTITREE_NODE*)treeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 467 | /*Codes_SRS_MULTITREE_99_051:[ The function returns MULTITREE_EMPTY_CHILD_NAME when used with the root of the tree.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 468 | if (node->name == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 469 | { |
AzureIoTClient | 0:1f9b2707ec7d | 470 | result = MULTITREE_EMPTY_CHILD_NAME; |
AzureIoTClient | 0:1f9b2707ec7d | 471 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 472 | } |
AzureIoTClient | 0:1f9b2707ec7d | 473 | /*Codes_SRS_MULTITREE_99_036:[ This function fills the buffer pointed to by parameter destination with the name of the root node of the tree designated by parameter treeHandle.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 474 | else if (STRING_concat(destination, node->name)!=0) |
AzureIoTClient | 0:1f9b2707ec7d | 475 | { |
AzureIoTClient | 0:1f9b2707ec7d | 476 | /*Codes_SRS_MULTITREE_99_040:[ The function returns MULTITREE_ERROR to indicate any other error.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 477 | result = MULTITREE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 478 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 479 | } |
AzureIoTClient | 0:1f9b2707ec7d | 480 | else |
AzureIoTClient | 0:1f9b2707ec7d | 481 | { |
AzureIoTClient | 0:1f9b2707ec7d | 482 | /*Codes_SRS_MULTITREE_99_039:[ The function returns MULTITREE_OK when destination contains the name of the root node of the tree designated by treeHandle parameter.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 483 | result = MULTITREE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 484 | } |
AzureIoTClient | 0:1f9b2707ec7d | 485 | } |
AzureIoTClient | 0:1f9b2707ec7d | 486 | |
AzureIoTClient | 0:1f9b2707ec7d | 487 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 488 | } |
AzureIoTClient | 0:1f9b2707ec7d | 489 | |
AzureIoTClient | 0:1f9b2707ec7d | 490 | /* Codes_SRS_MULTITREE_99_063:[ MultiTree_GetChildByName shall retrieve the handle of the child node childName from the treeNode node.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 491 | MULTITREE_RESULT MultiTree_GetChildByName(MULTITREE_HANDLE treeHandle, const char* childName, MULTITREE_HANDLE *childHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 492 | { |
AzureIoTClient | 0:1f9b2707ec7d | 493 | MULTITREE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 494 | |
AzureIoTClient | 0:1f9b2707ec7d | 495 | /* Codes_SRS_MULTITREE_99_065:[ If any argument is NULL, MultiTree_GetChildByName shall return MULTITREE_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 496 | if ((treeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 497 | (childHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 498 | (childName == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 499 | { |
AzureIoTClient | 0:1f9b2707ec7d | 500 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 501 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 502 | } |
AzureIoTClient | 0:1f9b2707ec7d | 503 | else |
AzureIoTClient | 0:1f9b2707ec7d | 504 | { |
AzureIoTClient | 0:1f9b2707ec7d | 505 | MULTITREE_NODE * node = (MULTITREE_NODE *)treeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 506 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 507 | |
AzureIoTClient | 0:1f9b2707ec7d | 508 | for (i = 0; i < node->nChildren; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 509 | { |
AzureIoTClient | 0:1f9b2707ec7d | 510 | if (strcmp(node->children[i]->name, childName) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 511 | { |
AzureIoTClient | 0:1f9b2707ec7d | 512 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 513 | } |
AzureIoTClient | 0:1f9b2707ec7d | 514 | } |
AzureIoTClient | 0:1f9b2707ec7d | 515 | |
AzureIoTClient | 0:1f9b2707ec7d | 516 | if (i == node->nChildren) |
AzureIoTClient | 0:1f9b2707ec7d | 517 | { |
AzureIoTClient | 0:1f9b2707ec7d | 518 | /* Codes_SRS_MULTITREE_99_068:[ If the specified child is not found, MultiTree_GetChildByName shall return MULTITREE_CHILD_NOT_FOUND.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 519 | result = MULTITREE_CHILD_NOT_FOUND; |
AzureIoTClient | 0:1f9b2707ec7d | 520 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 521 | } |
AzureIoTClient | 0:1f9b2707ec7d | 522 | else |
AzureIoTClient | 0:1f9b2707ec7d | 523 | { |
AzureIoTClient | 0:1f9b2707ec7d | 524 | /* Codes_SRS_MULTITREE_99_067:[ The child node handle shall be returned in the childHandle argument.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 525 | *childHandle = node->children[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 526 | |
AzureIoTClient | 0:1f9b2707ec7d | 527 | /* Codes_SRS_MULTITREE_99_064:[ On success, MultiTree_GetChildByName shall return MULTITREE_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 528 | result = MULTITREE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 529 | } |
AzureIoTClient | 0:1f9b2707ec7d | 530 | } |
AzureIoTClient | 0:1f9b2707ec7d | 531 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 532 | } |
AzureIoTClient | 0:1f9b2707ec7d | 533 | |
AzureIoTClient | 0:1f9b2707ec7d | 534 | MULTITREE_RESULT MultiTree_GetValue(MULTITREE_HANDLE treeHandle, const void** destination) |
AzureIoTClient | 0:1f9b2707ec7d | 535 | { |
AzureIoTClient | 0:1f9b2707ec7d | 536 | MULTITREE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 537 | /*Codes_SRS_MULTITREE_99_042:[If treeHandle is NULL, the function shall return MULTITREE_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 538 | if (treeHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 539 | { |
AzureIoTClient | 0:1f9b2707ec7d | 540 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 541 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 542 | } |
AzureIoTClient | 0:1f9b2707ec7d | 543 | /*Codes_SRS_MULTITREE_99_043:[ If destination is NULL, the function shall return MULTITREE_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 544 | else if (destination == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 545 | { |
AzureIoTClient | 0:1f9b2707ec7d | 546 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 547 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 548 | } |
AzureIoTClient | 0:1f9b2707ec7d | 549 | else |
AzureIoTClient | 0:1f9b2707ec7d | 550 | { |
AzureIoTClient | 0:1f9b2707ec7d | 551 | MULTITREE_NODE * node = (MULTITREE_NODE*)treeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 552 | /*Codes_SRS_MULTITREE_99_044:[ If there is no value in the node then MULTITREE_EMPTY_VALUE shall be returned.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 553 | if (node->value == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 554 | { |
AzureIoTClient | 0:1f9b2707ec7d | 555 | result = MULTITREE_EMPTY_VALUE; |
AzureIoTClient | 0:1f9b2707ec7d | 556 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 557 | } |
AzureIoTClient | 0:1f9b2707ec7d | 558 | else |
AzureIoTClient | 0:1f9b2707ec7d | 559 | { |
AzureIoTClient | 0:1f9b2707ec7d | 560 | /*Codes_SRS_MULTITREE_99_041:[This function updates the *destination parameter to the internally stored value.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 561 | *destination = node->value; |
AzureIoTClient | 0:1f9b2707ec7d | 562 | result = MULTITREE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 563 | } |
AzureIoTClient | 0:1f9b2707ec7d | 564 | } |
AzureIoTClient | 0:1f9b2707ec7d | 565 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 566 | } |
AzureIoTClient | 0:1f9b2707ec7d | 567 | |
AzureIoTClient | 0:1f9b2707ec7d | 568 | MULTITREE_RESULT MultiTree_SetValue(MULTITREE_HANDLE treeHandle, void* value) |
AzureIoTClient | 0:1f9b2707ec7d | 569 | { |
AzureIoTClient | 0:1f9b2707ec7d | 570 | MULTITREE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 571 | |
AzureIoTClient | 0:1f9b2707ec7d | 572 | /* Codes_SRS_MULTITREE_99_074:[ If any argument is NULL, MultiTree_SetValue shall return MULTITREE_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 573 | if ((treeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 574 | (value == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 575 | { |
AzureIoTClient | 0:1f9b2707ec7d | 576 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 577 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 578 | } |
AzureIoTClient | 0:1f9b2707ec7d | 579 | else |
AzureIoTClient | 0:1f9b2707ec7d | 580 | { |
AzureIoTClient | 0:1f9b2707ec7d | 581 | MULTITREE_NODE * node = (MULTITREE_NODE*)treeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 582 | if (node->value != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 583 | { |
AzureIoTClient | 0:1f9b2707ec7d | 584 | /* Codes_SRS_MULTITREE_99_076:[ If the node already has a value then MultiTree_SetValue shall return MULTITREE_ALREADY_HAS_A_VALUE.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 585 | result = MULTITREE_ALREADY_HAS_A_VALUE; |
AzureIoTClient | 0:1f9b2707ec7d | 586 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 587 | } |
AzureIoTClient | 0:1f9b2707ec7d | 588 | else |
AzureIoTClient | 0:1f9b2707ec7d | 589 | { |
AzureIoTClient | 0:1f9b2707ec7d | 590 | /* Codes_SRS_MULTITREE_99_072:[ MultiTree_SetValue shall set the value of the node indicated by the treeHandle argument to the value of the argument value.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 591 | if (node->cloneFunction(&node->value, value) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 592 | { |
AzureIoTClient | 0:1f9b2707ec7d | 593 | /* Codes_SRS_MULTITREE_99_075:[ MultiTree_SetValue shall return MULTITREE_ERROR to indicate any other error.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 594 | result = MULTITREE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 595 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 596 | } |
AzureIoTClient | 0:1f9b2707ec7d | 597 | else |
AzureIoTClient | 0:1f9b2707ec7d | 598 | { |
AzureIoTClient | 0:1f9b2707ec7d | 599 | /* Codes_SRS_MULTITREE_99_073:[ On success, MultiTree_SetValue shall return MULTITREE_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 600 | result = MULTITREE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 601 | } |
AzureIoTClient | 0:1f9b2707ec7d | 602 | } |
AzureIoTClient | 0:1f9b2707ec7d | 603 | } |
AzureIoTClient | 0:1f9b2707ec7d | 604 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 605 | } |
AzureIoTClient | 0:1f9b2707ec7d | 606 | |
AzureIoTClient | 0:1f9b2707ec7d | 607 | void MultiTree_Destroy(MULTITREE_HANDLE treeHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 608 | { |
AzureIoTClient | 0:1f9b2707ec7d | 609 | if (treeHandle != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 610 | { |
AzureIoTClient | 0:1f9b2707ec7d | 611 | MULTITREE_NODE* node = (MULTITREE_NODE*)treeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 612 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 613 | for (i = 0; i < node->nChildren;i++) |
AzureIoTClient | 0:1f9b2707ec7d | 614 | { |
AzureIoTClient | 0:1f9b2707ec7d | 615 | /*Codes_SRS_MULTITREE_99_047:[ This function frees any system resource used by the tree designated by parameter treeHandle]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 616 | MultiTree_Destroy(node->children[i]); |
AzureIoTClient | 0:1f9b2707ec7d | 617 | } |
AzureIoTClient | 0:1f9b2707ec7d | 618 | /*Codes_SRS_MULTITREE_99_047:[ This function frees any system resource used by the tree designated by parameter treeHandle]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 619 | if (node->children != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 620 | { |
AzureIoTClient | 0:1f9b2707ec7d | 621 | free(node->children); |
AzureIoTClient | 0:1f9b2707ec7d | 622 | node->children = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 623 | } |
AzureIoTClient | 0:1f9b2707ec7d | 624 | |
AzureIoTClient | 0:1f9b2707ec7d | 625 | /*Codes_SRS_MULTITREE_99_047:[ This function frees any system resource used by the tree designated by parameter treeHandle]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 626 | if (node->name != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 627 | { |
AzureIoTClient | 0:1f9b2707ec7d | 628 | free(node->name); |
AzureIoTClient | 0:1f9b2707ec7d | 629 | node->name = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 630 | } |
AzureIoTClient | 0:1f9b2707ec7d | 631 | |
AzureIoTClient | 0:1f9b2707ec7d | 632 | /*Codes_SRS_MULTITREE_99_047:[ This function frees any system resource used by the tree designated by parameter treeHandle]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 633 | if (node->value != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 634 | { |
AzureIoTClient | 0:1f9b2707ec7d | 635 | node->freeFunction(node->value); |
AzureIoTClient | 0:1f9b2707ec7d | 636 | node->value = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 637 | } |
AzureIoTClient | 0:1f9b2707ec7d | 638 | |
AzureIoTClient | 0:1f9b2707ec7d | 639 | /*Codes_SRS_MULTITREE_99_047:[ This function frees any system resource used by the tree designated by parameter treeHandle]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 640 | free(node); |
AzureIoTClient | 0:1f9b2707ec7d | 641 | } |
AzureIoTClient | 0:1f9b2707ec7d | 642 | } |
AzureIoTClient | 0:1f9b2707ec7d | 643 | |
AzureIoTClient | 0:1f9b2707ec7d | 644 | MULTITREE_RESULT MultiTree_GetLeafValue(MULTITREE_HANDLE treeHandle, const char* leafPath, const void** destination) |
AzureIoTClient | 0:1f9b2707ec7d | 645 | { |
AzureIoTClient | 0:1f9b2707ec7d | 646 | MULTITREE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 647 | |
AzureIoTClient | 0:1f9b2707ec7d | 648 | /* Codes_SRS_MULTITREE_99_055:[ If any argument is NULL, MultiTree_GetLeafValue shall return MULTITREE_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 649 | if ((treeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 650 | (leafPath == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 651 | (destination == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 652 | { |
AzureIoTClient | 0:1f9b2707ec7d | 653 | result = MULTITREE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 654 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 655 | } |
AzureIoTClient | 0:1f9b2707ec7d | 656 | /* Codes_SRS_MULTITREE_99_058:[ The last child designates the child that will receive the value. If a child name is empty (such as in "/child1//child12"), MULTITREE_EMPTY_CHILD_NAME shall be returned.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 657 | else if (strlen(leafPath) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 658 | { |
AzureIoTClient | 0:1f9b2707ec7d | 659 | result = MULTITREE_EMPTY_CHILD_NAME; |
AzureIoTClient | 0:1f9b2707ec7d | 660 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 661 | } |
AzureIoTClient | 0:1f9b2707ec7d | 662 | else |
AzureIoTClient | 0:1f9b2707ec7d | 663 | { |
AzureIoTClient | 0:1f9b2707ec7d | 664 | /*break the path into components*/ |
AzureIoTClient | 0:1f9b2707ec7d | 665 | /*find the first child name*/ |
AzureIoTClient | 0:1f9b2707ec7d | 666 | MULTITREE_NODE* node = (MULTITREE_NODE *)treeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 667 | const char* pos = leafPath; |
AzureIoTClient | 0:1f9b2707ec7d | 668 | const char * whereIsDelimiter; |
AzureIoTClient | 0:1f9b2707ec7d | 669 | |
AzureIoTClient | 0:1f9b2707ec7d | 670 | /*if first character is / then skip it*/ |
AzureIoTClient | 0:1f9b2707ec7d | 671 | if (*pos == '/') |
AzureIoTClient | 0:1f9b2707ec7d | 672 | { |
AzureIoTClient | 0:1f9b2707ec7d | 673 | pos++; |
AzureIoTClient | 0:1f9b2707ec7d | 674 | } |
AzureIoTClient | 0:1f9b2707ec7d | 675 | |
AzureIoTClient | 0:1f9b2707ec7d | 676 | if (*pos == '\0') |
AzureIoTClient | 0:1f9b2707ec7d | 677 | { |
AzureIoTClient | 0:1f9b2707ec7d | 678 | /* Codes_SRS_MULTITREE_99_069:[ If a child name is empty (such as in "/child1//child12"), MULTITREE_EMPTY_CHILD_NAME shall be returned.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 679 | result = MULTITREE_EMPTY_CHILD_NAME; |
AzureIoTClient | 0:1f9b2707ec7d | 680 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 681 | } |
AzureIoTClient | 0:1f9b2707ec7d | 682 | else |
AzureIoTClient | 0:1f9b2707ec7d | 683 | { |
AzureIoTClient | 0:1f9b2707ec7d | 684 | result = MULTITREE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 685 | |
AzureIoTClient | 0:1f9b2707ec7d | 686 | /* Codes_SRS_MULTITREE_99_056:[ The leafPath argument is a string in the following format: /child1/child12 or child1/child12.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 687 | /* Codes_SRS_MULTITREE_99_058:[ The last child designates the child that will receive the value.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 688 | while (*pos != '\0') |
AzureIoTClient | 0:1f9b2707ec7d | 689 | { |
AzureIoTClient | 0:1f9b2707ec7d | 690 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 691 | size_t childCount = node->nChildren; |
AzureIoTClient | 0:1f9b2707ec7d | 692 | |
AzureIoTClient | 0:1f9b2707ec7d | 693 | whereIsDelimiter = pos; |
AzureIoTClient | 0:1f9b2707ec7d | 694 | |
AzureIoTClient | 0:1f9b2707ec7d | 695 | while ((*whereIsDelimiter != '/') && (*whereIsDelimiter != '\0')) |
AzureIoTClient | 0:1f9b2707ec7d | 696 | { |
AzureIoTClient | 0:1f9b2707ec7d | 697 | whereIsDelimiter++; |
AzureIoTClient | 0:1f9b2707ec7d | 698 | } |
AzureIoTClient | 0:1f9b2707ec7d | 699 | |
AzureIoTClient | 0:1f9b2707ec7d | 700 | if (whereIsDelimiter == pos) |
AzureIoTClient | 0:1f9b2707ec7d | 701 | { |
AzureIoTClient | 0:1f9b2707ec7d | 702 | /* Codes_SRS_MULTITREE_99_069:[ If a child name is empty (such as in "/child1//child12"), MULTITREE_EMPTY_CHILD_NAME shall be returned.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 703 | result = MULTITREE_EMPTY_CHILD_NAME; |
AzureIoTClient | 0:1f9b2707ec7d | 704 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 705 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 706 | } |
AzureIoTClient | 0:1f9b2707ec7d | 707 | else if (childCount == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 708 | { |
AzureIoTClient | 0:1f9b2707ec7d | 709 | /* Codes_SRS_MULTITREE_99_071:[ When the child node is not found, MultiTree_GetLeafValue shall return MULTITREE_CHILD_NOT_FOUND.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 710 | result = MULTITREE_CHILD_NOT_FOUND; |
AzureIoTClient | 0:1f9b2707ec7d | 711 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 712 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 713 | } |
AzureIoTClient | 0:1f9b2707ec7d | 714 | else |
AzureIoTClient | 0:1f9b2707ec7d | 715 | { |
AzureIoTClient | 0:1f9b2707ec7d | 716 | for (i = 0; i < childCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 717 | { |
AzureIoTClient | 0:1f9b2707ec7d | 718 | if (strncmp(node->children[i]->name, pos, whereIsDelimiter - pos) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 719 | { |
AzureIoTClient | 0:1f9b2707ec7d | 720 | /* Codes_SRS_MULTITREE_99_057:[ Subsequent names designate hierarchical children in the tree.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 721 | node = node->children[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 722 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 723 | } |
AzureIoTClient | 0:1f9b2707ec7d | 724 | } |
AzureIoTClient | 0:1f9b2707ec7d | 725 | |
AzureIoTClient | 0:1f9b2707ec7d | 726 | if (i == childCount) |
AzureIoTClient | 0:1f9b2707ec7d | 727 | { |
AzureIoTClient | 0:1f9b2707ec7d | 728 | /* Codes_SRS_MULTITREE_99_071:[ When the child node is not found, MultiTree_GetLeafValue shall return MULTITREE_CHILD_NOT_FOUND.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 729 | result = MULTITREE_CHILD_NOT_FOUND; |
AzureIoTClient | 0:1f9b2707ec7d | 730 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 731 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 732 | } |
AzureIoTClient | 0:1f9b2707ec7d | 733 | else |
AzureIoTClient | 0:1f9b2707ec7d | 734 | { |
AzureIoTClient | 0:1f9b2707ec7d | 735 | if (*whereIsDelimiter == '/') |
AzureIoTClient | 0:1f9b2707ec7d | 736 | { |
AzureIoTClient | 0:1f9b2707ec7d | 737 | pos = whereIsDelimiter + 1; |
AzureIoTClient | 0:1f9b2707ec7d | 738 | } |
AzureIoTClient | 0:1f9b2707ec7d | 739 | else |
AzureIoTClient | 0:1f9b2707ec7d | 740 | { |
AzureIoTClient | 0:1f9b2707ec7d | 741 | /* end of path */ |
AzureIoTClient | 0:1f9b2707ec7d | 742 | pos = whereIsDelimiter; |
AzureIoTClient | 0:1f9b2707ec7d | 743 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 744 | } |
AzureIoTClient | 0:1f9b2707ec7d | 745 | } |
AzureIoTClient | 0:1f9b2707ec7d | 746 | } |
AzureIoTClient | 0:1f9b2707ec7d | 747 | } |
AzureIoTClient | 0:1f9b2707ec7d | 748 | |
AzureIoTClient | 0:1f9b2707ec7d | 749 | if (*pos == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 750 | { |
AzureIoTClient | 0:1f9b2707ec7d | 751 | if (node->value == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 752 | { |
AzureIoTClient | 0:1f9b2707ec7d | 753 | /* Codes_SRS_MULTITREE_99_070:[ If an attempt is made to get the value for a node that does not have a value set, then MultiTree_GetLeafValue shall return MULTITREE_EMPTY_VALUE.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 754 | result = MULTITREE_EMPTY_VALUE; |
AzureIoTClient | 0:1f9b2707ec7d | 755 | LogError("(result = %s)\r\n", ENUM_TO_STRING(MULTITREE_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 756 | } |
AzureIoTClient | 0:1f9b2707ec7d | 757 | /*Codes_SRS_MULTITREE_99_053:[ MultiTree_GetLeafValue shall copy into the *destination argument the value of the node identified by the leafPath argument.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 758 | else |
AzureIoTClient | 0:1f9b2707ec7d | 759 | { |
AzureIoTClient | 0:1f9b2707ec7d | 760 | *destination = node->value; |
AzureIoTClient | 0:1f9b2707ec7d | 761 | /* Codes_SRS_MULTITREE_99_054:[ On success, MultiTree_GetLeafValue shall return MULTITREE_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 762 | result = MULTITREE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 763 | } |
AzureIoTClient | 0:1f9b2707ec7d | 764 | } |
AzureIoTClient | 0:1f9b2707ec7d | 765 | } |
AzureIoTClient | 0:1f9b2707ec7d | 766 | } |
AzureIoTClient | 0:1f9b2707ec7d | 767 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 768 | } |