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

Committer:
AzureIoTClient
Date:
Tue Sep 11 11:14:37 2018 -0700
Revision:
36:7d12a5386197
Parent:
31:bdcce611d29b
1.2.9

Who changed what in which revision?

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