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@13:16e88f0cfa5f, 2016-07-01 (annotated)
- Committer:
- Azure.IoT Build
- Date:
- Fri Jul 01 10:43:11 2016 -0700
- Revision:
- 13:16e88f0cfa5f
- Parent:
- 11:b1327861f5e0
- Child:
- 17:fa1bba4c6053
1.0.10
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 | 0:1f9b2707ec7d | 20 | typedef struct DEVICE_TAG |
AzureIoTClient | 0:1f9b2707ec7d | 21 | { |
AzureIoTClient | 0:1f9b2707ec7d | 22 | SCHEMA_MODEL_TYPE_HANDLE model; |
AzureIoTClient | 0:1f9b2707ec7d | 23 | DATA_PUBLISHER_HANDLE dataPublisherHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 24 | pPfDeviceActionCallback deviceActionCallback; |
AzureIoTClient | 0:1f9b2707ec7d | 25 | void* callbackUserContext; |
AzureIoTClient | 0:1f9b2707ec7d | 26 | COMMAND_DECODER_HANDLE commandDecoderHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 27 | } DEVICE; |
AzureIoTClient | 0:1f9b2707ec7d | 28 | |
AzureIoTClient | 0:1f9b2707ec7d | 29 | DEFINE_ENUM_STRINGS(DEVICE_RESULT, DEVICE_RESULT_VALUES); |
AzureIoTClient | 0:1f9b2707ec7d | 30 | |
AzureIoTClient | 0:1f9b2707ec7d | 31 | static EXECUTE_COMMAND_RESULT DeviceInvokeAction(void* actionCallbackContext, const char* relativeActionPath, const char* actionName, size_t argCount, const AGENT_DATA_TYPE* args) |
AzureIoTClient | 0:1f9b2707ec7d | 32 | { |
AzureIoTClient | 0:1f9b2707ec7d | 33 | EXECUTE_COMMAND_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 34 | |
AzureIoTClient | 0:1f9b2707ec7d | 35 | /*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 | 36 | if (actionCallbackContext == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 37 | { |
AzureIoTClient | 0:1f9b2707ec7d | 38 | result = EXECUTE_COMMAND_ERROR; |
AzureIoTClient | 11:b1327861f5e0 | 39 | LogError("(Error code = %s)", ENUM_TO_STRING(DEVICE_RESULT, DEVICE_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 40 | } |
AzureIoTClient | 0:1f9b2707ec7d | 41 | else |
AzureIoTClient | 0:1f9b2707ec7d | 42 | { |
AzureIoTClient | 0:1f9b2707ec7d | 43 | DEVICE* device = (DEVICE*)actionCallbackContext; |
AzureIoTClient | 0:1f9b2707ec7d | 44 | |
AzureIoTClient | 0:1f9b2707ec7d | 45 | /* 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 | 46 | /* 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 | 47 | result = device->deviceActionCallback((DEVICE_HANDLE)device, device->callbackUserContext, relativeActionPath, actionName, argCount, args); |
AzureIoTClient | 0:1f9b2707ec7d | 48 | } |
AzureIoTClient | 0:1f9b2707ec7d | 49 | |
AzureIoTClient | 0:1f9b2707ec7d | 50 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 51 | } |
AzureIoTClient | 0:1f9b2707ec7d | 52 | |
AzureIoTClient | 0:1f9b2707ec7d | 53 | DEVICE_RESULT Device_Create(SCHEMA_MODEL_TYPE_HANDLE modelHandle, pPfDeviceActionCallback deviceActionCallback, void* callbackUserContext, bool includePropertyPath, DEVICE_HANDLE* deviceHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 54 | { |
AzureIoTClient | 0:1f9b2707ec7d | 55 | DEVICE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 56 | |
AzureIoTClient | 0:1f9b2707ec7d | 57 | /* Codes_SRS_DEVICE_05_014: [If any of the modelHandle, deviceHandle or deviceActionCallback arguments are NULL, Device_Create shall return DEVICE_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 58 | if (modelHandle == NULL || deviceHandle == NULL || deviceActionCallback == NULL ) |
AzureIoTClient | 0:1f9b2707ec7d | 59 | { |
AzureIoTClient | 0:1f9b2707ec7d | 60 | result = DEVICE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 61 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 62 | } |
AzureIoTClient | 0:1f9b2707ec7d | 63 | else |
AzureIoTClient | 0:1f9b2707ec7d | 64 | { |
AzureIoTClient | 0:1f9b2707ec7d | 65 | DEVICE* device = (DEVICE*)malloc(sizeof(DEVICE)); |
AzureIoTClient | 0:1f9b2707ec7d | 66 | if (device == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 67 | { |
AzureIoTClient | 0:1f9b2707ec7d | 68 | /* Codes_SRS_DEVICE_05_015: [If an error occurs while trying to create the device, Device_Create shall return DEVICE_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 69 | result = DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 70 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 71 | } |
AzureIoTClient | 0:1f9b2707ec7d | 72 | else |
AzureIoTClient | 0:1f9b2707ec7d | 73 | { |
AzureIoTClient | 0:1f9b2707ec7d | 74 | /* Codes_SRS_DEVICE_01_018: [Device_Create shall create a DataPublisher instance by calling DataPublisher_Create.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 75 | /* Codes_SRS_DEVICE_01_020: [Device_Create shall pass to DataPublisher_Create the FrontDoor instance obtained earlier.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 76 | /* Codes_SRS_DEVICE_01_004: [DeviceCreate shall pass to DataPublisher_create the includePropertyPath argument.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 77 | if ((device->dataPublisherHandle = DataPublisher_Create(modelHandle, includePropertyPath)) == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 78 | { |
AzureIoTClient | 0:1f9b2707ec7d | 79 | free(device); |
AzureIoTClient | 0:1f9b2707ec7d | 80 | |
AzureIoTClient | 0:1f9b2707ec7d | 81 | /* Codes_SRS_DEVICE_01_019: [If creating the DataPublisher instance fails, Device_Create shall return DEVICE_DATA_PUBLISHER_FAILED.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 82 | result = DEVICE_DATA_PUBLISHER_FAILED; |
AzureIoTClient | 0:1f9b2707ec7d | 83 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 84 | } |
AzureIoTClient | 0:1f9b2707ec7d | 85 | else |
AzureIoTClient | 0:1f9b2707ec7d | 86 | { |
AzureIoTClient | 0:1f9b2707ec7d | 87 | device->model = modelHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 88 | device->deviceActionCallback = deviceActionCallback; |
AzureIoTClient | 0:1f9b2707ec7d | 89 | device->callbackUserContext = callbackUserContext; |
AzureIoTClient | 0:1f9b2707ec7d | 90 | |
AzureIoTClient | 0:1f9b2707ec7d | 91 | /* 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 | 92 | /* 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.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 93 | if ((device->commandDecoderHandle = CommandDecoder_Create(modelHandle, DeviceInvokeAction, device)) == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 94 | { |
AzureIoTClient | 0:1f9b2707ec7d | 95 | free(device); |
AzureIoTClient | 0:1f9b2707ec7d | 96 | |
AzureIoTClient | 0:1f9b2707ec7d | 97 | /* Codes_SRS_DEVICE_01_003: [If CommandDecoder_Create fails, Device_Create shall return DEVICE_COMMAND_DECODER_FAILED.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 98 | result = DEVICE_COMMAND_DECODER_FAILED; |
AzureIoTClient | 0:1f9b2707ec7d | 99 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 100 | } |
AzureIoTClient | 0:1f9b2707ec7d | 101 | else |
AzureIoTClient | 0:1f9b2707ec7d | 102 | { |
AzureIoTClient | 0:1f9b2707ec7d | 103 | /* Codes_SRS_DEVICE_03_003: [The DEVICE_HANDLE shall be provided via the deviceHandle out argument.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 104 | *deviceHandle = (DEVICE_HANDLE)device; |
AzureIoTClient | 0:1f9b2707ec7d | 105 | /* Codes_SRS_DEVICE_03_004: [Device_Create shall return DEVICE_OK upon success.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 106 | result = DEVICE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 107 | } |
AzureIoTClient | 0:1f9b2707ec7d | 108 | } |
AzureIoTClient | 0:1f9b2707ec7d | 109 | } |
AzureIoTClient | 0:1f9b2707ec7d | 110 | } |
AzureIoTClient | 0:1f9b2707ec7d | 111 | |
AzureIoTClient | 0:1f9b2707ec7d | 112 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 113 | } |
AzureIoTClient | 0:1f9b2707ec7d | 114 | |
AzureIoTClient | 0:1f9b2707ec7d | 115 | /* Codes_SRS_DEVICE_03_006: [Device_Destroy shall free all resources associated with a device.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 116 | void Device_Destroy(DEVICE_HANDLE deviceHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 117 | { |
AzureIoTClient | 0:1f9b2707ec7d | 118 | /* Codes_SRS_DEVICE_03_007: [Device_Destroy will not do anything if deviceHandle is NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 119 | if (deviceHandle != NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 120 | { |
AzureIoTClient | 0:1f9b2707ec7d | 121 | DEVICE* device = (DEVICE*)deviceHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 122 | |
AzureIoTClient | 0:1f9b2707ec7d | 123 | DataPublisher_Destroy(device->dataPublisherHandle); |
AzureIoTClient | 0:1f9b2707ec7d | 124 | CommandDecoder_Destroy(device->commandDecoderHandle); |
AzureIoTClient | 0:1f9b2707ec7d | 125 | |
AzureIoTClient | 0:1f9b2707ec7d | 126 | free(device); |
AzureIoTClient | 0:1f9b2707ec7d | 127 | } |
AzureIoTClient | 0:1f9b2707ec7d | 128 | } |
AzureIoTClient | 0:1f9b2707ec7d | 129 | |
AzureIoTClient | 0:1f9b2707ec7d | 130 | TRANSACTION_HANDLE Device_StartTransaction(DEVICE_HANDLE deviceHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 131 | { |
AzureIoTClient | 0:1f9b2707ec7d | 132 | TRANSACTION_HANDLE result; |
AzureIoTClient | 0:1f9b2707ec7d | 133 | |
AzureIoTClient | 0:1f9b2707ec7d | 134 | /* Codes_SRS_DEVICE_01_035: [If any argument is NULL, Device_StartTransaction shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 135 | if (deviceHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 136 | { |
AzureIoTClient | 0:1f9b2707ec7d | 137 | result = NULL; |
AzureIoTClient | 11:b1327861f5e0 | 138 | LogError("(Error code = %s)", ENUM_TO_STRING(DEVICE_RESULT, DEVICE_INVALID_ARG)); |
AzureIoTClient | 0:1f9b2707ec7d | 139 | } |
AzureIoTClient | 0:1f9b2707ec7d | 140 | else |
AzureIoTClient | 0:1f9b2707ec7d | 141 | { |
AzureIoTClient | 0:1f9b2707ec7d | 142 | DEVICE* deviceInstance = (DEVICE*)deviceHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 143 | |
AzureIoTClient | 0:1f9b2707ec7d | 144 | /* Codes_SRS_DEVICE_01_034: [Device_StartTransaction shall invoke DataPublisher_StartTransaction for the DataPublisher handle associated with the deviceHandle argument.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 145 | /* Codes_SRS_DEVICE_01_043: [On success, Device_StartTransaction shall return a non NULL handle.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 146 | /* Codes_SRS_DEVICE_01_048: [When DataPublisher_StartTransaction fails, Device_StartTransaction shall return NULL.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 147 | result = DataPublisher_StartTransaction(deviceInstance->dataPublisherHandle); |
AzureIoTClient | 0:1f9b2707ec7d | 148 | } |
AzureIoTClient | 0:1f9b2707ec7d | 149 | |
AzureIoTClient | 0:1f9b2707ec7d | 150 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 151 | } |
AzureIoTClient | 0:1f9b2707ec7d | 152 | |
AzureIoTClient | 0:1f9b2707ec7d | 153 | DEVICE_RESULT Device_PublishTransacted(TRANSACTION_HANDLE transactionHandle, const char* propertyPath, const AGENT_DATA_TYPE* data) |
AzureIoTClient | 0:1f9b2707ec7d | 154 | { |
AzureIoTClient | 0:1f9b2707ec7d | 155 | DEVICE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 156 | |
AzureIoTClient | 0:1f9b2707ec7d | 157 | /* Codes_SRS_DEVICE_01_037: [If any argument is NULL, Device_PublishTransacted shall return DEVICE_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 158 | if ((transactionHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 159 | (propertyPath == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 160 | (data == NULL)) |
AzureIoTClient | 0:1f9b2707ec7d | 161 | { |
AzureIoTClient | 0:1f9b2707ec7d | 162 | result = DEVICE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 163 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 164 | } |
AzureIoTClient | 0:1f9b2707ec7d | 165 | /* Codes_SRS_DEVICE_01_036: [Device_PublishTransacted shall invoke DataPublisher_PublishTransacted.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 166 | else if (DataPublisher_PublishTransacted(transactionHandle, propertyPath, data) != DATA_PUBLISHER_OK) |
AzureIoTClient | 0:1f9b2707ec7d | 167 | { |
AzureIoTClient | 0:1f9b2707ec7d | 168 | /* Codes_SRS_DEVICE_01_049: [When DataPublisher_PublishTransacted fails, Device_PublishTransacted shall return DEVICE_DATA_PUBLISHER_FAILED.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 169 | result = DEVICE_DATA_PUBLISHER_FAILED; |
AzureIoTClient | 0:1f9b2707ec7d | 170 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 171 | } |
AzureIoTClient | 0:1f9b2707ec7d | 172 | else |
AzureIoTClient | 0:1f9b2707ec7d | 173 | { |
AzureIoTClient | 0:1f9b2707ec7d | 174 | /* Codes_SRS_DEVICE_01_044: [On success, Device_PublishTransacted shall return DEVICE_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 175 | result = DEVICE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 176 | } |
AzureIoTClient | 0:1f9b2707ec7d | 177 | |
AzureIoTClient | 0:1f9b2707ec7d | 178 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 179 | } |
AzureIoTClient | 0:1f9b2707ec7d | 180 | |
AzureIoTClient | 0:1f9b2707ec7d | 181 | DEVICE_RESULT Device_EndTransaction(TRANSACTION_HANDLE transactionHandle, unsigned char** destination, size_t* destinationSize) |
AzureIoTClient | 0:1f9b2707ec7d | 182 | { |
AzureIoTClient | 0:1f9b2707ec7d | 183 | DEVICE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 184 | |
AzureIoTClient | 0:1f9b2707ec7d | 185 | /* Codes_SRS_DEVICE_01_039: [If any parameter is NULL, Device_EndTransaction shall return DEVICE_INVALID_ARG.]*/ |
AzureIoTClient | 0:1f9b2707ec7d | 186 | if ( |
AzureIoTClient | 0:1f9b2707ec7d | 187 | (transactionHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 188 | (destination == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 189 | (destinationSize == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 190 | ) |
AzureIoTClient | 0:1f9b2707ec7d | 191 | { |
AzureIoTClient | 0:1f9b2707ec7d | 192 | result = DEVICE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 193 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 194 | } |
AzureIoTClient | 0:1f9b2707ec7d | 195 | /* Codes_SRS_DEVICE_01_038: [Device_EndTransaction shall invoke DataPublisher_EndTransaction.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 196 | else if (DataPublisher_EndTransaction(transactionHandle, destination, destinationSize) != DATA_PUBLISHER_OK) |
AzureIoTClient | 0:1f9b2707ec7d | 197 | { |
AzureIoTClient | 0:1f9b2707ec7d | 198 | /* Codes_SRS_DEVICE_01_050: [When DataPublisher_EndTransaction fails, Device_EndTransaction shall return DEVICE_DATA_PUBLISHER_FAILED.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 199 | result = DEVICE_DATA_PUBLISHER_FAILED; |
AzureIoTClient | 0:1f9b2707ec7d | 200 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 201 | } |
AzureIoTClient | 0:1f9b2707ec7d | 202 | else |
AzureIoTClient | 0:1f9b2707ec7d | 203 | { |
AzureIoTClient | 0:1f9b2707ec7d | 204 | /* Codes_SRS_DEVICE_01_045: [On success, Device_EndTransaction shall return DEVICE_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 205 | result = DEVICE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 206 | } |
AzureIoTClient | 0:1f9b2707ec7d | 207 | |
AzureIoTClient | 0:1f9b2707ec7d | 208 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 209 | } |
AzureIoTClient | 0:1f9b2707ec7d | 210 | |
AzureIoTClient | 0:1f9b2707ec7d | 211 | DEVICE_RESULT Device_CancelTransaction(TRANSACTION_HANDLE transactionHandle) |
AzureIoTClient | 0:1f9b2707ec7d | 212 | { |
AzureIoTClient | 0:1f9b2707ec7d | 213 | DEVICE_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 214 | |
AzureIoTClient | 0:1f9b2707ec7d | 215 | /* Codes_SRS_DEVICE_01_041: [If any argument is NULL, Device_CancelTransaction shall return DEVICE_INVALID_ARG.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 216 | if (transactionHandle == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 217 | { |
AzureIoTClient | 0:1f9b2707ec7d | 218 | result = DEVICE_INVALID_ARG; |
AzureIoTClient | 0:1f9b2707ec7d | 219 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 220 | } |
AzureIoTClient | 0:1f9b2707ec7d | 221 | /* Codes_SRS_DEVICE_01_040: [Device_CancelTransaction shall invoke DataPublisher_CancelTransaction.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 222 | else if (DataPublisher_CancelTransaction(transactionHandle) != DATA_PUBLISHER_OK) |
AzureIoTClient | 0:1f9b2707ec7d | 223 | { |
AzureIoTClient | 0:1f9b2707ec7d | 224 | /* Codes_SRS_DEVICE_01_051: [When DataPublisher_CancelTransaction fails, Device_CancelTransaction shall return DEVICE_DATA_PUBLISHER_FAILED.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 225 | result = DEVICE_DATA_PUBLISHER_FAILED; |
AzureIoTClient | 0:1f9b2707ec7d | 226 | LOG_DEVICE_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 227 | } |
AzureIoTClient | 0:1f9b2707ec7d | 228 | else |
AzureIoTClient | 0:1f9b2707ec7d | 229 | { |
AzureIoTClient | 0:1f9b2707ec7d | 230 | /* Codes_SRS_DEVICE_01_046: [On success, Device_PublishTransacted shall return DEVICE_OK.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 231 | result = DEVICE_OK; |
AzureIoTClient | 0:1f9b2707ec7d | 232 | } |
AzureIoTClient | 0:1f9b2707ec7d | 233 | |
AzureIoTClient | 0:1f9b2707ec7d | 234 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 235 | } |
AzureIoTClient | 0:1f9b2707ec7d | 236 | |
AzureIoTClient | 0:1f9b2707ec7d | 237 | EXECUTE_COMMAND_RESULT Device_ExecuteCommand(DEVICE_HANDLE deviceHandle, const char* command) |
AzureIoTClient | 0:1f9b2707ec7d | 238 | { |
AzureIoTClient | 0:1f9b2707ec7d | 239 | EXECUTE_COMMAND_RESULT result; |
AzureIoTClient | 0:1f9b2707ec7d | 240 | /*Codes_SRS_DEVICE_02_012: [If any parameters are NULL, then Device_ExecuteCommand shall return EXECUTE_COMMAND_ERROR.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 241 | if ( |
AzureIoTClient | 0:1f9b2707ec7d | 242 | (deviceHandle == NULL) || |
AzureIoTClient | 0:1f9b2707ec7d | 243 | (command == NULL) |
AzureIoTClient | 0:1f9b2707ec7d | 244 | ) |
AzureIoTClient | 0:1f9b2707ec7d | 245 | { |
AzureIoTClient | 0:1f9b2707ec7d | 246 | result = EXECUTE_COMMAND_ERROR; |
AzureIoTClient | 0:1f9b2707ec7d | 247 | LogError("invalid parameter (NULL passed to Device_ExecuteCommand DEVICE_HANDLE deviceHandle=%p, const char* command=%p", deviceHandle, command); |
AzureIoTClient | 0:1f9b2707ec7d | 248 | } |
AzureIoTClient | 0:1f9b2707ec7d | 249 | else |
AzureIoTClient | 0:1f9b2707ec7d | 250 | { |
AzureIoTClient | 0:1f9b2707ec7d | 251 | /*Codes_SRS_DEVICE_02_013: [Otherwise, Device_ExecuteCommand shall call CommandDecoder_ExecuteCommand and return what CommandDecoder_ExecuteCommand is returning.] */ |
AzureIoTClient | 0:1f9b2707ec7d | 252 | DEVICE* device = (DEVICE*)deviceHandle; |
AzureIoTClient | 0:1f9b2707ec7d | 253 | result = CommandDecoder_ExecuteCommand(device->commandDecoderHandle, command); |
AzureIoTClient | 0:1f9b2707ec7d | 254 | } |
AzureIoTClient | 0:1f9b2707ec7d | 255 | return result; |
AzureIoTClient | 0:1f9b2707ec7d | 256 | } |