Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: sht15_remote_monitoring f767zi_mqtt remote_monitoring simplesample_amqp ... more
schemalib.c
00001 // Copyright (c) Microsoft. All rights reserved. 00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information. 00003 00004 #include "azure_c_shared_utility/gballoc.h" 00005 00006 #include "schemalib.h" 00007 #include "codefirst.h" 00008 #include "schema.h" 00009 #include "datamarshaller.h" 00010 #include "datapublisher.h" 00011 #include <stddef.h> 00012 #include "azure_c_shared_utility/xlogging.h" 00013 #include "iotdevice.h" 00014 00015 #define DEFAULT_CONTAINER_NAME "Container" 00016 00017 DEFINE_ENUM_STRINGS(SERIALIZER_RESULT, SERIALIZER_RESULT_VALUES); 00018 00019 typedef enum AGENT_STATE_TAG 00020 { 00021 AGENT_NOT_INITIALIZED, 00022 AGENT_INITIALIZED 00023 } AGENT_STATE; 00024 00025 static AGENT_STATE g_AgentState = AGENT_NOT_INITIALIZED; 00026 00027 SERIALIZER_RESULT serializer_init(const char* overrideSchemaNamespace) 00028 { 00029 SERIALIZER_RESULT result; 00030 00031 /* Codes_SRS_SCHEMALIB_99_074:[serializer_init when already initialized shall return SERIALIZER_ALREADY_INIT.] */ 00032 if (g_AgentState != AGENT_NOT_INITIALIZED) 00033 { 00034 result = SERIALIZER_ALREADY_INIT; 00035 LogError("(result = %s)", ENUM_TO_STRING(SERIALIZER_RESULT, result)); 00036 } 00037 else 00038 { 00039 /* Codes_SRS_SCHEMALIB_99_006:[ Initialize CodeFirst by a call to CodeFirst_Init.] */ 00040 /* Codes_SRS_SCHEMALIB_99_076:[serializer_init shall pass the value of overrideSchemaNamespace argument to CodeFirst_Init.] */ 00041 if (CodeFirst_Init(overrideSchemaNamespace) != CODEFIRST_OK) 00042 { 00043 /* Codes_SRS_SCHEMALIB_99_007:[ On error SERIALIZER_CODEFIRST_INIT_FAILED shall be returned.] */ 00044 result = SERIALIZER_CODEFIRST_INIT_FAILED; 00045 LogError("(result = %s)", ENUM_TO_STRING(SERIALIZER_RESULT, result)); 00046 } 00047 else 00048 { 00049 /* 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.] */ 00050 g_AgentState = AGENT_INITIALIZED; 00051 00052 /* Codes_SRS_SCHEMALIB_99_073:[On success serializer_init shall return SERIALIZER_OK.] */ 00053 result = SERIALIZER_OK; 00054 } 00055 } 00056 00057 return result; 00058 } 00059 00060 void serializer_deinit(void) 00061 { 00062 /* Codes_SRS_SCHEMALIB_99_025:[ serializer_deinit shall de-initialize all modules initialized by serializer_init.] */ 00063 if (g_AgentState == AGENT_INITIALIZED) 00064 { 00065 CodeFirst_Deinit(); 00066 } 00067 00068 /* Codes_SRS_SCHEMALIB_99_026:[ A subsequent call to serializer_start shall succeed.] */ 00069 g_AgentState = AGENT_NOT_INITIALIZED; 00070 } 00071 00072 SERIALIZER_RESULT serializer_setconfig(SERIALIZER_CONFIG which, void* value) 00073 { 00074 SERIALIZER_RESULT result; 00075 00076 /* Codes_SRS_SCHEMALIB_99_137:[ If the value argument is NULL, serializer_setconfig shall return SERIALIZER_INVALID_ARG.] */ 00077 if (value == NULL) 00078 { 00079 result = SERIALIZER_INVALID_ARG; 00080 } 00081 /* 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.] */ 00082 else if (which == SerializeDelayedBufferMaxSize) 00083 { 00084 DataPublisher_SetMaxBufferSize(*(size_t*)value); 00085 result = SERIALIZER_OK; 00086 } 00087 /* 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.] */ 00088 else 00089 { 00090 result = SERIALIZER_INVALID_ARG; 00091 } 00092 00093 return result; 00094 }
Generated on Tue Jul 12 2022 19:56:37 by
