A modelling and serializer library for Microsoft Azure IoTHub client applications

Dependents:   sht15_remote_monitoring f767zi_mqtt remote_monitoring simplesample_amqp ... more

This library implements a serializer library to be used in projects involving Microsoft Azure IoT Hub connectivity. The code is replicated from https://github.com/Azure/azure-iot-sdks

Committer:
AzureIoTClient
Date:
Fri Mar 24 16:36:07 2017 -0700
Revision:
24:49c36a13bed1
Parent:
22:422d94bd3c18
Child:
36:7d12a5386197
1.1.10

Who changed what in which revision?

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