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:
Mon Mar 05 17:42:32 2018 -0800
Revision:
31:bdcce611d29b
Parent:
30:5fabc80edeb1
Child:
36:7d12a5386197
1.2.0

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 0:1f9b2707ec7d 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 0:1f9b2707ec7d 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 0:1f9b2707ec7d 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 0:1f9b2707ec7d 292 if (strncpy_s(firstInnerNodeName, INNER_NODE_NAME_SIZE, destinationPath, whereIsDelimiter - destinationPath) != 0)
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 11:b1327861f5e0 296 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 297 }
AzureIoTClient 0:1f9b2707ec7d 298 else
AzureIoTClient 0:1f9b2707ec7d 299 {
AzureIoTClient 17:fa1bba4c6053 300 MULTITREE_HANDLE_DATA *child = getChildByName(node, firstInnerNodeName);
AzureIoTClient 0:1f9b2707ec7d 301 if (child == NULL)
AzureIoTClient 0:1f9b2707ec7d 302 {
AzureIoTClient 0:1f9b2707ec7d 303 /*Codes_SRS_MULTITREE_99_022:[ If a child along the path does not exist, it shall be created.] */
AzureIoTClient 0:1f9b2707ec7d 304 /*Codes_SRS_MULTITREE_99_023:[ The newly created children along the path shall have a NULL value by default.]*/
AzureIoTClient 0:1f9b2707ec7d 305 CREATELEAF_RESULT res = createLeaf(node, firstInnerNodeName, NULL, NULL);
AzureIoTClient 0:1f9b2707ec7d 306 switch (res)
AzureIoTClient 0:1f9b2707ec7d 307 {
AzureIoTClient 0:1f9b2707ec7d 308 default:
AzureIoTClient 0:1f9b2707ec7d 309 {
AzureIoTClient 0:1f9b2707ec7d 310 result = MULTITREE_ERROR;
AzureIoTClient 11:b1327861f5e0 311 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 312 break;
AzureIoTClient 0:1f9b2707ec7d 313 }
AzureIoTClient 0:1f9b2707ec7d 314 case(CREATELEAF_EMPTY_NAME):
AzureIoTClient 0:1f9b2707ec7d 315 {
AzureIoTClient 0:1f9b2707ec7d 316 /*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 317 result = MULTITREE_EMPTY_CHILD_NAME;
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_OK):
AzureIoTClient 0:1f9b2707ec7d 322 {
AzureIoTClient 17:fa1bba4c6053 323 MULTITREE_HANDLE_DATA *createdChild = getChildByName(node, firstInnerNodeName);
AzureIoTClient 0:1f9b2707ec7d 324 result = MultiTree_AddLeaf(createdChild, whereIsDelimiter, value);
AzureIoTClient 0:1f9b2707ec7d 325 break;
AzureIoTClient 0:1f9b2707ec7d 326 }
AzureIoTClient 0:1f9b2707ec7d 327 };
AzureIoTClient 0:1f9b2707ec7d 328 }
AzureIoTClient 0:1f9b2707ec7d 329 else
AzureIoTClient 0:1f9b2707ec7d 330 {
AzureIoTClient 0:1f9b2707ec7d 331 result = MultiTree_AddLeaf(child, whereIsDelimiter, value);
AzureIoTClient 0:1f9b2707ec7d 332 }
AzureIoTClient 0:1f9b2707ec7d 333 }
AzureIoTClient 0:1f9b2707ec7d 334 }
AzureIoTClient 0:1f9b2707ec7d 335 }
AzureIoTClient 0:1f9b2707ec7d 336 return result;
AzureIoTClient 0:1f9b2707ec7d 337 }
AzureIoTClient 0:1f9b2707ec7d 338
AzureIoTClient 0:1f9b2707ec7d 339 /* 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 340 MULTITREE_RESULT MultiTree_AddChild(MULTITREE_HANDLE treeHandle, const char* childName, MULTITREE_HANDLE* childHandle)
AzureIoTClient 0:1f9b2707ec7d 341 {
AzureIoTClient 0:1f9b2707ec7d 342 MULTITREE_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 343 /* Codes_SRS_MULTITREE_99_055:[ If any argument is NULL, MultiTree_AddChild shall return MULTITREE_INVALID_ARG.] */
AzureIoTClient 0:1f9b2707ec7d 344 if ((treeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 345 (childName == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 346 (childHandle == NULL))
AzureIoTClient 0:1f9b2707ec7d 347 {
AzureIoTClient 0:1f9b2707ec7d 348 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 349 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 350 }
AzureIoTClient 0:1f9b2707ec7d 351 else
AzureIoTClient 0:1f9b2707ec7d 352 {
AzureIoTClient 17:fa1bba4c6053 353 MULTITREE_HANDLE_DATA* childNode;
AzureIoTClient 0:1f9b2707ec7d 354
AzureIoTClient 0:1f9b2707ec7d 355 /* Codes_SRS_MULTITREE_99_060:[ The value associated with the new node shall be NULL.] */
AzureIoTClient 17:fa1bba4c6053 356 CREATELEAF_RESULT res = createLeaf((MULTITREE_HANDLE_DATA*)treeHandle, childName, NULL, &childNode);
AzureIoTClient 0:1f9b2707ec7d 357 switch (res)
AzureIoTClient 0:1f9b2707ec7d 358 {
AzureIoTClient 0:1f9b2707ec7d 359 default:
AzureIoTClient 0:1f9b2707ec7d 360 {
AzureIoTClient 0:1f9b2707ec7d 361 result = MULTITREE_ERROR;
AzureIoTClient 11:b1327861f5e0 362 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 363 break;
AzureIoTClient 0:1f9b2707ec7d 364 }
AzureIoTClient 0:1f9b2707ec7d 365 case CREATELEAF_ALREADY_EXISTS:
AzureIoTClient 0:1f9b2707ec7d 366 {
AzureIoTClient 0:1f9b2707ec7d 367 /* 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 368 result = MULTITREE_ALREADY_HAS_A_VALUE;
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_OK:
AzureIoTClient 0:1f9b2707ec7d 373 {
AzureIoTClient 0:1f9b2707ec7d 374 /* Codes_SRS_MULTITREE_99_062:[ The new node handle shall be returned in the childHandle argument.] */
AzureIoTClient 0:1f9b2707ec7d 375 *childHandle = childNode;
AzureIoTClient 0:1f9b2707ec7d 376
AzureIoTClient 0:1f9b2707ec7d 377 /* Codes_SRS_MULTITREE_99_054:[ On success, MultiTree_AddChild shall return MULTITREE_OK.] */
AzureIoTClient 0:1f9b2707ec7d 378 result = MULTITREE_OK;
AzureIoTClient 0:1f9b2707ec7d 379 break;
AzureIoTClient 0:1f9b2707ec7d 380 }
AzureIoTClient 0:1f9b2707ec7d 381 case CREATELEAF_EMPTY_NAME:
AzureIoTClient 0:1f9b2707ec7d 382 {
AzureIoTClient 0:1f9b2707ec7d 383 /* Tests_SRS_MULTITREE_99_066:[ If the childName argument is an empty string, MultiTree_AddChild shall return MULTITREE_EMPTY_CHILD_NAME.] */
AzureIoTClient 0:1f9b2707ec7d 384 result = MULTITREE_EMPTY_CHILD_NAME;
AzureIoTClient 11:b1327861f5e0 385 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 386 break;
AzureIoTClient 0:1f9b2707ec7d 387 }
AzureIoTClient 0:1f9b2707ec7d 388 }
AzureIoTClient 0:1f9b2707ec7d 389 }
AzureIoTClient 0:1f9b2707ec7d 390
AzureIoTClient 0:1f9b2707ec7d 391 return result;
AzureIoTClient 0:1f9b2707ec7d 392 }
AzureIoTClient 0:1f9b2707ec7d 393
AzureIoTClient 0:1f9b2707ec7d 394 MULTITREE_RESULT MultiTree_GetChildCount(MULTITREE_HANDLE treeHandle, size_t* count)
AzureIoTClient 0:1f9b2707ec7d 395 {
AzureIoTClient 0:1f9b2707ec7d 396 MULTITREE_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 397 /*Codes_SRS_MULTITREE_99_027:[If treeHandle is NULL, the function returns MULTITREE_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 398 if (treeHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 399 {
AzureIoTClient 0:1f9b2707ec7d 400 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 401 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 402 }
AzureIoTClient 0:1f9b2707ec7d 403 /*Codes_SRS_MULTITREE_99_028:[ If parameter count is NULL, the function returns MULTITREE_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 404 else if (count == NULL)
AzureIoTClient 0:1f9b2707ec7d 405 {
AzureIoTClient 0:1f9b2707ec7d 406 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 407 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 408 }
AzureIoTClient 0:1f9b2707ec7d 409 else
AzureIoTClient 0:1f9b2707ec7d 410 {
AzureIoTClient 0:1f9b2707ec7d 411 /*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 412 *count = ((MULTITREE_HANDLE_DATA*)treeHandle)->nChildren;
AzureIoTClient 0:1f9b2707ec7d 413 /*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 414 result = MULTITREE_OK;
AzureIoTClient 0:1f9b2707ec7d 415 }
AzureIoTClient 0:1f9b2707ec7d 416 return result;
AzureIoTClient 0:1f9b2707ec7d 417 }
AzureIoTClient 0:1f9b2707ec7d 418
AzureIoTClient 0:1f9b2707ec7d 419 MULTITREE_RESULT MultiTree_GetChild(MULTITREE_HANDLE treeHandle, size_t index, MULTITREE_HANDLE *childHandle)
AzureIoTClient 0:1f9b2707ec7d 420 {
AzureIoTClient 0:1f9b2707ec7d 421 MULTITREE_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 422 /*Codes_SRS_MULTITREE_99_031:[ If parameter treeHandle is NULL, the function returns MULTITREE_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 423 if (treeHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 424 {
AzureIoTClient 0:1f9b2707ec7d 425 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 426 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 427 }
AzureIoTClient 0:1f9b2707ec7d 428 /*Codes_SRS_MULTITREE_99_033:[ If parameter childHandle is NULL, the function shall return MULTITREE_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 429 else if (childHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 430 {
AzureIoTClient 0:1f9b2707ec7d 431 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 432 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 433 }
AzureIoTClient 0:1f9b2707ec7d 434 else
AzureIoTClient 0:1f9b2707ec7d 435 {
AzureIoTClient 17:fa1bba4c6053 436 MULTITREE_HANDLE_DATA * node = (MULTITREE_HANDLE_DATA *)treeHandle;
AzureIoTClient 0:1f9b2707ec7d 437 /*Codes_SRS_MULTITREE_99_032:[If parameter index is out of range, the function shall return MULTITREE_OUT_OF_RANGE_INDEX]*/
AzureIoTClient 0:1f9b2707ec7d 438 if (node->nChildren <= index)
AzureIoTClient 0:1f9b2707ec7d 439 {
AzureIoTClient 0:1f9b2707ec7d 440 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 441 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 442 }
AzureIoTClient 0:1f9b2707ec7d 443 else
AzureIoTClient 0:1f9b2707ec7d 444 {
AzureIoTClient 0:1f9b2707ec7d 445 /*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 446 /*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 447 *childHandle = node->children[index];
AzureIoTClient 0:1f9b2707ec7d 448 result = MULTITREE_OK;
AzureIoTClient 0:1f9b2707ec7d 449 }
AzureIoTClient 0:1f9b2707ec7d 450 }
AzureIoTClient 0:1f9b2707ec7d 451 return result;
AzureIoTClient 0:1f9b2707ec7d 452 }
AzureIoTClient 0:1f9b2707ec7d 453
AzureIoTClient 0:1f9b2707ec7d 454 MULTITREE_RESULT MultiTree_GetName(MULTITREE_HANDLE treeHandle, STRING_HANDLE destination)
AzureIoTClient 0:1f9b2707ec7d 455 {
AzureIoTClient 0:1f9b2707ec7d 456 MULTITREE_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 457 /*Codes_SRS_MULTITREE_99_037:[ If treeHandle is NULL, the function shall return MULTITREE_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 458 if (treeHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 459 {
AzureIoTClient 0:1f9b2707ec7d 460 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 461 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 462 }
AzureIoTClient 0:1f9b2707ec7d 463 /*Codes_SRS_MULTITREE_99_038:[If destination is NULL, the function shall return MULTITREE_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 464 else if (destination == NULL)
AzureIoTClient 0:1f9b2707ec7d 465 {
AzureIoTClient 0:1f9b2707ec7d 466 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 467 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 468 }
AzureIoTClient 0:1f9b2707ec7d 469 else
AzureIoTClient 0:1f9b2707ec7d 470 {
AzureIoTClient 17:fa1bba4c6053 471 MULTITREE_HANDLE_DATA *node = (MULTITREE_HANDLE_DATA*)treeHandle;
AzureIoTClient 0:1f9b2707ec7d 472 /*Codes_SRS_MULTITREE_99_051:[ The function returns MULTITREE_EMPTY_CHILD_NAME when used with the root of the tree.]*/
AzureIoTClient 0:1f9b2707ec7d 473 if (node->name == NULL)
AzureIoTClient 0:1f9b2707ec7d 474 {
AzureIoTClient 0:1f9b2707ec7d 475 result = MULTITREE_EMPTY_CHILD_NAME;
AzureIoTClient 11:b1327861f5e0 476 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 477 }
AzureIoTClient 0:1f9b2707ec7d 478 /*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 479 else if (STRING_concat(destination, node->name)!=0)
AzureIoTClient 0:1f9b2707ec7d 480 {
AzureIoTClient 0:1f9b2707ec7d 481 /*Codes_SRS_MULTITREE_99_040:[ The function returns MULTITREE_ERROR to indicate any other error.]*/
AzureIoTClient 0:1f9b2707ec7d 482 result = MULTITREE_ERROR;
AzureIoTClient 11:b1327861f5e0 483 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 484 }
AzureIoTClient 0:1f9b2707ec7d 485 else
AzureIoTClient 0:1f9b2707ec7d 486 {
AzureIoTClient 0:1f9b2707ec7d 487 /*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 488 result = MULTITREE_OK;
AzureIoTClient 0:1f9b2707ec7d 489 }
AzureIoTClient 0:1f9b2707ec7d 490 }
AzureIoTClient 0:1f9b2707ec7d 491
AzureIoTClient 0:1f9b2707ec7d 492 return result;
AzureIoTClient 0:1f9b2707ec7d 493 }
AzureIoTClient 0:1f9b2707ec7d 494
AzureIoTClient 0:1f9b2707ec7d 495 /* Codes_SRS_MULTITREE_99_063:[ MultiTree_GetChildByName shall retrieve the handle of the child node childName from the treeNode node.] */
AzureIoTClient 0:1f9b2707ec7d 496 MULTITREE_RESULT MultiTree_GetChildByName(MULTITREE_HANDLE treeHandle, const char* childName, MULTITREE_HANDLE *childHandle)
AzureIoTClient 0:1f9b2707ec7d 497 {
AzureIoTClient 0:1f9b2707ec7d 498 MULTITREE_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 499
AzureIoTClient 0:1f9b2707ec7d 500 /* Codes_SRS_MULTITREE_99_065:[ If any argument is NULL, MultiTree_GetChildByName shall return MULTITREE_INVALID_ARG.] */
AzureIoTClient 0:1f9b2707ec7d 501 if ((treeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 502 (childHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 503 (childName == NULL))
AzureIoTClient 0:1f9b2707ec7d 504 {
AzureIoTClient 0:1f9b2707ec7d 505 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 506 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 507 }
AzureIoTClient 0:1f9b2707ec7d 508 else
AzureIoTClient 0:1f9b2707ec7d 509 {
AzureIoTClient 17:fa1bba4c6053 510 MULTITREE_HANDLE_DATA * node = (MULTITREE_HANDLE_DATA *)treeHandle;
AzureIoTClient 0:1f9b2707ec7d 511 size_t i;
AzureIoTClient 0:1f9b2707ec7d 512
AzureIoTClient 0:1f9b2707ec7d 513 for (i = 0; i < node->nChildren; i++)
AzureIoTClient 0:1f9b2707ec7d 514 {
AzureIoTClient 0:1f9b2707ec7d 515 if (strcmp(node->children[i]->name, childName) == 0)
AzureIoTClient 0:1f9b2707ec7d 516 {
AzureIoTClient 0:1f9b2707ec7d 517 break;
AzureIoTClient 0:1f9b2707ec7d 518 }
AzureIoTClient 0:1f9b2707ec7d 519 }
AzureIoTClient 0:1f9b2707ec7d 520
AzureIoTClient 0:1f9b2707ec7d 521 if (i == node->nChildren)
AzureIoTClient 0:1f9b2707ec7d 522 {
AzureIoTClient 0:1f9b2707ec7d 523 /* Codes_SRS_MULTITREE_99_068:[ If the specified child is not found, MultiTree_GetChildByName shall return MULTITREE_CHILD_NOT_FOUND.] */
AzureIoTClient 0:1f9b2707ec7d 524 result = MULTITREE_CHILD_NOT_FOUND;
AzureIoTClient 11:b1327861f5e0 525 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 526 }
AzureIoTClient 0:1f9b2707ec7d 527 else
AzureIoTClient 0:1f9b2707ec7d 528 {
AzureIoTClient 0:1f9b2707ec7d 529 /* Codes_SRS_MULTITREE_99_067:[ The child node handle shall be returned in the childHandle argument.] */
AzureIoTClient 0:1f9b2707ec7d 530 *childHandle = node->children[i];
AzureIoTClient 0:1f9b2707ec7d 531
AzureIoTClient 0:1f9b2707ec7d 532 /* Codes_SRS_MULTITREE_99_064:[ On success, MultiTree_GetChildByName shall return MULTITREE_OK.] */
AzureIoTClient 0:1f9b2707ec7d 533 result = MULTITREE_OK;
AzureIoTClient 0:1f9b2707ec7d 534 }
AzureIoTClient 0:1f9b2707ec7d 535 }
AzureIoTClient 0:1f9b2707ec7d 536 return result;
AzureIoTClient 0:1f9b2707ec7d 537 }
AzureIoTClient 0:1f9b2707ec7d 538
AzureIoTClient 0:1f9b2707ec7d 539 MULTITREE_RESULT MultiTree_GetValue(MULTITREE_HANDLE treeHandle, const void** destination)
AzureIoTClient 0:1f9b2707ec7d 540 {
AzureIoTClient 0:1f9b2707ec7d 541 MULTITREE_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 542 /*Codes_SRS_MULTITREE_99_042:[If treeHandle is NULL, the function shall return MULTITREE_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 543 if (treeHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 544 {
AzureIoTClient 0:1f9b2707ec7d 545 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 546 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 547 }
AzureIoTClient 0:1f9b2707ec7d 548 /*Codes_SRS_MULTITREE_99_043:[ If destination is NULL, the function shall return MULTITREE_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 549 else if (destination == NULL)
AzureIoTClient 0:1f9b2707ec7d 550 {
AzureIoTClient 0:1f9b2707ec7d 551 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 552 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 553 }
AzureIoTClient 0:1f9b2707ec7d 554 else
AzureIoTClient 0:1f9b2707ec7d 555 {
AzureIoTClient 17:fa1bba4c6053 556 MULTITREE_HANDLE_DATA * node = (MULTITREE_HANDLE_DATA*)treeHandle;
AzureIoTClient 0:1f9b2707ec7d 557 /*Codes_SRS_MULTITREE_99_044:[ If there is no value in the node then MULTITREE_EMPTY_VALUE shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 558 if (node->value == NULL)
AzureIoTClient 0:1f9b2707ec7d 559 {
AzureIoTClient 0:1f9b2707ec7d 560 result = MULTITREE_EMPTY_VALUE;
AzureIoTClient 11:b1327861f5e0 561 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 562 }
AzureIoTClient 0:1f9b2707ec7d 563 else
AzureIoTClient 0:1f9b2707ec7d 564 {
AzureIoTClient 0:1f9b2707ec7d 565 /*Codes_SRS_MULTITREE_99_041:[This function updates the *destination parameter to the internally stored value.]*/
AzureIoTClient 0:1f9b2707ec7d 566 *destination = node->value;
AzureIoTClient 0:1f9b2707ec7d 567 result = MULTITREE_OK;
AzureIoTClient 0:1f9b2707ec7d 568 }
AzureIoTClient 0:1f9b2707ec7d 569 }
AzureIoTClient 0:1f9b2707ec7d 570 return result;
AzureIoTClient 0:1f9b2707ec7d 571 }
AzureIoTClient 0:1f9b2707ec7d 572
AzureIoTClient 0:1f9b2707ec7d 573 MULTITREE_RESULT MultiTree_SetValue(MULTITREE_HANDLE treeHandle, void* value)
AzureIoTClient 0:1f9b2707ec7d 574 {
AzureIoTClient 0:1f9b2707ec7d 575 MULTITREE_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 576
AzureIoTClient 0:1f9b2707ec7d 577 /* Codes_SRS_MULTITREE_99_074:[ If any argument is NULL, MultiTree_SetValue shall return MULTITREE_INVALID_ARG.] */
AzureIoTClient 0:1f9b2707ec7d 578 if ((treeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 579 (value == NULL))
AzureIoTClient 0:1f9b2707ec7d 580 {
AzureIoTClient 0:1f9b2707ec7d 581 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 582 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 583 }
AzureIoTClient 0:1f9b2707ec7d 584 else
AzureIoTClient 0:1f9b2707ec7d 585 {
AzureIoTClient 17:fa1bba4c6053 586 MULTITREE_HANDLE_DATA * node = (MULTITREE_HANDLE_DATA*)treeHandle;
AzureIoTClient 0:1f9b2707ec7d 587 if (node->value != NULL)
AzureIoTClient 0:1f9b2707ec7d 588 {
AzureIoTClient 0:1f9b2707ec7d 589 /* 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 590 result = MULTITREE_ALREADY_HAS_A_VALUE;
AzureIoTClient 11:b1327861f5e0 591 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 592 }
AzureIoTClient 0:1f9b2707ec7d 593 else
AzureIoTClient 0:1f9b2707ec7d 594 {
AzureIoTClient 0:1f9b2707ec7d 595 /* 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 596 if (node->cloneFunction(&node->value, value) != 0)
AzureIoTClient 0:1f9b2707ec7d 597 {
AzureIoTClient 0:1f9b2707ec7d 598 /* Codes_SRS_MULTITREE_99_075:[ MultiTree_SetValue shall return MULTITREE_ERROR to indicate any other error.] */
AzureIoTClient 0:1f9b2707ec7d 599 result = MULTITREE_ERROR;
AzureIoTClient 11:b1327861f5e0 600 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 601 }
AzureIoTClient 0:1f9b2707ec7d 602 else
AzureIoTClient 0:1f9b2707ec7d 603 {
AzureIoTClient 0:1f9b2707ec7d 604 /* Codes_SRS_MULTITREE_99_073:[ On success, MultiTree_SetValue shall return MULTITREE_OK.] */
AzureIoTClient 0:1f9b2707ec7d 605 result = MULTITREE_OK;
AzureIoTClient 0:1f9b2707ec7d 606 }
AzureIoTClient 0:1f9b2707ec7d 607 }
AzureIoTClient 0:1f9b2707ec7d 608 }
AzureIoTClient 0:1f9b2707ec7d 609 return result;
AzureIoTClient 0:1f9b2707ec7d 610 }
AzureIoTClient 0:1f9b2707ec7d 611
AzureIoTClient 0:1f9b2707ec7d 612 void MultiTree_Destroy(MULTITREE_HANDLE treeHandle)
AzureIoTClient 0:1f9b2707ec7d 613 {
AzureIoTClient 0:1f9b2707ec7d 614 if (treeHandle != NULL)
AzureIoTClient 0:1f9b2707ec7d 615 {
AzureIoTClient 17:fa1bba4c6053 616 MULTITREE_HANDLE_DATA* node = (MULTITREE_HANDLE_DATA*)treeHandle;
AzureIoTClient 0:1f9b2707ec7d 617 size_t i;
AzureIoTClient 0:1f9b2707ec7d 618 for (i = 0; i < node->nChildren;i++)
AzureIoTClient 0:1f9b2707ec7d 619 {
AzureIoTClient 0:1f9b2707ec7d 620 /*Codes_SRS_MULTITREE_99_047:[ This function frees any system resource used by the tree designated by parameter treeHandle]*/
AzureIoTClient 0:1f9b2707ec7d 621 MultiTree_Destroy(node->children[i]);
AzureIoTClient 0:1f9b2707ec7d 622 }
AzureIoTClient 0:1f9b2707ec7d 623 /*Codes_SRS_MULTITREE_99_047:[ This function frees any system resource used by the tree designated by parameter treeHandle]*/
AzureIoTClient 0:1f9b2707ec7d 624 if (node->children != NULL)
AzureIoTClient 0:1f9b2707ec7d 625 {
AzureIoTClient 0:1f9b2707ec7d 626 free(node->children);
AzureIoTClient 0:1f9b2707ec7d 627 node->children = NULL;
AzureIoTClient 0:1f9b2707ec7d 628 }
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->name != NULL)
AzureIoTClient 0:1f9b2707ec7d 632 {
AzureIoTClient 0:1f9b2707ec7d 633 free(node->name);
AzureIoTClient 0:1f9b2707ec7d 634 node->name = 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->value != NULL)
AzureIoTClient 0:1f9b2707ec7d 639 {
AzureIoTClient 0:1f9b2707ec7d 640 node->freeFunction(node->value);
AzureIoTClient 0:1f9b2707ec7d 641 node->value = 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 free(node);
AzureIoTClient 0:1f9b2707ec7d 646 }
AzureIoTClient 0:1f9b2707ec7d 647 }
AzureIoTClient 0:1f9b2707ec7d 648
AzureIoTClient 0:1f9b2707ec7d 649 MULTITREE_RESULT MultiTree_GetLeafValue(MULTITREE_HANDLE treeHandle, const char* leafPath, const void** destination)
AzureIoTClient 0:1f9b2707ec7d 650 {
AzureIoTClient 0:1f9b2707ec7d 651 MULTITREE_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 652
AzureIoTClient 0:1f9b2707ec7d 653 /* Codes_SRS_MULTITREE_99_055:[ If any argument is NULL, MultiTree_GetLeafValue shall return MULTITREE_INVALID_ARG.] */
AzureIoTClient 0:1f9b2707ec7d 654 if ((treeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 655 (leafPath == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 656 (destination == NULL))
AzureIoTClient 0:1f9b2707ec7d 657 {
AzureIoTClient 0:1f9b2707ec7d 658 result = MULTITREE_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 659 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 660 }
AzureIoTClient 0:1f9b2707ec7d 661 /* 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 662 else if (strlen(leafPath) == 0)
AzureIoTClient 0:1f9b2707ec7d 663 {
AzureIoTClient 0:1f9b2707ec7d 664 result = MULTITREE_EMPTY_CHILD_NAME;
AzureIoTClient 11:b1327861f5e0 665 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 666 }
AzureIoTClient 0:1f9b2707ec7d 667 else
AzureIoTClient 0:1f9b2707ec7d 668 {
AzureIoTClient 0:1f9b2707ec7d 669 /*break the path into components*/
AzureIoTClient 0:1f9b2707ec7d 670 /*find the first child name*/
AzureIoTClient 17:fa1bba4c6053 671 MULTITREE_HANDLE_DATA* node = (MULTITREE_HANDLE_DATA *)treeHandle;
AzureIoTClient 0:1f9b2707ec7d 672 const char* pos = leafPath;
AzureIoTClient 0:1f9b2707ec7d 673 const char * whereIsDelimiter;
AzureIoTClient 0:1f9b2707ec7d 674
AzureIoTClient 0:1f9b2707ec7d 675 /*if first character is / then skip it*/
AzureIoTClient 0:1f9b2707ec7d 676 if (*pos == '/')
AzureIoTClient 0:1f9b2707ec7d 677 {
AzureIoTClient 0:1f9b2707ec7d 678 pos++;
AzureIoTClient 0:1f9b2707ec7d 679 }
AzureIoTClient 0:1f9b2707ec7d 680
AzureIoTClient 0:1f9b2707ec7d 681 if (*pos == '\0')
AzureIoTClient 0:1f9b2707ec7d 682 {
AzureIoTClient 0:1f9b2707ec7d 683 /* 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 684 result = MULTITREE_EMPTY_CHILD_NAME;
AzureIoTClient 11:b1327861f5e0 685 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 686 }
AzureIoTClient 0:1f9b2707ec7d 687 else
AzureIoTClient 0:1f9b2707ec7d 688 {
AzureIoTClient 0:1f9b2707ec7d 689 result = MULTITREE_OK;
AzureIoTClient 0:1f9b2707ec7d 690
AzureIoTClient 0:1f9b2707ec7d 691 /* Codes_SRS_MULTITREE_99_056:[ The leafPath argument is a string in the following format: /child1/child12 or child1/child12.] */
AzureIoTClient 0:1f9b2707ec7d 692 /* Codes_SRS_MULTITREE_99_058:[ The last child designates the child that will receive the value.] */
AzureIoTClient 0:1f9b2707ec7d 693 while (*pos != '\0')
AzureIoTClient 0:1f9b2707ec7d 694 {
AzureIoTClient 0:1f9b2707ec7d 695 size_t i;
AzureIoTClient 0:1f9b2707ec7d 696 size_t childCount = node->nChildren;
AzureIoTClient 0:1f9b2707ec7d 697
AzureIoTClient 0:1f9b2707ec7d 698 whereIsDelimiter = pos;
AzureIoTClient 0:1f9b2707ec7d 699
AzureIoTClient 0:1f9b2707ec7d 700 while ((*whereIsDelimiter != '/') && (*whereIsDelimiter != '\0'))
AzureIoTClient 0:1f9b2707ec7d 701 {
AzureIoTClient 0:1f9b2707ec7d 702 whereIsDelimiter++;
AzureIoTClient 0:1f9b2707ec7d 703 }
AzureIoTClient 0:1f9b2707ec7d 704
AzureIoTClient 0:1f9b2707ec7d 705 if (whereIsDelimiter == pos)
AzureIoTClient 0:1f9b2707ec7d 706 {
AzureIoTClient 0:1f9b2707ec7d 707 /* 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 708 result = MULTITREE_EMPTY_CHILD_NAME;
AzureIoTClient 11:b1327861f5e0 709 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 710 break;
AzureIoTClient 0:1f9b2707ec7d 711 }
AzureIoTClient 0:1f9b2707ec7d 712 else if (childCount == 0)
AzureIoTClient 0:1f9b2707ec7d 713 {
AzureIoTClient 0:1f9b2707ec7d 714 /* Codes_SRS_MULTITREE_99_071:[ When the child node is not found, MultiTree_GetLeafValue shall return MULTITREE_CHILD_NOT_FOUND.] */
AzureIoTClient 0:1f9b2707ec7d 715 result = MULTITREE_CHILD_NOT_FOUND;
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
AzureIoTClient 0:1f9b2707ec7d 720 {
AzureIoTClient 0:1f9b2707ec7d 721 for (i = 0; i < childCount; i++)
AzureIoTClient 0:1f9b2707ec7d 722 {
AzureIoTClient 0:1f9b2707ec7d 723 if (strncmp(node->children[i]->name, pos, whereIsDelimiter - pos) == 0)
AzureIoTClient 0:1f9b2707ec7d 724 {
AzureIoTClient 0:1f9b2707ec7d 725 /* Codes_SRS_MULTITREE_99_057:[ Subsequent names designate hierarchical children in the tree.] */
AzureIoTClient 0:1f9b2707ec7d 726 node = node->children[i];
AzureIoTClient 0:1f9b2707ec7d 727 break;
AzureIoTClient 0:1f9b2707ec7d 728 }
AzureIoTClient 0:1f9b2707ec7d 729 }
AzureIoTClient 0:1f9b2707ec7d 730
AzureIoTClient 0:1f9b2707ec7d 731 if (i == childCount)
AzureIoTClient 0:1f9b2707ec7d 732 {
AzureIoTClient 0:1f9b2707ec7d 733 /* Codes_SRS_MULTITREE_99_071:[ When the child node is not found, MultiTree_GetLeafValue shall return MULTITREE_CHILD_NOT_FOUND.] */
AzureIoTClient 0:1f9b2707ec7d 734 result = MULTITREE_CHILD_NOT_FOUND;
AzureIoTClient 11:b1327861f5e0 735 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 736 break;
AzureIoTClient 0:1f9b2707ec7d 737 }
AzureIoTClient 0:1f9b2707ec7d 738 else
AzureIoTClient 0:1f9b2707ec7d 739 {
AzureIoTClient 0:1f9b2707ec7d 740 if (*whereIsDelimiter == '/')
AzureIoTClient 0:1f9b2707ec7d 741 {
AzureIoTClient 0:1f9b2707ec7d 742 pos = whereIsDelimiter + 1;
AzureIoTClient 0:1f9b2707ec7d 743 }
AzureIoTClient 0:1f9b2707ec7d 744 else
AzureIoTClient 0:1f9b2707ec7d 745 {
AzureIoTClient 0:1f9b2707ec7d 746 /* end of path */
AzureIoTClient 0:1f9b2707ec7d 747 pos = whereIsDelimiter;
AzureIoTClient 0:1f9b2707ec7d 748 break;
AzureIoTClient 0:1f9b2707ec7d 749 }
AzureIoTClient 0:1f9b2707ec7d 750 }
AzureIoTClient 0:1f9b2707ec7d 751 }
AzureIoTClient 0:1f9b2707ec7d 752 }
AzureIoTClient 0:1f9b2707ec7d 753
AzureIoTClient 0:1f9b2707ec7d 754 if (*pos == 0)
AzureIoTClient 0:1f9b2707ec7d 755 {
AzureIoTClient 0:1f9b2707ec7d 756 if (node->value == NULL)
AzureIoTClient 0:1f9b2707ec7d 757 {
AzureIoTClient 0:1f9b2707ec7d 758 /* 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 759 result = MULTITREE_EMPTY_VALUE;
AzureIoTClient 11:b1327861f5e0 760 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 761 }
AzureIoTClient 0:1f9b2707ec7d 762 /*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 763 else
AzureIoTClient 0:1f9b2707ec7d 764 {
AzureIoTClient 0:1f9b2707ec7d 765 *destination = node->value;
AzureIoTClient 0:1f9b2707ec7d 766 /* Codes_SRS_MULTITREE_99_054:[ On success, MultiTree_GetLeafValue shall return MULTITREE_OK.] */
AzureIoTClient 0:1f9b2707ec7d 767 result = MULTITREE_OK;
AzureIoTClient 0:1f9b2707ec7d 768 }
AzureIoTClient 0:1f9b2707ec7d 769 }
AzureIoTClient 0:1f9b2707ec7d 770 }
AzureIoTClient 0:1f9b2707ec7d 771 }
AzureIoTClient 0:1f9b2707ec7d 772 return result;
AzureIoTClient 0:1f9b2707ec7d 773 }
AzureIoTClient 26:7c0e6f86d034 774
AzureIoTClient 26:7c0e6f86d034 775 /* Codes_SRS_MULTITREE_99_077:[ MultiTree_DeleteChild shall remove the direct children node (no recursive search) set by childName.] */
AzureIoTClient 26:7c0e6f86d034 776 MULTITREE_RESULT MultiTree_DeleteChild(MULTITREE_HANDLE treeHandle, const char* childName)
AzureIoTClient 26:7c0e6f86d034 777 {
AzureIoTClient 26:7c0e6f86d034 778 MULTITREE_RESULT result;
AzureIoTClient 26:7c0e6f86d034 779 /* Codes_SRS_MULTITREE_99_077:[ If any argument is NULL, MultiTree_DeleteChild shall return MULTITREE_INVALID_ARG.] */
AzureIoTClient 26:7c0e6f86d034 780 if ((treeHandle == NULL) ||
AzureIoTClient 26:7c0e6f86d034 781 (childName == NULL))
AzureIoTClient 26:7c0e6f86d034 782 {
AzureIoTClient 26:7c0e6f86d034 783 result = MULTITREE_INVALID_ARG;
AzureIoTClient 26:7c0e6f86d034 784 LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
AzureIoTClient 26:7c0e6f86d034 785 }
AzureIoTClient 26:7c0e6f86d034 786 else
AzureIoTClient 26:7c0e6f86d034 787 {
AzureIoTClient 26:7c0e6f86d034 788 size_t i;
AzureIoTClient 26:7c0e6f86d034 789 size_t childToRemove = treeHandle->nChildren;
AzureIoTClient 26:7c0e6f86d034 790 MULTITREE_HANDLE treeToRemove = NULL;
AzureIoTClient 26:7c0e6f86d034 791
AzureIoTClient 26:7c0e6f86d034 792 for (i = 0; i < treeHandle->nChildren; i++)
AzureIoTClient 26:7c0e6f86d034 793 {
AzureIoTClient 26:7c0e6f86d034 794 if (0 == strcmp(treeHandle->children[i]->name, childName))
AzureIoTClient 26:7c0e6f86d034 795 {
AzureIoTClient 26:7c0e6f86d034 796 childToRemove = i;
AzureIoTClient 26:7c0e6f86d034 797 treeToRemove = treeHandle->children[childToRemove];
AzureIoTClient 26:7c0e6f86d034 798 break;
AzureIoTClient 26:7c0e6f86d034 799 }
AzureIoTClient 26:7c0e6f86d034 800 }
AzureIoTClient 26:7c0e6f86d034 801
AzureIoTClient 26:7c0e6f86d034 802 if (i == treeHandle->nChildren)
AzureIoTClient 26:7c0e6f86d034 803 {
AzureIoTClient 26:7c0e6f86d034 804 /* Codes_SRS_MULTITREE_99_079:[If childName is not found, MultiTree_DeleteChild shall return MULTITREE_CHILD_NOT_FOUND.] */
AzureIoTClient 26:7c0e6f86d034 805 result = MULTITREE_CHILD_NOT_FOUND;
AzureIoTClient 26:7c0e6f86d034 806 // Don't log error; this function is best effort only. Caller will determine actual error state.
AzureIoTClient 26:7c0e6f86d034 807 }
AzureIoTClient 26:7c0e6f86d034 808 else
AzureIoTClient 26:7c0e6f86d034 809 {
AzureIoTClient 26:7c0e6f86d034 810 for (i = childToRemove; i < treeHandle->nChildren - 1; i++)
AzureIoTClient 26:7c0e6f86d034 811 {
AzureIoTClient 26:7c0e6f86d034 812 treeHandle->children[i] = treeHandle->children[i+1];
AzureIoTClient 26:7c0e6f86d034 813 }
AzureIoTClient 26:7c0e6f86d034 814
AzureIoTClient 26:7c0e6f86d034 815 /* Codes_SRS_MULTITREE_99_077:[ MultiTree_DeleteChild shall remove the direct children node (no recursive search) set by childName */
AzureIoTClient 26:7c0e6f86d034 816 MultiTree_Destroy(treeToRemove);
AzureIoTClient 26:7c0e6f86d034 817
AzureIoTClient 26:7c0e6f86d034 818 // Even though this isn't reachable anymore after decrementing count, NULL out for cleanliness
AzureIoTClient 26:7c0e6f86d034 819 treeHandle->children[treeHandle->nChildren - 1] = NULL;
AzureIoTClient 26:7c0e6f86d034 820 treeHandle->nChildren = treeHandle->nChildren - 1;
AzureIoTClient 26:7c0e6f86d034 821
AzureIoTClient 26:7c0e6f86d034 822 result = MULTITREE_OK;
AzureIoTClient 26:7c0e6f86d034 823 }
AzureIoTClient 26:7c0e6f86d034 824 }
AzureIoTClient 26:7c0e6f86d034 825
AzureIoTClient 26:7c0e6f86d034 826 return result;
AzureIoTClient 26:7c0e6f86d034 827 }
AzureIoTClient 26:7c0e6f86d034 828