A modelling and serializer library for Microsoft Azure IoTHub client applications

Dependents:   sht15_remote_monitoring f767zi_mqtt remote_monitoring simplesample_amqp ... more

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

Committer:
AzureIoTClient
Date:
Tue Sep 22 20:36:53 2015 -0700
Revision:
2:d9c585174187
Parent:
0:1f9b2707ec7d
New release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 0:1f9b2707ec7d 1 // Copyright (c) Microsoft. All rights reserved.
AzureIoTClient 0:1f9b2707ec7d 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
AzureIoTClient 0:1f9b2707ec7d 3
AzureIoTClient 2:d9c585174187 4 /** @file serializer.h
AzureIoTClient 2:d9c585174187 5 * @brief The IoT Hub Serializer APIs allows developers to define models for
AzureIoTClient 2:d9c585174187 6 * their devices
AzureIoTClient 2:d9c585174187 7 *
AzureIoTClient 2:d9c585174187 8 * @details The IoT Hub Serializer APIs allows developers to quickly and easily define
AzureIoTClient 2:d9c585174187 9 * models for their devices directly as code, while supporting the required
AzureIoTClient 2:d9c585174187 10 * features for modeling devices (including multiple models and multiple
AzureIoTClient 2:d9c585174187 11 * devices within the same application). For example:
AzureIoTClient 2:d9c585174187 12 *
AzureIoTClient 2:d9c585174187 13 * <pre>
AzureIoTClient 2:d9c585174187 14 * BEGIN_NAMESPACE(Contoso);
AzureIoTClient 2:d9c585174187 15 *
AzureIoTClient 2:d9c585174187 16 * DECLARE_STRUCT(SystemProperties,
AzureIoTClient 2:d9c585174187 17 * ascii_char_ptr, DeviceID,
AzureIoTClient 2:d9c585174187 18 * _Bool, Enabled
AzureIoTClient 2:d9c585174187 19 * );
AzureIoTClient 2:d9c585174187 20 *
AzureIoTClient 2:d9c585174187 21 * DECLARE_MODEL(VendingMachine,
AzureIoTClient 2:d9c585174187 22 *
AzureIoTClient 2:d9c585174187 23 * WITH_DATA(int, SensorValue),
AzureIoTClient 2:d9c585174187 24 *
AzureIoTClient 2:d9c585174187 25 * WITH_DATA(ascii_char_ptr, ObjectName),
AzureIoTClient 2:d9c585174187 26 * WITH_DATA(ascii_char_ptr, ObjectType),
AzureIoTClient 2:d9c585174187 27 * WITH_DATA(ascii_char_ptr, Version),
AzureIoTClient 2:d9c585174187 28 * WITH_DATA(SystemProperties, SystemProperties),
AzureIoTClient 2:d9c585174187 29 * WITH_DATA(ascii_char_ptr_no_quotes, Commands),
AzureIoTClient 2:d9c585174187 30 *
AzureIoTClient 2:d9c585174187 31 * WITH_ACTION(SetItemPrice, ascii_char_ptr, itemId, ascii_char_ptr, price)
AzureIoTClient 2:d9c585174187 32 * );
AzureIoTClient 2:d9c585174187 33 *
AzureIoTClient 2:d9c585174187 34 * END_NAMESPACE(Contoso);
AzureIoTClient 2:d9c585174187 35 * </pre>
AzureIoTClient 2:d9c585174187 36 */
AzureIoTClient 2:d9c585174187 37
AzureIoTClient 0:1f9b2707ec7d 38 #ifndef SERIALIZER_H
AzureIoTClient 0:1f9b2707ec7d 39 #define SERIALIZER_H
AzureIoTClient 0:1f9b2707ec7d 40
AzureIoTClient 0:1f9b2707ec7d 41 #ifdef __cplusplus
AzureIoTClient 0:1f9b2707ec7d 42 #include <cstdlib>
AzureIoTClient 0:1f9b2707ec7d 43 #include <cstdarg>
AzureIoTClient 0:1f9b2707ec7d 44
AzureIoTClient 0:1f9b2707ec7d 45 #else
AzureIoTClient 0:1f9b2707ec7d 46 #include <stdlib.h>
AzureIoTClient 0:1f9b2707ec7d 47 #include <stdarg.h>
AzureIoTClient 0:1f9b2707ec7d 48 #endif
AzureIoTClient 0:1f9b2707ec7d 49
AzureIoTClient 0:1f9b2707ec7d 50 #ifdef _CRTDBG_MAP_ALLOC
AzureIoTClient 0:1f9b2707ec7d 51 #include <crtdbg.h>
AzureIoTClient 0:1f9b2707ec7d 52 #endif
AzureIoTClient 0:1f9b2707ec7d 53
AzureIoTClient 0:1f9b2707ec7d 54 #include "gballoc.h"
AzureIoTClient 0:1f9b2707ec7d 55 #include "macro_utils.h"
AzureIoTClient 0:1f9b2707ec7d 56 #include "iotdevice.h"
AzureIoTClient 0:1f9b2707ec7d 57 #include "crt_abstractions.h"
AzureIoTClient 0:1f9b2707ec7d 58 #include "iot_logging.h"
AzureIoTClient 0:1f9b2707ec7d 59 #include "schemalib.h"
AzureIoTClient 0:1f9b2707ec7d 60 #include "codefirst.h"
AzureIoTClient 0:1f9b2707ec7d 61 #include "agenttypesystem.h"
AzureIoTClient 0:1f9b2707ec7d 62 #include "schema.h"
AzureIoTClient 0:1f9b2707ec7d 63
AzureIoTClient 0:1f9b2707ec7d 64
AzureIoTClient 0:1f9b2707ec7d 65 #ifdef __cplusplus
AzureIoTClient 0:1f9b2707ec7d 66 extern "C"
AzureIoTClient 0:1f9b2707ec7d 67 {
AzureIoTClient 0:1f9b2707ec7d 68 #endif
AzureIoTClient 0:1f9b2707ec7d 69
AzureIoTClient 0:1f9b2707ec7d 70 #define IOT_AGENT_RESULT_ENUM_VALUES \
AzureIoTClient 0:1f9b2707ec7d 71 IOT_AGENT_OK, \
AzureIoTClient 0:1f9b2707ec7d 72 IOT_AGENT_AGENT_DATA_TYPES_ERROR, \
AzureIoTClient 0:1f9b2707ec7d 73 IOT_AGENT_COMMAND_EXECUTION_ERROR, \
AzureIoTClient 0:1f9b2707ec7d 74 IOT_AGENT_ERROR, \
AzureIoTClient 0:1f9b2707ec7d 75 IOT_AGENT_SERIALIZE_FAILED, \
AzureIoTClient 0:1f9b2707ec7d 76 IOT_AGENT_INVALID_ARG
AzureIoTClient 0:1f9b2707ec7d 77
AzureIoTClient 0:1f9b2707ec7d 78 DEFINE_ENUM(IOT_AGENT_RESULT, IOT_AGENT_RESULT_ENUM_VALUES);
AzureIoTClient 0:1f9b2707ec7d 79
AzureIoTClient 0:1f9b2707ec7d 80
AzureIoTClient 0:1f9b2707ec7d 81 /* IOT Agent Macros */
AzureIoTClient 0:1f9b2707ec7d 82
AzureIoTClient 2:d9c585174187 83 /**
AzureIoTClient 2:d9c585174187 84 * @def BEGIN_NAMESPACE(schemaNamespace)
AzureIoTClient 2:d9c585174187 85 * This macro marks the start of a section that declares IOT model
AzureIoTClient 2:d9c585174187 86 * elements (like complex types, etc.). Declarations are typically
AzureIoTClient 2:d9c585174187 87 * placed in header files, so that they can be shared between
AzureIoTClient 2:d9c585174187 88 * translation units.
AzureIoTClient 2:d9c585174187 89 */
AzureIoTClient 0:1f9b2707ec7d 90 /* Codes_SRS_SERIALIZER_99_001:[For each completed schema declaration block, a unique storage container for schema metadata shall be available in the translation unit at runtime.] */
AzureIoTClient 0:1f9b2707ec7d 91 #define BEGIN_NAMESPACE(schemaNamespace) \
AzureIoTClient 0:1f9b2707ec7d 92 REFLECTED_END_OF_LIST
AzureIoTClient 0:1f9b2707ec7d 93
AzureIoTClient 2:d9c585174187 94 /**
AzureIoTClient 2:d9c585174187 95 * @def END_NAMESPACE(schemaNamespace)
AzureIoTClient 2:d9c585174187 96 * This macro marks the end of a section that declares IOT model
AzureIoTClient 2:d9c585174187 97 * elements.
AzureIoTClient 2:d9c585174187 98 */
AzureIoTClient 0:1f9b2707ec7d 99 #define END_NAMESPACE(schemaNamespace) \
AzureIoTClient 0:1f9b2707ec7d 100 REFLECTED_LIST_HEAD(schemaNamespace)
AzureIoTClient 0:1f9b2707ec7d 101
AzureIoTClient 2:d9c585174187 102 /**
AzureIoTClient 2:d9c585174187 103 * @def DECLARE_STRUCT(name, ...)
AzureIoTClient 2:d9c585174187 104 * This macro allows the definition of a struct type that can then be used as
AzureIoTClient 2:d9c585174187 105 * part of a model definition.
AzureIoTClient 2:d9c585174187 106 *
AzureIoTClient 2:d9c585174187 107 * @param name Name of the struct
AzureIoTClient 2:d9c585174187 108 * @param element1, element2... Specifies a list of struct members
AzureIoTClient 2:d9c585174187 109 */
AzureIoTClient 0:1f9b2707ec7d 110 /* Codes_SRS_SERIALIZER_99_080:[ The DECLARE_STRUCT declaration shall insert metadata describing a complex data type.] */
AzureIoTClient 0:1f9b2707ec7d 111 #define DECLARE_STRUCT(name, ...) \
AzureIoTClient 0:1f9b2707ec7d 112 /* Codes_SRS_SERIALIZER_99_096:[ DECLARE_STRUCT shall declare a matching C struct data type named name, which can be referenced from any code that can access the declaration.] */ \
AzureIoTClient 0:1f9b2707ec7d 113 typedef struct name##_TAG { \
AzureIoTClient 0:1f9b2707ec7d 114 FOR_EACH_2(INSERT_FIELD_INTO_STRUCT, __VA_ARGS__) \
AzureIoTClient 0:1f9b2707ec7d 115 } name; \
AzureIoTClient 0:1f9b2707ec7d 116 /* Codes_SRS_SERIALIZER_99_081:[ DECLARE_STRUCT's name argument shall uniquely identify the struct within the schema.] */ \
AzureIoTClient 0:1f9b2707ec7d 117 REFLECTED_STRUCT(name) \
AzureIoTClient 0:1f9b2707ec7d 118 /* Codes_SRS_SERIALIZER_99_082:[ DECLARE_STRUCT's field<n>Name argument shall uniquely name a field within the struct.] */ \
AzureIoTClient 0:1f9b2707ec7d 119 FOR_EACH_2_KEEP_1(REFLECTED_FIELD, name, __VA_ARGS__) \
AzureIoTClient 0:1f9b2707ec7d 120 TO_AGENT_DATA_TYPE(name, __VA_ARGS__) \
AzureIoTClient 0:1f9b2707ec7d 121 /*Codes_SRS_SERIALIZER_99_042:[ The parameter types are either predefined parameter types (specs SRS_SERIALIZER_99_004-SRS_SERIALIZER_99_014) or a type introduced by DECLARE_STRUCT.]*/ \
AzureIoTClient 0:1f9b2707ec7d 122 static AGENT_DATA_TYPES_RESULT FromAGENT_DATA_TYPE_##name(const AGENT_DATA_TYPE* source, name* destination) \
AzureIoTClient 0:1f9b2707ec7d 123 { \
AzureIoTClient 0:1f9b2707ec7d 124 AGENT_DATA_TYPES_RESULT result; \
AzureIoTClient 0:1f9b2707ec7d 125 if(source->type != EDM_COMPLEX_TYPE_TYPE) \
AzureIoTClient 0:1f9b2707ec7d 126 { \
AzureIoTClient 0:1f9b2707ec7d 127 result = AGENT_DATA_TYPES_INVALID_ARG; \
AzureIoTClient 0:1f9b2707ec7d 128 } \
AzureIoTClient 0:1f9b2707ec7d 129 else if(DIV2(COUNT_ARG(__VA_ARGS__)) != source->value.edmComplexType.nMembers) \
AzureIoTClient 0:1f9b2707ec7d 130 { \
AzureIoTClient 0:1f9b2707ec7d 131 /*too many or too few fields*/ \
AzureIoTClient 0:1f9b2707ec7d 132 result = AGENT_DATA_TYPES_INVALID_ARG; \
AzureIoTClient 0:1f9b2707ec7d 133 } \
AzureIoTClient 0:1f9b2707ec7d 134 else \
AzureIoTClient 0:1f9b2707ec7d 135 { \
AzureIoTClient 0:1f9b2707ec7d 136 result = AGENT_DATA_TYPES_OK; \
AzureIoTClient 0:1f9b2707ec7d 137 FOR_EACH_2(BUILD_DESTINATION_FIELD, __VA_ARGS__); \
AzureIoTClient 0:1f9b2707ec7d 138 } \
AzureIoTClient 0:1f9b2707ec7d 139 return result; \
AzureIoTClient 0:1f9b2707ec7d 140 } \
AzureIoTClient 0:1f9b2707ec7d 141 static void C2(destroyLocalParameter, name)(name * value) \
AzureIoTClient 0:1f9b2707ec7d 142 { \
AzureIoTClient 0:1f9b2707ec7d 143 FOR_EACH_2_KEEP_1(UNBUILD_DESTINATION_FIELD, value, __VA_ARGS__); \
AzureIoTClient 0:1f9b2707ec7d 144 }
AzureIoTClient 0:1f9b2707ec7d 145
AzureIoTClient 2:d9c585174187 146 /**
AzureIoTClient 2:d9c585174187 147 * @def DECLARE_MODEL(name, ...)
AzureIoTClient 2:d9c585174187 148 * This macro allows declaring a model that can be later used to instantiate
AzureIoTClient 2:d9c585174187 149 * a device.
AzureIoTClient 2:d9c585174187 150 *
AzureIoTClient 2:d9c585174187 151 * @param name Specifies the model name
AzureIoTClient 2:d9c585174187 152 * @param element1, element2... Specifies a model element which can be
AzureIoTClient 2:d9c585174187 153 * a property or an action.
AzureIoTClient 2:d9c585174187 154 * - A property is described in a
AzureIoTClient 2:d9c585174187 155 * model by using the WITH_DATA
AzureIoTClient 2:d9c585174187 156 * - An action is described in a
AzureIoTClient 2:d9c585174187 157 * model by using the ::WITH_ACTION
AzureIoTClient 2:d9c585174187 158 * macro.
AzureIoTClient 2:d9c585174187 159 *
AzureIoTClient 2:d9c585174187 160 */
AzureIoTClient 0:1f9b2707ec7d 161 /* WITH_DATA's name argument shall be one of the following data types: */
AzureIoTClient 0:1f9b2707ec7d 162 /* Codes_SRS_SERIALIZER_99_133:[a model type introduced previously by DECLARE_MODEL] */
AzureIoTClient 0:1f9b2707ec7d 163 #define DECLARE_MODEL(name, ...) \
AzureIoTClient 0:1f9b2707ec7d 164 REFLECTED_MODEL(name) \
AzureIoTClient 0:1f9b2707ec7d 165 typedef struct name { int :1; FOR_EACH_1(BUILD_MODEL_STRUCT, __VA_ARGS__) } name; \
AzureIoTClient 0:1f9b2707ec7d 166 FOR_EACH_1_KEEP_1(CREATE_MODEL_ELEMENT, name, __VA_ARGS__) \
AzureIoTClient 0:1f9b2707ec7d 167 TO_AGENT_DATA_TYPE(name, DROP_FIRST_COMMA_FROM_ARGS(EXPAND_MODEL_ARGS(__VA_ARGS__)))
AzureIoTClient 0:1f9b2707ec7d 168
AzureIoTClient 2:d9c585174187 169 /**
AzureIoTClient 2:d9c585174187 170 * @def WITH_DATA(type, name)
AzureIoTClient 2:d9c585174187 171 * The ::WITH_DATA macro allows declaring a model property in a model. A
AzureIoTClient 2:d9c585174187 172 * property can be published by using the ::SERIALIZE macro.
AzureIoTClient 2:d9c585174187 173 *
AzureIoTClient 2:d9c585174187 174 * @param type Specifies the property type. Can be any of the following
AzureIoTClient 2:d9c585174187 175 * types:
AzureIoTClient 2:d9c585174187 176 * - int
AzureIoTClient 2:d9c585174187 177 * - double
AzureIoTClient 2:d9c585174187 178 * - float
AzureIoTClient 2:d9c585174187 179 * - long
AzureIoTClient 2:d9c585174187 180 * - int8_t
AzureIoTClient 2:d9c585174187 181 * - uint8_t
AzureIoTClient 2:d9c585174187 182 * - int16_t
AzureIoTClient 2:d9c585174187 183 * - int32_t
AzureIoTClient 2:d9c585174187 184 * - int64_t
AzureIoTClient 2:d9c585174187 185 * - bool
AzureIoTClient 2:d9c585174187 186 * - ascii_char_ptr
AzureIoTClient 2:d9c585174187 187 * - EDM_DATE_TIME_OFFSET
AzureIoTClient 2:d9c585174187 188 * - EDM_GUID
AzureIoTClient 2:d9c585174187 189 * - EDM_BINARY
AzureIoTClient 2:d9c585174187 190 * - Any struct type previously introduced by another ::DECLARE_STRUCT.
AzureIoTClient 2:d9c585174187 191 *
AzureIoTClient 2:d9c585174187 192 * @param name Specifies the property name
AzureIoTClient 2:d9c585174187 193 */
AzureIoTClient 0:1f9b2707ec7d 194 #define WITH_DATA(type, name) MODEL_PROPERTY(type, name)
AzureIoTClient 0:1f9b2707ec7d 195
AzureIoTClient 2:d9c585174187 196 /**
AzureIoTClient 2:d9c585174187 197 * @def WITH_ACTION(name, ...)
AzureIoTClient 2:d9c585174187 198 * The ::WITH_ACTION macro allows declaring a model action.
AzureIoTClient 2:d9c585174187 199 *
AzureIoTClient 2:d9c585174187 200 * @param name Specifies the action name.
AzureIoTClient 2:d9c585174187 201 * @param argXtype, argXName... Defines the type and name for the X<sup>th</sup>
AzureIoTClient 2:d9c585174187 202 * argument of the action. The type can be any of
AzureIoTClient 2:d9c585174187 203 * the primitive types or a struct type.
AzureIoTClient 2:d9c585174187 204 */
AzureIoTClient 0:1f9b2707ec7d 205 /*Codes_SRS_SERIALIZER_99_039:[WITH_ACTION shall declare an action of the current data provider called as the first macro parameter(name) and having the first parameter called parameter1Name of type parameter1Type, the second parameter named parameter2Name having the type parameter2Type and so on.]*/
AzureIoTClient 0:1f9b2707ec7d 206 #define WITH_ACTION(name, ...) MODEL_ACTION(name, __VA_ARGS__)
AzureIoTClient 0:1f9b2707ec7d 207
AzureIoTClient 2:d9c585174187 208 /**
AzureIoTClient 2:d9c585174187 209 * @def GET_MODEL_HANDLE(schemaNamespace, modelName)
AzureIoTClient 2:d9c585174187 210 * The ::GET_MODEL_HANDLE macro returns a model handle that can be used in
AzureIoTClient 2:d9c585174187 211 * subsequent operations like generating the CSDL schema for the model,
AzureIoTClient 2:d9c585174187 212 * uploading the schema, creating a device, etc.
AzureIoTClient 2:d9c585174187 213 *
AzureIoTClient 2:d9c585174187 214 * @param schemaNamespace The namespace to which the model belongs.
AzureIoTClient 2:d9c585174187 215 * @param modelName The name of the model.
AzureIoTClient 2:d9c585174187 216 */
AzureIoTClient 0:1f9b2707ec7d 217 /* Codes_SRS_SERIALIZER_99_110:[ The GET_MODEL_HANDLE function macro shall first register the schema by calling CodeFirst_RegisterSchema, passing schemaNamespace and a pointer to the metadata generated in the schema declaration block.] */
AzureIoTClient 0:1f9b2707ec7d 218 /* Codes_SRS_SERIALIZER_99_094:[ GET_MODEL_HANDLE shall then call Schema_GetModelByName, passing the schemaHandle obtained from CodeFirst_RegisterSchema and modelName arguments, to retrieve the SCHEMA_MODEL_TYPE_HANDLE corresponding to the modelName argument.] */
AzureIoTClient 0:1f9b2707ec7d 219 /* Codes_SRS_SERIALIZER_99_112:[ GET_MODEL_HANDLE will return the handle for the named model.] */
AzureIoTClient 0:1f9b2707ec7d 220 #define GET_MODEL_HANDLE(schemaNamespace, modelName) \
AzureIoTClient 0:1f9b2707ec7d 221 Schema_GetModelByName(CodeFirst_RegisterSchema(TOSTRING(schemaNamespace), &ALL_REFLECTED(schemaNamespace)), #modelName)
AzureIoTClient 0:1f9b2707ec7d 222
AzureIoTClient 0:1f9b2707ec7d 223 /* Codes_SRS_SERIALIZER_01_002: [If the argument serializerIncludePropertyPath is specified, its value shall be passed to CodeFirst_Create.] */
AzureIoTClient 0:1f9b2707ec7d 224 #define CREATE_DEVICE_WITH_INCLUDE_PROPERTY_PATH(schemaNamespace, modelName, serializerIncludePropertyPath) \
AzureIoTClient 0:1f9b2707ec7d 225 (modelName*)CodeFirst_CreateDevice(GET_MODEL_HANDLE(schemaNamespace, modelName), &ALL_REFLECTED(schemaNamespace), sizeof(modelName), serializerIncludePropertyPath)
AzureIoTClient 0:1f9b2707ec7d 226
AzureIoTClient 0:1f9b2707ec7d 227 /* Codes_SRS_SERIALIZER_01_003: [If the argument serializerIncludePropertyPath is not specified, CREATE_MODEL_INSTANCE shall pass false to CodeFirst_Create.] */
AzureIoTClient 0:1f9b2707ec7d 228 #define CREATE_DEVICE_WITHOUT_INCLUDE_PROPERTY_PATH(schemaNamespace, modelName) \
AzureIoTClient 0:1f9b2707ec7d 229 (modelName*)CodeFirst_CreateDevice(GET_MODEL_HANDLE(schemaNamespace, modelName), &ALL_REFLECTED(schemaNamespace), sizeof(modelName), false)
AzureIoTClient 0:1f9b2707ec7d 230
AzureIoTClient 0:1f9b2707ec7d 231 /* Codes_SRS_SERIALIZER_99_104:[ CREATE_MODEL_INSTANCE shall call GET_MODEL_HANDLE, passing schemaNamespace and modelName, to get a model handle representing the model defined in the corresponding schema declaration block.] */
AzureIoTClient 0:1f9b2707ec7d 232 /* Codes_SRS_SERIALIZER_99_106:[ CREATE_MODEL_INSTANCE shall call CodeFirst_CreateDevice, passing the model handle (SCHEMA_MODEL_TYPE_HANDLE]*/
AzureIoTClient 0:1f9b2707ec7d 233 /* Codes_SRS_SERIALIZER_99_107:[ If CodeFirst_CreateDevice fails, CREATE_MODEL_INSTANCE shall return NULL.] */
AzureIoTClient 0:1f9b2707ec7d 234 /* Codes_SRS_SERIALIZER_99_108:[ If CodeFirst_CreateDevice succeeds, CREATE_MODEL_INSTANCE shall return a pointer to an instance of the C struct representing the model for the device.] */
AzureIoTClient 0:1f9b2707ec7d 235 #define CREATE_MODEL_INSTANCE(schemaNamespace, ...) \
AzureIoTClient 0:1f9b2707ec7d 236 IF(DIV2(COUNT_ARG(__VA_ARGS__)), CREATE_DEVICE_WITH_INCLUDE_PROPERTY_PATH, CREATE_DEVICE_WITHOUT_INCLUDE_PROPERTY_PATH) (schemaNamespace, __VA_ARGS__)
AzureIoTClient 0:1f9b2707ec7d 237
AzureIoTClient 0:1f9b2707ec7d 238 /* Codes_SRS_SERIALIZER_99_109:[ DESTROY_MODEL_INSTANCE shall call CodeFirst_DestroyDevice, passing the pointer returned from CREATE_MODEL_INSTANCE, to release all resources associated with the device.] */
AzureIoTClient 0:1f9b2707ec7d 239 #define DESTROY_MODEL_INSTANCE(deviceData) \
AzureIoTClient 0:1f9b2707ec7d 240 CodeFirst_DestroyDevice(deviceData)
AzureIoTClient 0:1f9b2707ec7d 241
AzureIoTClient 2:d9c585174187 242 /**
AzureIoTClient 2:d9c585174187 243 * @def SERIALIZE(destination, destinationSize,...)
AzureIoTClient 2:d9c585174187 244 * This macro produces JSON serialized representation of the properties.
AzureIoTClient 2:d9c585174187 245 *
AzureIoTClient 2:d9c585174187 246 * @param destination Pointer to an @c unsigned @c char* that
AzureIoTClient 2:d9c585174187 247 * will receive the serialized data.
AzureIoTClient 2:d9c585174187 248 * @param destinationSize Pointer to a @c size_t that gets
AzureIoTClient 2:d9c585174187 249 * written with the size in bytes of the
AzureIoTClient 2:d9c585174187 250 * serialized data
AzureIoTClient 2:d9c585174187 251 * @param property1, property2... A list of property values to send. The
AzureIoTClient 2:d9c585174187 252 * order in which the properties appear in
AzureIoTClient 2:d9c585174187 253 * the list does not matter, all values
AzureIoTClient 2:d9c585174187 254 * will be sent together.
AzureIoTClient 2:d9c585174187 255 *
AzureIoTClient 2:d9c585174187 256 */
AzureIoTClient 0:1f9b2707ec7d 257 /*Codes_SRS_SERIALIZER_99_113:[ SERIALIZE shall call CodeFirst_SendAsync, passing a destination, destinationSize, the number of properties to publish, and pointers to the values for each property.] */
AzureIoTClient 0:1f9b2707ec7d 258 /*Codes_SRS_SERIALIZER_99_117:[ If CodeFirst_SendAsync succeeds, SEND will return IOT_AGENT_OK.] */
AzureIoTClient 0:1f9b2707ec7d 259 /*Codes_SRS_SERIALIZER_99_114:[ If CodeFirst_SendAsync fails, SEND shall return IOT_AGENT_SERIALIZE_FAILED.] */
AzureIoTClient 0:1f9b2707ec7d 260 #define SERIALIZE(destination, destinationSize,...) ((CodeFirst_SendAsync(destination, destinationSize, COUNT_ARG(__VA_ARGS__) FOR_EACH_1(ADDRESS_MACRO, __VA_ARGS__)) == CODEFIRST_OK) ? IOT_AGENT_OK : IOT_AGENT_SERIALIZE_FAILED)
AzureIoTClient 0:1f9b2707ec7d 261
AzureIoTClient 2:d9c585174187 262 /**
AzureIoTClient 2:d9c585174187 263 * @def EXECUTE_COMMAND(device, command)
AzureIoTClient 2:d9c585174187 264 * Any action that is declared in a model must also have an implementation as
AzureIoTClient 2:d9c585174187 265 * a C function.
AzureIoTClient 2:d9c585174187 266 *
AzureIoTClient 2:d9c585174187 267 * @param device Pointer to device data.
AzureIoTClient 2:d9c585174187 268 * @param command Values that match the arguments declared in the model
AzureIoTClient 2:d9c585174187 269 * action.
AzureIoTClient 2:d9c585174187 270 */
AzureIoTClient 0:1f9b2707ec7d 271 /*Codes_SRS_SERIALIZER_02_018: [EXECUTE_COMMAND macro shall call CodeFirst_ExecuteCommand passing device, commandBuffer and commandBufferSize.]*/
AzureIoTClient 0:1f9b2707ec7d 272 #define EXECUTE_COMMAND(device, command) (CodeFirst_ExecuteCommand(device, command))
AzureIoTClient 0:1f9b2707ec7d 273
AzureIoTClient 0:1f9b2707ec7d 274 /* Helper macros */
AzureIoTClient 0:1f9b2707ec7d 275
AzureIoTClient 0:1f9b2707ec7d 276 /* These macros remove a useless comma from the beginning of an argument list that looks like:
AzureIoTClient 0:1f9b2707ec7d 277 ,x1,y1,x2,y2 */
AzureIoTClient 0:1f9b2707ec7d 278 #ifdef _MSC_VER
AzureIoTClient 0:1f9b2707ec7d 279
AzureIoTClient 0:1f9b2707ec7d 280 #define DROP_FIRST_COMMA(N, x) \
AzureIoTClient 0:1f9b2707ec7d 281 x IFCOMMA_NOFIRST(N)
AzureIoTClient 0:1f9b2707ec7d 282
AzureIoTClient 0:1f9b2707ec7d 283 #define DROP_IF_EMPTY(N, x) \
AzureIoTClient 0:1f9b2707ec7d 284 IF(COUNT_ARG(x),DROP_FIRST_COMMA(N,x),x)
AzureIoTClient 0:1f9b2707ec7d 285
AzureIoTClient 0:1f9b2707ec7d 286 #define DROP_FIRST_COMMA_FROM_ARGS(...) \
AzureIoTClient 0:1f9b2707ec7d 287 FOR_EACH_1_COUNTED(DROP_IF_EMPTY, C1(__VA_ARGS__))
AzureIoTClient 0:1f9b2707ec7d 288
AzureIoTClient 0:1f9b2707ec7d 289 #else
AzureIoTClient 0:1f9b2707ec7d 290
AzureIoTClient 0:1f9b2707ec7d 291 #define DROP_FIRST_COMMA_0(N, x) \
AzureIoTClient 0:1f9b2707ec7d 292 x IFCOMMA_NOFIRST(N)
AzureIoTClient 0:1f9b2707ec7d 293
AzureIoTClient 0:1f9b2707ec7d 294 #define DROP_FIRST_COMMA_1(N, x) \
AzureIoTClient 0:1f9b2707ec7d 295 x
AzureIoTClient 0:1f9b2707ec7d 296
AzureIoTClient 0:1f9b2707ec7d 297 #define DROP_FIRST_COMMA(empty, N, x) \
AzureIoTClient 0:1f9b2707ec7d 298 C2(DROP_FIRST_COMMA_,empty)(N,x)
AzureIoTClient 0:1f9b2707ec7d 299
AzureIoTClient 0:1f9b2707ec7d 300 #define DROP_IF_EMPTY(N, x) \
AzureIoTClient 0:1f9b2707ec7d 301 DROP_FIRST_COMMA(ISEMPTY(x),N,x)
AzureIoTClient 0:1f9b2707ec7d 302
AzureIoTClient 0:1f9b2707ec7d 303 #define DROP_FIRST_COMMA_FROM_ARGS(...) \
AzureIoTClient 0:1f9b2707ec7d 304 FOR_EACH_1_COUNTED(DROP_IF_EMPTY, __VA_ARGS__)
AzureIoTClient 0:1f9b2707ec7d 305
AzureIoTClient 0:1f9b2707ec7d 306 #endif
AzureIoTClient 0:1f9b2707ec7d 307
AzureIoTClient 0:1f9b2707ec7d 308 /* These macros expand a sequence of arguments for DECLARE_MODEL that looks like
AzureIoTClient 0:1f9b2707ec7d 309 WITH_DATA(x, y), WITH_DATA(x2, y2) to a list of arguments consumed by the macro that marshalls a struct, like:
AzureIoTClient 0:1f9b2707ec7d 310 x, y, x2, y2
AzureIoTClient 0:1f9b2707ec7d 311 Actions are discarded, since no marshalling will be done for those when sending state data */
AzureIoTClient 0:1f9b2707ec7d 312 #define TO_AGENT_DT_EXPAND_MODEL_PROPERTY(x, y) ,x,y
AzureIoTClient 0:1f9b2707ec7d 313 #define TO_AGENT_DT_EXPAND_MODEL_ACTION(...)
AzureIoTClient 0:1f9b2707ec7d 314
AzureIoTClient 0:1f9b2707ec7d 315 #define TO_AGENT_DT_EXPAND_ELEMENT_ARGS(N, ...) TO_AGENT_DT_EXPAND_##__VA_ARGS__
AzureIoTClient 0:1f9b2707ec7d 316
AzureIoTClient 0:1f9b2707ec7d 317 #define EXPAND_MODEL_ARGS(...) \
AzureIoTClient 0:1f9b2707ec7d 318 FOR_EACH_1_COUNTED(TO_AGENT_DT_EXPAND_ELEMENT_ARGS, __VA_ARGS__)
AzureIoTClient 0:1f9b2707ec7d 319
AzureIoTClient 0:1f9b2707ec7d 320 #define TO_AGENT_DATA_TYPE(name, ...) \
AzureIoTClient 0:1f9b2707ec7d 321 static AGENT_DATA_TYPES_RESULT ToAGENT_DATA_TYPE_##name(AGENT_DATA_TYPE *destination, const name value) \
AzureIoTClient 0:1f9b2707ec7d 322 { \
AzureIoTClient 0:1f9b2707ec7d 323 AGENT_DATA_TYPES_RESULT result = AGENT_DATA_TYPES_OK; \
AzureIoTClient 0:1f9b2707ec7d 324 size_t iMember = 0; \
AzureIoTClient 0:1f9b2707ec7d 325 DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(phantomName, 1); \
AzureIoTClient 0:1f9b2707ec7d 326 const char* memberNames[IF(DIV2(C1(COUNT_ARG(__VA_ARGS__))), DIV2(C1(COUNT_ARG(__VA_ARGS__))), 1)] = { 0 }; \
AzureIoTClient 0:1f9b2707ec7d 327 size_t memberCount = sizeof(memberNames) / sizeof(memberNames[0]); \
AzureIoTClient 0:1f9b2707ec7d 328 (void)value; \
AzureIoTClient 0:1f9b2707ec7d 329 if (memberCount == 0) \
AzureIoTClient 0:1f9b2707ec7d 330 { \
AzureIoTClient 0:1f9b2707ec7d 331 result = AGENT_DATA_TYPES_OK; \
AzureIoTClient 0:1f9b2707ec7d 332 } \
AzureIoTClient 0:1f9b2707ec7d 333 else \
AzureIoTClient 0:1f9b2707ec7d 334 { \
AzureIoTClient 0:1f9b2707ec7d 335 AGENT_DATA_TYPE members[sizeof(memberNames) / sizeof(memberNames[0])]; \
AzureIoTClient 0:1f9b2707ec7d 336 DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(phantomName, 2); \
AzureIoTClient 0:1f9b2707ec7d 337 FOR_EACH_2(FIELD_AS_STRING, EXPAND_TWICE(__VA_ARGS__)) \
AzureIoTClient 0:1f9b2707ec7d 338 iMember = 0; \
AzureIoTClient 0:1f9b2707ec7d 339 INSTRUCTION_THAT_CAN_SUSTAIN_A_COMMA_STEAL; \
AzureIoTClient 0:1f9b2707ec7d 340 FOR_EACH_2(CREATE_AGENT_DATA_TYPE, EXPAND_TWICE(__VA_ARGS__)) \
AzureIoTClient 0:1f9b2707ec7d 341 INSTRUCTION_THAT_CAN_SUSTAIN_A_COMMA_STEAL; \
AzureIoTClient 0:1f9b2707ec7d 342 result = ((result == AGENT_DATA_TYPES_OK) && (Create_AGENT_DATA_TYPE_from_Members(destination, #name, sizeof(memberNames) / sizeof(memberNames[0]), memberNames, members) == AGENT_DATA_TYPES_OK)) \
AzureIoTClient 0:1f9b2707ec7d 343 ? AGENT_DATA_TYPES_OK \
AzureIoTClient 0:1f9b2707ec7d 344 : AGENT_DATA_TYPES_ERROR; \
AzureIoTClient 0:1f9b2707ec7d 345 { \
AzureIoTClient 0:1f9b2707ec7d 346 size_t jMember; \
AzureIoTClient 0:1f9b2707ec7d 347 for (jMember = 0; jMember < iMember; jMember++) \
AzureIoTClient 0:1f9b2707ec7d 348 { \
AzureIoTClient 0:1f9b2707ec7d 349 Destroy_AGENT_DATA_TYPE(&members[jMember]); \
AzureIoTClient 0:1f9b2707ec7d 350 } \
AzureIoTClient 0:1f9b2707ec7d 351 } \
AzureIoTClient 0:1f9b2707ec7d 352 } \
AzureIoTClient 0:1f9b2707ec7d 353 return result; \
AzureIoTClient 0:1f9b2707ec7d 354 }
AzureIoTClient 0:1f9b2707ec7d 355
AzureIoTClient 0:1f9b2707ec7d 356 #define FIELD_AS_STRING(x,y) memberNames[iMember++] = #y;
AzureIoTClient 0:1f9b2707ec7d 357
AzureIoTClient 0:1f9b2707ec7d 358 #define REFLECTED_LIST_HEAD(name) \
AzureIoTClient 0:1f9b2707ec7d 359 static const REFLECTED_DATA_FROM_DATAPROVIDER ALL_REFLECTED(name) = { &C2(REFLECTED_, C1(DEC(__COUNTER__))) };
AzureIoTClient 0:1f9b2707ec7d 360 #define REFLECTED_STRUCT(name) \
AzureIoTClient 0:1f9b2707ec7d 361 static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(__COUNTER__))) = { REFLECTION_STRUCT_TYPE, &C2(REFLECTED_, C1(DEC(DEC(__COUNTER__)))), { {TOSTRING(name)}, {0}, {0}, {0}, {0}} };
AzureIoTClient 0:1f9b2707ec7d 362 #define REFLECTED_FIELD(XstructName, XfieldType, XfieldName) \
AzureIoTClient 0:1f9b2707ec7d 363 static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(__COUNTER__))) = { REFLECTION_FIELD_TYPE, &C2(REFLECTED_, C1(DEC(DEC(__COUNTER__)))), { {0}, {TOSTRING(XfieldName), TOSTRING(XfieldType), TOSTRING(XstructName)}, {0}, {0}, {0} } };
AzureIoTClient 0:1f9b2707ec7d 364 #define REFLECTED_MODEL(name) \
AzureIoTClient 0:1f9b2707ec7d 365 static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(__COUNTER__))) = { REFLECTION_MODEL_TYPE, &C2(REFLECTED_, C1(DEC(DEC(__COUNTER__)))), { {0}, {0}, {0}, {0}, {TOSTRING(name)} } };
AzureIoTClient 0:1f9b2707ec7d 366 #define REFLECTED_PROPERTY(type, name, modelName) \
AzureIoTClient 0:1f9b2707ec7d 367 static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(__COUNTER__))) = { REFLECTION_PROPERTY_TYPE, &C2(REFLECTED_, C1(DEC(DEC(__COUNTER__)))), { {0}, {0}, {TOSTRING(name), TOSTRING(type), Create_AGENT_DATA_TYPE_From_Ptr_##name, offsetof(modelName, name), sizeof(type), TOSTRING(modelName)}, {0}, {0}} };
AzureIoTClient 0:1f9b2707ec7d 368 #define REFLECTED_ACTION(name, argc, argv, fn, modelName) \
AzureIoTClient 0:1f9b2707ec7d 369 static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(__COUNTER__))) = { REFLECTION_ACTION_TYPE, &C2(REFLECTED_, C1(DEC(DEC(__COUNTER__)))), { {0}, {0}, {0}, {TOSTRING(name), (0 ? (uintptr_t)("", "") : argc), argv, fn, TOSTRING(modelName)}, {0}} };
AzureIoTClient 0:1f9b2707ec7d 370 #define REFLECTED_END_OF_LIST \
AzureIoTClient 0:1f9b2707ec7d 371 static const REFLECTED_SOMETHING C2(REFLECTED_, __COUNTER__) = { REFLECTION_NOTHING, NULL, { {0}, {0}, {0}, {0}, {0}} };
AzureIoTClient 0:1f9b2707ec7d 372
AzureIoTClient 0:1f9b2707ec7d 373 #define EXPAND_MODEL_PROPERTY(type, name) EXPAND_ARGS(MODEL_PROPERTY, type, name)
AzureIoTClient 0:1f9b2707ec7d 374 #define EXPAND_MODEL_ACTION(...) EXPAND_ARGS(MODEL_ACTION, __VA_ARGS__)
AzureIoTClient 0:1f9b2707ec7d 375
AzureIoTClient 0:1f9b2707ec7d 376 #define BUILD_MODEL_STRUCT(elem) INSERT_FIELD_FOR_##elem
AzureIoTClient 0:1f9b2707ec7d 377
AzureIoTClient 0:1f9b2707ec7d 378 #define CREATE_MODEL_ENTITY(modelName, callType, ...) EXPAND_ARGS(CREATE_##callType(modelName, __VA_ARGS__))
AzureIoTClient 0:1f9b2707ec7d 379 #define CREATE_SOMETHING(modelName, ...) EXPAND_ARGS(CREATE_MODEL_ENTITY(modelName, __VA_ARGS__))
AzureIoTClient 0:1f9b2707ec7d 380 #define CREATE_ELEMENT(modelName, elem) EXPAND_ARGS(CREATE_SOMETHING(modelName, EXPAND_ARGS(EXPAND_##elem)))
AzureIoTClient 0:1f9b2707ec7d 381
AzureIoTClient 0:1f9b2707ec7d 382 #define CREATE_MODEL_ELEMENT(modelName, elem) EXPAND_ARGS(CREATE_ELEMENT(modelName, elem))
AzureIoTClient 0:1f9b2707ec7d 383
AzureIoTClient 0:1f9b2707ec7d 384 #define INSERT_FIELD_INTO_STRUCT(x, y) x y;
AzureIoTClient 0:1f9b2707ec7d 385 #define INSERT_FIELD_FOR_MODEL_PROPERTY(type, name) INSERT_FIELD_INTO_STRUCT(type, name)
AzureIoTClient 0:1f9b2707ec7d 386 #define INSERT_FIELD_FOR_MODEL_ACTION(name, ...) /* action isn't a part of the model struct */
AzureIoTClient 0:1f9b2707ec7d 387
AzureIoTClient 0:1f9b2707ec7d 388 #define CREATE_MODEL_PROPERTY(modelName, type, name) \
AzureIoTClient 0:1f9b2707ec7d 389 IMPL_PROPERTY(type, name, modelName)
AzureIoTClient 0:1f9b2707ec7d 390
AzureIoTClient 0:1f9b2707ec7d 391 #define IMPL_PROPERTY(propertyType, propertyName, modelName) \
AzureIoTClient 0:1f9b2707ec7d 392 static int Create_AGENT_DATA_TYPE_From_Ptr_##propertyName(void* param, AGENT_DATA_TYPE* dest) \
AzureIoTClient 0:1f9b2707ec7d 393 { \
AzureIoTClient 0:1f9b2707ec7d 394 return C1(ToAGENT_DATA_TYPE_##propertyType)(dest, *(propertyType*)param); \
AzureIoTClient 0:1f9b2707ec7d 395 } \
AzureIoTClient 0:1f9b2707ec7d 396 REFLECTED_PROPERTY(propertyType, propertyName, modelName)
AzureIoTClient 0:1f9b2707ec7d 397
AzureIoTClient 0:1f9b2707ec7d 398 #define CREATE_MODEL_ACTION(modelName, actionName, ...) \
AzureIoTClient 0:1f9b2707ec7d 399 DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(modelName##actionName, 1); \
AzureIoTClient 0:1f9b2707ec7d 400 EXECUTE_COMMAND_RESULT actionName (modelName* device FOR_EACH_2(DEFINE_FUNCTION_PARAMETER, __VA_ARGS__)); \
AzureIoTClient 0:1f9b2707ec7d 401 static EXECUTE_COMMAND_RESULT C2(actionName, WRAPPER)(void* device, size_t ParameterCount, const AGENT_DATA_TYPE* values); \
AzureIoTClient 0:1f9b2707ec7d 402 /*for macro purposes, this array always has at least 1 element*/ \
AzureIoTClient 0:1f9b2707ec7d 403 /*Codes_SRS_SERIALIZER_99_043:[ It is valid for a method not to have any parameters.]*/ \
AzureIoTClient 0:1f9b2707ec7d 404 DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 1); \
AzureIoTClient 0:1f9b2707ec7d 405 static const WRAPPER_ARGUMENT C2(actionName, WRAPPERARGUMENTS)[DIV2(INC(INC(COUNT_ARG(__VA_ARGS__))))] = { FOR_EACH_2_COUNTED(MAKE_WRAPPER_ARGUMENT, __VA_ARGS__) IFCOMMA(INC(INC(COUNT_ARG(__VA_ARGS__)))) {0} }; \
AzureIoTClient 0:1f9b2707ec7d 406 REFLECTED_ACTION(actionName, DIV2(COUNT_ARG(__VA_ARGS__)), C2(actionName, WRAPPERARGUMENTS), C2(actionName, WRAPPER), modelName) \
AzureIoTClient 0:1f9b2707ec7d 407 /*Codes_SRS_SERIALIZER_99_040:[ In addition to declaring the function, DECLARE_IOT_METHOD shall provide a definition for a wrapper that takes as parameters a size_t parameterCount and const AGENT_DATA_TYPE*.] */ \
AzureIoTClient 0:1f9b2707ec7d 408 /*Codes_SRS_SERIALIZER_99_041:[ This wrapper shall convert all the arguments to predefined types and then call the function written by the data provider developer.]*/ \
AzureIoTClient 0:1f9b2707ec7d 409 static EXECUTE_COMMAND_RESULT C2(actionName, WRAPPER)(void* device, size_t ParameterCount, const AGENT_DATA_TYPE* values) \
AzureIoTClient 0:1f9b2707ec7d 410 { \
AzureIoTClient 0:1f9b2707ec7d 411 EXECUTE_COMMAND_RESULT result; \
AzureIoTClient 0:1f9b2707ec7d 412 DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 2); \
AzureIoTClient 0:1f9b2707ec7d 413 /*Codes_SRS_SERIALIZER_99_045:[ If the number of passed parameters doesn't match the number of declared parameters, wrapper execution shall fail and return DATA_PROVIDER_INVALID_ARG;]*/ \
AzureIoTClient 0:1f9b2707ec7d 414 if(ParameterCount != DIV2(COUNT_ARG(__VA_ARGS__))) \
AzureIoTClient 0:1f9b2707ec7d 415 { \
AzureIoTClient 0:1f9b2707ec7d 416 result = EXECUTE_COMMAND_ERROR; \
AzureIoTClient 0:1f9b2707ec7d 417 } \
AzureIoTClient 0:1f9b2707ec7d 418 else \
AzureIoTClient 0:1f9b2707ec7d 419 { \
AzureIoTClient 0:1f9b2707ec7d 420 /*the below line takes care of initialized but not referenced parameter warning*/ \
AzureIoTClient 0:1f9b2707ec7d 421 DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 3); \
AzureIoTClient 0:1f9b2707ec7d 422 IF(DIV2(COUNT_ARG(__VA_ARGS__)), size_t iParameter = 0;, ) \
AzureIoTClient 0:1f9b2707ec7d 423 DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 4); \
AzureIoTClient 0:1f9b2707ec7d 424 /*the below line takes care of an unused parameter when values is really never questioned*/ \
AzureIoTClient 0:1f9b2707ec7d 425 DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 5); \
AzureIoTClient 0:1f9b2707ec7d 426 FOR_EACH_2(DEFINE_LOCAL_PARAMETER, __VA_ARGS__) \
AzureIoTClient 0:1f9b2707ec7d 427 DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 6); \
AzureIoTClient 0:1f9b2707ec7d 428 IF(DIV2(COUNT_ARG(__VA_ARGS__)), , (void)values;) \
AzureIoTClient 0:1f9b2707ec7d 429 INSTRUCTION_THAT_CAN_SUSTAIN_A_COMMA_STEAL; \
AzureIoTClient 0:1f9b2707ec7d 430 FOR_EACH_2(START_BUILD_LOCAL_PARAMETER, __VA_ARGS__) \
AzureIoTClient 0:1f9b2707ec7d 431 INSTRUCTION_THAT_CAN_SUSTAIN_A_COMMA_STEAL; \
AzureIoTClient 0:1f9b2707ec7d 432 result = actionName((modelName*)device FOR_EACH_2(PUSH_LOCAL_PARAMETER, __VA_ARGS__)); \
AzureIoTClient 0:1f9b2707ec7d 433 FOR_EACH_2(END_BUILD_LOCAL_PARAMETER, __VA_ARGS__) \
AzureIoTClient 0:1f9b2707ec7d 434 } \
AzureIoTClient 0:1f9b2707ec7d 435 return result; \
AzureIoTClient 0:1f9b2707ec7d 436 }
AzureIoTClient 0:1f9b2707ec7d 437
AzureIoTClient 0:1f9b2707ec7d 438 #define CREATE_AGENT_DATA_TYPE(type, name) \
AzureIoTClient 0:1f9b2707ec7d 439 result = (( result==AGENT_DATA_TYPES_OK) && (ToAGENT_DATA_TYPE_##type( &(members[iMember]), value.name) == AGENT_DATA_TYPES_OK))?AGENT_DATA_TYPES_OK:AGENT_DATA_TYPES_ERROR; \
AzureIoTClient 0:1f9b2707ec7d 440 iMember+= ((result==AGENT_DATA_TYPES_OK)?1:0);
AzureIoTClient 0:1f9b2707ec7d 441
AzureIoTClient 0:1f9b2707ec7d 442 #define BUILD_DESTINATION_FIELD(type, name) \
AzureIoTClient 0:1f9b2707ec7d 443 if(result == AGENT_DATA_TYPES_OK) \
AzureIoTClient 0:1f9b2707ec7d 444 { \
AzureIoTClient 0:1f9b2707ec7d 445 size_t i; \
AzureIoTClient 0:1f9b2707ec7d 446 bool wasFieldConverted = false; \
AzureIoTClient 0:1f9b2707ec7d 447 for (i = 0; i < source->value.edmComplexType.nMembers; i++) \
AzureIoTClient 0:1f9b2707ec7d 448 { \
AzureIoTClient 0:1f9b2707ec7d 449 /*the name of the field of the complex type must match the name of the field of the structure (parameter name here)*/ \
AzureIoTClient 0:1f9b2707ec7d 450 if (strcmp(source->value.edmComplexType.fields[i].fieldName, TOSTRING(name)) == 0) \
AzureIoTClient 0:1f9b2707ec7d 451 { /*Codes_SRS_SERIALIZER_99_017:[ These types can either be one of the types mentioned in WITH_DATA or it can be a type introduced by a previous DECLARE_STRUCT.]*/ \
AzureIoTClient 0:1f9b2707ec7d 452 wasFieldConverted = (C2(FromAGENT_DATA_TYPE_, type)(source->value.edmComplexType.fields[i].value, &(destination->name)) == AGENT_DATA_TYPES_OK); \
AzureIoTClient 0:1f9b2707ec7d 453 break; \
AzureIoTClient 0:1f9b2707ec7d 454 } \
AzureIoTClient 0:1f9b2707ec7d 455 } \
AzureIoTClient 0:1f9b2707ec7d 456 result = (wasFieldConverted == true)? AGENT_DATA_TYPES_OK: AGENT_DATA_TYPES_INVALID_ARG; \
AzureIoTClient 0:1f9b2707ec7d 457 } \
AzureIoTClient 0:1f9b2707ec7d 458 else \
AzureIoTClient 0:1f9b2707ec7d 459 { \
AzureIoTClient 0:1f9b2707ec7d 460 /*fallthrough*/ \
AzureIoTClient 0:1f9b2707ec7d 461 }
AzureIoTClient 0:1f9b2707ec7d 462
AzureIoTClient 0:1f9b2707ec7d 463 #define UNBUILD_DESTINATION_FIELD(value, type, name) \
AzureIoTClient 0:1f9b2707ec7d 464 C2(destroyLocalParameter, type)(&(value->name));
AzureIoTClient 0:1f9b2707ec7d 465
AzureIoTClient 0:1f9b2707ec7d 466
AzureIoTClient 0:1f9b2707ec7d 467 #define ADDRESS_MACRO(x) ,&x
AzureIoTClient 0:1f9b2707ec7d 468
AzureIoTClient 0:1f9b2707ec7d 469 #define KEEP_FIRST_(X, ...) X
AzureIoTClient 0:1f9b2707ec7d 470 #ifdef _MSC_VER
AzureIoTClient 0:1f9b2707ec7d 471 #define KEEP_FIRST(X) KEEP_FIRST_ LPAREN X)
AzureIoTClient 0:1f9b2707ec7d 472 #else
AzureIoTClient 0:1f9b2707ec7d 473 #define KEEP_FIRST(X) KEEP_FIRST_(X)
AzureIoTClient 0:1f9b2707ec7d 474 #endif
AzureIoTClient 0:1f9b2707ec7d 475
AzureIoTClient 0:1f9b2707ec7d 476 #define PROMOTIONMAP_float double, double
AzureIoTClient 0:1f9b2707ec7d 477 #define PROMOTIONMAP_int8_t int, int
AzureIoTClient 0:1f9b2707ec7d 478 #define PROMOTIONMAP_uint8_t int, int
AzureIoTClient 0:1f9b2707ec7d 479 #define PROMOTIONMAP_int16_t int, int
AzureIoTClient 0:1f9b2707ec7d 480 #define PROMOTIONMAP__Bool int, int
AzureIoTClient 0:1f9b2707ec7d 481 #define PROMOTIONMAP_bool int, int
AzureIoTClient 0:1f9b2707ec7d 482
AzureIoTClient 0:1f9b2707ec7d 483 #define CASTMAP_float (float), (float)
AzureIoTClient 0:1f9b2707ec7d 484 #define CASTMAP_int8_t (int8_t), (int8_t)
AzureIoTClient 0:1f9b2707ec7d 485 #define CASTMAP_uint8_t (uint8_t), (uint8_t)
AzureIoTClient 0:1f9b2707ec7d 486 #define CASTMAP_int16_t (int16_t), (int16_t)
AzureIoTClient 0:1f9b2707ec7d 487 #define CASTMAP__Bool 0!=, 0!=
AzureIoTClient 0:1f9b2707ec7d 488 #define CASTMAP_bool 0!=, 0!=
AzureIoTClient 0:1f9b2707ec7d 489
AzureIoTClient 0:1f9b2707ec7d 490 #define EMPTY_TOKEN
AzureIoTClient 0:1f9b2707ec7d 491
AzureIoTClient 0:1f9b2707ec7d 492 #define ANOTHERIF(x) C2(ANOTHERIF,x)
AzureIoTClient 0:1f9b2707ec7d 493 #define ANOTHERIF0(a,b) a
AzureIoTClient 0:1f9b2707ec7d 494 #define ANOTHERIF1(a,b) b
AzureIoTClient 0:1f9b2707ec7d 495 #define ANOTHERIF2(a,b) b
AzureIoTClient 0:1f9b2707ec7d 496 #define ANOTHERIF3(a,b) b
AzureIoTClient 0:1f9b2707ec7d 497 #define ANOTHERIF4(a,b) b
AzureIoTClient 0:1f9b2707ec7d 498 #define ANOTHERIF5(a,b) b
AzureIoTClient 0:1f9b2707ec7d 499 #define ANOTHERIF6(a,b) b
AzureIoTClient 0:1f9b2707ec7d 500 #define ANOTHERIF7(a,b) b
AzureIoTClient 0:1f9b2707ec7d 501 #define ANOTHERIF8(a,b) b
AzureIoTClient 0:1f9b2707ec7d 502 #define ANOTHERIF9(a,b) b
AzureIoTClient 0:1f9b2707ec7d 503 #define ANOTHERIF10(a,b) b
AzureIoTClient 0:1f9b2707ec7d 504 #define ANOTHERIF11(a,b) b
AzureIoTClient 0:1f9b2707ec7d 505 #define ANOTHERIF12(a,b) b
AzureIoTClient 0:1f9b2707ec7d 506
AzureIoTClient 0:1f9b2707ec7d 507 #define MAP_PROMOTED_TYPE(X) ANOTHERIF(DEC(COUNT_ARG(PROMOTIONMAP_##X))) (X, KEEP_FIRST(PROMOTIONMAP_##X))
AzureIoTClient 0:1f9b2707ec7d 508 #define MAP_CAST_TYPE(X) ANOTHERIF(DEC(COUNT_ARG(CASTMAP_##X))) (EMPTY_TOKEN, KEEP_FIRST(CASTMAP_##X) )
AzureIoTClient 0:1f9b2707ec7d 509
AzureIoTClient 0:1f9b2707ec7d 510 #define IFCOMMA(N) C2(IFCOMMA_, N)
AzureIoTClient 0:1f9b2707ec7d 511 #define IFCOMMA_0
AzureIoTClient 0:1f9b2707ec7d 512 #define IFCOMMA_2
AzureIoTClient 0:1f9b2707ec7d 513 #define IFCOMMA_4 ,
AzureIoTClient 0:1f9b2707ec7d 514 #define IFCOMMA_6 ,
AzureIoTClient 0:1f9b2707ec7d 515 #define IFCOMMA_8 ,
AzureIoTClient 0:1f9b2707ec7d 516 #define IFCOMMA_10 ,
AzureIoTClient 0:1f9b2707ec7d 517 #define IFCOMMA_12 ,
AzureIoTClient 0:1f9b2707ec7d 518 #define IFCOMMA_14 ,
AzureIoTClient 0:1f9b2707ec7d 519 #define IFCOMMA_16 ,
AzureIoTClient 0:1f9b2707ec7d 520 #define IFCOMMA_18 ,
AzureIoTClient 0:1f9b2707ec7d 521 #define IFCOMMA_20 ,
AzureIoTClient 0:1f9b2707ec7d 522 #define IFCOMMA_22 ,
AzureIoTClient 0:1f9b2707ec7d 523 #define IFCOMMA_24 ,
AzureIoTClient 0:1f9b2707ec7d 524 #define IFCOMMA_26 ,
AzureIoTClient 0:1f9b2707ec7d 525 #define IFCOMMA_28 ,
AzureIoTClient 0:1f9b2707ec7d 526 #define IFCOMMA_30 ,
AzureIoTClient 0:1f9b2707ec7d 527 #define IFCOMMA_32 ,
AzureIoTClient 0:1f9b2707ec7d 528 #define IFCOMMA_34 ,
AzureIoTClient 0:1f9b2707ec7d 529 #define IFCOMMA_36 ,
AzureIoTClient 0:1f9b2707ec7d 530 #define IFCOMMA_38 ,
AzureIoTClient 0:1f9b2707ec7d 531 #define IFCOMMA_40 ,
AzureIoTClient 0:1f9b2707ec7d 532 #define IFCOMMA_42 ,
AzureIoTClient 0:1f9b2707ec7d 533 #define IFCOMMA_44 ,
AzureIoTClient 0:1f9b2707ec7d 534 #define IFCOMMA_46 ,
AzureIoTClient 0:1f9b2707ec7d 535 #define IFCOMMA_48 ,
AzureIoTClient 0:1f9b2707ec7d 536 #define IFCOMMA_50 ,
AzureIoTClient 0:1f9b2707ec7d 537 #define IFCOMMA_52 ,
AzureIoTClient 0:1f9b2707ec7d 538 #define IFCOMMA_54 ,
AzureIoTClient 0:1f9b2707ec7d 539 #define IFCOMMA_56 ,
AzureIoTClient 0:1f9b2707ec7d 540 #define IFCOMMA_58 ,
AzureIoTClient 0:1f9b2707ec7d 541 #define IFCOMMA_60 ,
AzureIoTClient 0:1f9b2707ec7d 542 #define IFCOMMA_62 ,
AzureIoTClient 0:1f9b2707ec7d 543 #define IFCOMMA_64 ,
AzureIoTClient 0:1f9b2707ec7d 544 #define IFCOMMA_66 ,
AzureIoTClient 0:1f9b2707ec7d 545 #define IFCOMMA_68 ,
AzureIoTClient 0:1f9b2707ec7d 546 #define IFCOMMA_70 ,
AzureIoTClient 0:1f9b2707ec7d 547 #define IFCOMMA_72 ,
AzureIoTClient 0:1f9b2707ec7d 548 #define IFCOMMA_74 ,
AzureIoTClient 0:1f9b2707ec7d 549 #define IFCOMMA_76 ,
AzureIoTClient 0:1f9b2707ec7d 550 #define IFCOMMA_78 ,
AzureIoTClient 0:1f9b2707ec7d 551 #define IFCOMMA_80 ,
AzureIoTClient 0:1f9b2707ec7d 552 #define IFCOMMA_82 ,
AzureIoTClient 0:1f9b2707ec7d 553 #define IFCOMMA_84 ,
AzureIoTClient 0:1f9b2707ec7d 554 #define IFCOMMA_86 ,
AzureIoTClient 0:1f9b2707ec7d 555 #define IFCOMMA_88 ,
AzureIoTClient 0:1f9b2707ec7d 556 #define IFCOMMA_90 ,
AzureIoTClient 0:1f9b2707ec7d 557 #define IFCOMMA_92 ,
AzureIoTClient 0:1f9b2707ec7d 558 #define IFCOMMA_94 ,
AzureIoTClient 0:1f9b2707ec7d 559 #define IFCOMMA_96 ,
AzureIoTClient 0:1f9b2707ec7d 560 #define IFCOMMA_98 ,
AzureIoTClient 0:1f9b2707ec7d 561 #define IFCOMMA_100 ,
AzureIoTClient 0:1f9b2707ec7d 562 #define IFCOMMA_102 ,
AzureIoTClient 0:1f9b2707ec7d 563 #define IFCOMMA_104 ,
AzureIoTClient 0:1f9b2707ec7d 564 #define IFCOMMA_106 ,
AzureIoTClient 0:1f9b2707ec7d 565 #define IFCOMMA_108 ,
AzureIoTClient 0:1f9b2707ec7d 566 #define IFCOMMA_110 ,
AzureIoTClient 0:1f9b2707ec7d 567 #define IFCOMMA_112 ,
AzureIoTClient 0:1f9b2707ec7d 568 #define IFCOMMA_114 ,
AzureIoTClient 0:1f9b2707ec7d 569 #define IFCOMMA_116 ,
AzureIoTClient 0:1f9b2707ec7d 570 #define IFCOMMA_118 ,
AzureIoTClient 0:1f9b2707ec7d 571 #define IFCOMMA_120 ,
AzureIoTClient 0:1f9b2707ec7d 572 #define IFCOMMA_122 ,
AzureIoTClient 0:1f9b2707ec7d 573 #define IFCOMMA_124 ,
AzureIoTClient 0:1f9b2707ec7d 574 #define IFCOMMA_126 ,
AzureIoTClient 0:1f9b2707ec7d 575 #define IFCOMMA_128 ,
AzureIoTClient 0:1f9b2707ec7d 576
AzureIoTClient 0:1f9b2707ec7d 577 #define DEFINE_LOCAL_PARAMETER(type, name) type C2(name,_local);
AzureIoTClient 0:1f9b2707ec7d 578
AzureIoTClient 0:1f9b2707ec7d 579 #define START_BUILD_LOCAL_PARAMETER(type, name) \
AzureIoTClient 0:1f9b2707ec7d 580 if (C2(FromAGENT_DATA_TYPE_, type)(&values[iParameter], &C2(name, _local)) != AGENT_DATA_TYPES_OK) \
AzureIoTClient 0:1f9b2707ec7d 581 { \
AzureIoTClient 0:1f9b2707ec7d 582 /*Codes_SRS_SERIALIZER_99_046:[ If the types of the parameters do not match the declared types, DATAPROVIDER_INVALID_ARG shall be returned.]*/ \
AzureIoTClient 0:1f9b2707ec7d 583 result = EXECUTE_COMMAND_ERROR; \
AzureIoTClient 0:1f9b2707ec7d 584 }\
AzureIoTClient 0:1f9b2707ec7d 585 else \
AzureIoTClient 0:1f9b2707ec7d 586 { \
AzureIoTClient 0:1f9b2707ec7d 587 iParameter++;
AzureIoTClient 0:1f9b2707ec7d 588
AzureIoTClient 0:1f9b2707ec7d 589 #define END_BUILD_LOCAL_PARAMETER(type, name) \
AzureIoTClient 0:1f9b2707ec7d 590 (void)C2(destroyLocalParameter, type)(&C2(name, _local)); \
AzureIoTClient 0:1f9b2707ec7d 591 }
AzureIoTClient 0:1f9b2707ec7d 592
AzureIoTClient 0:1f9b2707ec7d 593 /*The following constructs have been devised to work around the precompiler bug of Visual Studio 2005, version 14.00.50727.42*/
AzureIoTClient 0:1f9b2707ec7d 594 /* The bug is explained in https://connect.microsoft.com/VisualStudio/feedback/details/278752/comma-missing-when-using-va-args */
AzureIoTClient 0:1f9b2707ec7d 595 /*A short description is: preprocessor is myteriously eating commas ','.
AzureIoTClient 0:1f9b2707ec7d 596 In order to feed the appetite of the preprocessor, several constructs have
AzureIoTClient 0:1f9b2707ec7d 597 been devised that can sustain a missing ',' while still compiling and while still doing nothing
AzureIoTClient 0:1f9b2707ec7d 598 and while hopefully being eliminated from the code based on "doesn't do anything" so no code size penalty
AzureIoTClient 0:1f9b2707ec7d 599 */
AzureIoTClient 0:1f9b2707ec7d 600
AzureIoTClient 0:1f9b2707ec7d 601 /*the reason why all these constructs work is:
AzureIoTClient 0:1f9b2707ec7d 602 if two strings separated by a comma will lose the comma (myteriously) then they will become just one string:
AzureIoTClient 0:1f9b2707ec7d 603 "a", "b" ------Preprocessor------> "a" "b" -----Compiler----> "ab"
AzureIoTClient 0:1f9b2707ec7d 604 */
AzureIoTClient 0:1f9b2707ec7d 605
AzureIoTClient 0:1f9b2707ec7d 606 #define LOTS_OF_COMMA_TO_BE_EATEN /*there were witnesses where as many as THREE commas have been eaten!*/ \
AzureIoTClient 0:1f9b2707ec7d 607 "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
AzureIoTClient 0:1f9b2707ec7d 608 #define DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(name, instance) static const char* eatThese_COMMA_##name##instance[] = {LOTS_OF_COMMA_TO_BE_EATEN}
AzureIoTClient 0:1f9b2707ec7d 609 #define INSTRUCTION_THAT_CAN_SUSTAIN_A_COMMA_STEAL 0?LOTS_OF_COMMA_TO_BE_EATEN:LOTS_OF_COMMA_TO_BE_EATEN
AzureIoTClient 0:1f9b2707ec7d 610
AzureIoTClient 0:1f9b2707ec7d 611 #define PUSH_LOCAL_PARAMETER(type, name) , C2(name, _local)
AzureIoTClient 0:1f9b2707ec7d 612 #define DEFINE_FUNCTION_PARAMETER(type, name) , type name
AzureIoTClient 0:1f9b2707ec7d 613 #define MAKE_WRAPPER_ARGUMENT(N, type, name) {TOSTRING(type), TOSTRING(name)} IFCOMMA(N)
AzureIoTClient 0:1f9b2707ec7d 614
AzureIoTClient 0:1f9b2707ec7d 615 /*Codes_SRS_SERIALIZER_99_019:[ Create_AGENT_DATA_TYPE_from_DOUBLE]*/
AzureIoTClient 0:1f9b2707ec7d 616 /*Codes_SRS_SERIALIZER_99_004:[ The propertyType can be any of the following data types: double]*/
AzureIoTClient 0:1f9b2707ec7d 617 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, double)(AGENT_DATA_TYPE* dest, double source)
AzureIoTClient 0:1f9b2707ec7d 618 {
AzureIoTClient 0:1f9b2707ec7d 619 return Create_AGENT_DATA_TYPE_from_DOUBLE(dest, source);
AzureIoTClient 0:1f9b2707ec7d 620 }
AzureIoTClient 0:1f9b2707ec7d 621
AzureIoTClient 0:1f9b2707ec7d 622 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, double)(const AGENT_DATA_TYPE* agentData, double* dest)
AzureIoTClient 0:1f9b2707ec7d 623 {
AzureIoTClient 0:1f9b2707ec7d 624 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 625 if (agentData->type != EDM_DOUBLE_TYPE)
AzureIoTClient 0:1f9b2707ec7d 626 {
AzureIoTClient 0:1f9b2707ec7d 627 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 628 }
AzureIoTClient 0:1f9b2707ec7d 629 else
AzureIoTClient 0:1f9b2707ec7d 630 {
AzureIoTClient 0:1f9b2707ec7d 631 *dest = agentData->value.edmDouble.value;
AzureIoTClient 0:1f9b2707ec7d 632 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 633 }
AzureIoTClient 0:1f9b2707ec7d 634 return result;
AzureIoTClient 0:1f9b2707ec7d 635 }
AzureIoTClient 0:1f9b2707ec7d 636
AzureIoTClient 0:1f9b2707ec7d 637 /*Codes_SRS_SERIALIZER_99_021:[ Create_AGENT_DATA_TYPE_from_FLOAT]*/
AzureIoTClient 0:1f9b2707ec7d 638 /*Codes_SRS_SERIALIZER_99_006:[ float]*/
AzureIoTClient 0:1f9b2707ec7d 639 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, float)(AGENT_DATA_TYPE* dest, float source)
AzureIoTClient 0:1f9b2707ec7d 640 {
AzureIoTClient 0:1f9b2707ec7d 641 return Create_AGENT_DATA_TYPE_from_FLOAT(dest, source);
AzureIoTClient 0:1f9b2707ec7d 642 }
AzureIoTClient 0:1f9b2707ec7d 643
AzureIoTClient 0:1f9b2707ec7d 644 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, float)(const AGENT_DATA_TYPE* agentData, float* dest)
AzureIoTClient 0:1f9b2707ec7d 645 {
AzureIoTClient 0:1f9b2707ec7d 646 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 647 if (agentData->type != EDM_SINGLE_TYPE)
AzureIoTClient 0:1f9b2707ec7d 648 {
AzureIoTClient 0:1f9b2707ec7d 649 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 650 }
AzureIoTClient 0:1f9b2707ec7d 651 else
AzureIoTClient 0:1f9b2707ec7d 652 {
AzureIoTClient 0:1f9b2707ec7d 653 *dest = agentData->value.edmSingle.value;
AzureIoTClient 0:1f9b2707ec7d 654 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 655 }
AzureIoTClient 0:1f9b2707ec7d 656 return result;
AzureIoTClient 0:1f9b2707ec7d 657 }
AzureIoTClient 0:1f9b2707ec7d 658
AzureIoTClient 0:1f9b2707ec7d 659
AzureIoTClient 0:1f9b2707ec7d 660 /*Codes_SRS_SERIALIZER_99_020:[ Create_AGENT_DATA_TYPE_from_SINT32]*/
AzureIoTClient 0:1f9b2707ec7d 661 /*Codes_SRS_SERIALIZER_99_005:[ int], */
AzureIoTClient 0:1f9b2707ec7d 662 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, int)(AGENT_DATA_TYPE* dest, int source)
AzureIoTClient 0:1f9b2707ec7d 663 {
AzureIoTClient 0:1f9b2707ec7d 664 return Create_AGENT_DATA_TYPE_from_SINT32(dest, source);
AzureIoTClient 0:1f9b2707ec7d 665 }
AzureIoTClient 0:1f9b2707ec7d 666
AzureIoTClient 0:1f9b2707ec7d 667 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, int)(const AGENT_DATA_TYPE* agentData, int* dest)
AzureIoTClient 0:1f9b2707ec7d 668 {
AzureIoTClient 0:1f9b2707ec7d 669 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 670 if (agentData->type != EDM_INT32_TYPE)
AzureIoTClient 0:1f9b2707ec7d 671 {
AzureIoTClient 0:1f9b2707ec7d 672 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 673 }
AzureIoTClient 0:1f9b2707ec7d 674 else
AzureIoTClient 0:1f9b2707ec7d 675 {
AzureIoTClient 0:1f9b2707ec7d 676 *dest = agentData->value.edmInt32.value;
AzureIoTClient 0:1f9b2707ec7d 677 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 678 }
AzureIoTClient 0:1f9b2707ec7d 679 return result;
AzureIoTClient 0:1f9b2707ec7d 680 }
AzureIoTClient 0:1f9b2707ec7d 681
AzureIoTClient 0:1f9b2707ec7d 682 /*Codes_SRS_SERIALIZER_99_022:[ Create_AGENT_DATA_TYPE_from_SINT64]*/
AzureIoTClient 0:1f9b2707ec7d 683 /*Codes_SRS_SERIALIZER_99_007:[ long]*/
AzureIoTClient 0:1f9b2707ec7d 684 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, long)(AGENT_DATA_TYPE* dest, long source)
AzureIoTClient 0:1f9b2707ec7d 685 {
AzureIoTClient 0:1f9b2707ec7d 686 return Create_AGENT_DATA_TYPE_from_SINT64(dest, source);
AzureIoTClient 0:1f9b2707ec7d 687 }
AzureIoTClient 0:1f9b2707ec7d 688
AzureIoTClient 0:1f9b2707ec7d 689 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, long)(const AGENT_DATA_TYPE* agentData, long* dest)
AzureIoTClient 0:1f9b2707ec7d 690 {
AzureIoTClient 0:1f9b2707ec7d 691 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 692 if (agentData->type != EDM_INT64_TYPE)
AzureIoTClient 0:1f9b2707ec7d 693 {
AzureIoTClient 0:1f9b2707ec7d 694 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 695 }
AzureIoTClient 0:1f9b2707ec7d 696 else
AzureIoTClient 0:1f9b2707ec7d 697 {
AzureIoTClient 0:1f9b2707ec7d 698 *dest = (long)agentData->value.edmInt64.value;
AzureIoTClient 0:1f9b2707ec7d 699 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 700 }
AzureIoTClient 0:1f9b2707ec7d 701 return result;
AzureIoTClient 0:1f9b2707ec7d 702 }
AzureIoTClient 0:1f9b2707ec7d 703
AzureIoTClient 0:1f9b2707ec7d 704 /*Codes_SRS_SERIALIZER_99_023:[ Create_AGENT_DATA_TYPE_from_SINT8]*/
AzureIoTClient 0:1f9b2707ec7d 705 /*Codes_SRS_SERIALIZER_99_008:[ int8_t]*/
AzureIoTClient 0:1f9b2707ec7d 706 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, int8_t)(AGENT_DATA_TYPE* dest, int8_t source)
AzureIoTClient 0:1f9b2707ec7d 707 {
AzureIoTClient 0:1f9b2707ec7d 708 return Create_AGENT_DATA_TYPE_from_SINT8(dest, source);
AzureIoTClient 0:1f9b2707ec7d 709 }
AzureIoTClient 0:1f9b2707ec7d 710
AzureIoTClient 0:1f9b2707ec7d 711 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, int8_t)(const AGENT_DATA_TYPE* agentData, int8_t* dest)
AzureIoTClient 0:1f9b2707ec7d 712 {
AzureIoTClient 0:1f9b2707ec7d 713 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 714 if (agentData->type != EDM_SBYTE_TYPE)
AzureIoTClient 0:1f9b2707ec7d 715 {
AzureIoTClient 0:1f9b2707ec7d 716 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 717 }
AzureIoTClient 0:1f9b2707ec7d 718 else
AzureIoTClient 0:1f9b2707ec7d 719 {
AzureIoTClient 0:1f9b2707ec7d 720 *dest = agentData->value.edmSbyte.value;
AzureIoTClient 0:1f9b2707ec7d 721 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 722 }
AzureIoTClient 0:1f9b2707ec7d 723 return result;
AzureIoTClient 0:1f9b2707ec7d 724 }
AzureIoTClient 0:1f9b2707ec7d 725
AzureIoTClient 0:1f9b2707ec7d 726 /*Codes_SRS_SERIALIZER_99_024:[ Create_AGENT_DATA_TYPE_from_UINT8]*/
AzureIoTClient 0:1f9b2707ec7d 727 /*Codes_SRS_SERIALIZER_99_009:[ uint8_t]*/
AzureIoTClient 0:1f9b2707ec7d 728 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, uint8_t)(AGENT_DATA_TYPE* dest, uint8_t source)
AzureIoTClient 0:1f9b2707ec7d 729 {
AzureIoTClient 0:1f9b2707ec7d 730 return Create_AGENT_DATA_TYPE_from_UINT8(dest, source);
AzureIoTClient 0:1f9b2707ec7d 731 }
AzureIoTClient 0:1f9b2707ec7d 732
AzureIoTClient 0:1f9b2707ec7d 733 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, uint8_t)(const AGENT_DATA_TYPE* agentData, uint8_t* dest)
AzureIoTClient 0:1f9b2707ec7d 734 {
AzureIoTClient 0:1f9b2707ec7d 735 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 736 if (agentData->type != EDM_BYTE_TYPE)
AzureIoTClient 0:1f9b2707ec7d 737 {
AzureIoTClient 0:1f9b2707ec7d 738 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 739 }
AzureIoTClient 0:1f9b2707ec7d 740 else
AzureIoTClient 0:1f9b2707ec7d 741 {
AzureIoTClient 0:1f9b2707ec7d 742 *dest = agentData->value.edmByte.value;
AzureIoTClient 0:1f9b2707ec7d 743 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 744 }
AzureIoTClient 0:1f9b2707ec7d 745 return result;
AzureIoTClient 0:1f9b2707ec7d 746 }
AzureIoTClient 0:1f9b2707ec7d 747
AzureIoTClient 0:1f9b2707ec7d 748 /*Codes_SRS_SERIALIZER_99_025:[ Create_AGENT_DATA_TYPE_from_SINT16]*/
AzureIoTClient 0:1f9b2707ec7d 749 /*Codes_SRS_SERIALIZER_99_010:[ int16_t]*/
AzureIoTClient 0:1f9b2707ec7d 750 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, int16_t)(AGENT_DATA_TYPE* dest, int16_t source)
AzureIoTClient 0:1f9b2707ec7d 751 {
AzureIoTClient 0:1f9b2707ec7d 752 return Create_AGENT_DATA_TYPE_from_SINT16(dest, source);
AzureIoTClient 0:1f9b2707ec7d 753 }
AzureIoTClient 0:1f9b2707ec7d 754
AzureIoTClient 0:1f9b2707ec7d 755 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, int16_t)(const AGENT_DATA_TYPE* agentData, int16_t* dest)
AzureIoTClient 0:1f9b2707ec7d 756 {
AzureIoTClient 0:1f9b2707ec7d 757 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 758 if (agentData->type != EDM_INT16_TYPE)
AzureIoTClient 0:1f9b2707ec7d 759 {
AzureIoTClient 0:1f9b2707ec7d 760 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 761 }
AzureIoTClient 0:1f9b2707ec7d 762 else
AzureIoTClient 0:1f9b2707ec7d 763 {
AzureIoTClient 0:1f9b2707ec7d 764 *dest = agentData->value.edmInt16.value;
AzureIoTClient 0:1f9b2707ec7d 765 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 766 }
AzureIoTClient 0:1f9b2707ec7d 767 return result;
AzureIoTClient 0:1f9b2707ec7d 768 }
AzureIoTClient 0:1f9b2707ec7d 769
AzureIoTClient 0:1f9b2707ec7d 770 /*Codes_SRS_SERIALIZER_99_026:[ Create_AGENT_DATA_TYPE_from_SINT32]*/
AzureIoTClient 0:1f9b2707ec7d 771 /*Codes_SRS_SERIALIZER_99_011:[ int32_t]*/
AzureIoTClient 0:1f9b2707ec7d 772 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, int32_t)(AGENT_DATA_TYPE* dest, int32_t source)
AzureIoTClient 0:1f9b2707ec7d 773 {
AzureIoTClient 0:1f9b2707ec7d 774 return Create_AGENT_DATA_TYPE_from_SINT32(dest, source);
AzureIoTClient 0:1f9b2707ec7d 775 }
AzureIoTClient 0:1f9b2707ec7d 776
AzureIoTClient 0:1f9b2707ec7d 777 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, int32_t)(const AGENT_DATA_TYPE* agentData, int32_t* dest)
AzureIoTClient 0:1f9b2707ec7d 778 {
AzureIoTClient 0:1f9b2707ec7d 779 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 780 if (agentData->type != EDM_INT32_TYPE)
AzureIoTClient 0:1f9b2707ec7d 781 {
AzureIoTClient 0:1f9b2707ec7d 782 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 783 }
AzureIoTClient 0:1f9b2707ec7d 784 else
AzureIoTClient 0:1f9b2707ec7d 785 {
AzureIoTClient 0:1f9b2707ec7d 786 *dest = agentData->value.edmInt32.value;
AzureIoTClient 0:1f9b2707ec7d 787 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 788 }
AzureIoTClient 0:1f9b2707ec7d 789 return result;
AzureIoTClient 0:1f9b2707ec7d 790 }
AzureIoTClient 0:1f9b2707ec7d 791
AzureIoTClient 0:1f9b2707ec7d 792 /*Codes_SRS_SERIALIZER_99_027:[ Create_AGENT_DATA_TYPE_from_SINT64]*/
AzureIoTClient 0:1f9b2707ec7d 793 /*Codes_SRS_SERIALIZER_99_012:[ int64_t]*/
AzureIoTClient 0:1f9b2707ec7d 794 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, int64_t)(AGENT_DATA_TYPE* dest, int64_t source)
AzureIoTClient 0:1f9b2707ec7d 795 {
AzureIoTClient 0:1f9b2707ec7d 796 return Create_AGENT_DATA_TYPE_from_SINT64(dest, source);
AzureIoTClient 0:1f9b2707ec7d 797 }
AzureIoTClient 0:1f9b2707ec7d 798
AzureIoTClient 0:1f9b2707ec7d 799 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, int64_t)(const AGENT_DATA_TYPE* agentData, int64_t* dest)
AzureIoTClient 0:1f9b2707ec7d 800 {
AzureIoTClient 0:1f9b2707ec7d 801 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 802 if (agentData->type != EDM_INT64_TYPE)
AzureIoTClient 0:1f9b2707ec7d 803 {
AzureIoTClient 0:1f9b2707ec7d 804 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 805 }
AzureIoTClient 0:1f9b2707ec7d 806 else
AzureIoTClient 0:1f9b2707ec7d 807 {
AzureIoTClient 0:1f9b2707ec7d 808 *dest = agentData->value.edmInt64.value;
AzureIoTClient 0:1f9b2707ec7d 809 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 810 }
AzureIoTClient 0:1f9b2707ec7d 811 return result;
AzureIoTClient 0:1f9b2707ec7d 812 }
AzureIoTClient 0:1f9b2707ec7d 813
AzureIoTClient 0:1f9b2707ec7d 814 /*Codes_SRS_SERIALIZER_99_013:[ bool]*/
AzureIoTClient 0:1f9b2707ec7d 815 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, bool)(AGENT_DATA_TYPE* dest, bool source)
AzureIoTClient 0:1f9b2707ec7d 816 {
AzureIoTClient 0:1f9b2707ec7d 817 return Create_EDM_BOOLEAN_from_int(dest, source == true);
AzureIoTClient 0:1f9b2707ec7d 818 }
AzureIoTClient 0:1f9b2707ec7d 819
AzureIoTClient 0:1f9b2707ec7d 820 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, bool)(const AGENT_DATA_TYPE* agentData, bool* dest)
AzureIoTClient 0:1f9b2707ec7d 821 {
AzureIoTClient 0:1f9b2707ec7d 822 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 823 if (agentData->type != EDM_BOOLEAN_TYPE)
AzureIoTClient 0:1f9b2707ec7d 824 {
AzureIoTClient 0:1f9b2707ec7d 825 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 826 }
AzureIoTClient 0:1f9b2707ec7d 827 else
AzureIoTClient 0:1f9b2707ec7d 828 {
AzureIoTClient 0:1f9b2707ec7d 829 *dest = (agentData->value.edmBoolean.value == EDM_TRUE) ? true : false;
AzureIoTClient 0:1f9b2707ec7d 830 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 831 }
AzureIoTClient 0:1f9b2707ec7d 832 return result;
AzureIoTClient 0:1f9b2707ec7d 833 }
AzureIoTClient 0:1f9b2707ec7d 834
AzureIoTClient 0:1f9b2707ec7d 835 /*Codes_SRS_SERIALIZER_99_014:[ ascii_char_ptr]*/
AzureIoTClient 0:1f9b2707ec7d 836 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, ascii_char_ptr)(AGENT_DATA_TYPE* dest, ascii_char_ptr source)
AzureIoTClient 0:1f9b2707ec7d 837 {
AzureIoTClient 0:1f9b2707ec7d 838 return Create_AGENT_DATA_TYPE_from_charz(dest, source);
AzureIoTClient 0:1f9b2707ec7d 839 }
AzureIoTClient 0:1f9b2707ec7d 840
AzureIoTClient 0:1f9b2707ec7d 841 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, ascii_char_ptr)(const AGENT_DATA_TYPE* agentData, ascii_char_ptr* dest)
AzureIoTClient 0:1f9b2707ec7d 842 {
AzureIoTClient 0:1f9b2707ec7d 843 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 844 if (agentData->type != EDM_STRING_TYPE)
AzureIoTClient 0:1f9b2707ec7d 845 {
AzureIoTClient 0:1f9b2707ec7d 846 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 847 }
AzureIoTClient 0:1f9b2707ec7d 848 else
AzureIoTClient 0:1f9b2707ec7d 849 {
AzureIoTClient 0:1f9b2707ec7d 850 *dest = agentData->value.edmString.chars;
AzureIoTClient 0:1f9b2707ec7d 851 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 852 }
AzureIoTClient 0:1f9b2707ec7d 853 return result;
AzureIoTClient 0:1f9b2707ec7d 854 }
AzureIoTClient 0:1f9b2707ec7d 855
AzureIoTClient 0:1f9b2707ec7d 856 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, ascii_char_ptr_no_quotes)(AGENT_DATA_TYPE* dest, ascii_char_ptr_no_quotes source)
AzureIoTClient 0:1f9b2707ec7d 857 {
AzureIoTClient 0:1f9b2707ec7d 858 return Create_AGENT_DATA_TYPE_from_charz_no_quotes(dest, source);
AzureIoTClient 0:1f9b2707ec7d 859 }
AzureIoTClient 0:1f9b2707ec7d 860
AzureIoTClient 0:1f9b2707ec7d 861 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, ascii_char_ptr_no_quotes)(const AGENT_DATA_TYPE* agentData, ascii_char_ptr_no_quotes* dest)
AzureIoTClient 0:1f9b2707ec7d 862 {
AzureIoTClient 0:1f9b2707ec7d 863 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 864 if (agentData->type != EDM_STRING_NO_QUOTES_TYPE)
AzureIoTClient 0:1f9b2707ec7d 865 {
AzureIoTClient 0:1f9b2707ec7d 866 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 867 }
AzureIoTClient 0:1f9b2707ec7d 868 else
AzureIoTClient 0:1f9b2707ec7d 869 {
AzureIoTClient 0:1f9b2707ec7d 870 *dest = agentData->value.edmStringNoQuotes.chars;
AzureIoTClient 0:1f9b2707ec7d 871 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 872 }
AzureIoTClient 0:1f9b2707ec7d 873 return result;
AzureIoTClient 0:1f9b2707ec7d 874 }
AzureIoTClient 0:1f9b2707ec7d 875
AzureIoTClient 0:1f9b2707ec7d 876 /*Codes_SRS_SERIALIZER_99_051:[ EDM_DATE_TIME_OFFSET*/
AzureIoTClient 0:1f9b2707ec7d 877 /*Codes_SRS_SERIALIZER_99_053:[Create_AGENT_DATA_TYPE_from_EDM_DATE_TIME_OFFSET]*/
AzureIoTClient 0:1f9b2707ec7d 878 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, EDM_DATE_TIME_OFFSET)(AGENT_DATA_TYPE* dest, EDM_DATE_TIME_OFFSET source)
AzureIoTClient 0:1f9b2707ec7d 879 {
AzureIoTClient 0:1f9b2707ec7d 880 return Create_AGENT_DATA_TYPE_from_EDM_DATE_TIME_OFFSET(dest, source);
AzureIoTClient 0:1f9b2707ec7d 881 }
AzureIoTClient 0:1f9b2707ec7d 882
AzureIoTClient 0:1f9b2707ec7d 883 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, EDM_DATE_TIME_OFFSET)(const AGENT_DATA_TYPE* agentData, EDM_DATE_TIME_OFFSET* dest)
AzureIoTClient 0:1f9b2707ec7d 884 {
AzureIoTClient 0:1f9b2707ec7d 885 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 886 if (agentData->type != EDM_DATE_TIME_OFFSET_TYPE)
AzureIoTClient 0:1f9b2707ec7d 887 {
AzureIoTClient 0:1f9b2707ec7d 888 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 889 }
AzureIoTClient 0:1f9b2707ec7d 890 else
AzureIoTClient 0:1f9b2707ec7d 891 {
AzureIoTClient 0:1f9b2707ec7d 892 *dest = agentData->value.edmDateTimeOffset;
AzureIoTClient 0:1f9b2707ec7d 893 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 894 }
AzureIoTClient 0:1f9b2707ec7d 895 return result;
AzureIoTClient 0:1f9b2707ec7d 896 }
AzureIoTClient 0:1f9b2707ec7d 897
AzureIoTClient 0:1f9b2707ec7d 898 /*Codes_SRS_SERIALIZER_99_072:[ EDM_GUID]*/
AzureIoTClient 0:1f9b2707ec7d 899 /*Codes_SRS_SERIALIZER_99_073:[ Create_AGENT_DATA_TYPE_from_EDM_GUID]*/
AzureIoTClient 0:1f9b2707ec7d 900 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, EDM_GUID)(AGENT_DATA_TYPE* dest, EDM_GUID guid)
AzureIoTClient 0:1f9b2707ec7d 901 {
AzureIoTClient 0:1f9b2707ec7d 902 return Create_AGENT_DATA_TYPE_from_EDM_GUID(dest, guid);
AzureIoTClient 0:1f9b2707ec7d 903 }
AzureIoTClient 0:1f9b2707ec7d 904
AzureIoTClient 0:1f9b2707ec7d 905 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, EDM_GUID)(const AGENT_DATA_TYPE* agentData, EDM_GUID* dest)
AzureIoTClient 0:1f9b2707ec7d 906 {
AzureIoTClient 0:1f9b2707ec7d 907 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 908 if (agentData->type != EDM_GUID_TYPE)
AzureIoTClient 0:1f9b2707ec7d 909 {
AzureIoTClient 0:1f9b2707ec7d 910 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 911 }
AzureIoTClient 0:1f9b2707ec7d 912 else
AzureIoTClient 0:1f9b2707ec7d 913 {
AzureIoTClient 0:1f9b2707ec7d 914 memcpy(dest->GUID, agentData->value.edmGuid.GUID, 16);
AzureIoTClient 0:1f9b2707ec7d 915 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 916 }
AzureIoTClient 0:1f9b2707ec7d 917 return result;
AzureIoTClient 0:1f9b2707ec7d 918 }
AzureIoTClient 0:1f9b2707ec7d 919
AzureIoTClient 0:1f9b2707ec7d 920 /*Codes_SRS_SERIALIZER_99_074:[ EDM_BINARY]*/
AzureIoTClient 0:1f9b2707ec7d 921 /*Codes_SRS_SERIALIZER_99_075:[ Create_AGENT_DATA_TYPE_from_EDM_BINARY]*/
AzureIoTClient 0:1f9b2707ec7d 922 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, EDM_BINARY)(AGENT_DATA_TYPE* dest, EDM_BINARY edmBinary)
AzureIoTClient 0:1f9b2707ec7d 923 {
AzureIoTClient 0:1f9b2707ec7d 924 return Create_AGENT_DATA_TYPE_from_EDM_BINARY(dest, edmBinary);
AzureIoTClient 0:1f9b2707ec7d 925 }
AzureIoTClient 0:1f9b2707ec7d 926
AzureIoTClient 0:1f9b2707ec7d 927 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, EDM_BINARY)(const AGENT_DATA_TYPE* agentData, EDM_BINARY* dest)
AzureIoTClient 0:1f9b2707ec7d 928 {
AzureIoTClient 0:1f9b2707ec7d 929 AGENT_DATA_TYPES_RESULT result;
AzureIoTClient 0:1f9b2707ec7d 930 if (agentData->type != EDM_BINARY_TYPE)
AzureIoTClient 0:1f9b2707ec7d 931 {
AzureIoTClient 0:1f9b2707ec7d 932 result = AGENT_DATA_TYPES_INVALID_ARG;
AzureIoTClient 0:1f9b2707ec7d 933 }
AzureIoTClient 0:1f9b2707ec7d 934 else
AzureIoTClient 0:1f9b2707ec7d 935 {
AzureIoTClient 0:1f9b2707ec7d 936 if ((dest->data = (unsigned char *)malloc(agentData->value.edmBinary.size)) == NULL) /*cast because this get included in a C++ file.*/
AzureIoTClient 0:1f9b2707ec7d 937 {
AzureIoTClient 0:1f9b2707ec7d 938 result = AGENT_DATA_TYPES_ERROR;
AzureIoTClient 0:1f9b2707ec7d 939 }
AzureIoTClient 0:1f9b2707ec7d 940 else
AzureIoTClient 0:1f9b2707ec7d 941 {
AzureIoTClient 0:1f9b2707ec7d 942 memcpy(dest->data, agentData->value.edmBinary.data, agentData->value.edmBinary.size);
AzureIoTClient 0:1f9b2707ec7d 943 dest->size = agentData->value.edmBinary.size;
AzureIoTClient 0:1f9b2707ec7d 944 result = AGENT_DATA_TYPES_OK;
AzureIoTClient 0:1f9b2707ec7d 945 }
AzureIoTClient 0:1f9b2707ec7d 946 }
AzureIoTClient 0:1f9b2707ec7d 947 return result;
AzureIoTClient 0:1f9b2707ec7d 948 }
AzureIoTClient 0:1f9b2707ec7d 949
AzureIoTClient 0:1f9b2707ec7d 950 static void C2(destroyLocalParameter, EDM_BINARY)(EDM_BINARY* value)
AzureIoTClient 0:1f9b2707ec7d 951 {
AzureIoTClient 0:1f9b2707ec7d 952 if (value != NULL)
AzureIoTClient 0:1f9b2707ec7d 953 {
AzureIoTClient 0:1f9b2707ec7d 954 free(value->data);
AzureIoTClient 0:1f9b2707ec7d 955 value->data = NULL;
AzureIoTClient 0:1f9b2707ec7d 956 value->size = 0;
AzureIoTClient 0:1f9b2707ec7d 957 }
AzureIoTClient 0:1f9b2707ec7d 958 }
AzureIoTClient 0:1f9b2707ec7d 959
AzureIoTClient 0:1f9b2707ec7d 960 static void C2(destroyLocalParameter, EDM_BOOLEAN)(EDM_BOOLEAN* value)
AzureIoTClient 0:1f9b2707ec7d 961 {
AzureIoTClient 0:1f9b2707ec7d 962 (void)value;
AzureIoTClient 0:1f9b2707ec7d 963 }
AzureIoTClient 0:1f9b2707ec7d 964
AzureIoTClient 0:1f9b2707ec7d 965 static void C2(destroyLocalParameter, EDM_BYTE)(EDM_BYTE* value)
AzureIoTClient 0:1f9b2707ec7d 966 {
AzureIoTClient 0:1f9b2707ec7d 967 (void)value;
AzureIoTClient 0:1f9b2707ec7d 968 }
AzureIoTClient 0:1f9b2707ec7d 969
AzureIoTClient 0:1f9b2707ec7d 970 static void C2(destroyLocalParameter, EDM_DATE)(EDM_DATE* value)
AzureIoTClient 0:1f9b2707ec7d 971 {
AzureIoTClient 0:1f9b2707ec7d 972 (void)value;
AzureIoTClient 0:1f9b2707ec7d 973 }
AzureIoTClient 0:1f9b2707ec7d 974
AzureIoTClient 0:1f9b2707ec7d 975 static void C2(destroyLocalParameter, EDM_DATE_TIME_OFFSET)(EDM_DATE_TIME_OFFSET* value)
AzureIoTClient 0:1f9b2707ec7d 976 {
AzureIoTClient 0:1f9b2707ec7d 977 (void)value;
AzureIoTClient 0:1f9b2707ec7d 978 }
AzureIoTClient 0:1f9b2707ec7d 979
AzureIoTClient 0:1f9b2707ec7d 980 static void C2(destroyLocalParameter, EDM_DECIMAL)(EDM_DECIMAL* value)
AzureIoTClient 0:1f9b2707ec7d 981 {
AzureIoTClient 0:1f9b2707ec7d 982 if (value != NULL)
AzureIoTClient 0:1f9b2707ec7d 983 {
AzureIoTClient 0:1f9b2707ec7d 984 STRING_delete(value->value);
AzureIoTClient 0:1f9b2707ec7d 985 value->value = NULL;
AzureIoTClient 0:1f9b2707ec7d 986 }
AzureIoTClient 0:1f9b2707ec7d 987 }
AzureIoTClient 0:1f9b2707ec7d 988
AzureIoTClient 0:1f9b2707ec7d 989 static void C2(destroyLocalParameter, EDM_DOUBLE)(EDM_DOUBLE* value)
AzureIoTClient 0:1f9b2707ec7d 990 {
AzureIoTClient 0:1f9b2707ec7d 991 (void)value;
AzureIoTClient 0:1f9b2707ec7d 992 }
AzureIoTClient 0:1f9b2707ec7d 993
AzureIoTClient 0:1f9b2707ec7d 994 static void C2(destroyLocalParameter, EDM_DURATION)(EDM_DURATION* value)
AzureIoTClient 0:1f9b2707ec7d 995 {
AzureIoTClient 0:1f9b2707ec7d 996 if (value != NULL)
AzureIoTClient 0:1f9b2707ec7d 997 {
AzureIoTClient 0:1f9b2707ec7d 998 free(value->digits);
AzureIoTClient 0:1f9b2707ec7d 999 value->digits = NULL;
AzureIoTClient 0:1f9b2707ec7d 1000 value->nDigits = 0;
AzureIoTClient 0:1f9b2707ec7d 1001 }
AzureIoTClient 0:1f9b2707ec7d 1002 }
AzureIoTClient 0:1f9b2707ec7d 1003
AzureIoTClient 0:1f9b2707ec7d 1004 static void C2(destroyLocalParameter, EDM_GUID)(EDM_GUID* value)
AzureIoTClient 0:1f9b2707ec7d 1005 {
AzureIoTClient 0:1f9b2707ec7d 1006 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1007 }
AzureIoTClient 0:1f9b2707ec7d 1008
AzureIoTClient 0:1f9b2707ec7d 1009 static void C2(destroyLocalParameter, EDM_INT16)(EDM_INT16* value)
AzureIoTClient 0:1f9b2707ec7d 1010 {
AzureIoTClient 0:1f9b2707ec7d 1011 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1012 }
AzureIoTClient 0:1f9b2707ec7d 1013
AzureIoTClient 0:1f9b2707ec7d 1014 static void C2(destroyLocalParameter, EDM_INT32)(EDM_INT32* value)
AzureIoTClient 0:1f9b2707ec7d 1015 {
AzureIoTClient 0:1f9b2707ec7d 1016 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1017 }
AzureIoTClient 0:1f9b2707ec7d 1018
AzureIoTClient 0:1f9b2707ec7d 1019 static void C2(destroyLocalParameter, EDM_INT64)(EDM_INT64* value)
AzureIoTClient 0:1f9b2707ec7d 1020 {
AzureIoTClient 0:1f9b2707ec7d 1021 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1022 }
AzureIoTClient 0:1f9b2707ec7d 1023
AzureIoTClient 0:1f9b2707ec7d 1024 static void C2(destroyLocalParameter, EDM_SBYTE)(EDM_SBYTE* value)
AzureIoTClient 0:1f9b2707ec7d 1025 {
AzureIoTClient 0:1f9b2707ec7d 1026 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1027 }
AzureIoTClient 0:1f9b2707ec7d 1028
AzureIoTClient 0:1f9b2707ec7d 1029 static void C2(destroyLocalParameter, EDM_SINGLE)(EDM_SINGLE* value)
AzureIoTClient 0:1f9b2707ec7d 1030 {
AzureIoTClient 0:1f9b2707ec7d 1031 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1032 }
AzureIoTClient 0:1f9b2707ec7d 1033
AzureIoTClient 0:1f9b2707ec7d 1034 static void C2(destroyLocalParameter, EDM_STRING)(EDM_STRING* value)
AzureIoTClient 0:1f9b2707ec7d 1035 {
AzureIoTClient 0:1f9b2707ec7d 1036 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1037 }
AzureIoTClient 0:1f9b2707ec7d 1038
AzureIoTClient 0:1f9b2707ec7d 1039
AzureIoTClient 0:1f9b2707ec7d 1040 static void C2(destroyLocalParameter, EDM_TIME_OF_DAY)(EDM_TIME_OF_DAY* value)
AzureIoTClient 0:1f9b2707ec7d 1041 {
AzureIoTClient 0:1f9b2707ec7d 1042 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1043 }
AzureIoTClient 0:1f9b2707ec7d 1044
AzureIoTClient 0:1f9b2707ec7d 1045 static void C2(destroyLocalParameter, int)(int* value)
AzureIoTClient 0:1f9b2707ec7d 1046 {
AzureIoTClient 0:1f9b2707ec7d 1047 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1048 }
AzureIoTClient 0:1f9b2707ec7d 1049
AzureIoTClient 0:1f9b2707ec7d 1050 static void C2(destroyLocalParameter, float)(float* value)
AzureIoTClient 0:1f9b2707ec7d 1051 {
AzureIoTClient 0:1f9b2707ec7d 1052 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1053 }
AzureIoTClient 0:1f9b2707ec7d 1054
AzureIoTClient 0:1f9b2707ec7d 1055 static void C2(destroyLocalParameter, double)(double* value)
AzureIoTClient 0:1f9b2707ec7d 1056 {
AzureIoTClient 0:1f9b2707ec7d 1057 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1058 }
AzureIoTClient 0:1f9b2707ec7d 1059
AzureIoTClient 0:1f9b2707ec7d 1060 static void C2(destroyLocalParameter, long)(long* value)
AzureIoTClient 0:1f9b2707ec7d 1061 {
AzureIoTClient 0:1f9b2707ec7d 1062 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1063 }
AzureIoTClient 0:1f9b2707ec7d 1064
AzureIoTClient 0:1f9b2707ec7d 1065 static void C2(destroyLocalParameter, int8_t)(int8_t* value)
AzureIoTClient 0:1f9b2707ec7d 1066 {
AzureIoTClient 0:1f9b2707ec7d 1067 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1068 }
AzureIoTClient 0:1f9b2707ec7d 1069
AzureIoTClient 0:1f9b2707ec7d 1070 static void C2(destroyLocalParameter, uint8_t)(uint8_t* value)
AzureIoTClient 0:1f9b2707ec7d 1071 {
AzureIoTClient 0:1f9b2707ec7d 1072 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1073 }
AzureIoTClient 0:1f9b2707ec7d 1074
AzureIoTClient 0:1f9b2707ec7d 1075 static void C2(destroyLocalParameter, int16_t)(int16_t* value)
AzureIoTClient 0:1f9b2707ec7d 1076 {
AzureIoTClient 0:1f9b2707ec7d 1077 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1078 }
AzureIoTClient 0:1f9b2707ec7d 1079
AzureIoTClient 0:1f9b2707ec7d 1080 static void C2(destroyLocalParameter, int32_t)(int32_t* value)
AzureIoTClient 0:1f9b2707ec7d 1081 {
AzureIoTClient 0:1f9b2707ec7d 1082 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1083 }
AzureIoTClient 0:1f9b2707ec7d 1084
AzureIoTClient 0:1f9b2707ec7d 1085 static void C2(destroyLocalParameter, int64_t)(int64_t* value)
AzureIoTClient 0:1f9b2707ec7d 1086 {
AzureIoTClient 0:1f9b2707ec7d 1087 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1088 }
AzureIoTClient 0:1f9b2707ec7d 1089
AzureIoTClient 0:1f9b2707ec7d 1090 static void C2(destroyLocalParameter, bool)(bool* value)
AzureIoTClient 0:1f9b2707ec7d 1091 {
AzureIoTClient 0:1f9b2707ec7d 1092 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1093 }
AzureIoTClient 0:1f9b2707ec7d 1094
AzureIoTClient 0:1f9b2707ec7d 1095 static void C2(destroyLocalParameter, ascii_char_ptr)(ascii_char_ptr* value)
AzureIoTClient 0:1f9b2707ec7d 1096 {
AzureIoTClient 0:1f9b2707ec7d 1097 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1098 }
AzureIoTClient 0:1f9b2707ec7d 1099
AzureIoTClient 0:1f9b2707ec7d 1100 static void C2(destroyLocalParameter, ascii_char_ptr_no_quotes)(ascii_char_ptr_no_quotes* value)
AzureIoTClient 0:1f9b2707ec7d 1101 {
AzureIoTClient 0:1f9b2707ec7d 1102 (void)value;
AzureIoTClient 0:1f9b2707ec7d 1103 }
AzureIoTClient 0:1f9b2707ec7d 1104
AzureIoTClient 0:1f9b2707ec7d 1105 #ifdef __cplusplus
AzureIoTClient 0:1f9b2707ec7d 1106 }
AzureIoTClient 0:1f9b2707ec7d 1107 #endif
AzureIoTClient 0:1f9b2707ec7d 1108
AzureIoTClient 0:1f9b2707ec7d 1109 #endif /*SERIALIZER_H*/
AzureIoTClient 0:1f9b2707ec7d 1110
AzureIoTClient 0:1f9b2707ec7d 1111