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:
Azure.IoT.Build
Date:
Wed Dec 14 16:00:39 2016 -0800
Revision:
18:58b667752399
Parent:
17:fa1bba4c6053
Child:
21:6d3dea1abd9c
1.1.2

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