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
codefirst.h@36:7d12a5386197, 2018-09-11 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Tue Sep 11 11:14:37 2018 -0700
- Revision:
- 36:7d12a5386197
- Parent:
- 27:1ac2fac5e8c2
1.2.9
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AzureIoTClient | 0:1f9b2707ec7d | 1 | // Copyright (c) Microsoft. All rights reserved. |
AzureIoTClient | 0:1f9b2707ec7d | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
AzureIoTClient | 0:1f9b2707ec7d | 3 | |
AzureIoTClient | 0:1f9b2707ec7d | 4 | #ifndef CODEFIRST_H |
AzureIoTClient | 0:1f9b2707ec7d | 5 | #define CODEFIRST_H |
AzureIoTClient | 0:1f9b2707ec7d | 6 | |
Azure.IoT.Build | 18:58b667752399 | 7 | #include "methodreturn.h" |
AzureIoTClient | 0:1f9b2707ec7d | 8 | #include "agenttypesystem.h" |
AzureIoTClient | 0:1f9b2707ec7d | 9 | #include "schema.h" |
Azure.IoT Build | 10:c2aee3965a83 | 10 | #include "azure_c_shared_utility/macro_utils.h" |
Azure.IoT Build | 10:c2aee3965a83 | 11 | #include "azure_c_shared_utility/strings.h" |
AzureIoTClient | 0:1f9b2707ec7d | 12 | #include "iotdevice.h" |
AzureIoTClient | 0:1f9b2707ec7d | 13 | |
AzureIoTClient | 0:1f9b2707ec7d | 14 | #ifdef __cplusplus |
AzureIoTClient | 0:1f9b2707ec7d | 15 | #include <cstddef> |
AzureIoTClient | 0:1f9b2707ec7d | 16 | #include <cstdarg> |
AzureIoTClient | 0:1f9b2707ec7d | 17 | extern "C" { |
AzureIoTClient | 0:1f9b2707ec7d | 18 | #else |
AzureIoTClient | 0:1f9b2707ec7d | 19 | #include <stddef.h> |
AzureIoTClient | 0:1f9b2707ec7d | 20 | #include <stdarg.h> |
AzureIoTClient | 26:7c0e6f86d034 | 21 | #include <stdbool.h> |
AzureIoTClient | 0:1f9b2707ec7d | 22 | #endif |
AzureIoTClient | 0:1f9b2707ec7d | 23 | |
AzureIoTClient | 0:1f9b2707ec7d | 24 | typedef char* ascii_char_ptr; |
AzureIoTClient | 0:1f9b2707ec7d | 25 | typedef char* ascii_char_ptr_no_quotes; |
AzureIoTClient | 0:1f9b2707ec7d | 26 | |
AzureIoTClient | 0:1f9b2707ec7d | 27 | typedef enum REFLECTION_TYPE_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 28 | { |
Azure.IoT.Build | 18:58b667752399 | 29 | REFLECTION_METHOD_TYPE, |
AzureIoTClient | 17:fa1bba4c6053 | 30 | REFLECTION_DESIRED_PROPERTY_TYPE, |
AzureIoTClient | 17:fa1bba4c6053 | 31 | REFLECTION_REPORTED_PROPERTY_TYPE, |
AzureIoTClient | 0:1f9b2707ec7d | 32 | REFLECTION_STRUCT_TYPE, |
AzureIoTClient | 0:1f9b2707ec7d | 33 | REFLECTION_FIELD_TYPE, |
AzureIoTClient | 0:1f9b2707ec7d | 34 | REFLECTION_PROPERTY_TYPE, |
AzureIoTClient | 0:1f9b2707ec7d | 35 | REFLECTION_ACTION_TYPE, |
AzureIoTClient | 0:1f9b2707ec7d | 36 | REFLECTION_MODEL_TYPE, |
AzureIoTClient | 0:1f9b2707ec7d | 37 | REFLECTION_NOTHING |
AzureIoTClient | 0:1f9b2707ec7d | 38 | }REFLECTION_TYPE; |
AzureIoTClient | 0:1f9b2707ec7d | 39 | |
AzureIoTClient | 0:1f9b2707ec7d | 40 | typedef EXECUTE_COMMAND_RESULT (*actionWrapper)(void* device, size_t ParameterCount, const AGENT_DATA_TYPE* values); |
AzureIoTClient | 0:1f9b2707ec7d | 41 | |
Azure.IoT.Build | 18:58b667752399 | 42 | typedef METHODRETURN_HANDLE (*methodWrapper)(void* device, size_t ParameterCount, const AGENT_DATA_TYPE* values); |
Azure.IoT.Build | 18:58b667752399 | 43 | |
AzureIoTClient | 0:1f9b2707ec7d | 44 | typedef struct REFLECTION_STRUCT_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 45 | { |
AzureIoTClient | 0:1f9b2707ec7d | 46 | const char* name; |
AzureIoTClient | 0:1f9b2707ec7d | 47 | }REFLECTION_STRUCT; |
AzureIoTClient | 0:1f9b2707ec7d | 48 | |
AzureIoTClient | 0:1f9b2707ec7d | 49 | typedef struct WRAPPER_ARGUMENT_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 50 | { |
AzureIoTClient | 0:1f9b2707ec7d | 51 | const char* type; |
AzureIoTClient | 0:1f9b2707ec7d | 52 | const char* name; |
AzureIoTClient | 0:1f9b2707ec7d | 53 | }WRAPPER_ARGUMENT; |
AzureIoTClient | 0:1f9b2707ec7d | 54 | |
AzureIoTClient | 0:1f9b2707ec7d | 55 | typedef struct REFLECTION_ACTION_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 56 | { |
AzureIoTClient | 0:1f9b2707ec7d | 57 | const char* name; |
AzureIoTClient | 0:1f9b2707ec7d | 58 | size_t nArguments; |
AzureIoTClient | 0:1f9b2707ec7d | 59 | const WRAPPER_ARGUMENT* arguments; |
AzureIoTClient | 0:1f9b2707ec7d | 60 | actionWrapper wrapper; |
AzureIoTClient | 0:1f9b2707ec7d | 61 | const char* modelName; |
AzureIoTClient | 0:1f9b2707ec7d | 62 | }REFLECTION_ACTION; |
AzureIoTClient | 0:1f9b2707ec7d | 63 | |
Azure.IoT.Build | 18:58b667752399 | 64 | typedef struct REFLECTION_METHOD_TAG |
Azure.IoT.Build | 18:58b667752399 | 65 | { |
Azure.IoT.Build | 18:58b667752399 | 66 | const char* name; |
Azure.IoT.Build | 18:58b667752399 | 67 | size_t nArguments; |
Azure.IoT.Build | 18:58b667752399 | 68 | const WRAPPER_ARGUMENT* arguments; |
Azure.IoT.Build | 18:58b667752399 | 69 | methodWrapper wrapper; |
Azure.IoT.Build | 18:58b667752399 | 70 | const char* modelName; |
Azure.IoT.Build | 18:58b667752399 | 71 | }REFLECTION_METHOD; |
Azure.IoT.Build | 18:58b667752399 | 72 | |
AzureIoTClient | 0:1f9b2707ec7d | 73 | typedef struct REFLECTION_FIELD_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 74 | { |
AzureIoTClient | 0:1f9b2707ec7d | 75 | const char* fieldName; |
AzureIoTClient | 0:1f9b2707ec7d | 76 | const char* fieldType; |
AzureIoTClient | 0:1f9b2707ec7d | 77 | const char* structName; |
AzureIoTClient | 0:1f9b2707ec7d | 78 | }REFLECTION_FIELD; |
AzureIoTClient | 0:1f9b2707ec7d | 79 | |
AzureIoTClient | 0:1f9b2707ec7d | 80 | typedef struct REFLECTION_PROPERTY_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 81 | { |
AzureIoTClient | 0:1f9b2707ec7d | 82 | const char* name; |
AzureIoTClient | 0:1f9b2707ec7d | 83 | const char* type; |
AzureIoTClient | 0:1f9b2707ec7d | 84 | int(*Create_AGENT_DATA_TYPE_from_Ptr)(void* param, AGENT_DATA_TYPE* dest); |
AzureIoTClient | 0:1f9b2707ec7d | 85 | size_t offset; |
AzureIoTClient | 0:1f9b2707ec7d | 86 | size_t size; |
AzureIoTClient | 0:1f9b2707ec7d | 87 | const char* modelName; |
AzureIoTClient | 0:1f9b2707ec7d | 88 | } REFLECTION_PROPERTY; |
AzureIoTClient | 0:1f9b2707ec7d | 89 | |
AzureIoTClient | 17:fa1bba4c6053 | 90 | |
AzureIoTClient | 17:fa1bba4c6053 | 91 | typedef struct REFLECTION_REPORTED_PROPERTY_TAG |
AzureIoTClient | 17:fa1bba4c6053 | 92 | { |
AzureIoTClient | 17:fa1bba4c6053 | 93 | const char* name; |
AzureIoTClient | 17:fa1bba4c6053 | 94 | const char* type; |
AzureIoTClient | 17:fa1bba4c6053 | 95 | int(*Create_AGENT_DATA_TYPE_from_Ptr)(void* param, AGENT_DATA_TYPE* dest); |
AzureIoTClient | 17:fa1bba4c6053 | 96 | size_t offset; |
AzureIoTClient | 17:fa1bba4c6053 | 97 | size_t size; |
AzureIoTClient | 17:fa1bba4c6053 | 98 | const char* modelName; |
AzureIoTClient | 17:fa1bba4c6053 | 99 | } REFLECTION_REPORTED_PROPERTY; |
AzureIoTClient | 17:fa1bba4c6053 | 100 | |
AzureIoTClient | 17:fa1bba4c6053 | 101 | typedef struct REFLECTION_DESIRED_PROPERTY_TAG |
AzureIoTClient | 17:fa1bba4c6053 | 102 | { |
AzureIoTClient | 17:fa1bba4c6053 | 103 | pfOnDesiredProperty onDesiredProperty; |
AzureIoTClient | 17:fa1bba4c6053 | 104 | void(*desiredPropertInitialize)(void* destination); |
AzureIoTClient | 17:fa1bba4c6053 | 105 | void(*desiredPropertDeinitialize)(void* destination); |
AzureIoTClient | 17:fa1bba4c6053 | 106 | const char* name; |
AzureIoTClient | 17:fa1bba4c6053 | 107 | const char* type; |
AzureIoTClient | 17:fa1bba4c6053 | 108 | int(*FromAGENT_DATA_TYPE)(const AGENT_DATA_TYPE* source, void* dest); /*destination is "something" everytime. When the DESIRED_PROPERTY is a MODEL, the function is empty*/ |
AzureIoTClient | 17:fa1bba4c6053 | 109 | size_t offset; |
AzureIoTClient | 17:fa1bba4c6053 | 110 | size_t size; |
AzureIoTClient | 17:fa1bba4c6053 | 111 | const char* modelName; |
AzureIoTClient | 17:fa1bba4c6053 | 112 | } REFLECTION_DESIRED_PROPERTY; |
AzureIoTClient | 17:fa1bba4c6053 | 113 | |
AzureIoTClient | 0:1f9b2707ec7d | 114 | typedef struct REFLECTION_MODEL_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 115 | { |
AzureIoTClient | 0:1f9b2707ec7d | 116 | const char* name; |
AzureIoTClient | 0:1f9b2707ec7d | 117 | } REFLECTION_MODEL; |
AzureIoTClient | 0:1f9b2707ec7d | 118 | |
AzureIoTClient | 0:1f9b2707ec7d | 119 | typedef struct REFLECTED_SOMETHING_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 120 | { |
AzureIoTClient | 0:1f9b2707ec7d | 121 | REFLECTION_TYPE type; |
AzureIoTClient | 0:1f9b2707ec7d | 122 | const struct REFLECTED_SOMETHING_TAG* next; |
AzureIoTClient | 0:1f9b2707ec7d | 123 | struct what |
AzureIoTClient | 0:1f9b2707ec7d | 124 | { |
Azure.IoT.Build | 18:58b667752399 | 125 | REFLECTION_METHOD method; |
AzureIoTClient | 17:fa1bba4c6053 | 126 | REFLECTION_DESIRED_PROPERTY desiredProperty; |
AzureIoTClient | 17:fa1bba4c6053 | 127 | REFLECTION_REPORTED_PROPERTY reportedProperty; |
AzureIoTClient | 0:1f9b2707ec7d | 128 | REFLECTION_STRUCT structure; |
AzureIoTClient | 0:1f9b2707ec7d | 129 | REFLECTION_FIELD field; |
AzureIoTClient | 0:1f9b2707ec7d | 130 | REFLECTION_PROPERTY property; |
AzureIoTClient | 0:1f9b2707ec7d | 131 | REFLECTION_ACTION action; |
AzureIoTClient | 0:1f9b2707ec7d | 132 | REFLECTION_MODEL model; |
AzureIoTClient | 0:1f9b2707ec7d | 133 | } what; |
AzureIoTClient | 0:1f9b2707ec7d | 134 | } REFLECTED_SOMETHING; |
AzureIoTClient | 0:1f9b2707ec7d | 135 | |
AzureIoTClient | 0:1f9b2707ec7d | 136 | typedef struct REFLECTED_DATA_FROM_DATAPROVIDER_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 137 | { |
AzureIoTClient | 0:1f9b2707ec7d | 138 | const REFLECTED_SOMETHING* reflectedData; |
AzureIoTClient | 0:1f9b2707ec7d | 139 | }REFLECTED_DATA_FROM_DATAPROVIDER; |
AzureIoTClient | 0:1f9b2707ec7d | 140 | |
AzureIoTClient | 0:1f9b2707ec7d | 141 | #define ALL_SOMETHING_REFLECTED(schemaNamespace) C2(schemaNamespace, _allSomethingReflected) |
AzureIoTClient | 0:1f9b2707ec7d | 142 | #define ALL_REFLECTED(schemaNamespace) C2(schemaNamespace, _allReflected) |
AzureIoTClient | 0:1f9b2707ec7d | 143 | #define ADDRESS_OF_ALL_REFLECTED(schemaNamespace) & C2(schemaNamespace, _allReflected), |
AzureIoTClient | 0:1f9b2707ec7d | 144 | #define DECLARE_EXTERN_CONST_DATAPROVIDER_DATA(x) extern const REFLECTED_DATA_FROM_DATAPROVIDER ALL_REFLECTED(x); |
AzureIoTClient | 0:1f9b2707ec7d | 145 | |
AzureIoTClient | 17:fa1bba4c6053 | 146 | #define CODEFIRST_RESULT_VALUES \ |
AzureIoTClient | 0:1f9b2707ec7d | 147 | CODEFIRST_OK, \ |
AzureIoTClient | 0:1f9b2707ec7d | 148 | CODEFIRST_INVALID_ARG, \ |
AzureIoTClient | 0:1f9b2707ec7d | 149 | CODEFIRST_ALREADY_INIT, \ |
AzureIoTClient | 0:1f9b2707ec7d | 150 | CODEFIRST_NOT_INIT, \ |
AzureIoTClient | 0:1f9b2707ec7d | 151 | CODEFIRST_ERROR, \ |
AzureIoTClient | 0:1f9b2707ec7d | 152 | CODEFIRST_NOT_ENOUGH_MEMORY, \ |
AzureIoTClient | 0:1f9b2707ec7d | 153 | CODEFIRST_ACTION_NOT_FOUND, \ |
AzureIoTClient | 0:1f9b2707ec7d | 154 | CODEFIRST_ACTION_EXECUTION_ERROR, \ |
AzureIoTClient | 0:1f9b2707ec7d | 155 | CODEFIRST_SCHEMA_ERROR, \ |
AzureIoTClient | 0:1f9b2707ec7d | 156 | CODEFIRST_AGENT_DATA_TYPE_ERROR, \ |
AzureIoTClient | 0:1f9b2707ec7d | 157 | CODEFIRST_VALUES_FROM_DIFFERENT_DEVICES_ERROR, \ |
AzureIoTClient | 0:1f9b2707ec7d | 158 | CODEFIRST_DEVICE_FAILED, \ |
AzureIoTClient | 0:1f9b2707ec7d | 159 | CODEFIRST_DEVICE_PUBLISH_FAILED, \ |
AzureIoTClient | 0:1f9b2707ec7d | 160 | CODEFIRST_NOT_A_PROPERTY |
AzureIoTClient | 0:1f9b2707ec7d | 161 | |
AzureIoTClient | 17:fa1bba4c6053 | 162 | DEFINE_ENUM(CODEFIRST_RESULT, CODEFIRST_RESULT_VALUES) |
AzureIoTClient | 0:1f9b2707ec7d | 163 | |
AzureIoTClient | 17:fa1bba4c6053 | 164 | #include "azure_c_shared_utility/umock_c_prod.h" |
AzureIoTClient | 17:fa1bba4c6053 | 165 | MOCKABLE_FUNCTION(, CODEFIRST_RESULT, CodeFirst_Init, const char*, overrideSchemaNamespace); |
AzureIoTClient | 17:fa1bba4c6053 | 166 | MOCKABLE_FUNCTION(, void, CodeFirst_Deinit); |
AzureIoTClient | 17:fa1bba4c6053 | 167 | MOCKABLE_FUNCTION(, SCHEMA_HANDLE, CodeFirst_RegisterSchema, const char*, schemaNamespace, const REFLECTED_DATA_FROM_DATAPROVIDER*, metadata); |
AzureIoTClient | 0:1f9b2707ec7d | 168 | |
AzureIoTClient | 17:fa1bba4c6053 | 169 | MOCKABLE_FUNCTION(, EXECUTE_COMMAND_RESULT, CodeFirst_InvokeAction, DEVICE_HANDLE, deviceHandle, void*, callbackUserContext, const char*, relativeActionPath, const char*, actionName, size_t, parameterCount, const AGENT_DATA_TYPE*, parameterValues); |
AzureIoTClient | 0:1f9b2707ec7d | 170 | |
Azure.IoT.Build | 18:58b667752399 | 171 | MOCKABLE_FUNCTION(, METHODRETURN_HANDLE, CodeFirst_InvokeMethod, DEVICE_HANDLE, deviceHandle, void*, callbackUserContext, const char*, relativeMethodPath, const char*, methodName, size_t, parameterCount, const AGENT_DATA_TYPE*, parameterValues); |
Azure.IoT.Build | 18:58b667752399 | 172 | |
AzureIoTClient | 17:fa1bba4c6053 | 173 | MOCKABLE_FUNCTION(, EXECUTE_COMMAND_RESULT, CodeFirst_ExecuteCommand, void*, device, const char*, command); |
AzureIoTClient | 0:1f9b2707ec7d | 174 | |
Azure.IoT.Build | 18:58b667752399 | 175 | MOCKABLE_FUNCTION(, METHODRETURN_HANDLE, CodeFirst_ExecuteMethod, void*, device, const char*, methodName, const char*, methodPayload); |
Azure.IoT.Build | 18:58b667752399 | 176 | |
AzureIoTClient | 17:fa1bba4c6053 | 177 | MOCKABLE_FUNCTION(, void*, CodeFirst_CreateDevice, SCHEMA_MODEL_TYPE_HANDLE, model, const REFLECTED_DATA_FROM_DATAPROVIDER*, metadata, size_t, dataSize, bool, includePropertyPath); |
AzureIoTClient | 17:fa1bba4c6053 | 178 | MOCKABLE_FUNCTION(, void, CodeFirst_DestroyDevice, void*, device); |
AzureIoTClient | 0:1f9b2707ec7d | 179 | |
AzureIoTClient | 0:1f9b2707ec7d | 180 | extern CODEFIRST_RESULT CodeFirst_SendAsync(unsigned char** destination, size_t* destinationSize, size_t numProperties, ...); |
AzureIoTClient | 17:fa1bba4c6053 | 181 | extern CODEFIRST_RESULT CodeFirst_SendAsyncReported(unsigned char** destination, size_t* destinationSize, size_t numReportedProperties, ...); |
AzureIoTClient | 0:1f9b2707ec7d | 182 | |
AzureIoTClient | 26:7c0e6f86d034 | 183 | MOCKABLE_FUNCTION(, CODEFIRST_RESULT, CodeFirst_IngestDesiredProperties, void*, device, const char*, jsonPayload, bool, parseDesiredNode); |
AzureIoTClient | 17:fa1bba4c6053 | 184 | |
AzureIoTClient | 17:fa1bba4c6053 | 185 | MOCKABLE_FUNCTION(, AGENT_DATA_TYPE_TYPE, CodeFirst_GetPrimitiveType, const char*, typeName); |
AzureIoTClient | 0:1f9b2707ec7d | 186 | |
AzureIoTClient | 0:1f9b2707ec7d | 187 | #ifdef __cplusplus |
AzureIoTClient | 0:1f9b2707ec7d | 188 | } |
AzureIoTClient | 0:1f9b2707ec7d | 189 | #endif |
AzureIoTClient | 0:1f9b2707ec7d | 190 | |
AzureIoTClient | 0:1f9b2707ec7d | 191 | #endif /* CODEFIRST_H */ |