Azure IoT / serializer

Dependents:   sht15_remote_monitoring f767zi_mqtt remote_monitoring simplesample_amqp ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers serializer.h Source File

serializer.h

Go to the documentation of this file.
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 /** @file   serializer.h
00005 *    @brief    The IoT Hub Serializer APIs allows developers to define models for
00006 *            their devices
00007 *
00008 *    @details    The IoT Hub Serializer APIs allows developers to quickly and easily define
00009 *                models for their devices directly as code, while supporting the required
00010 *                features for modeling devices (including multiple models and multiple
00011 *                devices within the same application). For example:
00012 *
00013 *        <pre>
00014 *       BEGIN_NAMESPACE(Contoso);
00015 *
00016 *           DECLARE_STRUCT(SystemProperties,
00017 *               ascii_char_ptr, DeviceID,
00018 *               _Bool, Enabled
00019 *           );
00020 *
00021 *           DECLARE_MODEL(VendingMachine,
00022 *
00023 *               WITH_DATA(int, SensorValue),
00024 *
00025 *               WITH_DATA(ascii_char_ptr, ObjectName),
00026 *               WITH_DATA(ascii_char_ptr, ObjectType),
00027 *               WITH_DATA(ascii_char_ptr, Version),
00028 *               WITH_DATA(SystemProperties, SystemProperties),
00029 *               WITH_DATA(ascii_char_ptr_no_quotes, Commands),
00030 *
00031 *               WITH_ACTION(SetItemPrice, ascii_char_ptr, itemId, ascii_char_ptr, price)
00032 *           );
00033 *
00034 *       END_NAMESPACE(Contoso);
00035 *       </pre>
00036 */
00037 
00038 #ifndef SERIALIZER_H
00039 #define SERIALIZER_H
00040 
00041 #ifdef __cplusplus
00042 #include <cstdlib>
00043 #include <cstdarg>
00044 
00045 #else
00046 #include <stdlib.h>
00047 #include <stdarg.h>
00048 #endif
00049 
00050 #include "azure_c_shared_utility/gballoc.h"
00051 #include "azure_c_shared_utility/macro_utils.h"
00052 #include "iotdevice.h"
00053 #include "azure_c_shared_utility/crt_abstractions.h"
00054 #include "azure_c_shared_utility/xlogging.h"
00055 #include "methodreturn.h"
00056 #include "schemalib.h"
00057 #include "codefirst.h"
00058 #include "agenttypesystem.h"
00059 #include "schema.h"
00060 
00061 
00062 
00063 #ifdef __cplusplus
00064 extern "C"
00065 {
00066 #endif
00067 
00068     /* IOT Agent Macros */
00069 
00070     /**
00071      * @def BEGIN_NAMESPACE(schemaNamespace)
00072      * This macro marks the start of a section that declares IOT model
00073      * elements (like complex types, etc.). Declarations are typically
00074      * placed in header files, so that they can be shared between
00075      * translation units.
00076      */
00077      /* 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.] */
00078 #define BEGIN_NAMESPACE(schemaNamespace) \
00079     REFLECTED_END_OF_LIST
00080 
00081 /**
00082 * @def END_NAMESPACE(schemaNamespace)
00083 * This macro marks the end of a section that declares IOT model
00084 * elements.
00085 */
00086 #define END_NAMESPACE(schemaNamespace) \
00087     REFLECTED_LIST_HEAD(schemaNamespace)
00088 
00089 #define GLOBAL_INITIALIZE_STRUCT_FIELD(structType, destination, type, name) GlobalInitialize_##type((char*)destination+offsetof(structType, name));
00090 #define GLOBAL_DEINITIALIZE_STRUCT_FIELD(structType, destination, type, name) GlobalDeinitialize_##type((char*)destination+offsetof(structType, name));
00091 /**
00092 * @def DECLARE_STRUCT(name, ...)
00093 * This macro allows the definition of a struct type that can then be used as
00094 * part of a model definition.
00095 *
00096 * @param name                      Name of the struct
00097 * @param element1, element2...     Specifies a list of struct members
00098 */
00099 /* Codes_SRS_SERIALIZER_99_080:[ The DECLARE_STRUCT declaration shall insert metadata describing a complex data type.] */
00100 #define DECLARE_STRUCT(name, ...) \
00101     /* 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.] */ \
00102     typedef struct name##_TAG { \
00103         FOR_EACH_2(INSERT_FIELD_INTO_STRUCT, __VA_ARGS__) \
00104     } name; \
00105     /* Codes_SRS_SERIALIZER_99_081:[ DECLARE_STRUCT's name argument shall uniquely identify the struct within the schema.] */ \
00106     REFLECTED_STRUCT(name) \
00107     /* Codes_SRS_SERIALIZER_99_082:[ DECLARE_STRUCT's field<n>Name argument shall uniquely name a field within the struct.] */ \
00108     FOR_EACH_2_KEEP_1(REFLECTED_FIELD, name, __VA_ARGS__) \
00109     TO_AGENT_DATA_TYPE(name, __VA_ARGS__) \
00110     /*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.]*/ \
00111     static AGENT_DATA_TYPES_RESULT FromAGENT_DATA_TYPE_##name(const AGENT_DATA_TYPE* source, name* destination) \
00112     { \
00113         AGENT_DATA_TYPES_RESULT result; \
00114         if(source->type != EDM_COMPLEX_TYPE_TYPE) \
00115         { \
00116             result = AGENT_DATA_TYPES_INVALID_ARG; \
00117         } \
00118         else if(DIV2(COUNT_ARG(__VA_ARGS__)) != source->value.edmComplexType.nMembers) \
00119         { \
00120             /*too many or too few fields*/ \
00121             result = AGENT_DATA_TYPES_INVALID_ARG; \
00122         } \
00123         else \
00124         { \
00125             result = AGENT_DATA_TYPES_OK; \
00126             FOR_EACH_2(BUILD_DESTINATION_FIELD, __VA_ARGS__); \
00127         } \
00128         return result; \
00129     } \
00130     static void C2(destroyLocalParameter, name)(name * value) \
00131     { \
00132         FOR_EACH_2_KEEP_1(UNBUILD_DESTINATION_FIELD, value, __VA_ARGS__); \
00133     } \
00134     static void C2(GlobalInitialize_, name)(void* destination) \
00135     { \
00136         FOR_EACH_2_KEEP_2(GLOBAL_INITIALIZE_STRUCT_FIELD, name, destination, __VA_ARGS__); \
00137     } \
00138     static void C2(GlobalDeinitialize_, name)(void* destination) \
00139     { \
00140         FOR_EACH_2_KEEP_2(GLOBAL_DEINITIALIZE_STRUCT_FIELD, name, destination, __VA_ARGS__); \
00141     } \
00142 
00143 
00144 /**
00145  * @def     DECLARE_MODEL(name, ...)
00146  * This macro allows declaring a model that can be later used to instantiate
00147  * a device.
00148  *
00149  * @param   name                        Specifies the model name
00150  * @param   element1, element2...       Specifies a model element which can be
00151  *                                         a property or an action.
00152  *                                             - A property is described in a
00153  *                                               model by using the WITH_DATA
00154  *                                             - An action is described in a
00155  *                                               model by using the ::WITH_ACTION
00156  *                                               macro.
00157  *
00158  */
00159  /* WITH_DATA's name argument shall be one of the following data types: */
00160  /* Codes_SRS_SERIALIZER_99_133:[a model type introduced previously by DECLARE_MODEL] */
00161 
00162 #define CREATE_DESIRED_PROPERTY_CALLBACK_MODEL_ACTION(...)
00163 #define CREATE_DESIRED_PROPERTY_CALLBACK_MODEL_METHOD(...)
00164 #define CREATE_DESIRED_PROPERTY_CALLBACK_MODEL_DESIRED_PROPERTY(type, name, ...) IF(COUNT_ARG(__VA_ARGS__), void __VA_ARGS__ (void*);, )
00165 #define CREATE_DESIRED_PROPERTY_CALLBACK_MODEL_PROPERTY(...)
00166 #define CREATE_DESIRED_PROPERTY_CALLBACK_MODEL_REPORTED_PROPERTY(...)
00167 
00168 #define CREATE_DESIRED_PROPERTY_CALLBACK(...) CREATE_DESIRED_PROPERTY_CALLBACK_##__VA_ARGS__
00169 
00170 #define SERIALIZER_REGISTER_NAMESPACE(NAMESPACE) CodeFirst_RegisterSchema(#NAMESPACE, & ALL_REFLECTED(NAMESPACE))
00171 
00172 #define DECLARE_MODEL(name, ...)                                                             \
00173     REFLECTED_MODEL(name)                                                                    \
00174     FOR_EACH_1(CREATE_DESIRED_PROPERTY_CALLBACK, __VA_ARGS__)                                \
00175     typedef struct name { int :1; FOR_EACH_1(BUILD_MODEL_STRUCT, __VA_ARGS__) } name;        \
00176     FOR_EACH_1_KEEP_1(CREATE_MODEL_ELEMENT, name, __VA_ARGS__)                               \
00177     TO_AGENT_DATA_TYPE(name, DROP_FIRST_COMMA_FROM_ARGS(EXPAND_MODEL_ARGS(__VA_ARGS__)))     \
00178     int FromAGENT_DATA_TYPE_##name(const AGENT_DATA_TYPE* source, void* destination)         \
00179     {                                                                                        \
00180         (void)source;                                                                        \
00181         (void)destination;                                                                   \
00182         LogError("SHOULD NOT GET CALLED... EVER");                                           \
00183         return 0;                                                                            \
00184     }                                                                                        \
00185     static void C2(GlobalInitialize_, name)(void* destination)                               \
00186     {                                                                                        \
00187         (void)destination;                                                                   \
00188         FOR_EACH_1_KEEP_1(CREATE_MODEL_ELEMENT_GLOBAL_INITIALIZE, name, __VA_ARGS__)         \
00189     }                                                                                        \
00190     static void C2(GlobalDeinitialize_, name)(void* destination)                             \
00191     {                                                                                        \
00192         (void)destination;                                                                   \
00193         FOR_EACH_1_KEEP_1(CREATE_MODEL_ELEMENT_GLOBAL_DEINITIALIZE, name, __VA_ARGS__)       \
00194     }                                                                                        \
00195 
00196 
00197 
00198 /**
00199  * @def   WITH_DATA(type, name)
00200  * The ::WITH_DATA macro allows declaring a model property in a model. A
00201  * property can be published by using the ::SERIALIZE macro.
00202  *
00203  * @param   type    Specifies the property type. Can be any of the following
00204  *                  types:
00205  *                   - int
00206  *                   - double
00207  *                   - float
00208  *                   - long
00209  *                   - int8_t
00210  *                   - uint8_t
00211  *                   - int16_t
00212  *                   - int32_t
00213  *                   - int64_t
00214  *                   - bool
00215  *                   - ascii_char_ptr
00216  *                   - EDM_DATE_TIME_OFFSET
00217  *                   - EDM_GUID
00218  *                   - EDM_BINARY
00219  *                   - Any struct type previously introduced by another ::DECLARE_STRUCT.
00220  *
00221  * @param   name    Specifies the property name
00222  */
00223 #define WITH_DATA(type, name) MODEL_PROPERTY(type, name)
00224 
00225 
00226 #define WITH_REPORTED_PROPERTY(type, name) MODEL_REPORTED_PROPERTY(type, name)
00227 
00228 #define WITH_DESIRED_PROPERTY(type, name, ...) MODEL_DESIRED_PROPERTY(type, name, __VA_ARGS__)
00229 
00230 /**
00231  * @def   WITH_ACTION(name, ...)
00232  * The ::WITH_ACTION macro allows declaring a model action.
00233  *
00234  * @param   name                    Specifies the action name.
00235  * @param   argXtype, argXName...   Defines the type and name for the X<sup>th</sup>
00236  *                                  argument of the action. The type can be any of
00237  *                                  the primitive types or a struct type.
00238  */
00239 /*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.]*/
00240 #define WITH_ACTION(name, ...)  MODEL_ACTION(name, __VA_ARGS__)
00241 
00242 
00243 /**
00244 * @def   WITH_METHOD(name, ...)
00245 * The ::WITH_METHOD macro allows declaring a model method.
00246 *
00247 * @param   name                    Specifies the method name.
00248 * @param   argXtype, argXName...   Defines the type and name for the X<sup>th</sup>
00249 *                                  argument of the method. The type can be any of
00250 *                                  the primitive types or a struct type.
00251 */
00252 /*Codes_SRS_SERIALIZER_H_02_029: [ WITH_METHOD shall declare a function with the signature 'METHODRETURN_HANDLE name(param1Type param1Name, ...)', which the developer can define to receive corresponding commands from the IoT service. ]*/
00253 #define WITH_METHOD(name, ...)  MODEL_METHOD(name, __VA_ARGS__)
00254 
00255 
00256 /**
00257  * @def   GET_MODEL_HANDLE(schemaNamespace, modelName)
00258  * The ::GET_MODEL_HANDLE macro returns a model handle that can be used in
00259  * subsequent operations like generating the CSDL schema for the model,
00260  * uploading the schema, creating a device, etc.
00261  *
00262  * @param   schemaNamespace The namespace to which the model belongs.
00263  * @param   modelName       The name of the model.
00264  */
00265 /* 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.] */
00266 /* 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.] */
00267 /* Codes_SRS_SERIALIZER_99_112:[ GET_MODEL_HANDLE will return the handle for the named model.] */
00268 #define GET_MODEL_HANDLE(schemaNamespace, modelName) \
00269     Schema_GetModelByName(CodeFirst_RegisterSchema(TOSTRING(schemaNamespace), &ALL_REFLECTED(schemaNamespace)), #modelName)
00270 
00271 /* Codes_SRS_SERIALIZER_01_002: [If the argument serializerIncludePropertyPath is specified, its value shall be passed to CodeFirst_Create.] */
00272 #define CREATE_DEVICE_WITH_INCLUDE_PROPERTY_PATH(schemaNamespace, modelName, serializerIncludePropertyPath) \
00273     (modelName*)CodeFirst_CreateDevice(GET_MODEL_HANDLE(schemaNamespace, modelName), &ALL_REFLECTED(schemaNamespace), sizeof(modelName), serializerIncludePropertyPath)
00274 
00275 /* Codes_SRS_SERIALIZER_01_003: [If the argument serializerIncludePropertyPath is not specified, CREATE_MODEL_INSTANCE shall pass false to CodeFirst_Create.] */
00276 #define CREATE_DEVICE_WITHOUT_INCLUDE_PROPERTY_PATH(schemaNamespace, modelName) \
00277     (modelName*)CodeFirst_CreateDevice(GET_MODEL_HANDLE(schemaNamespace, modelName), &ALL_REFLECTED(schemaNamespace), sizeof(modelName), false)
00278 
00279 /* 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.] */
00280 /* Codes_SRS_SERIALIZER_99_106:[ CREATE_MODEL_INSTANCE shall call CodeFirst_CreateDevice, passing the model handle (SCHEMA_MODEL_TYPE_HANDLE]*/
00281 /* Codes_SRS_SERIALIZER_99_107:[ If CodeFirst_CreateDevice fails, CREATE_MODEL_INSTANCE shall return NULL.] */
00282 /* 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.] */
00283 #define CREATE_MODEL_INSTANCE(schemaNamespace, ...) \
00284     IF(DIV2(COUNT_ARG(__VA_ARGS__)), CREATE_DEVICE_WITH_INCLUDE_PROPERTY_PATH, CREATE_DEVICE_WITHOUT_INCLUDE_PROPERTY_PATH) (schemaNamespace, __VA_ARGS__)
00285 
00286 /* 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.] */
00287 #define DESTROY_MODEL_INSTANCE(deviceData) \
00288     CodeFirst_DestroyDevice(deviceData)
00289 
00290 /**
00291  * @def      SERIALIZE(destination, destinationSize,...)
00292  * This macro produces JSON serialized representation of the properties.
00293  *
00294  * @param   destination                  Pointer to an @c unsigned @c char* that
00295  *                                       will receive the serialized data.
00296  * @param   destinationSize              Pointer to a @c size_t that gets
00297  *                                       written with the size in bytes of the
00298  *                                       serialized data
00299  * @param    property1, property2...     A list of property values to send. The
00300  *                                       order in which the properties appear in
00301  *                                       the list does not matter, all values
00302  *                                       will be sent together.
00303  *
00304  */
00305 /*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.] */
00306 /*Codes_SRS_SERIALIZER_99_117:[ If CodeFirst_SendAsync succeeds, SEND will return IOT_AGENT_OK.] */
00307 /*Codes_SRS_SERIALIZER_99_114:[ If CodeFirst_SendAsync fails, SEND shall return IOT_AGENT_SERIALIZE_FAILED.] */
00308 #define SERIALIZE(destination, destinationSize,...) CodeFirst_SendAsync(destination, destinationSize, COUNT_ARG(__VA_ARGS__) FOR_EACH_1(ADDRESS_MACRO, __VA_ARGS__))
00309 
00310 #define SERIALIZE_REPORTED_PROPERTIES(destination, destinationSize,...) CodeFirst_SendAsyncReported(destination, destinationSize, COUNT_ARG(__VA_ARGS__) FOR_EACH_1(ADDRESS_MACRO, __VA_ARGS__))
00311 
00312 
00313 #define IDENTITY_MACRO(x) ,x
00314 #define SERIALIZE_REPORTED_PROPERTIES_FROM_POINTERS(destination, destinationSize, ...) CodeFirst_SendAsyncReported(destination, destinationSize, COUNT_ARG(__VA_ARGS__) FOR_EACH_1(IDENTITY_MACRO, __VA_ARGS__))
00315 
00316 /**
00317  * @def   EXECUTE_COMMAND(device, command)
00318  * Any action that is declared in a model must also have an implementation as
00319  * a C function.
00320  *
00321  * @param   device      Pointer to device data.
00322  * @param   command     Values that match the arguments declared in the model
00323  *                      action.
00324  */
00325 /*Codes_SRS_SERIALIZER_02_018: [EXECUTE_COMMAND macro shall call CodeFirst_ExecuteCommand passing device, commandBuffer and commandBufferSize.]*/
00326 #define EXECUTE_COMMAND(device, command) (CodeFirst_ExecuteCommand(device, command))
00327 
00328 /**
00329 * @def   EXECUTE_METHOD(device, methodName, methodPayload)
00330 * Any method that is declared in a model must also have an implementation as
00331 * a C function.
00332 *
00333 * @param   device      Pointer to device data.
00334 * @param   methodName       The method name.
00335 * @param   methodPayload    The method payload.
00336 */
00337 #define EXECUTE_METHOD(device, methodName, methodPayload) CodeFirst_ExecuteMethod(device, methodName, methodPayload)
00338 
00339 /**
00340 * @def   INGEST_DESIRED_PROPERTIES(device, desiredProperties)
00341 *
00342 * @param   device                return of CodeFirst_CreateDevice.
00343 * @param   desiredProperties     a null terminated string containing in JSON format the desired properties
00344 */
00345 #define INGEST_DESIRED_PROPERTIES(device, jsonPayload, parseDesiredNode) (CodeFirst_IngestDesiredProperties(device, jsonPayload, parseDesiredNode))
00346 
00347 /* Helper macros */
00348 
00349 /* These macros remove a useless comma from the beginning of an argument list that looks like:
00350 ,x1,y1,x2,y2 */
00351 #ifdef _MSC_VER
00352 
00353 #define DROP_FIRST_COMMA(N, x) \
00354 x IFCOMMA_NOFIRST(N)
00355 
00356 #define DROP_IF_EMPTY(N, x) \
00357 IF(COUNT_ARG(x),DROP_FIRST_COMMA(N,x),x)
00358 
00359 #define DROP_FIRST_COMMA_FROM_ARGS(...) \
00360 FOR_EACH_1_COUNTED(DROP_IF_EMPTY, C1(__VA_ARGS__))
00361 
00362 #else
00363 
00364 #define DROP_FIRST_COMMA_0(N, x) \
00365     x IFCOMMA_NOFIRST(N)
00366 
00367 #define DROP_FIRST_COMMA_1(N, x) \
00368     x
00369 
00370 #define DROP_FIRST_COMMA(empty, N, x) \
00371     C2(DROP_FIRST_COMMA_,empty)(N,x)
00372 
00373 #define DROP_IF_EMPTY(N, x) \
00374     DROP_FIRST_COMMA(ISEMPTY(x),N,x)
00375 
00376 #define DROP_FIRST_COMMA_FROM_ARGS(...) \
00377     FOR_EACH_1_COUNTED(DROP_IF_EMPTY, __VA_ARGS__)
00378 
00379 #endif
00380 
00381 /* These macros expand a sequence of arguments for DECLARE_MODEL that looks like
00382 WITH_DATA(x, y), WITH_DATA(x2, y2) to a list of arguments consumed by the macro that marshalls a struct, like:
00383 x, y, x2, y2
00384 Actions are discarded, since no marshalling will be done for those when sending state data */
00385 #define TO_AGENT_DT_EXPAND_MODEL_PROPERTY(x, y) ,x,y
00386 
00387 #define TO_AGENT_DT_EXPAND_MODEL_REPORTED_PROPERTY(x, y) ,x,y
00388 
00389 #define TO_AGENT_DT_EXPAND_MODEL_DESIRED_PROPERTY(x, y, ...) ,x,y
00390 
00391 #define TO_AGENT_DT_EXPAND_MODEL_ACTION(...)
00392 
00393 #define TO_AGENT_DT_EXPAND_MODEL_METHOD(...)
00394 
00395 #define TO_AGENT_DT_EXPAND_ELEMENT_ARGS(N, ...) TO_AGENT_DT_EXPAND_##__VA_ARGS__
00396 
00397 #define EXPAND_MODEL_ARGS(...) \
00398     FOR_EACH_1_COUNTED(TO_AGENT_DT_EXPAND_ELEMENT_ARGS, __VA_ARGS__)
00399 
00400 #define TO_AGENT_DATA_TYPE(name, ...) \
00401     static AGENT_DATA_TYPES_RESULT ToAGENT_DATA_TYPE_##name(AGENT_DATA_TYPE *destination, const name value) \
00402     { \
00403         AGENT_DATA_TYPES_RESULT result = AGENT_DATA_TYPES_OK; \
00404         size_t iMember = 0; \
00405         DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(phantomName, 1); \
00406         const char* memberNames[IF(DIV2(C1(COUNT_ARG(__VA_ARGS__))), DIV2(C1(COUNT_ARG(__VA_ARGS__))), 1)] = { 0 }; \
00407         size_t memberCount = sizeof(memberNames) / sizeof(memberNames[0]); \
00408         (void)value; \
00409         if (memberCount == 0) \
00410         { \
00411             result = AGENT_DATA_TYPES_OK; \
00412         } \
00413         else \
00414         { \
00415             AGENT_DATA_TYPE members[sizeof(memberNames) / sizeof(memberNames[0])]; \
00416             DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(phantomName, 2); \
00417             FOR_EACH_2(FIELD_AS_STRING, EXPAND_TWICE(__VA_ARGS__)) \
00418             iMember = 0; \
00419             { \
00420                 DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(phantomName, 3); \
00421                 FOR_EACH_2(CREATE_AGENT_DATA_TYPE, EXPAND_TWICE(__VA_ARGS__)) \
00422                 {DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(phantomName, 4); } \
00423                 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)) \
00424                             ? AGENT_DATA_TYPES_OK \
00425                             : AGENT_DATA_TYPES_ERROR; \
00426                 { \
00427                     size_t jMember; \
00428                     for (jMember = 0; jMember < iMember; jMember++) \
00429                     { \
00430                         Destroy_AGENT_DATA_TYPE(&members[jMember]); \
00431                     } \
00432                 } \
00433             } \
00434         } \
00435         return result; \
00436     }
00437 
00438 #define FIELD_AS_STRING(x,y) memberNames[iMember++] = #y;
00439 
00440 #define REFLECTED_LIST_HEAD(name) \
00441     static const REFLECTED_DATA_FROM_DATAPROVIDER ALL_REFLECTED(name) = { &C2(REFLECTED_, C1(DEC(__COUNTER__))) };
00442 #define REFLECTED_STRUCT(name) \
00443     static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(__COUNTER__))) = { REFLECTION_STRUCT_TYPE,               &C2(REFLECTED_, C1(DEC(DEC(__COUNTER__)))), { {0}, {0}, {0}, {TOSTRING(name)}, {0}, {0}, {0}, {0}} };
00444 #define REFLECTED_FIELD(XstructName, XfieldType, XfieldName) \
00445     static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(__COUNTER__))) = { REFLECTION_FIELD_TYPE,                &C2(REFLECTED_, C1(DEC(DEC(__COUNTER__)))), { {0}, {0}, {0}, {0}, {TOSTRING(XfieldName), TOSTRING(XfieldType), TOSTRING(XstructName)}, {0}, {0}, {0} } };
00446 #define REFLECTED_MODEL(name) \
00447     static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(__COUNTER__))) = { REFLECTION_MODEL_TYPE,                &C2(REFLECTED_, C1(DEC(DEC(__COUNTER__)))), { {0}, {0}, {0}, {0}, {0}, {0}, {0}, {TOSTRING(name)} } };
00448 #define REFLECTED_PROPERTY(type, name, modelName) \
00449     static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(__COUNTER__))) = { REFLECTION_PROPERTY_TYPE,             &C2(REFLECTED_, C1(DEC(DEC(__COUNTER__)))), { {0}, {0}, {0}, {0}, {0}, {TOSTRING(name), TOSTRING(type), Create_AGENT_DATA_TYPE_From_Ptr_##modelName##name, offsetof(modelName, name), sizeof(type), TOSTRING(modelName)}, {0}, {0} } };
00450 #define REFLECTED_REPORTED_PROPERTY(type, name, modelName) \
00451     static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(__COUNTER__))) = { REFLECTION_REPORTED_PROPERTY_TYPE,    &C2(REFLECTED_, C1(DEC(DEC(__COUNTER__)))), { {0}, {0}, {TOSTRING(name), TOSTRING(type), Create_AGENT_DATA_TYPE_From_Ptr_##modelName##name, offsetof(modelName, name), sizeof(type), TOSTRING(modelName)}, {0}, {0}, {0}, {0}, {0} } };
00452 
00453 
00454 #define REFLECTED_DESIRED_PROPERTY_WITH_ON_DESIRED_PROPERTY_CHANGE(type, name, modelName, COUNTER, onDesiredPropertyChange) \
00455     static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(COUNTER))) =      { REFLECTION_DESIRED_PROPERTY_TYPE,     &C2(REFLECTED_, C1(DEC(COUNTER))),         { {0}, {onDesiredPropertyChange, DesiredPropertyInitialize_##modelName##name, DesiredPropertyDeinitialize_##modelName##name, TOSTRING(name), TOSTRING(type), (int(*)(const AGENT_DATA_TYPE*, void*))FromAGENT_DATA_TYPE_##type, offsetof(modelName, name), sizeof(type), TOSTRING(modelName)}, {0}, {0}, {0}, {0}, {0}, {0}} };
00456 
00457 #define REFLECTED_DESIRED_PROPERTY(type, name, modelName, ...)                                                              \
00458     IF(COUNT_ARG(__VA_ARGS__),                                                                                              \
00459         MACRO_UTILS_DELAY(REFLECTED_DESIRED_PROPERTY_WITH_ON_DESIRED_PROPERTY_CHANGE)(type, name, modelName,__COUNTER__, __VA_ARGS__),  \
00460         MACRO_UTILS_DELAY(REFLECTED_DESIRED_PROPERTY_WITH_ON_DESIRED_PROPERTY_CHANGE)(type, name, modelName,DEC(__COUNTER__), NULL)     \
00461     )                                                                                                                       \
00462 
00463 #define REFLECTED_ACTION(name, argc, argv, fn, modelName) \
00464     static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(__COUNTER__))) = { REFLECTION_ACTION_TYPE,               &C2(REFLECTED_, C1(DEC(DEC(__COUNTER__)))), { {0}, {0}, {0}, {0}, {0}, {0}, {TOSTRING(name), argc, argv, fn, TOSTRING(modelName)}, {0}} };
00465 
00466 #define REFLECTED_METHOD(name, argc, argv, fn, modelName) \
00467     static const REFLECTED_SOMETHING C2(REFLECTED_, C1(INC(__COUNTER__))) = { REFLECTION_METHOD_TYPE,               &C2(REFLECTED_, C1(DEC(DEC(__COUNTER__)))), { {TOSTRING(name), argc, argv, fn, TOSTRING(modelName)}, {0}, {0}, {0}, {0}, {0}, {0}, {0}} };
00468 
00469 
00470 #define REFLECTED_END_OF_LIST \
00471     static const REFLECTED_SOMETHING C2(REFLECTED_, __COUNTER__) = {          REFLECTION_NOTHING,                   NULL,                                       { {0},{0}, {0}, {0}, {0}, {0}, {0}, {0}} };
00472 
00473 #define EXPAND_MODEL_PROPERTY(type, name) EXPAND_ARGS(MODEL_PROPERTY, type, name)
00474 
00475 #define EXPAND_MODEL_REPORTED_PROPERTY(type, name) EXPAND_ARGS(MODEL_REPORTED_PROPERTY, type, name)
00476 
00477 #define EXPAND_MODEL_DESIRED_PROPERTY(type, name, ...) EXPAND_ARGS(MODEL_DESIRED_PROPERTY, type, name, __VA_ARGS__)
00478 
00479 #define EXPAND_MODEL_ACTION(...) EXPAND_ARGS(MODEL_ACTION, __VA_ARGS__)
00480 
00481 #define EXPAND_MODEL_METHOD(...) EXPAND_ARGS(MODEL_METHOD, __VA_ARGS__)
00482 
00483 #define BUILD_MODEL_STRUCT(elem) INSERT_FIELD_FOR_##elem
00484 
00485 #define CREATE_MODEL_ENTITY(modelName, callType, ...) EXPAND_ARGS(CREATE_##callType(modelName, __VA_ARGS__))
00486 #define CREATE_SOMETHING(modelName, ...) EXPAND_ARGS(CREATE_MODEL_ENTITY(modelName, __VA_ARGS__))
00487 #define CREATE_ELEMENT(modelName, elem) EXPAND_ARGS(CREATE_SOMETHING(modelName, EXPAND_ARGS(EXPAND_##elem)))
00488 
00489 #define CREATE_MODEL_ELEMENT(modelName, elem) EXPAND_ARGS(CREATE_ELEMENT(modelName, elem))
00490 
00491 
00492 #define CREATE_MODEL_ENTITY_GLOBAL_INITIALIZATION(modelName, callType, ...) EXPAND_ARGS(CREATE_GLOBAL_INITIALIZE_##callType(modelName, __VA_ARGS__))
00493 #define CREATE_SOMETHING_GLOBAL_INITIALIZATION(modelName, ...) EXPAND_ARGS(CREATE_MODEL_ENTITY_GLOBAL_INITIALIZATION(modelName, __VA_ARGS__))
00494 #define CREATE_ELEMENT_GLOBAL_INITIALIZATION(modelName, elem) EXPAND_ARGS(CREATE_SOMETHING_GLOBAL_INITIALIZATION(modelName, EXPAND_ARGS(EXPAND_##elem)))
00495 #define CREATE_MODEL_ELEMENT_GLOBAL_INITIALIZE(modelName, elem) EXPAND_ARGS(CREATE_ELEMENT_GLOBAL_INITIALIZATION(modelName, elem))
00496 
00497 #define CREATE_MODEL_ENTITY_GLOBAL_DEINITIALIZATION(modelName, callType, ...) EXPAND_ARGS(CREATE_GLOBAL_DEINITIALIZE_##callType(modelName, __VA_ARGS__))
00498 #define CREATE_SOMETHING_GLOBAL_DEINITIALIZATION(modelName, ...) EXPAND_ARGS(CREATE_MODEL_ENTITY_GLOBAL_DEINITIALIZATION(modelName, __VA_ARGS__))
00499 #define CREATE_ELEMENT_GLOBAL_DEINITIALIZATION(modelName, elem) EXPAND_ARGS(CREATE_SOMETHING_GLOBAL_DEINITIALIZATION(modelName, EXPAND_ARGS(EXPAND_##elem)))
00500 #define CREATE_MODEL_ELEMENT_GLOBAL_DEINITIALIZE(modelName, elem) EXPAND_ARGS(CREATE_ELEMENT_GLOBAL_DEINITIALIZATION(modelName, elem))
00501 
00502 #define INSERT_FIELD_INTO_STRUCT(x, y) x y;
00503 
00504 
00505 #define INSERT_FIELD_FOR_MODEL_PROPERTY(type, name) INSERT_FIELD_INTO_STRUCT(type, name)
00506 #define CREATE_GLOBAL_INITIALIZE_MODEL_PROPERTY(modelName, type, name) /*do nothing, this is written by user*/
00507 #define CREATE_GLOBAL_DEINITIALIZE_MODEL_PROPERTY(modelName, type, name) /*do nothing, this is user's stuff*/
00508 
00509 /*REPORTED_PROPERTY is not different than regular WITH_DATA*/
00510 #define INSERT_FIELD_FOR_MODEL_REPORTED_PROPERTY(type, name) INSERT_FIELD_INTO_STRUCT(type, name)
00511 #define CREATE_GLOBAL_INITIALIZE_MODEL_REPORTED_PROPERTY(modelName, type,name) GlobalInitialize_##type((char*)destination+offsetof(modelName, name));
00512 #define CREATE_GLOBAL_DEINITIALIZE_MODEL_REPORTED_PROPERTY(modelName, type,name) GlobalDeinitialize_##type((char*)destination+offsetof(modelName, name));
00513 
00514 /*DESIRED_PROPERTY is not different than regular WITH_DATA*/
00515 #define INSERT_FIELD_FOR_MODEL_DESIRED_PROPERTY(type, name, ...) INSERT_FIELD_INTO_STRUCT(type, name)
00516 #define CREATE_GLOBAL_INITIALIZE_MODEL_DESIRED_PROPERTY(modelName, type, name, ...) /*do nothing*/
00517 #define CREATE_GLOBAL_DEINITIALIZE_MODEL_DESIRED_PROPERTY(modelName, type, name, ...) /*do nothing*/
00518 
00519 #define INSERT_FIELD_FOR_MODEL_ACTION(name, ...) /* action isn't a part of the model struct */
00520 #define INSERT_FIELD_FOR_MODEL_METHOD(name, ...) /* method isn't a part of the model struct */
00521 
00522 #define CREATE_GLOBAL_INITIALIZE_MODEL_ACTION(...) /*do nothing*/
00523 #define CREATE_GLOBAL_DEINITIALIZE_MODEL_ACTION(...) /*do nothing*/
00524 
00525 #define CREATE_GLOBAL_INITIALIZE_MODEL_METHOD(...) /*do nothing*/
00526 #define CREATE_GLOBAL_DEINITIALIZE_MODEL_METHOD(...) /*do nothing*/
00527 
00528 #define CREATE_MODEL_PROPERTY(modelName, type, name) \
00529     IMPL_PROPERTY(type, name, modelName)
00530 
00531 #define CREATE_MODEL_REPORTED_PROPERTY(modelName, type, name) \
00532     IMPL_REPORTED_PROPERTY(type, name, modelName)
00533 
00534 #define CREATE_MODEL_DESIRED_PROPERTY(modelName, type, name, ...) \
00535     IMPL_DESIRED_PROPERTY(type, name, modelName, __VA_ARGS__)
00536 
00537 #define IMPL_PROPERTY(propertyType, propertyName, modelName) \
00538     static int Create_AGENT_DATA_TYPE_From_Ptr_##modelName##propertyName(void* param, AGENT_DATA_TYPE* dest) \
00539     { \
00540         return C1(ToAGENT_DATA_TYPE_##propertyType)(dest, *(propertyType*)param); \
00541     } \
00542     REFLECTED_PROPERTY(propertyType, propertyName, modelName)
00543 
00544 #define IMPL_REPORTED_PROPERTY(propertyType, propertyName, modelName) \
00545     static int Create_AGENT_DATA_TYPE_From_Ptr_##modelName##propertyName(void* param, AGENT_DATA_TYPE* dest) \
00546     { \
00547         return C1(ToAGENT_DATA_TYPE_##propertyType)(dest, *(propertyType*)param); \
00548     } \
00549     REFLECTED_REPORTED_PROPERTY(propertyType, propertyName, modelName)
00550 
00551 #define IMPL_DESIRED_PROPERTY(propertyType, propertyName, modelName, ...)           \
00552     static void DesiredPropertyInitialize_##modelName##propertyName(void* destination)                             \
00553     {                                                                                                   \
00554         GlobalInitialize_##propertyType(destination);                                                   \
00555     }                                                                                                   \
00556     static void DesiredPropertyDeinitialize_##modelName##propertyName(void* destination)                           \
00557     {                                                                                                   \
00558        GlobalDeinitialize_##propertyType(destination);                                                  \
00559     }                                                                                                   \
00560     REFLECTED_DESIRED_PROPERTY(propertyType, propertyName, modelName, __VA_ARGS__)          \
00561 
00562 #define CREATE_MODEL_ACTION(modelName, actionName, ...) \
00563     DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(modelName##actionName, 1); \
00564     EXECUTE_COMMAND_RESULT actionName (modelName* device FOR_EACH_2(DEFINE_FUNCTION_PARAMETER, __VA_ARGS__)); \
00565     static EXECUTE_COMMAND_RESULT C2(actionName, WRAPPER)(void* device, size_t ParameterCount, const AGENT_DATA_TYPE* values); \
00566     /*for macro purposes, this array always has at least 1 element*/ \
00567     /*Codes_SRS_SERIALIZER_99_043:[ It is valid for a method not to have any parameters.]*/ \
00568     DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 1); \
00569     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} }; \
00570     REFLECTED_ACTION(actionName, DIV2(COUNT_ARG(__VA_ARGS__)), C2(actionName, WRAPPERARGUMENTS), C2(actionName, WRAPPER), modelName) \
00571     /*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*.] */ \
00572     /*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.]*/ \
00573     static EXECUTE_COMMAND_RESULT C2(actionName, WRAPPER)(void* device, size_t ParameterCount, const AGENT_DATA_TYPE* values) \
00574     { \
00575         EXECUTE_COMMAND_RESULT result; \
00576         DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 2); \
00577         /*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;]*/ \
00578         if(ParameterCount != DIV2(COUNT_ARG(__VA_ARGS__))) \
00579         { \
00580             result = EXECUTE_COMMAND_ERROR; \
00581         } \
00582         else \
00583         { \
00584             /*the below line takes care of initialized but not referenced parameter warning*/ \
00585             DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 3); \
00586             IF(DIV2(COUNT_ARG(__VA_ARGS__)), size_t iParameter = 0;, ) \
00587             DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 4); \
00588             /*the below line takes care of an unused parameter when values is really never questioned*/ \
00589             DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 5); \
00590             FOR_EACH_2(DEFINE_LOCAL_PARAMETER, __VA_ARGS__) \
00591             DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 6); \
00592             IF(DIV2(COUNT_ARG(__VA_ARGS__)), , (void)values;) \
00593             { \
00594                DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 7); \
00595             } \
00596             FOR_EACH_2_KEEP_1(START_BUILD_LOCAL_PARAMETER, EXECUTE_COMMAND_ERROR, __VA_ARGS__) \
00597             { \
00598                DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 8); \
00599             } \
00600             result = actionName((modelName*)device FOR_EACH_2(PUSH_LOCAL_PARAMETER, __VA_ARGS__)); \
00601             FOR_EACH_2_REVERSE(END_BUILD_LOCAL_PARAMETER, __VA_ARGS__) \
00602         } \
00603         return result; \
00604     }
00605 
00606 #define CREATE_MODEL_METHOD(modelName, methodName, ...) \
00607     DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(modelName##methodName, 1); \
00608     METHODRETURN_HANDLE methodName (modelName* device FOR_EACH_2(DEFINE_FUNCTION_PARAMETER, __VA_ARGS__)); \
00609     static METHODRETURN_HANDLE C2(methodName, WRAPPER)(void* device, size_t ParameterCount, const AGENT_DATA_TYPE* values); \
00610     /*for macro purposes, this array always has at least 1 element*/ \
00611     /*Codes_SRS_SERIALIZER_H_02_030: [ It is valid for a method function not to have any parameters. ]*/ \
00612     DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(methodName, 1); \
00613     static const WRAPPER_ARGUMENT C2(methodName, 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} }; \
00614     REFLECTED_METHOD(methodName, DIV2(COUNT_ARG(__VA_ARGS__)), C2(methodName, WRAPPERARGUMENTS), C2(methodName, WRAPPER), modelName) \
00615     /*Codes_SRS_SERIALIZER_H_02_034: [ WITH_METHOD shall result in the declaration of a conversion function with the prototype METHODRETURN_HANDLE nameWRAPPER(size_t ParameterCount, const AGENT_DATA_TYPE* values)' ]*/ \
00616     /*Codes_SRS_SERIALIZER_H_02_031: [ The function shall convert the input arguments to the types declared in the method parameter list and then call the user-defined method function. ]*/ \
00617     static METHODRETURN_HANDLE C2(methodName, WRAPPER)(void* device, size_t ParameterCount, const AGENT_DATA_TYPE* values) \
00618     { \
00619         METHODRETURN_HANDLE result; \
00620         DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(methodName, 2); \
00621         /*Codes_SRS_SERIALIZER_H_02_032: [ If the number of arguments passed to the conversion function does not match the expected count, the function shall return DATAPROVIDER_INVALID_ARG. ]*/ \
00622         if(ParameterCount != DIV2(COUNT_ARG(__VA_ARGS__))) \
00623         { \
00624             LogError("expected parameter count (%zu) does not match the actual parameter count (%zu)", ParameterCount, COUNT_ARG(__VA_ARGS__)); \
00625             result = NULL; \
00626         } \
00627         else \
00628         { \
00629             /*the below line takes care of initialized but not referenced parameter warning*/ \
00630             DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(methodName, 3); \
00631             IF(DIV2(COUNT_ARG(__VA_ARGS__)), size_t iParameter = 0;, ) \
00632             DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(methodName, 4); \
00633             /*the below line takes care of an unused parameter when values is really never questioned*/ \
00634             DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(methodName, 5); \
00635             FOR_EACH_2(DEFINE_LOCAL_PARAMETER, __VA_ARGS__) \
00636             DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(methodName, 6); \
00637             IF(DIV2(COUNT_ARG(__VA_ARGS__)), , (void)values;) \
00638             { \
00639                DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 7); \
00640             } \
00641             FOR_EACH_2_KEEP_1(START_BUILD_LOCAL_PARAMETER, NULL,__VA_ARGS__) \
00642             { \
00643                DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(actionName, 8); \
00644             } \
00645             result = methodName((modelName*)device FOR_EACH_2(PUSH_LOCAL_PARAMETER, __VA_ARGS__)); \
00646             FOR_EACH_2_REVERSE(END_BUILD_LOCAL_PARAMETER, __VA_ARGS__) \
00647         } \
00648         return result; \
00649     }
00650 
00651 #define CREATE_AGENT_DATA_TYPE(type, name) \
00652     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; \
00653     iMember+= ((result==AGENT_DATA_TYPES_OK)?1:0);
00654 
00655 #define BUILD_DESTINATION_FIELD(type, name) \
00656     if(result == AGENT_DATA_TYPES_OK) \
00657     { \
00658         size_t i; \
00659         bool wasFieldConverted = false; \
00660         for (i = 0; i < source->value.edmComplexType.nMembers; i++) \
00661         { \
00662             /*the name of the field of the complex type must match the name of the field of the structure (parameter name here)*/ \
00663             if (strcmp(source->value.edmComplexType.fields[i].fieldName, TOSTRING(name)) == 0) \
00664             { /*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.]*/ \
00665                 wasFieldConverted = (C2(FromAGENT_DATA_TYPE_, type)(source->value.edmComplexType.fields[i].value, &(destination->name)) == AGENT_DATA_TYPES_OK); \
00666                 break; \
00667             } \
00668         } \
00669         result = (wasFieldConverted == true)? AGENT_DATA_TYPES_OK: AGENT_DATA_TYPES_INVALID_ARG; \
00670     } \
00671     else \
00672     { \
00673         /*fallthrough*/ \
00674     }
00675 
00676 #define UNBUILD_DESTINATION_FIELD(value, type, name) \
00677     C2(destroyLocalParameter, type)(&(value->name));
00678 
00679 
00680 #define ADDRESS_MACRO(x) ,&x
00681 
00682 #define KEEP_FIRST_(X, ...) X
00683 #ifdef _MSC_VER
00684 #define KEEP_FIRST(X) KEEP_FIRST_ LPAREN X)
00685 #else
00686 #define KEEP_FIRST(X) KEEP_FIRST_(X)
00687 #endif
00688 
00689 #define PROMOTIONMAP_float double, double
00690 #define PROMOTIONMAP_int8_t int, int
00691 #define PROMOTIONMAP_uint8_t int, int
00692 #define PROMOTIONMAP_int16_t int, int
00693 #define PROMOTIONMAP__Bool int, int
00694 #define PROMOTIONMAP_bool int, int
00695 
00696 #define CASTMAP_float (float), (float)
00697 #define CASTMAP_int8_t (int8_t), (int8_t)
00698 #define CASTMAP_uint8_t (uint8_t), (uint8_t)
00699 #define CASTMAP_int16_t (int16_t), (int16_t)
00700 #define CASTMAP__Bool 0!=, 0!=
00701 #define CASTMAP_bool 0!=, 0!=
00702 
00703 #define EMPTY_TOKEN
00704 
00705 #define ANOTHERIF(x) C2(ANOTHERIF,x)
00706 #define ANOTHERIF0(a,b) a
00707 #define ANOTHERIF1(a,b) b
00708 #define ANOTHERIF2(a,b) b
00709 #define ANOTHERIF3(a,b) b
00710 #define ANOTHERIF4(a,b) b
00711 #define ANOTHERIF5(a,b) b
00712 #define ANOTHERIF6(a,b) b
00713 #define ANOTHERIF7(a,b) b
00714 #define ANOTHERIF8(a,b) b
00715 #define ANOTHERIF9(a,b) b
00716 #define ANOTHERIF10(a,b) b
00717 #define ANOTHERIF11(a,b) b
00718 #define ANOTHERIF12(a,b) b
00719 
00720 #define MAP_PROMOTED_TYPE(X) ANOTHERIF(DEC(COUNT_ARG(PROMOTIONMAP_##X))) (X, KEEP_FIRST(PROMOTIONMAP_##X))
00721 #define MAP_CAST_TYPE(X) ANOTHERIF(DEC(COUNT_ARG(CASTMAP_##X)))    (EMPTY_TOKEN, KEEP_FIRST(CASTMAP_##X)  )
00722 
00723 #define IFCOMMA(N) C2(IFCOMMA_, N)
00724 #define IFCOMMA_0
00725 #define IFCOMMA_2
00726 #define IFCOMMA_4 ,
00727 #define IFCOMMA_6 ,
00728 #define IFCOMMA_8 ,
00729 #define IFCOMMA_10 ,
00730 #define IFCOMMA_12 ,
00731 #define IFCOMMA_14 ,
00732 #define IFCOMMA_16 ,
00733 #define IFCOMMA_18 ,
00734 #define IFCOMMA_20 ,
00735 #define IFCOMMA_22 ,
00736 #define IFCOMMA_24 ,
00737 #define IFCOMMA_26 ,
00738 #define IFCOMMA_28 ,
00739 #define IFCOMMA_30 ,
00740 #define IFCOMMA_32 ,
00741 #define IFCOMMA_34 ,
00742 #define IFCOMMA_36 ,
00743 #define IFCOMMA_38 ,
00744 #define IFCOMMA_40 ,
00745 #define IFCOMMA_42 ,
00746 #define IFCOMMA_44 ,
00747 #define IFCOMMA_46 ,
00748 #define IFCOMMA_48 ,
00749 #define IFCOMMA_50 ,
00750 #define IFCOMMA_52 ,
00751 #define IFCOMMA_54 ,
00752 #define IFCOMMA_56 ,
00753 #define IFCOMMA_58 ,
00754 #define IFCOMMA_60 ,
00755 #define IFCOMMA_62 ,
00756 #define IFCOMMA_64 ,
00757 #define IFCOMMA_66 ,
00758 #define IFCOMMA_68 ,
00759 #define IFCOMMA_70 ,
00760 #define IFCOMMA_72 ,
00761 #define IFCOMMA_74 ,
00762 #define IFCOMMA_76 ,
00763 #define IFCOMMA_78 ,
00764 #define IFCOMMA_80 ,
00765 #define IFCOMMA_82 ,
00766 #define IFCOMMA_84 ,
00767 #define IFCOMMA_86 ,
00768 #define IFCOMMA_88 ,
00769 #define IFCOMMA_90 ,
00770 #define IFCOMMA_92 ,
00771 #define IFCOMMA_94 ,
00772 #define IFCOMMA_96 ,
00773 #define IFCOMMA_98 ,
00774 #define IFCOMMA_100 ,
00775 #define IFCOMMA_102 ,
00776 #define IFCOMMA_104 ,
00777 #define IFCOMMA_106 ,
00778 #define IFCOMMA_108 ,
00779 #define IFCOMMA_110 ,
00780 #define IFCOMMA_112 ,
00781 #define IFCOMMA_114 ,
00782 #define IFCOMMA_116 ,
00783 #define IFCOMMA_118 ,
00784 #define IFCOMMA_120 ,
00785 #define IFCOMMA_122 ,
00786 #define IFCOMMA_124 ,
00787 #define IFCOMMA_126 ,
00788 #define IFCOMMA_128 ,
00789 
00790 #define DEFINE_LOCAL_PARAMETER(type, name) type C2(name,_local); GlobalInitialize_##type(& C2(name, _local));
00791 
00792 #define START_BUILD_LOCAL_PARAMETER(errorWhenItFails, type, name) \
00793     if (C2(FromAGENT_DATA_TYPE_, type)(&values[iParameter], &C2(name, _local)) != AGENT_DATA_TYPES_OK) \
00794     { \
00795         /*Codes_SRS_SERIALIZER_99_046:[ If the types of the parameters do not match the declared types, DATAPROVIDER_INVALID_ARG shall be returned.]*/ \
00796         result = errorWhenItFails; \
00797     }\
00798     else \
00799     { \
00800         iParameter++;
00801 
00802 #define END_BUILD_LOCAL_PARAMETER(type, name) \
00803     (void)C2(destroyLocalParameter, type)(&C2(name, _local)); \
00804     }
00805 
00806 /*The following constructs have been devised to work around the precompiler bug of Visual Studio 2005, version 14.00.50727.42*/
00807 /* The bug is explained in https://connect.microsoft.com/VisualStudio/feedback/details/278752/comma-missing-when-using-va-args */
00808 /*A short description is: preprocessor is mysteriously eating commas ','.
00809 In order to feed the appetite of the preprocessor, several constructs have
00810 been devised that can sustain a missing ',' while still compiling and while still doing nothing
00811 and while hopefully being eliminated from the code based on "doesn't do anything" so no code size penalty
00812 */
00813 
00814 /*the reason why all these constructs work is:
00815 if two strings separated by a comma will lose the comma (myteriously) then they will become just one string:
00816 "a", "b" ------Preprocessor------> "a" "b" -----Compiler----> "ab"
00817 */
00818 
00819 #define LOTS_OF_COMMA_TO_BE_EATEN /*there were witnesses where as many as THREE commas have been eaten!*/ \
00820 "0" "1", "2", "3", "4", "5", "6", "7", "8", "9"
00821 #define DEFINITION_THAT_CAN_SUSTAIN_A_COMMA_STEAL(name, instance) static const char* eatThese_COMMA_##name##instance[] = {LOTS_OF_COMMA_TO_BE_EATEN}
00822 
00823 #define PUSH_LOCAL_PARAMETER(type, name) , C2(name, _local)
00824 #define DEFINE_FUNCTION_PARAMETER(type, name) , type name
00825 #define MAKE_WRAPPER_ARGUMENT(N, type, name) {TOSTRING(type), TOSTRING(name)} IFCOMMA(N)
00826 
00827 /*Codes_SRS_SERIALIZER_99_019:[ Create_AGENT_DATA_TYPE_from_DOUBLE]*/
00828 /*Codes_SRS_SERIALIZER_99_004:[ The propertyType can be any of the following data types: double]*/
00829 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, double)(AGENT_DATA_TYPE* dest, double source)
00830 {
00831     return Create_AGENT_DATA_TYPE_from_DOUBLE(dest, source);
00832 }
00833 
00834 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, double)(const AGENT_DATA_TYPE* agentData, double* dest)
00835 {
00836     AGENT_DATA_TYPES_RESULT result;
00837     if (agentData->type != EDM_DOUBLE_TYPE)
00838     {
00839         result = AGENT_DATA_TYPES_INVALID_ARG;
00840     }
00841     else
00842     {
00843         *dest = agentData->value.edmDouble.value;
00844         result = AGENT_DATA_TYPES_OK;
00845     }
00846     return result;
00847 }
00848 
00849 static void C2(GlobalInitialize_, double)(void* dest)
00850 {
00851     *(double*)dest = 0.0;
00852 }
00853 
00854 static void C2(GlobalDeinitialize_, double)(void* dest)
00855 {
00856     (void)(dest);
00857 }
00858 
00859 /*Codes_SRS_SERIALIZER_99_021:[ Create_AGENT_DATA_TYPE_from_FLOAT]*/
00860 /*Codes_SRS_SERIALIZER_99_006:[ float]*/
00861 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, float)(AGENT_DATA_TYPE* dest, float source)
00862 {
00863     return Create_AGENT_DATA_TYPE_from_FLOAT(dest, source);
00864 }
00865 
00866 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, float)(const AGENT_DATA_TYPE* agentData, float* dest)
00867 {
00868     AGENT_DATA_TYPES_RESULT result;
00869     if (agentData->type != EDM_SINGLE_TYPE)
00870     {
00871         result = AGENT_DATA_TYPES_INVALID_ARG;
00872     }
00873     else
00874     {
00875         *dest = agentData->value.edmSingle.value;
00876         result = AGENT_DATA_TYPES_OK;
00877     }
00878     return result;
00879 }
00880 
00881 static void C2(GlobalInitialize_, float)(void* dest)
00882 {
00883     *(float*)dest = 0.0f;
00884 }
00885 
00886 static void C2(GlobalDeinitialize_, float)(void* dest)
00887 {
00888     (void)(dest);
00889 }
00890 
00891 
00892 /*Codes_SRS_SERIALIZER_99_020:[ Create_AGENT_DATA_TYPE_from_SINT32]*/
00893 /*Codes_SRS_SERIALIZER_99_005:[ int], */
00894 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, int)(AGENT_DATA_TYPE* dest, int source)
00895 {
00896     return Create_AGENT_DATA_TYPE_from_SINT32(dest, source);
00897 }
00898 
00899 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, int)(const AGENT_DATA_TYPE* agentData, int* dest)
00900 {
00901     AGENT_DATA_TYPES_RESULT result;
00902     if (agentData->type != EDM_INT32_TYPE)
00903     {
00904         result = AGENT_DATA_TYPES_INVALID_ARG;
00905     }
00906     else
00907     {
00908         *dest = agentData->value.edmInt32.value;
00909         result = AGENT_DATA_TYPES_OK;
00910     }
00911     return result;
00912 }
00913 
00914 static void C2(GlobalInitialize_, int)(void* dest)
00915 {
00916     *(int*)dest = 0;
00917 }
00918 
00919 static void C2(GlobalDeinitialize_, int)(void* dest)
00920 {
00921     (void)(dest);
00922 }
00923 
00924 /*Codes_SRS_SERIALIZER_99_022:[ Create_AGENT_DATA_TYPE_from_SINT64]*/
00925 /*Codes_SRS_SERIALIZER_99_007:[ long]*/
00926 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, long)(AGENT_DATA_TYPE* dest, long source)
00927 {
00928     return Create_AGENT_DATA_TYPE_from_SINT64(dest, source);
00929 }
00930 
00931 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, long)(const AGENT_DATA_TYPE* agentData, long* dest)
00932 {
00933     AGENT_DATA_TYPES_RESULT result;
00934     if (agentData->type != EDM_INT64_TYPE)
00935     {
00936         result = AGENT_DATA_TYPES_INVALID_ARG;
00937     }
00938     else
00939     {
00940         *dest = (long)agentData->value.edmInt64.value;
00941         result = AGENT_DATA_TYPES_OK;
00942     }
00943     return result;
00944 }
00945 
00946 static void C2(GlobalInitialize_, long)(void* dest)
00947 {
00948     *(long*)dest = 0;
00949 }
00950 
00951 static void C2(GlobalDeinitialize_, long)(void* dest)
00952 {
00953     (void)(dest);
00954 }
00955 
00956 
00957 /*Codes_SRS_SERIALIZER_99_023:[ Create_AGENT_DATA_TYPE_from_SINT8]*/
00958 /*Codes_SRS_SERIALIZER_99_008:[ int8_t]*/
00959 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, int8_t)(AGENT_DATA_TYPE* dest, int8_t source)
00960 {
00961     return Create_AGENT_DATA_TYPE_from_SINT8(dest, source);
00962 }
00963 
00964 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, int8_t)(const AGENT_DATA_TYPE* agentData, int8_t* dest)
00965 {
00966     AGENT_DATA_TYPES_RESULT result;
00967     if (agentData->type != EDM_SBYTE_TYPE)
00968     {
00969         result = AGENT_DATA_TYPES_INVALID_ARG;
00970     }
00971     else
00972     {
00973         *dest = agentData->value.edmSbyte.value;
00974         result = AGENT_DATA_TYPES_OK;
00975     }
00976     return result;
00977 }
00978 
00979 static void C2(GlobalInitialize_, int8_t)(void* dest)
00980 {
00981     *(int8_t*)dest = 0;
00982 }
00983 
00984 static void C2(GlobalDeinitialize_, int8_t)(void* dest)
00985 {
00986     (void)(dest);
00987 }
00988 
00989 /*Codes_SRS_SERIALIZER_99_024:[ Create_AGENT_DATA_TYPE_from_UINT8]*/
00990 /*Codes_SRS_SERIALIZER_99_009:[ uint8_t]*/
00991 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, uint8_t)(AGENT_DATA_TYPE* dest, uint8_t source)
00992 {
00993     return Create_AGENT_DATA_TYPE_from_UINT8(dest, source);
00994 }
00995 
00996 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, uint8_t)(const AGENT_DATA_TYPE* agentData, uint8_t* dest)
00997 {
00998     AGENT_DATA_TYPES_RESULT result;
00999     if (agentData->type != EDM_BYTE_TYPE)
01000     {
01001         result = AGENT_DATA_TYPES_INVALID_ARG;
01002     }
01003     else
01004     {
01005         *dest = agentData->value.edmByte.value;
01006         result = AGENT_DATA_TYPES_OK;
01007     }
01008     return result;
01009 }
01010 
01011 static void C2(GlobalInitialize_, uint8_t)(void* dest)
01012 {
01013     *(uint8_t*)dest = 0;
01014 }
01015 
01016 static void C2(GlobalDeinitialize_, uint8_t)(void* dest)
01017 {
01018     (void)(dest);
01019 }
01020 
01021 
01022 /*Codes_SRS_SERIALIZER_99_025:[ Create_AGENT_DATA_TYPE_from_SINT16]*/
01023 /*Codes_SRS_SERIALIZER_99_010:[ int16_t]*/
01024 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, int16_t)(AGENT_DATA_TYPE* dest, int16_t source)
01025 {
01026     return Create_AGENT_DATA_TYPE_from_SINT16(dest, source);
01027 }
01028 
01029 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, int16_t)(const AGENT_DATA_TYPE* agentData, int16_t* dest)
01030 {
01031     AGENT_DATA_TYPES_RESULT result;
01032     if (agentData->type != EDM_INT16_TYPE)
01033     {
01034         result = AGENT_DATA_TYPES_INVALID_ARG;
01035     }
01036     else
01037     {
01038         *dest = agentData->value.edmInt16.value;
01039         result = AGENT_DATA_TYPES_OK;
01040     }
01041     return result;
01042 }
01043 
01044 static void C2(GlobalInitialize_, int16_t)(void* dest)
01045 {
01046     *(int16_t*)dest = 0;
01047 }
01048 
01049 static void C2(GlobalDeinitialize_, int16_t)(void* dest)
01050 {
01051     (void)(dest);
01052 }
01053 
01054 /*Codes_SRS_SERIALIZER_99_026:[ Create_AGENT_DATA_TYPE_from_SINT32]*/
01055 /*Codes_SRS_SERIALIZER_99_011:[ int32_t]*/
01056 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, int32_t)(AGENT_DATA_TYPE* dest, int32_t source)
01057 {
01058     return Create_AGENT_DATA_TYPE_from_SINT32(dest, source);
01059 }
01060 
01061 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, int32_t)(const AGENT_DATA_TYPE* agentData, int32_t* dest)
01062 {
01063     AGENT_DATA_TYPES_RESULT result;
01064     if (agentData->type != EDM_INT32_TYPE)
01065     {
01066         result = AGENT_DATA_TYPES_INVALID_ARG;
01067     }
01068     else
01069     {
01070         *dest = agentData->value.edmInt32.value;
01071         result = AGENT_DATA_TYPES_OK;
01072     }
01073     return result;
01074 }
01075 
01076 static void C2(GlobalInitialize_, int32_t)(void* dest)
01077 {
01078     *(int32_t*)dest = 0;
01079 }
01080 
01081 static void C2(GlobalDeinitialize_, int32_t)(void* dest)
01082 {
01083     (void)(dest);
01084 }
01085 
01086 /*Codes_SRS_SERIALIZER_99_027:[ Create_AGENT_DATA_TYPE_from_SINT64]*/
01087 /*Codes_SRS_SERIALIZER_99_012:[ int64_t]*/
01088 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, int64_t)(AGENT_DATA_TYPE* dest, int64_t source)
01089 {
01090     return Create_AGENT_DATA_TYPE_from_SINT64(dest, source);
01091 }
01092 
01093 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, int64_t)(const AGENT_DATA_TYPE* agentData, int64_t* dest)
01094 {
01095     AGENT_DATA_TYPES_RESULT result;
01096     if (agentData->type != EDM_INT64_TYPE)
01097     {
01098         result = AGENT_DATA_TYPES_INVALID_ARG;
01099     }
01100     else
01101     {
01102         *dest = agentData->value.edmInt64.value;
01103         result = AGENT_DATA_TYPES_OK;
01104     }
01105     return result;
01106 }
01107 
01108 static void C2(GlobalInitialize_, int64_t)(void* dest)
01109 {
01110     *(int64_t*)dest = 0;
01111 }
01112 
01113 static void C2(GlobalDeinitialize_, int64_t)(void* dest)
01114 {
01115     (void)(dest);
01116 }
01117 
01118 /*Codes_SRS_SERIALIZER_99_013:[ bool]*/
01119 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, bool)(AGENT_DATA_TYPE* dest, bool source)
01120 {
01121     return Create_EDM_BOOLEAN_from_int(dest, source == true);
01122 }
01123 
01124 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, bool)(const AGENT_DATA_TYPE* agentData, bool* dest)
01125 {
01126     AGENT_DATA_TYPES_RESULT result;
01127     if (agentData->type != EDM_BOOLEAN_TYPE)
01128     {
01129         result = AGENT_DATA_TYPES_INVALID_ARG;
01130     }
01131     else
01132     {
01133         *dest = (agentData->value.edmBoolean.value == EDM_TRUE) ? true : false;
01134         result = AGENT_DATA_TYPES_OK;
01135     }
01136     return result;
01137 }
01138 
01139 static void C2(GlobalInitialize_, bool)(void* dest)
01140 {
01141     *(bool*)dest = false;
01142 }
01143 
01144 static void C2(GlobalDeinitialize_, bool)(void* dest)
01145 {
01146     (void)(dest);
01147 }
01148 
01149 /*Codes_SRS_SERIALIZER_99_014:[ ascii_char_ptr]*/
01150 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, ascii_char_ptr)(AGENT_DATA_TYPE* dest, ascii_char_ptr source)
01151 {
01152     return Create_AGENT_DATA_TYPE_from_charz(dest, source);
01153 }
01154 
01155 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, ascii_char_ptr)(const AGENT_DATA_TYPE* agentData, ascii_char_ptr* dest)
01156 {
01157     AGENT_DATA_TYPES_RESULT result;
01158     if (agentData->type != EDM_STRING_TYPE)
01159     {
01160         result = AGENT_DATA_TYPES_INVALID_ARG;
01161     }
01162     else
01163     {
01164         if (*dest != NULL)
01165         {
01166             free(*dest);
01167             *dest = NULL;
01168         }
01169 
01170         if (mallocAndStrcpy_s(dest, agentData->value.edmString.chars) != 0)
01171         {
01172             LogError("failure in mallocAndStrcpy_s");
01173             result = AGENT_DATA_TYPES_ERROR;
01174         }
01175         else
01176         {
01177             result = AGENT_DATA_TYPES_OK;
01178         }
01179 
01180     }
01181     return result;
01182 }
01183 
01184 static void C2(GlobalInitialize_, ascii_char_ptr)(void* dest)
01185 {
01186     *(ascii_char_ptr*)dest = NULL;
01187 }
01188 
01189 static void C2(GlobalDeinitialize_, ascii_char_ptr)(void* dest)
01190 {
01191     if (*(ascii_char_ptr*)dest != NULL)
01192     {
01193         free(*(ascii_char_ptr*)dest);
01194     }
01195 }
01196 
01197 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, ascii_char_ptr_no_quotes)(AGENT_DATA_TYPE* dest, ascii_char_ptr_no_quotes source)
01198 {
01199     return Create_AGENT_DATA_TYPE_from_charz_no_quotes(dest, source);
01200 }
01201 
01202 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)
01203 {
01204     AGENT_DATA_TYPES_RESULT result;
01205     if (agentData->type != EDM_STRING_NO_QUOTES_TYPE)
01206     {
01207         result = AGENT_DATA_TYPES_INVALID_ARG;
01208     }
01209     else
01210     {
01211         if (*dest != NULL)
01212         {
01213             free(*dest);
01214             *dest = NULL;
01215         }
01216 
01217         if (mallocAndStrcpy_s(dest, agentData->value.edmStringNoQuotes.chars) != 0)
01218         {
01219             LogError("failure in mallocAndStrcpy_s");
01220             result = AGENT_DATA_TYPES_ERROR;
01221         }
01222         else
01223         {
01224             result = AGENT_DATA_TYPES_OK;
01225         }
01226     }
01227     return result;
01228 }
01229 
01230 static void C2(GlobalInitialize_, ascii_char_ptr_no_quotes)(void* dest)
01231 {
01232     *(ascii_char_ptr_no_quotes*)dest = NULL;
01233 }
01234 
01235 static void C2(GlobalDeinitialize_, ascii_char_ptr_no_quotes)(void* dest)
01236 {
01237     if (*(ascii_char_ptr_no_quotes*)dest != NULL)
01238     {
01239         free(*(ascii_char_ptr_no_quotes*)dest);
01240     }
01241 }
01242 
01243 /*Codes_SRS_SERIALIZER_99_051:[ EDM_DATE_TIME_OFFSET*/
01244 /*Codes_SRS_SERIALIZER_99_053:[Create_AGENT_DATA_TYPE_from_EDM_DATE_TIME_OFFSET]*/
01245 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, EDM_DATE_TIME_OFFSET)(AGENT_DATA_TYPE* dest, EDM_DATE_TIME_OFFSET source)
01246 {
01247     return Create_AGENT_DATA_TYPE_from_EDM_DATE_TIME_OFFSET(dest, source);
01248 }
01249 
01250 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, EDM_DATE_TIME_OFFSET)(const AGENT_DATA_TYPE* agentData, EDM_DATE_TIME_OFFSET* dest)
01251 {
01252     AGENT_DATA_TYPES_RESULT result;
01253     if (agentData->type != EDM_DATE_TIME_OFFSET_TYPE)
01254     {
01255         result = AGENT_DATA_TYPES_INVALID_ARG;
01256     }
01257     else
01258     {
01259         *dest = agentData->value.edmDateTimeOffset;
01260         result = AGENT_DATA_TYPES_OK;
01261     }
01262     return result;
01263 }
01264 
01265 static void C2(GlobalInitialize_, EDM_DATE_TIME_OFFSET)(void* dest)
01266 {
01267     memset(dest, 0, sizeof(EDM_DATE_TIME_OFFSET));
01268 }
01269 
01270 static void C2(GlobalDeinitialize_, EDM_DATE_TIME_OFFSET)(void* dest)
01271 {
01272     (void)(dest);
01273 }
01274 
01275 /*Codes_SRS_SERIALIZER_99_072:[ EDM_GUID]*/
01276 /*Codes_SRS_SERIALIZER_99_073:[ Create_AGENT_DATA_TYPE_from_EDM_GUID]*/
01277 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, EDM_GUID)(AGENT_DATA_TYPE* dest, EDM_GUID guid)
01278 {
01279     return Create_AGENT_DATA_TYPE_from_EDM_GUID(dest, guid);
01280 }
01281 
01282 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, EDM_GUID)(const AGENT_DATA_TYPE* agentData, EDM_GUID* dest)
01283 {
01284     AGENT_DATA_TYPES_RESULT result;
01285     if (agentData->type != EDM_GUID_TYPE)
01286     {
01287         result = AGENT_DATA_TYPES_INVALID_ARG;
01288     }
01289     else
01290     {
01291         (void)memcpy(dest->GUID, agentData->value.edmGuid.GUID, 16);
01292         result = AGENT_DATA_TYPES_OK;
01293     }
01294     return result;
01295 }
01296 
01297 static void C2(GlobalInitialize_, EDM_GUID)(void* dest)
01298 {
01299     memset(dest, 0, sizeof(EDM_GUID));
01300 }
01301 
01302 static void C2(GlobalDeinitialize_, EDM_GUID)(void* dest)
01303 {
01304     (void)(dest);
01305 }
01306 
01307 
01308 /*Codes_SRS_SERIALIZER_99_074:[ EDM_BINARY]*/
01309 /*Codes_SRS_SERIALIZER_99_075:[ Create_AGENT_DATA_TYPE_from_EDM_BINARY]*/
01310 static AGENT_DATA_TYPES_RESULT C2(ToAGENT_DATA_TYPE_, EDM_BINARY)(AGENT_DATA_TYPE* dest, EDM_BINARY edmBinary)
01311 {
01312     return Create_AGENT_DATA_TYPE_from_EDM_BINARY(dest, edmBinary);
01313 }
01314 
01315 static AGENT_DATA_TYPES_RESULT C2(FromAGENT_DATA_TYPE_, EDM_BINARY)(const AGENT_DATA_TYPE* agentData, EDM_BINARY* dest)
01316 {
01317     AGENT_DATA_TYPES_RESULT result;
01318     if (agentData->type != EDM_BINARY_TYPE)
01319     {
01320         result = AGENT_DATA_TYPES_INVALID_ARG;
01321     }
01322     else
01323     {
01324         if ((dest->data = (unsigned char *)malloc(agentData->value.edmBinary.size)) == NULL) /*cast because this get included in a C++ file.*/
01325         {
01326             result = AGENT_DATA_TYPES_ERROR;
01327         }
01328         else
01329         {
01330             (void)memcpy(dest->data, agentData->value.edmBinary.data, agentData->value.edmBinary.size);
01331             dest->size = agentData->value.edmBinary.size;
01332             result = AGENT_DATA_TYPES_OK;
01333         }
01334     }
01335     return result;
01336 }
01337 
01338 static void C2(GlobalInitialize_, EDM_BINARY)(void* dest)
01339 {
01340     ((EDM_BINARY*)dest)->data = NULL;
01341     ((EDM_BINARY*)dest)->size = 0;
01342 }
01343 
01344 static void C2(GlobalDeinitialize_, EDM_BINARY)(void* dest)
01345 {
01346     if ((((EDM_BINARY*)dest)->data) != NULL)
01347     {
01348         free(((EDM_BINARY*)dest)->data);
01349     }
01350 }
01351 
01352 static void C2(destroyLocalParameter, EDM_BINARY)(EDM_BINARY* value)
01353 {
01354     if (value != NULL)
01355     {
01356         free(value->data);
01357         value->data = NULL;
01358         value->size = 0;
01359     }
01360 }
01361 
01362 static void C2(destroyLocalParameter, EDM_BOOLEAN)(EDM_BOOLEAN* value)
01363 {
01364     (void)value;
01365 }
01366 
01367 static void C2(destroyLocalParameter, EDM_BYTE)(EDM_BYTE* value)
01368 {
01369     (void)value;
01370 }
01371 
01372 static void C2(destroyLocalParameter, EDM_DATE)(EDM_DATE* value)
01373 {
01374     (void)value;
01375 }
01376 
01377 static void C2(destroyLocalParameter, EDM_DATE_TIME_OFFSET)(EDM_DATE_TIME_OFFSET* value)
01378 {
01379     (void)value;
01380 }
01381 
01382 static void C2(destroyLocalParameter, EDM_DECIMAL)(EDM_DECIMAL* value)
01383 {
01384     if (value != NULL)
01385     {
01386         STRING_delete(value->value);
01387         value->value = NULL;
01388     }
01389 }
01390 
01391 static void C2(destroyLocalParameter, EDM_DOUBLE)(EDM_DOUBLE* value)
01392 {
01393     (void)value;
01394 }
01395 
01396 static void C2(destroyLocalParameter, EDM_DURATION)(EDM_DURATION* value)
01397 {
01398     if (value != NULL)
01399     {
01400         free(value->digits);
01401         value->digits = NULL;
01402         value->nDigits = 0;
01403     }
01404 }
01405 
01406 static void C2(destroyLocalParameter, EDM_GUID)(EDM_GUID* value)
01407 {
01408     (void)value;
01409 }
01410 
01411 static void C2(destroyLocalParameter, EDM_INT16)(EDM_INT16* value)
01412 {
01413     (void)value;
01414 }
01415 
01416 static void C2(destroyLocalParameter, EDM_INT32)(EDM_INT32* value)
01417 {
01418     (void)value;
01419 }
01420 
01421 static void C2(destroyLocalParameter, EDM_INT64)(EDM_INT64* value)
01422 {
01423     (void)value;
01424 }
01425 
01426 static void C2(destroyLocalParameter, EDM_SBYTE)(EDM_SBYTE* value)
01427 {
01428     (void)value;
01429 }
01430 
01431 static void C2(destroyLocalParameter, EDM_SINGLE)(EDM_SINGLE* value)
01432 {
01433     (void)value;
01434 }
01435 
01436 static void C2(destroyLocalParameter, EDM_STRING)(EDM_STRING* value)
01437 {
01438     (void)value;
01439 }
01440 
01441 
01442 static void C2(destroyLocalParameter, EDM_TIME_OF_DAY)(EDM_TIME_OF_DAY* value)
01443 {
01444     (void)value;
01445 }
01446 
01447 static void C2(destroyLocalParameter, int)(int* value)
01448 {
01449     (void)value;
01450 }
01451 
01452 static void C2(destroyLocalParameter, float)(float* value)
01453 {
01454     (void)value;
01455 }
01456 
01457 static void C2(destroyLocalParameter, double)(double* value)
01458 {
01459     (void)value;
01460 }
01461 
01462 static void C2(destroyLocalParameter, long)(long* value)
01463 {
01464     (void)value;
01465 }
01466 
01467 static void C2(destroyLocalParameter, int8_t)(int8_t* value)
01468 {
01469     (void)value;
01470 }
01471 
01472 static void C2(destroyLocalParameter, uint8_t)(uint8_t* value)
01473 {
01474     (void)value;
01475 }
01476 
01477 static void C2(destroyLocalParameter, int16_t)(int16_t* value)
01478 {
01479     (void)value;
01480 }
01481 
01482 static void C2(destroyLocalParameter, int32_t)(int32_t* value)
01483 {
01484     (void)value;
01485 }
01486 
01487 static void C2(destroyLocalParameter, int64_t)(int64_t* value)
01488 {
01489     (void)value;
01490 }
01491 
01492 static void C2(destroyLocalParameter, bool)(bool* value)
01493 {
01494     (void)value;
01495 }
01496 
01497 static void C2(destroyLocalParameter, ascii_char_ptr)(ascii_char_ptr* value)
01498 {
01499     if (value != NULL)
01500     {
01501         free(*value);
01502     }
01503 
01504 }
01505 
01506 static void C2(destroyLocalParameter, ascii_char_ptr_no_quotes)(ascii_char_ptr_no_quotes* value)
01507 {
01508     if (value != NULL)
01509     {
01510         free(*value);
01511     }
01512 }
01513 
01514 #ifdef __cplusplus
01515     }
01516 #endif
01517 
01518 #endif /*SERIALIZER_H*/
01519 
01520