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
schemalib.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:
- 21:6d3dea1abd9c
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 | 5:c08e3ffc68e4 | 5 | #ifndef WINCE |
AzureIoTClient | 0:1f9b2707ec7d | 6 | #ifdef _CRTDBG_MAP_ALLOC |
AzureIoTClient | 0:1f9b2707ec7d | 7 | #include <crtdbg.h> |
AzureIoTClient | 0:1f9b2707ec7d | 8 | #endif |
AzureIoTClient | 5:c08e3ffc68e4 | 9 | #endif |
Azure.IoT Build | 10:c2aee3965a83 | 10 | #include "azure_c_shared_utility/gballoc.h" |
AzureIoTClient | 0:1f9b2707ec7d | 11 | |
AzureIoTClient | 0:1f9b2707ec7d | 12 | #include "schemalib.h" |
AzureIoTClient | 0:1f9b2707ec7d | 13 | #include "codefirst.h" |
AzureIoTClient | 0:1f9b2707ec7d | 14 | #include "schema.h" |
AzureIoTClient | 0:1f9b2707ec7d | 15 | #include "datamarshaller.h" |
AzureIoTClient | 0:1f9b2707ec7d | 16 | #include "datapublisher.h" |
AzureIoTClient | 0:1f9b2707ec7d | 17 | #include <stddef.h> |
Azure.IoT Build | 13:16e88f0cfa5f | 18 | #include "azure_c_shared_utility/xlogging.h" |
AzureIoTClient | 0:1f9b2707ec7d | 19 | #include "iotdevice.h" |
AzureIoTClient | 0:1f9b2707ec7d | 20 | |
AzureIoTClient | 0:1f9b2707ec7d | 21 | #define DEFAULT_CONTAINER_NAME "Container" |
AzureIoTClient | 0:1f9b2707ec7d | 22 | |
AzureIoTClient | 0:1f9b2707ec7d | 23 | DEFINE_ENUM_STRINGS(SERIALIZER_RESULT, SERIALIZER_RESULT_VALUES); |
AzureIoTClient | 0:1f9b2707ec7d | 24 | |
AzureIoTClient | 0:1f9b2707ec7d | 25 | typedef enum AGENT_STATE_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 26 | { |
AzureIoTClient | 0:1f9b2707ec7d | 27 | AGENT_NOT_INITIALIZED, |
AzureIoTClient | 0:1f9b2707ec7d | 28 | AGENT_INITIALIZED |
AzureIoTClient | 0:1f9b2707ec7d | 29 | } AGENT_STATE; |
AzureIoTClient | 0:1f9b2707ec7d | 30 | |
AzureIoTClient | 0:1f9b2707ec7d | 31 | static AGENT_STATE g_AgentState = AGENT_NOT_INITIALIZED; |
AzureIoTClient | 0:1f9b2707ec7d | 32 | |
AzureIoTClient | 0:1f9b2707ec7d | 33 | SERIALIZER_RESULT serializer_init(const char* overrideSchemaNamespace) |
AzureIoTClient | 0:1f9b2707ec7d | 34 | { |
AzureIoTClient | 0:1f9b2707ec7d | 35 | SERIALIZER_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 36 | |
AzureIoTClient | 0:1f9b2707ec7d | 37 | /* Codes_SRS_SCHEMALIB_99_074:[serializer_init when already initialized shall return SERIALIZER_ALREADY_INIT.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 38 | if (g_AgentState != AGENT_NOT_INITIALIZED) |
AzureIoTClient | 0:1f9b2707ec7d | 39 | { |
AzureIoTClient | 0:1f9b2707ec7d | 40 | result = SERIALIZER_ALREADY_INIT; |
AzureIoTClient | 11:b1327861f5e0 | 41 | LogError("(result = %s)", ENUM_TO_STRING(SERIALIZER_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 42 | } |
AzureIoTClient | 0:1f9b2707ec7d | 43 | else |
AzureIoTClient | 0:1f9b2707ec7d | 44 | { |
AzureIoTClient | 0:1f9b2707ec7d | 45 | /* Codes_SRS_SCHEMALIB_99_006:[ Initialize CodeFirst by a call to CodeFirst_Init.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 46 | /* Codes_SRS_SCHEMALIB_99_076:[serializer_init shall pass the value of overrideSchemaNamespace argument to CodeFirst_Init.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 47 | if (CodeFirst_Init(overrideSchemaNamespace) != CODEFIRST_OK) |
AzureIoTClient | 0:1f9b2707ec7d | 48 | { |
AzureIoTClient | 0:1f9b2707ec7d | 49 | /* Codes_SRS_SCHEMALIB_99_007:[ On error SERIALIZER_CODEFIRST_INIT_FAILED shall be returned.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 50 | result = SERIALIZER_CODEFIRST_INIT_FAILED; |
AzureIoTClient | 11:b1327861f5e0 | 51 | LogError("(result = %s)", ENUM_TO_STRING(SERIALIZER_RESULT, result)); |
AzureIoTClient | 0:1f9b2707ec7d | 52 | } |
AzureIoTClient | 0:1f9b2707ec7d | 53 | else |
AzureIoTClient | 0:1f9b2707ec7d | 54 | { |
AzureIoTClient | 0:1f9b2707ec7d | 55 | /* Codes_SRS_SCHEMALIB_99_075:[When an serializer_init call fails for any reason the previous initialization state shall be preserved. The initialized state shall only be changed on a succesfull Init.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 56 | g_AgentState = AGENT_INITIALIZED; |
AzureIoTClient | 0:1f9b2707ec7d | 57 | |
AzureIoTClient | 0:1f9b2707ec7d | 58 | /* Codes_SRS_SCHEMALIB_99_073:[On success serializer_init shall return SERIALIZER_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 59 | result = SERIALIZER_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 60 | } |
AzureIoTClient | 0:1f9b2707ec7d | 61 | } |
AzureIoTClient | 0:1f9b2707ec7d | 62 | |
AzureIoTClient | 0:1f9b2707ec7d | 63 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 64 | } |
AzureIoTClient | 0:1f9b2707ec7d | 65 | |
AzureIoTClient | 0:1f9b2707ec7d | 66 | void serializer_deinit(void) |
AzureIoTClient | 0:1f9b2707ec7d | 67 | { |
AzureIoTClient | 0:1f9b2707ec7d | 68 | /* Codes_SRS_SCHEMALIB_99_025:[ serializer_deinit shall de-initialize all modules initialized by serializer_init.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 69 | if (g_AgentState == AGENT_INITIALIZED) |
AzureIoTClient | 0:1f9b2707ec7d | 70 | { |
AzureIoTClient | 0:1f9b2707ec7d | 71 | CodeFirst_Deinit(); |
AzureIoTClient | 0:1f9b2707ec7d | 72 | } |
AzureIoTClient | 0:1f9b2707ec7d | 73 | |
AzureIoTClient | 0:1f9b2707ec7d | 74 | /* Codes_SRS_SCHEMALIB_99_026:[ A subsequent call to serializer_start shall succeed.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 75 | g_AgentState = AGENT_NOT_INITIALIZED; |
AzureIoTClient | 0:1f9b2707ec7d | 76 | } |
AzureIoTClient | 0:1f9b2707ec7d | 77 | |
AzureIoTClient | 0:1f9b2707ec7d | 78 | SERIALIZER_RESULT serializer_setconfig(SERIALIZER_CONFIG which, void* value) |
AzureIoTClient | 0:1f9b2707ec7d | 79 | { |
AzureIoTClient | 0:1f9b2707ec7d | 80 | SERIALIZER_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 81 | |
AzureIoTClient | 0:1f9b2707ec7d | 82 | /* Codes_SRS_SCHEMALIB_99_137:[ If the value argument is NULL, serializer_setconfig shall return SERIALIZER_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 83 | if (value == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 84 | { |
AzureIoTClient | 0:1f9b2707ec7d | 85 | result = SERIALIZER_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 86 | } |
AzureIoTClient | 0:1f9b2707ec7d | 87 | /* Codes_SRS_SCHEMALIB_99_142:[ When the which argument is SerializeDelayedBufferMaxSize, serializer_setconfig shall invoke DataPublisher_SetMaxBufferSize with the dereferenced value argument, and shall return SERIALIZER_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 88 | else if (which == SerializeDelayedBufferMaxSize) |
AzureIoTClient | 0:1f9b2707ec7d | 89 | { |
AzureIoTClient | 0:1f9b2707ec7d | 90 | DataPublisher_SetMaxBufferSize(*(size_t*)value); |
AzureIoTClient | 0:1f9b2707ec7d | 91 | result = SERIALIZER_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 92 | } |
AzureIoTClient | 0:1f9b2707ec7d | 93 | /* Codes_SRS_SCHEMALIB_99_138:[ If the which argument is not one of the declared members of the SERIALIZER_CONFIG enum, serializer_setconfig shall return SERIALIZER_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 94 | else |
AzureIoTClient | 0:1f9b2707ec7d | 95 | { |
AzureIoTClient | 0:1f9b2707ec7d | 96 | result = SERIALIZER_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 97 | } |
AzureIoTClient | 0:1f9b2707ec7d | 98 | |
AzureIoTClient | 0:1f9b2707ec7d | 99 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 100 | } |