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
iotdevice.c@18:58b667752399, 2016-12-14 (annotated)
- Committer:
- Azure.IoT.Build
- Date:
- Wed Dec 14 16:00:39 2016 -0800
- Revision:
- 18:58b667752399
- Parent:
- 17:fa1bba4c6053
- Child:
- 21:6d3dea1abd9c
1.1.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AzureIoTClient | 0:1f9b2707ec7d | 1 | // Copyright (c) Microsoft. All rights reserved. |
AzureIoTClient | 0:1f9b2707ec7d | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
AzureIoTClient | 0:1f9b2707ec7d | 3 | |
AzureIoTClient | 0:1f9b2707ec7d | 4 | #include <stdlib.h> |
AzureIoTClient | 0:1f9b2707ec7d | 5 | #ifdef _CRTDBG_MAP_ALLOC |
AzureIoTClient | 0:1f9b2707ec7d | 6 | #include <crtdbg.h> |
AzureIoTClient | 0:1f9b2707ec7d | 7 | #endif |
Azure.IoT Build | 10:c2aee3965a83 | 8 | #include "azure_c_shared_utility/gballoc.h" |
AzureIoTClient | 0:1f9b2707ec7d | 9 | |
AzureIoTClient | 0:1f9b2707ec7d | 10 | #include <stdbool.h> |
AzureIoTClient | 0:1f9b2707ec7d | 11 | #include "iotdevice.h" |
AzureIoTClient | 0:1f9b2707ec7d | 12 | #include "datapublisher.h" |
AzureIoTClient | 0:1f9b2707ec7d | 13 | #include "commanddecoder.h" |
Azure.IoT Build | 10:c2aee3965a83 | 14 | #include "azure_c_shared_utility/crt_abstractions.h" |
Azure.IoT Build | 13:16e88f0cfa5f | 15 | #include "azure_c_shared_utility/xlogging.h" |
AzureIoTClient | 0:1f9b2707ec7d | 16 | |
AzureIoTClient | 0:1f9b2707ec7d | 17 | #define LOG_DEVICE_ERROR \ |
AzureIoTClient | 11:b1327861f5e0 | 18 | LogError("(result = %s)", ENUM_TO_STRING(DEVICE_RESULT, result)) |
AzureIoTClient | 0:1f9b2707ec7d | 19 | |
AzureIoTClient | 17:fa1bba4c6053 | 20 | |
AzureIoTClient | 17:fa1bba4c6053 | 21 | |
AzureIoTClient | 17:fa1bba4c6053 | 22 | typedef struct DEVICE_HANDLE_DATA_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 23 | { |
AzureIoTClient | 0:1f9b2707ec7d | 24 | SCHEMA_MODEL_TYPE_HANDLE model; |
AzureIoTClient | 0:1f9b2707ec7d | 25 | DATA_PUBLISHER_HANDLE dataPublisherHandle; |
AzureIoTClient | 17:fa1bba4c6053 | 26 | pfDeviceActionCallback deviceActionCallback; |
AzureIoTClient | 0:1f9b2707ec7d | 27 | void* callbackUserContext; |
Azure.IoT.Build | 18:58b667752399 | 28 | pfDeviceMethodCallback deviceMethodCallback; |
Azure.IoT.Build | 18:58b667752399 | 29 | void* methodCallbackUserContext; |
Azure.IoT.Build | 18:58b667752399 | 30 | |
AzureIoTClient | 0:1f9b2707ec7d | 31 | COMMAND_DECODER_HANDLE commandDecoderHandle; |
AzureIoTClient | 17:fa1bba4c6053 | 32 | } DEVICE_HANDLE_DATA; |
AzureIoTClient | 0:1f9b2707ec7d | 33 | |
AzureIoTClient | 0:1f9b2707ec7d | 34 | DEFINE_ENUM_STRINGS(DEVICE_RESULT, DEVICE_RESULT_VALUES); |
AzureIoTClient | 0:1f9b2707ec7d | 35 | |
AzureIoTClient | 0:1f9b2707ec7d | 36 | static EXECUTE_COMMAND_RESULT DeviceInvokeAction(void* actionCallbackContext, const char* relativeActionPath, const char* actionName, size_t argCount, const AGENT_DATA_TYPE* args) |
AzureIoTClient | 0:1f9b2707ec7d | 37 | { |
AzureIoTClient | 0:1f9b2707ec7d | 38 | EXECUTE_COMMAND_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 39 | |
AzureIoTClient | 0:1f9b2707ec7d | 40 | /*Codes_SRS_DEVICE_02_011: [If the parameter actionCallbackContent passed the callback is NULL then the callback shall return EXECUTE_COMMAND_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 41 | if (actionCallbackContext == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 42 | { |
AzureIoTClient | 0:1f9b2707ec7d | 43 | result = EXECUTE_COMMAND_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 44 | LogError("(Error code = %s)", ENUM_TO_STRING(DEVICE_RESULT, DEVICE_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 45 | } |
AzureIoTClient | 0:1f9b2707ec7d | 46 | else |
AzureIoTClient | 0:1f9b2707ec7d | 47 | { |
AzureIoTClient | 17:fa1bba4c6053 | 48 | DEVICE_HANDLE_DATA* device = (DEVICE_HANDLE_DATA*)actionCallbackContext; |
AzureIoTClient | 0:1f9b2707ec7d | 49 | |
AzureIoTClient | 0:1f9b2707ec7d | 50 | /* Codes_SRS_DEVICE_01_052: [When the action callback passed to CommandDecoder is called, Device shall call the appropriate user callback associated with the device handle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 51 | /* Codes_SRS_DEVICE_01_055: [The value passed in callbackUserContext when creating the device shall be passed to the callback as the value for the callbackUserContext argument.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 52 | result = device->deviceActionCallback((DEVICE_HANDLE)device, device->callbackUserContext, relativeActionPath, actionName, argCount, args); |
AzureIoTClient | 0:1f9b2707ec7d | 53 | } |
AzureIoTClient | 0:1f9b2707ec7d | 54 | |
AzureIoTClient | 0:1f9b2707ec7d | 55 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 56 | } |
AzureIoTClient | 0:1f9b2707ec7d | 57 | |
Azure.IoT.Build | 18:58b667752399 | 58 | static METHODRETURN_HANDLE DeviceInvokeMethod(void* methodCallbackContext, const char* relativeMethodPath, const char* methodName, size_t argCount, const AGENT_DATA_TYPE* args) |
Azure.IoT.Build | 18:58b667752399 | 59 | { |
Azure.IoT.Build | 18:58b667752399 | 60 | METHODRETURN_HANDLE result; |
Azure.IoT.Build | 18:58b667752399 | 61 | |
Azure.IoT.Build | 18:58b667752399 | 62 | if (methodCallbackContext == NULL) |
Azure.IoT.Build | 18:58b667752399 | 63 | { |
Azure.IoT.Build | 18:58b667752399 | 64 | result = NULL; |
Azure.IoT.Build | 18:58b667752399 | 65 | LogError("(Error code = %s)", ENUM_TO_STRING(DEVICE_RESULT, DEVICE_INVALID_ARG)); |
Azure.IoT.Build | 18:58b667752399 | 66 | } |
Azure.IoT.Build | 18:58b667752399 | 67 | else |
Azure.IoT.Build | 18:58b667752399 | 68 | { |
Azure.IoT.Build | 18:58b667752399 | 69 | DEVICE_HANDLE_DATA* device = (DEVICE_HANDLE_DATA*)methodCallbackContext; |
Azure.IoT.Build | 18:58b667752399 | 70 | |
Azure.IoT.Build | 18:58b667752399 | 71 | result = device->deviceMethodCallback((DEVICE_HANDLE)device, device->methodCallbackUserContext, relativeMethodPath, methodName, argCount, args); |
Azure.IoT.Build | 18:58b667752399 | 72 | } |
Azure.IoT.Build | 18:58b667752399 | 73 | |
Azure.IoT.Build | 18:58b667752399 | 74 | return result; |
Azure.IoT.Build | 18:58b667752399 | 75 | } |
Azure.IoT.Build | 18:58b667752399 | 76 | |
Azure.IoT.Build | 18:58b667752399 | 77 | DEVICE_RESULT Device_Create(SCHEMA_MODEL_TYPE_HANDLE modelHandle, pfDeviceActionCallback deviceActionCallback, void* callbackUserContext, pfDeviceMethodCallback methodCallback, void* methodCallbackContext, bool includePropertyPath, DEVICE_HANDLE* deviceHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 78 | { |
AzureIoTClient | 0:1f9b2707ec7d | 79 | DEVICE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 80 | |
AzureIoTClient | 0:1f9b2707ec7d | 81 | /* Codes_SRS_DEVICE_05_014: [If any of the modelHandle, deviceHandle or deviceActionCallback arguments are NULL, Device_Create shall return DEVICE_INVALID_ARG.]*/ |
Azure.IoT.Build | 18:58b667752399 | 82 | if (modelHandle == NULL || deviceHandle == NULL || deviceActionCallback == NULL || methodCallback == NULL || methodCallbackContext == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 83 | { |
AzureIoTClient | 0:1f9b2707ec7d | 84 | result = DEVICE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 85 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 86 | } |
AzureIoTClient | 0:1f9b2707ec7d | 87 | else |
AzureIoTClient | 0:1f9b2707ec7d | 88 | { |
AzureIoTClient | 17:fa1bba4c6053 | 89 | DEVICE_HANDLE_DATA* device = (DEVICE_HANDLE_DATA*)malloc(sizeof(DEVICE_HANDLE_DATA)); |
AzureIoTClient | 0:1f9b2707ec7d | 90 | if (device == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 91 | { |
AzureIoTClient | 0:1f9b2707ec7d | 92 | /* Codes_SRS_DEVICE_05_015: [If an error occurs while trying to create the device, Device_Create shall return DEVICE_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 93 | result = DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 94 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 95 | } |
AzureIoTClient | 0:1f9b2707ec7d | 96 | else |
AzureIoTClient | 0:1f9b2707ec7d | 97 | { |
AzureIoTClient | 0:1f9b2707ec7d | 98 | /* Codes_SRS_DEVICE_01_018: [Device_Create shall create a DataPublisher instance by calling DataPublisher_Create.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 99 | /* Codes_SRS_DEVICE_01_020: [Device_Create shall pass to DataPublisher_Create the FrontDoor instance obtained earlier.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 100 | /* Codes_SRS_DEVICE_01_004: [DeviceCreate shall pass to DataPublisher_create the includePropertyPath argument.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 101 | if ((device->dataPublisherHandle = DataPublisher_Create(modelHandle, includePropertyPath)) == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 102 | { |
AzureIoTClient | 0:1f9b2707ec7d | 103 | free(device); |
AzureIoTClient | 0:1f9b2707ec7d | 104 | |
AzureIoTClient | 0:1f9b2707ec7d | 105 | /* Codes_SRS_DEVICE_01_019: [If creating the DataPublisher instance fails, Device_Create shall return DEVICE_DATA_PUBLISHER_FAILED.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 106 | result = DEVICE_DATA_PUBLISHER_FAILED; |
AzureIoTClient | 0:1f9b2707ec7d | 107 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 108 | } |
AzureIoTClient | 0:1f9b2707ec7d | 109 | else |
AzureIoTClient | 0:1f9b2707ec7d | 110 | { |
AzureIoTClient | 0:1f9b2707ec7d | 111 | device->model = modelHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 112 | device->deviceActionCallback = deviceActionCallback; |
AzureIoTClient | 0:1f9b2707ec7d | 113 | device->callbackUserContext = callbackUserContext; |
Azure.IoT.Build | 18:58b667752399 | 114 | device->deviceMethodCallback = methodCallback; |
Azure.IoT.Build | 18:58b667752399 | 115 | device->methodCallbackUserContext = methodCallbackContext; |
AzureIoTClient | 0:1f9b2707ec7d | 116 | |
AzureIoTClient | 0:1f9b2707ec7d | 117 | /* Codes_SRS_DEVICE_01_001: [Device_Create shall create a CommandDecoder instance by calling CommandDecoder_Create and passing to it the model handle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 118 | /* Codes_SRS_DEVICE_01_002: [Device_Create shall also pass to CommandDecoder_Create a callback to be invoked when a command is received and a context that shall be the device handle.] */ |
Azure.IoT.Build | 18:58b667752399 | 119 | if ((device->commandDecoderHandle = CommandDecoder_Create(modelHandle, DeviceInvokeAction, device, DeviceInvokeMethod, device)) == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 120 | { |
AzureIoTClient | 17:fa1bba4c6053 | 121 | DataPublisher_Destroy(device->dataPublisherHandle); |
AzureIoTClient | 0:1f9b2707ec7d | 122 | free(device); |
AzureIoTClient | 0:1f9b2707ec7d | 123 | |
AzureIoTClient | 0:1f9b2707ec7d | 124 | /* Codes_SRS_DEVICE_01_003: [If CommandDecoder_Create fails, Device_Create shall return DEVICE_COMMAND_DECODER_FAILED.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 125 | result = DEVICE_COMMAND_DECODER_FAILED; |
AzureIoTClient | 0:1f9b2707ec7d | 126 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 127 | } |
AzureIoTClient | 0:1f9b2707ec7d | 128 | else |
AzureIoTClient | 0:1f9b2707ec7d | 129 | { |
AzureIoTClient | 0:1f9b2707ec7d | 130 | /* Codes_SRS_DEVICE_03_003: [The DEVICE_HANDLE shall be provided via the deviceHandle out argument.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 131 | *deviceHandle = (DEVICE_HANDLE)device; |
AzureIoTClient | 0:1f9b2707ec7d | 132 | /* Codes_SRS_DEVICE_03_004: [Device_Create shall return DEVICE_OK upon success.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 133 | result = DEVICE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 134 | } |
AzureIoTClient | 0:1f9b2707ec7d | 135 | } |
AzureIoTClient | 0:1f9b2707ec7d | 136 | } |
AzureIoTClient | 0:1f9b2707ec7d | 137 | } |
AzureIoTClient | 0:1f9b2707ec7d | 138 | |
AzureIoTClient | 0:1f9b2707ec7d | 139 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 140 | } |
AzureIoTClient | 0:1f9b2707ec7d | 141 | |
AzureIoTClient | 0:1f9b2707ec7d | 142 | /* Codes_SRS_DEVICE_03_006: [Device_Destroy shall free all resources associated with a device.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 143 | void Device_Destroy(DEVICE_HANDLE deviceHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 144 | { |
AzureIoTClient | 0:1f9b2707ec7d | 145 | /* Codes_SRS_DEVICE_03_007: [Device_Destroy will not do anything if deviceHandle is NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 146 | if (deviceHandle != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 147 | { |
AzureIoTClient | 17:fa1bba4c6053 | 148 | DEVICE_HANDLE_DATA* device = (DEVICE_HANDLE_DATA*)deviceHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 149 | |
AzureIoTClient | 0:1f9b2707ec7d | 150 | DataPublisher_Destroy(device->dataPublisherHandle); |
AzureIoTClient | 0:1f9b2707ec7d | 151 | CommandDecoder_Destroy(device->commandDecoderHandle); |
AzureIoTClient | 0:1f9b2707ec7d | 152 | |
AzureIoTClient | 0:1f9b2707ec7d | 153 | free(device); |
AzureIoTClient | 0:1f9b2707ec7d | 154 | } |
AzureIoTClient | 0:1f9b2707ec7d | 155 | } |
AzureIoTClient | 0:1f9b2707ec7d | 156 | |
AzureIoTClient | 0:1f9b2707ec7d | 157 | TRANSACTION_HANDLE Device_StartTransaction(DEVICE_HANDLE deviceHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 158 | { |
AzureIoTClient | 0:1f9b2707ec7d | 159 | TRANSACTION_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 160 | |
AzureIoTClient | 0:1f9b2707ec7d | 161 | /* Codes_SRS_DEVICE_01_035: [If any argument is NULL, Device_StartTransaction shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 162 | if (deviceHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 163 | { |
AzureIoTClient | 0:1f9b2707ec7d | 164 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 165 | LogError("(Error code = %s)", ENUM_TO_STRING(DEVICE_RESULT, DEVICE_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 166 | } |
AzureIoTClient | 0:1f9b2707ec7d | 167 | else |
AzureIoTClient | 0:1f9b2707ec7d | 168 | { |
AzureIoTClient | 17:fa1bba4c6053 | 169 | DEVICE_HANDLE_DATA* deviceInstance = (DEVICE_HANDLE_DATA*)deviceHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 170 | |
AzureIoTClient | 0:1f9b2707ec7d | 171 | /* Codes_SRS_DEVICE_01_034: [Device_StartTransaction shall invoke DataPublisher_StartTransaction for the DataPublisher handle associated with the deviceHandle argument.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 172 | /* Codes_SRS_DEVICE_01_043: [On success, Device_StartTransaction shall return a non NULL handle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 173 | /* Codes_SRS_DEVICE_01_048: [When DataPublisher_StartTransaction fails, Device_StartTransaction shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 174 | result = DataPublisher_StartTransaction(deviceInstance->dataPublisherHandle); |
AzureIoTClient | 0:1f9b2707ec7d | 175 | } |
AzureIoTClient | 0:1f9b2707ec7d | 176 | |
AzureIoTClient | 0:1f9b2707ec7d | 177 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 178 | } |
AzureIoTClient | 0:1f9b2707ec7d | 179 | |
AzureIoTClient | 0:1f9b2707ec7d | 180 | DEVICE_RESULT Device_PublishTransacted(TRANSACTION_HANDLE transactionHandle, const char* propertyPath, const AGENT_DATA_TYPE* data) |
AzureIoTClient | 0:1f9b2707ec7d | 181 | { |
AzureIoTClient | 0:1f9b2707ec7d | 182 | DEVICE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 183 | |
AzureIoTClient | 0:1f9b2707ec7d | 184 | /* Codes_SRS_DEVICE_01_037: [If any argument is NULL, Device_PublishTransacted shall return DEVICE_INVALID_ARG.] */ |
AzureIoTClient | 17:fa1bba4c6053 | 185 | if ( |
AzureIoTClient | 17:fa1bba4c6053 | 186 | (transactionHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 187 | (propertyPath == NULL) || |
AzureIoTClient | 17:fa1bba4c6053 | 188 | (data == NULL) |
AzureIoTClient | 17:fa1bba4c6053 | 189 | ) |
AzureIoTClient | 0:1f9b2707ec7d | 190 | { |
AzureIoTClient | 0:1f9b2707ec7d | 191 | result = DEVICE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 192 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 193 | } |
AzureIoTClient | 0:1f9b2707ec7d | 194 | /* Codes_SRS_DEVICE_01_036: [Device_PublishTransacted shall invoke DataPublisher_PublishTransacted.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 195 | else if (DataPublisher_PublishTransacted(transactionHandle, propertyPath, data) != DATA_PUBLISHER_OK) |
AzureIoTClient | 0:1f9b2707ec7d | 196 | { |
AzureIoTClient | 0:1f9b2707ec7d | 197 | /* Codes_SRS_DEVICE_01_049: [When DataPublisher_PublishTransacted fails, Device_PublishTransacted shall return DEVICE_DATA_PUBLISHER_FAILED.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 198 | result = DEVICE_DATA_PUBLISHER_FAILED; |
AzureIoTClient | 0:1f9b2707ec7d | 199 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 200 | } |
AzureIoTClient | 0:1f9b2707ec7d | 201 | else |
AzureIoTClient | 0:1f9b2707ec7d | 202 | { |
AzureIoTClient | 0:1f9b2707ec7d | 203 | /* Codes_SRS_DEVICE_01_044: [On success, Device_PublishTransacted shall return DEVICE_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 204 | result = DEVICE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 205 | } |
AzureIoTClient | 0:1f9b2707ec7d | 206 | |
AzureIoTClient | 0:1f9b2707ec7d | 207 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 208 | } |
AzureIoTClient | 0:1f9b2707ec7d | 209 | |
AzureIoTClient | 0:1f9b2707ec7d | 210 | DEVICE_RESULT Device_EndTransaction(TRANSACTION_HANDLE transactionHandle, unsigned char** destination, size_t* destinationSize) |
AzureIoTClient | 0:1f9b2707ec7d | 211 | { |
AzureIoTClient | 0:1f9b2707ec7d | 212 | DEVICE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 213 | |
AzureIoTClient | 0:1f9b2707ec7d | 214 | /* Codes_SRS_DEVICE_01_039: [If any parameter is NULL, Device_EndTransaction shall return DEVICE_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 215 | if ( |
AzureIoTClient | 0:1f9b2707ec7d | 216 | (transactionHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 217 | (destination == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 218 | (destinationSize == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 219 | ) |
AzureIoTClient | 0:1f9b2707ec7d | 220 | { |
AzureIoTClient | 0:1f9b2707ec7d | 221 | result = DEVICE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 222 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 223 | } |
AzureIoTClient | 0:1f9b2707ec7d | 224 | /* Codes_SRS_DEVICE_01_038: [Device_EndTransaction shall invoke DataPublisher_EndTransaction.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 225 | else if (DataPublisher_EndTransaction(transactionHandle, destination, destinationSize) != DATA_PUBLISHER_OK) |
AzureIoTClient | 0:1f9b2707ec7d | 226 | { |
AzureIoTClient | 0:1f9b2707ec7d | 227 | /* Codes_SRS_DEVICE_01_050: [When DataPublisher_EndTransaction fails, Device_EndTransaction shall return DEVICE_DATA_PUBLISHER_FAILED.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 228 | result = DEVICE_DATA_PUBLISHER_FAILED; |
AzureIoTClient | 0:1f9b2707ec7d | 229 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 230 | } |
AzureIoTClient | 0:1f9b2707ec7d | 231 | else |
AzureIoTClient | 0:1f9b2707ec7d | 232 | { |
AzureIoTClient | 0:1f9b2707ec7d | 233 | /* Codes_SRS_DEVICE_01_045: [On success, Device_EndTransaction shall return DEVICE_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 234 | result = DEVICE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 235 | } |
AzureIoTClient | 0:1f9b2707ec7d | 236 | |
AzureIoTClient | 0:1f9b2707ec7d | 237 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 238 | } |
AzureIoTClient | 0:1f9b2707ec7d | 239 | |
AzureIoTClient | 0:1f9b2707ec7d | 240 | DEVICE_RESULT Device_CancelTransaction(TRANSACTION_HANDLE transactionHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 241 | { |
AzureIoTClient | 0:1f9b2707ec7d | 242 | DEVICE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 243 | |
AzureIoTClient | 0:1f9b2707ec7d | 244 | /* Codes_SRS_DEVICE_01_041: [If any argument is NULL, Device_CancelTransaction shall return DEVICE_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 245 | if (transactionHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 246 | { |
AzureIoTClient | 0:1f9b2707ec7d | 247 | result = DEVICE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 248 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 249 | } |
AzureIoTClient | 0:1f9b2707ec7d | 250 | /* Codes_SRS_DEVICE_01_040: [Device_CancelTransaction shall invoke DataPublisher_CancelTransaction.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 251 | else if (DataPublisher_CancelTransaction(transactionHandle) != DATA_PUBLISHER_OK) |
AzureIoTClient | 0:1f9b2707ec7d | 252 | { |
AzureIoTClient | 0:1f9b2707ec7d | 253 | /* Codes_SRS_DEVICE_01_051: [When DataPublisher_CancelTransaction fails, Device_CancelTransaction shall return DEVICE_DATA_PUBLISHER_FAILED.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 254 | result = DEVICE_DATA_PUBLISHER_FAILED; |
AzureIoTClient | 0:1f9b2707ec7d | 255 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 256 | } |
AzureIoTClient | 0:1f9b2707ec7d | 257 | else |
AzureIoTClient | 0:1f9b2707ec7d | 258 | { |
AzureIoTClient | 0:1f9b2707ec7d | 259 | /* Codes_SRS_DEVICE_01_046: [On success, Device_PublishTransacted shall return DEVICE_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 260 | result = DEVICE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 261 | } |
AzureIoTClient | 0:1f9b2707ec7d | 262 | |
AzureIoTClient | 0:1f9b2707ec7d | 263 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 264 | } |
AzureIoTClient | 0:1f9b2707ec7d | 265 | |
AzureIoTClient | 0:1f9b2707ec7d | 266 | EXECUTE_COMMAND_RESULT Device_ExecuteCommand(DEVICE_HANDLE deviceHandle, const char* command) |
AzureIoTClient | 0:1f9b2707ec7d | 267 | { |
AzureIoTClient | 0:1f9b2707ec7d | 268 | EXECUTE_COMMAND_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 269 | /*Codes_SRS_DEVICE_02_012: [If any parameters are NULL, then Device_ExecuteCommand shall return EXECUTE_COMMAND_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 270 | if ( |
AzureIoTClient | 0:1f9b2707ec7d | 271 | (deviceHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 272 | (command == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 273 | ) |
AzureIoTClient | 0:1f9b2707ec7d | 274 | { |
AzureIoTClient | 0:1f9b2707ec7d | 275 | result = EXECUTE_COMMAND_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 276 | LogError("invalid parameter (NULL passed to Device_ExecuteCommand DEVICE_HANDLE deviceHandle=%p, const char* command=%p", deviceHandle, command); |
AzureIoTClient | 0:1f9b2707ec7d | 277 | } |
AzureIoTClient | 0:1f9b2707ec7d | 278 | else |
AzureIoTClient | 0:1f9b2707ec7d | 279 | { |
AzureIoTClient | 0:1f9b2707ec7d | 280 | /*Codes_SRS_DEVICE_02_013: [Otherwise, Device_ExecuteCommand shall call CommandDecoder_ExecuteCommand and return what CommandDecoder_ExecuteCommand is returning.] */ |
AzureIoTClient | 17:fa1bba4c6053 | 281 | DEVICE_HANDLE_DATA* device = (DEVICE_HANDLE_DATA*)deviceHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 282 | result = CommandDecoder_ExecuteCommand(device->commandDecoderHandle, command); |
AzureIoTClient | 0:1f9b2707ec7d | 283 | } |
AzureIoTClient | 0:1f9b2707ec7d | 284 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 285 | } |
AzureIoTClient | 17:fa1bba4c6053 | 286 | |
Azure.IoT.Build | 18:58b667752399 | 287 | METHODRETURN_HANDLE Device_ExecuteMethod(DEVICE_HANDLE deviceHandle, const char* methodName, const char* methodPayload) |
Azure.IoT.Build | 18:58b667752399 | 288 | { |
Azure.IoT.Build | 18:58b667752399 | 289 | METHODRETURN_HANDLE result; |
Azure.IoT.Build | 18:58b667752399 | 290 | if ( |
Azure.IoT.Build | 18:58b667752399 | 291 | (deviceHandle == NULL) || |
Azure.IoT.Build | 18:58b667752399 | 292 | (methodName == NULL) /*methodPayload can be NULL*/ |
Azure.IoT.Build | 18:58b667752399 | 293 | ) |
Azure.IoT.Build | 18:58b667752399 | 294 | { |
Azure.IoT.Build | 18:58b667752399 | 295 | result = NULL; |
Azure.IoT.Build | 18:58b667752399 | 296 | LogError("invalid parameter (NULL passed to Device_ExecuteMethod DEVICE_HANDLE deviceHandle=%p, const char* methodPayload=%p", deviceHandle, methodPayload); |
Azure.IoT.Build | 18:58b667752399 | 297 | } |
Azure.IoT.Build | 18:58b667752399 | 298 | else |
Azure.IoT.Build | 18:58b667752399 | 299 | { |
Azure.IoT.Build | 18:58b667752399 | 300 | DEVICE_HANDLE_DATA* device = (DEVICE_HANDLE_DATA*)deviceHandle; |
Azure.IoT.Build | 18:58b667752399 | 301 | result = CommandDecoder_ExecuteMethod(device->commandDecoderHandle, methodName, methodPayload); |
Azure.IoT.Build | 18:58b667752399 | 302 | } |
Azure.IoT.Build | 18:58b667752399 | 303 | return result; |
Azure.IoT.Build | 18:58b667752399 | 304 | } |
Azure.IoT.Build | 18:58b667752399 | 305 | |
AzureIoTClient | 17:fa1bba4c6053 | 306 | REPORTED_PROPERTIES_TRANSACTION_HANDLE Device_CreateTransaction_ReportedProperties(DEVICE_HANDLE deviceHandle) |
AzureIoTClient | 17:fa1bba4c6053 | 307 | { |
AzureIoTClient | 17:fa1bba4c6053 | 308 | REPORTED_PROPERTIES_TRANSACTION_HANDLE result; |
AzureIoTClient | 17:fa1bba4c6053 | 309 | |
AzureIoTClient | 17:fa1bba4c6053 | 310 | /*Codes_SRS_DEVICE_02_014: [ If argument deviceHandle is NULL then Device_CreateTransaction_ReportedProperties shall fail and return NULL. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 311 | if (deviceHandle == NULL) |
AzureIoTClient | 17:fa1bba4c6053 | 312 | { |
AzureIoTClient | 17:fa1bba4c6053 | 313 | LogError("invalid argument DEVICE_HANDLE deviceHandle=%p", deviceHandle); |
AzureIoTClient | 17:fa1bba4c6053 | 314 | result = NULL; |
AzureIoTClient | 17:fa1bba4c6053 | 315 | } |
AzureIoTClient | 17:fa1bba4c6053 | 316 | else |
AzureIoTClient | 17:fa1bba4c6053 | 317 | { |
AzureIoTClient | 17:fa1bba4c6053 | 318 | DEVICE_HANDLE_DATA* deviceInstance = (DEVICE_HANDLE_DATA*)deviceHandle; |
AzureIoTClient | 17:fa1bba4c6053 | 319 | /*Codes_SRS_DEVICE_02_015: [ Otherwise, Device_CreateTransaction_ReportedProperties shall call DataPublisher_CreateTransaction_ReportedProperties. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 320 | /*Codes_SRS_DEVICE_02_016: [ If DataPublisher_CreateTransaction_ReportedProperties fails then Device_CreateTransaction_ReportedProperties shall fail and return NULL. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 321 | /*Codes_SRS_DEVICE_02_017: [ Otherwise Device_CreateTransaction_ReportedProperties shall succeed and return a non-NULL value. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 322 | result = DataPublisher_CreateTransaction_ReportedProperties(deviceInstance->dataPublisherHandle); |
AzureIoTClient | 17:fa1bba4c6053 | 323 | if (result == NULL) |
AzureIoTClient | 17:fa1bba4c6053 | 324 | { |
AzureIoTClient | 17:fa1bba4c6053 | 325 | LogError("unable to DataPublisher_CreateTransaction_ReportedProperties"); |
AzureIoTClient | 17:fa1bba4c6053 | 326 | /*return as is*/ |
AzureIoTClient | 17:fa1bba4c6053 | 327 | } |
AzureIoTClient | 17:fa1bba4c6053 | 328 | else |
AzureIoTClient | 17:fa1bba4c6053 | 329 | { |
AzureIoTClient | 17:fa1bba4c6053 | 330 | /*return as is*/ |
AzureIoTClient | 17:fa1bba4c6053 | 331 | } |
AzureIoTClient | 17:fa1bba4c6053 | 332 | } |
AzureIoTClient | 17:fa1bba4c6053 | 333 | |
AzureIoTClient | 17:fa1bba4c6053 | 334 | return result; |
AzureIoTClient | 17:fa1bba4c6053 | 335 | } |
AzureIoTClient | 17:fa1bba4c6053 | 336 | |
AzureIoTClient | 17:fa1bba4c6053 | 337 | DEVICE_RESULT Device_PublishTransacted_ReportedProperty(REPORTED_PROPERTIES_TRANSACTION_HANDLE transactionHandle, const char* reportedPropertyPath, const AGENT_DATA_TYPE* data) |
AzureIoTClient | 17:fa1bba4c6053 | 338 | { |
AzureIoTClient | 17:fa1bba4c6053 | 339 | DEVICE_RESULT result; |
AzureIoTClient | 17:fa1bba4c6053 | 340 | /*Codes_SRS_DEVICE_02_018: [ If argument transactionHandle is NULL then Device_PublishTransacted_ReportedProperty shall fail and return DEVICE_INVALID_ARG. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 341 | /*Codes_SRS_DEVICE_02_019: [ If argument reportedPropertyPath is NULL then Device_PublishTransacted_ReportedProperty shall fail and return DEVICE_INVALID_ARG. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 342 | /*Codes_SRS_DEVICE_02_020: [ If argument data is NULL then Device_PublishTransacted_ReportedProperty shall fail and return DEVICE_INVALID_ARG. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 343 | if ( |
AzureIoTClient | 17:fa1bba4c6053 | 344 | (transactionHandle == NULL) || |
AzureIoTClient | 17:fa1bba4c6053 | 345 | (reportedPropertyPath == NULL) || |
AzureIoTClient | 17:fa1bba4c6053 | 346 | (data == NULL) |
AzureIoTClient | 17:fa1bba4c6053 | 347 | ) |
AzureIoTClient | 17:fa1bba4c6053 | 348 | { |
AzureIoTClient | 17:fa1bba4c6053 | 349 | LogError("invalid argument REPORTED_PROPERTIES_TRANSACTION_HANDLE transactionHandle=%p, const char* reportedPropertyPath=%s, const AGENT_DATA_TYPE* data=%p", transactionHandle, reportedPropertyPath, data); |
AzureIoTClient | 17:fa1bba4c6053 | 350 | result = DEVICE_INVALID_ARG; |
AzureIoTClient | 17:fa1bba4c6053 | 351 | } |
AzureIoTClient | 17:fa1bba4c6053 | 352 | else |
AzureIoTClient | 17:fa1bba4c6053 | 353 | { |
AzureIoTClient | 17:fa1bba4c6053 | 354 | /*Codes_SRS_DEVICE_02_021: [ Device_PublishTransacted_ReportedProperty shall call DataPublisher_PublishTransacted_ReportedProperty. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 355 | DATA_PUBLISHER_RESULT r = DataPublisher_PublishTransacted_ReportedProperty(transactionHandle, reportedPropertyPath, data); |
AzureIoTClient | 17:fa1bba4c6053 | 356 | if (r != DATA_PUBLISHER_OK) |
AzureIoTClient | 17:fa1bba4c6053 | 357 | { |
AzureIoTClient | 17:fa1bba4c6053 | 358 | LogError("unable to DataPublisher_PublishTransacted_ReportedProperty"); |
AzureIoTClient | 17:fa1bba4c6053 | 359 | /*Codes_SRS_DEVICE_02_022: [ If DataPublisher_PublishTransacted_ReportedProperty fails then Device_PublishTransacted_ReportedProperty shall fail and return DEVICE_DATA_PUBLISHER_FAILED. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 360 | result = DEVICE_DATA_PUBLISHER_FAILED; |
AzureIoTClient | 17:fa1bba4c6053 | 361 | } |
AzureIoTClient | 17:fa1bba4c6053 | 362 | else |
AzureIoTClient | 17:fa1bba4c6053 | 363 | { |
AzureIoTClient | 17:fa1bba4c6053 | 364 | /*Codes_SRS_DEVICE_02_023: [ Otherwise, Device_PublishTransacted_ReportedProperty shall succeed and return DEVICE_OK. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 365 | result = DEVICE_OK; |
AzureIoTClient | 17:fa1bba4c6053 | 366 | } |
AzureIoTClient | 17:fa1bba4c6053 | 367 | } |
AzureIoTClient | 17:fa1bba4c6053 | 368 | return result; |
AzureIoTClient | 17:fa1bba4c6053 | 369 | } |
AzureIoTClient | 17:fa1bba4c6053 | 370 | |
AzureIoTClient | 17:fa1bba4c6053 | 371 | DEVICE_RESULT Device_CommitTransaction_ReportedProperties(REPORTED_PROPERTIES_TRANSACTION_HANDLE transactionHandle, unsigned char** destination, size_t* destinationSize) |
AzureIoTClient | 17:fa1bba4c6053 | 372 | { |
AzureIoTClient | 17:fa1bba4c6053 | 373 | DEVICE_RESULT result; |
AzureIoTClient | 17:fa1bba4c6053 | 374 | |
AzureIoTClient | 17:fa1bba4c6053 | 375 | /*Codes_SRS_DEVICE_02_024: [ If argument transactionHandle is NULL then Device_CommitTransaction_ReportedProperties shall fail and return DEVICE_INVALID_ARG. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 376 | /*Codes_SRS_DEVICE_02_025: [ If argument destination is NULL then Device_CommitTransaction_ReportedProperties shall fail and return DEVICE_INVALID_ARG. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 377 | /*Codes_SRS_DEVICE_02_026: [ If argument destinationSize is NULL then Device_CommitTransaction_ReportedProperties shall fail and return DEVICE_INVALID_ARG. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 378 | if ( |
AzureIoTClient | 17:fa1bba4c6053 | 379 | (transactionHandle == NULL) || |
AzureIoTClient | 17:fa1bba4c6053 | 380 | (destination == NULL) || |
AzureIoTClient | 17:fa1bba4c6053 | 381 | (destinationSize == NULL) |
AzureIoTClient | 17:fa1bba4c6053 | 382 | ) |
AzureIoTClient | 17:fa1bba4c6053 | 383 | { |
AzureIoTClient | 17:fa1bba4c6053 | 384 | LogError("invalid argument REPORTED_PROPERTIES_TRANSACTION_HANDLE transactionHandle=%p, unsigned char** destination=%p, size_t* destinationSize=%p", transactionHandle, destination, destinationSize); |
AzureIoTClient | 17:fa1bba4c6053 | 385 | result = DEVICE_INVALID_ARG; |
AzureIoTClient | 17:fa1bba4c6053 | 386 | } |
AzureIoTClient | 17:fa1bba4c6053 | 387 | else |
AzureIoTClient | 17:fa1bba4c6053 | 388 | { |
AzureIoTClient | 17:fa1bba4c6053 | 389 | /*Codes_SRS_DEVICE_02_027: [ Device_CommitTransaction_ReportedProperties shall call DataPublisher_CommitTransaction_ReportedProperties. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 390 | DATA_PUBLISHER_RESULT r = DataPublisher_CommitTransaction_ReportedProperties(transactionHandle, destination, destinationSize); |
AzureIoTClient | 17:fa1bba4c6053 | 391 | |
AzureIoTClient | 17:fa1bba4c6053 | 392 | /*Codes_SRS_DEVICE_02_028: [ If DataPublisher_CommitTransaction_ReportedProperties fails then Device_CommitTransaction_ReportedProperties shall fail and return DEVICE_DATA_PUBLISHER_FAILED. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 393 | if (r != DATA_PUBLISHER_OK) |
AzureIoTClient | 17:fa1bba4c6053 | 394 | { |
AzureIoTClient | 17:fa1bba4c6053 | 395 | LogError("unable to DataPublisher_CommitTransaction_ReportedProperties"); |
AzureIoTClient | 17:fa1bba4c6053 | 396 | result = DEVICE_DATA_PUBLISHER_FAILED; |
AzureIoTClient | 17:fa1bba4c6053 | 397 | } |
AzureIoTClient | 17:fa1bba4c6053 | 398 | else |
AzureIoTClient | 17:fa1bba4c6053 | 399 | { |
AzureIoTClient | 17:fa1bba4c6053 | 400 | /*Codes_SRS_DEVICE_02_029: [ Otherwise Device_CommitTransaction_ReportedProperties shall succeed and return DEVICE_OK. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 401 | result = DEVICE_OK; |
AzureIoTClient | 17:fa1bba4c6053 | 402 | } |
AzureIoTClient | 17:fa1bba4c6053 | 403 | } |
AzureIoTClient | 17:fa1bba4c6053 | 404 | return result; |
AzureIoTClient | 17:fa1bba4c6053 | 405 | } |
AzureIoTClient | 17:fa1bba4c6053 | 406 | |
AzureIoTClient | 17:fa1bba4c6053 | 407 | void Device_DestroyTransaction_ReportedProperties(REPORTED_PROPERTIES_TRANSACTION_HANDLE transactionHandle) |
AzureIoTClient | 17:fa1bba4c6053 | 408 | { |
AzureIoTClient | 17:fa1bba4c6053 | 409 | /*Codes_SRS_DEVICE_02_030: [ If argument transactionHandle is NULL then Device_DestroyTransaction_ReportedProperties shall return. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 410 | if (transactionHandle == NULL) |
AzureIoTClient | 17:fa1bba4c6053 | 411 | { |
AzureIoTClient | 17:fa1bba4c6053 | 412 | LogError("invalid argument REPORTED_PROPERTIES_TRANSACTION_HANDLE transactionHandle=%p", transactionHandle); |
AzureIoTClient | 17:fa1bba4c6053 | 413 | } |
AzureIoTClient | 17:fa1bba4c6053 | 414 | else |
AzureIoTClient | 17:fa1bba4c6053 | 415 | { |
AzureIoTClient | 17:fa1bba4c6053 | 416 | /*Codes_SRS_DEVICE_02_031: [ Otherwise Device_DestroyTransaction_ReportedProperties shall free all used resources. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 417 | DataPublisher_DestroyTransaction_ReportedProperties(transactionHandle); |
AzureIoTClient | 17:fa1bba4c6053 | 418 | } |
AzureIoTClient | 17:fa1bba4c6053 | 419 | } |
AzureIoTClient | 17:fa1bba4c6053 | 420 | |
AzureIoTClient | 17:fa1bba4c6053 | 421 | DEVICE_RESULT Device_IngestDesiredProperties(void* startAddress, DEVICE_HANDLE deviceHandle, const char* desiredProperties) |
AzureIoTClient | 17:fa1bba4c6053 | 422 | { |
AzureIoTClient | 17:fa1bba4c6053 | 423 | DEVICE_RESULT result; |
AzureIoTClient | 17:fa1bba4c6053 | 424 | /*Codes_SRS_DEVICE_02_032: [ If deviceHandle is NULL then Device_IngestDesiredProperties shall fail and return DEVICE_INVALID_ARG. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 425 | /*Codes_SRS_DEVICE_02_033: [ If desiredProperties is NULL then Device_IngestDesiredProperties shall fail and return DEVICE_INVALID_ARG. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 426 | /*Codes_SRS_DEVICE_02_037: [ If startAddress is NULL then Device_IngestDesiredProperties shall fail and return DEVICE_INVALID_ARG. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 427 | if ( |
AzureIoTClient | 17:fa1bba4c6053 | 428 | (deviceHandle == NULL) || |
AzureIoTClient | 17:fa1bba4c6053 | 429 | (desiredProperties == NULL) || |
AzureIoTClient | 17:fa1bba4c6053 | 430 | (startAddress == NULL) |
AzureIoTClient | 17:fa1bba4c6053 | 431 | ) |
AzureIoTClient | 17:fa1bba4c6053 | 432 | { |
AzureIoTClient | 17:fa1bba4c6053 | 433 | LogError("invalid argument void* startAddress=%p, DEVICE_HANDLE deviceHandle=%p, const char* desiredProperties=%p\n", startAddress, deviceHandle, desiredProperties); |
AzureIoTClient | 17:fa1bba4c6053 | 434 | result = DEVICE_INVALID_ARG; |
AzureIoTClient | 17:fa1bba4c6053 | 435 | } |
AzureIoTClient | 17:fa1bba4c6053 | 436 | else |
AzureIoTClient | 17:fa1bba4c6053 | 437 | { |
AzureIoTClient | 17:fa1bba4c6053 | 438 | /*Codes_SRS_DEVICE_02_034: [ Device_IngestDesiredProperties shall call CommandDecoder_IngestDesiredProperties. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 439 | DEVICE_HANDLE_DATA* device = (DEVICE_HANDLE_DATA*)deviceHandle; |
AzureIoTClient | 17:fa1bba4c6053 | 440 | if (CommandDecoder_IngestDesiredProperties(startAddress, device->commandDecoderHandle, desiredProperties) != COMMANDDECODER_OK) |
AzureIoTClient | 17:fa1bba4c6053 | 441 | { |
AzureIoTClient | 17:fa1bba4c6053 | 442 | /*Codes_SRS_DEVICE_02_035: [ If any failure happens then Device_IngestDesiredProperties shall fail and return DEVICE_ERROR. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 443 | LogError("failure in CommandDecoder_IngestDesiredProperties"); |
AzureIoTClient | 17:fa1bba4c6053 | 444 | result = DEVICE_ERROR; |
AzureIoTClient | 17:fa1bba4c6053 | 445 | } |
AzureIoTClient | 17:fa1bba4c6053 | 446 | else |
AzureIoTClient | 17:fa1bba4c6053 | 447 | { |
AzureIoTClient | 17:fa1bba4c6053 | 448 | /*Codes_SRS_DEVICE_02_036: [ Otherwise, Device_IngestDesiredProperties shall succeed and return DEVICE_OK. ]*/ |
AzureIoTClient | 17:fa1bba4c6053 | 449 | result = DEVICE_OK; |
AzureIoTClient | 17:fa1bba4c6053 | 450 | } |
AzureIoTClient | 17:fa1bba4c6053 | 451 | } |
AzureIoTClient | 17:fa1bba4c6053 | 452 | return result; |
AzureIoTClient | 17:fa1bba4c6053 | 453 | } |