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
schema.c@13:16e88f0cfa5f, 2016-07-01 (annotated)
- Committer:
- Azure.IoT Build
- Date:
- Fri Jul 01 10:43:11 2016 -0700
- Revision:
- 13:16e88f0cfa5f
- Parent:
- 11:b1327861f5e0
- Child:
- 17:fa1bba4c6053
1.0.10
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AzureIoTClient | 0:1f9b2707ec7d | 1 | // Copyright (c) Microsoft. All rights reserved. |
AzureIoTClient | 0:1f9b2707ec7d | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
AzureIoTClient | 0:1f9b2707ec7d | 3 | |
AzureIoTClient | 0:1f9b2707ec7d | 4 | #include <stdlib.h> |
AzureIoTClient | 0:1f9b2707ec7d | 5 | #ifdef _CRTDBG_MAP_ALLOC |
AzureIoTClient | 0:1f9b2707ec7d | 6 | #include <crtdbg.h> |
AzureIoTClient | 0:1f9b2707ec7d | 7 | #endif |
Azure.IoT Build | 10:c2aee3965a83 | 8 | #include "azure_c_shared_utility/gballoc.h" |
AzureIoTClient | 0:1f9b2707ec7d | 9 | |
AzureIoTClient | 0:1f9b2707ec7d | 10 | #include "schema.h" |
Azure.IoT Build | 10:c2aee3965a83 | 11 | #include "azure_c_shared_utility/crt_abstractions.h" |
Azure.IoT Build | 13:16e88f0cfa5f | 12 | #include "azure_c_shared_utility/xlogging.h" |
Azure.IoT Build | 10:c2aee3965a83 | 13 | #include "azure_c_shared_utility/vector.h" |
AzureIoTClient | 0:1f9b2707ec7d | 14 | |
AzureIoTClient | 0:1f9b2707ec7d | 15 | |
AzureIoTClient | 0:1f9b2707ec7d | 16 | DEFINE_ENUM_STRINGS(SCHEMA_RESULT, SCHEMA_RESULT_VALUES); |
AzureIoTClient | 0:1f9b2707ec7d | 17 | |
AzureIoTClient | 0:1f9b2707ec7d | 18 | typedef struct PROPERTY_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 19 | { |
AzureIoTClient | 0:1f9b2707ec7d | 20 | const char* PropertyName; |
AzureIoTClient | 0:1f9b2707ec7d | 21 | const char* PropertyType; |
AzureIoTClient | 0:1f9b2707ec7d | 22 | } PROPERTY; |
AzureIoTClient | 0:1f9b2707ec7d | 23 | |
AzureIoTClient | 0:1f9b2707ec7d | 24 | typedef struct SCHEMA_ACTION_ARGUMENT_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 25 | { |
AzureIoTClient | 0:1f9b2707ec7d | 26 | const char* Name; |
AzureIoTClient | 0:1f9b2707ec7d | 27 | const char* Type; |
AzureIoTClient | 0:1f9b2707ec7d | 28 | } SCHEMA_ACTION_ARGUMENT; |
AzureIoTClient | 0:1f9b2707ec7d | 29 | |
AzureIoTClient | 0:1f9b2707ec7d | 30 | typedef struct ACTION_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 31 | { |
AzureIoTClient | 0:1f9b2707ec7d | 32 | const char* ActionName; |
AzureIoTClient | 0:1f9b2707ec7d | 33 | size_t ArgumentCount; |
AzureIoTClient | 0:1f9b2707ec7d | 34 | SCHEMA_ACTION_ARGUMENT_HANDLE* ArgumentHandles; |
AzureIoTClient | 0:1f9b2707ec7d | 35 | } ACTION; |
AzureIoTClient | 0:1f9b2707ec7d | 36 | |
AzureIoTClient | 0:1f9b2707ec7d | 37 | typedef struct MODEL_IN_MODEL_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 38 | { |
AzureIoTClient | 0:1f9b2707ec7d | 39 | const char* propertyName; |
AzureIoTClient | 0:1f9b2707ec7d | 40 | SCHEMA_MODEL_TYPE_HANDLE modelHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 41 | } MODEL_IN_MODEL; |
AzureIoTClient | 0:1f9b2707ec7d | 42 | |
AzureIoTClient | 0:1f9b2707ec7d | 43 | typedef struct MODEL_TYPE_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 44 | { |
AzureIoTClient | 0:1f9b2707ec7d | 45 | const char* Name; |
AzureIoTClient | 0:1f9b2707ec7d | 46 | SCHEMA_HANDLE SchemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 47 | SCHEMA_PROPERTY_HANDLE* Properties; |
AzureIoTClient | 0:1f9b2707ec7d | 48 | size_t PropertyCount; |
AzureIoTClient | 0:1f9b2707ec7d | 49 | SCHEMA_ACTION_HANDLE* Actions; |
AzureIoTClient | 0:1f9b2707ec7d | 50 | size_t ActionCount; |
AzureIoTClient | 0:1f9b2707ec7d | 51 | VECTOR_HANDLE models; |
AzureIoTClient | 0:1f9b2707ec7d | 52 | size_t DeviceCount; |
AzureIoTClient | 0:1f9b2707ec7d | 53 | } MODEL_TYPE; |
AzureIoTClient | 0:1f9b2707ec7d | 54 | |
AzureIoTClient | 0:1f9b2707ec7d | 55 | typedef struct STRUCT_TYPE_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 56 | { |
AzureIoTClient | 0:1f9b2707ec7d | 57 | const char* Name; |
AzureIoTClient | 0:1f9b2707ec7d | 58 | SCHEMA_PROPERTY_HANDLE* Properties; |
AzureIoTClient | 0:1f9b2707ec7d | 59 | size_t PropertyCount; |
AzureIoTClient | 0:1f9b2707ec7d | 60 | } STRUCT_TYPE; |
AzureIoTClient | 0:1f9b2707ec7d | 61 | |
AzureIoTClient | 0:1f9b2707ec7d | 62 | typedef struct SCHEMA_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 63 | { |
AzureIoTClient | 0:1f9b2707ec7d | 64 | const char* Namespace; |
AzureIoTClient | 0:1f9b2707ec7d | 65 | SCHEMA_MODEL_TYPE_HANDLE* ModelTypes; |
AzureIoTClient | 0:1f9b2707ec7d | 66 | size_t ModelTypeCount; |
AzureIoTClient | 0:1f9b2707ec7d | 67 | SCHEMA_STRUCT_TYPE_HANDLE* StructTypes; |
AzureIoTClient | 0:1f9b2707ec7d | 68 | size_t StructTypeCount; |
AzureIoTClient | 0:1f9b2707ec7d | 69 | } SCHEMA; |
AzureIoTClient | 0:1f9b2707ec7d | 70 | |
AzureIoTClient | 0:1f9b2707ec7d | 71 | static VECTOR_HANDLE g_schemas = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 72 | |
AzureIoTClient | 0:1f9b2707ec7d | 73 | static void DestroyProperty(SCHEMA_PROPERTY_HANDLE propertyHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 74 | { |
AzureIoTClient | 0:1f9b2707ec7d | 75 | PROPERTY* propertyType = (PROPERTY*)propertyHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 76 | free((void*)propertyType->PropertyName); |
AzureIoTClient | 0:1f9b2707ec7d | 77 | free((void*)propertyType->PropertyType); |
AzureIoTClient | 0:1f9b2707ec7d | 78 | free(propertyType); |
AzureIoTClient | 0:1f9b2707ec7d | 79 | } |
AzureIoTClient | 0:1f9b2707ec7d | 80 | |
AzureIoTClient | 0:1f9b2707ec7d | 81 | static void DestroyActionArgument(SCHEMA_ACTION_ARGUMENT_HANDLE actionArgumentHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 82 | { |
AzureIoTClient | 0:1f9b2707ec7d | 83 | SCHEMA_ACTION_ARGUMENT* actionArgument = (SCHEMA_ACTION_ARGUMENT*)actionArgumentHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 84 | if (actionArgument != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 85 | { |
AzureIoTClient | 0:1f9b2707ec7d | 86 | free((void*)actionArgument->Name); |
AzureIoTClient | 0:1f9b2707ec7d | 87 | free((void*)actionArgument->Type); |
AzureIoTClient | 0:1f9b2707ec7d | 88 | free(actionArgument); |
AzureIoTClient | 0:1f9b2707ec7d | 89 | } |
AzureIoTClient | 0:1f9b2707ec7d | 90 | } |
AzureIoTClient | 0:1f9b2707ec7d | 91 | |
AzureIoTClient | 0:1f9b2707ec7d | 92 | static void DestroyAction(SCHEMA_ACTION_HANDLE actionHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 93 | { |
AzureIoTClient | 0:1f9b2707ec7d | 94 | ACTION* action = (ACTION*)actionHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 95 | if (action != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 96 | { |
AzureIoTClient | 0:1f9b2707ec7d | 97 | size_t j; |
AzureIoTClient | 0:1f9b2707ec7d | 98 | |
AzureIoTClient | 0:1f9b2707ec7d | 99 | for (j = 0; j < action->ArgumentCount; j++) |
AzureIoTClient | 0:1f9b2707ec7d | 100 | { |
AzureIoTClient | 0:1f9b2707ec7d | 101 | DestroyActionArgument(action->ArgumentHandles[j]); |
AzureIoTClient | 0:1f9b2707ec7d | 102 | } |
AzureIoTClient | 0:1f9b2707ec7d | 103 | free(action->ArgumentHandles); |
AzureIoTClient | 0:1f9b2707ec7d | 104 | |
AzureIoTClient | 0:1f9b2707ec7d | 105 | free((void*)action->ActionName); |
AzureIoTClient | 0:1f9b2707ec7d | 106 | free(action); |
AzureIoTClient | 0:1f9b2707ec7d | 107 | } |
AzureIoTClient | 0:1f9b2707ec7d | 108 | } |
AzureIoTClient | 0:1f9b2707ec7d | 109 | |
AzureIoTClient | 0:1f9b2707ec7d | 110 | static void DestroyStruct(SCHEMA_STRUCT_TYPE_HANDLE structTypeHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 111 | { |
AzureIoTClient | 0:1f9b2707ec7d | 112 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 113 | STRUCT_TYPE* structType = (STRUCT_TYPE*)structTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 114 | if (structType != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 115 | { |
AzureIoTClient | 0:1f9b2707ec7d | 116 | for (i = 0; i < structType->PropertyCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 117 | { |
AzureIoTClient | 0:1f9b2707ec7d | 118 | DestroyProperty(structType->Properties[i]); |
AzureIoTClient | 0:1f9b2707ec7d | 119 | } |
AzureIoTClient | 0:1f9b2707ec7d | 120 | free(structType->Properties); |
AzureIoTClient | 0:1f9b2707ec7d | 121 | |
AzureIoTClient | 0:1f9b2707ec7d | 122 | free((void*)structType->Name); |
AzureIoTClient | 0:1f9b2707ec7d | 123 | |
AzureIoTClient | 0:1f9b2707ec7d | 124 | free(structType); |
AzureIoTClient | 0:1f9b2707ec7d | 125 | } |
AzureIoTClient | 0:1f9b2707ec7d | 126 | } |
AzureIoTClient | 0:1f9b2707ec7d | 127 | |
AzureIoTClient | 0:1f9b2707ec7d | 128 | static void DestroyModel(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 129 | { |
AzureIoTClient | 0:1f9b2707ec7d | 130 | MODEL_TYPE* modelType = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 131 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 132 | |
AzureIoTClient | 0:1f9b2707ec7d | 133 | free((void*)modelType->Name); |
AzureIoTClient | 0:1f9b2707ec7d | 134 | modelType->Name = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 135 | |
AzureIoTClient | 0:1f9b2707ec7d | 136 | for (i = 0; i < modelType->PropertyCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 137 | { |
AzureIoTClient | 0:1f9b2707ec7d | 138 | DestroyProperty(modelType->Properties[i]); |
AzureIoTClient | 0:1f9b2707ec7d | 139 | } |
AzureIoTClient | 0:1f9b2707ec7d | 140 | |
AzureIoTClient | 0:1f9b2707ec7d | 141 | free(modelType->Properties); |
AzureIoTClient | 0:1f9b2707ec7d | 142 | |
AzureIoTClient | 0:1f9b2707ec7d | 143 | for (i = 0; i < modelType->ActionCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 144 | { |
AzureIoTClient | 0:1f9b2707ec7d | 145 | DestroyAction(modelType->Actions[i]); |
AzureIoTClient | 0:1f9b2707ec7d | 146 | } |
AzureIoTClient | 0:1f9b2707ec7d | 147 | |
AzureIoTClient | 0:1f9b2707ec7d | 148 | /*destroy the vector holding the added models. This does not destroy the said models, however, their names shall be*/ |
AzureIoTClient | 0:1f9b2707ec7d | 149 | for (i = 0; i < VECTOR_size(modelType->models); i++) |
AzureIoTClient | 0:1f9b2707ec7d | 150 | { |
AzureIoTClient | 0:1f9b2707ec7d | 151 | MODEL_IN_MODEL* temp = (MODEL_IN_MODEL*)VECTOR_element(modelType->models, i); |
AzureIoTClient | 0:1f9b2707ec7d | 152 | free((void*)temp->propertyName); |
AzureIoTClient | 0:1f9b2707ec7d | 153 | } |
AzureIoTClient | 0:1f9b2707ec7d | 154 | VECTOR_clear(modelType->models); |
AzureIoTClient | 0:1f9b2707ec7d | 155 | VECTOR_destroy(modelType->models); |
AzureIoTClient | 0:1f9b2707ec7d | 156 | |
AzureIoTClient | 0:1f9b2707ec7d | 157 | free(modelType->Actions); |
AzureIoTClient | 0:1f9b2707ec7d | 158 | free(modelType); |
AzureIoTClient | 0:1f9b2707ec7d | 159 | } |
AzureIoTClient | 0:1f9b2707ec7d | 160 | |
AzureIoTClient | 0:1f9b2707ec7d | 161 | static SCHEMA_RESULT AddModelProperty(MODEL_TYPE* modelType, const char* name, const char* type) |
AzureIoTClient | 0:1f9b2707ec7d | 162 | { |
AzureIoTClient | 0:1f9b2707ec7d | 163 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 164 | |
AzureIoTClient | 0:1f9b2707ec7d | 165 | /* Codes_SRS_SCHEMA_99_013:[If any of the arguments is NULL, Schema_AddModelProperty shall return SCHEMA_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 166 | if ((modelType == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 167 | (name == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 168 | (type == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 169 | { |
AzureIoTClient | 0:1f9b2707ec7d | 170 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 11:b1327861f5e0 | 171 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 172 | } |
AzureIoTClient | 0:1f9b2707ec7d | 173 | else |
AzureIoTClient | 0:1f9b2707ec7d | 174 | { |
AzureIoTClient | 0:1f9b2707ec7d | 175 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 176 | |
AzureIoTClient | 0:1f9b2707ec7d | 177 | /* 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 | 178 | for (i = 0; i < modelType->PropertyCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 179 | { |
AzureIoTClient | 0:1f9b2707ec7d | 180 | PROPERTY* property = (PROPERTY*)modelType->Properties[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 181 | if (strcmp(property->PropertyName, name) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 182 | { |
AzureIoTClient | 0:1f9b2707ec7d | 183 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 184 | } |
AzureIoTClient | 0:1f9b2707ec7d | 185 | } |
AzureIoTClient | 0:1f9b2707ec7d | 186 | |
AzureIoTClient | 0:1f9b2707ec7d | 187 | if (i < modelType->PropertyCount) |
AzureIoTClient | 0:1f9b2707ec7d | 188 | { |
AzureIoTClient | 0:1f9b2707ec7d | 189 | result = SCHEMA_DUPLICATE_ELEMENT; |
AzureIoTClient | 11:b1327861f5e0 | 190 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 191 | } |
AzureIoTClient | 0:1f9b2707ec7d | 192 | else |
AzureIoTClient | 0:1f9b2707ec7d | 193 | { |
AzureIoTClient | 0:1f9b2707ec7d | 194 | SCHEMA_PROPERTY_HANDLE* newProperties = (SCHEMA_PROPERTY_HANDLE*)realloc(modelType->Properties, sizeof(SCHEMA_PROPERTY_HANDLE) * (modelType->PropertyCount + 1)); |
AzureIoTClient | 0:1f9b2707ec7d | 195 | if (newProperties == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 196 | { |
AzureIoTClient | 0:1f9b2707ec7d | 197 | /* Codes_SRS_SCHEMA_99_014:[On any other error, Schema_AddModelProperty shall return SCHEMA_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 198 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 199 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 200 | } |
AzureIoTClient | 0:1f9b2707ec7d | 201 | else |
AzureIoTClient | 0:1f9b2707ec7d | 202 | { |
AzureIoTClient | 0:1f9b2707ec7d | 203 | PROPERTY* newProperty; |
AzureIoTClient | 0:1f9b2707ec7d | 204 | |
AzureIoTClient | 0:1f9b2707ec7d | 205 | modelType->Properties = newProperties; |
AzureIoTClient | 0:1f9b2707ec7d | 206 | if ((newProperty = (PROPERTY*)malloc(sizeof(PROPERTY))) == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 207 | { |
AzureIoTClient | 0:1f9b2707ec7d | 208 | /* Codes_SRS_SCHEMA_99_014:[On any other error, Schema_AddModelProperty shall return SCHEMA_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 209 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 210 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 211 | } |
AzureIoTClient | 0:1f9b2707ec7d | 212 | else |
AzureIoTClient | 0:1f9b2707ec7d | 213 | { |
AzureIoTClient | 0:1f9b2707ec7d | 214 | if (mallocAndStrcpy_s((char**)&newProperty->PropertyName, name) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 215 | { |
AzureIoTClient | 0:1f9b2707ec7d | 216 | /* Codes_SRS_SCHEMA_99_014:[On any other error, Schema_AddModelProperty shall return SCHEMA_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 217 | free(newProperty); |
AzureIoTClient | 0:1f9b2707ec7d | 218 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 219 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 220 | } |
AzureIoTClient | 0:1f9b2707ec7d | 221 | else if (mallocAndStrcpy_s((char**)&newProperty->PropertyType, type) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 222 | { |
AzureIoTClient | 0:1f9b2707ec7d | 223 | /* Codes_SRS_SCHEMA_99_014:[On any other error, Schema_AddModelProperty shall return SCHEMA_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 224 | free((void*)newProperty->PropertyName); |
AzureIoTClient | 0:1f9b2707ec7d | 225 | free(newProperty); |
AzureIoTClient | 0:1f9b2707ec7d | 226 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 227 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 228 | } |
AzureIoTClient | 0:1f9b2707ec7d | 229 | else |
AzureIoTClient | 0:1f9b2707ec7d | 230 | { |
AzureIoTClient | 0:1f9b2707ec7d | 231 | modelType->Properties[modelType->PropertyCount] = (SCHEMA_PROPERTY_HANDLE)newProperty; |
AzureIoTClient | 0:1f9b2707ec7d | 232 | modelType->PropertyCount++; |
AzureIoTClient | 0:1f9b2707ec7d | 233 | |
AzureIoTClient | 0:1f9b2707ec7d | 234 | /* Codes_SRS_SCHEMA_99_012:[On success, Schema_AddModelProperty shall return SCHEMA_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 235 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 236 | } |
AzureIoTClient | 0:1f9b2707ec7d | 237 | } |
AzureIoTClient | 0:1f9b2707ec7d | 238 | |
AzureIoTClient | 0:1f9b2707ec7d | 239 | /* If possible, reduce the memory of over allocation */ |
AzureIoTClient | 0:1f9b2707ec7d | 240 | if (result != SCHEMA_OK) |
AzureIoTClient | 0:1f9b2707ec7d | 241 | { |
AzureIoTClient | 0:1f9b2707ec7d | 242 | SCHEMA_PROPERTY_HANDLE* oldProperties = (SCHEMA_PROPERTY_HANDLE*)realloc(modelType->Properties, sizeof(SCHEMA_PROPERTY_HANDLE) * modelType->PropertyCount); |
AzureIoTClient | 0:1f9b2707ec7d | 243 | if (oldProperties == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 244 | { |
AzureIoTClient | 0:1f9b2707ec7d | 245 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 246 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 247 | } |
AzureIoTClient | 0:1f9b2707ec7d | 248 | else |
AzureIoTClient | 0:1f9b2707ec7d | 249 | { |
AzureIoTClient | 0:1f9b2707ec7d | 250 | modelType->Properties = oldProperties; |
AzureIoTClient | 0:1f9b2707ec7d | 251 | } |
AzureIoTClient | 0:1f9b2707ec7d | 252 | } |
AzureIoTClient | 0:1f9b2707ec7d | 253 | } |
AzureIoTClient | 0:1f9b2707ec7d | 254 | } |
AzureIoTClient | 0:1f9b2707ec7d | 255 | } |
AzureIoTClient | 0:1f9b2707ec7d | 256 | |
AzureIoTClient | 0:1f9b2707ec7d | 257 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 258 | } |
AzureIoTClient | 0:1f9b2707ec7d | 259 | |
AzureIoTClient | 0:1f9b2707ec7d | 260 | static bool SchemaHandlesMatch(const SCHEMA_HANDLE* handle, const SCHEMA_HANDLE* otherHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 261 | { |
AzureIoTClient | 0:1f9b2707ec7d | 262 | return (*handle == *otherHandle); |
AzureIoTClient | 0:1f9b2707ec7d | 263 | } |
AzureIoTClient | 0:1f9b2707ec7d | 264 | |
AzureIoTClient | 0:1f9b2707ec7d | 265 | static bool SchemaNamespacesMatch(const SCHEMA_HANDLE* handle, const char* schemaNamespace) |
AzureIoTClient | 0:1f9b2707ec7d | 266 | { |
AzureIoTClient | 0:1f9b2707ec7d | 267 | const SCHEMA* schema = (SCHEMA*)*handle; |
AzureIoTClient | 0:1f9b2707ec7d | 268 | return (strcmp(schema->Namespace, schemaNamespace) == 0); |
AzureIoTClient | 0:1f9b2707ec7d | 269 | } |
AzureIoTClient | 0:1f9b2707ec7d | 270 | |
AzureIoTClient | 0:1f9b2707ec7d | 271 | /* Codes_SRS_SCHEMA_99_001:[Schema_Create shall initialize a schema with a given namespace.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 272 | SCHEMA_HANDLE Schema_Create(const char* schemaNamespace) |
AzureIoTClient | 0:1f9b2707ec7d | 273 | { |
AzureIoTClient | 0:1f9b2707ec7d | 274 | SCHEMA* result; |
AzureIoTClient | 0:1f9b2707ec7d | 275 | |
AzureIoTClient | 0:1f9b2707ec7d | 276 | /* Codes_SRS_SCHEMA_99_004:[If schemaNamespace is NULL, Schema_Create shall fail.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 277 | if (schemaNamespace == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 278 | { |
AzureIoTClient | 0:1f9b2707ec7d | 279 | /* Codes_SRS_SCHEMA_99_003:[On failure, NULL shall be returned.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 280 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 281 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 282 | } |
AzureIoTClient | 0:1f9b2707ec7d | 283 | else |
AzureIoTClient | 0:1f9b2707ec7d | 284 | { |
AzureIoTClient | 0:1f9b2707ec7d | 285 | if (g_schemas == NULL && (g_schemas = VECTOR_create(sizeof(SCHEMA*) ) ) == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 286 | { |
AzureIoTClient | 0:1f9b2707ec7d | 287 | /* Codes_SRS_SCHEMA_99_003:[On failure, NULL shall be returned.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 288 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 289 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 290 | } |
AzureIoTClient | 0:1f9b2707ec7d | 291 | else if ((result = (SCHEMA*)malloc(sizeof(SCHEMA))) == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 292 | { |
AzureIoTClient | 0:1f9b2707ec7d | 293 | /* Codes_SRS_SCHEMA_99_003:[On failure, NULL shall be returned.] */ |
AzureIoTClient | 11:b1327861f5e0 | 294 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 295 | } |
AzureIoTClient | 0:1f9b2707ec7d | 296 | else if (mallocAndStrcpy_s((char**)&result->Namespace, schemaNamespace) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 297 | { |
AzureIoTClient | 0:1f9b2707ec7d | 298 | /* Codes_SRS_SCHEMA_99_003:[On failure, NULL shall be returned.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 299 | free(result); |
AzureIoTClient | 0:1f9b2707ec7d | 300 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 301 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 302 | } |
AzureIoTClient | 0:1f9b2707ec7d | 303 | else if (VECTOR_push_back(g_schemas, &result, 1) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 304 | { |
AzureIoTClient | 0:1f9b2707ec7d | 305 | free((void*)result->Namespace); |
AzureIoTClient | 0:1f9b2707ec7d | 306 | free(result); |
AzureIoTClient | 0:1f9b2707ec7d | 307 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 308 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 309 | } |
AzureIoTClient | 0:1f9b2707ec7d | 310 | else |
AzureIoTClient | 0:1f9b2707ec7d | 311 | { |
AzureIoTClient | 0:1f9b2707ec7d | 312 | /* Codes_SRS_SCHEMA_99_002:[On success a non-NULL handle to the newly created schema shall be returned.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 313 | result->ModelTypes = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 314 | result->ModelTypeCount = 0; |
AzureIoTClient | 0:1f9b2707ec7d | 315 | result->StructTypes = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 316 | result->StructTypeCount = 0; |
AzureIoTClient | 0:1f9b2707ec7d | 317 | } |
AzureIoTClient | 0:1f9b2707ec7d | 318 | } |
AzureIoTClient | 0:1f9b2707ec7d | 319 | |
AzureIoTClient | 0:1f9b2707ec7d | 320 | return (SCHEMA_HANDLE)result; |
AzureIoTClient | 0:1f9b2707ec7d | 321 | } |
AzureIoTClient | 0:1f9b2707ec7d | 322 | |
AzureIoTClient | 0:1f9b2707ec7d | 323 | size_t Schema_GetSchemaCount(void) |
AzureIoTClient | 0:1f9b2707ec7d | 324 | { |
AzureIoTClient | 0:1f9b2707ec7d | 325 | /* Codes_SRS_SCHEMA_99_153: [Schema_GetSchemaCount shall return the number of "active" schemas (all schemas created with Schema_Create |
AzureIoTClient | 0:1f9b2707ec7d | 326 | in the current process, for which Schema_Destroy has not been called).] */ |
AzureIoTClient | 0:1f9b2707ec7d | 327 | return VECTOR_size(g_schemas); |
AzureIoTClient | 0:1f9b2707ec7d | 328 | } |
AzureIoTClient | 0:1f9b2707ec7d | 329 | |
AzureIoTClient | 0:1f9b2707ec7d | 330 | SCHEMA_HANDLE Schema_GetSchemaByNamespace(const char* schemaNamespace) |
AzureIoTClient | 0:1f9b2707ec7d | 331 | { |
AzureIoTClient | 0:1f9b2707ec7d | 332 | /* Codes_SRS_SCHEMA_99_151: [If no active schema matches the schemaNamespace argument, Schema_GetSchemaByNamespace shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 333 | SCHEMA_HANDLE result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 334 | |
AzureIoTClient | 0:1f9b2707ec7d | 335 | /* Codes_SRS_SCHEMA_99_150: [If the schemaNamespace argument is NULL, Schema_GetSchemaByNamespace shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 336 | if (schemaNamespace != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 337 | { |
AzureIoTClient | 0:1f9b2707ec7d | 338 | SCHEMA_HANDLE* handle = (SCHEMA_HANDLE*)VECTOR_find_if(g_schemas, (PREDICATE_FUNCTION)SchemaNamespacesMatch, schemaNamespace); |
AzureIoTClient | 0:1f9b2707ec7d | 339 | if (handle != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 340 | { |
AzureIoTClient | 0:1f9b2707ec7d | 341 | /* Codes_SRS_SCHEMA_99_148: [Schema_GetSchemaByNamespace shall search all active schemas and return the schema with the |
AzureIoTClient | 0:1f9b2707ec7d | 342 | namespace given by the schemaNamespace argument.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 343 | result = *handle; |
AzureIoTClient | 0:1f9b2707ec7d | 344 | } |
AzureIoTClient | 0:1f9b2707ec7d | 345 | } |
AzureIoTClient | 0:1f9b2707ec7d | 346 | |
AzureIoTClient | 0:1f9b2707ec7d | 347 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 348 | } |
AzureIoTClient | 0:1f9b2707ec7d | 349 | |
AzureIoTClient | 0:1f9b2707ec7d | 350 | const char* Schema_GetSchemaNamespace(SCHEMA_HANDLE schemaHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 351 | { |
AzureIoTClient | 0:1f9b2707ec7d | 352 | const char* result; |
AzureIoTClient | 0:1f9b2707ec7d | 353 | |
AzureIoTClient | 0:1f9b2707ec7d | 354 | /* Codes_SRS_SCHEMA_99_130: [If the schemaHandle argument is NULL, Schema_GetSchemaNamespace shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 355 | if (schemaHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 356 | { |
AzureIoTClient | 0:1f9b2707ec7d | 357 | result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 358 | } |
AzureIoTClient | 0:1f9b2707ec7d | 359 | else |
AzureIoTClient | 0:1f9b2707ec7d | 360 | { |
AzureIoTClient | 0:1f9b2707ec7d | 361 | /* Codes_SRS_SCHEMA_99_129: [Schema_GetSchemaNamespace shall return the namespace for the schema identified by schemaHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 362 | result = ((SCHEMA*)schemaHandle)->Namespace; |
AzureIoTClient | 0:1f9b2707ec7d | 363 | } |
AzureIoTClient | 0:1f9b2707ec7d | 364 | |
AzureIoTClient | 0:1f9b2707ec7d | 365 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 366 | } |
AzureIoTClient | 0:1f9b2707ec7d | 367 | |
AzureIoTClient | 0:1f9b2707ec7d | 368 | void Schema_Destroy(SCHEMA_HANDLE schemaHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 369 | { |
AzureIoTClient | 0:1f9b2707ec7d | 370 | /* Codes_SRS_SCHEMA_99_006:[If the schemaHandle is NULL, Schema_Destroy shall do nothing.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 371 | if (schemaHandle != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 372 | { |
AzureIoTClient | 0:1f9b2707ec7d | 373 | SCHEMA* schema = (SCHEMA*)schemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 374 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 375 | |
AzureIoTClient | 0:1f9b2707ec7d | 376 | /* Codes_SRS_SCHEMA_99_005:[Schema_Destroy shall free all resources associated with a schema.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 377 | for (i = 0; i < schema->ModelTypeCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 378 | { |
AzureIoTClient | 0:1f9b2707ec7d | 379 | DestroyModel(schema->ModelTypes[i]); |
AzureIoTClient | 0:1f9b2707ec7d | 380 | } |
AzureIoTClient | 0:1f9b2707ec7d | 381 | |
AzureIoTClient | 0:1f9b2707ec7d | 382 | free(schema->ModelTypes); |
AzureIoTClient | 0:1f9b2707ec7d | 383 | |
AzureIoTClient | 0:1f9b2707ec7d | 384 | /* Codes_SRS_SCHEMA_99_005:[Schema_Destroy shall free all resources associated with a schema.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 385 | for (i = 0; i < schema->StructTypeCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 386 | { |
AzureIoTClient | 0:1f9b2707ec7d | 387 | DestroyStruct(schema->StructTypes[i]); |
AzureIoTClient | 0:1f9b2707ec7d | 388 | } |
AzureIoTClient | 0:1f9b2707ec7d | 389 | |
AzureIoTClient | 0:1f9b2707ec7d | 390 | free(schema->StructTypes); |
AzureIoTClient | 0:1f9b2707ec7d | 391 | free((void*)schema->Namespace); |
AzureIoTClient | 0:1f9b2707ec7d | 392 | free(schema); |
AzureIoTClient | 0:1f9b2707ec7d | 393 | |
AzureIoTClient | 0:1f9b2707ec7d | 394 | schema = (SCHEMA*)VECTOR_find_if(g_schemas, (PREDICATE_FUNCTION)SchemaHandlesMatch, &schemaHandle); |
AzureIoTClient | 0:1f9b2707ec7d | 395 | if (schema != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 396 | { |
AzureIoTClient | 0:1f9b2707ec7d | 397 | VECTOR_erase(g_schemas, schema, 1); |
AzureIoTClient | 0:1f9b2707ec7d | 398 | } |
AzureIoTClient | 0:1f9b2707ec7d | 399 | // If the g_schema is empty then destroy it |
AzureIoTClient | 0:1f9b2707ec7d | 400 | if (VECTOR_size(g_schemas) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 401 | { |
AzureIoTClient | 0:1f9b2707ec7d | 402 | VECTOR_destroy(g_schemas); |
AzureIoTClient | 0:1f9b2707ec7d | 403 | g_schemas = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 404 | } |
AzureIoTClient | 0:1f9b2707ec7d | 405 | } |
AzureIoTClient | 0:1f9b2707ec7d | 406 | } |
AzureIoTClient | 0:1f9b2707ec7d | 407 | |
AzureIoTClient | 0:1f9b2707ec7d | 408 | SCHEMA_RESULT Schema_DestroyIfUnused(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 409 | { |
AzureIoTClient | 0:1f9b2707ec7d | 410 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 411 | |
AzureIoTClient | 0:1f9b2707ec7d | 412 | /* Codes_SRS_SCHEMA_07_189: [If modelHandle variable is NULL Schema_DestroyIfUnused shall do nothing.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 413 | if (modelTypeHandle != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 414 | { |
AzureIoTClient | 0:1f9b2707ec7d | 415 | SCHEMA_HANDLE schemaHandle = Schema_GetSchemaForModelType(modelTypeHandle); |
AzureIoTClient | 0:1f9b2707ec7d | 416 | if (schemaHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 417 | { |
AzureIoTClient | 0:1f9b2707ec7d | 418 | result = SCHEMA_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 419 | } |
AzureIoTClient | 0:1f9b2707ec7d | 420 | else |
AzureIoTClient | 0:1f9b2707ec7d | 421 | { |
AzureIoTClient | 0:1f9b2707ec7d | 422 | SCHEMA* schema = (SCHEMA*)schemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 423 | size_t nIndex; |
AzureIoTClient | 0:1f9b2707ec7d | 424 | |
AzureIoTClient | 0:1f9b2707ec7d | 425 | /* 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 | 426 | for (nIndex = 0; nIndex < schema->ModelTypeCount; nIndex++) |
AzureIoTClient | 0:1f9b2707ec7d | 427 | { |
AzureIoTClient | 0:1f9b2707ec7d | 428 | MODEL_TYPE* modelType = (MODEL_TYPE*)schema->ModelTypes[nIndex]; |
AzureIoTClient | 0:1f9b2707ec7d | 429 | if (modelType->DeviceCount > 0) |
AzureIoTClient | 0:1f9b2707ec7d | 430 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 431 | } |
AzureIoTClient | 0:1f9b2707ec7d | 432 | /* Codes_SRS_SCHEMA_07_191: [If 1 or more DeviceCount variables are > 0 then Schema_DestroyIfUnused shall do nothing.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 433 | if (nIndex == schema->ModelTypeCount) |
AzureIoTClient | 0:1f9b2707ec7d | 434 | { |
AzureIoTClient | 0:1f9b2707ec7d | 435 | Schema_Destroy(schemaHandle); |
AzureIoTClient | 0:1f9b2707ec7d | 436 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 437 | } |
AzureIoTClient | 0:1f9b2707ec7d | 438 | else |
AzureIoTClient | 0:1f9b2707ec7d | 439 | { |
AzureIoTClient | 0:1f9b2707ec7d | 440 | result = SCHEMA_MODEL_IN_USE; |
AzureIoTClient | 0:1f9b2707ec7d | 441 | } |
AzureIoTClient | 0:1f9b2707ec7d | 442 | } |
AzureIoTClient | 0:1f9b2707ec7d | 443 | } |
AzureIoTClient | 0:1f9b2707ec7d | 444 | else |
AzureIoTClient | 0:1f9b2707ec7d | 445 | { |
AzureIoTClient | 0:1f9b2707ec7d | 446 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 447 | } |
AzureIoTClient | 0:1f9b2707ec7d | 448 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 449 | } |
AzureIoTClient | 0:1f9b2707ec7d | 450 | |
AzureIoTClient | 0:1f9b2707ec7d | 451 | SCHEMA_RESULT Schema_AddDeviceRef(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 452 | { |
AzureIoTClient | 0:1f9b2707ec7d | 453 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 454 | if (modelTypeHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 455 | { |
AzureIoTClient | 0:1f9b2707ec7d | 456 | /* Codes_SRS_SCHEMA_07_187: [Schema_AddDeviceRef shall return SCHEMA_INVALID_ARG if modelTypeHandle is NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 457 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 11:b1327861f5e0 | 458 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 459 | } |
AzureIoTClient | 0:1f9b2707ec7d | 460 | else |
AzureIoTClient | 0:1f9b2707ec7d | 461 | { |
AzureIoTClient | 0:1f9b2707ec7d | 462 | MODEL_TYPE* model = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 463 | /* Codes_SRS_SCHEMA_07_188: [If the modelTypeHandle is nonNULL, Schema_AddDeviceRef shall increment the MODEL_TYPE DeviceCount variable.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 464 | model->DeviceCount++; |
AzureIoTClient | 0:1f9b2707ec7d | 465 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 466 | } |
AzureIoTClient | 0:1f9b2707ec7d | 467 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 468 | } |
AzureIoTClient | 0:1f9b2707ec7d | 469 | |
AzureIoTClient | 0:1f9b2707ec7d | 470 | SCHEMA_RESULT Schema_ReleaseDeviceRef(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 471 | { |
AzureIoTClient | 0:1f9b2707ec7d | 472 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 473 | /* Codes_SRS_SCHEMA_07_184: [Schema_DeviceRelease shall do nothing if the supplied modelHandle is NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 474 | if (modelTypeHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 475 | { |
AzureIoTClient | 0:1f9b2707ec7d | 476 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 11:b1327861f5e0 | 477 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 478 | } |
AzureIoTClient | 0:1f9b2707ec7d | 479 | else |
AzureIoTClient | 0:1f9b2707ec7d | 480 | { |
AzureIoTClient | 0:1f9b2707ec7d | 481 | MODEL_TYPE* model = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 482 | if (model->DeviceCount > 0) |
AzureIoTClient | 0:1f9b2707ec7d | 483 | { |
AzureIoTClient | 0:1f9b2707ec7d | 484 | /* 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 | 485 | model->DeviceCount--; |
AzureIoTClient | 0:1f9b2707ec7d | 486 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 487 | } |
AzureIoTClient | 0:1f9b2707ec7d | 488 | else |
AzureIoTClient | 0:1f9b2707ec7d | 489 | { |
AzureIoTClient | 0:1f9b2707ec7d | 490 | result = SCHEMA_DEVICE_COUNT_ZERO; |
AzureIoTClient | 11:b1327861f5e0 | 491 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 492 | } |
AzureIoTClient | 0:1f9b2707ec7d | 493 | } |
AzureIoTClient | 0:1f9b2707ec7d | 494 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 495 | } |
AzureIoTClient | 0:1f9b2707ec7d | 496 | |
AzureIoTClient | 0:1f9b2707ec7d | 497 | /* Codes_SRS_SCHEMA_99_007:[Schema_CreateModelType shall create a new model type and return a handle to it.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 498 | SCHEMA_MODEL_TYPE_HANDLE Schema_CreateModelType(SCHEMA_HANDLE schemaHandle, const char* modelName) |
AzureIoTClient | 0:1f9b2707ec7d | 499 | { |
AzureIoTClient | 0:1f9b2707ec7d | 500 | SCHEMA_MODEL_TYPE_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 501 | |
AzureIoTClient | 0:1f9b2707ec7d | 502 | /* Codes_SRS_SCHEMA_99_010:[If any of the arguments is NULL, Schema_CreateModelType shall fail.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 503 | if ((schemaHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 504 | (modelName == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 505 | { |
AzureIoTClient | 0:1f9b2707ec7d | 506 | /* Codes_SRS_SCHEMA_99_009:[On failure, Schema_CreateModelType shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 507 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 508 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 509 | } |
AzureIoTClient | 0:1f9b2707ec7d | 510 | else |
AzureIoTClient | 0:1f9b2707ec7d | 511 | { |
AzureIoTClient | 0:1f9b2707ec7d | 512 | SCHEMA* schema = (SCHEMA*)schemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 513 | |
AzureIoTClient | 0:1f9b2707ec7d | 514 | /* Codes_SRS_SCHEMA_99_100: [Schema_CreateModelType shall return SCHEMA_DUPLICATE_ELEMENT if modelName already exists.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 515 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 516 | for (i = 0; i < schema->ModelTypeCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 517 | { |
AzureIoTClient | 0:1f9b2707ec7d | 518 | MODEL_TYPE* model = (MODEL_TYPE*)(schema->ModelTypes[i]); |
AzureIoTClient | 0:1f9b2707ec7d | 519 | if (strcmp(model->Name, modelName) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 520 | { |
AzureIoTClient | 0:1f9b2707ec7d | 521 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 522 | } |
AzureIoTClient | 0:1f9b2707ec7d | 523 | } |
AzureIoTClient | 0:1f9b2707ec7d | 524 | |
AzureIoTClient | 0:1f9b2707ec7d | 525 | if (i < schema->ModelTypeCount) |
AzureIoTClient | 0:1f9b2707ec7d | 526 | { |
AzureIoTClient | 0:1f9b2707ec7d | 527 | /* Codes_SRS_SCHEMA_99_009:[On failure, Schema_CreateModelType shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 528 | result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 529 | LogError("%s Model Name already exists", modelName); |
AzureIoTClient | 0:1f9b2707ec7d | 530 | } |
AzureIoTClient | 0:1f9b2707ec7d | 531 | |
AzureIoTClient | 0:1f9b2707ec7d | 532 | else |
AzureIoTClient | 0:1f9b2707ec7d | 533 | { |
AzureIoTClient | 0:1f9b2707ec7d | 534 | SCHEMA_MODEL_TYPE_HANDLE* newModelTypes = (SCHEMA_MODEL_TYPE_HANDLE*)realloc(schema->ModelTypes, sizeof(SCHEMA_MODEL_TYPE_HANDLE) * (schema->ModelTypeCount + 1)); |
AzureIoTClient | 0:1f9b2707ec7d | 535 | if (newModelTypes == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 536 | { |
AzureIoTClient | 0:1f9b2707ec7d | 537 | /* Codes_SRS_SCHEMA_99_009:[On failure, Schema_CreateModelType shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 538 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 539 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 540 | } |
AzureIoTClient | 0:1f9b2707ec7d | 541 | else |
AzureIoTClient | 0:1f9b2707ec7d | 542 | { |
AzureIoTClient | 0:1f9b2707ec7d | 543 | MODEL_TYPE* modelType; |
AzureIoTClient | 0:1f9b2707ec7d | 544 | schema->ModelTypes = newModelTypes; |
AzureIoTClient | 0:1f9b2707ec7d | 545 | |
AzureIoTClient | 0:1f9b2707ec7d | 546 | if ((modelType = (MODEL_TYPE*)malloc(sizeof(MODEL_TYPE))) == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 547 | { |
AzureIoTClient | 0:1f9b2707ec7d | 548 | |
AzureIoTClient | 0:1f9b2707ec7d | 549 | /* Codes_SRS_SCHEMA_99_009:[On failure, Schema_CreateModelType shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 550 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 551 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 552 | } |
AzureIoTClient | 0:1f9b2707ec7d | 553 | else if (mallocAndStrcpy_s((char**)&modelType->Name, modelName) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 554 | { |
AzureIoTClient | 0:1f9b2707ec7d | 555 | /* Codes_SRS_SCHEMA_99_009:[On failure, Schema_CreateModelType shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 556 | result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 557 | free(modelType); |
AzureIoTClient | 11:b1327861f5e0 | 558 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 559 | } |
AzureIoTClient | 0:1f9b2707ec7d | 560 | else |
AzureIoTClient | 0:1f9b2707ec7d | 561 | { |
AzureIoTClient | 0:1f9b2707ec7d | 562 | modelType->PropertyCount = 0; |
AzureIoTClient | 0:1f9b2707ec7d | 563 | modelType->Properties = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 564 | modelType->ActionCount = 0; |
AzureIoTClient | 0:1f9b2707ec7d | 565 | modelType->Actions = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 566 | modelType->SchemaHandle = schemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 567 | modelType->DeviceCount = 0; |
AzureIoTClient | 0:1f9b2707ec7d | 568 | modelType->models = VECTOR_create(sizeof(MODEL_IN_MODEL) ); |
AzureIoTClient | 0:1f9b2707ec7d | 569 | schema->ModelTypes[schema->ModelTypeCount] = modelType; |
AzureIoTClient | 0:1f9b2707ec7d | 570 | schema->ModelTypeCount++; |
AzureIoTClient | 0:1f9b2707ec7d | 571 | |
AzureIoTClient | 0:1f9b2707ec7d | 572 | /* Codes_SRS_SCHEMA_99_008:[On success, a non-NULL handle shall be returned.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 573 | result = (SCHEMA_MODEL_TYPE_HANDLE)modelType; |
AzureIoTClient | 0:1f9b2707ec7d | 574 | } |
AzureIoTClient | 0:1f9b2707ec7d | 575 | |
AzureIoTClient | 0:1f9b2707ec7d | 576 | /* If possible, reduce the memory of over allocation */ |
AzureIoTClient | 0:1f9b2707ec7d | 577 | if (result == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 578 | { |
AzureIoTClient | 0:1f9b2707ec7d | 579 | SCHEMA_MODEL_TYPE_HANDLE* oldModelTypes = (SCHEMA_MODEL_TYPE_HANDLE*)realloc(schema->ModelTypes, sizeof(SCHEMA_MODEL_TYPE_HANDLE) * schema->ModelTypeCount); |
AzureIoTClient | 0:1f9b2707ec7d | 580 | if (oldModelTypes == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 581 | { |
AzureIoTClient | 0:1f9b2707ec7d | 582 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 583 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 584 | } |
AzureIoTClient | 0:1f9b2707ec7d | 585 | else |
AzureIoTClient | 0:1f9b2707ec7d | 586 | { |
AzureIoTClient | 0:1f9b2707ec7d | 587 | schema->ModelTypes = oldModelTypes; |
AzureIoTClient | 0:1f9b2707ec7d | 588 | } |
AzureIoTClient | 0:1f9b2707ec7d | 589 | } |
AzureIoTClient | 0:1f9b2707ec7d | 590 | } |
AzureIoTClient | 0:1f9b2707ec7d | 591 | } |
AzureIoTClient | 0:1f9b2707ec7d | 592 | } |
AzureIoTClient | 0:1f9b2707ec7d | 593 | |
AzureIoTClient | 0:1f9b2707ec7d | 594 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 595 | } |
AzureIoTClient | 0:1f9b2707ec7d | 596 | |
AzureIoTClient | 0:1f9b2707ec7d | 597 | SCHEMA_HANDLE Schema_GetSchemaForModelType(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 598 | { |
AzureIoTClient | 0:1f9b2707ec7d | 599 | SCHEMA_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 600 | |
AzureIoTClient | 0:1f9b2707ec7d | 601 | if (modelTypeHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 602 | { |
AzureIoTClient | 0:1f9b2707ec7d | 603 | /* Codes_SRS_SCHEMA_99_132: [If the modelTypeHandle argument is NULL, Schema_GetSchemaForModelType shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 604 | result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 605 | } |
AzureIoTClient | 0:1f9b2707ec7d | 606 | else |
AzureIoTClient | 0:1f9b2707ec7d | 607 | { |
AzureIoTClient | 0:1f9b2707ec7d | 608 | /* Codes_SRS_SCHEMA_99_131: [Schema_GetSchemaForModelType returns the schema handle for a given model type.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 609 | result = ((MODEL_TYPE*)modelTypeHandle)->SchemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 610 | } |
AzureIoTClient | 0:1f9b2707ec7d | 611 | |
AzureIoTClient | 0:1f9b2707ec7d | 612 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 613 | } |
AzureIoTClient | 0:1f9b2707ec7d | 614 | |
AzureIoTClient | 0:1f9b2707ec7d | 615 | /* Codes_SRS_SCHEMA_99_011:[Schema_AddModelProperty shall add one property to the model type identified by modelTypeHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 616 | SCHEMA_RESULT Schema_AddModelProperty(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* propertyName, const char* propertyType) |
AzureIoTClient | 0:1f9b2707ec7d | 617 | { |
AzureIoTClient | 0:1f9b2707ec7d | 618 | return AddModelProperty((MODEL_TYPE*)modelTypeHandle, propertyName, propertyType); |
AzureIoTClient | 0:1f9b2707ec7d | 619 | } |
AzureIoTClient | 0:1f9b2707ec7d | 620 | |
AzureIoTClient | 0:1f9b2707ec7d | 621 | SCHEMA_ACTION_HANDLE Schema_CreateModelAction(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* actionName) |
AzureIoTClient | 0:1f9b2707ec7d | 622 | { |
AzureIoTClient | 0:1f9b2707ec7d | 623 | SCHEMA_ACTION_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 624 | |
AzureIoTClient | 0:1f9b2707ec7d | 625 | /* Codes_SRS_SCHEMA_99_104: [If any of the modelTypeHandle or actionName arguments is NULL, Schema_CreateModelAction shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 626 | if ((modelTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 627 | (actionName == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 628 | { |
AzureIoTClient | 0:1f9b2707ec7d | 629 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 630 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 631 | } |
AzureIoTClient | 0:1f9b2707ec7d | 632 | else |
AzureIoTClient | 0:1f9b2707ec7d | 633 | { |
AzureIoTClient | 0:1f9b2707ec7d | 634 | MODEL_TYPE* modelType = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 635 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 636 | |
AzureIoTClient | 0:1f9b2707ec7d | 637 | /* 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 | 638 | for (i = 0; i < modelType->ActionCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 639 | { |
AzureIoTClient | 0:1f9b2707ec7d | 640 | ACTION* action = (ACTION*)modelType->Actions[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 641 | if (strcmp(action->ActionName, actionName) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 642 | { |
AzureIoTClient | 0:1f9b2707ec7d | 643 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 644 | } |
AzureIoTClient | 0:1f9b2707ec7d | 645 | } |
AzureIoTClient | 0:1f9b2707ec7d | 646 | |
AzureIoTClient | 0:1f9b2707ec7d | 647 | if (i < modelType->ActionCount) |
AzureIoTClient | 0:1f9b2707ec7d | 648 | { |
AzureIoTClient | 0:1f9b2707ec7d | 649 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 650 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_DUPLICATE_ELEMENT)); |
AzureIoTClient | 0:1f9b2707ec7d | 651 | } |
AzureIoTClient | 0:1f9b2707ec7d | 652 | else |
AzureIoTClient | 0:1f9b2707ec7d | 653 | { |
AzureIoTClient | 0:1f9b2707ec7d | 654 | /* Codes_SRS_SCHEMA_99_102: [Schema_CreateModelAction shall add one action to the model type identified by modelTypeHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 655 | SCHEMA_ACTION_HANDLE* newActions = (SCHEMA_ACTION_HANDLE*)realloc(modelType->Actions, sizeof(SCHEMA_ACTION_HANDLE) * (modelType->ActionCount + 1)); |
AzureIoTClient | 0:1f9b2707ec7d | 656 | if (newActions == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 657 | { |
AzureIoTClient | 0:1f9b2707ec7d | 658 | /* Codes_SRS_SCHEMA_99_106: [On any other error, Schema_CreateModelAction shall return NULL.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 659 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 660 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 661 | } |
AzureIoTClient | 0:1f9b2707ec7d | 662 | else |
AzureIoTClient | 0:1f9b2707ec7d | 663 | { |
AzureIoTClient | 0:1f9b2707ec7d | 664 | ACTION* newAction; |
AzureIoTClient | 0:1f9b2707ec7d | 665 | modelType->Actions = newActions; |
AzureIoTClient | 0:1f9b2707ec7d | 666 | |
AzureIoTClient | 0:1f9b2707ec7d | 667 | /* Codes_SRS_SCHEMA_99_103: [On success, Schema_CreateModelAction shall return a none-NULL SCHEMA_ACTION_HANDLE to the newly created action.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 668 | if ((newAction = (ACTION*)malloc(sizeof(ACTION))) == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 669 | { |
AzureIoTClient | 0:1f9b2707ec7d | 670 | /* Codes_SRS_SCHEMA_99_106: [On any other error, Schema_CreateModelAction shall return NULL.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 671 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 672 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 673 | } |
AzureIoTClient | 0:1f9b2707ec7d | 674 | else |
AzureIoTClient | 0:1f9b2707ec7d | 675 | { |
AzureIoTClient | 0:1f9b2707ec7d | 676 | if (mallocAndStrcpy_s((char**)&newAction->ActionName, actionName) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 677 | { |
AzureIoTClient | 0:1f9b2707ec7d | 678 | /* Codes_SRS_SCHEMA_99_106: [On any other error, Schema_CreateModelAction shall return NULL.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 679 | free(newAction); |
AzureIoTClient | 0:1f9b2707ec7d | 680 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 681 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 682 | } |
AzureIoTClient | 0:1f9b2707ec7d | 683 | else |
AzureIoTClient | 0:1f9b2707ec7d | 684 | { |
AzureIoTClient | 0:1f9b2707ec7d | 685 | newAction->ArgumentCount = 0; |
AzureIoTClient | 0:1f9b2707ec7d | 686 | newAction->ArgumentHandles = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 687 | |
AzureIoTClient | 0:1f9b2707ec7d | 688 | modelType->Actions[modelType->ActionCount] = newAction; |
AzureIoTClient | 0:1f9b2707ec7d | 689 | modelType->ActionCount++; |
AzureIoTClient | 0:1f9b2707ec7d | 690 | result = (SCHEMA_ACTION_HANDLE)(newAction); |
AzureIoTClient | 0:1f9b2707ec7d | 691 | } |
AzureIoTClient | 0:1f9b2707ec7d | 692 | |
AzureIoTClient | 0:1f9b2707ec7d | 693 | /* If possible, reduce the memory of over allocation */ |
AzureIoTClient | 0:1f9b2707ec7d | 694 | if (result == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 695 | { |
AzureIoTClient | 0:1f9b2707ec7d | 696 | SCHEMA_ACTION_HANDLE* oldActions = (SCHEMA_ACTION_HANDLE*)realloc(modelType->Actions, sizeof(SCHEMA_ACTION_HANDLE) * modelType->ActionCount); |
AzureIoTClient | 0:1f9b2707ec7d | 697 | if (oldActions == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 698 | { |
AzureIoTClient | 11:b1327861f5e0 | 699 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 700 | } |
AzureIoTClient | 0:1f9b2707ec7d | 701 | else |
AzureIoTClient | 0:1f9b2707ec7d | 702 | { |
AzureIoTClient | 0:1f9b2707ec7d | 703 | modelType->Actions = oldActions; |
AzureIoTClient | 0:1f9b2707ec7d | 704 | } |
AzureIoTClient | 0:1f9b2707ec7d | 705 | } |
AzureIoTClient | 0:1f9b2707ec7d | 706 | } |
AzureIoTClient | 0:1f9b2707ec7d | 707 | } |
AzureIoTClient | 0:1f9b2707ec7d | 708 | } |
AzureIoTClient | 0:1f9b2707ec7d | 709 | } |
AzureIoTClient | 0:1f9b2707ec7d | 710 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 711 | } |
AzureIoTClient | 0:1f9b2707ec7d | 712 | |
AzureIoTClient | 0:1f9b2707ec7d | 713 | SCHEMA_RESULT Schema_AddModelActionArgument(SCHEMA_ACTION_HANDLE actionHandle, const char* argumentName, const char* argumentType) |
AzureIoTClient | 0:1f9b2707ec7d | 714 | { |
AzureIoTClient | 0:1f9b2707ec7d | 715 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 716 | |
AzureIoTClient | 0:1f9b2707ec7d | 717 | /* Codes_SRS_SCHEMA_99_109: [If any of the arguments is NULL, Schema_AddModelActionArgument shall return SCHEMA_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 718 | if ((actionHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 719 | (argumentName == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 720 | (argumentType == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 721 | { |
AzureIoTClient | 0:1f9b2707ec7d | 722 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 11:b1327861f5e0 | 723 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 724 | } |
AzureIoTClient | 0:1f9b2707ec7d | 725 | else |
AzureIoTClient | 0:1f9b2707ec7d | 726 | { |
AzureIoTClient | 0:1f9b2707ec7d | 727 | ACTION* action = (ACTION*)actionHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 728 | |
AzureIoTClient | 0:1f9b2707ec7d | 729 | /* 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 | 730 | /* Codes_SRS_SCHEMA_99_111: [Schema_AddModelActionArgument shall accept arguments with different names of the same type.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 731 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 732 | for (i = 0; i < action->ArgumentCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 733 | { |
AzureIoTClient | 0:1f9b2707ec7d | 734 | SCHEMA_ACTION_ARGUMENT* actionArgument = (SCHEMA_ACTION_ARGUMENT*)action->ArgumentHandles[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 735 | if (strcmp((actionArgument->Name), argumentName) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 736 | { |
AzureIoTClient | 0:1f9b2707ec7d | 737 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 738 | } |
AzureIoTClient | 0:1f9b2707ec7d | 739 | } |
AzureIoTClient | 0:1f9b2707ec7d | 740 | |
AzureIoTClient | 0:1f9b2707ec7d | 741 | if (i < action->ArgumentCount) |
AzureIoTClient | 0:1f9b2707ec7d | 742 | { |
AzureIoTClient | 0:1f9b2707ec7d | 743 | result = SCHEMA_DUPLICATE_ELEMENT; |
AzureIoTClient | 11:b1327861f5e0 | 744 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 745 | } |
AzureIoTClient | 0:1f9b2707ec7d | 746 | else |
AzureIoTClient | 0:1f9b2707ec7d | 747 | { |
AzureIoTClient | 0:1f9b2707ec7d | 748 | /* Codes_SRS_SCHEMA_99_107: [Schema_AddModelActionArgument shall add one argument name & type to an action identified by actionHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 749 | SCHEMA_ACTION_ARGUMENT_HANDLE* newArguments = (SCHEMA_ACTION_ARGUMENT_HANDLE*)realloc(action->ArgumentHandles, sizeof(SCHEMA_ACTION_ARGUMENT_HANDLE) * (action->ArgumentCount + 1)); |
AzureIoTClient | 0:1f9b2707ec7d | 750 | if (newArguments == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 751 | { |
AzureIoTClient | 0:1f9b2707ec7d | 752 | /* Codes_SRS_SCHEMA_99_112: [On any other error, Schema_ AddModelActionArgumet shall return SCHEMA_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 753 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 754 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 755 | } |
AzureIoTClient | 0:1f9b2707ec7d | 756 | else |
AzureIoTClient | 0:1f9b2707ec7d | 757 | { |
AzureIoTClient | 0:1f9b2707ec7d | 758 | SCHEMA_ACTION_ARGUMENT* newActionArgument; |
AzureIoTClient | 0:1f9b2707ec7d | 759 | if ((newActionArgument = (SCHEMA_ACTION_ARGUMENT*)malloc(sizeof(SCHEMA_ACTION_ARGUMENT))) == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 760 | { |
AzureIoTClient | 0:1f9b2707ec7d | 761 | /* Codes_SRS_SCHEMA_99_112: [On any other error, Schema_ AddModelActionArgumet shall return SCHEMA_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 762 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 763 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 764 | } |
AzureIoTClient | 0:1f9b2707ec7d | 765 | else |
AzureIoTClient | 0:1f9b2707ec7d | 766 | { |
AzureIoTClient | 0:1f9b2707ec7d | 767 | if (mallocAndStrcpy_s((char**)&newActionArgument->Name, argumentName) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 768 | { |
AzureIoTClient | 0:1f9b2707ec7d | 769 | /* Codes_SRS_SCHEMA_99_112: [On any other error, Schema_ AddModelActionArgumet shall return SCHEMA_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 770 | free(newActionArgument); |
AzureIoTClient | 0:1f9b2707ec7d | 771 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 772 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 773 | } |
AzureIoTClient | 0:1f9b2707ec7d | 774 | else if (mallocAndStrcpy_s((char**)&newActionArgument->Type, argumentType) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 775 | { |
AzureIoTClient | 0:1f9b2707ec7d | 776 | /* Codes_SRS_SCHEMA_99_112: [On any other error, Schema_ AddModelActionArgumet shall return SCHEMA_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 777 | free((void*)newActionArgument->Name); |
AzureIoTClient | 0:1f9b2707ec7d | 778 | free(newActionArgument); |
AzureIoTClient | 0:1f9b2707ec7d | 779 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 780 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 781 | } |
AzureIoTClient | 0:1f9b2707ec7d | 782 | else |
AzureIoTClient | 0:1f9b2707ec7d | 783 | { |
AzureIoTClient | 0:1f9b2707ec7d | 784 | action->ArgumentHandles = newArguments; |
AzureIoTClient | 0:1f9b2707ec7d | 785 | /* 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 | 786 | action->ArgumentHandles[action->ArgumentCount] = newActionArgument; |
AzureIoTClient | 0:1f9b2707ec7d | 787 | action->ArgumentCount++; |
AzureIoTClient | 0:1f9b2707ec7d | 788 | |
AzureIoTClient | 0:1f9b2707ec7d | 789 | /* Codes_SRS_SCHEMA_99_108: [On success, Schema_AddModelActionArgunent shall return SCHEMA_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 790 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 791 | } |
AzureIoTClient | 0:1f9b2707ec7d | 792 | } |
AzureIoTClient | 0:1f9b2707ec7d | 793 | |
AzureIoTClient | 0:1f9b2707ec7d | 794 | /* If possible, reduce the memory of over allocation */ |
AzureIoTClient | 0:1f9b2707ec7d | 795 | if (result == SCHEMA_ERROR) |
AzureIoTClient | 0:1f9b2707ec7d | 796 | { |
AzureIoTClient | 0:1f9b2707ec7d | 797 | SCHEMA_ACTION_ARGUMENT_HANDLE* oldArguments = (SCHEMA_ACTION_ARGUMENT_HANDLE*)realloc(action->ArgumentHandles, sizeof(SCHEMA_ACTION_ARGUMENT_HANDLE) * action->ArgumentCount); |
AzureIoTClient | 0:1f9b2707ec7d | 798 | if (oldArguments == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 799 | { |
AzureIoTClient | 11:b1327861f5e0 | 800 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 801 | } |
AzureIoTClient | 0:1f9b2707ec7d | 802 | else |
AzureIoTClient | 0:1f9b2707ec7d | 803 | { |
AzureIoTClient | 0:1f9b2707ec7d | 804 | action->ArgumentHandles = oldArguments; |
AzureIoTClient | 0:1f9b2707ec7d | 805 | } |
AzureIoTClient | 0:1f9b2707ec7d | 806 | } |
AzureIoTClient | 0:1f9b2707ec7d | 807 | } |
AzureIoTClient | 0:1f9b2707ec7d | 808 | } |
AzureIoTClient | 0:1f9b2707ec7d | 809 | } |
AzureIoTClient | 0:1f9b2707ec7d | 810 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 811 | } |
AzureIoTClient | 0:1f9b2707ec7d | 812 | |
AzureIoTClient | 0:1f9b2707ec7d | 813 | SCHEMA_PROPERTY_HANDLE Schema_GetModelPropertyByName(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* propertyName) |
AzureIoTClient | 0:1f9b2707ec7d | 814 | { |
AzureIoTClient | 0:1f9b2707ec7d | 815 | SCHEMA_PROPERTY_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 816 | |
AzureIoTClient | 0:1f9b2707ec7d | 817 | /* 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 | 818 | if ((modelTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 819 | (propertyName == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 820 | { |
AzureIoTClient | 0:1f9b2707ec7d | 821 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 822 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 823 | } |
AzureIoTClient | 0:1f9b2707ec7d | 824 | else |
AzureIoTClient | 0:1f9b2707ec7d | 825 | { |
AzureIoTClient | 0:1f9b2707ec7d | 826 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 827 | MODEL_TYPE* modelType = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 828 | |
AzureIoTClient | 0:1f9b2707ec7d | 829 | /* 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 | 830 | for (i = 0; i < modelType->PropertyCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 831 | { |
AzureIoTClient | 0:1f9b2707ec7d | 832 | PROPERTY* modelProperty = (PROPERTY*)modelType->Properties[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 833 | if (strcmp(modelProperty->PropertyName, propertyName) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 834 | { |
AzureIoTClient | 0:1f9b2707ec7d | 835 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 836 | } |
AzureIoTClient | 0:1f9b2707ec7d | 837 | } |
AzureIoTClient | 0:1f9b2707ec7d | 838 | |
AzureIoTClient | 0:1f9b2707ec7d | 839 | if (i == modelType->PropertyCount) |
AzureIoTClient | 0:1f9b2707ec7d | 840 | { |
AzureIoTClient | 0:1f9b2707ec7d | 841 | /* 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 | 842 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 843 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ELEMENT_NOT_FOUND)); |
AzureIoTClient | 0:1f9b2707ec7d | 844 | } |
AzureIoTClient | 0:1f9b2707ec7d | 845 | else |
AzureIoTClient | 0:1f9b2707ec7d | 846 | { |
AzureIoTClient | 0:1f9b2707ec7d | 847 | result = (SCHEMA_PROPERTY_HANDLE)(modelType->Properties[i]); |
AzureIoTClient | 0:1f9b2707ec7d | 848 | } |
AzureIoTClient | 0:1f9b2707ec7d | 849 | } |
AzureIoTClient | 0:1f9b2707ec7d | 850 | |
AzureIoTClient | 0:1f9b2707ec7d | 851 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 852 | } |
AzureIoTClient | 0:1f9b2707ec7d | 853 | |
AzureIoTClient | 0:1f9b2707ec7d | 854 | SCHEMA_RESULT Schema_GetModelPropertyCount(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t* propertyCount) |
AzureIoTClient | 0:1f9b2707ec7d | 855 | { |
AzureIoTClient | 0:1f9b2707ec7d | 856 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 857 | |
AzureIoTClient | 0:1f9b2707ec7d | 858 | /* Codes_SRS_SCHEMA_99_092: [Schema_GetModelPropertyCount shall return SCHEMA_INVALID_ARG if any of the arguments is NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 859 | if ((modelTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 860 | (propertyCount == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 861 | { |
AzureIoTClient | 0:1f9b2707ec7d | 862 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 863 | } |
AzureIoTClient | 0:1f9b2707ec7d | 864 | else |
AzureIoTClient | 0:1f9b2707ec7d | 865 | { |
AzureIoTClient | 0:1f9b2707ec7d | 866 | /* Codes_SRS_SCHEMA_99_089: [Schema_GetModelPropertyCount shall provide the number of properties defined in the model type identified by modelTypeHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 867 | MODEL_TYPE* modelType = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 868 | |
AzureIoTClient | 0:1f9b2707ec7d | 869 | /* Codes_SRS_SCHEMA_99_090: [The count shall be provided via the out argument propertyCount.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 870 | *propertyCount = modelType->PropertyCount; |
AzureIoTClient | 0:1f9b2707ec7d | 871 | |
AzureIoTClient | 0:1f9b2707ec7d | 872 | /* Codes_SRS_SCHEMA_99_091: [On success, Schema_GetModelPropertyCount shall return SCHEMA_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 873 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 874 | } |
AzureIoTClient | 0:1f9b2707ec7d | 875 | |
AzureIoTClient | 0:1f9b2707ec7d | 876 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 877 | } |
AzureIoTClient | 0:1f9b2707ec7d | 878 | |
AzureIoTClient | 0:1f9b2707ec7d | 879 | SCHEMA_PROPERTY_HANDLE Schema_GetModelPropertyByIndex(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t index) |
AzureIoTClient | 0:1f9b2707ec7d | 880 | { |
AzureIoTClient | 0:1f9b2707ec7d | 881 | SCHEMA_PROPERTY_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 882 | MODEL_TYPE* modelType = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 883 | |
AzureIoTClient | 0:1f9b2707ec7d | 884 | /* 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 | 885 | if ((modelTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 886 | (index >= modelType->PropertyCount)) |
AzureIoTClient | 0:1f9b2707ec7d | 887 | { |
AzureIoTClient | 0:1f9b2707ec7d | 888 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 889 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 890 | } |
AzureIoTClient | 0:1f9b2707ec7d | 891 | else |
AzureIoTClient | 0:1f9b2707ec7d | 892 | { |
AzureIoTClient | 0:1f9b2707ec7d | 893 | /* 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 | 894 | /* 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 | 895 | result = modelType->Properties[index]; |
AzureIoTClient | 0:1f9b2707ec7d | 896 | } |
AzureIoTClient | 0:1f9b2707ec7d | 897 | |
AzureIoTClient | 0:1f9b2707ec7d | 898 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 899 | } |
AzureIoTClient | 0:1f9b2707ec7d | 900 | |
AzureIoTClient | 0:1f9b2707ec7d | 901 | SCHEMA_ACTION_HANDLE Schema_GetModelActionByName(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* actionName) |
AzureIoTClient | 0:1f9b2707ec7d | 902 | { |
AzureIoTClient | 0:1f9b2707ec7d | 903 | SCHEMA_ACTION_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 904 | |
AzureIoTClient | 0:1f9b2707ec7d | 905 | /* 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 | 906 | if ((modelTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 907 | (actionName == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 908 | { |
AzureIoTClient | 0:1f9b2707ec7d | 909 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 910 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 911 | } |
AzureIoTClient | 0:1f9b2707ec7d | 912 | else |
AzureIoTClient | 0:1f9b2707ec7d | 913 | { |
AzureIoTClient | 0:1f9b2707ec7d | 914 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 915 | MODEL_TYPE* modelType = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 916 | |
AzureIoTClient | 0:1f9b2707ec7d | 917 | /* 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 | 918 | for (i = 0; i < modelType->ActionCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 919 | { |
AzureIoTClient | 0:1f9b2707ec7d | 920 | ACTION* modelAction = (ACTION*)modelType->Actions[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 921 | if (strcmp(modelAction->ActionName, actionName) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 922 | { |
AzureIoTClient | 0:1f9b2707ec7d | 923 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 924 | } |
AzureIoTClient | 0:1f9b2707ec7d | 925 | } |
AzureIoTClient | 0:1f9b2707ec7d | 926 | |
AzureIoTClient | 0:1f9b2707ec7d | 927 | if (i == modelType->ActionCount) |
AzureIoTClient | 0:1f9b2707ec7d | 928 | { |
AzureIoTClient | 0:1f9b2707ec7d | 929 | /* 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 | 930 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 931 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ELEMENT_NOT_FOUND)); |
AzureIoTClient | 0:1f9b2707ec7d | 932 | } |
AzureIoTClient | 0:1f9b2707ec7d | 933 | else |
AzureIoTClient | 0:1f9b2707ec7d | 934 | { |
AzureIoTClient | 0:1f9b2707ec7d | 935 | result = modelType->Actions[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 936 | } |
AzureIoTClient | 0:1f9b2707ec7d | 937 | } |
AzureIoTClient | 0:1f9b2707ec7d | 938 | |
AzureIoTClient | 0:1f9b2707ec7d | 939 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 940 | } |
AzureIoTClient | 0:1f9b2707ec7d | 941 | |
AzureIoTClient | 0:1f9b2707ec7d | 942 | SCHEMA_RESULT Schema_GetModelActionCount(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t* actionCount) |
AzureIoTClient | 0:1f9b2707ec7d | 943 | { |
AzureIoTClient | 0:1f9b2707ec7d | 944 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 945 | |
AzureIoTClient | 0:1f9b2707ec7d | 946 | /* 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 | 947 | if ((modelTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 948 | (actionCount == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 949 | { |
AzureIoTClient | 0:1f9b2707ec7d | 950 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 11:b1327861f5e0 | 951 | LogError("(result=%s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 952 | } |
AzureIoTClient | 0:1f9b2707ec7d | 953 | else |
AzureIoTClient | 0:1f9b2707ec7d | 954 | { |
AzureIoTClient | 0:1f9b2707ec7d | 955 | /* Codes_SRS_SCHEMA_99_042:[Schema_GetModelActionCount shall provide the total number of actions defined in a model type identified by the modelTypeHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 956 | MODEL_TYPE* modelType = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 957 | |
AzureIoTClient | 0:1f9b2707ec7d | 958 | /* Codes_SRS_SCHEMA_99_043:[The count shall be provided via the out argument actionCount.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 959 | *actionCount = modelType->ActionCount; |
AzureIoTClient | 0:1f9b2707ec7d | 960 | |
AzureIoTClient | 0:1f9b2707ec7d | 961 | /* Codes_SRS_SCHEMA_99_044:[On success, Schema_GetModelActionCount shall return SCHEMA_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 962 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 963 | } |
AzureIoTClient | 0:1f9b2707ec7d | 964 | |
AzureIoTClient | 0:1f9b2707ec7d | 965 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 966 | } |
AzureIoTClient | 0:1f9b2707ec7d | 967 | |
AzureIoTClient | 0:1f9b2707ec7d | 968 | SCHEMA_ACTION_HANDLE Schema_GetModelActionByIndex(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t index) |
AzureIoTClient | 0:1f9b2707ec7d | 969 | { |
AzureIoTClient | 0:1f9b2707ec7d | 970 | SCHEMA_ACTION_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 971 | MODEL_TYPE* modelType = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 972 | |
AzureIoTClient | 0:1f9b2707ec7d | 973 | /* 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 | 974 | if ((modelType == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 975 | (index >= modelType->ActionCount)) |
AzureIoTClient | 0:1f9b2707ec7d | 976 | { |
AzureIoTClient | 0:1f9b2707ec7d | 977 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 978 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 979 | } |
AzureIoTClient | 0:1f9b2707ec7d | 980 | else |
AzureIoTClient | 0:1f9b2707ec7d | 981 | { |
AzureIoTClient | 0:1f9b2707ec7d | 982 | /* 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 | 983 | /* 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 | 984 | result = modelType->Actions[index]; |
AzureIoTClient | 0:1f9b2707ec7d | 985 | } |
AzureIoTClient | 0:1f9b2707ec7d | 986 | |
AzureIoTClient | 0:1f9b2707ec7d | 987 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 988 | } |
AzureIoTClient | 0:1f9b2707ec7d | 989 | |
AzureIoTClient | 0:1f9b2707ec7d | 990 | const char* Schema_GetModelActionName(SCHEMA_ACTION_HANDLE actionHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 991 | { |
AzureIoTClient | 0:1f9b2707ec7d | 992 | const char* result; |
AzureIoTClient | 0:1f9b2707ec7d | 993 | |
AzureIoTClient | 0:1f9b2707ec7d | 994 | /* Codes_SRS_SCHEMA_99_050:[If the actionHandle is NULL, Schema_GetModelActionName shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 995 | if (actionHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 996 | { |
AzureIoTClient | 0:1f9b2707ec7d | 997 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 998 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 999 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1000 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1001 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1002 | ACTION* action = (ACTION*)actionHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1003 | /* Codes_SRS_SCHEMA_99_049:[Schema_GetModelActionName shall return the action name for a given action handle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1004 | result = action->ActionName; |
AzureIoTClient | 0:1f9b2707ec7d | 1005 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1006 | |
AzureIoTClient | 0:1f9b2707ec7d | 1007 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1008 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1009 | |
AzureIoTClient | 0:1f9b2707ec7d | 1010 | SCHEMA_RESULT Schema_GetModelActionArgumentCount(SCHEMA_ACTION_HANDLE actionHandle, size_t* argumentCount) |
AzureIoTClient | 0:1f9b2707ec7d | 1011 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1012 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 1013 | |
AzureIoTClient | 0:1f9b2707ec7d | 1014 | /* Codes_SRS_SCHEMA_99_054:[If any argument is NULL, Schema_GetModelActionArgumentCount shall return SCHEMA_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1015 | if ((actionHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1016 | (argumentCount == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 1017 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1018 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 11:b1327861f5e0 | 1019 | LogError("(result=%s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1020 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1021 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1022 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1023 | ACTION* modelAction = (ACTION*)actionHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1024 | |
AzureIoTClient | 0:1f9b2707ec7d | 1025 | /* Codes_SRS_SCHEMA_99_051:[Schema_GetModelActionArgumentCount shall provide the number of arguments for a specific schema action identified by actionHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1026 | /* Codes_SRS_SCHEMA_99_052:[The argument count shall be provided via the out argument argumentCount.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1027 | *argumentCount = modelAction->ArgumentCount; |
AzureIoTClient | 0:1f9b2707ec7d | 1028 | |
AzureIoTClient | 0:1f9b2707ec7d | 1029 | /* Codes_SRS_SCHEMA_99_053:[On success, Schema_GetModelActionArgumentCount shall return SCHEMA_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1030 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 1031 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1032 | |
AzureIoTClient | 0:1f9b2707ec7d | 1033 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1034 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1035 | |
AzureIoTClient | 0:1f9b2707ec7d | 1036 | SCHEMA_ACTION_ARGUMENT_HANDLE Schema_GetModelActionArgumentByName(SCHEMA_ACTION_HANDLE actionHandle, const char* actionArgumentName) |
AzureIoTClient | 0:1f9b2707ec7d | 1037 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1038 | SCHEMA_ACTION_ARGUMENT_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 1039 | |
AzureIoTClient | 0:1f9b2707ec7d | 1040 | /* 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 | 1041 | if ((actionHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1042 | (actionArgumentName == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 1043 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1044 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1045 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1046 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1047 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1048 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1049 | /* 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 | 1050 | ACTION* modelAction = (ACTION*)actionHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1051 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 1052 | |
AzureIoTClient | 0:1f9b2707ec7d | 1053 | for (i = 0; i < modelAction->ArgumentCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 1054 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1055 | SCHEMA_ACTION_ARGUMENT* actionArgument = (SCHEMA_ACTION_ARGUMENT*)modelAction->ArgumentHandles[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 1056 | if (strcmp(actionArgument->Name, actionArgumentName) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 1057 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1058 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 1059 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1060 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1061 | |
AzureIoTClient | 0:1f9b2707ec7d | 1062 | if (i == modelAction->ArgumentCount) |
AzureIoTClient | 0:1f9b2707ec7d | 1063 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1064 | /* 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 | 1065 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1066 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ELEMENT_NOT_FOUND)); |
AzureIoTClient | 0:1f9b2707ec7d | 1067 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1068 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1069 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1070 | /* 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 | 1071 | result = modelAction->ArgumentHandles[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 1072 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1073 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1074 | |
AzureIoTClient | 0:1f9b2707ec7d | 1075 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1076 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1077 | |
AzureIoTClient | 0:1f9b2707ec7d | 1078 | SCHEMA_ACTION_ARGUMENT_HANDLE Schema_GetModelActionArgumentByIndex(SCHEMA_ACTION_HANDLE actionHandle, size_t argumentIndex) |
AzureIoTClient | 0:1f9b2707ec7d | 1079 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1080 | SCHEMA_ACTION_ARGUMENT_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 1081 | ACTION* modelAction = (ACTION*)actionHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1082 | |
AzureIoTClient | 0:1f9b2707ec7d | 1083 | /* 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 | 1084 | if ((actionHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1085 | (argumentIndex >= modelAction->ArgumentCount)) |
AzureIoTClient | 0:1f9b2707ec7d | 1086 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1087 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1088 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1089 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1090 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1091 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1092 | /* 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 | 1093 | result = modelAction->ArgumentHandles[argumentIndex]; |
AzureIoTClient | 0:1f9b2707ec7d | 1094 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1095 | |
AzureIoTClient | 0:1f9b2707ec7d | 1096 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1097 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1098 | |
AzureIoTClient | 0:1f9b2707ec7d | 1099 | const char* Schema_GetActionArgumentName(SCHEMA_ACTION_ARGUMENT_HANDLE actionArgumentHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 1100 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1101 | const char* result; |
AzureIoTClient | 0:1f9b2707ec7d | 1102 | /* Codes_SRS_SCHEMA_99_114: [Schema_GetActionArgumentName shall return NULL if actionArgumentHandle is NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1103 | if (actionArgumentHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1104 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1105 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1106 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1107 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1108 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1109 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1110 | /* Codes_SRS_SCHEMA_99_113: [Schema_GetActionArgumentName shall return the argument name identified by the actionArgumentHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1111 | SCHEMA_ACTION_ARGUMENT* actionArgument = (SCHEMA_ACTION_ARGUMENT*)actionArgumentHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1112 | result = actionArgument->Name; |
AzureIoTClient | 0:1f9b2707ec7d | 1113 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1114 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1115 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1116 | |
AzureIoTClient | 0:1f9b2707ec7d | 1117 | const char* Schema_GetActionArgumentType(SCHEMA_ACTION_ARGUMENT_HANDLE actionArgumentHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 1118 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1119 | const char* result; |
AzureIoTClient | 0:1f9b2707ec7d | 1120 | /* Codes_SRS_SCHEMA_99_116: [Schema_GetActionArgumentType shall return NULL if actionArgumentHandle is NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1121 | if (actionArgumentHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1122 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1123 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1124 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1125 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1126 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1127 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1128 | /* Codes_SRS_SCHEMA_99_115: [Schema_GetActionArgumentType shall return the argument type identified by the actionArgumentHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1129 | SCHEMA_ACTION_ARGUMENT* actionArgument = (SCHEMA_ACTION_ARGUMENT*)actionArgumentHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1130 | result = actionArgument->Type; |
AzureIoTClient | 0:1f9b2707ec7d | 1131 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1132 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1133 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1134 | |
AzureIoTClient | 0:1f9b2707ec7d | 1135 | SCHEMA_STRUCT_TYPE_HANDLE Schema_CreateStructType(SCHEMA_HANDLE schemaHandle, const char* typeName) |
AzureIoTClient | 0:1f9b2707ec7d | 1136 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1137 | SCHEMA_STRUCT_TYPE_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 1138 | SCHEMA* schema = (SCHEMA*)schemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1139 | |
AzureIoTClient | 0:1f9b2707ec7d | 1140 | /* Codes_SRS_SCHEMA_99_060:[If any of the arguments is NULL, Schema_CreateStructType shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1141 | if ((schema == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1142 | (typeName == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 1143 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1144 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1145 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1146 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1147 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1148 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1149 | STRUCT_TYPE* structType; |
AzureIoTClient | 0:1f9b2707ec7d | 1150 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 1151 | |
AzureIoTClient | 0:1f9b2707ec7d | 1152 | /* Codes_SRS_SCHEMA_99_061:[If a struct type with the same name already exists, Schema_CreateStructType shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1153 | for (i = 0; i < schema->StructTypeCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 1154 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1155 | structType = (STRUCT_TYPE*)schema->StructTypes[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 1156 | if (strcmp(structType->Name, typeName) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 1157 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1158 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 1159 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1160 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1161 | |
AzureIoTClient | 0:1f9b2707ec7d | 1162 | if (i < schema->StructTypeCount) |
AzureIoTClient | 0:1f9b2707ec7d | 1163 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1164 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1165 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_DUPLICATE_ELEMENT)); |
AzureIoTClient | 0:1f9b2707ec7d | 1166 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1167 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1168 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1169 | SCHEMA_STRUCT_TYPE_HANDLE* newStructTypes = (SCHEMA_STRUCT_TYPE_HANDLE*)realloc(schema->StructTypes, sizeof(SCHEMA_STRUCT_TYPE_HANDLE) * (schema->StructTypeCount + 1)); |
AzureIoTClient | 0:1f9b2707ec7d | 1170 | if (newStructTypes == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1171 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1172 | /* Codes_SRS_SCHEMA_99_066:[On any other error, Schema_CreateStructType shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1173 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1174 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 1175 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1176 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1177 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1178 | schema->StructTypes = newStructTypes; |
AzureIoTClient | 0:1f9b2707ec7d | 1179 | if ((structType = (STRUCT_TYPE*)malloc(sizeof(STRUCT_TYPE))) == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1180 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1181 | /* Codes_SRS_SCHEMA_99_066:[On any other error, Schema_CreateStructType shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1182 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1183 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 1184 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1185 | else if (mallocAndStrcpy_s((char**)&structType->Name, typeName) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 1186 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1187 | /* Codes_SRS_SCHEMA_99_066:[On any other error, Schema_CreateStructType shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1188 | result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 1189 | free(structType); |
AzureIoTClient | 11:b1327861f5e0 | 1190 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 1191 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1192 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1193 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1194 | /* Codes_SRS_SCHEMA_99_057:[Schema_CreateStructType shall create a new struct type and return a handle to it.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1195 | schema->StructTypes[schema->StructTypeCount] = structType; |
AzureIoTClient | 0:1f9b2707ec7d | 1196 | schema->StructTypeCount++; |
AzureIoTClient | 0:1f9b2707ec7d | 1197 | structType->PropertyCount = 0; |
AzureIoTClient | 0:1f9b2707ec7d | 1198 | structType->Properties = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 1199 | |
AzureIoTClient | 0:1f9b2707ec7d | 1200 | /* Codes_SRS_SCHEMA_99_058:[On success, a non-NULL handle shall be returned.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1201 | result = (SCHEMA_STRUCT_TYPE_HANDLE)structType; |
AzureIoTClient | 0:1f9b2707ec7d | 1202 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1203 | |
AzureIoTClient | 0:1f9b2707ec7d | 1204 | /* If possible, reduce the memory of over allocation */ |
AzureIoTClient | 0:1f9b2707ec7d | 1205 | if (result == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1206 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1207 | SCHEMA_STRUCT_TYPE_HANDLE* oldStructTypes = (SCHEMA_STRUCT_TYPE_HANDLE*)realloc(schema->StructTypes, sizeof(SCHEMA_STRUCT_TYPE_HANDLE) * schema->StructTypeCount); |
AzureIoTClient | 0:1f9b2707ec7d | 1208 | if (oldStructTypes == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1209 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1210 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1211 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ERROR)); |
AzureIoTClient | 0:1f9b2707ec7d | 1212 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1213 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1214 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1215 | schema->StructTypes = oldStructTypes; |
AzureIoTClient | 0:1f9b2707ec7d | 1216 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1217 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1218 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1219 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1220 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1221 | |
AzureIoTClient | 0:1f9b2707ec7d | 1222 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1223 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1224 | |
AzureIoTClient | 0:1f9b2707ec7d | 1225 | const char* Schema_GetStructTypeName(SCHEMA_STRUCT_TYPE_HANDLE structTypeHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 1226 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1227 | const char* result; |
AzureIoTClient | 0:1f9b2707ec7d | 1228 | |
AzureIoTClient | 0:1f9b2707ec7d | 1229 | /* Codes_SRS_SCHEMA_99_136: [If structTypeHandle is NULL, Schema_GetStructTypeName shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1230 | if (structTypeHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1231 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1232 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1233 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1234 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1235 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1236 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1237 | /* Codes_SRS_SCHEMA_99_135: [Schema_GetStructTypeName shall return the name of a struct type identified by the structTypeHandle argument.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1238 | result = ((STRUCT_TYPE*)structTypeHandle)->Name; |
AzureIoTClient | 0:1f9b2707ec7d | 1239 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1240 | |
AzureIoTClient | 0:1f9b2707ec7d | 1241 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1242 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1243 | |
AzureIoTClient | 0:1f9b2707ec7d | 1244 | SCHEMA_RESULT Schema_GetStructTypeCount(SCHEMA_HANDLE schemaHandle, size_t* structTypeCount) |
AzureIoTClient | 0:1f9b2707ec7d | 1245 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1246 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 1247 | |
AzureIoTClient | 0:1f9b2707ec7d | 1248 | /* Codes_SRS_SCHEMA_99_140: [Schema_GetStructTypeCount shall return SCHEMA_INVALID_ARG if any of the arguments is NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1249 | if ((schemaHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1250 | (structTypeCount == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 1251 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1252 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 11:b1327861f5e0 | 1253 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1254 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1255 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1256 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1257 | /* Codes_SRS_SCHEMA_99_137: [Schema_GetStructTypeCount shall provide the number of structs defined in the schema identified by schemaHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1258 | SCHEMA* schema = (SCHEMA*)schemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1259 | /* Codes_SRS_SCHEMA_99_138: [The count shall be provided via the out argument structTypeCount.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1260 | *structTypeCount = schema->StructTypeCount; |
AzureIoTClient | 0:1f9b2707ec7d | 1261 | /* Codes_SRS_SCHEMA_99_139: [On success, Schema_GetStructTypeCount shall return SCHEMA_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1262 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 1263 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1264 | |
AzureIoTClient | 0:1f9b2707ec7d | 1265 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1266 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1267 | |
AzureIoTClient | 0:1f9b2707ec7d | 1268 | SCHEMA_STRUCT_TYPE_HANDLE Schema_GetStructTypeByName(SCHEMA_HANDLE schemaHandle, const char* name) |
AzureIoTClient | 0:1f9b2707ec7d | 1269 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1270 | SCHEMA_ACTION_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 1271 | SCHEMA* schema = (SCHEMA*)schemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1272 | |
AzureIoTClient | 0:1f9b2707ec7d | 1273 | /* 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 | 1274 | if ((schemaHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1275 | (name == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 1276 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1277 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1278 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1279 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1280 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1281 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1282 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 1283 | |
AzureIoTClient | 0:1f9b2707ec7d | 1284 | /* 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 | 1285 | for (i = 0; i < schema->StructTypeCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 1286 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1287 | STRUCT_TYPE* structType = (STRUCT_TYPE*)schema->StructTypes[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 1288 | if (strcmp(structType->Name, name) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 1289 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1290 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 1291 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1292 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1293 | |
AzureIoTClient | 0:1f9b2707ec7d | 1294 | if (i == schema->StructTypeCount) |
AzureIoTClient | 0:1f9b2707ec7d | 1295 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1296 | /* 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 | 1297 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1298 | LogError("(Error code:%s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ELEMENT_NOT_FOUND)); |
AzureIoTClient | 0:1f9b2707ec7d | 1299 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1300 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1301 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1302 | result = schema->StructTypes[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 1303 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1304 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1305 | |
AzureIoTClient | 0:1f9b2707ec7d | 1306 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1307 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1308 | |
AzureIoTClient | 0:1f9b2707ec7d | 1309 | SCHEMA_STRUCT_TYPE_HANDLE Schema_GetStructTypeByIndex(SCHEMA_HANDLE schemaHandle, size_t index) |
AzureIoTClient | 0:1f9b2707ec7d | 1310 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1311 | SCHEMA_STRUCT_TYPE_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 1312 | SCHEMA* schema = (SCHEMA*)schemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1313 | |
AzureIoTClient | 0:1f9b2707ec7d | 1314 | /* 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 | 1315 | /* 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 | 1316 | if ((schemaHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1317 | (index >= schema->StructTypeCount)) |
AzureIoTClient | 0:1f9b2707ec7d | 1318 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1319 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1320 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1321 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1322 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1323 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1324 | |
AzureIoTClient | 0:1f9b2707ec7d | 1325 | /* 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 | 1326 | /* 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 | 1327 | result = schema->StructTypes[index]; |
AzureIoTClient | 0:1f9b2707ec7d | 1328 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1329 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1330 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1331 | |
AzureIoTClient | 0:1f9b2707ec7d | 1332 | SCHEMA_RESULT Schema_AddStructTypeProperty(SCHEMA_STRUCT_TYPE_HANDLE structTypeHandle, const char* propertyName, const char* propertyType) |
AzureIoTClient | 0:1f9b2707ec7d | 1333 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1334 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 1335 | |
AzureIoTClient | 0:1f9b2707ec7d | 1336 | /* Codes_SRS_SCHEMA_99_072:[If any of the arguments is NULL, Schema_AddStructTypeProperty shall return SCHEMA_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1337 | if ((structTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1338 | (propertyName == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1339 | (propertyType == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 1340 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1341 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 11:b1327861f5e0 | 1342 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1343 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1344 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1345 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1346 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 1347 | STRUCT_TYPE* structType = (STRUCT_TYPE*)structTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1348 | |
AzureIoTClient | 0:1f9b2707ec7d | 1349 | /* 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 | 1350 | for (i = 0; i < structType->PropertyCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 1351 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1352 | PROPERTY* property = (PROPERTY*)structType->Properties[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 1353 | if (strcmp(property->PropertyName, propertyName) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 1354 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1355 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 1356 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1357 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1358 | |
AzureIoTClient | 0:1f9b2707ec7d | 1359 | if (i < structType->PropertyCount) |
AzureIoTClient | 0:1f9b2707ec7d | 1360 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1361 | result = SCHEMA_DUPLICATE_ELEMENT; |
AzureIoTClient | 11:b1327861f5e0 | 1362 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1363 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1364 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1365 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1366 | SCHEMA_PROPERTY_HANDLE* newProperties = (SCHEMA_PROPERTY_HANDLE*)realloc(structType->Properties, sizeof(SCHEMA_PROPERTY_HANDLE) * (structType->PropertyCount + 1)); |
AzureIoTClient | 0:1f9b2707ec7d | 1367 | if (newProperties == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1368 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1369 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 1370 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1371 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1372 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1373 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1374 | PROPERTY* newProperty; |
AzureIoTClient | 0:1f9b2707ec7d | 1375 | |
AzureIoTClient | 0:1f9b2707ec7d | 1376 | structType->Properties = newProperties; |
AzureIoTClient | 0:1f9b2707ec7d | 1377 | if ((newProperty = (PROPERTY*)malloc(sizeof(PROPERTY))) == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1378 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1379 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 1380 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1381 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1382 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1383 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1384 | if (mallocAndStrcpy_s((char**)&newProperty->PropertyName, propertyName) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 1385 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1386 | free(newProperty); |
AzureIoTClient | 0:1f9b2707ec7d | 1387 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 1388 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1389 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1390 | else if (mallocAndStrcpy_s((char**)&newProperty->PropertyType, propertyType) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 1391 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1392 | free((void*)newProperty->PropertyName); |
AzureIoTClient | 0:1f9b2707ec7d | 1393 | free(newProperty); |
AzureIoTClient | 0:1f9b2707ec7d | 1394 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 1395 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1396 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1397 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1398 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1399 | /* Codes_SRS_SCHEMA_99_070:[Schema_AddStructTypeProperty shall add one property to the struct type identified by structTypeHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1400 | structType->Properties[structType->PropertyCount] = (SCHEMA_PROPERTY_HANDLE)newProperty; |
AzureIoTClient | 0:1f9b2707ec7d | 1401 | structType->PropertyCount++; |
AzureIoTClient | 0:1f9b2707ec7d | 1402 | |
AzureIoTClient | 0:1f9b2707ec7d | 1403 | /* Codes_SRS_SCHEMA_99_071:[On success, Schema_AddStructTypeProperty shall return SCHEMA_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1404 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 1405 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1406 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1407 | |
AzureIoTClient | 0:1f9b2707ec7d | 1408 | /* If possible, reduce the memory of over allocation */ |
AzureIoTClient | 0:1f9b2707ec7d | 1409 | if (result != SCHEMA_OK) |
AzureIoTClient | 0:1f9b2707ec7d | 1410 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1411 | SCHEMA_PROPERTY_HANDLE* oldProperties = (SCHEMA_PROPERTY_HANDLE*)realloc(structType->Properties, sizeof(SCHEMA_PROPERTY_HANDLE) * structType->PropertyCount); |
AzureIoTClient | 0:1f9b2707ec7d | 1412 | if (oldProperties == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1413 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1414 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 1415 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1416 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1417 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1418 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1419 | structType->Properties = oldProperties; |
AzureIoTClient | 0:1f9b2707ec7d | 1420 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1421 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1422 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1423 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1424 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1425 | |
AzureIoTClient | 0:1f9b2707ec7d | 1426 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1427 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1428 | |
AzureIoTClient | 0:1f9b2707ec7d | 1429 | SCHEMA_PROPERTY_HANDLE Schema_GetStructTypePropertyByName(SCHEMA_STRUCT_TYPE_HANDLE structTypeHandle, const char* propertyName) |
AzureIoTClient | 0:1f9b2707ec7d | 1430 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1431 | SCHEMA_PROPERTY_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 1432 | |
AzureIoTClient | 0:1f9b2707ec7d | 1433 | /* 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 | 1434 | if ((structTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1435 | (propertyName == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 1436 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1437 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1438 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1439 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1440 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1441 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1442 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 1443 | STRUCT_TYPE* structType = (STRUCT_TYPE*)structTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1444 | |
AzureIoTClient | 0:1f9b2707ec7d | 1445 | for (i = 0; i < structType->PropertyCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 1446 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1447 | PROPERTY* modelProperty = (PROPERTY*)structType->Properties[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 1448 | if (strcmp(modelProperty->PropertyName, propertyName) == 0) |
AzureIoTClient | 0:1f9b2707ec7d | 1449 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1450 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 1451 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1452 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1453 | |
AzureIoTClient | 0:1f9b2707ec7d | 1454 | /* 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 | 1455 | if (i == structType->PropertyCount) |
AzureIoTClient | 0:1f9b2707ec7d | 1456 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1457 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1458 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_ELEMENT_NOT_FOUND)); |
AzureIoTClient | 0:1f9b2707ec7d | 1459 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1460 | /* 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 | 1461 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1462 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1463 | result = structType->Properties[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 1464 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1465 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1466 | |
AzureIoTClient | 0:1f9b2707ec7d | 1467 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1468 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1469 | |
AzureIoTClient | 0:1f9b2707ec7d | 1470 | SCHEMA_RESULT Schema_GetStructTypePropertyCount(SCHEMA_STRUCT_TYPE_HANDLE structTypeHandle, size_t* propertyCount) |
AzureIoTClient | 0:1f9b2707ec7d | 1471 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1472 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 1473 | |
AzureIoTClient | 0:1f9b2707ec7d | 1474 | /* 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 | 1475 | if ((structTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1476 | (propertyCount == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 1477 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1478 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 11:b1327861f5e0 | 1479 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1480 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1481 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1482 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1483 | STRUCT_TYPE* structType = (STRUCT_TYPE*)structTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1484 | |
AzureIoTClient | 0:1f9b2707ec7d | 1485 | /* 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 | 1486 | /* Codes_SRS_SCHEMA_99_081: [The count shall be provided via the out argument propertyCount.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1487 | *propertyCount = structType->PropertyCount; |
AzureIoTClient | 0:1f9b2707ec7d | 1488 | |
AzureIoTClient | 0:1f9b2707ec7d | 1489 | /* Codes_SRS_SCHEMA_99_078: [On success, Schema_ GetStructTypePropertyCount shall return SCHEMA_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1490 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 1491 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1492 | |
AzureIoTClient | 0:1f9b2707ec7d | 1493 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1494 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1495 | |
AzureIoTClient | 0:1f9b2707ec7d | 1496 | SCHEMA_PROPERTY_HANDLE Schema_GetStructTypePropertyByIndex(SCHEMA_STRUCT_TYPE_HANDLE structTypeHandle, size_t index) |
AzureIoTClient | 0:1f9b2707ec7d | 1497 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1498 | SCHEMA_PROPERTY_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 1499 | STRUCT_TYPE* structType = (STRUCT_TYPE*)structTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1500 | |
AzureIoTClient | 0:1f9b2707ec7d | 1501 | /* 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 | 1502 | if ((structTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1503 | (index >= structType->PropertyCount)) |
AzureIoTClient | 0:1f9b2707ec7d | 1504 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1505 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1506 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1507 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1508 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1509 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1510 | /* 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 | 1511 | /* 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 | 1512 | result = structType->Properties[index]; |
AzureIoTClient | 0:1f9b2707ec7d | 1513 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1514 | |
AzureIoTClient | 0:1f9b2707ec7d | 1515 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1516 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1517 | |
AzureIoTClient | 0:1f9b2707ec7d | 1518 | const char* Schema_GetPropertyName(SCHEMA_PROPERTY_HANDLE propertyHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 1519 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1520 | const char* result; |
AzureIoTClient | 0:1f9b2707ec7d | 1521 | |
AzureIoTClient | 0:1f9b2707ec7d | 1522 | /* Codes_SRS_SCHEMA_99_086: [If propertyHandle is NULL, Schema_GetPropertyName shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1523 | if (propertyHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1524 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1525 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1526 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1527 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1528 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1529 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1530 | PROPERTY* propertyType = (PROPERTY*)propertyHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1531 | |
AzureIoTClient | 0:1f9b2707ec7d | 1532 | /* Codes_SRS_SCHEMA_99_085: [Schema_GetPropertyName shall return the property name identified by the propertyHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1533 | result = propertyType->PropertyName; |
AzureIoTClient | 0:1f9b2707ec7d | 1534 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1535 | |
AzureIoTClient | 0:1f9b2707ec7d | 1536 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1537 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1538 | |
AzureIoTClient | 0:1f9b2707ec7d | 1539 | const char* Schema_GetPropertyType(SCHEMA_PROPERTY_HANDLE propertyHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 1540 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1541 | const char* result; |
AzureIoTClient | 0:1f9b2707ec7d | 1542 | |
AzureIoTClient | 0:1f9b2707ec7d | 1543 | /* Codes_SRS_SCHEMA_99_088: [If propertyHandle is NULL, Schema_GetPropertyType shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1544 | if (propertyHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1545 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1546 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1547 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1548 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1549 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1550 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1551 | PROPERTY* modelProperty = (PROPERTY*)propertyHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1552 | |
AzureIoTClient | 0:1f9b2707ec7d | 1553 | /* Codes_SRS_SCHEMA_99_087: [Schema_GetPropertyType shall return the property type identified by the propertyHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1554 | result = modelProperty->PropertyType; |
AzureIoTClient | 0:1f9b2707ec7d | 1555 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1556 | |
AzureIoTClient | 0:1f9b2707ec7d | 1557 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1558 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1559 | |
AzureIoTClient | 0:1f9b2707ec7d | 1560 | SCHEMA_RESULT Schema_GetModelCount(SCHEMA_HANDLE schemaHandle, size_t* modelCount) |
AzureIoTClient | 0:1f9b2707ec7d | 1561 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1562 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 1563 | /* Codes_SRS_SCHEMA_99_123: [Schema_GetModelCount shall return SCHEMA_INVALID_ARG if any of the arguments is NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1564 | if ((schemaHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1565 | (modelCount == NULL) ) |
AzureIoTClient | 0:1f9b2707ec7d | 1566 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1567 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 11:b1327861f5e0 | 1568 | LogError("(result = %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1569 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1570 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1571 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1572 | /* Codes_SRS_SCHEMA_99_120: [Schema_GetModelCount shall provide the number of models defined in the schema identified by schemaHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1573 | SCHEMA* schema = (SCHEMA*)schemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1574 | /* Codes_SRS_SCHEMA_99_121: [The count shall be provided via the out argument modelCount.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1575 | *modelCount = schema->ModelTypeCount; |
AzureIoTClient | 0:1f9b2707ec7d | 1576 | /* Codes_SRS_SCHEMA_99_122: [On success, Schema_GetModelCount shall return SCHEMA_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1577 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 1578 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1579 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1580 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1581 | |
AzureIoTClient | 0:1f9b2707ec7d | 1582 | SCHEMA_MODEL_TYPE_HANDLE Schema_GetModelByName(SCHEMA_HANDLE schemaHandle, const char* modelName) |
AzureIoTClient | 0:1f9b2707ec7d | 1583 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1584 | SCHEMA_MODEL_TYPE_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 1585 | |
AzureIoTClient | 0:1f9b2707ec7d | 1586 | /* 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 | 1587 | if ((schemaHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1588 | (modelName == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 1589 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1590 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1591 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1592 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1593 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1594 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1595 | /* 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 | 0:1f9b2707ec7d | 1596 | SCHEMA* schema = (SCHEMA*)schemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1597 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 1598 | for (i = 0; i < schema->ModelTypeCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 1599 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1600 | MODEL_TYPE* modelType = (MODEL_TYPE*)schema->ModelTypes[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 1601 | if (strcmp(modelName, modelType->Name)==0) |
AzureIoTClient | 0:1f9b2707ec7d | 1602 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1603 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 1604 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1605 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1606 | if (i == schema->ModelTypeCount) |
AzureIoTClient | 0:1f9b2707ec7d | 1607 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1608 | /* 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 | 1609 | result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 1610 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1611 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1612 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1613 | result = schema->ModelTypes[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 1614 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1615 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1616 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1617 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1618 | |
AzureIoTClient | 0:1f9b2707ec7d | 1619 | SCHEMA_MODEL_TYPE_HANDLE Schema_GetModelByIndex(SCHEMA_HANDLE schemaHandle, size_t index) |
AzureIoTClient | 0:1f9b2707ec7d | 1620 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1621 | SCHEMA_MODEL_TYPE_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 1622 | SCHEMA* schema = (SCHEMA*)schemaHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1623 | |
AzureIoTClient | 0:1f9b2707ec7d | 1624 | /* 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 | 1625 | /* 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 | 1626 | if ((schemaHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1627 | (index >= schema->ModelTypeCount)) |
AzureIoTClient | 0:1f9b2707ec7d | 1628 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1629 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 1630 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1631 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1632 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1633 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1634 | |
AzureIoTClient | 0:1f9b2707ec7d | 1635 | /* 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 | 1636 | /* 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 | 1637 | result = schema->ModelTypes[index]; |
AzureIoTClient | 0:1f9b2707ec7d | 1638 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1639 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1640 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1641 | |
AzureIoTClient | 0:1f9b2707ec7d | 1642 | /*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 | 1643 | const char* Schema_GetModelName(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 1644 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1645 | const char* result; |
AzureIoTClient | 0:1f9b2707ec7d | 1646 | if (modelTypeHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1647 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1648 | result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 1649 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1650 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1651 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1652 | MODEL_TYPE* modelType = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1653 | result = modelType->Name; |
AzureIoTClient | 0:1f9b2707ec7d | 1654 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1655 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1656 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1657 | |
AzureIoTClient | 0:1f9b2707ec7d | 1658 | /*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 | 0:1f9b2707ec7d | 1659 | SCHEMA_RESULT Schema_AddModelModel(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* propertyName, SCHEMA_MODEL_TYPE_HANDLE modelType) |
AzureIoTClient | 0:1f9b2707ec7d | 1660 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1661 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 1662 | /*Codes_SRS_SCHEMA_99_165: [If any of the parameters is NULL then Schema_AddModelModel shall return SCHEMA_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1663 | if ( |
AzureIoTClient | 0:1f9b2707ec7d | 1664 | (modelTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1665 | (propertyName == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1666 | (modelType == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1667 | ) |
AzureIoTClient | 0:1f9b2707ec7d | 1668 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1669 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 11:b1327861f5e0 | 1670 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, SCHEMA_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 1671 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1672 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1673 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1674 | MODEL_TYPE* parentModel = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1675 | MODEL_IN_MODEL temp; |
AzureIoTClient | 0:1f9b2707ec7d | 1676 | temp.modelHandle = modelType; |
AzureIoTClient | 0:1f9b2707ec7d | 1677 | if (mallocAndStrcpy_s((char**)&(temp.propertyName), propertyName) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 1678 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1679 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 1680 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1681 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1682 | else if (VECTOR_push_back(parentModel->models, &temp, 1) != 0) |
AzureIoTClient | 0:1f9b2707ec7d | 1683 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1684 | /*Codes_SRS_SCHEMA_99_174: [The function shall return SCHEMA_ERROR if any other error occurs.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1685 | free((void*)temp.propertyName); |
AzureIoTClient | 0:1f9b2707ec7d | 1686 | result = SCHEMA_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 1687 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1688 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1689 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1690 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1691 | /*Codes_SRS_SCHEMA_99_164: [If the function succeeds, then the return value shall be SCHEMA_OK.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1692 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 1693 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1694 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1695 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1696 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1697 | |
AzureIoTClient | 0:1f9b2707ec7d | 1698 | |
AzureIoTClient | 0:1f9b2707ec7d | 1699 | SCHEMA_RESULT Schema_GetModelModelCount(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t* modelCount) |
AzureIoTClient | 0:1f9b2707ec7d | 1700 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1701 | SCHEMA_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 1702 | /*Codes_SRS_SCHEMA_99_169: [If any of the parameters is NULL, then the function shall return SCHEMA_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1703 | if ( |
AzureIoTClient | 0:1f9b2707ec7d | 1704 | (modelTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1705 | (modelCount == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1706 | ) |
AzureIoTClient | 0:1f9b2707ec7d | 1707 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1708 | result = SCHEMA_INVALID_ARG; |
AzureIoTClient | 11:b1327861f5e0 | 1709 | LogError("(Error code: %s)", ENUM_TO_STRING(SCHEMA_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 1710 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1711 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1712 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1713 | MODEL_TYPE* model = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1714 | /*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 | 1715 | *modelCount = VECTOR_size(model->models); |
AzureIoTClient | 0:1f9b2707ec7d | 1716 | /*SRS_SCHEMA_99_168: [If the function succeeds, it shall return SCHEMA_OK.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1717 | result = SCHEMA_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 1718 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1719 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1720 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1721 | |
AzureIoTClient | 0:1f9b2707ec7d | 1722 | static bool matchModelName(const void* element, const void* value) |
AzureIoTClient | 0:1f9b2707ec7d | 1723 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1724 | MODEL_IN_MODEL* decodedElement = (MODEL_IN_MODEL*)element; |
AzureIoTClient | 0:1f9b2707ec7d | 1725 | const char* name = (const char*)value; |
AzureIoTClient | 0:1f9b2707ec7d | 1726 | return (strcmp(decodedElement->propertyName, name) == 0); |
AzureIoTClient | 0:1f9b2707ec7d | 1727 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1728 | |
AzureIoTClient | 0:1f9b2707ec7d | 1729 | SCHEMA_MODEL_TYPE_HANDLE Schema_GetModelModelByName(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* propertyName) |
AzureIoTClient | 0:1f9b2707ec7d | 1730 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1731 | SCHEMA_MODEL_TYPE_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 1732 | if ( |
AzureIoTClient | 0:1f9b2707ec7d | 1733 | (modelTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1734 | (propertyName == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1735 | ) |
AzureIoTClient | 0:1f9b2707ec7d | 1736 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1737 | /*Codes_SRS_SCHEMA_99_171: [If Schema_GetModelModelByName is unable to provide the handle it shall return NULL.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1738 | result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 1739 | LogError("error SCHEMA_INVALID_ARG"); |
AzureIoTClient | 0:1f9b2707ec7d | 1740 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1741 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1742 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1743 | MODEL_TYPE* model = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1744 | /*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 | 1745 | /*Codes_SRS_SCHEMA_99_171: [If Schema_GetModelModelByName is unable to provide the handle it shall return NULL.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1746 | void* temp = VECTOR_find_if(model->models, matchModelName, propertyName); |
AzureIoTClient | 0:1f9b2707ec7d | 1747 | if (temp == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1748 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1749 | LogError("specified propertyName not found (%s)", propertyName); |
AzureIoTClient | 0:1f9b2707ec7d | 1750 | result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 1751 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1752 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1753 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1754 | result = ((MODEL_IN_MODEL*)temp)->modelHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1755 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1756 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1757 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1758 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1759 | |
AzureIoTClient | 0:1f9b2707ec7d | 1760 | SCHEMA_MODEL_TYPE_HANDLE Schema_GetModelModelyByIndex(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t index) |
AzureIoTClient | 0:1f9b2707ec7d | 1761 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1762 | SCHEMA_MODEL_TYPE_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 1763 | if ( |
AzureIoTClient | 0:1f9b2707ec7d | 1764 | (modelTypeHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1765 | ) |
AzureIoTClient | 0:1f9b2707ec7d | 1766 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1767 | /*Codes_SRS_SCHEMA_99_173: [Schema_GetModelModelyByIndex shall return NULL in the cases when it cannot provide the handle.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1768 | result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 1769 | LogError("error SCHEMA_INVALID_ARG"); |
AzureIoTClient | 0:1f9b2707ec7d | 1770 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1771 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1772 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1773 | MODEL_TYPE* model = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1774 | size_t nModelsInModel; |
AzureIoTClient | 0:1f9b2707ec7d | 1775 | /*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 | 1776 | /*Codes_SRS_SCHEMA_99_173: [Schema_GetModelModelyByIndex shall return NULL in the cases when it cannot provide the handle.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1777 | nModelsInModel = VECTOR_size(model->models); |
AzureIoTClient | 0:1f9b2707ec7d | 1778 | if (index < nModelsInModel) |
AzureIoTClient | 0:1f9b2707ec7d | 1779 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1780 | result = ((MODEL_IN_MODEL*)VECTOR_element(model->models, index))->modelHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1781 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1782 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1783 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1784 | LogError("attempted out of bounds access in array."); |
AzureIoTClient | 0:1f9b2707ec7d | 1785 | result = NULL; /*out of bounds array access*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1786 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1787 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1788 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1789 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1790 | |
AzureIoTClient | 0:1f9b2707ec7d | 1791 | const char* Schema_GetModelModelPropertyNameByIndex(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, size_t index) |
AzureIoTClient | 0:1f9b2707ec7d | 1792 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1793 | const char* result; |
AzureIoTClient | 0:1f9b2707ec7d | 1794 | if (modelTypeHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1795 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1796 | /*Codes_SRS_SCHEMA_99_176: [If Schema_GetModelModelPropertyNameByIndex cannot produce the property name, it shall return NULL.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1797 | result = NULL; |
AzureIoTClient | 0:1f9b2707ec7d | 1798 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1799 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1800 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1801 | MODEL_TYPE* model = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1802 | size_t nModelsInModel; |
AzureIoTClient | 0:1f9b2707ec7d | 1803 | /*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 | 1804 | /*Codes_SRS_SCHEMA_99_176: [If Schema_GetModelModelPropertyNameByIndex cannot produce the property name, it shall return NULL.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1805 | nModelsInModel = VECTOR_size(model->models); |
AzureIoTClient | 0:1f9b2707ec7d | 1806 | if (index < nModelsInModel) |
AzureIoTClient | 0:1f9b2707ec7d | 1807 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1808 | result = ((MODEL_IN_MODEL*)VECTOR_element(model->models, index))->propertyName; |
AzureIoTClient | 0:1f9b2707ec7d | 1809 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1810 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1811 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1812 | LogError("attempted out of bounds access in array."); |
AzureIoTClient | 0:1f9b2707ec7d | 1813 | result = NULL; /*out of bounds array access*/ |
AzureIoTClient | 0:1f9b2707ec7d | 1814 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1815 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1816 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1817 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1818 | |
AzureIoTClient | 0:1f9b2707ec7d | 1819 | bool Schema_ModelPropertyByPathExists(SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle, const char* propertyPath) |
AzureIoTClient | 0:1f9b2707ec7d | 1820 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1821 | bool result; |
AzureIoTClient | 0:1f9b2707ec7d | 1822 | |
AzureIoTClient | 0:1f9b2707ec7d | 1823 | /* Codes_SRS_SCHEMA_99_180: [If any of the arguments are NULL, Schema_ModelPropertyByPathExists shall return false.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1824 | if ((modelTypeHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 1825 | (propertyPath == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 1826 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1827 | LogError("error SCHEMA_INVALID_ARG"); |
AzureIoTClient | 0:1f9b2707ec7d | 1828 | result = false; |
AzureIoTClient | 0:1f9b2707ec7d | 1829 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1830 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1831 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1832 | const char* slashPos; |
AzureIoTClient | 0:1f9b2707ec7d | 1833 | result = false; |
AzureIoTClient | 0:1f9b2707ec7d | 1834 | |
AzureIoTClient | 0:1f9b2707ec7d | 1835 | /* 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 | 1836 | if (*propertyPath == '/') |
AzureIoTClient | 0:1f9b2707ec7d | 1837 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1838 | propertyPath++; |
AzureIoTClient | 0:1f9b2707ec7d | 1839 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1840 | |
AzureIoTClient | 0:1f9b2707ec7d | 1841 | do |
AzureIoTClient | 0:1f9b2707ec7d | 1842 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1843 | const char* endPos; |
AzureIoTClient | 0:1f9b2707ec7d | 1844 | size_t i; |
AzureIoTClient | 0:1f9b2707ec7d | 1845 | size_t modelCount; |
AzureIoTClient | 0:1f9b2707ec7d | 1846 | MODEL_TYPE* modelType = (MODEL_TYPE*)modelTypeHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1847 | |
AzureIoTClient | 0:1f9b2707ec7d | 1848 | /* Codes_SRS_SCHEMA_99_179: [The propertyPath shall be assumed to be in the format model1/model2/.../propertyName.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1849 | slashPos = strchr(propertyPath, '/'); |
AzureIoTClient | 0:1f9b2707ec7d | 1850 | endPos = slashPos; |
AzureIoTClient | 0:1f9b2707ec7d | 1851 | if (endPos == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1852 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1853 | endPos = &propertyPath[strlen(propertyPath)]; |
AzureIoTClient | 0:1f9b2707ec7d | 1854 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1855 | |
AzureIoTClient | 0:1f9b2707ec7d | 1856 | /* get the child-model */ |
AzureIoTClient | 0:1f9b2707ec7d | 1857 | modelCount = VECTOR_size(modelType->models); |
AzureIoTClient | 0:1f9b2707ec7d | 1858 | for (i = 0; i < modelCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 1859 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1860 | MODEL_IN_MODEL* childModel = (MODEL_IN_MODEL*)VECTOR_element(modelType->models, i); |
AzureIoTClient | 0:1f9b2707ec7d | 1861 | if ((strncmp(childModel->propertyName, propertyPath, endPos - propertyPath) == 0) && |
AzureIoTClient | 0:1f9b2707ec7d | 1862 | (strlen(childModel->propertyName) == (size_t)(endPos - propertyPath))) |
AzureIoTClient | 0:1f9b2707ec7d | 1863 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1864 | /* found */ |
AzureIoTClient | 0:1f9b2707ec7d | 1865 | modelTypeHandle = childModel->modelHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 1866 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 1867 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1868 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1869 | |
AzureIoTClient | 0:1f9b2707ec7d | 1870 | if (i < modelCount) |
AzureIoTClient | 0:1f9b2707ec7d | 1871 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1872 | /* model found, check if there is more in the path */ |
AzureIoTClient | 0:1f9b2707ec7d | 1873 | if (slashPos == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 1874 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1875 | /* this is the last one, so this is the thing we were looking for */ |
AzureIoTClient | 0:1f9b2707ec7d | 1876 | result = true; |
AzureIoTClient | 0:1f9b2707ec7d | 1877 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 1878 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1879 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1880 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1881 | /* continue looking, there's more */ |
AzureIoTClient | 0:1f9b2707ec7d | 1882 | propertyPath = slashPos + 1; |
AzureIoTClient | 0:1f9b2707ec7d | 1883 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1884 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1885 | else |
AzureIoTClient | 0:1f9b2707ec7d | 1886 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1887 | /* no model found, let's see if this is a property */ |
AzureIoTClient | 0:1f9b2707ec7d | 1888 | /* Codes_SRS_SCHEMA_99_178: [The argument propertyPath shall be used to find the leaf property.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1889 | for (i = 0; i < modelType->PropertyCount; i++) |
AzureIoTClient | 0:1f9b2707ec7d | 1890 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1891 | PROPERTY* property = (PROPERTY*)modelType->Properties[i]; |
AzureIoTClient | 0:1f9b2707ec7d | 1892 | if ((strncmp(property->PropertyName, propertyPath, endPos - propertyPath) == 0) && |
AzureIoTClient | 0:1f9b2707ec7d | 1893 | (strlen(property->PropertyName) == (size_t)(endPos - propertyPath))) |
AzureIoTClient | 0:1f9b2707ec7d | 1894 | { |
AzureIoTClient | 0:1f9b2707ec7d | 1895 | /* found property */ |
AzureIoTClient | 0:1f9b2707ec7d | 1896 | /* Codes_SRS_SCHEMA_99_177: [Schema_ModelPropertyByPathExists shall return true if a leaf property exists in the model modelTypeHandle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 1897 | result = true; |
AzureIoTClient | 0:1f9b2707ec7d | 1898 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 1899 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1900 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1901 | |
AzureIoTClient | 0:1f9b2707ec7d | 1902 | break; |
AzureIoTClient | 0:1f9b2707ec7d | 1903 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1904 | } while (slashPos != NULL); |
AzureIoTClient | 0:1f9b2707ec7d | 1905 | } |
AzureIoTClient | 0:1f9b2707ec7d | 1906 | |
AzureIoTClient | 0:1f9b2707ec7d | 1907 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 1908 | } |