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:
Wed Nov 16 21:38:26 2016 -0800
Revision:
17:fa1bba4c6053
Parent:
13:16e88f0cfa5f
Child:
18:58b667752399
1.0.10

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>
AzureIoTClient 0:1f9b2707ec7d 5 #ifdef _CRTDBG_MAP_ALLOC
AzureIoTClient 0:1f9b2707ec7d 6 #include <crtdbg.h>
AzureIoTClient 0:1f9b2707ec7d 7 #endif
Azure.IoT Build 10:c2aee3965a83 8 #include "azure_c_shared_utility/gballoc.h"
AzureIoTClient 0:1f9b2707ec7d 9
AzureIoTClient 0:1f9b2707ec7d 10 #include "schema.h"
Azure.IoT Build 10:c2aee3965a83 11 #include "azure_c_shared_utility/crt_abstractions.h"
Azure.IoT Build 13:16e88f0cfa5f 12 #include "azure_c_shared_utility/xlogging.h"
Azure.IoT Build 10:c2aee3965a83 13 #include "azure_c_shared_utility/vector.h"
AzureIoTClient 0:1f9b2707ec7d 14
AzureIoTClient 0:1f9b2707ec7d 15
AzureIoTClient 0:1f9b2707ec7d 16 DEFINE_ENUM_STRINGS(SCHEMA_RESULT, SCHEMA_RESULT_VALUES);
AzureIoTClient 0:1f9b2707ec7d 17
AzureIoTClient 17:fa1bba4c6053 18 typedef struct SCHEMA_PROPERTY_HANDLE_DATA_TAG
AzureIoTClient 0:1f9b2707ec7d 19 {
AzureIoTClient 0:1f9b2707ec7d 20 const char* PropertyName;
AzureIoTClient 0:1f9b2707ec7d 21 const char* PropertyType;
AzureIoTClient 17:fa1bba4c6053 22 } SCHEMA_PROPERTY_HANDLE_DATA;
AzureIoTClient 17:fa1bba4c6053 23
AzureIoTClient 17:fa1bba4c6053 24 typedef struct SCHEMA_REPORTED_PROPERTY_HANDLE_DATA_TAG
AzureIoTClient 17:fa1bba4c6053 25 {
AzureIoTClient 17:fa1bba4c6053 26 const char* reportedPropertyName;
AzureIoTClient 17:fa1bba4c6053 27 const char* reportedPropertyType;
AzureIoTClient 17:fa1bba4c6053 28 } SCHEMA_REPORTED_PROPERTY_HANDLE_DATA;
AzureIoTClient 0:1f9b2707ec7d 29
AzureIoTClient 17:fa1bba4c6053 30 typedef struct SCHEMA_DESIRED_PROPERTY_HANDLE_DATA_TAG
AzureIoTClient 17:fa1bba4c6053 31 {
AzureIoTClient 17:fa1bba4c6053 32 pfOnDesiredProperty onDesiredProperty;
AzureIoTClient 17:fa1bba4c6053 33 pfDesiredPropertyInitialize desiredPropertInitialize;
AzureIoTClient 17:fa1bba4c6053 34 pfDesiredPropertyDeinitialize desiredPropertDeinitialize;
AzureIoTClient 17:fa1bba4c6053 35 const char* desiredPropertyName;
AzureIoTClient 17:fa1bba4c6053 36 const char* desiredPropertyType;
AzureIoTClient 17:fa1bba4c6053 37 pfDesiredPropertyFromAGENT_DATA_TYPE desiredPropertyFromAGENT_DATA_TYPE;
AzureIoTClient 17:fa1bba4c6053 38 size_t offset;
AzureIoTClient 17:fa1bba4c6053 39 } SCHEMA_DESIRED_PROPERTY_HANDLE_DATA;
AzureIoTClient 17:fa1bba4c6053 40
AzureIoTClient 17:fa1bba4c6053 41 typedef struct SCHEMA_ACTION_ARGUMENT_HANDLE_DATA_TAG
AzureIoTClient 0:1f9b2707ec7d 42 {
AzureIoTClient 0:1f9b2707ec7d 43 const char* Name;
AzureIoTClient 0:1f9b2707ec7d 44 const char* Type;
AzureIoTClient 17:fa1bba4c6053 45 } SCHEMA_ACTION_ARGUMENT_HANDLE_DATA;
AzureIoTClient 0:1f9b2707ec7d 46
AzureIoTClient 17:fa1bba4c6053 47 typedef struct SCHEMA_ACTION_HANDLE_DATA_TAG
AzureIoTClient 0:1f9b2707ec7d 48 {
AzureIoTClient 0:1f9b2707ec7d 49 const char* ActionName;
AzureIoTClient 0:1f9b2707ec7d 50 size_t ArgumentCount;
AzureIoTClient 0:1f9b2707ec7d 51 SCHEMA_ACTION_ARGUMENT_HANDLE* ArgumentHandles;
AzureIoTClient 17:fa1bba4c6053 52 } SCHEMA_ACTION_HANDLE_DATA;
AzureIoTClient 0:1f9b2707ec7d 53
AzureIoTClient 0:1f9b2707ec7d 54 typedef struct MODEL_IN_MODEL_TAG
AzureIoTClient 0:1f9b2707ec7d 55 {
AzureIoTClient 17:fa1bba4c6053 56 pfOnDesiredProperty onDesiredProperty; /*is NULL if not specified or if the model in model is not WITH_DESIRED_PROPERTY*/
AzureIoTClient 17:fa1bba4c6053 57 size_t offset; /*offset of the model in model (offsetof)*/
AzureIoTClient 0:1f9b2707ec7d 58 const char* propertyName;
AzureIoTClient 0:1f9b2707ec7d 59 SCHEMA_MODEL_TYPE_HANDLE modelHandle;
AzureIoTClient 0:1f9b2707ec7d 60 } MODEL_IN_MODEL;
AzureIoTClient 0:1f9b2707ec7d 61
AzureIoTClient 17:fa1bba4c6053 62 typedef struct SCHEMA_MODEL_TYPE_HANDLE_DATA_TAG
AzureIoTClient 0:1f9b2707ec7d 63 {
AzureIoTClient 17:fa1bba4c6053 64 VECTOR_HANDLE desiredProperties; /*holds SCHEMA_DESIRED_PROPERTY_HANDLE_DATA*/
AzureIoTClient 0:1f9b2707ec7d 65 const char* Name;
AzureIoTClient 0:1f9b2707ec7d 66 SCHEMA_HANDLE SchemaHandle;
AzureIoTClient 0:1f9b2707ec7d 67 SCHEMA_PROPERTY_HANDLE* Properties;
AzureIoTClient 0:1f9b2707ec7d 68 size_t PropertyCount;
AzureIoTClient 17:fa1bba4c6053 69 VECTOR_HANDLE reportedProperties; /*holds SCHEMA_REPORTED_PROPERTY_HANDLE*/
AzureIoTClient 0:1f9b2707ec7d 70 SCHEMA_ACTION_HANDLE* Actions;
AzureIoTClient 0:1f9b2707ec7d 71 size_t ActionCount;
AzureIoTClient 0:1f9b2707ec7d 72 VECTOR_HANDLE models;
AzureIoTClient 0:1f9b2707ec7d 73 size_t DeviceCount;
AzureIoTClient 17:fa1bba4c6053 74 } SCHEMA_MODEL_TYPE_HANDLE_DATA;
AzureIoTClient 0:1f9b2707ec7d 75
AzureIoTClient 17:fa1bba4c6053 76 typedef struct SCHEMA_STRUCT_TYPE_HANDLE_DATA_TAG
AzureIoTClient 0:1f9b2707ec7d 77 {
AzureIoTClient 0:1f9b2707ec7d 78 const char* Name;
AzureIoTClient 0:1f9b2707ec7d 79 SCHEMA_PROPERTY_HANDLE* Properties;
AzureIoTClient 0:1f9b2707ec7d 80 size_t PropertyCount;
AzureIoTClient 17:fa1bba4c6053 81 } SCHEMA_STRUCT_TYPE_HANDLE_DATA;
AzureIoTClient 0:1f9b2707ec7d 82
AzureIoTClient 17:fa1bba4c6053 83 typedef struct SCHEMA_HANDLE_DATA_TAG
AzureIoTClient 0:1f9b2707ec7d 84 {
AzureIoTClient 17:fa1bba4c6053 85 void* metadata;
AzureIoTClient 0:1f9b2707ec7d 86 const char* Namespace;
AzureIoTClient 0:1f9b2707ec7d 87 SCHEMA_MODEL_TYPE_HANDLE* ModelTypes;
AzureIoTClient 0:1f9b2707ec7d 88 size_t ModelTypeCount;
AzureIoTClient 0:1f9b2707ec7d 89 SCHEMA_STRUCT_TYPE_HANDLE* StructTypes;
AzureIoTClient 0:1f9b2707ec7d 90 size_t StructTypeCount;
AzureIoTClient 17:fa1bba4c6053 91 } SCHEMA_HANDLE_DATA;
AzureIoTClient 0:1f9b2707ec7d 92
AzureIoTClient 0:1f9b2707ec7d 93 static VECTOR_HANDLE g_schemas = NULL;
AzureIoTClient 0:1f9b2707ec7d 94
AzureIoTClient 0:1f9b2707ec7d 95 static void DestroyProperty(SCHEMA_PROPERTY_HANDLE propertyHandle)
AzureIoTClient 0:1f9b2707ec7d 96 {
AzureIoTClient 17:fa1bba4c6053 97 SCHEMA_PROPERTY_HANDLE_DATA* propertyType = (SCHEMA_PROPERTY_HANDLE_DATA*)propertyHandle;
AzureIoTClient 0:1f9b2707ec7d 98 free((void*)propertyType->PropertyName);
AzureIoTClient 0:1f9b2707ec7d 99 free((void*)propertyType->PropertyType);
AzureIoTClient 0:1f9b2707ec7d 100 free(propertyType);
AzureIoTClient 0:1f9b2707ec7d 101 }
AzureIoTClient 0:1f9b2707ec7d 102
AzureIoTClient 0:1f9b2707ec7d 103 static void DestroyActionArgument(SCHEMA_ACTION_ARGUMENT_HANDLE actionArgumentHandle)
AzureIoTClient 0:1f9b2707ec7d 104 {
AzureIoTClient 17:fa1bba4c6053 105 SCHEMA_ACTION_ARGUMENT_HANDLE_DATA* actionArgument = (SCHEMA_ACTION_ARGUMENT_HANDLE_DATA*)actionArgumentHandle;
AzureIoTClient 0:1f9b2707ec7d 106 if (actionArgument != NULL)
AzureIoTClient 0:1f9b2707ec7d 107 {
AzureIoTClient 0:1f9b2707ec7d 108 free((void*)actionArgument->Name);
AzureIoTClient 0:1f9b2707ec7d 109 free((void*)actionArgument->Type);
AzureIoTClient 0:1f9b2707ec7d 110 free(actionArgument);
AzureIoTClient 0:1f9b2707ec7d 111 }
AzureIoTClient 0:1f9b2707ec7d 112 }
AzureIoTClient 0:1f9b2707ec7d 113
AzureIoTClient 0:1f9b2707ec7d 114 static void DestroyAction(SCHEMA_ACTION_HANDLE actionHandle)
AzureIoTClient 0:1f9b2707ec7d 115 {
AzureIoTClient 17:fa1bba4c6053 116 SCHEMA_ACTION_HANDLE_DATA* action = (SCHEMA_ACTION_HANDLE_DATA*)actionHandle;
AzureIoTClient 0:1f9b2707ec7d 117 if (action != NULL)
AzureIoTClient 0:1f9b2707ec7d 118 {
AzureIoTClient 0:1f9b2707ec7d 119 size_t j;
AzureIoTClient 0:1f9b2707ec7d 120
AzureIoTClient 0:1f9b2707ec7d 121 for (j = 0; j < action->ArgumentCount; j++)
AzureIoTClient 0:1f9b2707ec7d 122 {
AzureIoTClient 0:1f9b2707ec7d 123 DestroyActionArgument(action->ArgumentHandles[j]);
AzureIoTClient 0:1f9b2707ec7d 124 }
AzureIoTClient 0:1f9b2707ec7d 125 free(action->ArgumentHandles);
AzureIoTClient 0:1f9b2707ec7d 126
AzureIoTClient 0:1f9b2707ec7d 127 free((void*)action->ActionName);
AzureIoTClient 0:1f9b2707ec7d 128 free(action);
AzureIoTClient 0:1f9b2707ec7d 129 }
AzureIoTClient 0:1f9b2707ec7d 130 }
AzureIoTClient 0:1f9b2707ec7d 131
AzureIoTClient 0:1f9b2707ec7d 132 static void DestroyStruct(SCHEMA_STRUCT_TYPE_HANDLE structTypeHandle)
AzureIoTClient 0:1f9b2707ec7d 133 {
AzureIoTClient 0:1f9b2707ec7d 134 size_t i;
AzureIoTClient 17:fa1bba4c6053 135 SCHEMA_STRUCT_TYPE_HANDLE_DATA* structType = (SCHEMA_STRUCT_TYPE_HANDLE_DATA*)structTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 136 if (structType != NULL)
AzureIoTClient 0:1f9b2707ec7d 137 {
AzureIoTClient 0:1f9b2707ec7d 138 for (i = 0; i < structType->PropertyCount; i++)
AzureIoTClient 0:1f9b2707ec7d 139 {
AzureIoTClient 0:1f9b2707ec7d 140 DestroyProperty(structType->Properties[i]);
AzureIoTClient 0:1f9b2707ec7d 141 }
AzureIoTClient 0:1f9b2707ec7d 142 free(structType->Properties);
AzureIoTClient 0:1f9b2707ec7d 143
AzureIoTClient 0:1f9b2707ec7d 144 free((void*)structType->Name);
AzureIoTClient 0:1f9b2707ec7d 145
AzureIoTClient 0:1f9b2707ec7d 146 free(structType);
AzureIoTClient 0:1f9b2707ec7d 147 }
AzureIoTClient 0:1f9b2707ec7d 148 }
AzureIoTClient 0:1f9b2707ec7d 149
AzureIoTClient 0:1f9b2707ec7d 150 static void DestroyModel(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle)
AzureIoTClient 0:1f9b2707ec7d 151 {
AzureIoTClient 17:fa1bba4c6053 152 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 153 size_t i, nReportedProperties;
AzureIoTClient 0:1f9b2707ec7d 154
AzureIoTClient 0:1f9b2707ec7d 155 free((void*)modelType->Name);
AzureIoTClient 0:1f9b2707ec7d 156 modelType->Name = NULL;
AzureIoTClient 0:1f9b2707ec7d 157
AzureIoTClient 0:1f9b2707ec7d 158 for (i = 0; i < modelType->PropertyCount; i++)
AzureIoTClient 0:1f9b2707ec7d 159 {
AzureIoTClient 0:1f9b2707ec7d 160 DestroyProperty(modelType->Properties[i]);
AzureIoTClient 0:1f9b2707ec7d 161 }
AzureIoTClient 0:1f9b2707ec7d 162
AzureIoTClient 0:1f9b2707ec7d 163 free(modelType->Properties);
AzureIoTClient 0:1f9b2707ec7d 164
AzureIoTClient 0:1f9b2707ec7d 165 for (i = 0; i < modelType->ActionCount; i++)
AzureIoTClient 0:1f9b2707ec7d 166 {
AzureIoTClient 0:1f9b2707ec7d 167 DestroyAction(modelType->Actions[i]);
AzureIoTClient 0:1f9b2707ec7d 168 }
AzureIoTClient 0:1f9b2707ec7d 169
AzureIoTClient 0:1f9b2707ec7d 170 /*destroy the vector holding the added models. This does not destroy the said models, however, their names shall be*/
AzureIoTClient 0:1f9b2707ec7d 171 for (i = 0; i < VECTOR_size(modelType->models); i++)
AzureIoTClient 0:1f9b2707ec7d 172 {
AzureIoTClient 0:1f9b2707ec7d 173 MODEL_IN_MODEL* temp = (MODEL_IN_MODEL*)VECTOR_element(modelType->models, i);
AzureIoTClient 0:1f9b2707ec7d 174 free((void*)temp->propertyName);
AzureIoTClient 0:1f9b2707ec7d 175 }
AzureIoTClient 17:fa1bba4c6053 176
AzureIoTClient 17:fa1bba4c6053 177 nReportedProperties = VECTOR_size(modelType->reportedProperties);
AzureIoTClient 17:fa1bba4c6053 178 for (i = 0;i < nReportedProperties;i++)
AzureIoTClient 17:fa1bba4c6053 179 {
AzureIoTClient 17:fa1bba4c6053 180 SCHEMA_REPORTED_PROPERTY_HANDLE_DATA* reportedProperty = *(SCHEMA_REPORTED_PROPERTY_HANDLE_DATA **)VECTOR_element(modelType->reportedProperties, i);
AzureIoTClient 17:fa1bba4c6053 181 free((void*)reportedProperty->reportedPropertyName);
AzureIoTClient 17:fa1bba4c6053 182 free((void*)reportedProperty->reportedPropertyType);
AzureIoTClient 17:fa1bba4c6053 183 free(reportedProperty);
AzureIoTClient 17:fa1bba4c6053 184 }
AzureIoTClient 17:fa1bba4c6053 185 VECTOR_destroy(modelType->reportedProperties);
AzureIoTClient 17:fa1bba4c6053 186
AzureIoTClient 17:fa1bba4c6053 187 size_t nDesiredProperties = VECTOR_size(modelType->desiredProperties);
AzureIoTClient 17:fa1bba4c6053 188 for (i = 0;i < nDesiredProperties;i++)
AzureIoTClient 17:fa1bba4c6053 189 {
AzureIoTClient 17:fa1bba4c6053 190 SCHEMA_DESIRED_PROPERTY_HANDLE_DATA* desiredProperty = *(SCHEMA_DESIRED_PROPERTY_HANDLE_DATA **)VECTOR_element(modelType->desiredProperties, i);
AzureIoTClient 17:fa1bba4c6053 191 free((void*)desiredProperty->desiredPropertyName);
AzureIoTClient 17:fa1bba4c6053 192 free((void*)desiredProperty->desiredPropertyType);
AzureIoTClient 17:fa1bba4c6053 193 free(desiredProperty);
AzureIoTClient 17:fa1bba4c6053 194 }
AzureIoTClient 17:fa1bba4c6053 195 VECTOR_destroy(modelType->desiredProperties);
AzureIoTClient 17:fa1bba4c6053 196
AzureIoTClient 0:1f9b2707ec7d 197 VECTOR_clear(modelType->models);
AzureIoTClient 0:1f9b2707ec7d 198 VECTOR_destroy(modelType->models);
AzureIoTClient 0:1f9b2707ec7d 199
AzureIoTClient 0:1f9b2707ec7d 200 free(modelType->Actions);
AzureIoTClient 0:1f9b2707ec7d 201 free(modelType);
AzureIoTClient 0:1f9b2707ec7d 202 }
AzureIoTClient 0:1f9b2707ec7d 203
AzureIoTClient 17:fa1bba4c6053 204 static SCHEMA_RESULT AddModelProperty(SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType, const char* name, const char* type)
AzureIoTClient 0:1f9b2707ec7d 205 {
AzureIoTClient 0:1f9b2707ec7d 206 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 207
AzureIoTClient 0:1f9b2707ec7d 208 /* Codes_SRS_SCHEMA_99_013:[If any of the arguments is NULL, Schema_AddModelProperty shall return SCHEMA_INVALID_ARG.] */
AzureIoTClient 0:1f9b2707ec7d 209 if ((modelType == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 210 (name == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 211 (type == NULL))
AzureIoTClient 0:1f9b2707ec7d 212 {
AzureIoTClient 0:1f9b2707ec7d 213 result = SCHEMA_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 214 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 215 }
AzureIoTClient 0:1f9b2707ec7d 216 else
AzureIoTClient 0:1f9b2707ec7d 217 {
AzureIoTClient 0:1f9b2707ec7d 218 size_t i;
AzureIoTClient 0:1f9b2707ec7d 219
AzureIoTClient 0:1f9b2707ec7d 220 /* Codes_SRS_SCHEMA_99_015:[The property name shall be unique per model, if the same property name is added twice to a model, SCHEMA_DUPLICATE_ELEMENT shall be returned.] */
AzureIoTClient 0:1f9b2707ec7d 221 for (i = 0; i < modelType->PropertyCount; i++)
AzureIoTClient 0:1f9b2707ec7d 222 {
AzureIoTClient 17:fa1bba4c6053 223 SCHEMA_PROPERTY_HANDLE_DATA* property = (SCHEMA_PROPERTY_HANDLE_DATA*)modelType->Properties[i];
AzureIoTClient 0:1f9b2707ec7d 224 if (strcmp(property->PropertyName, name) == 0)
AzureIoTClient 0:1f9b2707ec7d 225 {
AzureIoTClient 0:1f9b2707ec7d 226 break;
AzureIoTClient 0:1f9b2707ec7d 227 }
AzureIoTClient 0:1f9b2707ec7d 228 }
AzureIoTClient 0:1f9b2707ec7d 229
AzureIoTClient 0:1f9b2707ec7d 230 if (i < modelType->PropertyCount)
AzureIoTClient 0:1f9b2707ec7d 231 {
AzureIoTClient 0:1f9b2707ec7d 232 result = SCHEMA_DUPLICATE_ELEMENT;
AzureIoTClient 11:b1327861f5e0 233 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 234 }
AzureIoTClient 0:1f9b2707ec7d 235 else
AzureIoTClient 0:1f9b2707ec7d 236 {
AzureIoTClient 0:1f9b2707ec7d 237 SCHEMA_PROPERTY_HANDLE* newProperties = (SCHEMA_PROPERTY_HANDLE*)realloc(modelType->Properties, sizeof(SCHEMA_PROPERTY_HANDLE) * (modelType->PropertyCount + 1));
AzureIoTClient 0:1f9b2707ec7d 238 if (newProperties == NULL)
AzureIoTClient 0:1f9b2707ec7d 239 {
AzureIoTClient 0:1f9b2707ec7d 240 /* Codes_SRS_SCHEMA_99_014:[On any other error, Schema_AddModelProperty shall return SCHEMA_ERROR.] */
AzureIoTClient 0:1f9b2707ec7d 241 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 242 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 243 }
AzureIoTClient 0:1f9b2707ec7d 244 else
AzureIoTClient 0:1f9b2707ec7d 245 {
AzureIoTClient 17:fa1bba4c6053 246 SCHEMA_PROPERTY_HANDLE_DATA* newProperty;
AzureIoTClient 0:1f9b2707ec7d 247
AzureIoTClient 0:1f9b2707ec7d 248 modelType->Properties = newProperties;
AzureIoTClient 17:fa1bba4c6053 249 if ((newProperty = (SCHEMA_PROPERTY_HANDLE_DATA*)malloc(sizeof(SCHEMA_PROPERTY_HANDLE_DATA))) == NULL)
AzureIoTClient 0:1f9b2707ec7d 250 {
AzureIoTClient 0:1f9b2707ec7d 251 /* Codes_SRS_SCHEMA_99_014:[On any other error, Schema_AddModelProperty shall return SCHEMA_ERROR.] */
AzureIoTClient 0:1f9b2707ec7d 252 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 253 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 254 }
AzureIoTClient 0:1f9b2707ec7d 255 else
AzureIoTClient 0:1f9b2707ec7d 256 {
AzureIoTClient 0:1f9b2707ec7d 257 if (mallocAndStrcpy_s((char**)&newProperty->PropertyName, name) != 0)
AzureIoTClient 0:1f9b2707ec7d 258 {
AzureIoTClient 0:1f9b2707ec7d 259 /* Codes_SRS_SCHEMA_99_014:[On any other error, Schema_AddModelProperty shall return SCHEMA_ERROR.] */
AzureIoTClient 0:1f9b2707ec7d 260 free(newProperty);
AzureIoTClient 0:1f9b2707ec7d 261 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 262 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 263 }
AzureIoTClient 0:1f9b2707ec7d 264 else if (mallocAndStrcpy_s((char**)&newProperty->PropertyType, type) != 0)
AzureIoTClient 0:1f9b2707ec7d 265 {
AzureIoTClient 0:1f9b2707ec7d 266 /* Codes_SRS_SCHEMA_99_014:[On any other error, Schema_AddModelProperty shall return SCHEMA_ERROR.] */
AzureIoTClient 0:1f9b2707ec7d 267 free((void*)newProperty->PropertyName);
AzureIoTClient 0:1f9b2707ec7d 268 free(newProperty);
AzureIoTClient 0:1f9b2707ec7d 269 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 270 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 271 }
AzureIoTClient 0:1f9b2707ec7d 272 else
AzureIoTClient 0:1f9b2707ec7d 273 {
AzureIoTClient 0:1f9b2707ec7d 274 modelType->Properties[modelType->PropertyCount] = (SCHEMA_PROPERTY_HANDLE)newProperty;
AzureIoTClient 0:1f9b2707ec7d 275 modelType->PropertyCount++;
AzureIoTClient 0:1f9b2707ec7d 276
AzureIoTClient 0:1f9b2707ec7d 277 /* Codes_SRS_SCHEMA_99_012:[On success, Schema_AddModelProperty shall return SCHEMA_OK.] */
AzureIoTClient 0:1f9b2707ec7d 278 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 279 }
AzureIoTClient 0:1f9b2707ec7d 280 }
AzureIoTClient 0:1f9b2707ec7d 281
AzureIoTClient 0:1f9b2707ec7d 282 /* If possible, reduce the memory of over allocation */
AzureIoTClient 0:1f9b2707ec7d 283 if (result != SCHEMA_OK)
AzureIoTClient 0:1f9b2707ec7d 284 {
AzureIoTClient 0:1f9b2707ec7d 285 SCHEMA_PROPERTY_HANDLE* oldProperties = (SCHEMA_PROPERTY_HANDLE*)realloc(modelType->Properties, sizeof(SCHEMA_PROPERTY_HANDLE) * modelType->PropertyCount);
AzureIoTClient 0:1f9b2707ec7d 286 if (oldProperties == NULL)
AzureIoTClient 0:1f9b2707ec7d 287 {
AzureIoTClient 0:1f9b2707ec7d 288 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 289 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 290 }
AzureIoTClient 0:1f9b2707ec7d 291 else
AzureIoTClient 0:1f9b2707ec7d 292 {
AzureIoTClient 0:1f9b2707ec7d 293 modelType->Properties = oldProperties;
AzureIoTClient 0:1f9b2707ec7d 294 }
AzureIoTClient 0:1f9b2707ec7d 295 }
AzureIoTClient 0:1f9b2707ec7d 296 }
AzureIoTClient 0:1f9b2707ec7d 297 }
AzureIoTClient 0:1f9b2707ec7d 298 }
AzureIoTClient 0:1f9b2707ec7d 299
AzureIoTClient 0:1f9b2707ec7d 300 return result;
AzureIoTClient 0:1f9b2707ec7d 301 }
AzureIoTClient 0:1f9b2707ec7d 302
AzureIoTClient 0:1f9b2707ec7d 303 static bool SchemaHandlesMatch(const SCHEMA_HANDLE* handle, const SCHEMA_HANDLE* otherHandle)
AzureIoTClient 0:1f9b2707ec7d 304 {
AzureIoTClient 0:1f9b2707ec7d 305 return (*handle == *otherHandle);
AzureIoTClient 0:1f9b2707ec7d 306 }
AzureIoTClient 0:1f9b2707ec7d 307
AzureIoTClient 0:1f9b2707ec7d 308 static bool SchemaNamespacesMatch(const SCHEMA_HANDLE* handle, const char* schemaNamespace)
AzureIoTClient 0:1f9b2707ec7d 309 {
AzureIoTClient 17:fa1bba4c6053 310 const SCHEMA_HANDLE_DATA* schema = (SCHEMA_HANDLE_DATA*)*handle;
AzureIoTClient 0:1f9b2707ec7d 311 return (strcmp(schema->Namespace, schemaNamespace) == 0);
AzureIoTClient 0:1f9b2707ec7d 312 }
AzureIoTClient 0:1f9b2707ec7d 313
AzureIoTClient 0:1f9b2707ec7d 314 /* Codes_SRS_SCHEMA_99_001:[Schema_Create shall initialize a schema with a given namespace.] */
AzureIoTClient 17:fa1bba4c6053 315 SCHEMA_HANDLE Schema_Create(const char* schemaNamespace, void* metadata)
AzureIoTClient 0:1f9b2707ec7d 316 {
AzureIoTClient 17:fa1bba4c6053 317 SCHEMA_HANDLE_DATA* result;
AzureIoTClient 17:fa1bba4c6053 318 /*Codes_SRS_SCHEMA_02_090: [ If metadata is NULL then Schema_Create shall fail and return NULL. ]*/
AzureIoTClient 0:1f9b2707ec7d 319 /* Codes_SRS_SCHEMA_99_004:[If schemaNamespace is NULL, Schema_Create shall fail.] */
AzureIoTClient 17:fa1bba4c6053 320 if (
AzureIoTClient 17:fa1bba4c6053 321 (schemaNamespace == NULL)||
AzureIoTClient 17:fa1bba4c6053 322 (metadata == NULL)
AzureIoTClient 17:fa1bba4c6053 323 )
AzureIoTClient 0:1f9b2707ec7d 324 {
AzureIoTClient 0:1f9b2707ec7d 325 /* Codes_SRS_SCHEMA_99_003:[On failure, NULL shall be returned.] */
AzureIoTClient 17:fa1bba4c6053 326 LogError("invalid arg const char* schemaNamespace=%p, void* metadata=%p",schemaNamespace, metadata);
AzureIoTClient 0:1f9b2707ec7d 327 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 328 }
AzureIoTClient 0:1f9b2707ec7d 329 else
AzureIoTClient 0:1f9b2707ec7d 330 {
AzureIoTClient 17:fa1bba4c6053 331 if (g_schemas == NULL && (g_schemas = VECTOR_create(sizeof(SCHEMA_HANDLE_DATA*) ) ) == NULL)
AzureIoTClient 0:1f9b2707ec7d 332 {
AzureIoTClient 0:1f9b2707ec7d 333 /* Codes_SRS_SCHEMA_99_003:[On failure, NULL shall be returned.] */
AzureIoTClient 0:1f9b2707ec7d 334 result = NULL;
AzureIoTClient 11:b1327861f5e0 335 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 336 }
AzureIoTClient 17:fa1bba4c6053 337 else if ((result = (SCHEMA_HANDLE_DATA*)malloc(sizeof(SCHEMA_HANDLE_DATA))) == NULL)
AzureIoTClient 0:1f9b2707ec7d 338 {
AzureIoTClient 0:1f9b2707ec7d 339 /* Codes_SRS_SCHEMA_99_003:[On failure, NULL shall be returned.] */
AzureIoTClient 11:b1327861f5e0 340 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 341 }
AzureIoTClient 0:1f9b2707ec7d 342 else if (mallocAndStrcpy_s((char**)&result->Namespace, schemaNamespace) != 0)
AzureIoTClient 0:1f9b2707ec7d 343 {
AzureIoTClient 0:1f9b2707ec7d 344 /* Codes_SRS_SCHEMA_99_003:[On failure, NULL shall be returned.] */
AzureIoTClient 0:1f9b2707ec7d 345 free(result);
AzureIoTClient 0:1f9b2707ec7d 346 result = NULL;
AzureIoTClient 11:b1327861f5e0 347 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 348 }
AzureIoTClient 0:1f9b2707ec7d 349 else if (VECTOR_push_back(g_schemas, &result, 1) != 0)
AzureIoTClient 0:1f9b2707ec7d 350 {
AzureIoTClient 0:1f9b2707ec7d 351 free((void*)result->Namespace);
AzureIoTClient 0:1f9b2707ec7d 352 free(result);
AzureIoTClient 0:1f9b2707ec7d 353 result = NULL;
AzureIoTClient 11:b1327861f5e0 354 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 355 }
AzureIoTClient 0:1f9b2707ec7d 356 else
AzureIoTClient 0:1f9b2707ec7d 357 {
AzureIoTClient 0:1f9b2707ec7d 358 /* Codes_SRS_SCHEMA_99_002:[On success a non-NULL handle to the newly created schema shall be returned.] */
AzureIoTClient 0:1f9b2707ec7d 359 result->ModelTypes = NULL;
AzureIoTClient 0:1f9b2707ec7d 360 result->ModelTypeCount = 0;
AzureIoTClient 0:1f9b2707ec7d 361 result->StructTypes = NULL;
AzureIoTClient 0:1f9b2707ec7d 362 result->StructTypeCount = 0;
AzureIoTClient 17:fa1bba4c6053 363 result->metadata = metadata;
AzureIoTClient 0:1f9b2707ec7d 364 }
AzureIoTClient 0:1f9b2707ec7d 365 }
AzureIoTClient 0:1f9b2707ec7d 366
AzureIoTClient 0:1f9b2707ec7d 367 return (SCHEMA_HANDLE)result;
AzureIoTClient 0:1f9b2707ec7d 368 }
AzureIoTClient 0:1f9b2707ec7d 369
AzureIoTClient 0:1f9b2707ec7d 370 size_t Schema_GetSchemaCount(void)
AzureIoTClient 0:1f9b2707ec7d 371 {
AzureIoTClient 0:1f9b2707ec7d 372 /* Codes_SRS_SCHEMA_99_153: [Schema_GetSchemaCount shall return the number of "active" schemas (all schemas created with Schema_Create
AzureIoTClient 0:1f9b2707ec7d 373 in the current process, for which Schema_Destroy has not been called).] */
AzureIoTClient 0:1f9b2707ec7d 374 return VECTOR_size(g_schemas);
AzureIoTClient 0:1f9b2707ec7d 375 }
AzureIoTClient 0:1f9b2707ec7d 376
AzureIoTClient 0:1f9b2707ec7d 377 SCHEMA_HANDLE Schema_GetSchemaByNamespace(const char* schemaNamespace)
AzureIoTClient 0:1f9b2707ec7d 378 {
AzureIoTClient 0:1f9b2707ec7d 379 /* Codes_SRS_SCHEMA_99_151: [If no active schema matches the schemaNamespace argument, Schema_GetSchemaByNamespace shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 380 SCHEMA_HANDLE result = NULL;
AzureIoTClient 0:1f9b2707ec7d 381
AzureIoTClient 0:1f9b2707ec7d 382 /* Codes_SRS_SCHEMA_99_150: [If the schemaNamespace argument is NULL, Schema_GetSchemaByNamespace shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 383 if (schemaNamespace != NULL)
AzureIoTClient 0:1f9b2707ec7d 384 {
AzureIoTClient 0:1f9b2707ec7d 385 SCHEMA_HANDLE* handle = (SCHEMA_HANDLE*)VECTOR_find_if(g_schemas, (PREDICATE_FUNCTION)SchemaNamespacesMatch, schemaNamespace);
AzureIoTClient 0:1f9b2707ec7d 386 if (handle != NULL)
AzureIoTClient 0:1f9b2707ec7d 387 {
AzureIoTClient 0:1f9b2707ec7d 388 /* Codes_SRS_SCHEMA_99_148: [Schema_GetSchemaByNamespace shall search all active schemas and return the schema with the
AzureIoTClient 0:1f9b2707ec7d 389 namespace given by the schemaNamespace argument.] */
AzureIoTClient 0:1f9b2707ec7d 390 result = *handle;
AzureIoTClient 0:1f9b2707ec7d 391 }
AzureIoTClient 0:1f9b2707ec7d 392 }
AzureIoTClient 0:1f9b2707ec7d 393
AzureIoTClient 0:1f9b2707ec7d 394 return result;
AzureIoTClient 0:1f9b2707ec7d 395 }
AzureIoTClient 0:1f9b2707ec7d 396
AzureIoTClient 0:1f9b2707ec7d 397 const char* Schema_GetSchemaNamespace(SCHEMA_HANDLE schemaHandle)
AzureIoTClient 0:1f9b2707ec7d 398 {
AzureIoTClient 0:1f9b2707ec7d 399 const char* result;
AzureIoTClient 0:1f9b2707ec7d 400
AzureIoTClient 0:1f9b2707ec7d 401 /* Codes_SRS_SCHEMA_99_130: [If the schemaHandle argument is NULL, Schema_GetSchemaNamespace shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 402 if (schemaHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 403 {
AzureIoTClient 0:1f9b2707ec7d 404 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 405 }
AzureIoTClient 0:1f9b2707ec7d 406 else
AzureIoTClient 0:1f9b2707ec7d 407 {
AzureIoTClient 0:1f9b2707ec7d 408 /* Codes_SRS_SCHEMA_99_129: [Schema_GetSchemaNamespace shall return the namespace for the schema identified by schemaHandle.] */
AzureIoTClient 17:fa1bba4c6053 409 result = ((SCHEMA_HANDLE_DATA*)schemaHandle)->Namespace;
AzureIoTClient 0:1f9b2707ec7d 410 }
AzureIoTClient 0:1f9b2707ec7d 411
AzureIoTClient 0:1f9b2707ec7d 412 return result;
AzureIoTClient 0:1f9b2707ec7d 413 }
AzureIoTClient 0:1f9b2707ec7d 414
AzureIoTClient 0:1f9b2707ec7d 415 void Schema_Destroy(SCHEMA_HANDLE schemaHandle)
AzureIoTClient 0:1f9b2707ec7d 416 {
AzureIoTClient 0:1f9b2707ec7d 417 /* Codes_SRS_SCHEMA_99_006:[If the schemaHandle is NULL, Schema_Destroy shall do nothing.] */
AzureIoTClient 0:1f9b2707ec7d 418 if (schemaHandle != NULL)
AzureIoTClient 0:1f9b2707ec7d 419 {
AzureIoTClient 17:fa1bba4c6053 420 SCHEMA_HANDLE_DATA* schema = (SCHEMA_HANDLE_DATA*)schemaHandle;
AzureIoTClient 0:1f9b2707ec7d 421 size_t i;
AzureIoTClient 0:1f9b2707ec7d 422
AzureIoTClient 0:1f9b2707ec7d 423 /* Codes_SRS_SCHEMA_99_005:[Schema_Destroy shall free all resources associated with a schema.] */
AzureIoTClient 0:1f9b2707ec7d 424 for (i = 0; i < schema->ModelTypeCount; i++)
AzureIoTClient 0:1f9b2707ec7d 425 {
AzureIoTClient 0:1f9b2707ec7d 426 DestroyModel(schema->ModelTypes[i]);
AzureIoTClient 0:1f9b2707ec7d 427 }
AzureIoTClient 0:1f9b2707ec7d 428
AzureIoTClient 0:1f9b2707ec7d 429 free(schema->ModelTypes);
AzureIoTClient 0:1f9b2707ec7d 430
AzureIoTClient 0:1f9b2707ec7d 431 /* Codes_SRS_SCHEMA_99_005:[Schema_Destroy shall free all resources associated with a schema.] */
AzureIoTClient 0:1f9b2707ec7d 432 for (i = 0; i < schema->StructTypeCount; i++)
AzureIoTClient 0:1f9b2707ec7d 433 {
AzureIoTClient 0:1f9b2707ec7d 434 DestroyStruct(schema->StructTypes[i]);
AzureIoTClient 0:1f9b2707ec7d 435 }
AzureIoTClient 0:1f9b2707ec7d 436
AzureIoTClient 0:1f9b2707ec7d 437 free(schema->StructTypes);
AzureIoTClient 0:1f9b2707ec7d 438 free((void*)schema->Namespace);
AzureIoTClient 0:1f9b2707ec7d 439 free(schema);
AzureIoTClient 0:1f9b2707ec7d 440
AzureIoTClient 17:fa1bba4c6053 441 schema = (SCHEMA_HANDLE_DATA*)VECTOR_find_if(g_schemas, (PREDICATE_FUNCTION)SchemaHandlesMatch, &schemaHandle);
AzureIoTClient 0:1f9b2707ec7d 442 if (schema != NULL)
AzureIoTClient 0:1f9b2707ec7d 443 {
AzureIoTClient 0:1f9b2707ec7d 444 VECTOR_erase(g_schemas, schema, 1);
AzureIoTClient 0:1f9b2707ec7d 445 }
AzureIoTClient 0:1f9b2707ec7d 446 // If the g_schema is empty then destroy it
AzureIoTClient 0:1f9b2707ec7d 447 if (VECTOR_size(g_schemas) == 0)
AzureIoTClient 0:1f9b2707ec7d 448 {
AzureIoTClient 0:1f9b2707ec7d 449 VECTOR_destroy(g_schemas);
AzureIoTClient 0:1f9b2707ec7d 450 g_schemas = NULL;
AzureIoTClient 0:1f9b2707ec7d 451 }
AzureIoTClient 0:1f9b2707ec7d 452 }
AzureIoTClient 0:1f9b2707ec7d 453 }
AzureIoTClient 0:1f9b2707ec7d 454
AzureIoTClient 0:1f9b2707ec7d 455 SCHEMA_RESULT Schema_DestroyIfUnused(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle)
AzureIoTClient 0:1f9b2707ec7d 456 {
AzureIoTClient 0:1f9b2707ec7d 457 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 458
AzureIoTClient 0:1f9b2707ec7d 459 /* Codes_SRS_SCHEMA_07_189: [If modelHandle variable is NULL Schema_DestroyIfUnused shall do nothing.] */
AzureIoTClient 0:1f9b2707ec7d 460 if (modelTypeHandle != NULL)
AzureIoTClient 0:1f9b2707ec7d 461 {
AzureIoTClient 0:1f9b2707ec7d 462 SCHEMA_HANDLE schemaHandle = Schema_GetSchemaForModelType(modelTypeHandle);
AzureIoTClient 0:1f9b2707ec7d 463 if (schemaHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 464 {
AzureIoTClient 0:1f9b2707ec7d 465 result = SCHEMA_ERROR;
AzureIoTClient 0:1f9b2707ec7d 466 }
AzureIoTClient 0:1f9b2707ec7d 467 else
AzureIoTClient 0:1f9b2707ec7d 468 {
AzureIoTClient 17:fa1bba4c6053 469 SCHEMA_HANDLE_DATA* schema = (SCHEMA_HANDLE_DATA*)schemaHandle;
AzureIoTClient 0:1f9b2707ec7d 470 size_t nIndex;
AzureIoTClient 0:1f9b2707ec7d 471
AzureIoTClient 0:1f9b2707ec7d 472 /* Codes_SRS_SCHEMA_07_190: [Schema_DestroyIfUnused shall iterate through the ModuleTypes objects and if all the DeviceCount variables 0 then it will delete the schemaHandle.] */
AzureIoTClient 0:1f9b2707ec7d 473 for (nIndex = 0; nIndex < schema->ModelTypeCount; nIndex++)
AzureIoTClient 0:1f9b2707ec7d 474 {
AzureIoTClient 17:fa1bba4c6053 475 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)schema->ModelTypes[nIndex];
AzureIoTClient 0:1f9b2707ec7d 476 if (modelType->DeviceCount > 0)
AzureIoTClient 0:1f9b2707ec7d 477 break;
AzureIoTClient 0:1f9b2707ec7d 478 }
AzureIoTClient 0:1f9b2707ec7d 479 /* Codes_SRS_SCHEMA_07_191: [If 1 or more DeviceCount variables are > 0 then Schema_DestroyIfUnused shall do nothing.] */
AzureIoTClient 0:1f9b2707ec7d 480 if (nIndex == schema->ModelTypeCount)
AzureIoTClient 0:1f9b2707ec7d 481 {
AzureIoTClient 0:1f9b2707ec7d 482 Schema_Destroy(schemaHandle);
AzureIoTClient 0:1f9b2707ec7d 483 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 484 }
AzureIoTClient 0:1f9b2707ec7d 485 else
AzureIoTClient 0:1f9b2707ec7d 486 {
AzureIoTClient 0:1f9b2707ec7d 487 result = SCHEMA_MODEL_IN_USE;
AzureIoTClient 0:1f9b2707ec7d 488 }
AzureIoTClient 0:1f9b2707ec7d 489 }
AzureIoTClient 0:1f9b2707ec7d 490 }
AzureIoTClient 0:1f9b2707ec7d 491 else
AzureIoTClient 0:1f9b2707ec7d 492 {
AzureIoTClient 0:1f9b2707ec7d 493 result = SCHEMA_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 494 }
AzureIoTClient 0:1f9b2707ec7d 495 return result;
AzureIoTClient 0:1f9b2707ec7d 496 }
AzureIoTClient 0:1f9b2707ec7d 497
AzureIoTClient 0:1f9b2707ec7d 498 SCHEMA_RESULT Schema_AddDeviceRef(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle)
AzureIoTClient 0:1f9b2707ec7d 499 {
AzureIoTClient 0:1f9b2707ec7d 500 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 501 if (modelTypeHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 502 {
AzureIoTClient 0:1f9b2707ec7d 503 /* Codes_SRS_SCHEMA_07_187: [Schema_AddDeviceRef shall return SCHEMA_INVALID_ARG if modelTypeHandle is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 504 result = SCHEMA_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 505 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 506 }
AzureIoTClient 0:1f9b2707ec7d 507 else
AzureIoTClient 0:1f9b2707ec7d 508 {
AzureIoTClient 17:fa1bba4c6053 509 SCHEMA_MODEL_TYPE_HANDLE_DATA* model = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 510 /* Codes_SRS_SCHEMA_07_188: [If the modelTypeHandle is nonNULL, Schema_AddDeviceRef shall increment the SCHEMA_MODEL_TYPE_HANDLE_DATA DeviceCount variable.] */
AzureIoTClient 0:1f9b2707ec7d 511 model->DeviceCount++;
AzureIoTClient 0:1f9b2707ec7d 512 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 513 }
AzureIoTClient 0:1f9b2707ec7d 514 return result;
AzureIoTClient 0:1f9b2707ec7d 515 }
AzureIoTClient 0:1f9b2707ec7d 516
AzureIoTClient 0:1f9b2707ec7d 517 SCHEMA_RESULT Schema_ReleaseDeviceRef(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle)
AzureIoTClient 0:1f9b2707ec7d 518 {
AzureIoTClient 0:1f9b2707ec7d 519 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 520 /* Codes_SRS_SCHEMA_07_184: [Schema_DeviceRelease shall do nothing if the supplied modelHandle is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 521 if (modelTypeHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 522 {
AzureIoTClient 0:1f9b2707ec7d 523 result = SCHEMA_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 524 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 525 }
AzureIoTClient 0:1f9b2707ec7d 526 else
AzureIoTClient 0:1f9b2707ec7d 527 {
AzureIoTClient 17:fa1bba4c6053 528 SCHEMA_MODEL_TYPE_HANDLE_DATA* model = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 529 if (model->DeviceCount > 0)
AzureIoTClient 0:1f9b2707ec7d 530 {
AzureIoTClient 0:1f9b2707ec7d 531 /* Codes_SRS_SCHEMA_07_186: [On a nonNULL SCHEMA_MODEL_TYPE_HANDLE if the DeviceCount variable is > 0 then the variable will be decremented.] */
AzureIoTClient 0:1f9b2707ec7d 532 model->DeviceCount--;
AzureIoTClient 0:1f9b2707ec7d 533 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 534 }
AzureIoTClient 0:1f9b2707ec7d 535 else
AzureIoTClient 0:1f9b2707ec7d 536 {
AzureIoTClient 17:fa1bba4c6053 537 result = SCHEMA_DEVICE_COUNT_ZERO;
AzureIoTClient 17:fa1bba4c6053 538 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 539 }
AzureIoTClient 0:1f9b2707ec7d 540 }
AzureIoTClient 0:1f9b2707ec7d 541 return result;
AzureIoTClient 0:1f9b2707ec7d 542 }
AzureIoTClient 0:1f9b2707ec7d 543
AzureIoTClient 0:1f9b2707ec7d 544 /* Codes_SRS_SCHEMA_99_007:[Schema_CreateModelType shall create a new model type and return a handle to it.] */
AzureIoTClient 0:1f9b2707ec7d 545 SCHEMA_MODEL_TYPE_HANDLE Schema_CreateModelType(SCHEMA_HANDLE schemaHandle, const char* modelName)
AzureIoTClient 0:1f9b2707ec7d 546 {
AzureIoTClient 0:1f9b2707ec7d 547 SCHEMA_MODEL_TYPE_HANDLE result;
AzureIoTClient 0:1f9b2707ec7d 548
AzureIoTClient 0:1f9b2707ec7d 549 /* Codes_SRS_SCHEMA_99_010:[If any of the arguments is NULL, Schema_CreateModelType shall fail.] */
AzureIoTClient 0:1f9b2707ec7d 550 if ((schemaHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 551 (modelName == NULL))
AzureIoTClient 0:1f9b2707ec7d 552 {
AzureIoTClient 0:1f9b2707ec7d 553 /* Codes_SRS_SCHEMA_99_009:[On failure, Schema_CreateModelType shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 554 result = NULL;
AzureIoTClient 11:b1327861f5e0 555 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 556 }
AzureIoTClient 0:1f9b2707ec7d 557 else
AzureIoTClient 0:1f9b2707ec7d 558 {
AzureIoTClient 17:fa1bba4c6053 559 SCHEMA_HANDLE_DATA* schema = (SCHEMA_HANDLE_DATA*)schemaHandle;
AzureIoTClient 0:1f9b2707ec7d 560
AzureIoTClient 0:1f9b2707ec7d 561 /* Codes_SRS_SCHEMA_99_100: [Schema_CreateModelType shall return SCHEMA_DUPLICATE_ELEMENT if modelName already exists.] */
AzureIoTClient 0:1f9b2707ec7d 562 size_t i;
AzureIoTClient 0:1f9b2707ec7d 563 for (i = 0; i < schema->ModelTypeCount; i++)
AzureIoTClient 0:1f9b2707ec7d 564 {
AzureIoTClient 17:fa1bba4c6053 565 SCHEMA_MODEL_TYPE_HANDLE_DATA* model = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)(schema->ModelTypes[i]);
AzureIoTClient 0:1f9b2707ec7d 566 if (strcmp(model->Name, modelName) == 0)
AzureIoTClient 0:1f9b2707ec7d 567 {
AzureIoTClient 0:1f9b2707ec7d 568 break;
AzureIoTClient 0:1f9b2707ec7d 569 }
AzureIoTClient 0:1f9b2707ec7d 570 }
AzureIoTClient 0:1f9b2707ec7d 571
AzureIoTClient 0:1f9b2707ec7d 572 if (i < schema->ModelTypeCount)
AzureIoTClient 0:1f9b2707ec7d 573 {
AzureIoTClient 0:1f9b2707ec7d 574 /* Codes_SRS_SCHEMA_99_009:[On failure, Schema_CreateModelType shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 575 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 576 LogError("%s Model Name already exists", modelName);
AzureIoTClient 0:1f9b2707ec7d 577 }
AzureIoTClient 0:1f9b2707ec7d 578
AzureIoTClient 0:1f9b2707ec7d 579 else
AzureIoTClient 0:1f9b2707ec7d 580 {
AzureIoTClient 0:1f9b2707ec7d 581 SCHEMA_MODEL_TYPE_HANDLE* newModelTypes = (SCHEMA_MODEL_TYPE_HANDLE*)realloc(schema->ModelTypes, sizeof(SCHEMA_MODEL_TYPE_HANDLE) * (schema->ModelTypeCount + 1));
AzureIoTClient 0:1f9b2707ec7d 582 if (newModelTypes == NULL)
AzureIoTClient 0:1f9b2707ec7d 583 {
AzureIoTClient 0:1f9b2707ec7d 584 /* Codes_SRS_SCHEMA_99_009:[On failure, Schema_CreateModelType shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 585 result = NULL;
AzureIoTClient 11:b1327861f5e0 586 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 587 }
AzureIoTClient 0:1f9b2707ec7d 588 else
AzureIoTClient 0:1f9b2707ec7d 589 {
AzureIoTClient 17:fa1bba4c6053 590 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType;
AzureIoTClient 0:1f9b2707ec7d 591 schema->ModelTypes = newModelTypes;
AzureIoTClient 0:1f9b2707ec7d 592
AzureIoTClient 17:fa1bba4c6053 593 if ((modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)malloc(sizeof(SCHEMA_MODEL_TYPE_HANDLE_DATA))) == NULL)
AzureIoTClient 0:1f9b2707ec7d 594 {
AzureIoTClient 0:1f9b2707ec7d 595
AzureIoTClient 0:1f9b2707ec7d 596 /* Codes_SRS_SCHEMA_99_009:[On failure, Schema_CreateModelType shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 597 result = NULL;
AzureIoTClient 11:b1327861f5e0 598 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 599 }
AzureIoTClient 0:1f9b2707ec7d 600 else if (mallocAndStrcpy_s((char**)&modelType->Name, modelName) != 0)
AzureIoTClient 0:1f9b2707ec7d 601 {
AzureIoTClient 0:1f9b2707ec7d 602 /* Codes_SRS_SCHEMA_99_009:[On failure, Schema_CreateModelType shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 603 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 604 free(modelType);
AzureIoTClient 11:b1327861f5e0 605 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 606 }
AzureIoTClient 0:1f9b2707ec7d 607 else
AzureIoTClient 0:1f9b2707ec7d 608 {
AzureIoTClient 17:fa1bba4c6053 609 modelType->models = VECTOR_create(sizeof(MODEL_IN_MODEL));
AzureIoTClient 17:fa1bba4c6053 610 if (modelType->models == NULL)
AzureIoTClient 17:fa1bba4c6053 611 {
AzureIoTClient 17:fa1bba4c6053 612 LogError("unable to VECTOR_create");
AzureIoTClient 17:fa1bba4c6053 613 free((void*)modelType->Name);
AzureIoTClient 17:fa1bba4c6053 614 free((void*)modelType);
AzureIoTClient 17:fa1bba4c6053 615 result = NULL;
AzureIoTClient 17:fa1bba4c6053 616 }
AzureIoTClient 17:fa1bba4c6053 617 else
AzureIoTClient 17:fa1bba4c6053 618 {
AzureIoTClient 17:fa1bba4c6053 619 if ((modelType->reportedProperties = VECTOR_create(sizeof(SCHEMA_REPORTED_PROPERTY_HANDLE))) == NULL)
AzureIoTClient 17:fa1bba4c6053 620 {
AzureIoTClient 17:fa1bba4c6053 621 LogError("failed to VECTOR_create (reported properties)");
AzureIoTClient 17:fa1bba4c6053 622 VECTOR_destroy(modelType->models);
AzureIoTClient 17:fa1bba4c6053 623 free((void*)modelType->Name);
AzureIoTClient 17:fa1bba4c6053 624 free((void*)modelType);
AzureIoTClient 17:fa1bba4c6053 625 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 626
AzureIoTClient 17:fa1bba4c6053 627 }
AzureIoTClient 17:fa1bba4c6053 628 else
AzureIoTClient 17:fa1bba4c6053 629 {
AzureIoTClient 17:fa1bba4c6053 630 if ((modelType->desiredProperties = VECTOR_create(sizeof(SCHEMA_DESIRED_PROPERTY_HANDLE))) == NULL)
AzureIoTClient 17:fa1bba4c6053 631 {
AzureIoTClient 17:fa1bba4c6053 632 LogError("failure in VECTOR_create (desired properties)");
AzureIoTClient 17:fa1bba4c6053 633 VECTOR_destroy(modelType->reportedProperties);
AzureIoTClient 17:fa1bba4c6053 634 VECTOR_destroy(modelType->models);
AzureIoTClient 17:fa1bba4c6053 635 free((void*)modelType->Name);
AzureIoTClient 17:fa1bba4c6053 636 free((void*)modelType);
AzureIoTClient 17:fa1bba4c6053 637 result = NULL;
AzureIoTClient 17:fa1bba4c6053 638 }
AzureIoTClient 17:fa1bba4c6053 639 else
AzureIoTClient 17:fa1bba4c6053 640 {
AzureIoTClient 17:fa1bba4c6053 641 modelType->PropertyCount = 0;
AzureIoTClient 17:fa1bba4c6053 642 modelType->Properties = NULL;
AzureIoTClient 17:fa1bba4c6053 643 modelType->ActionCount = 0;
AzureIoTClient 17:fa1bba4c6053 644 modelType->Actions = NULL;
AzureIoTClient 17:fa1bba4c6053 645 modelType->SchemaHandle = schemaHandle;
AzureIoTClient 17:fa1bba4c6053 646 modelType->DeviceCount = 0;
AzureIoTClient 17:fa1bba4c6053 647
AzureIoTClient 17:fa1bba4c6053 648 schema->ModelTypes[schema->ModelTypeCount] = modelType;
AzureIoTClient 17:fa1bba4c6053 649 schema->ModelTypeCount++;
AzureIoTClient 17:fa1bba4c6053 650 /* Codes_SRS_SCHEMA_99_008:[On success, a non-NULL handle shall be returned.] */
AzureIoTClient 17:fa1bba4c6053 651 result = (SCHEMA_MODEL_TYPE_HANDLE)modelType;
AzureIoTClient 17:fa1bba4c6053 652 }
AzureIoTClient 17:fa1bba4c6053 653 }
AzureIoTClient 17:fa1bba4c6053 654 }
AzureIoTClient 0:1f9b2707ec7d 655 }
AzureIoTClient 0:1f9b2707ec7d 656
AzureIoTClient 0:1f9b2707ec7d 657 /* If possible, reduce the memory of over allocation */
AzureIoTClient 17:fa1bba4c6053 658 if ((result == NULL) &&(schema->ModelTypeCount>0))
AzureIoTClient 0:1f9b2707ec7d 659 {
AzureIoTClient 0:1f9b2707ec7d 660 SCHEMA_MODEL_TYPE_HANDLE* oldModelTypes = (SCHEMA_MODEL_TYPE_HANDLE*)realloc(schema->ModelTypes, sizeof(SCHEMA_MODEL_TYPE_HANDLE) * schema->ModelTypeCount);
AzureIoTClient 0:1f9b2707ec7d 661 if (oldModelTypes == NULL)
AzureIoTClient 0:1f9b2707ec7d 662 {
AzureIoTClient 11:b1327861f5e0 663 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 664 }
AzureIoTClient 0:1f9b2707ec7d 665 else
AzureIoTClient 0:1f9b2707ec7d 666 {
AzureIoTClient 0:1f9b2707ec7d 667 schema->ModelTypes = oldModelTypes;
AzureIoTClient 0:1f9b2707ec7d 668 }
AzureIoTClient 0:1f9b2707ec7d 669 }
AzureIoTClient 0:1f9b2707ec7d 670 }
AzureIoTClient 0:1f9b2707ec7d 671 }
AzureIoTClient 0:1f9b2707ec7d 672 }
AzureIoTClient 0:1f9b2707ec7d 673
AzureIoTClient 0:1f9b2707ec7d 674 return result;
AzureIoTClient 0:1f9b2707ec7d 675 }
AzureIoTClient 0:1f9b2707ec7d 676
AzureIoTClient 0:1f9b2707ec7d 677 SCHEMA_HANDLE Schema_GetSchemaForModelType(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle)
AzureIoTClient 0:1f9b2707ec7d 678 {
AzureIoTClient 0:1f9b2707ec7d 679 SCHEMA_HANDLE result;
AzureIoTClient 0:1f9b2707ec7d 680
AzureIoTClient 0:1f9b2707ec7d 681 if (modelTypeHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 682 {
AzureIoTClient 0:1f9b2707ec7d 683 /* Codes_SRS_SCHEMA_99_132: [If the modelTypeHandle argument is NULL, Schema_GetSchemaForModelType shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 684 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 685 }
AzureIoTClient 0:1f9b2707ec7d 686 else
AzureIoTClient 0:1f9b2707ec7d 687 {
AzureIoTClient 0:1f9b2707ec7d 688 /* Codes_SRS_SCHEMA_99_131: [Schema_GetSchemaForModelType returns the schema handle for a given model type.] */
AzureIoTClient 17:fa1bba4c6053 689 result = ((SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle)->SchemaHandle;
AzureIoTClient 0:1f9b2707ec7d 690 }
AzureIoTClient 0:1f9b2707ec7d 691
AzureIoTClient 0:1f9b2707ec7d 692 return result;
AzureIoTClient 0:1f9b2707ec7d 693 }
AzureIoTClient 0:1f9b2707ec7d 694
AzureIoTClient 0:1f9b2707ec7d 695 /* Codes_SRS_SCHEMA_99_011:[Schema_AddModelProperty shall add one property to the model type identified by modelTypeHandle.] */
AzureIoTClient 0:1f9b2707ec7d 696 SCHEMA_RESULT Schema_AddModelProperty(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* propertyName, const char* propertyType)
AzureIoTClient 0:1f9b2707ec7d 697 {
AzureIoTClient 17:fa1bba4c6053 698 return AddModelProperty((SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle, propertyName, propertyType);
AzureIoTClient 17:fa1bba4c6053 699 }
AzureIoTClient 17:fa1bba4c6053 700
AzureIoTClient 17:fa1bba4c6053 701 static bool reportedPropertyExists(const void* element, const void* value)
AzureIoTClient 17:fa1bba4c6053 702 {
AzureIoTClient 17:fa1bba4c6053 703 SCHEMA_REPORTED_PROPERTY_HANDLE_DATA* reportedProperty = *(SCHEMA_REPORTED_PROPERTY_HANDLE_DATA**)element;
AzureIoTClient 17:fa1bba4c6053 704 return (strcmp(reportedProperty->reportedPropertyName, value) == 0);
AzureIoTClient 17:fa1bba4c6053 705 }
AzureIoTClient 17:fa1bba4c6053 706
AzureIoTClient 17:fa1bba4c6053 707 SCHEMA_RESULT Schema_AddModelReportedProperty(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* reportedPropertyName, const char* reportedPropertyType)
AzureIoTClient 17:fa1bba4c6053 708 {
AzureIoTClient 17:fa1bba4c6053 709 SCHEMA_RESULT result;
AzureIoTClient 17:fa1bba4c6053 710 /*Codes_SRS_SCHEMA_02_001: [ If modelTypeHandle is NULL then Schema_AddModelReportedProperty shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 711 /*Codes_SRS_SCHEMA_02_002: [ If reportedPropertyName is NULL then Schema_AddModelReportedProperty shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 712 /*Codes_SRS_SCHEMA_02_003: [ If reportedPropertyType is NULL then Schema_AddModelReportedProperty shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 713 if (
AzureIoTClient 17:fa1bba4c6053 714 (modelTypeHandle == NULL) ||
AzureIoTClient 17:fa1bba4c6053 715 (reportedPropertyName == NULL) ||
AzureIoTClient 17:fa1bba4c6053 716 (reportedPropertyType == NULL)
AzureIoTClient 17:fa1bba4c6053 717 )
AzureIoTClient 17:fa1bba4c6053 718 {
AzureIoTClient 17:fa1bba4c6053 719 LogError("invalid argument SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle=%p, const char* reportedPropertyName=%p, const char* reportedPropertyType=%p", modelTypeHandle, reportedPropertyName, reportedPropertyType);
AzureIoTClient 17:fa1bba4c6053 720 result = SCHEMA_INVALID_ARG;
AzureIoTClient 17:fa1bba4c6053 721 }
AzureIoTClient 17:fa1bba4c6053 722 else
AzureIoTClient 17:fa1bba4c6053 723 {
AzureIoTClient 17:fa1bba4c6053 724 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 725 /*Codes_SRS_SCHEMA_02_004: [ If reportedPropertyName has already been added then Schema_AddModelReportedProperty shall fail and return SCHEMA_PROPERTY_ELEMENT_EXISTS. ]*/
AzureIoTClient 17:fa1bba4c6053 726 if (VECTOR_find_if(modelType->reportedProperties, reportedPropertyExists, reportedPropertyName) != NULL)
AzureIoTClient 17:fa1bba4c6053 727 {
AzureIoTClient 17:fa1bba4c6053 728 LogError("unable to add reportedProperty %s because it already exists", reportedPropertyName);
AzureIoTClient 17:fa1bba4c6053 729 result = SCHEMA_DUPLICATE_ELEMENT;
AzureIoTClient 17:fa1bba4c6053 730 }
AzureIoTClient 17:fa1bba4c6053 731 else
AzureIoTClient 17:fa1bba4c6053 732 {
AzureIoTClient 17:fa1bba4c6053 733 /*Codes_SRS_SCHEMA_02_005: [ Schema_AddModelReportedProperty shall record reportedPropertyName and reportedPropertyType. ]*/
AzureIoTClient 17:fa1bba4c6053 734 SCHEMA_REPORTED_PROPERTY_HANDLE_DATA* reportedProperty = (SCHEMA_REPORTED_PROPERTY_HANDLE_DATA*)malloc(sizeof(SCHEMA_REPORTED_PROPERTY_HANDLE_DATA));
AzureIoTClient 17:fa1bba4c6053 735 if (reportedProperty == NULL)
AzureIoTClient 17:fa1bba4c6053 736 {
AzureIoTClient 17:fa1bba4c6053 737 /*Codes_SRS_SCHEMA_02_006: [ If any error occurs then Schema_AddModelReportedProperty shall fail and return SCHEMA_ERROR. ]*/
AzureIoTClient 17:fa1bba4c6053 738 LogError("unable to malloc");
AzureIoTClient 17:fa1bba4c6053 739 result = SCHEMA_ERROR;
AzureIoTClient 17:fa1bba4c6053 740 }
AzureIoTClient 17:fa1bba4c6053 741 else
AzureIoTClient 17:fa1bba4c6053 742 {
AzureIoTClient 17:fa1bba4c6053 743 if (mallocAndStrcpy_s((char**)&reportedProperty->reportedPropertyName, reportedPropertyName) != 0)
AzureIoTClient 17:fa1bba4c6053 744 {
AzureIoTClient 17:fa1bba4c6053 745 /*Codes_SRS_SCHEMA_02_006: [ If any error occurs then Schema_AddModelReportedProperty shall fail and return SCHEMA_ERROR. ]*/
AzureIoTClient 17:fa1bba4c6053 746 LogError("unable to mallocAndStrcpy_s");
AzureIoTClient 17:fa1bba4c6053 747 free(reportedProperty);
AzureIoTClient 17:fa1bba4c6053 748 result = SCHEMA_ERROR;
AzureIoTClient 17:fa1bba4c6053 749 }
AzureIoTClient 17:fa1bba4c6053 750 else
AzureIoTClient 17:fa1bba4c6053 751 {
AzureIoTClient 17:fa1bba4c6053 752 if (mallocAndStrcpy_s((char**)&reportedProperty->reportedPropertyType, reportedPropertyType) != 0)
AzureIoTClient 17:fa1bba4c6053 753 {
AzureIoTClient 17:fa1bba4c6053 754 /*Codes_SRS_SCHEMA_02_006: [ If any error occurs then Schema_AddModelReportedProperty shall fail and return SCHEMA_ERROR. ]*/
AzureIoTClient 17:fa1bba4c6053 755 LogError("unable to mallocAndStrcpy_s");
AzureIoTClient 17:fa1bba4c6053 756 free((void*)reportedProperty->reportedPropertyName);
AzureIoTClient 17:fa1bba4c6053 757 free(reportedProperty);
AzureIoTClient 17:fa1bba4c6053 758 result = SCHEMA_ERROR;
AzureIoTClient 17:fa1bba4c6053 759 }
AzureIoTClient 17:fa1bba4c6053 760 else
AzureIoTClient 17:fa1bba4c6053 761 {
AzureIoTClient 17:fa1bba4c6053 762 if (VECTOR_push_back(modelType->reportedProperties, &reportedProperty, 1) != 0)
AzureIoTClient 17:fa1bba4c6053 763 {
AzureIoTClient 17:fa1bba4c6053 764 /*Codes_SRS_SCHEMA_02_006: [ If any error occurs then Schema_AddModelReportedProperty shall fail and return SCHEMA_ERROR. ]*/
AzureIoTClient 17:fa1bba4c6053 765 LogError("unable to VECTOR_push_back");
AzureIoTClient 17:fa1bba4c6053 766 free((void*)reportedProperty->reportedPropertyType);
AzureIoTClient 17:fa1bba4c6053 767 free((void*)reportedProperty->reportedPropertyName);
AzureIoTClient 17:fa1bba4c6053 768 free(reportedProperty);
AzureIoTClient 17:fa1bba4c6053 769 result = SCHEMA_ERROR;
AzureIoTClient 17:fa1bba4c6053 770 }
AzureIoTClient 17:fa1bba4c6053 771 else
AzureIoTClient 17:fa1bba4c6053 772 {
AzureIoTClient 17:fa1bba4c6053 773 /*Codes_SRS_SCHEMA_02_007: [ Otherwise Schema_AddModelReportedProperty shall succeed and return SCHEMA_OK. ]*/
AzureIoTClient 17:fa1bba4c6053 774 result = SCHEMA_OK;
AzureIoTClient 17:fa1bba4c6053 775 }
AzureIoTClient 17:fa1bba4c6053 776 }
AzureIoTClient 17:fa1bba4c6053 777 }
AzureIoTClient 17:fa1bba4c6053 778 }
AzureIoTClient 17:fa1bba4c6053 779 }
AzureIoTClient 17:fa1bba4c6053 780 }
AzureIoTClient 17:fa1bba4c6053 781 return result;
AzureIoTClient 0:1f9b2707ec7d 782 }
AzureIoTClient 0:1f9b2707ec7d 783
AzureIoTClient 0:1f9b2707ec7d 784 SCHEMA_ACTION_HANDLE Schema_CreateModelAction(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* actionName)
AzureIoTClient 0:1f9b2707ec7d 785 {
AzureIoTClient 0:1f9b2707ec7d 786 SCHEMA_ACTION_HANDLE result;
AzureIoTClient 0:1f9b2707ec7d 787
AzureIoTClient 0:1f9b2707ec7d 788 /* Codes_SRS_SCHEMA_99_104: [If any of the modelTypeHandle or actionName arguments is NULL, Schema_CreateModelAction shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 789 if ((modelTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 790 (actionName == NULL))
AzureIoTClient 0:1f9b2707ec7d 791 {
AzureIoTClient 0:1f9b2707ec7d 792 result = NULL;
AzureIoTClient 11:b1327861f5e0 793 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 794 }
AzureIoTClient 0:1f9b2707ec7d 795 else
AzureIoTClient 0:1f9b2707ec7d 796 {
AzureIoTClient 17:fa1bba4c6053 797 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 798 size_t i;
AzureIoTClient 0:1f9b2707ec7d 799
AzureIoTClient 0:1f9b2707ec7d 800 /* Codes_SRS_SCHEMA_99_105: [The action name shall be unique per model, if the same action name is added twice to a model, Schema_CreateModelAction shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 801 for (i = 0; i < modelType->ActionCount; i++)
AzureIoTClient 0:1f9b2707ec7d 802 {
AzureIoTClient 17:fa1bba4c6053 803 SCHEMA_ACTION_HANDLE_DATA* action = (SCHEMA_ACTION_HANDLE_DATA*)modelType->Actions[i];
AzureIoTClient 0:1f9b2707ec7d 804 if (strcmp(action->ActionName, actionName) == 0)
AzureIoTClient 0:1f9b2707ec7d 805 {
AzureIoTClient 0:1f9b2707ec7d 806 break;
AzureIoTClient 0:1f9b2707ec7d 807 }
AzureIoTClient 0:1f9b2707ec7d 808 }
AzureIoTClient 0:1f9b2707ec7d 809
AzureIoTClient 0:1f9b2707ec7d 810 if (i < modelType->ActionCount)
AzureIoTClient 0:1f9b2707ec7d 811 {
AzureIoTClient 0:1f9b2707ec7d 812 result = NULL;
AzureIoTClient 11:b1327861f5e0 813 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_DUPLICATE_ELEMENT));
AzureIoTClient 0:1f9b2707ec7d 814 }
AzureIoTClient 0:1f9b2707ec7d 815 else
AzureIoTClient 0:1f9b2707ec7d 816 {
AzureIoTClient 0:1f9b2707ec7d 817 /* Codes_SRS_SCHEMA_99_102: [Schema_CreateModelAction shall add one action to the model type identified by modelTypeHandle.] */
AzureIoTClient 0:1f9b2707ec7d 818 SCHEMA_ACTION_HANDLE* newActions = (SCHEMA_ACTION_HANDLE*)realloc(modelType->Actions, sizeof(SCHEMA_ACTION_HANDLE) * (modelType->ActionCount + 1));
AzureIoTClient 0:1f9b2707ec7d 819 if (newActions == NULL)
AzureIoTClient 0:1f9b2707ec7d 820 {
AzureIoTClient 0:1f9b2707ec7d 821 /* Codes_SRS_SCHEMA_99_106: [On any other error, Schema_CreateModelAction shall return NULL.]*/
AzureIoTClient 0:1f9b2707ec7d 822 result = NULL;
AzureIoTClient 11:b1327861f5e0 823 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 824 }
AzureIoTClient 0:1f9b2707ec7d 825 else
AzureIoTClient 0:1f9b2707ec7d 826 {
AzureIoTClient 17:fa1bba4c6053 827 SCHEMA_ACTION_HANDLE_DATA* newAction;
AzureIoTClient 0:1f9b2707ec7d 828 modelType->Actions = newActions;
AzureIoTClient 0:1f9b2707ec7d 829
AzureIoTClient 0:1f9b2707ec7d 830 /* Codes_SRS_SCHEMA_99_103: [On success, Schema_CreateModelAction shall return a none-NULL SCHEMA_ACTION_HANDLE to the newly created action.] */
AzureIoTClient 17:fa1bba4c6053 831 if ((newAction = (SCHEMA_ACTION_HANDLE_DATA*)malloc(sizeof(SCHEMA_ACTION_HANDLE_DATA))) == NULL)
AzureIoTClient 0:1f9b2707ec7d 832 {
AzureIoTClient 0:1f9b2707ec7d 833 /* Codes_SRS_SCHEMA_99_106: [On any other error, Schema_CreateModelAction shall return NULL.]*/
AzureIoTClient 0:1f9b2707ec7d 834 result = NULL;
AzureIoTClient 11:b1327861f5e0 835 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 836 }
AzureIoTClient 0:1f9b2707ec7d 837 else
AzureIoTClient 0:1f9b2707ec7d 838 {
AzureIoTClient 0:1f9b2707ec7d 839 if (mallocAndStrcpy_s((char**)&newAction->ActionName, actionName) != 0)
AzureIoTClient 0:1f9b2707ec7d 840 {
AzureIoTClient 0:1f9b2707ec7d 841 /* Codes_SRS_SCHEMA_99_106: [On any other error, Schema_CreateModelAction shall return NULL.]*/
AzureIoTClient 0:1f9b2707ec7d 842 free(newAction);
AzureIoTClient 0:1f9b2707ec7d 843 result = NULL;
AzureIoTClient 11:b1327861f5e0 844 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 845 }
AzureIoTClient 0:1f9b2707ec7d 846 else
AzureIoTClient 0:1f9b2707ec7d 847 {
AzureIoTClient 0:1f9b2707ec7d 848 newAction->ArgumentCount = 0;
AzureIoTClient 0:1f9b2707ec7d 849 newAction->ArgumentHandles = NULL;
AzureIoTClient 0:1f9b2707ec7d 850
AzureIoTClient 0:1f9b2707ec7d 851 modelType->Actions[modelType->ActionCount] = newAction;
AzureIoTClient 0:1f9b2707ec7d 852 modelType->ActionCount++;
AzureIoTClient 0:1f9b2707ec7d 853 result = (SCHEMA_ACTION_HANDLE)(newAction);
AzureIoTClient 0:1f9b2707ec7d 854 }
AzureIoTClient 0:1f9b2707ec7d 855
AzureIoTClient 0:1f9b2707ec7d 856 /* If possible, reduce the memory of over allocation */
AzureIoTClient 0:1f9b2707ec7d 857 if (result == NULL)
AzureIoTClient 0:1f9b2707ec7d 858 {
AzureIoTClient 0:1f9b2707ec7d 859 SCHEMA_ACTION_HANDLE* oldActions = (SCHEMA_ACTION_HANDLE*)realloc(modelType->Actions, sizeof(SCHEMA_ACTION_HANDLE) * modelType->ActionCount);
AzureIoTClient 0:1f9b2707ec7d 860 if (oldActions == NULL)
AzureIoTClient 0:1f9b2707ec7d 861 {
AzureIoTClient 11:b1327861f5e0 862 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 863 }
AzureIoTClient 0:1f9b2707ec7d 864 else
AzureIoTClient 0:1f9b2707ec7d 865 {
AzureIoTClient 0:1f9b2707ec7d 866 modelType->Actions = oldActions;
AzureIoTClient 0:1f9b2707ec7d 867 }
AzureIoTClient 0:1f9b2707ec7d 868 }
AzureIoTClient 0:1f9b2707ec7d 869 }
AzureIoTClient 0:1f9b2707ec7d 870 }
AzureIoTClient 0:1f9b2707ec7d 871 }
AzureIoTClient 0:1f9b2707ec7d 872 }
AzureIoTClient 0:1f9b2707ec7d 873 return result;
AzureIoTClient 0:1f9b2707ec7d 874 }
AzureIoTClient 0:1f9b2707ec7d 875
AzureIoTClient 0:1f9b2707ec7d 876 SCHEMA_RESULT Schema_AddModelActionArgument(SCHEMA_ACTION_HANDLE actionHandle, const char* argumentName, const char* argumentType)
AzureIoTClient 0:1f9b2707ec7d 877 {
AzureIoTClient 0:1f9b2707ec7d 878 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 879
AzureIoTClient 0:1f9b2707ec7d 880 /* Codes_SRS_SCHEMA_99_109: [If any of the arguments is NULL, Schema_AddModelActionArgument shall return SCHEMA_INVALID_ARG.] */
AzureIoTClient 0:1f9b2707ec7d 881 if ((actionHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 882 (argumentName == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 883 (argumentType == NULL))
AzureIoTClient 0:1f9b2707ec7d 884 {
AzureIoTClient 0:1f9b2707ec7d 885 result = SCHEMA_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 886 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 887 }
AzureIoTClient 0:1f9b2707ec7d 888 else
AzureIoTClient 0:1f9b2707ec7d 889 {
AzureIoTClient 17:fa1bba4c6053 890 SCHEMA_ACTION_HANDLE_DATA* action = (SCHEMA_ACTION_HANDLE_DATA*)actionHandle;
AzureIoTClient 0:1f9b2707ec7d 891
AzureIoTClient 0:1f9b2707ec7d 892 /* Codes_SRS_SCHEMA_99_110: [The argument name shall be unique per action, if the same name is added twice to an action, SCHEMA_DUPLICATE_ELEMENT shall be returned.] */
AzureIoTClient 0:1f9b2707ec7d 893 /* Codes_SRS_SCHEMA_99_111: [Schema_AddModelActionArgument shall accept arguments with different names of the same type.] */
AzureIoTClient 0:1f9b2707ec7d 894 size_t i;
AzureIoTClient 0:1f9b2707ec7d 895 for (i = 0; i < action->ArgumentCount; i++)
AzureIoTClient 0:1f9b2707ec7d 896 {
AzureIoTClient 17:fa1bba4c6053 897 SCHEMA_ACTION_ARGUMENT_HANDLE_DATA* actionArgument = (SCHEMA_ACTION_ARGUMENT_HANDLE_DATA*)action->ArgumentHandles[i];
AzureIoTClient 0:1f9b2707ec7d 898 if (strcmp((actionArgument->Name), argumentName) == 0)
AzureIoTClient 0:1f9b2707ec7d 899 {
AzureIoTClient 0:1f9b2707ec7d 900 break;
AzureIoTClient 0:1f9b2707ec7d 901 }
AzureIoTClient 0:1f9b2707ec7d 902 }
AzureIoTClient 0:1f9b2707ec7d 903
AzureIoTClient 0:1f9b2707ec7d 904 if (i < action->ArgumentCount)
AzureIoTClient 0:1f9b2707ec7d 905 {
AzureIoTClient 0:1f9b2707ec7d 906 result = SCHEMA_DUPLICATE_ELEMENT;
AzureIoTClient 11:b1327861f5e0 907 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 908 }
AzureIoTClient 0:1f9b2707ec7d 909 else
AzureIoTClient 0:1f9b2707ec7d 910 {
AzureIoTClient 0:1f9b2707ec7d 911 /* Codes_SRS_SCHEMA_99_107: [Schema_AddModelActionArgument shall add one argument name & type to an action identified by actionHandle.] */
AzureIoTClient 0:1f9b2707ec7d 912 SCHEMA_ACTION_ARGUMENT_HANDLE* newArguments = (SCHEMA_ACTION_ARGUMENT_HANDLE*)realloc(action->ArgumentHandles, sizeof(SCHEMA_ACTION_ARGUMENT_HANDLE) * (action->ArgumentCount + 1));
AzureIoTClient 0:1f9b2707ec7d 913 if (newArguments == NULL)
AzureIoTClient 0:1f9b2707ec7d 914 {
AzureIoTClient 0:1f9b2707ec7d 915 /* Codes_SRS_SCHEMA_99_112: [On any other error, Schema_ AddModelActionArgumet shall return SCHEMA_ERROR.] */
AzureIoTClient 0:1f9b2707ec7d 916 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 917 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 918 }
AzureIoTClient 0:1f9b2707ec7d 919 else
AzureIoTClient 0:1f9b2707ec7d 920 {
AzureIoTClient 17:fa1bba4c6053 921 SCHEMA_ACTION_ARGUMENT_HANDLE_DATA* newActionArgument;
AzureIoTClient 17:fa1bba4c6053 922 if ((newActionArgument = (SCHEMA_ACTION_ARGUMENT_HANDLE_DATA*)malloc(sizeof(SCHEMA_ACTION_ARGUMENT_HANDLE_DATA))) == NULL)
AzureIoTClient 0:1f9b2707ec7d 923 {
AzureIoTClient 0:1f9b2707ec7d 924 /* Codes_SRS_SCHEMA_99_112: [On any other error, Schema_ AddModelActionArgumet shall return SCHEMA_ERROR.] */
AzureIoTClient 0:1f9b2707ec7d 925 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 926 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 927 }
AzureIoTClient 0:1f9b2707ec7d 928 else
AzureIoTClient 0:1f9b2707ec7d 929 {
AzureIoTClient 0:1f9b2707ec7d 930 if (mallocAndStrcpy_s((char**)&newActionArgument->Name, argumentName) != 0)
AzureIoTClient 0:1f9b2707ec7d 931 {
AzureIoTClient 0:1f9b2707ec7d 932 /* Codes_SRS_SCHEMA_99_112: [On any other error, Schema_ AddModelActionArgumet shall return SCHEMA_ERROR.] */
AzureIoTClient 0:1f9b2707ec7d 933 free(newActionArgument);
AzureIoTClient 0:1f9b2707ec7d 934 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 935 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 936 }
AzureIoTClient 0:1f9b2707ec7d 937 else if (mallocAndStrcpy_s((char**)&newActionArgument->Type, argumentType) != 0)
AzureIoTClient 0:1f9b2707ec7d 938 {
AzureIoTClient 0:1f9b2707ec7d 939 /* Codes_SRS_SCHEMA_99_112: [On any other error, Schema_ AddModelActionArgumet shall return SCHEMA_ERROR.] */
AzureIoTClient 0:1f9b2707ec7d 940 free((void*)newActionArgument->Name);
AzureIoTClient 0:1f9b2707ec7d 941 free(newActionArgument);
AzureIoTClient 0:1f9b2707ec7d 942 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 943 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 944 }
AzureIoTClient 0:1f9b2707ec7d 945 else
AzureIoTClient 0:1f9b2707ec7d 946 {
AzureIoTClient 0:1f9b2707ec7d 947 action->ArgumentHandles = newArguments;
AzureIoTClient 0:1f9b2707ec7d 948 /* Codes_SRS_SCHEMA_99_119: [Schema_AddModelActionArgument shall preserve the order of the action arguments according to the order in which they were added, starting with index 0 for the first added argument.] */
AzureIoTClient 0:1f9b2707ec7d 949 action->ArgumentHandles[action->ArgumentCount] = newActionArgument;
AzureIoTClient 0:1f9b2707ec7d 950 action->ArgumentCount++;
AzureIoTClient 0:1f9b2707ec7d 951
AzureIoTClient 0:1f9b2707ec7d 952 /* Codes_SRS_SCHEMA_99_108: [On success, Schema_AddModelActionArgunent shall return SCHEMA_OK.] */
AzureIoTClient 0:1f9b2707ec7d 953 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 954 }
AzureIoTClient 0:1f9b2707ec7d 955 }
AzureIoTClient 0:1f9b2707ec7d 956
AzureIoTClient 0:1f9b2707ec7d 957 /* If possible, reduce the memory of over allocation */
AzureIoTClient 0:1f9b2707ec7d 958 if (result == SCHEMA_ERROR)
AzureIoTClient 0:1f9b2707ec7d 959 {
AzureIoTClient 0:1f9b2707ec7d 960 SCHEMA_ACTION_ARGUMENT_HANDLE* oldArguments = (SCHEMA_ACTION_ARGUMENT_HANDLE*)realloc(action->ArgumentHandles, sizeof(SCHEMA_ACTION_ARGUMENT_HANDLE) * action->ArgumentCount);
AzureIoTClient 0:1f9b2707ec7d 961 if (oldArguments == NULL)
AzureIoTClient 0:1f9b2707ec7d 962 {
AzureIoTClient 11:b1327861f5e0 963 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 964 }
AzureIoTClient 0:1f9b2707ec7d 965 else
AzureIoTClient 0:1f9b2707ec7d 966 {
AzureIoTClient 0:1f9b2707ec7d 967 action->ArgumentHandles = oldArguments;
AzureIoTClient 0:1f9b2707ec7d 968 }
AzureIoTClient 0:1f9b2707ec7d 969 }
AzureIoTClient 0:1f9b2707ec7d 970 }
AzureIoTClient 0:1f9b2707ec7d 971 }
AzureIoTClient 0:1f9b2707ec7d 972 }
AzureIoTClient 0:1f9b2707ec7d 973 return result;
AzureIoTClient 0:1f9b2707ec7d 974 }
AzureIoTClient 0:1f9b2707ec7d 975
AzureIoTClient 0:1f9b2707ec7d 976 SCHEMA_PROPERTY_HANDLE Schema_GetModelPropertyByName(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* propertyName)
AzureIoTClient 0:1f9b2707ec7d 977 {
AzureIoTClient 0:1f9b2707ec7d 978 SCHEMA_PROPERTY_HANDLE result;
AzureIoTClient 0:1f9b2707ec7d 979
AzureIoTClient 0:1f9b2707ec7d 980 /* Codes_SRS_SCHEMA_99_038:[Schema_GetModelPropertyByName shall return NULL if unable to find a matching property or if any of the arguments are NULL.] */
AzureIoTClient 0:1f9b2707ec7d 981 if ((modelTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 982 (propertyName == NULL))
AzureIoTClient 0:1f9b2707ec7d 983 {
AzureIoTClient 0:1f9b2707ec7d 984 result = NULL;
AzureIoTClient 11:b1327861f5e0 985 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 986 }
AzureIoTClient 0:1f9b2707ec7d 987 else
AzureIoTClient 0:1f9b2707ec7d 988 {
AzureIoTClient 0:1f9b2707ec7d 989 size_t i;
AzureIoTClient 17:fa1bba4c6053 990 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 991
AzureIoTClient 0:1f9b2707ec7d 992 /* Codes_SRS_SCHEMA_99_036:[Schema_GetModelPropertyByName shall return a non-NULL SCHEMA_PROPERTY_HANDLE corresponding to the model type identified by modelTypeHandle and matching the propertyName argument value.] */
AzureIoTClient 0:1f9b2707ec7d 993 for (i = 0; i < modelType->PropertyCount; i++)
AzureIoTClient 0:1f9b2707ec7d 994 {
AzureIoTClient 17:fa1bba4c6053 995 SCHEMA_PROPERTY_HANDLE_DATA* modelProperty = (SCHEMA_PROPERTY_HANDLE_DATA*)modelType->Properties[i];
AzureIoTClient 0:1f9b2707ec7d 996 if (strcmp(modelProperty->PropertyName, propertyName) == 0)
AzureIoTClient 0:1f9b2707ec7d 997 {
AzureIoTClient 0:1f9b2707ec7d 998 break;
AzureIoTClient 0:1f9b2707ec7d 999 }
AzureIoTClient 0:1f9b2707ec7d 1000 }
AzureIoTClient 0:1f9b2707ec7d 1001
AzureIoTClient 0:1f9b2707ec7d 1002 if (i == modelType->PropertyCount)
AzureIoTClient 0:1f9b2707ec7d 1003 {
AzureIoTClient 0:1f9b2707ec7d 1004 /* Codes_SRS_SCHEMA_99_038:[Schema_GetModelPropertyByName shall return NULL if unable to find a matching property or if any of the arguments are NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1005 result = NULL;
AzureIoTClient 11:b1327861f5e0 1006 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ELEMENT_NOT_FOUND));
AzureIoTClient 0:1f9b2707ec7d 1007 }
AzureIoTClient 0:1f9b2707ec7d 1008 else
AzureIoTClient 0:1f9b2707ec7d 1009 {
AzureIoTClient 0:1f9b2707ec7d 1010 result = (SCHEMA_PROPERTY_HANDLE)(modelType->Properties[i]);
AzureIoTClient 0:1f9b2707ec7d 1011 }
AzureIoTClient 0:1f9b2707ec7d 1012 }
AzureIoTClient 0:1f9b2707ec7d 1013
AzureIoTClient 0:1f9b2707ec7d 1014 return result;
AzureIoTClient 0:1f9b2707ec7d 1015 }
AzureIoTClient 0:1f9b2707ec7d 1016
AzureIoTClient 0:1f9b2707ec7d 1017 SCHEMA_RESULT Schema_GetModelPropertyCount(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t* propertyCount)
AzureIoTClient 0:1f9b2707ec7d 1018 {
AzureIoTClient 0:1f9b2707ec7d 1019 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 1020
AzureIoTClient 0:1f9b2707ec7d 1021 /* Codes_SRS_SCHEMA_99_092: [Schema_GetModelPropertyCount shall return SCHEMA_INVALID_ARG if any of the arguments is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1022 if ((modelTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1023 (propertyCount == NULL))
AzureIoTClient 0:1f9b2707ec7d 1024 {
AzureIoTClient 0:1f9b2707ec7d 1025 result = SCHEMA_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 1026 }
AzureIoTClient 0:1f9b2707ec7d 1027 else
AzureIoTClient 0:1f9b2707ec7d 1028 {
AzureIoTClient 0:1f9b2707ec7d 1029 /* Codes_SRS_SCHEMA_99_089: [Schema_GetModelPropertyCount shall provide the number of properties defined in the model type identified by modelTypeHandle.] */
AzureIoTClient 17:fa1bba4c6053 1030 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1031
AzureIoTClient 0:1f9b2707ec7d 1032 /* Codes_SRS_SCHEMA_99_090: [The count shall be provided via the out argument propertyCount.]*/
AzureIoTClient 0:1f9b2707ec7d 1033 *propertyCount = modelType->PropertyCount;
AzureIoTClient 0:1f9b2707ec7d 1034
AzureIoTClient 0:1f9b2707ec7d 1035 /* Codes_SRS_SCHEMA_99_091: [On success, Schema_GetModelPropertyCount shall return SCHEMA_OK.] */
AzureIoTClient 0:1f9b2707ec7d 1036 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 1037 }
AzureIoTClient 0:1f9b2707ec7d 1038
AzureIoTClient 0:1f9b2707ec7d 1039 return result;
AzureIoTClient 0:1f9b2707ec7d 1040 }
AzureIoTClient 0:1f9b2707ec7d 1041
AzureIoTClient 17:fa1bba4c6053 1042 SCHEMA_RESULT Schema_GetModelReportedPropertyCount(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t* reportedPropertyCount)
AzureIoTClient 17:fa1bba4c6053 1043 {
AzureIoTClient 17:fa1bba4c6053 1044 SCHEMA_RESULT result;
AzureIoTClient 17:fa1bba4c6053 1045 /*Codes_SRS_SCHEMA_02_008: [ If parameter modelTypeHandle is NULL then Schema_GetModelReportedPropertyCount shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 1046 /*Codes_SRS_SCHEMA_02_009: [ If parameter reportedPropertyCount is NULL then Schema_GetModelReportedPropertyCount shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 1047 if (
AzureIoTClient 17:fa1bba4c6053 1048 (modelTypeHandle == NULL)||
AzureIoTClient 17:fa1bba4c6053 1049 (reportedPropertyCount==NULL)
AzureIoTClient 17:fa1bba4c6053 1050 )
AzureIoTClient 17:fa1bba4c6053 1051 {
AzureIoTClient 17:fa1bba4c6053 1052 LogError("SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle=%p, size_t* reportedPropertyCount=%p", modelTypeHandle, reportedPropertyCount);
AzureIoTClient 17:fa1bba4c6053 1053 result = SCHEMA_INVALID_ARG;
AzureIoTClient 17:fa1bba4c6053 1054 }
AzureIoTClient 17:fa1bba4c6053 1055 else
AzureIoTClient 17:fa1bba4c6053 1056 {
AzureIoTClient 17:fa1bba4c6053 1057 /*Codes_SRS_SCHEMA_02_010: [ Schema_GetModelReportedPropertyCount shall provide in reportedPropertyCount the number of reported properties and return SCHEMA_OK. ]*/
AzureIoTClient 17:fa1bba4c6053 1058 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 1059 *reportedPropertyCount = VECTOR_size(modelType->reportedProperties);
AzureIoTClient 17:fa1bba4c6053 1060 result = SCHEMA_OK;
AzureIoTClient 17:fa1bba4c6053 1061 }
AzureIoTClient 17:fa1bba4c6053 1062 return result;
AzureIoTClient 17:fa1bba4c6053 1063 }
AzureIoTClient 17:fa1bba4c6053 1064
AzureIoTClient 17:fa1bba4c6053 1065 SCHEMA_REPORTED_PROPERTY_HANDLE Schema_GetModelReportedPropertyByName(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* reportedPropertyName)
AzureIoTClient 17:fa1bba4c6053 1066 {
AzureIoTClient 17:fa1bba4c6053 1067 SCHEMA_REPORTED_PROPERTY_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 1068 /*Codes_SRS_SCHEMA_02_011: [ If argument modelTypeHandle is NULL then Schema_GetModelReportedPropertyByName shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 1069 /*Codes_SRS_SCHEMA_02_012: [ If argument reportedPropertyName is NULL then Schema_GetModelReportedPropertyByName shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 1070 if(
AzureIoTClient 17:fa1bba4c6053 1071 (modelTypeHandle == NULL) ||
AzureIoTClient 17:fa1bba4c6053 1072 (reportedPropertyName == NULL)
AzureIoTClient 17:fa1bba4c6053 1073 )
AzureIoTClient 17:fa1bba4c6053 1074 {
AzureIoTClient 17:fa1bba4c6053 1075 LogError("invalid argument SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle=%p, const char* reportedPropertyName=%p", modelTypeHandle, reportedPropertyName);
AzureIoTClient 17:fa1bba4c6053 1076 result = NULL;
AzureIoTClient 17:fa1bba4c6053 1077 }
AzureIoTClient 17:fa1bba4c6053 1078 else
AzureIoTClient 17:fa1bba4c6053 1079 {
AzureIoTClient 17:fa1bba4c6053 1080 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 1081 /*Codes_SRS_SCHEMA_02_013: [ If reported property by the name reportedPropertyName exists then Schema_GetModelReportedPropertyByName shall succeed and return a non-NULL value. ]*/
AzureIoTClient 17:fa1bba4c6053 1082 /*Codes_SRS_SCHEMA_02_014: [ Otherwise Schema_GetModelReportedPropertyByName shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 1083 if((result = VECTOR_find_if(modelType->reportedProperties, reportedPropertyExists, reportedPropertyName))==NULL)
AzureIoTClient 17:fa1bba4c6053 1084 {
AzureIoTClient 17:fa1bba4c6053 1085 LogError("a reported property with name \"%s\" does not exist", reportedPropertyName);
AzureIoTClient 17:fa1bba4c6053 1086 }
AzureIoTClient 17:fa1bba4c6053 1087 else
AzureIoTClient 17:fa1bba4c6053 1088 {
AzureIoTClient 17:fa1bba4c6053 1089 /*return as is*/
AzureIoTClient 17:fa1bba4c6053 1090 }
AzureIoTClient 17:fa1bba4c6053 1091 }
AzureIoTClient 17:fa1bba4c6053 1092 return result;
AzureIoTClient 17:fa1bba4c6053 1093 }
AzureIoTClient 17:fa1bba4c6053 1094
AzureIoTClient 17:fa1bba4c6053 1095 SCHEMA_REPORTED_PROPERTY_HANDLE Schema_GetModelReportedPropertyByIndex(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t index)
AzureIoTClient 17:fa1bba4c6053 1096 {
AzureIoTClient 17:fa1bba4c6053 1097 SCHEMA_REPORTED_PROPERTY_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 1098 /*Codes_SRS_SCHEMA_02_015: [ If argument modelTypeHandle is NULL then Schema_GetModelReportedPropertyByIndex shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 1099 if (modelTypeHandle == NULL)
AzureIoTClient 17:fa1bba4c6053 1100 {
AzureIoTClient 17:fa1bba4c6053 1101 LogError("invalid argument SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle=%p, size_t index=%zu", modelTypeHandle, index);
AzureIoTClient 17:fa1bba4c6053 1102 result = NULL;
AzureIoTClient 17:fa1bba4c6053 1103 }
AzureIoTClient 17:fa1bba4c6053 1104 else
AzureIoTClient 17:fa1bba4c6053 1105 {
AzureIoTClient 17:fa1bba4c6053 1106 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 1107
AzureIoTClient 17:fa1bba4c6053 1108 /*Codes_SRS_SCHEMA_02_016: [ If a reported property with index equal to index exists then Schema_GetModelReportedPropertyByIndex shall succeed and return the non-NULL handle of that REPORTED_PROPERTY. ]*/
AzureIoTClient 17:fa1bba4c6053 1109 /*Codes_SRS_SCHEMA_02_017: [ Otherwise Schema_GetModelReportedPropertyByIndex shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 1110 if ((result = VECTOR_element(modelType->reportedProperties, index)) == NULL)
AzureIoTClient 17:fa1bba4c6053 1111 {
AzureIoTClient 17:fa1bba4c6053 1112 LogError("index %zu is invalid", index);
AzureIoTClient 17:fa1bba4c6053 1113 }
AzureIoTClient 17:fa1bba4c6053 1114 else
AzureIoTClient 17:fa1bba4c6053 1115 {
AzureIoTClient 17:fa1bba4c6053 1116 /*return as is*/
AzureIoTClient 17:fa1bba4c6053 1117 }
AzureIoTClient 17:fa1bba4c6053 1118 }
AzureIoTClient 17:fa1bba4c6053 1119 return result;
AzureIoTClient 17:fa1bba4c6053 1120 }
AzureIoTClient 17:fa1bba4c6053 1121
AzureIoTClient 0:1f9b2707ec7d 1122 SCHEMA_PROPERTY_HANDLE Schema_GetModelPropertyByIndex(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t index)
AzureIoTClient 0:1f9b2707ec7d 1123 {
AzureIoTClient 0:1f9b2707ec7d 1124 SCHEMA_PROPERTY_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 1125 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1126
AzureIoTClient 0:1f9b2707ec7d 1127 /* Codes_SRS_SCHEMA_99_094: [Schema_GetModelProperty shall return NULL if the index specified is outside the valid range or if modelTypeHandle argument is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1128 if ((modelTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1129 (index >= modelType->PropertyCount))
AzureIoTClient 0:1f9b2707ec7d 1130 {
AzureIoTClient 0:1f9b2707ec7d 1131 result = NULL;
AzureIoTClient 11:b1327861f5e0 1132 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1133 }
AzureIoTClient 0:1f9b2707ec7d 1134 else
AzureIoTClient 0:1f9b2707ec7d 1135 {
AzureIoTClient 0:1f9b2707ec7d 1136 /* Tests_SRS_SCHEMA_99_093: [Schema_GetModelProperty shall return a non-NULL SCHEMA_PROPERTY_HANDLE corresponding to the model type identified by modelTypeHandle and matching the index number provided by the index argument.] */
AzureIoTClient 0:1f9b2707ec7d 1137 /* Codes_SRS_SCHEMA_99_097: [index is zero based, and the order in which actions were added shall be the index in which they will be retrieved.] */
AzureIoTClient 0:1f9b2707ec7d 1138 result = modelType->Properties[index];
AzureIoTClient 0:1f9b2707ec7d 1139 }
AzureIoTClient 0:1f9b2707ec7d 1140
AzureIoTClient 0:1f9b2707ec7d 1141 return result;
AzureIoTClient 0:1f9b2707ec7d 1142 }
AzureIoTClient 0:1f9b2707ec7d 1143
AzureIoTClient 0:1f9b2707ec7d 1144 SCHEMA_ACTION_HANDLE Schema_GetModelActionByName(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* actionName)
AzureIoTClient 0:1f9b2707ec7d 1145 {
AzureIoTClient 0:1f9b2707ec7d 1146 SCHEMA_ACTION_HANDLE result;
AzureIoTClient 0:1f9b2707ec7d 1147
AzureIoTClient 0:1f9b2707ec7d 1148 /* Codes_SRS_SCHEMA_99_041:[Schema_GetModelActionByName shall return NULL if unable to find a matching action, if any of the arguments are NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1149 if ((modelTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1150 (actionName == NULL))
AzureIoTClient 0:1f9b2707ec7d 1151 {
AzureIoTClient 0:1f9b2707ec7d 1152 result = NULL;
AzureIoTClient 11:b1327861f5e0 1153 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1154 }
AzureIoTClient 0:1f9b2707ec7d 1155 else
AzureIoTClient 0:1f9b2707ec7d 1156 {
AzureIoTClient 0:1f9b2707ec7d 1157 size_t i;
AzureIoTClient 17:fa1bba4c6053 1158 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1159
AzureIoTClient 0:1f9b2707ec7d 1160 /* Codes_SRS_SCHEMA_99_040:[Schema_GetModelActionByName shall return a non-NULL SCHEMA_ACTION_HANDLE corresponding to the model type identified by modelTypeHandle and matching the actionName argument value.] */
AzureIoTClient 0:1f9b2707ec7d 1161 for (i = 0; i < modelType->ActionCount; i++)
AzureIoTClient 0:1f9b2707ec7d 1162 {
AzureIoTClient 17:fa1bba4c6053 1163 SCHEMA_ACTION_HANDLE_DATA* modelAction = (SCHEMA_ACTION_HANDLE_DATA*)modelType->Actions[i];
AzureIoTClient 0:1f9b2707ec7d 1164 if (strcmp(modelAction->ActionName, actionName) == 0)
AzureIoTClient 0:1f9b2707ec7d 1165 {
AzureIoTClient 0:1f9b2707ec7d 1166 break;
AzureIoTClient 0:1f9b2707ec7d 1167 }
AzureIoTClient 0:1f9b2707ec7d 1168 }
AzureIoTClient 0:1f9b2707ec7d 1169
AzureIoTClient 0:1f9b2707ec7d 1170 if (i == modelType->ActionCount)
AzureIoTClient 0:1f9b2707ec7d 1171 {
AzureIoTClient 0:1f9b2707ec7d 1172 /* Codes_SRS_SCHEMA_99_041:[Schema_GetModelActionByName shall return NULL if unable to find a matching action, if any of the arguments are NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1173 result = NULL;
AzureIoTClient 11:b1327861f5e0 1174 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ELEMENT_NOT_FOUND));
AzureIoTClient 0:1f9b2707ec7d 1175 }
AzureIoTClient 0:1f9b2707ec7d 1176 else
AzureIoTClient 0:1f9b2707ec7d 1177 {
AzureIoTClient 0:1f9b2707ec7d 1178 result = modelType->Actions[i];
AzureIoTClient 0:1f9b2707ec7d 1179 }
AzureIoTClient 0:1f9b2707ec7d 1180 }
AzureIoTClient 0:1f9b2707ec7d 1181
AzureIoTClient 0:1f9b2707ec7d 1182 return result;
AzureIoTClient 0:1f9b2707ec7d 1183 }
AzureIoTClient 0:1f9b2707ec7d 1184
AzureIoTClient 0:1f9b2707ec7d 1185 SCHEMA_RESULT Schema_GetModelActionCount(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t* actionCount)
AzureIoTClient 0:1f9b2707ec7d 1186 {
AzureIoTClient 0:1f9b2707ec7d 1187 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 1188
AzureIoTClient 0:1f9b2707ec7d 1189 /* Codes_SRS_SCHEMA_99_045:[If any of the modelTypeHandle or actionCount arguments is NULL, Schema_GetModelActionCount shall return SCHEMA_INVALID_ARG.] */
AzureIoTClient 0:1f9b2707ec7d 1190 if ((modelTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1191 (actionCount == NULL))
AzureIoTClient 0:1f9b2707ec7d 1192 {
AzureIoTClient 0:1f9b2707ec7d 1193 result = SCHEMA_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1194 LogError("(result=%s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1195 }
AzureIoTClient 0:1f9b2707ec7d 1196 else
AzureIoTClient 0:1f9b2707ec7d 1197 {
AzureIoTClient 0:1f9b2707ec7d 1198 /* Codes_SRS_SCHEMA_99_042:[Schema_GetModelActionCount shall provide the total number of actions defined in a model type identified by the modelTypeHandle.] */
AzureIoTClient 17:fa1bba4c6053 1199 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1200
AzureIoTClient 0:1f9b2707ec7d 1201 /* Codes_SRS_SCHEMA_99_043:[The count shall be provided via the out argument actionCount.] */
AzureIoTClient 0:1f9b2707ec7d 1202 *actionCount = modelType->ActionCount;
AzureIoTClient 0:1f9b2707ec7d 1203
AzureIoTClient 0:1f9b2707ec7d 1204 /* Codes_SRS_SCHEMA_99_044:[On success, Schema_GetModelActionCount shall return SCHEMA_OK.] */
AzureIoTClient 0:1f9b2707ec7d 1205 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 1206 }
AzureIoTClient 0:1f9b2707ec7d 1207
AzureIoTClient 0:1f9b2707ec7d 1208 return result;
AzureIoTClient 0:1f9b2707ec7d 1209 }
AzureIoTClient 0:1f9b2707ec7d 1210
AzureIoTClient 0:1f9b2707ec7d 1211 SCHEMA_ACTION_HANDLE Schema_GetModelActionByIndex(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t index)
AzureIoTClient 0:1f9b2707ec7d 1212 {
AzureIoTClient 0:1f9b2707ec7d 1213 SCHEMA_ACTION_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 1214 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1215
AzureIoTClient 0:1f9b2707ec7d 1216 /* Codes_SRS_SCHEMA_99_048:[Schema_GetModelAction shall return NULL if the index specified is outside the valid range or if modelTypeHandle argument is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1217 if ((modelType == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1218 (index >= modelType->ActionCount))
AzureIoTClient 0:1f9b2707ec7d 1219 {
AzureIoTClient 0:1f9b2707ec7d 1220 result = NULL;
AzureIoTClient 11:b1327861f5e0 1221 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1222 }
AzureIoTClient 0:1f9b2707ec7d 1223 else
AzureIoTClient 0:1f9b2707ec7d 1224 {
AzureIoTClient 0:1f9b2707ec7d 1225 /* Codes_SRS_SCHEMA_99_047:[Schema_GetModelAction shall return a non-NULL SCHEMA_ACTION_HANDLE corresponding to the model type identified by modelTypeHandle and matching the index number provided by the index argument.] */
AzureIoTClient 0:1f9b2707ec7d 1226 /* Codes_SRS_SCHEMA_99_096: [index is zero based and the order in which actions were added shall be the index in which they will be retrieved.] */
AzureIoTClient 0:1f9b2707ec7d 1227 result = modelType->Actions[index];
AzureIoTClient 0:1f9b2707ec7d 1228 }
AzureIoTClient 0:1f9b2707ec7d 1229
AzureIoTClient 0:1f9b2707ec7d 1230 return result;
AzureIoTClient 0:1f9b2707ec7d 1231 }
AzureIoTClient 0:1f9b2707ec7d 1232
AzureIoTClient 0:1f9b2707ec7d 1233 const char* Schema_GetModelActionName(SCHEMA_ACTION_HANDLE actionHandle)
AzureIoTClient 0:1f9b2707ec7d 1234 {
AzureIoTClient 0:1f9b2707ec7d 1235 const char* result;
AzureIoTClient 0:1f9b2707ec7d 1236
AzureIoTClient 0:1f9b2707ec7d 1237 /* Codes_SRS_SCHEMA_99_050:[If the actionHandle is NULL, Schema_GetModelActionName shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1238 if (actionHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 1239 {
AzureIoTClient 0:1f9b2707ec7d 1240 result = NULL;
AzureIoTClient 11:b1327861f5e0 1241 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1242 }
AzureIoTClient 0:1f9b2707ec7d 1243 else
AzureIoTClient 0:1f9b2707ec7d 1244 {
AzureIoTClient 17:fa1bba4c6053 1245 SCHEMA_ACTION_HANDLE_DATA* action = (SCHEMA_ACTION_HANDLE_DATA*)actionHandle;
AzureIoTClient 0:1f9b2707ec7d 1246 /* Codes_SRS_SCHEMA_99_049:[Schema_GetModelActionName shall return the action name for a given action handle.] */
AzureIoTClient 0:1f9b2707ec7d 1247 result = action->ActionName;
AzureIoTClient 0:1f9b2707ec7d 1248 }
AzureIoTClient 0:1f9b2707ec7d 1249
AzureIoTClient 0:1f9b2707ec7d 1250 return result;
AzureIoTClient 0:1f9b2707ec7d 1251 }
AzureIoTClient 0:1f9b2707ec7d 1252
AzureIoTClient 0:1f9b2707ec7d 1253 SCHEMA_RESULT Schema_GetModelActionArgumentCount(SCHEMA_ACTION_HANDLE actionHandle, size_t* argumentCount)
AzureIoTClient 0:1f9b2707ec7d 1254 {
AzureIoTClient 0:1f9b2707ec7d 1255 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 1256
AzureIoTClient 0:1f9b2707ec7d 1257 /* Codes_SRS_SCHEMA_99_054:[If any argument is NULL, Schema_GetModelActionArgumentCount shall return SCHEMA_INVALID_ARG.] */
AzureIoTClient 0:1f9b2707ec7d 1258 if ((actionHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1259 (argumentCount == NULL))
AzureIoTClient 0:1f9b2707ec7d 1260 {
AzureIoTClient 0:1f9b2707ec7d 1261 result = SCHEMA_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1262 LogError("(result=%s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1263 }
AzureIoTClient 0:1f9b2707ec7d 1264 else
AzureIoTClient 0:1f9b2707ec7d 1265 {
AzureIoTClient 17:fa1bba4c6053 1266 SCHEMA_ACTION_HANDLE_DATA* modelAction = (SCHEMA_ACTION_HANDLE_DATA*)actionHandle;
AzureIoTClient 0:1f9b2707ec7d 1267
AzureIoTClient 0:1f9b2707ec7d 1268 /* Codes_SRS_SCHEMA_99_051:[Schema_GetModelActionArgumentCount shall provide the number of arguments for a specific schema action identified by actionHandle.] */
AzureIoTClient 0:1f9b2707ec7d 1269 /* Codes_SRS_SCHEMA_99_052:[The argument count shall be provided via the out argument argumentCount.] */
AzureIoTClient 0:1f9b2707ec7d 1270 *argumentCount = modelAction->ArgumentCount;
AzureIoTClient 0:1f9b2707ec7d 1271
AzureIoTClient 0:1f9b2707ec7d 1272 /* Codes_SRS_SCHEMA_99_053:[On success, Schema_GetModelActionArgumentCount shall return SCHEMA_OK.] */
AzureIoTClient 0:1f9b2707ec7d 1273 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 1274 }
AzureIoTClient 0:1f9b2707ec7d 1275
AzureIoTClient 0:1f9b2707ec7d 1276 return result;
AzureIoTClient 0:1f9b2707ec7d 1277 }
AzureIoTClient 0:1f9b2707ec7d 1278
AzureIoTClient 0:1f9b2707ec7d 1279 SCHEMA_ACTION_ARGUMENT_HANDLE Schema_GetModelActionArgumentByName(SCHEMA_ACTION_HANDLE actionHandle, const char* actionArgumentName)
AzureIoTClient 0:1f9b2707ec7d 1280 {
AzureIoTClient 0:1f9b2707ec7d 1281 SCHEMA_ACTION_ARGUMENT_HANDLE result;
AzureIoTClient 0:1f9b2707ec7d 1282
AzureIoTClient 0:1f9b2707ec7d 1283 /* Codes_SRS_SCHEMA_99_118: [Schema_GetModelActionArgumentByName shall return NULL if unable to find a matching argument or if any of the arguments are NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1284 if ((actionHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1285 (actionArgumentName == NULL))
AzureIoTClient 0:1f9b2707ec7d 1286 {
AzureIoTClient 0:1f9b2707ec7d 1287 result = NULL;
AzureIoTClient 11:b1327861f5e0 1288 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1289 }
AzureIoTClient 0:1f9b2707ec7d 1290 else
AzureIoTClient 0:1f9b2707ec7d 1291 {
AzureIoTClient 0:1f9b2707ec7d 1292 /* Codes_SRS_SCHEMA_99_118: [Schema_GetModelActionArgumentByName shall return NULL if unable to find a matching argument or if any of the arguments are NULL.] */
AzureIoTClient 17:fa1bba4c6053 1293 SCHEMA_ACTION_HANDLE_DATA* modelAction = (SCHEMA_ACTION_HANDLE_DATA*)actionHandle;
AzureIoTClient 0:1f9b2707ec7d 1294 size_t i;
AzureIoTClient 0:1f9b2707ec7d 1295
AzureIoTClient 0:1f9b2707ec7d 1296 for (i = 0; i < modelAction->ArgumentCount; i++)
AzureIoTClient 0:1f9b2707ec7d 1297 {
AzureIoTClient 17:fa1bba4c6053 1298 SCHEMA_ACTION_ARGUMENT_HANDLE_DATA* actionArgument = (SCHEMA_ACTION_ARGUMENT_HANDLE_DATA*)modelAction->ArgumentHandles[i];
AzureIoTClient 0:1f9b2707ec7d 1299 if (strcmp(actionArgument->Name, actionArgumentName) == 0)
AzureIoTClient 0:1f9b2707ec7d 1300 {
AzureIoTClient 0:1f9b2707ec7d 1301 break;
AzureIoTClient 0:1f9b2707ec7d 1302 }
AzureIoTClient 0:1f9b2707ec7d 1303 }
AzureIoTClient 0:1f9b2707ec7d 1304
AzureIoTClient 0:1f9b2707ec7d 1305 if (i == modelAction->ArgumentCount)
AzureIoTClient 0:1f9b2707ec7d 1306 {
AzureIoTClient 0:1f9b2707ec7d 1307 /* Codes_SRS_SCHEMA_99_118: [Schema_GetModelActionArgumentByName shall return NULL if unable to find a matching argument or if any of the arguments are NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1308 result = NULL;
AzureIoTClient 11:b1327861f5e0 1309 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ELEMENT_NOT_FOUND));
AzureIoTClient 0:1f9b2707ec7d 1310 }
AzureIoTClient 0:1f9b2707ec7d 1311 else
AzureIoTClient 0:1f9b2707ec7d 1312 {
AzureIoTClient 0:1f9b2707ec7d 1313 /* Codes_SRS_SCHEMA_99_117: [Schema_GetModelActionArgumentByName shall return a non-NULL handle corresponding to an action argument identified by the actionHandle and actionArgumentName.] */
AzureIoTClient 0:1f9b2707ec7d 1314 result = modelAction->ArgumentHandles[i];
AzureIoTClient 0:1f9b2707ec7d 1315 }
AzureIoTClient 0:1f9b2707ec7d 1316 }
AzureIoTClient 0:1f9b2707ec7d 1317
AzureIoTClient 0:1f9b2707ec7d 1318 return result;
AzureIoTClient 0:1f9b2707ec7d 1319 }
AzureIoTClient 0:1f9b2707ec7d 1320
AzureIoTClient 0:1f9b2707ec7d 1321 SCHEMA_ACTION_ARGUMENT_HANDLE Schema_GetModelActionArgumentByIndex(SCHEMA_ACTION_HANDLE actionHandle, size_t argumentIndex)
AzureIoTClient 0:1f9b2707ec7d 1322 {
AzureIoTClient 0:1f9b2707ec7d 1323 SCHEMA_ACTION_ARGUMENT_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 1324 SCHEMA_ACTION_HANDLE_DATA* modelAction = (SCHEMA_ACTION_HANDLE_DATA*)actionHandle;
AzureIoTClient 0:1f9b2707ec7d 1325
AzureIoTClient 0:1f9b2707ec7d 1326 /* Codes_SRS_SCHEMA_99_056:[Schema_GetModelActionArgument shall return NULL if the index specified is outside the valid range or if the actionHandle argument is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1327 if ((actionHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1328 (argumentIndex >= modelAction->ArgumentCount))
AzureIoTClient 0:1f9b2707ec7d 1329 {
AzureIoTClient 0:1f9b2707ec7d 1330 result = NULL;
AzureIoTClient 11:b1327861f5e0 1331 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1332 }
AzureIoTClient 0:1f9b2707ec7d 1333 else
AzureIoTClient 0:1f9b2707ec7d 1334 {
AzureIoTClient 0:1f9b2707ec7d 1335 /* Codes_SRS_SCHEMA_99_055:[Schema_GetModelActionArgument shall return a non-NULL SCHEMA_ACTION_ARGUMENT_HANDLE corresponding to the action type identified by actionHandle and matching the index number provided by the argumentIndex argument.] */
AzureIoTClient 0:1f9b2707ec7d 1336 result = modelAction->ArgumentHandles[argumentIndex];
AzureIoTClient 0:1f9b2707ec7d 1337 }
AzureIoTClient 0:1f9b2707ec7d 1338
AzureIoTClient 0:1f9b2707ec7d 1339 return result;
AzureIoTClient 0:1f9b2707ec7d 1340 }
AzureIoTClient 0:1f9b2707ec7d 1341
AzureIoTClient 0:1f9b2707ec7d 1342 const char* Schema_GetActionArgumentName(SCHEMA_ACTION_ARGUMENT_HANDLE actionArgumentHandle)
AzureIoTClient 0:1f9b2707ec7d 1343 {
AzureIoTClient 0:1f9b2707ec7d 1344 const char* result;
AzureIoTClient 0:1f9b2707ec7d 1345 /* Codes_SRS_SCHEMA_99_114: [Schema_GetActionArgumentName shall return NULL if actionArgumentHandle is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1346 if (actionArgumentHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 1347 {
AzureIoTClient 0:1f9b2707ec7d 1348 result = NULL;
AzureIoTClient 11:b1327861f5e0 1349 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1350 }
AzureIoTClient 0:1f9b2707ec7d 1351 else
AzureIoTClient 0:1f9b2707ec7d 1352 {
AzureIoTClient 0:1f9b2707ec7d 1353 /* Codes_SRS_SCHEMA_99_113: [Schema_GetActionArgumentName shall return the argument name identified by the actionArgumentHandle.] */
AzureIoTClient 17:fa1bba4c6053 1354 SCHEMA_ACTION_ARGUMENT_HANDLE_DATA* actionArgument = (SCHEMA_ACTION_ARGUMENT_HANDLE_DATA*)actionArgumentHandle;
AzureIoTClient 0:1f9b2707ec7d 1355 result = actionArgument->Name;
AzureIoTClient 0:1f9b2707ec7d 1356 }
AzureIoTClient 0:1f9b2707ec7d 1357 return result;
AzureIoTClient 0:1f9b2707ec7d 1358 }
AzureIoTClient 0:1f9b2707ec7d 1359
AzureIoTClient 0:1f9b2707ec7d 1360 const char* Schema_GetActionArgumentType(SCHEMA_ACTION_ARGUMENT_HANDLE actionArgumentHandle)
AzureIoTClient 0:1f9b2707ec7d 1361 {
AzureIoTClient 0:1f9b2707ec7d 1362 const char* result;
AzureIoTClient 0:1f9b2707ec7d 1363 /* Codes_SRS_SCHEMA_99_116: [Schema_GetActionArgumentType shall return NULL if actionArgumentHandle is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1364 if (actionArgumentHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 1365 {
AzureIoTClient 0:1f9b2707ec7d 1366 result = NULL;
AzureIoTClient 11:b1327861f5e0 1367 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1368 }
AzureIoTClient 0:1f9b2707ec7d 1369 else
AzureIoTClient 0:1f9b2707ec7d 1370 {
AzureIoTClient 0:1f9b2707ec7d 1371 /* Codes_SRS_SCHEMA_99_115: [Schema_GetActionArgumentType shall return the argument type identified by the actionArgumentHandle.] */
AzureIoTClient 17:fa1bba4c6053 1372 SCHEMA_ACTION_ARGUMENT_HANDLE_DATA* actionArgument = (SCHEMA_ACTION_ARGUMENT_HANDLE_DATA*)actionArgumentHandle;
AzureIoTClient 0:1f9b2707ec7d 1373 result = actionArgument->Type;
AzureIoTClient 0:1f9b2707ec7d 1374 }
AzureIoTClient 0:1f9b2707ec7d 1375 return result;
AzureIoTClient 0:1f9b2707ec7d 1376 }
AzureIoTClient 0:1f9b2707ec7d 1377
AzureIoTClient 0:1f9b2707ec7d 1378 SCHEMA_STRUCT_TYPE_HANDLE Schema_CreateStructType(SCHEMA_HANDLE schemaHandle, const char* typeName)
AzureIoTClient 0:1f9b2707ec7d 1379 {
AzureIoTClient 0:1f9b2707ec7d 1380 SCHEMA_STRUCT_TYPE_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 1381 SCHEMA_HANDLE_DATA* schema = (SCHEMA_HANDLE_DATA*)schemaHandle;
AzureIoTClient 0:1f9b2707ec7d 1382
AzureIoTClient 0:1f9b2707ec7d 1383 /* Codes_SRS_SCHEMA_99_060:[If any of the arguments is NULL, Schema_CreateStructType shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1384 if ((schema == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1385 (typeName == NULL))
AzureIoTClient 0:1f9b2707ec7d 1386 {
AzureIoTClient 0:1f9b2707ec7d 1387 result = NULL;
AzureIoTClient 11:b1327861f5e0 1388 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1389 }
AzureIoTClient 0:1f9b2707ec7d 1390 else
AzureIoTClient 0:1f9b2707ec7d 1391 {
AzureIoTClient 17:fa1bba4c6053 1392 SCHEMA_STRUCT_TYPE_HANDLE_DATA* structType;
AzureIoTClient 0:1f9b2707ec7d 1393 size_t i;
AzureIoTClient 0:1f9b2707ec7d 1394
AzureIoTClient 0:1f9b2707ec7d 1395 /* Codes_SRS_SCHEMA_99_061:[If a struct type with the same name already exists, Schema_CreateStructType shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1396 for (i = 0; i < schema->StructTypeCount; i++)
AzureIoTClient 0:1f9b2707ec7d 1397 {
AzureIoTClient 17:fa1bba4c6053 1398 structType = (SCHEMA_STRUCT_TYPE_HANDLE_DATA*)schema->StructTypes[i];
AzureIoTClient 0:1f9b2707ec7d 1399 if (strcmp(structType->Name, typeName) == 0)
AzureIoTClient 0:1f9b2707ec7d 1400 {
AzureIoTClient 0:1f9b2707ec7d 1401 break;
AzureIoTClient 0:1f9b2707ec7d 1402 }
AzureIoTClient 0:1f9b2707ec7d 1403 }
AzureIoTClient 0:1f9b2707ec7d 1404
AzureIoTClient 0:1f9b2707ec7d 1405 if (i < schema->StructTypeCount)
AzureIoTClient 0:1f9b2707ec7d 1406 {
AzureIoTClient 0:1f9b2707ec7d 1407 result = NULL;
AzureIoTClient 11:b1327861f5e0 1408 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_DUPLICATE_ELEMENT));
AzureIoTClient 0:1f9b2707ec7d 1409 }
AzureIoTClient 0:1f9b2707ec7d 1410 else
AzureIoTClient 0:1f9b2707ec7d 1411 {
AzureIoTClient 0:1f9b2707ec7d 1412 SCHEMA_STRUCT_TYPE_HANDLE* newStructTypes = (SCHEMA_STRUCT_TYPE_HANDLE*)realloc(schema->StructTypes, sizeof(SCHEMA_STRUCT_TYPE_HANDLE) * (schema->StructTypeCount + 1));
AzureIoTClient 0:1f9b2707ec7d 1413 if (newStructTypes == NULL)
AzureIoTClient 0:1f9b2707ec7d 1414 {
AzureIoTClient 0:1f9b2707ec7d 1415 /* Codes_SRS_SCHEMA_99_066:[On any other error, Schema_CreateStructType shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1416 result = NULL;
AzureIoTClient 11:b1327861f5e0 1417 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 1418 }
AzureIoTClient 0:1f9b2707ec7d 1419 else
AzureIoTClient 0:1f9b2707ec7d 1420 {
AzureIoTClient 0:1f9b2707ec7d 1421 schema->StructTypes = newStructTypes;
AzureIoTClient 17:fa1bba4c6053 1422 if ((structType = (SCHEMA_STRUCT_TYPE_HANDLE_DATA*)malloc(sizeof(SCHEMA_STRUCT_TYPE_HANDLE_DATA))) == NULL)
AzureIoTClient 0:1f9b2707ec7d 1423 {
AzureIoTClient 0:1f9b2707ec7d 1424 /* Codes_SRS_SCHEMA_99_066:[On any other error, Schema_CreateStructType shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1425 result = NULL;
AzureIoTClient 11:b1327861f5e0 1426 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 1427 }
AzureIoTClient 0:1f9b2707ec7d 1428 else if (mallocAndStrcpy_s((char**)&structType->Name, typeName) != 0)
AzureIoTClient 0:1f9b2707ec7d 1429 {
AzureIoTClient 0:1f9b2707ec7d 1430 /* Codes_SRS_SCHEMA_99_066:[On any other error, Schema_CreateStructType shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1431 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 1432 free(structType);
AzureIoTClient 11:b1327861f5e0 1433 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 1434 }
AzureIoTClient 0:1f9b2707ec7d 1435 else
AzureIoTClient 0:1f9b2707ec7d 1436 {
AzureIoTClient 0:1f9b2707ec7d 1437 /* Codes_SRS_SCHEMA_99_057:[Schema_CreateStructType shall create a new struct type and return a handle to it.] */
AzureIoTClient 0:1f9b2707ec7d 1438 schema->StructTypes[schema->StructTypeCount] = structType;
AzureIoTClient 0:1f9b2707ec7d 1439 schema->StructTypeCount++;
AzureIoTClient 0:1f9b2707ec7d 1440 structType->PropertyCount = 0;
AzureIoTClient 0:1f9b2707ec7d 1441 structType->Properties = NULL;
AzureIoTClient 0:1f9b2707ec7d 1442
AzureIoTClient 0:1f9b2707ec7d 1443 /* Codes_SRS_SCHEMA_99_058:[On success, a non-NULL handle shall be returned.] */
AzureIoTClient 0:1f9b2707ec7d 1444 result = (SCHEMA_STRUCT_TYPE_HANDLE)structType;
AzureIoTClient 0:1f9b2707ec7d 1445 }
AzureIoTClient 0:1f9b2707ec7d 1446
AzureIoTClient 0:1f9b2707ec7d 1447 /* If possible, reduce the memory of over allocation */
AzureIoTClient 0:1f9b2707ec7d 1448 if (result == NULL)
AzureIoTClient 0:1f9b2707ec7d 1449 {
AzureIoTClient 0:1f9b2707ec7d 1450 SCHEMA_STRUCT_TYPE_HANDLE* oldStructTypes = (SCHEMA_STRUCT_TYPE_HANDLE*)realloc(schema->StructTypes, sizeof(SCHEMA_STRUCT_TYPE_HANDLE) * schema->StructTypeCount);
AzureIoTClient 0:1f9b2707ec7d 1451 if (oldStructTypes == NULL)
AzureIoTClient 0:1f9b2707ec7d 1452 {
AzureIoTClient 0:1f9b2707ec7d 1453 result = NULL;
AzureIoTClient 11:b1327861f5e0 1454 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR));
AzureIoTClient 0:1f9b2707ec7d 1455 }
AzureIoTClient 0:1f9b2707ec7d 1456 else
AzureIoTClient 0:1f9b2707ec7d 1457 {
AzureIoTClient 0:1f9b2707ec7d 1458 schema->StructTypes = oldStructTypes;
AzureIoTClient 0:1f9b2707ec7d 1459 }
AzureIoTClient 0:1f9b2707ec7d 1460 }
AzureIoTClient 0:1f9b2707ec7d 1461 }
AzureIoTClient 0:1f9b2707ec7d 1462 }
AzureIoTClient 0:1f9b2707ec7d 1463 }
AzureIoTClient 0:1f9b2707ec7d 1464
AzureIoTClient 0:1f9b2707ec7d 1465 return result;
AzureIoTClient 0:1f9b2707ec7d 1466 }
AzureIoTClient 0:1f9b2707ec7d 1467
AzureIoTClient 0:1f9b2707ec7d 1468 const char* Schema_GetStructTypeName(SCHEMA_STRUCT_TYPE_HANDLE structTypeHandle)
AzureIoTClient 0:1f9b2707ec7d 1469 {
AzureIoTClient 0:1f9b2707ec7d 1470 const char* result;
AzureIoTClient 0:1f9b2707ec7d 1471
AzureIoTClient 0:1f9b2707ec7d 1472 /* Codes_SRS_SCHEMA_99_136: [If structTypeHandle is NULL, Schema_GetStructTypeName shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1473 if (structTypeHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 1474 {
AzureIoTClient 0:1f9b2707ec7d 1475 result = NULL;
AzureIoTClient 11:b1327861f5e0 1476 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1477 }
AzureIoTClient 0:1f9b2707ec7d 1478 else
AzureIoTClient 0:1f9b2707ec7d 1479 {
AzureIoTClient 0:1f9b2707ec7d 1480 /* Codes_SRS_SCHEMA_99_135: [Schema_GetStructTypeName shall return the name of a struct type identified by the structTypeHandle argument.] */
AzureIoTClient 17:fa1bba4c6053 1481 result = ((SCHEMA_STRUCT_TYPE_HANDLE_DATA*)structTypeHandle)->Name;
AzureIoTClient 0:1f9b2707ec7d 1482 }
AzureIoTClient 0:1f9b2707ec7d 1483
AzureIoTClient 0:1f9b2707ec7d 1484 return result;
AzureIoTClient 0:1f9b2707ec7d 1485 }
AzureIoTClient 0:1f9b2707ec7d 1486
AzureIoTClient 0:1f9b2707ec7d 1487 SCHEMA_RESULT Schema_GetStructTypeCount(SCHEMA_HANDLE schemaHandle, size_t* structTypeCount)
AzureIoTClient 0:1f9b2707ec7d 1488 {
AzureIoTClient 0:1f9b2707ec7d 1489 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 1490
AzureIoTClient 0:1f9b2707ec7d 1491 /* Codes_SRS_SCHEMA_99_140: [Schema_GetStructTypeCount shall return SCHEMA_INVALID_ARG if any of the arguments is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1492 if ((schemaHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1493 (structTypeCount == NULL))
AzureIoTClient 0:1f9b2707ec7d 1494 {
AzureIoTClient 0:1f9b2707ec7d 1495 result = SCHEMA_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1496 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1497 }
AzureIoTClient 0:1f9b2707ec7d 1498 else
AzureIoTClient 0:1f9b2707ec7d 1499 {
AzureIoTClient 0:1f9b2707ec7d 1500 /* Codes_SRS_SCHEMA_99_137: [Schema_GetStructTypeCount shall provide the number of structs defined in the schema identified by schemaHandle.] */
AzureIoTClient 17:fa1bba4c6053 1501 SCHEMA_HANDLE_DATA* schema = (SCHEMA_HANDLE_DATA*)schemaHandle;
AzureIoTClient 0:1f9b2707ec7d 1502 /* Codes_SRS_SCHEMA_99_138: [The count shall be provided via the out argument structTypeCount.] */
AzureIoTClient 0:1f9b2707ec7d 1503 *structTypeCount = schema->StructTypeCount;
AzureIoTClient 0:1f9b2707ec7d 1504 /* Codes_SRS_SCHEMA_99_139: [On success, Schema_GetStructTypeCount shall return SCHEMA_OK.] */
AzureIoTClient 0:1f9b2707ec7d 1505 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 1506 }
AzureIoTClient 0:1f9b2707ec7d 1507
AzureIoTClient 0:1f9b2707ec7d 1508 return result;
AzureIoTClient 0:1f9b2707ec7d 1509 }
AzureIoTClient 0:1f9b2707ec7d 1510
AzureIoTClient 0:1f9b2707ec7d 1511 SCHEMA_STRUCT_TYPE_HANDLE Schema_GetStructTypeByName(SCHEMA_HANDLE schemaHandle, const char* name)
AzureIoTClient 0:1f9b2707ec7d 1512 {
AzureIoTClient 17:fa1bba4c6053 1513 SCHEMA_STRUCT_TYPE_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 1514 SCHEMA_HANDLE_DATA* schema = (SCHEMA_HANDLE_DATA*)schemaHandle;
AzureIoTClient 0:1f9b2707ec7d 1515
AzureIoTClient 0:1f9b2707ec7d 1516 /* Codes_SRS_SCHEMA_99_069:[Schema_GetStructTypeByName shall return NULL if unable to find a matching struct or if any of the arguments are NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1517 if ((schemaHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1518 (name == NULL))
AzureIoTClient 0:1f9b2707ec7d 1519 {
AzureIoTClient 0:1f9b2707ec7d 1520 result = NULL;
AzureIoTClient 11:b1327861f5e0 1521 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1522 }
AzureIoTClient 0:1f9b2707ec7d 1523 else
AzureIoTClient 0:1f9b2707ec7d 1524 {
AzureIoTClient 0:1f9b2707ec7d 1525 size_t i;
AzureIoTClient 0:1f9b2707ec7d 1526
AzureIoTClient 0:1f9b2707ec7d 1527 /* Codes_SRS_SCHEMA_99_068:[Schema_GetStructTypeByName shall return a non-NULL handle corresponding to the struct type identified by the structTypeName in the schemaHandle schema.] */
AzureIoTClient 0:1f9b2707ec7d 1528 for (i = 0; i < schema->StructTypeCount; i++)
AzureIoTClient 0:1f9b2707ec7d 1529 {
AzureIoTClient 17:fa1bba4c6053 1530 SCHEMA_STRUCT_TYPE_HANDLE_DATA* structType = (SCHEMA_STRUCT_TYPE_HANDLE_DATA*)schema->StructTypes[i];
AzureIoTClient 0:1f9b2707ec7d 1531 if (strcmp(structType->Name, name) == 0)
AzureIoTClient 0:1f9b2707ec7d 1532 {
AzureIoTClient 0:1f9b2707ec7d 1533 break;
AzureIoTClient 0:1f9b2707ec7d 1534 }
AzureIoTClient 0:1f9b2707ec7d 1535 }
AzureIoTClient 0:1f9b2707ec7d 1536
AzureIoTClient 0:1f9b2707ec7d 1537 if (i == schema->StructTypeCount)
AzureIoTClient 0:1f9b2707ec7d 1538 {
AzureIoTClient 0:1f9b2707ec7d 1539 /* Codes_SRS_SCHEMA_99_069:[Schema_GetStructTypeByName shall return NULL if unable to find a matching struct or if any of the arguments are NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1540 result = NULL;
AzureIoTClient 11:b1327861f5e0 1541 LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ELEMENT_NOT_FOUND));
AzureIoTClient 0:1f9b2707ec7d 1542 }
AzureIoTClient 0:1f9b2707ec7d 1543 else
AzureIoTClient 0:1f9b2707ec7d 1544 {
AzureIoTClient 0:1f9b2707ec7d 1545 result = schema->StructTypes[i];
AzureIoTClient 0:1f9b2707ec7d 1546 }
AzureIoTClient 0:1f9b2707ec7d 1547 }
AzureIoTClient 0:1f9b2707ec7d 1548
AzureIoTClient 0:1f9b2707ec7d 1549 return result;
AzureIoTClient 0:1f9b2707ec7d 1550 }
AzureIoTClient 0:1f9b2707ec7d 1551
AzureIoTClient 0:1f9b2707ec7d 1552 SCHEMA_STRUCT_TYPE_HANDLE Schema_GetStructTypeByIndex(SCHEMA_HANDLE schemaHandle, size_t index)
AzureIoTClient 0:1f9b2707ec7d 1553 {
AzureIoTClient 0:1f9b2707ec7d 1554 SCHEMA_STRUCT_TYPE_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 1555 SCHEMA_HANDLE_DATA* schema = (SCHEMA_HANDLE_DATA*)schemaHandle;
AzureIoTClient 0:1f9b2707ec7d 1556
AzureIoTClient 0:1f9b2707ec7d 1557 /* Codes_SRS_SCHEMA_99_143: [Schema_GetStructTypeByIndex shall return NULL if the index specified is outside the valid range or if schemaHandle argument is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1558 /* Codes_SRS_SCHEMA_99_142: [The index argument is zero based, and the order in which models were added shall be the index in which they will be retrieved.] */
AzureIoTClient 0:1f9b2707ec7d 1559 if ((schemaHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1560 (index >= schema->StructTypeCount))
AzureIoTClient 0:1f9b2707ec7d 1561 {
AzureIoTClient 0:1f9b2707ec7d 1562 result = NULL;
AzureIoTClient 11:b1327861f5e0 1563 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1564 }
AzureIoTClient 0:1f9b2707ec7d 1565 else
AzureIoTClient 0:1f9b2707ec7d 1566 {
AzureIoTClient 0:1f9b2707ec7d 1567
AzureIoTClient 0:1f9b2707ec7d 1568 /* Codes_SRS_SCHEMA_99_141: [Schema_GetStructTypeByIndex shall return a non-NULL SCHEMA_STRUCT_TYPE_HANDLE corresponding to the struct type identified by schemaHandle and matching the index number provided by the index argument.] */
AzureIoTClient 0:1f9b2707ec7d 1569 /* Codes_SRS_SCHEMA_99_142: [The index argument is zero based, and the order in which models were added shall be the index in which they will be retrieved.] */
AzureIoTClient 0:1f9b2707ec7d 1570 result = schema->StructTypes[index];
AzureIoTClient 0:1f9b2707ec7d 1571 }
AzureIoTClient 0:1f9b2707ec7d 1572 return result;
AzureIoTClient 0:1f9b2707ec7d 1573 }
AzureIoTClient 0:1f9b2707ec7d 1574
AzureIoTClient 0:1f9b2707ec7d 1575 SCHEMA_RESULT Schema_AddStructTypeProperty(SCHEMA_STRUCT_TYPE_HANDLE structTypeHandle, const char* propertyName, const char* propertyType)
AzureIoTClient 0:1f9b2707ec7d 1576 {
AzureIoTClient 0:1f9b2707ec7d 1577 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 1578
AzureIoTClient 0:1f9b2707ec7d 1579 /* Codes_SRS_SCHEMA_99_072:[If any of the arguments is NULL, Schema_AddStructTypeProperty shall return SCHEMA_INVALID_ARG.] */
AzureIoTClient 0:1f9b2707ec7d 1580 if ((structTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1581 (propertyName == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1582 (propertyType == NULL))
AzureIoTClient 0:1f9b2707ec7d 1583 {
AzureIoTClient 0:1f9b2707ec7d 1584 result = SCHEMA_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1585 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1586 }
AzureIoTClient 0:1f9b2707ec7d 1587 else
AzureIoTClient 0:1f9b2707ec7d 1588 {
AzureIoTClient 0:1f9b2707ec7d 1589 size_t i;
AzureIoTClient 17:fa1bba4c6053 1590 SCHEMA_STRUCT_TYPE_HANDLE_DATA* structType = (SCHEMA_STRUCT_TYPE_HANDLE_DATA*)structTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1591
AzureIoTClient 0:1f9b2707ec7d 1592 /* Codes_SRS_SCHEMA_99_074:[The property name shall be unique per struct type, if the same property name is added twice to a struct type, SCHEMA_DUPLICATE_ELEMENT shall be returned.] */
AzureIoTClient 0:1f9b2707ec7d 1593 for (i = 0; i < structType->PropertyCount; i++)
AzureIoTClient 0:1f9b2707ec7d 1594 {
AzureIoTClient 17:fa1bba4c6053 1595 SCHEMA_PROPERTY_HANDLE_DATA* property = (SCHEMA_PROPERTY_HANDLE_DATA*)structType->Properties[i];
AzureIoTClient 0:1f9b2707ec7d 1596 if (strcmp(property->PropertyName, propertyName) == 0)
AzureIoTClient 0:1f9b2707ec7d 1597 {
AzureIoTClient 0:1f9b2707ec7d 1598 break;
AzureIoTClient 0:1f9b2707ec7d 1599 }
AzureIoTClient 0:1f9b2707ec7d 1600 }
AzureIoTClient 0:1f9b2707ec7d 1601
AzureIoTClient 0:1f9b2707ec7d 1602 if (i < structType->PropertyCount)
AzureIoTClient 0:1f9b2707ec7d 1603 {
AzureIoTClient 0:1f9b2707ec7d 1604 result = SCHEMA_DUPLICATE_ELEMENT;
AzureIoTClient 11:b1327861f5e0 1605 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1606 }
AzureIoTClient 0:1f9b2707ec7d 1607 else
AzureIoTClient 0:1f9b2707ec7d 1608 {
AzureIoTClient 0:1f9b2707ec7d 1609 SCHEMA_PROPERTY_HANDLE* newProperties = (SCHEMA_PROPERTY_HANDLE*)realloc(structType->Properties, sizeof(SCHEMA_PROPERTY_HANDLE) * (structType->PropertyCount + 1));
AzureIoTClient 0:1f9b2707ec7d 1610 if (newProperties == NULL)
AzureIoTClient 0:1f9b2707ec7d 1611 {
AzureIoTClient 0:1f9b2707ec7d 1612 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 1613 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1614 }
AzureIoTClient 0:1f9b2707ec7d 1615 else
AzureIoTClient 0:1f9b2707ec7d 1616 {
AzureIoTClient 17:fa1bba4c6053 1617 SCHEMA_PROPERTY_HANDLE_DATA* newProperty;
AzureIoTClient 0:1f9b2707ec7d 1618
AzureIoTClient 0:1f9b2707ec7d 1619 structType->Properties = newProperties;
AzureIoTClient 17:fa1bba4c6053 1620 if ((newProperty = (SCHEMA_PROPERTY_HANDLE_DATA*)malloc(sizeof(SCHEMA_PROPERTY_HANDLE_DATA))) == NULL)
AzureIoTClient 0:1f9b2707ec7d 1621 {
AzureIoTClient 0:1f9b2707ec7d 1622 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 1623 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1624 }
AzureIoTClient 0:1f9b2707ec7d 1625 else
AzureIoTClient 0:1f9b2707ec7d 1626 {
AzureIoTClient 0:1f9b2707ec7d 1627 if (mallocAndStrcpy_s((char**)&newProperty->PropertyName, propertyName) != 0)
AzureIoTClient 0:1f9b2707ec7d 1628 {
AzureIoTClient 0:1f9b2707ec7d 1629 free(newProperty);
AzureIoTClient 0:1f9b2707ec7d 1630 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 1631 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1632 }
AzureIoTClient 0:1f9b2707ec7d 1633 else if (mallocAndStrcpy_s((char**)&newProperty->PropertyType, propertyType) != 0)
AzureIoTClient 0:1f9b2707ec7d 1634 {
AzureIoTClient 0:1f9b2707ec7d 1635 free((void*)newProperty->PropertyName);
AzureIoTClient 0:1f9b2707ec7d 1636 free(newProperty);
AzureIoTClient 0:1f9b2707ec7d 1637 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 1638 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1639 }
AzureIoTClient 0:1f9b2707ec7d 1640 else
AzureIoTClient 0:1f9b2707ec7d 1641 {
AzureIoTClient 0:1f9b2707ec7d 1642 /* Codes_SRS_SCHEMA_99_070:[Schema_AddStructTypeProperty shall add one property to the struct type identified by structTypeHandle.] */
AzureIoTClient 0:1f9b2707ec7d 1643 structType->Properties[structType->PropertyCount] = (SCHEMA_PROPERTY_HANDLE)newProperty;
AzureIoTClient 0:1f9b2707ec7d 1644 structType->PropertyCount++;
AzureIoTClient 0:1f9b2707ec7d 1645
AzureIoTClient 0:1f9b2707ec7d 1646 /* Codes_SRS_SCHEMA_99_071:[On success, Schema_AddStructTypeProperty shall return SCHEMA_OK.] */
AzureIoTClient 0:1f9b2707ec7d 1647 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 1648 }
AzureIoTClient 0:1f9b2707ec7d 1649 }
AzureIoTClient 0:1f9b2707ec7d 1650
AzureIoTClient 0:1f9b2707ec7d 1651 /* If possible, reduce the memory of over allocation */
AzureIoTClient 0:1f9b2707ec7d 1652 if (result != SCHEMA_OK)
AzureIoTClient 0:1f9b2707ec7d 1653 {
AzureIoTClient 0:1f9b2707ec7d 1654 SCHEMA_PROPERTY_HANDLE* oldProperties = (SCHEMA_PROPERTY_HANDLE*)realloc(structType->Properties, sizeof(SCHEMA_PROPERTY_HANDLE) * structType->PropertyCount);
AzureIoTClient 0:1f9b2707ec7d 1655 if (oldProperties == NULL)
AzureIoTClient 0:1f9b2707ec7d 1656 {
AzureIoTClient 0:1f9b2707ec7d 1657 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 1658 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1659 }
AzureIoTClient 0:1f9b2707ec7d 1660 else
AzureIoTClient 0:1f9b2707ec7d 1661 {
AzureIoTClient 0:1f9b2707ec7d 1662 structType->Properties = oldProperties;
AzureIoTClient 0:1f9b2707ec7d 1663 }
AzureIoTClient 0:1f9b2707ec7d 1664 }
AzureIoTClient 0:1f9b2707ec7d 1665 }
AzureIoTClient 0:1f9b2707ec7d 1666 }
AzureIoTClient 0:1f9b2707ec7d 1667 }
AzureIoTClient 0:1f9b2707ec7d 1668
AzureIoTClient 0:1f9b2707ec7d 1669 return result;
AzureIoTClient 0:1f9b2707ec7d 1670 }
AzureIoTClient 0:1f9b2707ec7d 1671
AzureIoTClient 0:1f9b2707ec7d 1672 SCHEMA_PROPERTY_HANDLE Schema_GetStructTypePropertyByName(SCHEMA_STRUCT_TYPE_HANDLE structTypeHandle, const char* propertyName)
AzureIoTClient 0:1f9b2707ec7d 1673 {
AzureIoTClient 0:1f9b2707ec7d 1674 SCHEMA_PROPERTY_HANDLE result;
AzureIoTClient 0:1f9b2707ec7d 1675
AzureIoTClient 0:1f9b2707ec7d 1676 /* Codes_SRS_SCHEMA_99_076:[Schema_GetStructTypePropertyByName shall return NULL if unable to find a matching property or if any of the arguments are NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1677 if ((structTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1678 (propertyName == NULL))
AzureIoTClient 0:1f9b2707ec7d 1679 {
AzureIoTClient 0:1f9b2707ec7d 1680 result = NULL;
AzureIoTClient 11:b1327861f5e0 1681 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1682 }
AzureIoTClient 0:1f9b2707ec7d 1683 else
AzureIoTClient 0:1f9b2707ec7d 1684 {
AzureIoTClient 0:1f9b2707ec7d 1685 size_t i;
AzureIoTClient 17:fa1bba4c6053 1686 SCHEMA_STRUCT_TYPE_HANDLE_DATA* structType = (SCHEMA_STRUCT_TYPE_HANDLE_DATA*)structTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1687
AzureIoTClient 0:1f9b2707ec7d 1688 for (i = 0; i < structType->PropertyCount; i++)
AzureIoTClient 0:1f9b2707ec7d 1689 {
AzureIoTClient 17:fa1bba4c6053 1690 SCHEMA_PROPERTY_HANDLE_DATA* modelProperty = (SCHEMA_PROPERTY_HANDLE_DATA*)structType->Properties[i];
AzureIoTClient 0:1f9b2707ec7d 1691 if (strcmp(modelProperty->PropertyName, propertyName) == 0)
AzureIoTClient 0:1f9b2707ec7d 1692 {
AzureIoTClient 0:1f9b2707ec7d 1693 break;
AzureIoTClient 0:1f9b2707ec7d 1694 }
AzureIoTClient 0:1f9b2707ec7d 1695 }
AzureIoTClient 0:1f9b2707ec7d 1696
AzureIoTClient 0:1f9b2707ec7d 1697 /* Codes_SRS_SCHEMA_99_076:[Schema_GetStructTypePropertyByName shall return NULL if unable to find a matching property or if any of the arguments are NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1698 if (i == structType->PropertyCount)
AzureIoTClient 0:1f9b2707ec7d 1699 {
AzureIoTClient 0:1f9b2707ec7d 1700 result = NULL;
AzureIoTClient 11:b1327861f5e0 1701 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ELEMENT_NOT_FOUND));
AzureIoTClient 0:1f9b2707ec7d 1702 }
AzureIoTClient 0:1f9b2707ec7d 1703 /* Codes_SRS_SCHEMA_99_075:[Schema_GetStructTypePropertyByName shall return a non-NULL handle corresponding to a property identified by the structTypeHandle and propertyName.] */
AzureIoTClient 0:1f9b2707ec7d 1704 else
AzureIoTClient 0:1f9b2707ec7d 1705 {
AzureIoTClient 0:1f9b2707ec7d 1706 result = structType->Properties[i];
AzureIoTClient 0:1f9b2707ec7d 1707 }
AzureIoTClient 0:1f9b2707ec7d 1708 }
AzureIoTClient 0:1f9b2707ec7d 1709
AzureIoTClient 0:1f9b2707ec7d 1710 return result;
AzureIoTClient 0:1f9b2707ec7d 1711 }
AzureIoTClient 0:1f9b2707ec7d 1712
AzureIoTClient 0:1f9b2707ec7d 1713 SCHEMA_RESULT Schema_GetStructTypePropertyCount(SCHEMA_STRUCT_TYPE_HANDLE structTypeHandle, size_t* propertyCount)
AzureIoTClient 0:1f9b2707ec7d 1714 {
AzureIoTClient 0:1f9b2707ec7d 1715 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 1716
AzureIoTClient 0:1f9b2707ec7d 1717 /* Codes_SRS_SCHEMA_99_079: [Schema_GetStructTypePropertyCount shall return SCHEMA_INVALID_ARG if any of the structlTypeHandle or propertyCount arguments is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1718 if ((structTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1719 (propertyCount == NULL))
AzureIoTClient 0:1f9b2707ec7d 1720 {
AzureIoTClient 0:1f9b2707ec7d 1721 result = SCHEMA_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1722 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1723 }
AzureIoTClient 0:1f9b2707ec7d 1724 else
AzureIoTClient 0:1f9b2707ec7d 1725 {
AzureIoTClient 17:fa1bba4c6053 1726 SCHEMA_STRUCT_TYPE_HANDLE_DATA* structType = (SCHEMA_STRUCT_TYPE_HANDLE_DATA*)structTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1727
AzureIoTClient 0:1f9b2707ec7d 1728 /* Codes_SRS_SCHEMA_99_077: [Schema_GetStructTypePropertyCount shall provide the total number of properties defined in a struct type identified by structTypeHandle. The value is provided via the out argument propertyCount.] */
AzureIoTClient 0:1f9b2707ec7d 1729 /* Codes_SRS_SCHEMA_99_081: [The count shall be provided via the out argument propertyCount.] */
AzureIoTClient 0:1f9b2707ec7d 1730 *propertyCount = structType->PropertyCount;
AzureIoTClient 0:1f9b2707ec7d 1731
AzureIoTClient 0:1f9b2707ec7d 1732 /* Codes_SRS_SCHEMA_99_078: [On success, Schema_ GetStructTypePropertyCount shall return SCHEMA_OK.] */
AzureIoTClient 0:1f9b2707ec7d 1733 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 1734 }
AzureIoTClient 0:1f9b2707ec7d 1735
AzureIoTClient 0:1f9b2707ec7d 1736 return result;
AzureIoTClient 0:1f9b2707ec7d 1737 }
AzureIoTClient 0:1f9b2707ec7d 1738
AzureIoTClient 0:1f9b2707ec7d 1739 SCHEMA_PROPERTY_HANDLE Schema_GetStructTypePropertyByIndex(SCHEMA_STRUCT_TYPE_HANDLE structTypeHandle, size_t index)
AzureIoTClient 0:1f9b2707ec7d 1740 {
AzureIoTClient 0:1f9b2707ec7d 1741 SCHEMA_PROPERTY_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 1742 SCHEMA_STRUCT_TYPE_HANDLE_DATA* structType = (SCHEMA_STRUCT_TYPE_HANDLE_DATA*)structTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1743
AzureIoTClient 0:1f9b2707ec7d 1744 /* Codes_SRS_SCHEMA_99_083: [Schema_ GetStructTypeProperty shall return NULL if the index specified is outside the valid range, if structTypeHandle argument is NULL] */
AzureIoTClient 0:1f9b2707ec7d 1745 if ((structTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1746 (index >= structType->PropertyCount))
AzureIoTClient 0:1f9b2707ec7d 1747 {
AzureIoTClient 0:1f9b2707ec7d 1748 result = NULL;
AzureIoTClient 11:b1327861f5e0 1749 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1750 }
AzureIoTClient 0:1f9b2707ec7d 1751 else
AzureIoTClient 0:1f9b2707ec7d 1752 {
AzureIoTClient 0:1f9b2707ec7d 1753 /* Codes_SRS_SCHEMA_99_082: [Schema_GetStructTypeProperty shall return a non-NULL SCHEMA_PROPERTY_HANDLE corresponding to the struct type identified by strutTypeHandle and matching the index number provided by the index argument.] */
AzureIoTClient 0:1f9b2707ec7d 1754 /* Codes_SRS_SCHEMA_99_098: [index is zero based and the order in which actions were added shall be the index in which they will be retrieved.] */
AzureIoTClient 0:1f9b2707ec7d 1755 result = structType->Properties[index];
AzureIoTClient 0:1f9b2707ec7d 1756 }
AzureIoTClient 0:1f9b2707ec7d 1757
AzureIoTClient 0:1f9b2707ec7d 1758 return result;
AzureIoTClient 0:1f9b2707ec7d 1759 }
AzureIoTClient 0:1f9b2707ec7d 1760
AzureIoTClient 0:1f9b2707ec7d 1761 const char* Schema_GetPropertyName(SCHEMA_PROPERTY_HANDLE propertyHandle)
AzureIoTClient 0:1f9b2707ec7d 1762 {
AzureIoTClient 0:1f9b2707ec7d 1763 const char* result;
AzureIoTClient 0:1f9b2707ec7d 1764
AzureIoTClient 0:1f9b2707ec7d 1765 /* Codes_SRS_SCHEMA_99_086: [If propertyHandle is NULL, Schema_GetPropertyName shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1766 if (propertyHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 1767 {
AzureIoTClient 0:1f9b2707ec7d 1768 result = NULL;
AzureIoTClient 11:b1327861f5e0 1769 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1770 }
AzureIoTClient 0:1f9b2707ec7d 1771 else
AzureIoTClient 0:1f9b2707ec7d 1772 {
AzureIoTClient 17:fa1bba4c6053 1773 SCHEMA_PROPERTY_HANDLE_DATA* propertyType = (SCHEMA_PROPERTY_HANDLE_DATA*)propertyHandle;
AzureIoTClient 0:1f9b2707ec7d 1774
AzureIoTClient 0:1f9b2707ec7d 1775 /* Codes_SRS_SCHEMA_99_085: [Schema_GetPropertyName shall return the property name identified by the propertyHandle.] */
AzureIoTClient 0:1f9b2707ec7d 1776 result = propertyType->PropertyName;
AzureIoTClient 0:1f9b2707ec7d 1777 }
AzureIoTClient 0:1f9b2707ec7d 1778
AzureIoTClient 0:1f9b2707ec7d 1779 return result;
AzureIoTClient 0:1f9b2707ec7d 1780 }
AzureIoTClient 0:1f9b2707ec7d 1781
AzureIoTClient 0:1f9b2707ec7d 1782 const char* Schema_GetPropertyType(SCHEMA_PROPERTY_HANDLE propertyHandle)
AzureIoTClient 0:1f9b2707ec7d 1783 {
AzureIoTClient 0:1f9b2707ec7d 1784 const char* result;
AzureIoTClient 0:1f9b2707ec7d 1785
AzureIoTClient 0:1f9b2707ec7d 1786 /* Codes_SRS_SCHEMA_99_088: [If propertyHandle is NULL, Schema_GetPropertyType shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1787 if (propertyHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 1788 {
AzureIoTClient 0:1f9b2707ec7d 1789 result = NULL;
AzureIoTClient 11:b1327861f5e0 1790 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1791 }
AzureIoTClient 0:1f9b2707ec7d 1792 else
AzureIoTClient 0:1f9b2707ec7d 1793 {
AzureIoTClient 17:fa1bba4c6053 1794 SCHEMA_PROPERTY_HANDLE_DATA* modelProperty = (SCHEMA_PROPERTY_HANDLE_DATA*)propertyHandle;
AzureIoTClient 0:1f9b2707ec7d 1795
AzureIoTClient 0:1f9b2707ec7d 1796 /* Codes_SRS_SCHEMA_99_087: [Schema_GetPropertyType shall return the property type identified by the propertyHandle.] */
AzureIoTClient 0:1f9b2707ec7d 1797 result = modelProperty->PropertyType;
AzureIoTClient 0:1f9b2707ec7d 1798 }
AzureIoTClient 0:1f9b2707ec7d 1799
AzureIoTClient 0:1f9b2707ec7d 1800 return result;
AzureIoTClient 0:1f9b2707ec7d 1801 }
AzureIoTClient 0:1f9b2707ec7d 1802
AzureIoTClient 0:1f9b2707ec7d 1803 SCHEMA_RESULT Schema_GetModelCount(SCHEMA_HANDLE schemaHandle, size_t* modelCount)
AzureIoTClient 0:1f9b2707ec7d 1804 {
AzureIoTClient 0:1f9b2707ec7d 1805 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 1806 /* Codes_SRS_SCHEMA_99_123: [Schema_GetModelCount shall return SCHEMA_INVALID_ARG if any of the arguments is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1807 if ((schemaHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1808 (modelCount == NULL) )
AzureIoTClient 0:1f9b2707ec7d 1809 {
AzureIoTClient 0:1f9b2707ec7d 1810 result = SCHEMA_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1811 LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1812 }
AzureIoTClient 0:1f9b2707ec7d 1813 else
AzureIoTClient 0:1f9b2707ec7d 1814 {
AzureIoTClient 0:1f9b2707ec7d 1815 /* Codes_SRS_SCHEMA_99_120: [Schema_GetModelCount shall provide the number of models defined in the schema identified by schemaHandle.] */
AzureIoTClient 17:fa1bba4c6053 1816 SCHEMA_HANDLE_DATA* schema = (SCHEMA_HANDLE_DATA*)schemaHandle;
AzureIoTClient 0:1f9b2707ec7d 1817 /* Codes_SRS_SCHEMA_99_121: [The count shall be provided via the out argument modelCount.] */
AzureIoTClient 0:1f9b2707ec7d 1818 *modelCount = schema->ModelTypeCount;
AzureIoTClient 0:1f9b2707ec7d 1819 /* Codes_SRS_SCHEMA_99_122: [On success, Schema_GetModelCount shall return SCHEMA_OK.] */
AzureIoTClient 0:1f9b2707ec7d 1820 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 1821 }
AzureIoTClient 0:1f9b2707ec7d 1822 return result;
AzureIoTClient 0:1f9b2707ec7d 1823 }
AzureIoTClient 0:1f9b2707ec7d 1824
AzureIoTClient 0:1f9b2707ec7d 1825 SCHEMA_MODEL_TYPE_HANDLE Schema_GetModelByName(SCHEMA_HANDLE schemaHandle, const char* modelName)
AzureIoTClient 0:1f9b2707ec7d 1826 {
AzureIoTClient 0:1f9b2707ec7d 1827 SCHEMA_MODEL_TYPE_HANDLE result;
AzureIoTClient 0:1f9b2707ec7d 1828
AzureIoTClient 0:1f9b2707ec7d 1829 /* Codes_SRS_SCHEMA_99_125: [Schema_GetModelByName shall return NULL if unable to find a matching model, or if any of the arguments are NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1830 if ((schemaHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1831 (modelName == NULL))
AzureIoTClient 0:1f9b2707ec7d 1832 {
AzureIoTClient 0:1f9b2707ec7d 1833 result = NULL;
AzureIoTClient 11:b1327861f5e0 1834 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1835 }
AzureIoTClient 0:1f9b2707ec7d 1836 else
AzureIoTClient 0:1f9b2707ec7d 1837 {
AzureIoTClient 0:1f9b2707ec7d 1838 /* Codes_SRS_SCHEMA_99_124: [Schema_GetModelByName shall return a non-NULL SCHEMA_MODEL_TYPE_HANDLE corresponding to the model identified by schemaHandle and matching the modelName argument value.] */
AzureIoTClient 17:fa1bba4c6053 1839 SCHEMA_HANDLE_DATA* schema = (SCHEMA_HANDLE_DATA*)schemaHandle;
AzureIoTClient 0:1f9b2707ec7d 1840 size_t i;
AzureIoTClient 0:1f9b2707ec7d 1841 for (i = 0; i < schema->ModelTypeCount; i++)
AzureIoTClient 0:1f9b2707ec7d 1842 {
AzureIoTClient 17:fa1bba4c6053 1843 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)schema->ModelTypes[i];
AzureIoTClient 0:1f9b2707ec7d 1844 if (strcmp(modelName, modelType->Name)==0)
AzureIoTClient 0:1f9b2707ec7d 1845 {
AzureIoTClient 0:1f9b2707ec7d 1846 break;
AzureIoTClient 0:1f9b2707ec7d 1847 }
AzureIoTClient 0:1f9b2707ec7d 1848 }
AzureIoTClient 0:1f9b2707ec7d 1849 if (i == schema->ModelTypeCount)
AzureIoTClient 0:1f9b2707ec7d 1850 {
AzureIoTClient 0:1f9b2707ec7d 1851 /* Codes_SRS_SCHEMA_99_125: [Schema_GetModelByName shall return NULL if unable to find a matching model, or if any of the arguments are NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1852 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 1853 }
AzureIoTClient 0:1f9b2707ec7d 1854 else
AzureIoTClient 0:1f9b2707ec7d 1855 {
AzureIoTClient 0:1f9b2707ec7d 1856 result = schema->ModelTypes[i];
AzureIoTClient 0:1f9b2707ec7d 1857 }
AzureIoTClient 0:1f9b2707ec7d 1858 }
AzureIoTClient 0:1f9b2707ec7d 1859 return result;
AzureIoTClient 0:1f9b2707ec7d 1860 }
AzureIoTClient 0:1f9b2707ec7d 1861
AzureIoTClient 0:1f9b2707ec7d 1862 SCHEMA_MODEL_TYPE_HANDLE Schema_GetModelByIndex(SCHEMA_HANDLE schemaHandle, size_t index)
AzureIoTClient 0:1f9b2707ec7d 1863 {
AzureIoTClient 0:1f9b2707ec7d 1864 SCHEMA_MODEL_TYPE_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 1865 SCHEMA_HANDLE_DATA* schema = (SCHEMA_HANDLE_DATA*)schemaHandle;
AzureIoTClient 0:1f9b2707ec7d 1866
AzureIoTClient 0:1f9b2707ec7d 1867 /* Codes_SRS_SCHEMA_99_128: [Schema_GetModelByIndex shall return NULL if the index specified is outside the valid range or if schemaHandle argument is NULL.] */
AzureIoTClient 0:1f9b2707ec7d 1868 /* Codes_SRS_SCHEMA_99_127: [The index argument is zero based, and the order in which models were added shall be the index in which they will be retrieved.] */
AzureIoTClient 0:1f9b2707ec7d 1869 if ((schemaHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1870 (index >= schema->ModelTypeCount))
AzureIoTClient 0:1f9b2707ec7d 1871 {
AzureIoTClient 0:1f9b2707ec7d 1872 result = NULL;
AzureIoTClient 11:b1327861f5e0 1873 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1874 }
AzureIoTClient 0:1f9b2707ec7d 1875 else
AzureIoTClient 0:1f9b2707ec7d 1876 {
AzureIoTClient 0:1f9b2707ec7d 1877
AzureIoTClient 0:1f9b2707ec7d 1878 /* Codes_SRS_SCHEMA_99_126: [Schema_GetModelByIndex shall return a non-NULL SCHEMA_MODEL_TYPE_HANDLE corresponding to the model identified by schemaHandle and matching the index number provided by the index argument.] */
AzureIoTClient 0:1f9b2707ec7d 1879 /* Codes_SRS_SCHEMA_99_127: [The index argument is zero based, and the order in which models were added shall be the index in which they will be retrieved.] */
AzureIoTClient 0:1f9b2707ec7d 1880 result = schema->ModelTypes[index];
AzureIoTClient 0:1f9b2707ec7d 1881 }
AzureIoTClient 0:1f9b2707ec7d 1882 return result;
AzureIoTClient 0:1f9b2707ec7d 1883 }
AzureIoTClient 0:1f9b2707ec7d 1884
AzureIoTClient 0:1f9b2707ec7d 1885 /*Codes_SRS_SCHEMA_99_160: [Schema_GetModelName shall return the name of the model identified by modelTypeHandle. If the name cannot be retrieved, then NULL shall be returned.]*/
AzureIoTClient 0:1f9b2707ec7d 1886 const char* Schema_GetModelName(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle)
AzureIoTClient 0:1f9b2707ec7d 1887 {
AzureIoTClient 0:1f9b2707ec7d 1888 const char* result;
AzureIoTClient 0:1f9b2707ec7d 1889 if (modelTypeHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 1890 {
AzureIoTClient 0:1f9b2707ec7d 1891 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 1892 }
AzureIoTClient 0:1f9b2707ec7d 1893 else
AzureIoTClient 0:1f9b2707ec7d 1894 {
AzureIoTClient 17:fa1bba4c6053 1895 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1896 result = modelType->Name;
AzureIoTClient 0:1f9b2707ec7d 1897 }
AzureIoTClient 0:1f9b2707ec7d 1898 return result;
AzureIoTClient 0:1f9b2707ec7d 1899 }
AzureIoTClient 0:1f9b2707ec7d 1900
AzureIoTClient 0:1f9b2707ec7d 1901 /*Codes_SRS_SCHEMA_99_163: [Schema_AddModelModel shall insert an existing model, identified by the handle modelType, into the existing model identified by modelTypeHandle under a property having the name propertyName.]*/
AzureIoTClient 17:fa1bba4c6053 1902 SCHEMA_RESULT Schema_AddModelModel(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* propertyName, SCHEMA_MODEL_TYPE_HANDLE modelType, size_t offset, pfOnDesiredProperty onDesiredProperty)
AzureIoTClient 0:1f9b2707ec7d 1903 {
AzureIoTClient 0:1f9b2707ec7d 1904 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 1905 /*Codes_SRS_SCHEMA_99_165: [If any of the parameters is NULL then Schema_AddModelModel shall return SCHEMA_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 1906 if (
AzureIoTClient 0:1f9b2707ec7d 1907 (modelTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1908 (propertyName == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1909 (modelType == NULL)
AzureIoTClient 0:1f9b2707ec7d 1910 )
AzureIoTClient 0:1f9b2707ec7d 1911 {
AzureIoTClient 0:1f9b2707ec7d 1912 result = SCHEMA_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1913 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG));
AzureIoTClient 0:1f9b2707ec7d 1914 }
AzureIoTClient 0:1f9b2707ec7d 1915 else
AzureIoTClient 0:1f9b2707ec7d 1916 {
AzureIoTClient 17:fa1bba4c6053 1917 SCHEMA_MODEL_TYPE_HANDLE_DATA* parentModel = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1918 MODEL_IN_MODEL temp;
AzureIoTClient 0:1f9b2707ec7d 1919 temp.modelHandle = modelType;
AzureIoTClient 17:fa1bba4c6053 1920 temp.offset = offset;
AzureIoTClient 17:fa1bba4c6053 1921 temp.onDesiredProperty = onDesiredProperty;
AzureIoTClient 0:1f9b2707ec7d 1922 if (mallocAndStrcpy_s((char**)&(temp.propertyName), propertyName) != 0)
AzureIoTClient 0:1f9b2707ec7d 1923 {
AzureIoTClient 0:1f9b2707ec7d 1924 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 1925 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1926 }
AzureIoTClient 0:1f9b2707ec7d 1927 else if (VECTOR_push_back(parentModel->models, &temp, 1) != 0)
AzureIoTClient 0:1f9b2707ec7d 1928 {
AzureIoTClient 0:1f9b2707ec7d 1929 /*Codes_SRS_SCHEMA_99_174: [The function shall return SCHEMA_ERROR if any other error occurs.]*/
AzureIoTClient 0:1f9b2707ec7d 1930 free((void*)temp.propertyName);
AzureIoTClient 0:1f9b2707ec7d 1931 result = SCHEMA_ERROR;
AzureIoTClient 11:b1327861f5e0 1932 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1933 }
AzureIoTClient 0:1f9b2707ec7d 1934 else
AzureIoTClient 0:1f9b2707ec7d 1935 {
AzureIoTClient 0:1f9b2707ec7d 1936 /*Codes_SRS_SCHEMA_99_164: [If the function succeeds, then the return value shall be SCHEMA_OK.]*/
AzureIoTClient 17:fa1bba4c6053 1937
AzureIoTClient 0:1f9b2707ec7d 1938 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 1939 }
AzureIoTClient 0:1f9b2707ec7d 1940 }
AzureIoTClient 0:1f9b2707ec7d 1941 return result;
AzureIoTClient 0:1f9b2707ec7d 1942 }
AzureIoTClient 0:1f9b2707ec7d 1943
AzureIoTClient 0:1f9b2707ec7d 1944
AzureIoTClient 0:1f9b2707ec7d 1945 SCHEMA_RESULT Schema_GetModelModelCount(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t* modelCount)
AzureIoTClient 0:1f9b2707ec7d 1946 {
AzureIoTClient 0:1f9b2707ec7d 1947 SCHEMA_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 1948 /*Codes_SRS_SCHEMA_99_169: [If any of the parameters is NULL, then the function shall return SCHEMA_INVALID_ARG.]*/
AzureIoTClient 0:1f9b2707ec7d 1949 if (
AzureIoTClient 0:1f9b2707ec7d 1950 (modelTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1951 (modelCount == NULL)
AzureIoTClient 0:1f9b2707ec7d 1952 )
AzureIoTClient 0:1f9b2707ec7d 1953 {
AzureIoTClient 0:1f9b2707ec7d 1954 result = SCHEMA_INVALID_ARG;
AzureIoTClient 11:b1327861f5e0 1955 LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, result));
AzureIoTClient 0:1f9b2707ec7d 1956 }
AzureIoTClient 0:1f9b2707ec7d 1957 else
AzureIoTClient 0:1f9b2707ec7d 1958 {
AzureIoTClient 17:fa1bba4c6053 1959 SCHEMA_MODEL_TYPE_HANDLE_DATA* model = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1960 /*Codes_SRS_SCHEMA_99_167: [Schema_GetModelModelCount shall return in parameter modelCount the number of models inserted in the model identified by parameter modelTypeHandle.]*/
AzureIoTClient 0:1f9b2707ec7d 1961 *modelCount = VECTOR_size(model->models);
AzureIoTClient 0:1f9b2707ec7d 1962 /*SRS_SCHEMA_99_168: [If the function succeeds, it shall return SCHEMA_OK.]*/
AzureIoTClient 0:1f9b2707ec7d 1963 result = SCHEMA_OK;
AzureIoTClient 0:1f9b2707ec7d 1964 }
AzureIoTClient 0:1f9b2707ec7d 1965 return result;
AzureIoTClient 0:1f9b2707ec7d 1966 }
AzureIoTClient 0:1f9b2707ec7d 1967
AzureIoTClient 0:1f9b2707ec7d 1968 static bool matchModelName(const void* element, const void* value)
AzureIoTClient 0:1f9b2707ec7d 1969 {
AzureIoTClient 0:1f9b2707ec7d 1970 MODEL_IN_MODEL* decodedElement = (MODEL_IN_MODEL*)element;
AzureIoTClient 0:1f9b2707ec7d 1971 const char* name = (const char*)value;
AzureIoTClient 0:1f9b2707ec7d 1972 return (strcmp(decodedElement->propertyName, name) == 0);
AzureIoTClient 0:1f9b2707ec7d 1973 }
AzureIoTClient 0:1f9b2707ec7d 1974
AzureIoTClient 0:1f9b2707ec7d 1975 SCHEMA_MODEL_TYPE_HANDLE Schema_GetModelModelByName(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* propertyName)
AzureIoTClient 0:1f9b2707ec7d 1976 {
AzureIoTClient 0:1f9b2707ec7d 1977 SCHEMA_MODEL_TYPE_HANDLE result;
AzureIoTClient 0:1f9b2707ec7d 1978 if (
AzureIoTClient 0:1f9b2707ec7d 1979 (modelTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 1980 (propertyName == NULL)
AzureIoTClient 0:1f9b2707ec7d 1981 )
AzureIoTClient 0:1f9b2707ec7d 1982 {
AzureIoTClient 0:1f9b2707ec7d 1983 /*Codes_SRS_SCHEMA_99_171: [If Schema_GetModelModelByName is unable to provide the handle it shall return NULL.]*/
AzureIoTClient 0:1f9b2707ec7d 1984 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 1985 LogError("error SCHEMA_INVALID_ARG");
AzureIoTClient 0:1f9b2707ec7d 1986 }
AzureIoTClient 0:1f9b2707ec7d 1987 else
AzureIoTClient 0:1f9b2707ec7d 1988 {
AzureIoTClient 17:fa1bba4c6053 1989 SCHEMA_MODEL_TYPE_HANDLE_DATA* model = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 1990 /*Codes_SRS_SCHEMA_99_170: [Schema_GetModelModelByName shall return a handle to the model identified by the property with the name propertyName in the model identified by the handle modelTypeHandle.]*/
AzureIoTClient 0:1f9b2707ec7d 1991 /*Codes_SRS_SCHEMA_99_171: [If Schema_GetModelModelByName is unable to provide the handle it shall return NULL.]*/
AzureIoTClient 0:1f9b2707ec7d 1992 void* temp = VECTOR_find_if(model->models, matchModelName, propertyName);
AzureIoTClient 0:1f9b2707ec7d 1993 if (temp == NULL)
AzureIoTClient 0:1f9b2707ec7d 1994 {
AzureIoTClient 0:1f9b2707ec7d 1995 LogError("specified propertyName not found (%s)", propertyName);
AzureIoTClient 0:1f9b2707ec7d 1996 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 1997 }
AzureIoTClient 0:1f9b2707ec7d 1998 else
AzureIoTClient 0:1f9b2707ec7d 1999 {
AzureIoTClient 0:1f9b2707ec7d 2000 result = ((MODEL_IN_MODEL*)temp)->modelHandle;
AzureIoTClient 0:1f9b2707ec7d 2001 }
AzureIoTClient 0:1f9b2707ec7d 2002 }
AzureIoTClient 0:1f9b2707ec7d 2003 return result;
AzureIoTClient 0:1f9b2707ec7d 2004 }
AzureIoTClient 0:1f9b2707ec7d 2005
AzureIoTClient 17:fa1bba4c6053 2006 size_t Schema_GetModelModelByName_Offset(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* propertyName)
AzureIoTClient 17:fa1bba4c6053 2007 {
AzureIoTClient 17:fa1bba4c6053 2008 size_t result;
AzureIoTClient 17:fa1bba4c6053 2009 /*Codes_SRS_SCHEMA_02_053: [ If modelTypeHandle is NULL then Schema_GetModelModelByName_Offset shall fail and return 0. ]*/
AzureIoTClient 17:fa1bba4c6053 2010 /*Codes_SRS_SCHEMA_02_054: [ If propertyName is NULL then Schema_GetModelModelByName_Offset shall fail and return 0. ]*/
AzureIoTClient 17:fa1bba4c6053 2011 if (
AzureIoTClient 17:fa1bba4c6053 2012 (modelTypeHandle == NULL) ||
AzureIoTClient 17:fa1bba4c6053 2013 (propertyName == NULL)
AzureIoTClient 17:fa1bba4c6053 2014 )
AzureIoTClient 17:fa1bba4c6053 2015 {
AzureIoTClient 17:fa1bba4c6053 2016 /*Codes_SRS_SCHEMA_99_171: [If Schema_GetModelModelByName is unable to provide the handle it shall return NULL.]*/
AzureIoTClient 17:fa1bba4c6053 2017 result = 0;
AzureIoTClient 17:fa1bba4c6053 2018 LogError("error SCHEMA_INVALID_ARG");
AzureIoTClient 17:fa1bba4c6053 2019 }
AzureIoTClient 17:fa1bba4c6053 2020 else
AzureIoTClient 17:fa1bba4c6053 2021 {
AzureIoTClient 17:fa1bba4c6053 2022 SCHEMA_MODEL_TYPE_HANDLE_DATA* model = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 2023 /*Codes_SRS_SCHEMA_02_056: [ If propertyName is not a model then Schema_GetModelModelByName_Offset shall fail and return 0. ]*/
AzureIoTClient 17:fa1bba4c6053 2024 void* temp = VECTOR_find_if(model->models, matchModelName, propertyName);
AzureIoTClient 17:fa1bba4c6053 2025 if (temp == NULL)
AzureIoTClient 17:fa1bba4c6053 2026 {
AzureIoTClient 17:fa1bba4c6053 2027 LogError("specified propertyName not found (%s)", propertyName);
AzureIoTClient 17:fa1bba4c6053 2028 result = 0;
AzureIoTClient 17:fa1bba4c6053 2029 }
AzureIoTClient 17:fa1bba4c6053 2030 else
AzureIoTClient 17:fa1bba4c6053 2031 {
AzureIoTClient 17:fa1bba4c6053 2032 /*Codes_SRS_SCHEMA_02_055: [ Otherwise Schema_GetModelModelByName_Offset shall succeed and return the offset. ]*/
AzureIoTClient 17:fa1bba4c6053 2033 result = ((MODEL_IN_MODEL*)temp)->offset;
AzureIoTClient 17:fa1bba4c6053 2034 }
AzureIoTClient 17:fa1bba4c6053 2035 }
AzureIoTClient 17:fa1bba4c6053 2036 return result;
AzureIoTClient 17:fa1bba4c6053 2037 }
AzureIoTClient 17:fa1bba4c6053 2038
AzureIoTClient 17:fa1bba4c6053 2039 pfOnDesiredProperty Schema_GetModelModelByName_OnDesiredProperty(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* propertyName)
AzureIoTClient 17:fa1bba4c6053 2040 {
AzureIoTClient 17:fa1bba4c6053 2041 pfOnDesiredProperty result;
AzureIoTClient 17:fa1bba4c6053 2042 /*Codes_SRS_SCHEMA_02_086: [ If modelTypeHandle is NULL then Schema_GetModelModelByName_OnDesiredProperty shall return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2043 /*Codes_SRS_SCHEMA_02_087: [ If propertyName is NULL then Schema_GetModelModelByName_OnDesiredProperty shall return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2044 if (
AzureIoTClient 17:fa1bba4c6053 2045 (modelTypeHandle == NULL) ||
AzureIoTClient 17:fa1bba4c6053 2046 (propertyName == NULL)
AzureIoTClient 17:fa1bba4c6053 2047 )
AzureIoTClient 17:fa1bba4c6053 2048 {
AzureIoTClient 17:fa1bba4c6053 2049 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2050 LogError("invalid argument SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle=%p, const char* propertyName=%p",modelTypeHandle, propertyName);
AzureIoTClient 17:fa1bba4c6053 2051 }
AzureIoTClient 17:fa1bba4c6053 2052 else
AzureIoTClient 17:fa1bba4c6053 2053 {
AzureIoTClient 17:fa1bba4c6053 2054 SCHEMA_MODEL_TYPE_HANDLE_DATA* model = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 2055 void* temp = VECTOR_find_if(model->models, matchModelName, propertyName);
AzureIoTClient 17:fa1bba4c6053 2056 if (temp == NULL)
AzureIoTClient 17:fa1bba4c6053 2057 {
AzureIoTClient 17:fa1bba4c6053 2058 LogError("specified propertyName not found (%s)", propertyName);
AzureIoTClient 17:fa1bba4c6053 2059 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2060 }
AzureIoTClient 17:fa1bba4c6053 2061 else
AzureIoTClient 17:fa1bba4c6053 2062 {
AzureIoTClient 17:fa1bba4c6053 2063 /*Codes_SRS_SCHEMA_02_089: [ Otherwise Schema_GetModelModelByName_OnDesiredProperty shall return the desired property callback. ]*/
AzureIoTClient 17:fa1bba4c6053 2064 result = ((MODEL_IN_MODEL*)temp)->onDesiredProperty;
AzureIoTClient 17:fa1bba4c6053 2065 }
AzureIoTClient 17:fa1bba4c6053 2066 }
AzureIoTClient 17:fa1bba4c6053 2067 return result;
AzureIoTClient 17:fa1bba4c6053 2068
AzureIoTClient 17:fa1bba4c6053 2069 }
AzureIoTClient 17:fa1bba4c6053 2070
AzureIoTClient 17:fa1bba4c6053 2071 size_t Schema_GetModelModelByIndex_Offset(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t index)
AzureIoTClient 17:fa1bba4c6053 2072 {
AzureIoTClient 17:fa1bba4c6053 2073 size_t result;
AzureIoTClient 17:fa1bba4c6053 2074 /*Codes_SRS_SCHEMA_02_057: [ If modelTypeHandle is NULL then Schema_GetModelModelByIndex_Offset shall fail and return 0. ]*/
AzureIoTClient 17:fa1bba4c6053 2075 if (
AzureIoTClient 17:fa1bba4c6053 2076 (modelTypeHandle == NULL)
AzureIoTClient 17:fa1bba4c6053 2077 )
AzureIoTClient 17:fa1bba4c6053 2078 {
AzureIoTClient 17:fa1bba4c6053 2079 result = 0;
AzureIoTClient 17:fa1bba4c6053 2080 LogError("error SCHEMA_INVALID_ARG");
AzureIoTClient 17:fa1bba4c6053 2081 }
AzureIoTClient 17:fa1bba4c6053 2082 else
AzureIoTClient 17:fa1bba4c6053 2083 {
AzureIoTClient 17:fa1bba4c6053 2084 SCHEMA_MODEL_TYPE_HANDLE_DATA* model = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 2085 /*Codes_SRS_SCHEMA_02_058: [ If index is not valid then Schema_GetModelModelByIndex_Offset shall fail and return 0. ]*/
AzureIoTClient 17:fa1bba4c6053 2086 void* temp = VECTOR_element(model->models, index);
AzureIoTClient 17:fa1bba4c6053 2087 if (temp == 0)
AzureIoTClient 17:fa1bba4c6053 2088 {
AzureIoTClient 17:fa1bba4c6053 2089 LogError("specified index [out of bounds] (%zu)", index);
AzureIoTClient 17:fa1bba4c6053 2090 result = 0;
AzureIoTClient 17:fa1bba4c6053 2091 }
AzureIoTClient 17:fa1bba4c6053 2092 else
AzureIoTClient 17:fa1bba4c6053 2093 {
AzureIoTClient 17:fa1bba4c6053 2094 /*Codes_SRS_SCHEMA_02_059: [ Otherwise Schema_GetModelModelByIndex_Offset shall succeed and return the offset. ]*/
AzureIoTClient 17:fa1bba4c6053 2095 result = ((MODEL_IN_MODEL*)temp)->offset;
AzureIoTClient 17:fa1bba4c6053 2096 }
AzureIoTClient 17:fa1bba4c6053 2097 }
AzureIoTClient 17:fa1bba4c6053 2098 return result;
AzureIoTClient 17:fa1bba4c6053 2099 }
AzureIoTClient 17:fa1bba4c6053 2100
AzureIoTClient 0:1f9b2707ec7d 2101 SCHEMA_MODEL_TYPE_HANDLE Schema_GetModelModelyByIndex(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t index)
AzureIoTClient 0:1f9b2707ec7d 2102 {
AzureIoTClient 0:1f9b2707ec7d 2103 SCHEMA_MODEL_TYPE_HANDLE result;
AzureIoTClient 0:1f9b2707ec7d 2104 if (
AzureIoTClient 0:1f9b2707ec7d 2105 (modelTypeHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 2106 )
AzureIoTClient 0:1f9b2707ec7d 2107 {
AzureIoTClient 0:1f9b2707ec7d 2108 /*Codes_SRS_SCHEMA_99_173: [Schema_GetModelModelyByIndex shall return NULL in the cases when it cannot provide the handle.]*/
AzureIoTClient 0:1f9b2707ec7d 2109 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 2110 LogError("error SCHEMA_INVALID_ARG");
AzureIoTClient 0:1f9b2707ec7d 2111 }
AzureIoTClient 0:1f9b2707ec7d 2112 else
AzureIoTClient 0:1f9b2707ec7d 2113 {
AzureIoTClient 17:fa1bba4c6053 2114 SCHEMA_MODEL_TYPE_HANDLE_DATA* model = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 2115 size_t nModelsInModel;
AzureIoTClient 0:1f9b2707ec7d 2116 /*Codes_SRS_SCHEMA_99_172: [ Schema_GetModelModelyByIndex shall return a handle to the "index"th model inserted in the model identified by the parameter modelTypeHandle.]*/
AzureIoTClient 0:1f9b2707ec7d 2117 /*Codes_SRS_SCHEMA_99_173: [Schema_GetModelModelyByIndex shall return NULL in the cases when it cannot provide the handle.]*/
AzureIoTClient 0:1f9b2707ec7d 2118 nModelsInModel = VECTOR_size(model->models);
AzureIoTClient 0:1f9b2707ec7d 2119 if (index < nModelsInModel)
AzureIoTClient 0:1f9b2707ec7d 2120 {
AzureIoTClient 0:1f9b2707ec7d 2121 result = ((MODEL_IN_MODEL*)VECTOR_element(model->models, index))->modelHandle;
AzureIoTClient 0:1f9b2707ec7d 2122 }
AzureIoTClient 0:1f9b2707ec7d 2123 else
AzureIoTClient 0:1f9b2707ec7d 2124 {
AzureIoTClient 0:1f9b2707ec7d 2125 LogError("attempted out of bounds access in array.");
AzureIoTClient 0:1f9b2707ec7d 2126 result = NULL; /*out of bounds array access*/
AzureIoTClient 0:1f9b2707ec7d 2127 }
AzureIoTClient 0:1f9b2707ec7d 2128 }
AzureIoTClient 0:1f9b2707ec7d 2129 return result;
AzureIoTClient 0:1f9b2707ec7d 2130 }
AzureIoTClient 0:1f9b2707ec7d 2131
AzureIoTClient 0:1f9b2707ec7d 2132 const char* Schema_GetModelModelPropertyNameByIndex(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t index)
AzureIoTClient 0:1f9b2707ec7d 2133 {
AzureIoTClient 0:1f9b2707ec7d 2134 const char* result;
AzureIoTClient 0:1f9b2707ec7d 2135 if (modelTypeHandle == NULL)
AzureIoTClient 0:1f9b2707ec7d 2136 {
AzureIoTClient 0:1f9b2707ec7d 2137 /*Codes_SRS_SCHEMA_99_176: [If Schema_GetModelModelPropertyNameByIndex cannot produce the property name, it shall return NULL.]*/
AzureIoTClient 0:1f9b2707ec7d 2138 result = NULL;
AzureIoTClient 0:1f9b2707ec7d 2139 }
AzureIoTClient 0:1f9b2707ec7d 2140 else
AzureIoTClient 0:1f9b2707ec7d 2141 {
AzureIoTClient 17:fa1bba4c6053 2142 SCHEMA_MODEL_TYPE_HANDLE_DATA* model = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 2143 size_t nModelsInModel;
AzureIoTClient 0:1f9b2707ec7d 2144 /*Codes_SRS_SCHEMA_99_175: [Schema_GetModelModelPropertyNameByIndex shall return the name of the property for the "index"th model in the model identified by modelTypeHandle parameter.]*/
AzureIoTClient 0:1f9b2707ec7d 2145 /*Codes_SRS_SCHEMA_99_176: [If Schema_GetModelModelPropertyNameByIndex cannot produce the property name, it shall return NULL.]*/
AzureIoTClient 0:1f9b2707ec7d 2146 nModelsInModel = VECTOR_size(model->models);
AzureIoTClient 0:1f9b2707ec7d 2147 if (index < nModelsInModel)
AzureIoTClient 0:1f9b2707ec7d 2148 {
AzureIoTClient 0:1f9b2707ec7d 2149 result = ((MODEL_IN_MODEL*)VECTOR_element(model->models, index))->propertyName;
AzureIoTClient 0:1f9b2707ec7d 2150 }
AzureIoTClient 0:1f9b2707ec7d 2151 else
AzureIoTClient 0:1f9b2707ec7d 2152 {
AzureIoTClient 0:1f9b2707ec7d 2153 LogError("attempted out of bounds access in array.");
AzureIoTClient 0:1f9b2707ec7d 2154 result = NULL; /*out of bounds array access*/
AzureIoTClient 0:1f9b2707ec7d 2155 }
AzureIoTClient 0:1f9b2707ec7d 2156 }
AzureIoTClient 0:1f9b2707ec7d 2157 return result;
AzureIoTClient 0:1f9b2707ec7d 2158 }
AzureIoTClient 0:1f9b2707ec7d 2159
AzureIoTClient 0:1f9b2707ec7d 2160 bool Schema_ModelPropertyByPathExists(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* propertyPath)
AzureIoTClient 0:1f9b2707ec7d 2161 {
AzureIoTClient 0:1f9b2707ec7d 2162 bool result;
AzureIoTClient 0:1f9b2707ec7d 2163
AzureIoTClient 0:1f9b2707ec7d 2164 /* Codes_SRS_SCHEMA_99_180: [If any of the arguments are NULL, Schema_ModelPropertyByPathExists shall return false.] */
AzureIoTClient 0:1f9b2707ec7d 2165 if ((modelTypeHandle == NULL) ||
AzureIoTClient 0:1f9b2707ec7d 2166 (propertyPath == NULL))
AzureIoTClient 0:1f9b2707ec7d 2167 {
AzureIoTClient 0:1f9b2707ec7d 2168 LogError("error SCHEMA_INVALID_ARG");
AzureIoTClient 0:1f9b2707ec7d 2169 result = false;
AzureIoTClient 0:1f9b2707ec7d 2170 }
AzureIoTClient 0:1f9b2707ec7d 2171 else
AzureIoTClient 0:1f9b2707ec7d 2172 {
AzureIoTClient 0:1f9b2707ec7d 2173 const char* slashPos;
AzureIoTClient 0:1f9b2707ec7d 2174 result = false;
AzureIoTClient 0:1f9b2707ec7d 2175
AzureIoTClient 0:1f9b2707ec7d 2176 /* Codes_SRS_SCHEMA_99_182: [A single slash ('/') at the beginning of the path shall be ignored and the path shall still be valid.] */
AzureIoTClient 0:1f9b2707ec7d 2177 if (*propertyPath == '/')
AzureIoTClient 0:1f9b2707ec7d 2178 {
AzureIoTClient 0:1f9b2707ec7d 2179 propertyPath++;
AzureIoTClient 0:1f9b2707ec7d 2180 }
AzureIoTClient 0:1f9b2707ec7d 2181
AzureIoTClient 0:1f9b2707ec7d 2182 do
AzureIoTClient 0:1f9b2707ec7d 2183 {
AzureIoTClient 0:1f9b2707ec7d 2184 const char* endPos;
AzureIoTClient 0:1f9b2707ec7d 2185 size_t i;
AzureIoTClient 0:1f9b2707ec7d 2186 size_t modelCount;
AzureIoTClient 17:fa1bba4c6053 2187 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 0:1f9b2707ec7d 2188
AzureIoTClient 0:1f9b2707ec7d 2189 /* Codes_SRS_SCHEMA_99_179: [The propertyPath shall be assumed to be in the format model1/model2/.../propertyName.] */
AzureIoTClient 0:1f9b2707ec7d 2190 slashPos = strchr(propertyPath, '/');
AzureIoTClient 0:1f9b2707ec7d 2191 endPos = slashPos;
AzureIoTClient 0:1f9b2707ec7d 2192 if (endPos == NULL)
AzureIoTClient 0:1f9b2707ec7d 2193 {
AzureIoTClient 0:1f9b2707ec7d 2194 endPos = &propertyPath[strlen(propertyPath)];
AzureIoTClient 0:1f9b2707ec7d 2195 }
AzureIoTClient 0:1f9b2707ec7d 2196
AzureIoTClient 0:1f9b2707ec7d 2197 /* get the child-model */
AzureIoTClient 0:1f9b2707ec7d 2198 modelCount = VECTOR_size(modelType->models);
AzureIoTClient 0:1f9b2707ec7d 2199 for (i = 0; i < modelCount; i++)
AzureIoTClient 0:1f9b2707ec7d 2200 {
AzureIoTClient 0:1f9b2707ec7d 2201 MODEL_IN_MODEL* childModel = (MODEL_IN_MODEL*)VECTOR_element(modelType->models, i);
AzureIoTClient 0:1f9b2707ec7d 2202 if ((strncmp(childModel->propertyName, propertyPath, endPos - propertyPath) == 0) &&
AzureIoTClient 0:1f9b2707ec7d 2203 (strlen(childModel->propertyName) == (size_t)(endPos - propertyPath)))
AzureIoTClient 0:1f9b2707ec7d 2204 {
AzureIoTClient 0:1f9b2707ec7d 2205 /* found */
AzureIoTClient 0:1f9b2707ec7d 2206 modelTypeHandle = childModel->modelHandle;
AzureIoTClient 0:1f9b2707ec7d 2207 break;
AzureIoTClient 0:1f9b2707ec7d 2208 }
AzureIoTClient 0:1f9b2707ec7d 2209 }
AzureIoTClient 0:1f9b2707ec7d 2210
AzureIoTClient 0:1f9b2707ec7d 2211 if (i < modelCount)
AzureIoTClient 0:1f9b2707ec7d 2212 {
AzureIoTClient 0:1f9b2707ec7d 2213 /* model found, check if there is more in the path */
AzureIoTClient 0:1f9b2707ec7d 2214 if (slashPos == NULL)
AzureIoTClient 0:1f9b2707ec7d 2215 {
AzureIoTClient 0:1f9b2707ec7d 2216 /* this is the last one, so this is the thing we were looking for */
AzureIoTClient 0:1f9b2707ec7d 2217 result = true;
AzureIoTClient 0:1f9b2707ec7d 2218 break;
AzureIoTClient 0:1f9b2707ec7d 2219 }
AzureIoTClient 0:1f9b2707ec7d 2220 else
AzureIoTClient 0:1f9b2707ec7d 2221 {
AzureIoTClient 0:1f9b2707ec7d 2222 /* continue looking, there's more */
AzureIoTClient 0:1f9b2707ec7d 2223 propertyPath = slashPos + 1;
AzureIoTClient 0:1f9b2707ec7d 2224 }
AzureIoTClient 0:1f9b2707ec7d 2225 }
AzureIoTClient 0:1f9b2707ec7d 2226 else
AzureIoTClient 0:1f9b2707ec7d 2227 {
AzureIoTClient 0:1f9b2707ec7d 2228 /* no model found, let's see if this is a property */
AzureIoTClient 0:1f9b2707ec7d 2229 /* Codes_SRS_SCHEMA_99_178: [The argument propertyPath shall be used to find the leaf property.] */
AzureIoTClient 0:1f9b2707ec7d 2230 for (i = 0; i < modelType->PropertyCount; i++)
AzureIoTClient 0:1f9b2707ec7d 2231 {
AzureIoTClient 17:fa1bba4c6053 2232 SCHEMA_PROPERTY_HANDLE_DATA* property = (SCHEMA_PROPERTY_HANDLE_DATA*)modelType->Properties[i];
AzureIoTClient 0:1f9b2707ec7d 2233 if ((strncmp(property->PropertyName, propertyPath, endPos - propertyPath) == 0) &&
AzureIoTClient 0:1f9b2707ec7d 2234 (strlen(property->PropertyName) == (size_t)(endPos - propertyPath)))
AzureIoTClient 0:1f9b2707ec7d 2235 {
AzureIoTClient 0:1f9b2707ec7d 2236 /* found property */
AzureIoTClient 0:1f9b2707ec7d 2237 /* Codes_SRS_SCHEMA_99_177: [Schema_ModelPropertyByPathExists shall return true if a leaf property exists in the model modelTypeHandle.] */
AzureIoTClient 0:1f9b2707ec7d 2238 result = true;
AzureIoTClient 0:1f9b2707ec7d 2239 break;
AzureIoTClient 0:1f9b2707ec7d 2240 }
AzureIoTClient 0:1f9b2707ec7d 2241 }
AzureIoTClient 0:1f9b2707ec7d 2242
AzureIoTClient 0:1f9b2707ec7d 2243 break;
AzureIoTClient 0:1f9b2707ec7d 2244 }
AzureIoTClient 0:1f9b2707ec7d 2245 } while (slashPos != NULL);
AzureIoTClient 0:1f9b2707ec7d 2246 }
AzureIoTClient 0:1f9b2707ec7d 2247
AzureIoTClient 0:1f9b2707ec7d 2248 return result;
AzureIoTClient 0:1f9b2707ec7d 2249 }
AzureIoTClient 17:fa1bba4c6053 2250
AzureIoTClient 17:fa1bba4c6053 2251 bool Schema_ModelReportedPropertyByPathExists(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* reportedPropertyPath)
AzureIoTClient 17:fa1bba4c6053 2252 {
AzureIoTClient 17:fa1bba4c6053 2253 bool result;
AzureIoTClient 17:fa1bba4c6053 2254
AzureIoTClient 17:fa1bba4c6053 2255 /*Codes_SRS_SCHEMA_02_018: [ If argument modelTypeHandle is NULL then Schema_ModelReportedPropertyByPathExists shall fail and return false. ]*/
AzureIoTClient 17:fa1bba4c6053 2256 /*Codes_SRS_SCHEMA_02_019: [ If argument reportedPropertyPath is NULL then Schema_ModelReportedPropertyByPathExists shall fail and return false. ]*/
AzureIoTClient 17:fa1bba4c6053 2257 if ((modelTypeHandle == NULL) ||
AzureIoTClient 17:fa1bba4c6053 2258 (reportedPropertyPath == NULL))
AzureIoTClient 17:fa1bba4c6053 2259 {
AzureIoTClient 17:fa1bba4c6053 2260 LogError("invalid argument SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle=%p, const char* reportedPropertyPath=%s", modelTypeHandle, reportedPropertyPath);
AzureIoTClient 17:fa1bba4c6053 2261 result = false;
AzureIoTClient 17:fa1bba4c6053 2262 }
AzureIoTClient 17:fa1bba4c6053 2263 else
AzureIoTClient 17:fa1bba4c6053 2264 {
AzureIoTClient 17:fa1bba4c6053 2265 const char* slashPos;
AzureIoTClient 17:fa1bba4c6053 2266
AzureIoTClient 17:fa1bba4c6053 2267 /*Codes_SRS_SCHEMA_02_021: [ If the reported property cannot be found Schema_ModelReportedPropertyByPathExists shall fail and return false. ]*/
AzureIoTClient 17:fa1bba4c6053 2268 result = false;
AzureIoTClient 17:fa1bba4c6053 2269
AzureIoTClient 17:fa1bba4c6053 2270 /*Codes_SRS_SCHEMA_02_020: [ reportedPropertyPath shall be assumed to be in the format model1/model2/.../reportedPropertyName. ]*/
AzureIoTClient 17:fa1bba4c6053 2271 if (*reportedPropertyPath == '/')
AzureIoTClient 17:fa1bba4c6053 2272 {
AzureIoTClient 17:fa1bba4c6053 2273 reportedPropertyPath++;
AzureIoTClient 17:fa1bba4c6053 2274 }
AzureIoTClient 17:fa1bba4c6053 2275
AzureIoTClient 17:fa1bba4c6053 2276 do
AzureIoTClient 17:fa1bba4c6053 2277 {
AzureIoTClient 17:fa1bba4c6053 2278 const char* endPos;
AzureIoTClient 17:fa1bba4c6053 2279 size_t i;
AzureIoTClient 17:fa1bba4c6053 2280 size_t modelCount;
AzureIoTClient 17:fa1bba4c6053 2281 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 2282
AzureIoTClient 17:fa1bba4c6053 2283 slashPos = strchr(reportedPropertyPath, '/');
AzureIoTClient 17:fa1bba4c6053 2284 endPos = slashPos;
AzureIoTClient 17:fa1bba4c6053 2285 if (endPos == NULL)
AzureIoTClient 17:fa1bba4c6053 2286 {
AzureIoTClient 17:fa1bba4c6053 2287 endPos = &reportedPropertyPath[strlen(reportedPropertyPath)];
AzureIoTClient 17:fa1bba4c6053 2288 }
AzureIoTClient 17:fa1bba4c6053 2289
AzureIoTClient 17:fa1bba4c6053 2290 modelCount = VECTOR_size(modelType->models);
AzureIoTClient 17:fa1bba4c6053 2291 for (i = 0; i < modelCount; i++)
AzureIoTClient 17:fa1bba4c6053 2292 {
AzureIoTClient 17:fa1bba4c6053 2293 MODEL_IN_MODEL* childModel = (MODEL_IN_MODEL*)VECTOR_element(modelType->models, i);
AzureIoTClient 17:fa1bba4c6053 2294 if ((strncmp(childModel->propertyName, reportedPropertyPath, endPos - reportedPropertyPath) == 0) &&
AzureIoTClient 17:fa1bba4c6053 2295 (strlen(childModel->propertyName) == (size_t)(endPos - reportedPropertyPath)))
AzureIoTClient 17:fa1bba4c6053 2296 {
AzureIoTClient 17:fa1bba4c6053 2297 /* found */
AzureIoTClient 17:fa1bba4c6053 2298 modelTypeHandle = childModel->modelHandle;
AzureIoTClient 17:fa1bba4c6053 2299 break;
AzureIoTClient 17:fa1bba4c6053 2300 }
AzureIoTClient 17:fa1bba4c6053 2301 }
AzureIoTClient 17:fa1bba4c6053 2302
AzureIoTClient 17:fa1bba4c6053 2303 if (i < modelCount)
AzureIoTClient 17:fa1bba4c6053 2304 {
AzureIoTClient 17:fa1bba4c6053 2305 /* model found, check if there is more in the path */
AzureIoTClient 17:fa1bba4c6053 2306 if (slashPos == NULL)
AzureIoTClient 17:fa1bba4c6053 2307 {
AzureIoTClient 17:fa1bba4c6053 2308 /*Codes_SRS_SCHEMA_02_022: [ If the path reportedPropertyPath points to a sub-model, Schema_ModelReportedPropertyByPathExists shall succeed and true. ]*/
AzureIoTClient 17:fa1bba4c6053 2309 /* this is the last one, so this is the thing we were looking for */
AzureIoTClient 17:fa1bba4c6053 2310 result = true;
AzureIoTClient 17:fa1bba4c6053 2311 break;
AzureIoTClient 17:fa1bba4c6053 2312 }
AzureIoTClient 17:fa1bba4c6053 2313 else
AzureIoTClient 17:fa1bba4c6053 2314 {
AzureIoTClient 17:fa1bba4c6053 2315 /* continue looking, there's more */
AzureIoTClient 17:fa1bba4c6053 2316 reportedPropertyPath = slashPos + 1;
AzureIoTClient 17:fa1bba4c6053 2317 }
AzureIoTClient 17:fa1bba4c6053 2318 }
AzureIoTClient 17:fa1bba4c6053 2319 else
AzureIoTClient 17:fa1bba4c6053 2320 {
AzureIoTClient 17:fa1bba4c6053 2321 /* no model found, let's see if this is a property */
AzureIoTClient 17:fa1bba4c6053 2322 result = (VECTOR_find_if(modelType->reportedProperties, reportedPropertyExists, reportedPropertyPath) != NULL);
AzureIoTClient 17:fa1bba4c6053 2323 if (!result)
AzureIoTClient 17:fa1bba4c6053 2324 {
AzureIoTClient 17:fa1bba4c6053 2325 LogError("no such reported property \"%s\"", reportedPropertyPath);
AzureIoTClient 17:fa1bba4c6053 2326 }
AzureIoTClient 17:fa1bba4c6053 2327 break;
AzureIoTClient 17:fa1bba4c6053 2328 }
AzureIoTClient 17:fa1bba4c6053 2329 } while (slashPos != NULL);
AzureIoTClient 17:fa1bba4c6053 2330 }
AzureIoTClient 17:fa1bba4c6053 2331
AzureIoTClient 17:fa1bba4c6053 2332 return result;
AzureIoTClient 17:fa1bba4c6053 2333 }
AzureIoTClient 17:fa1bba4c6053 2334
AzureIoTClient 17:fa1bba4c6053 2335 static bool desiredPropertyExists(const void* element, const void* value)
AzureIoTClient 17:fa1bba4c6053 2336 {
AzureIoTClient 17:fa1bba4c6053 2337 SCHEMA_DESIRED_PROPERTY_HANDLE_DATA* desiredProperty = *(SCHEMA_DESIRED_PROPERTY_HANDLE_DATA**)element;
AzureIoTClient 17:fa1bba4c6053 2338 return (strcmp(desiredProperty->desiredPropertyName, value) == 0);
AzureIoTClient 17:fa1bba4c6053 2339 }
AzureIoTClient 17:fa1bba4c6053 2340
AzureIoTClient 17:fa1bba4c6053 2341 SCHEMA_RESULT Schema_AddModelDesiredProperty(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* desiredPropertyName, const char* desiredPropertyType, pfDesiredPropertyFromAGENT_DATA_TYPE desiredPropertyFromAGENT_DATA_TYPE, pfDesiredPropertyInitialize desiredPropertyInitialize, pfDesiredPropertyDeinitialize desiredPropertyDeinitialize, size_t offset, pfOnDesiredProperty onDesiredProperty)
AzureIoTClient 17:fa1bba4c6053 2342 {
AzureIoTClient 17:fa1bba4c6053 2343 SCHEMA_RESULT result;
AzureIoTClient 17:fa1bba4c6053 2344 /*Codes_SRS_SCHEMA_02_024: [ If modelTypeHandle is NULL then Schema_AddModelDesiredProperty shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 2345 /*Codes_SRS_SCHEMA_02_025: [ If desiredPropertyName is NULL then Schema_AddModelDesiredProperty shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 2346 /*Codes_SRS_SCHEMA_02_026: [ If desiredPropertyType is NULL then Schema_AddModelDesiredProperty shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 2347 /*Codes_SRS_SCHEMA_02_048: [ If desiredPropertyFromAGENT_DATA_TYPE is NULL then Schema_AddModelDesiredProperty shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 2348 /*Codes_SRS_SCHEMA_02_049: [ If desiredPropertyInitialize is NULL then Schema_AddModelDesiredProperty shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 2349 /*Codes_SRS_SCHEMA_02_050: [ If desiredPropertyDeinitialize is NULL then Schema_AddModelDesiredProperty shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 2350 if (
AzureIoTClient 17:fa1bba4c6053 2351 (modelTypeHandle == NULL) ||
AzureIoTClient 17:fa1bba4c6053 2352 (desiredPropertyName == NULL) ||
AzureIoTClient 17:fa1bba4c6053 2353 (desiredPropertyType == NULL) ||
AzureIoTClient 17:fa1bba4c6053 2354 (desiredPropertyFromAGENT_DATA_TYPE == NULL) ||
AzureIoTClient 17:fa1bba4c6053 2355 (desiredPropertyInitialize == NULL) ||
AzureIoTClient 17:fa1bba4c6053 2356 (desiredPropertyDeinitialize== NULL)
AzureIoTClient 17:fa1bba4c6053 2357 )
AzureIoTClient 17:fa1bba4c6053 2358 {
AzureIoTClient 17:fa1bba4c6053 2359 LogError("invalid arg SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle=%p, const char* desiredPropertyName=%p, const char* desiredPropertyType=%p, pfDesiredPropertyFromAGENT_DATA_TYPE desiredPropertyFromAGENT_DATA_TYPE=%p, pfDesiredPropertyInitialize desiredPropertyInitialize=%p, pfDesiredPropertyDeinitialize desiredPropertyDeinitialize=%p, size_t offset=%zu",
AzureIoTClient 17:fa1bba4c6053 2360 modelTypeHandle, desiredPropertyName, desiredPropertyType, desiredPropertyFromAGENT_DATA_TYPE, desiredPropertyInitialize, desiredPropertyDeinitialize, offset);
AzureIoTClient 17:fa1bba4c6053 2361 result = SCHEMA_INVALID_ARG;
AzureIoTClient 17:fa1bba4c6053 2362 }
AzureIoTClient 17:fa1bba4c6053 2363 else
AzureIoTClient 17:fa1bba4c6053 2364 {
AzureIoTClient 17:fa1bba4c6053 2365 SCHEMA_MODEL_TYPE_HANDLE_DATA* handleData = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 2366 /*Codes_SRS_SCHEMA_02_027: [ Schema_AddModelDesiredProperty shall add the desired property given by the name desiredPropertyName and the type desiredPropertyType to the collection of existing desired properties. ]*/
AzureIoTClient 17:fa1bba4c6053 2367 if (VECTOR_find_if(handleData->desiredProperties, desiredPropertyExists, desiredPropertyName) != NULL)
AzureIoTClient 17:fa1bba4c6053 2368 {
AzureIoTClient 17:fa1bba4c6053 2369 /*Codes_SRS_SCHEMA_02_047: [ If the desired property already exists, then Schema_AddModelDesiredProperty shall fail and return SCHEMA_DUPLICATE_ELEMENT. ]*/
AzureIoTClient 17:fa1bba4c6053 2370 LogError("unable to Schema_AddModelDesiredProperty because a desired property with the same name (%s) already exists", desiredPropertyName);
AzureIoTClient 17:fa1bba4c6053 2371 result = SCHEMA_DUPLICATE_ELEMENT;
AzureIoTClient 17:fa1bba4c6053 2372 }
AzureIoTClient 17:fa1bba4c6053 2373 else
AzureIoTClient 17:fa1bba4c6053 2374 {
AzureIoTClient 17:fa1bba4c6053 2375 SCHEMA_DESIRED_PROPERTY_HANDLE_DATA* desiredProperty = (SCHEMA_DESIRED_PROPERTY_HANDLE_DATA*)malloc(sizeof(SCHEMA_DESIRED_PROPERTY_HANDLE_DATA));
AzureIoTClient 17:fa1bba4c6053 2376 if (desiredProperty == NULL)
AzureIoTClient 17:fa1bba4c6053 2377 {
AzureIoTClient 17:fa1bba4c6053 2378 /*Codes_SRS_SCHEMA_02_028: [ If any failure occurs then Schema_AddModelDesiredProperty shall fail and return SCHEMA_ERROR. ]*/
AzureIoTClient 17:fa1bba4c6053 2379 LogError("failure in malloc");
AzureIoTClient 17:fa1bba4c6053 2380 result = SCHEMA_ERROR;
AzureIoTClient 17:fa1bba4c6053 2381 }
AzureIoTClient 17:fa1bba4c6053 2382 else
AzureIoTClient 17:fa1bba4c6053 2383 {
AzureIoTClient 17:fa1bba4c6053 2384 if (mallocAndStrcpy_s((char**)&desiredProperty->desiredPropertyName, desiredPropertyName) != 0)
AzureIoTClient 17:fa1bba4c6053 2385 {
AzureIoTClient 17:fa1bba4c6053 2386 /*Codes_SRS_SCHEMA_02_028: [ If any failure occurs then Schema_AddModelDesiredProperty shall fail and return SCHEMA_ERROR. ]*/
AzureIoTClient 17:fa1bba4c6053 2387 LogError("failure in mallocAndStrcpy_s");
AzureIoTClient 17:fa1bba4c6053 2388 free(desiredProperty);
AzureIoTClient 17:fa1bba4c6053 2389 result = SCHEMA_ERROR;
AzureIoTClient 17:fa1bba4c6053 2390 }
AzureIoTClient 17:fa1bba4c6053 2391 else
AzureIoTClient 17:fa1bba4c6053 2392 {
AzureIoTClient 17:fa1bba4c6053 2393 if (mallocAndStrcpy_s((char**)&desiredProperty->desiredPropertyType, desiredPropertyType) != 0)
AzureIoTClient 17:fa1bba4c6053 2394 {
AzureIoTClient 17:fa1bba4c6053 2395 /*Codes_SRS_SCHEMA_02_028: [ If any failure occurs then Schema_AddModelDesiredProperty shall fail and return SCHEMA_ERROR. ]*/
AzureIoTClient 17:fa1bba4c6053 2396 LogError("failure in mallocAndStrcpy_s");
AzureIoTClient 17:fa1bba4c6053 2397 free((void*)desiredProperty->desiredPropertyName);
AzureIoTClient 17:fa1bba4c6053 2398 free(desiredProperty);
AzureIoTClient 17:fa1bba4c6053 2399 result = SCHEMA_ERROR;
AzureIoTClient 17:fa1bba4c6053 2400 }
AzureIoTClient 17:fa1bba4c6053 2401 else
AzureIoTClient 17:fa1bba4c6053 2402 {
AzureIoTClient 17:fa1bba4c6053 2403 if (VECTOR_push_back(handleData->desiredProperties, &desiredProperty, 1) != 0)
AzureIoTClient 17:fa1bba4c6053 2404 {
AzureIoTClient 17:fa1bba4c6053 2405 /*Codes_SRS_SCHEMA_02_028: [ If any failure occurs then Schema_AddModelDesiredProperty shall fail and return SCHEMA_ERROR. ]*/
AzureIoTClient 17:fa1bba4c6053 2406 LogError("failure in VECTOR_push_back");
AzureIoTClient 17:fa1bba4c6053 2407 free((void*)desiredProperty->desiredPropertyType);
AzureIoTClient 17:fa1bba4c6053 2408 free((void*)desiredProperty->desiredPropertyName);
AzureIoTClient 17:fa1bba4c6053 2409 free(desiredProperty);
AzureIoTClient 17:fa1bba4c6053 2410 result = SCHEMA_ERROR;
AzureIoTClient 17:fa1bba4c6053 2411 }
AzureIoTClient 17:fa1bba4c6053 2412 else
AzureIoTClient 17:fa1bba4c6053 2413 {
AzureIoTClient 17:fa1bba4c6053 2414 /*Codes_SRS_SCHEMA_02_029: [ Otherwise, Schema_AddModelDesiredProperty shall succeed and return SCHEMA_OK. ]*/
AzureIoTClient 17:fa1bba4c6053 2415 desiredProperty->desiredPropertyFromAGENT_DATA_TYPE = desiredPropertyFromAGENT_DATA_TYPE;
AzureIoTClient 17:fa1bba4c6053 2416 desiredProperty->desiredPropertInitialize = desiredPropertyInitialize;
AzureIoTClient 17:fa1bba4c6053 2417 desiredProperty->desiredPropertDeinitialize = desiredPropertyDeinitialize;
AzureIoTClient 17:fa1bba4c6053 2418 desiredProperty->onDesiredProperty = onDesiredProperty; /*NULL is a perfectly fine value*/
AzureIoTClient 17:fa1bba4c6053 2419 desiredProperty->offset = offset;
AzureIoTClient 17:fa1bba4c6053 2420 result = SCHEMA_OK;
AzureIoTClient 17:fa1bba4c6053 2421 }
AzureIoTClient 17:fa1bba4c6053 2422 }
AzureIoTClient 17:fa1bba4c6053 2423 }
AzureIoTClient 17:fa1bba4c6053 2424 }
AzureIoTClient 17:fa1bba4c6053 2425 }
AzureIoTClient 17:fa1bba4c6053 2426 }
AzureIoTClient 17:fa1bba4c6053 2427 return result;
AzureIoTClient 17:fa1bba4c6053 2428 }
AzureIoTClient 17:fa1bba4c6053 2429
AzureIoTClient 17:fa1bba4c6053 2430
AzureIoTClient 17:fa1bba4c6053 2431 SCHEMA_RESULT Schema_GetModelDesiredPropertyCount(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t* desiredPropertyCount)
AzureIoTClient 17:fa1bba4c6053 2432 {
AzureIoTClient 17:fa1bba4c6053 2433 SCHEMA_RESULT result;
AzureIoTClient 17:fa1bba4c6053 2434 /*Codes_SRS_SCHEMA_02_030: [ If modelTypeHandle is NULL then Schema_GetModelDesiredPropertyCount shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 2435 /*Codes_SRS_SCHEMA_02_031: [ If desiredPropertyCount is NULL then Schema_GetModelDesiredPropertyCount shall fail and return SCHEMA_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 2436 if (
AzureIoTClient 17:fa1bba4c6053 2437 (modelTypeHandle == NULL) ||
AzureIoTClient 17:fa1bba4c6053 2438 (desiredPropertyCount == NULL)
AzureIoTClient 17:fa1bba4c6053 2439 )
AzureIoTClient 17:fa1bba4c6053 2440 {
AzureIoTClient 17:fa1bba4c6053 2441 LogError("invalid arg: SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle=%p, size_t* desiredPropertyCount=%p", modelTypeHandle, desiredPropertyCount);
AzureIoTClient 17:fa1bba4c6053 2442 result = SCHEMA_INVALID_ARG;
AzureIoTClient 17:fa1bba4c6053 2443 }
AzureIoTClient 17:fa1bba4c6053 2444 else
AzureIoTClient 17:fa1bba4c6053 2445 {
AzureIoTClient 17:fa1bba4c6053 2446 /*Codes_SRS_SCHEMA_02_032: [ Otherwise, Schema_GetModelDesiredPropertyCount shall succeed and write in desiredPropertyCount the existing number of desired properties. ]*/
AzureIoTClient 17:fa1bba4c6053 2447 SCHEMA_MODEL_TYPE_HANDLE_DATA* handleData = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 2448 *desiredPropertyCount = VECTOR_size(handleData->desiredProperties);
AzureIoTClient 17:fa1bba4c6053 2449 result = SCHEMA_OK;
AzureIoTClient 17:fa1bba4c6053 2450 }
AzureIoTClient 17:fa1bba4c6053 2451 return result;
AzureIoTClient 17:fa1bba4c6053 2452 }
AzureIoTClient 17:fa1bba4c6053 2453
AzureIoTClient 17:fa1bba4c6053 2454 SCHEMA_DESIRED_PROPERTY_HANDLE Schema_GetModelDesiredPropertyByName(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* desiredPropertyName)
AzureIoTClient 17:fa1bba4c6053 2455 {
AzureIoTClient 17:fa1bba4c6053 2456 SCHEMA_DESIRED_PROPERTY_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 2457 /*Codes_SRS_SCHEMA_02_034: [ If modelTypeHandle is NULL then Schema_GetModelDesiredPropertyByName shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2458 /*Codes_SRS_SCHEMA_02_035: [ If desiredPropertyName is NULL then Schema_GetModelDesiredPropertyByName shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2459 if (
AzureIoTClient 17:fa1bba4c6053 2460 (modelTypeHandle == NULL) ||
AzureIoTClient 17:fa1bba4c6053 2461 (desiredPropertyName == NULL)
AzureIoTClient 17:fa1bba4c6053 2462 )
AzureIoTClient 17:fa1bba4c6053 2463 {
AzureIoTClient 17:fa1bba4c6053 2464 LogError("invalid arg SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle=%p, const char* desiredPropertyName=%p", modelTypeHandle, desiredPropertyName);
AzureIoTClient 17:fa1bba4c6053 2465 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2466 }
AzureIoTClient 17:fa1bba4c6053 2467 else
AzureIoTClient 17:fa1bba4c6053 2468 {
AzureIoTClient 17:fa1bba4c6053 2469 /*Codes_SRS_SCHEMA_02_036: [ If a desired property having the name desiredPropertyName exists then Schema_GetModelDesiredPropertyByName shall succeed and return a non-NULL value. ]*/
AzureIoTClient 17:fa1bba4c6053 2470 /*Codes_SRS_SCHEMA_02_037: [ Otherwise, Schema_GetModelDesiredPropertyByName shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2471 SCHEMA_MODEL_TYPE_HANDLE_DATA* handleData = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 2472 SCHEMA_DESIRED_PROPERTY_HANDLE* temp = VECTOR_find_if(handleData->desiredProperties, desiredPropertyExists, desiredPropertyName);
AzureIoTClient 17:fa1bba4c6053 2473 if (temp == NULL)
AzureIoTClient 17:fa1bba4c6053 2474 {
AzureIoTClient 17:fa1bba4c6053 2475 LogError("no such desired property by name %s", desiredPropertyName);
AzureIoTClient 17:fa1bba4c6053 2476 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2477 }
AzureIoTClient 17:fa1bba4c6053 2478 else
AzureIoTClient 17:fa1bba4c6053 2479 {
AzureIoTClient 17:fa1bba4c6053 2480 result = *temp;
AzureIoTClient 17:fa1bba4c6053 2481 }
AzureIoTClient 17:fa1bba4c6053 2482 }
AzureIoTClient 17:fa1bba4c6053 2483 return result;
AzureIoTClient 17:fa1bba4c6053 2484 }
AzureIoTClient 17:fa1bba4c6053 2485
AzureIoTClient 17:fa1bba4c6053 2486 SCHEMA_DESIRED_PROPERTY_HANDLE Schema_GetModelDesiredPropertyByIndex(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t index)
AzureIoTClient 17:fa1bba4c6053 2487 {
AzureIoTClient 17:fa1bba4c6053 2488 SCHEMA_DESIRED_PROPERTY_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 2489 /*Codes_SRS_SCHEMA_02_038: [ If modelTypeHandle is NULL then Schema_GetModelDesiredPropertyByIndex shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2490 if (modelTypeHandle == NULL)
AzureIoTClient 17:fa1bba4c6053 2491 {
AzureIoTClient 17:fa1bba4c6053 2492 LogError("invalid argument SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle=%p, size_t index=%p", modelTypeHandle, index);
AzureIoTClient 17:fa1bba4c6053 2493 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2494 }
AzureIoTClient 17:fa1bba4c6053 2495 else
AzureIoTClient 17:fa1bba4c6053 2496 {
AzureIoTClient 17:fa1bba4c6053 2497 SCHEMA_MODEL_TYPE_HANDLE_DATA* handleData = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 2498 /*Codes_SRS_SCHEMA_02_039: [ If index is outside the range for existing indexes of desire properties, then Schema_GetModelDesiredPropertyByIndex shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2499 /*Codes_SRS_SCHEMA_02_040: [ Otherwise, Schema_GetModelDesiredPropertyByIndex shall succeed and return a non-NULL value. ]*/
AzureIoTClient 17:fa1bba4c6053 2500 SCHEMA_DESIRED_PROPERTY_HANDLE* temp = VECTOR_element(handleData->desiredProperties, index);
AzureIoTClient 17:fa1bba4c6053 2501 if (temp == NULL)
AzureIoTClient 17:fa1bba4c6053 2502 {
AzureIoTClient 17:fa1bba4c6053 2503 LogError("VECTOR_element produced NULL (likely out of bounds index)");
AzureIoTClient 17:fa1bba4c6053 2504 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2505 }
AzureIoTClient 17:fa1bba4c6053 2506 else
AzureIoTClient 17:fa1bba4c6053 2507 {
AzureIoTClient 17:fa1bba4c6053 2508 result = *temp;
AzureIoTClient 17:fa1bba4c6053 2509 }
AzureIoTClient 17:fa1bba4c6053 2510 }
AzureIoTClient 17:fa1bba4c6053 2511 return result;
AzureIoTClient 17:fa1bba4c6053 2512 }
AzureIoTClient 17:fa1bba4c6053 2513
AzureIoTClient 17:fa1bba4c6053 2514 bool Schema_ModelDesiredPropertyByPathExists(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* desiredPropertyPath)
AzureIoTClient 17:fa1bba4c6053 2515 {
AzureIoTClient 17:fa1bba4c6053 2516 bool result;
AzureIoTClient 17:fa1bba4c6053 2517 /*Codes_SRS_SCHEMA_02_041: [ If modelTypeHandle is NULL then Schema_ModelDesiredPropertyByPathExists shall fail and return false. ]*/
AzureIoTClient 17:fa1bba4c6053 2518 /*Codes_SRS_SCHEMA_02_042: [ If desiredPropertyPath is NULL then Schema_ModelDesiredPropertyByPathExists shall fail and return false. ]*/
AzureIoTClient 17:fa1bba4c6053 2519 if (
AzureIoTClient 17:fa1bba4c6053 2520 (modelTypeHandle == NULL) ||
AzureIoTClient 17:fa1bba4c6053 2521 (desiredPropertyPath == NULL)
AzureIoTClient 17:fa1bba4c6053 2522 )
AzureIoTClient 17:fa1bba4c6053 2523 {
AzureIoTClient 17:fa1bba4c6053 2524 LogError("invalid arg SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle=%p, const char* desiredPropertyPath=%p", modelTypeHandle, desiredPropertyPath);
AzureIoTClient 17:fa1bba4c6053 2525 result = false;
AzureIoTClient 17:fa1bba4c6053 2526 }
AzureIoTClient 17:fa1bba4c6053 2527 else
AzureIoTClient 17:fa1bba4c6053 2528 {
AzureIoTClient 17:fa1bba4c6053 2529 const char* slashPos;
AzureIoTClient 17:fa1bba4c6053 2530
AzureIoTClient 17:fa1bba4c6053 2531 /*Codes_SRS_SCHEMA_02_044: [ If the desired property cannot be found Schema_ModelDesiredPropertyByPathExists shall fail and return false. ]*/
AzureIoTClient 17:fa1bba4c6053 2532 result = false;
AzureIoTClient 17:fa1bba4c6053 2533
AzureIoTClient 17:fa1bba4c6053 2534 /*Codes_SRS_SCHEMA_02_043: [ desiredPropertyPath shall be assumed to be in the format model1/model2/.../desiredPropertyName. ]*/
AzureIoTClient 17:fa1bba4c6053 2535 if (*desiredPropertyPath == '/')
AzureIoTClient 17:fa1bba4c6053 2536 {
AzureIoTClient 17:fa1bba4c6053 2537 desiredPropertyPath++;
AzureIoTClient 17:fa1bba4c6053 2538 }
AzureIoTClient 17:fa1bba4c6053 2539
AzureIoTClient 17:fa1bba4c6053 2540 do
AzureIoTClient 17:fa1bba4c6053 2541 {
AzureIoTClient 17:fa1bba4c6053 2542 const char* endPos;
AzureIoTClient 17:fa1bba4c6053 2543 size_t i;
AzureIoTClient 17:fa1bba4c6053 2544 size_t modelCount;
AzureIoTClient 17:fa1bba4c6053 2545 SCHEMA_MODEL_TYPE_HANDLE_DATA* modelType = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 2546
AzureIoTClient 17:fa1bba4c6053 2547 slashPos = strchr(desiredPropertyPath, '/');
AzureIoTClient 17:fa1bba4c6053 2548 endPos = slashPos;
AzureIoTClient 17:fa1bba4c6053 2549 if (endPos == NULL)
AzureIoTClient 17:fa1bba4c6053 2550 {
AzureIoTClient 17:fa1bba4c6053 2551 endPos = &desiredPropertyPath[strlen(desiredPropertyPath)];
AzureIoTClient 17:fa1bba4c6053 2552 }
AzureIoTClient 17:fa1bba4c6053 2553
AzureIoTClient 17:fa1bba4c6053 2554 modelCount = VECTOR_size(modelType->models);
AzureIoTClient 17:fa1bba4c6053 2555 for (i = 0; i < modelCount; i++)
AzureIoTClient 17:fa1bba4c6053 2556 {
AzureIoTClient 17:fa1bba4c6053 2557 MODEL_IN_MODEL* childModel = (MODEL_IN_MODEL*)VECTOR_element(modelType->models, i);
AzureIoTClient 17:fa1bba4c6053 2558 if ((strncmp(childModel->propertyName, desiredPropertyPath, endPos - desiredPropertyPath) == 0) &&
AzureIoTClient 17:fa1bba4c6053 2559 (strlen(childModel->propertyName) == (size_t)(endPos - desiredPropertyPath)))
AzureIoTClient 17:fa1bba4c6053 2560 {
AzureIoTClient 17:fa1bba4c6053 2561 /* found */
AzureIoTClient 17:fa1bba4c6053 2562 modelTypeHandle = childModel->modelHandle;
AzureIoTClient 17:fa1bba4c6053 2563 break;
AzureIoTClient 17:fa1bba4c6053 2564 }
AzureIoTClient 17:fa1bba4c6053 2565 }
AzureIoTClient 17:fa1bba4c6053 2566
AzureIoTClient 17:fa1bba4c6053 2567 if (i < modelCount)
AzureIoTClient 17:fa1bba4c6053 2568 {
AzureIoTClient 17:fa1bba4c6053 2569 /* model found, check if there is more in the path */
AzureIoTClient 17:fa1bba4c6053 2570 if (slashPos == NULL)
AzureIoTClient 17:fa1bba4c6053 2571 {
AzureIoTClient 17:fa1bba4c6053 2572 /*Codes_SRS_SCHEMA_02_045: [ If the path desiredPropertyPath points to a sub-model, Schema_ModelDesiredPropertyByPathExists shall succeed and true. ]*/
AzureIoTClient 17:fa1bba4c6053 2573 /* this is the last one, so this is the thing we were looking for */
AzureIoTClient 17:fa1bba4c6053 2574 result = true;
AzureIoTClient 17:fa1bba4c6053 2575 break;
AzureIoTClient 17:fa1bba4c6053 2576 }
AzureIoTClient 17:fa1bba4c6053 2577 else
AzureIoTClient 17:fa1bba4c6053 2578 {
AzureIoTClient 17:fa1bba4c6053 2579 /* continue looking, there's more */
AzureIoTClient 17:fa1bba4c6053 2580 desiredPropertyPath = slashPos + 1;
AzureIoTClient 17:fa1bba4c6053 2581 }
AzureIoTClient 17:fa1bba4c6053 2582 }
AzureIoTClient 17:fa1bba4c6053 2583 else
AzureIoTClient 17:fa1bba4c6053 2584 {
AzureIoTClient 17:fa1bba4c6053 2585 /* no model found, let's see if this is a property */
AzureIoTClient 17:fa1bba4c6053 2586 result = (VECTOR_find_if(modelType->desiredProperties, desiredPropertyExists, desiredPropertyPath) != NULL);
AzureIoTClient 17:fa1bba4c6053 2587 if (!result)
AzureIoTClient 17:fa1bba4c6053 2588 {
AzureIoTClient 17:fa1bba4c6053 2589 LogError("no such desired property \"%s\"", desiredPropertyPath);
AzureIoTClient 17:fa1bba4c6053 2590 }
AzureIoTClient 17:fa1bba4c6053 2591 break;
AzureIoTClient 17:fa1bba4c6053 2592 }
AzureIoTClient 17:fa1bba4c6053 2593 } while (slashPos != NULL);
AzureIoTClient 17:fa1bba4c6053 2594 }
AzureIoTClient 17:fa1bba4c6053 2595 return result;
AzureIoTClient 17:fa1bba4c6053 2596 }
AzureIoTClient 17:fa1bba4c6053 2597
AzureIoTClient 17:fa1bba4c6053 2598 const char* Schema_GetModelDesiredPropertyType(SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle)
AzureIoTClient 17:fa1bba4c6053 2599 {
AzureIoTClient 17:fa1bba4c6053 2600 const char* result;
AzureIoTClient 17:fa1bba4c6053 2601 /*Codes_SRS_SCHEMA_02_062: [ If desiredPropertyHandle is NULL then Schema_GetModelDesiredPropertyType shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2602 if (desiredPropertyHandle == NULL)
AzureIoTClient 17:fa1bba4c6053 2603 {
AzureIoTClient 17:fa1bba4c6053 2604 LogError("invalid argument SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle=%p", desiredPropertyHandle);
AzureIoTClient 17:fa1bba4c6053 2605 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2606 }
AzureIoTClient 17:fa1bba4c6053 2607 else
AzureIoTClient 17:fa1bba4c6053 2608 {
AzureIoTClient 17:fa1bba4c6053 2609 /*Codes_SRS_SCHEMA_02_063: [ Otherwise, Schema_GetModelDesiredPropertyType shall return the type of the desired property. ]*/
AzureIoTClient 17:fa1bba4c6053 2610 SCHEMA_DESIRED_PROPERTY_HANDLE_DATA* desirePropertyHandleData = (SCHEMA_DESIRED_PROPERTY_HANDLE_DATA*)desiredPropertyHandle;
AzureIoTClient 17:fa1bba4c6053 2611 result = desirePropertyHandleData->desiredPropertyType;
AzureIoTClient 17:fa1bba4c6053 2612 }
AzureIoTClient 17:fa1bba4c6053 2613 return result;
AzureIoTClient 17:fa1bba4c6053 2614 }
AzureIoTClient 17:fa1bba4c6053 2615
AzureIoTClient 17:fa1bba4c6053 2616 pfDesiredPropertyFromAGENT_DATA_TYPE Schema_GetModelDesiredProperty_pfDesiredPropertyFromAGENT_DATA_TYPE(SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle)
AzureIoTClient 17:fa1bba4c6053 2617 {
AzureIoTClient 17:fa1bba4c6053 2618 pfDesiredPropertyFromAGENT_DATA_TYPE result;
AzureIoTClient 17:fa1bba4c6053 2619 if (desiredPropertyHandle == NULL)
AzureIoTClient 17:fa1bba4c6053 2620 {
AzureIoTClient 17:fa1bba4c6053 2621 LogError("invalid argument SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle=%p", desiredPropertyHandle);
AzureIoTClient 17:fa1bba4c6053 2622 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2623 }
AzureIoTClient 17:fa1bba4c6053 2624 else
AzureIoTClient 17:fa1bba4c6053 2625 {
AzureIoTClient 17:fa1bba4c6053 2626 SCHEMA_DESIRED_PROPERTY_HANDLE_DATA* desirePropertyHandleData = (SCHEMA_DESIRED_PROPERTY_HANDLE_DATA*)desiredPropertyHandle;
AzureIoTClient 17:fa1bba4c6053 2627 result = desirePropertyHandleData->desiredPropertyFromAGENT_DATA_TYPE;
AzureIoTClient 17:fa1bba4c6053 2628 }
AzureIoTClient 17:fa1bba4c6053 2629 return result;
AzureIoTClient 17:fa1bba4c6053 2630 }
AzureIoTClient 17:fa1bba4c6053 2631
AzureIoTClient 17:fa1bba4c6053 2632 pfOnDesiredProperty Schema_GetModelDesiredProperty_pfOnDesiredProperty(SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle)
AzureIoTClient 17:fa1bba4c6053 2633 {
AzureIoTClient 17:fa1bba4c6053 2634 pfOnDesiredProperty result;
AzureIoTClient 17:fa1bba4c6053 2635 /*Codes_SRS_SCHEMA_02_084: [ If desiredPropertyHandle is NULL then Schema_GetModelDesiredProperty_pfOnDesiredProperty shall return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2636 if (desiredPropertyHandle == NULL)
AzureIoTClient 17:fa1bba4c6053 2637 {
AzureIoTClient 17:fa1bba4c6053 2638 LogError("invalid argument SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle=%p", desiredPropertyHandle);
AzureIoTClient 17:fa1bba4c6053 2639 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2640 }
AzureIoTClient 17:fa1bba4c6053 2641 else
AzureIoTClient 17:fa1bba4c6053 2642 {
AzureIoTClient 17:fa1bba4c6053 2643 /*Codes_SRS_SCHEMA_02_085: [ Otherwise Schema_GetModelDesiredProperty_pfOnDesiredProperty shall return the saved desired property callback. ]*/
AzureIoTClient 17:fa1bba4c6053 2644 SCHEMA_DESIRED_PROPERTY_HANDLE_DATA* desirePropertyHandleData = (SCHEMA_DESIRED_PROPERTY_HANDLE_DATA*)desiredPropertyHandle;
AzureIoTClient 17:fa1bba4c6053 2645 result = desirePropertyHandleData->onDesiredProperty;
AzureIoTClient 17:fa1bba4c6053 2646 }
AzureIoTClient 17:fa1bba4c6053 2647 return result;
AzureIoTClient 17:fa1bba4c6053 2648 }
AzureIoTClient 17:fa1bba4c6053 2649
AzureIoTClient 17:fa1bba4c6053 2650 size_t Schema_GetModelDesiredProperty_offset(SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle)
AzureIoTClient 17:fa1bba4c6053 2651 {
AzureIoTClient 17:fa1bba4c6053 2652 size_t result;
AzureIoTClient 17:fa1bba4c6053 2653 /*Codes_SRS_SCHEMA_02_060: [ If desiredPropertyHandle is NULL then Schema_GetModelDesiredProperty_offset shall fail and return 0. ]*/
AzureIoTClient 17:fa1bba4c6053 2654 if (desiredPropertyHandle == NULL)
AzureIoTClient 17:fa1bba4c6053 2655 {
AzureIoTClient 17:fa1bba4c6053 2656 LogError("invalid argument SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle=%p", desiredPropertyHandle);
AzureIoTClient 17:fa1bba4c6053 2657 result = 0;
AzureIoTClient 17:fa1bba4c6053 2658 }
AzureIoTClient 17:fa1bba4c6053 2659 else
AzureIoTClient 17:fa1bba4c6053 2660 {
AzureIoTClient 17:fa1bba4c6053 2661 /*Codes_SRS_SCHEMA_02_061: [ Otherwise Schema_GetModelDesiredProperty_offset shall succeed and return the offset. ]*/
AzureIoTClient 17:fa1bba4c6053 2662 SCHEMA_DESIRED_PROPERTY_HANDLE_DATA* desirePropertyHandleData = (SCHEMA_DESIRED_PROPERTY_HANDLE_DATA*)desiredPropertyHandle;
AzureIoTClient 17:fa1bba4c6053 2663 result = desirePropertyHandleData->offset;
AzureIoTClient 17:fa1bba4c6053 2664 }
AzureIoTClient 17:fa1bba4c6053 2665 return result;
AzureIoTClient 17:fa1bba4c6053 2666 }
AzureIoTClient 17:fa1bba4c6053 2667
AzureIoTClient 17:fa1bba4c6053 2668 static bool modelInModelExists(const void* element, const void* value)
AzureIoTClient 17:fa1bba4c6053 2669 {
AzureIoTClient 17:fa1bba4c6053 2670 MODEL_IN_MODEL* modelInModel = (MODEL_IN_MODEL*)element;
AzureIoTClient 17:fa1bba4c6053 2671 return (strcmp(modelInModel->propertyName, value) == 0);
AzureIoTClient 17:fa1bba4c6053 2672 }
AzureIoTClient 17:fa1bba4c6053 2673
AzureIoTClient 17:fa1bba4c6053 2674 SCHEMA_MODEL_ELEMENT Schema_GetModelElementByName(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* elementName)
AzureIoTClient 17:fa1bba4c6053 2675 {
AzureIoTClient 17:fa1bba4c6053 2676 SCHEMA_MODEL_ELEMENT result;
AzureIoTClient 17:fa1bba4c6053 2677 /*Codes_SRS_SCHEMA_02_076: [ If modelTypeHandle is NULL then Schema_GetModelElementByName shall fail and set SCHEMA_MODEL_ELEMENT.elementType to SCHEMA_SEARCH_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 2678 /*Codes_SRS_SCHEMA_02_077: [ If elementName is NULL then Schema_GetModelElementByName shall fail and set SCHEMA_MODEL_ELEMENT.elementType to SCHEMA_SEARCH_INVALID_ARG. ]*/
AzureIoTClient 17:fa1bba4c6053 2679 if (
AzureIoTClient 17:fa1bba4c6053 2680 (modelTypeHandle == NULL) ||
AzureIoTClient 17:fa1bba4c6053 2681 (elementName == NULL)
AzureIoTClient 17:fa1bba4c6053 2682 )
AzureIoTClient 17:fa1bba4c6053 2683 {
AzureIoTClient 17:fa1bba4c6053 2684 LogError("invalid argument SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle=%p, const char* elementName=%p", modelTypeHandle, elementName);
AzureIoTClient 17:fa1bba4c6053 2685 result.elementType = SCHEMA_SEARCH_INVALID_ARG;
AzureIoTClient 17:fa1bba4c6053 2686 }
AzureIoTClient 17:fa1bba4c6053 2687 else
AzureIoTClient 17:fa1bba4c6053 2688 {
AzureIoTClient 17:fa1bba4c6053 2689 SCHEMA_MODEL_TYPE_HANDLE_DATA* handleData = (SCHEMA_MODEL_TYPE_HANDLE_DATA*)modelTypeHandle;
AzureIoTClient 17:fa1bba4c6053 2690
AzureIoTClient 17:fa1bba4c6053 2691 SCHEMA_DESIRED_PROPERTY_HANDLE* desiredPropertyHandle = VECTOR_find_if(handleData->desiredProperties, desiredPropertyExists, elementName);
AzureIoTClient 17:fa1bba4c6053 2692 if (desiredPropertyHandle != NULL)
AzureIoTClient 17:fa1bba4c6053 2693 {
AzureIoTClient 17:fa1bba4c6053 2694 /*Codes_SRS_SCHEMA_02_080: [ If elementName is a desired property then Schema_GetModelElementByName shall succeed and set SCHEMA_MODEL_ELEMENT.elementType to SCHEMA_DESIRED_PROPERTY and SCHEMA_MODEL_ELEMENT.elementHandle.desiredPropertyHandle to the handle of the desired property. ]*/
AzureIoTClient 17:fa1bba4c6053 2695 result.elementType = SCHEMA_DESIRED_PROPERTY;
AzureIoTClient 17:fa1bba4c6053 2696 result.elementHandle.desiredPropertyHandle = *desiredPropertyHandle;
AzureIoTClient 17:fa1bba4c6053 2697 }
AzureIoTClient 17:fa1bba4c6053 2698 else
AzureIoTClient 17:fa1bba4c6053 2699 {
AzureIoTClient 17:fa1bba4c6053 2700 size_t nProcessedProperties = 0;
AzureIoTClient 17:fa1bba4c6053 2701 SCHEMA_PROPERTY_HANDLE_DATA* property = NULL;
AzureIoTClient 17:fa1bba4c6053 2702 for (size_t i = 0; i < handleData->PropertyCount;i++)
AzureIoTClient 17:fa1bba4c6053 2703 {
AzureIoTClient 17:fa1bba4c6053 2704 property = (SCHEMA_PROPERTY_HANDLE_DATA*)(handleData->Properties[i]);
AzureIoTClient 17:fa1bba4c6053 2705 if (strcmp(property->PropertyName, elementName) == 0)
AzureIoTClient 17:fa1bba4c6053 2706 {
AzureIoTClient 17:fa1bba4c6053 2707 i = handleData->PropertyCount; /*found it*/
AzureIoTClient 17:fa1bba4c6053 2708 }
AzureIoTClient 17:fa1bba4c6053 2709 else
AzureIoTClient 17:fa1bba4c6053 2710 {
AzureIoTClient 17:fa1bba4c6053 2711 nProcessedProperties++;
AzureIoTClient 17:fa1bba4c6053 2712 }
AzureIoTClient 17:fa1bba4c6053 2713 }
AzureIoTClient 17:fa1bba4c6053 2714
AzureIoTClient 17:fa1bba4c6053 2715 if (nProcessedProperties < handleData->PropertyCount)
AzureIoTClient 17:fa1bba4c6053 2716 {
AzureIoTClient 17:fa1bba4c6053 2717 /*Codes_SRS_SCHEMA_02_078: [ If elementName is a property then Schema_GetModelElementByName shall succeed and set SCHEMA_MODEL_ELEMENT.elementType to SCHEMA_PROPERTY and SCHEMA_MODEL_ELEMENT.elementHandle.propertyHandle to the handle of the property. ]*/
AzureIoTClient 17:fa1bba4c6053 2718 result.elementType = SCHEMA_PROPERTY;
AzureIoTClient 17:fa1bba4c6053 2719 result.elementHandle.propertyHandle = property;
AzureIoTClient 17:fa1bba4c6053 2720 }
AzureIoTClient 17:fa1bba4c6053 2721 else
AzureIoTClient 17:fa1bba4c6053 2722 {
AzureIoTClient 17:fa1bba4c6053 2723
AzureIoTClient 17:fa1bba4c6053 2724 SCHEMA_REPORTED_PROPERTY_HANDLE* reportedPropertyHandle = VECTOR_find_if(handleData->reportedProperties, reportedPropertyExists, elementName);
AzureIoTClient 17:fa1bba4c6053 2725 if (reportedPropertyHandle != NULL)
AzureIoTClient 17:fa1bba4c6053 2726 {
AzureIoTClient 17:fa1bba4c6053 2727 /*Codes_SRS_SCHEMA_02_079: [ If elementName is a reported property then Schema_GetModelElementByName shall succeed and set SCHEMA_MODEL_ELEMENT.elementType to SCHEMA_REPORTED_PROPERTY and SCHEMA_MODEL_ELEMENT.elementHandle.reportedPropertyHandle to the handle of the reported property. ]*/
AzureIoTClient 17:fa1bba4c6053 2728 result.elementType = SCHEMA_REPORTED_PROPERTY;
AzureIoTClient 17:fa1bba4c6053 2729 result.elementHandle.reportedPropertyHandle = *reportedPropertyHandle;
AzureIoTClient 17:fa1bba4c6053 2730 }
AzureIoTClient 17:fa1bba4c6053 2731 else
AzureIoTClient 17:fa1bba4c6053 2732 {
AzureIoTClient 17:fa1bba4c6053 2733
AzureIoTClient 17:fa1bba4c6053 2734 size_t nProcessedActions = 0;
AzureIoTClient 17:fa1bba4c6053 2735 SCHEMA_ACTION_HANDLE_DATA* actionHandleData = NULL;
AzureIoTClient 17:fa1bba4c6053 2736 for (size_t i = 0;i < handleData->ActionCount; i++)
AzureIoTClient 17:fa1bba4c6053 2737 {
AzureIoTClient 17:fa1bba4c6053 2738 actionHandleData = (SCHEMA_ACTION_HANDLE_DATA*)(handleData->Actions[i]);
AzureIoTClient 17:fa1bba4c6053 2739 if (strcmp(actionHandleData->ActionName, elementName) == 0)
AzureIoTClient 17:fa1bba4c6053 2740 {
AzureIoTClient 17:fa1bba4c6053 2741 i = handleData->ActionCount; /*get out quickly*/
AzureIoTClient 17:fa1bba4c6053 2742 }
AzureIoTClient 17:fa1bba4c6053 2743 else
AzureIoTClient 17:fa1bba4c6053 2744 {
AzureIoTClient 17:fa1bba4c6053 2745 nProcessedActions++;
AzureIoTClient 17:fa1bba4c6053 2746 }
AzureIoTClient 17:fa1bba4c6053 2747 }
AzureIoTClient 17:fa1bba4c6053 2748
AzureIoTClient 17:fa1bba4c6053 2749 if (nProcessedActions < handleData->ActionCount)
AzureIoTClient 17:fa1bba4c6053 2750 {
AzureIoTClient 17:fa1bba4c6053 2751 /*Codes_SRS_SCHEMA_02_081: [ If elementName is a model action then Schema_GetModelElementByName shall succeed and set SCHEMA_MODEL_ELEMENT.elementType to SCHEMA_MODEL_ACTION and SCHEMA_MODEL_ELEMENT.elementHandle.actionHandle to the handle of the action. ]*/
AzureIoTClient 17:fa1bba4c6053 2752 result.elementType = SCHEMA_MODEL_ACTION;
AzureIoTClient 17:fa1bba4c6053 2753 result.elementHandle.actionHandle = actionHandleData;
AzureIoTClient 17:fa1bba4c6053 2754 }
AzureIoTClient 17:fa1bba4c6053 2755 else
AzureIoTClient 17:fa1bba4c6053 2756 {
AzureIoTClient 17:fa1bba4c6053 2757 MODEL_IN_MODEL* modelInModel = VECTOR_find_if(handleData->models, modelInModelExists, elementName);
AzureIoTClient 17:fa1bba4c6053 2758 if (modelInModel != NULL)
AzureIoTClient 17:fa1bba4c6053 2759 {
AzureIoTClient 17:fa1bba4c6053 2760 /*Codes_SRS_SCHEMA_02_082: [ If elementName is a model in model then Schema_GetModelElementByName shall succeed and set SCHEMA_MODEL_ELEMENT.elementType to SCHEMA_MODEL_IN_MODEL and SCHEMA_MODEL_ELEMENT.elementHandle.modelHandle to the handle of the model. ]*/
AzureIoTClient 17:fa1bba4c6053 2761 result.elementType = SCHEMA_MODEL_IN_MODEL;
AzureIoTClient 17:fa1bba4c6053 2762 result.elementHandle.modelHandle = modelInModel->modelHandle;
AzureIoTClient 17:fa1bba4c6053 2763 }
AzureIoTClient 17:fa1bba4c6053 2764 else
AzureIoTClient 17:fa1bba4c6053 2765 {
AzureIoTClient 17:fa1bba4c6053 2766 /*Codes_SRS_SCHEMA_02_083: [ Otherwise Schema_GetModelElementByName shall fail and set SCHEMA_MODEL_ELEMENT.elementType to SCHEMA_NOT_FOUND. ]*/
AzureIoTClient 17:fa1bba4c6053 2767 result.elementType = SCHEMA_NOT_FOUND;
AzureIoTClient 17:fa1bba4c6053 2768 }
AzureIoTClient 17:fa1bba4c6053 2769 }
AzureIoTClient 17:fa1bba4c6053 2770 }
AzureIoTClient 17:fa1bba4c6053 2771 }
AzureIoTClient 17:fa1bba4c6053 2772 }
AzureIoTClient 17:fa1bba4c6053 2773 }
AzureIoTClient 17:fa1bba4c6053 2774 return result;
AzureIoTClient 17:fa1bba4c6053 2775 }
AzureIoTClient 17:fa1bba4c6053 2776
AzureIoTClient 17:fa1bba4c6053 2777 pfDesiredPropertyDeinitialize Schema_GetModelDesiredProperty_pfDesiredPropertyDeinitialize(SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle)
AzureIoTClient 17:fa1bba4c6053 2778 {
AzureIoTClient 17:fa1bba4c6053 2779 pfDesiredPropertyDeinitialize result;
AzureIoTClient 17:fa1bba4c6053 2780 /*Ccodes_SRS_SCHEMA_02_064: [ If desiredPropertyHandle is NULL then Schema_GetModelDesiredProperty_pfDesiredPropertyDeinitialize shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2781 if (desiredPropertyHandle == NULL)
AzureIoTClient 17:fa1bba4c6053 2782 {
AzureIoTClient 17:fa1bba4c6053 2783 LogError("invalid argument SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle=%p", desiredPropertyHandle);
AzureIoTClient 17:fa1bba4c6053 2784 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2785 }
AzureIoTClient 17:fa1bba4c6053 2786 else
AzureIoTClient 17:fa1bba4c6053 2787 {
AzureIoTClient 17:fa1bba4c6053 2788 /*Codes_SRS_SCHEMA_02_065: [ Otherwise Schema_GetModelDesiredProperty_pfDesiredPropertyDeinitialize shall return a non-NULL function pointer. ]*/
AzureIoTClient 17:fa1bba4c6053 2789 SCHEMA_DESIRED_PROPERTY_HANDLE_DATA* handleData = (SCHEMA_DESIRED_PROPERTY_HANDLE_DATA*)desiredPropertyHandle;
AzureIoTClient 17:fa1bba4c6053 2790 result = handleData->desiredPropertDeinitialize;
AzureIoTClient 17:fa1bba4c6053 2791 }
AzureIoTClient 17:fa1bba4c6053 2792 return result;
AzureIoTClient 17:fa1bba4c6053 2793 }
AzureIoTClient 17:fa1bba4c6053 2794
AzureIoTClient 17:fa1bba4c6053 2795 pfDesiredPropertyInitialize Schema_GetModelDesiredProperty_pfDesiredPropertyInitialize(SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle)
AzureIoTClient 17:fa1bba4c6053 2796 {
AzureIoTClient 17:fa1bba4c6053 2797 pfDesiredPropertyInitialize result;
AzureIoTClient 17:fa1bba4c6053 2798 /*Codes_SRS_SCHEMA_02_066: [ If desiredPropertyHandle is NULL then Schema_GetModelDesiredProperty_pfDesiredPropertyInitialize shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2799 if (desiredPropertyHandle == NULL)
AzureIoTClient 17:fa1bba4c6053 2800 {
AzureIoTClient 17:fa1bba4c6053 2801 LogError("invalid argument SCHEMA_DESIRED_PROPERTY_HANDLE desiredPropertyHandle=%p", desiredPropertyHandle);
AzureIoTClient 17:fa1bba4c6053 2802 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2803 }
AzureIoTClient 17:fa1bba4c6053 2804 else
AzureIoTClient 17:fa1bba4c6053 2805 {
AzureIoTClient 17:fa1bba4c6053 2806 /*Codes_SRS_SCHEMA_02_067: [ Otherwise Schema_GetModelDesiredProperty_pfDesiredPropertyInitialize shall return a non-NULL function pointer. ]*/
AzureIoTClient 17:fa1bba4c6053 2807 SCHEMA_DESIRED_PROPERTY_HANDLE_DATA* handleData = (SCHEMA_DESIRED_PROPERTY_HANDLE_DATA*)desiredPropertyHandle;
AzureIoTClient 17:fa1bba4c6053 2808 result = handleData->desiredPropertInitialize;
AzureIoTClient 17:fa1bba4c6053 2809 }
AzureIoTClient 17:fa1bba4c6053 2810 return result;
AzureIoTClient 17:fa1bba4c6053 2811 }
AzureIoTClient 17:fa1bba4c6053 2812
AzureIoTClient 17:fa1bba4c6053 2813 static bool SchemaHasModel(const SCHEMA_HANDLE* schemaHandle, const char* modelName)
AzureIoTClient 17:fa1bba4c6053 2814 {
AzureIoTClient 17:fa1bba4c6053 2815 return (Schema_GetModelByName(*schemaHandle, modelName) != NULL);
AzureIoTClient 17:fa1bba4c6053 2816 }
AzureIoTClient 17:fa1bba4c6053 2817
AzureIoTClient 17:fa1bba4c6053 2818
AzureIoTClient 17:fa1bba4c6053 2819 SCHEMA_HANDLE Schema_GetSchemaForModel(const char* modelName)
AzureIoTClient 17:fa1bba4c6053 2820 {
AzureIoTClient 17:fa1bba4c6053 2821 SCHEMA_HANDLE result;
AzureIoTClient 17:fa1bba4c6053 2822 /*Codes_SRS_SCHEMA_02_093: [ If modelName is NULL then Schema_GetSchemaForModel shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2823 if (modelName == NULL)
AzureIoTClient 17:fa1bba4c6053 2824 {
AzureIoTClient 17:fa1bba4c6053 2825 LogError("invalid arg const char* modelName=%p", modelName);
AzureIoTClient 17:fa1bba4c6053 2826 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2827 }
AzureIoTClient 17:fa1bba4c6053 2828 else
AzureIoTClient 17:fa1bba4c6053 2829 {
AzureIoTClient 17:fa1bba4c6053 2830 /*Codes_SRS_SCHEMA_02_094: [ Schema_GetSchemaForModel shall find the SCHEMA_HANDLE that contains a model by name modelName and if found, succeed and return that. ]*/
AzureIoTClient 17:fa1bba4c6053 2831 SCHEMA_HANDLE* temp = VECTOR_find_if(g_schemas, (PREDICATE_FUNCTION)SchemaHasModel, modelName);
AzureIoTClient 17:fa1bba4c6053 2832
AzureIoTClient 17:fa1bba4c6053 2833 if (temp == NULL)
AzureIoTClient 17:fa1bba4c6053 2834 {
AzureIoTClient 17:fa1bba4c6053 2835 /*Codes_SRS_SCHEMA_02_095: [ If the model is not found in any schema, then Schema_GetSchemaForModel shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2836 LogError("unable to find a schema that has a model named %s", modelName);
AzureIoTClient 17:fa1bba4c6053 2837 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2838 }
AzureIoTClient 17:fa1bba4c6053 2839 else
AzureIoTClient 17:fa1bba4c6053 2840 {
AzureIoTClient 17:fa1bba4c6053 2841 /*Codes_SRS_SCHEMA_02_094: [ Schema_GetSchemaForModel shall find the SCHEMA_HANDLE that contains a model by name modelName and if found, succeed and return that. ]*/
AzureIoTClient 17:fa1bba4c6053 2842 result = *temp;
AzureIoTClient 17:fa1bba4c6053 2843 }
AzureIoTClient 17:fa1bba4c6053 2844 }
AzureIoTClient 17:fa1bba4c6053 2845
AzureIoTClient 17:fa1bba4c6053 2846 return result;
AzureIoTClient 17:fa1bba4c6053 2847 }
AzureIoTClient 17:fa1bba4c6053 2848
AzureIoTClient 17:fa1bba4c6053 2849 void* Schema_GetMetadata(SCHEMA_HANDLE schemaHandle)
AzureIoTClient 17:fa1bba4c6053 2850 {
AzureIoTClient 17:fa1bba4c6053 2851 void* result;
AzureIoTClient 17:fa1bba4c6053 2852 /*Codes_SRS_SCHEMA_02_091: [ If schemaHandle is NULL then Schema_GetMetadata shall fail and return NULL. ]*/
AzureIoTClient 17:fa1bba4c6053 2853 if (schemaHandle == NULL)
AzureIoTClient 17:fa1bba4c6053 2854 {
AzureIoTClient 17:fa1bba4c6053 2855 LogError("invalid arg SCHEMA_HANDLE schemaHandle=%p", schemaHandle);
AzureIoTClient 17:fa1bba4c6053 2856 result = NULL;
AzureIoTClient 17:fa1bba4c6053 2857 }
AzureIoTClient 17:fa1bba4c6053 2858 else
AzureIoTClient 17:fa1bba4c6053 2859 {
AzureIoTClient 17:fa1bba4c6053 2860 /*Codes_SRS_SCHEMA_02_092: [ Otherwise, Schema_GetMetadata shall succeed and return the saved metadata pointer. ]*/
AzureIoTClient 17:fa1bba4c6053 2861 result = ((SCHEMA_HANDLE_DATA*)schemaHandle)->metadata;
AzureIoTClient 17:fa1bba4c6053 2862 }
AzureIoTClient 17:fa1bba4c6053 2863 return result;
AzureIoTClient 17:fa1bba4c6053 2864 }