Microsoft Azure IoTHub client libraries
Dependents: sht15_remote_monitoring RobotArmDemo iothub_client_sample_amqp f767zi_mqtt ... more
This library implements the Microsoft Azure IoTHub client library. The code is replicated from https://github.com/Azure/azure-iot-sdks
iothub_client_ll.c@78:74a8d3068204, 2017-11-03 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Fri Nov 03 13:18:25 2017 -0700
- Revision:
- 78:74a8d3068204
- Parent:
- 77:e4e36df9caee
- Child:
- 80:db5f5237bc95
1.1.27
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AzureIoTClient | 16:deba40344375 | 1 | // Copyright (c) Microsoft. All rights reserved. |
AzureIoTClient | 16:deba40344375 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
AzureIoTClient | 16:deba40344375 | 3 | |
AzureIoTClient | 16:deba40344375 | 4 | #include <stdlib.h> |
Azure.IoT Build | 38:a05929a75111 | 5 | #include <string.h> |
AzureIoTClient | 60:41648c4e7036 | 6 | #include "azure_c_shared_utility/optimize_size.h" |
Azure.IoT Build | 38:a05929a75111 | 7 | #include "azure_c_shared_utility/gballoc.h" |
Azure.IoT Build | 38:a05929a75111 | 8 | #include "azure_c_shared_utility/string_tokenizer.h" |
Azure.IoT Build | 38:a05929a75111 | 9 | #include "azure_c_shared_utility/doublylinkedlist.h" |
Azure.IoT Build | 45:54c11b1b1407 | 10 | #include "azure_c_shared_utility/xlogging.h" |
Azure.IoT Build | 38:a05929a75111 | 11 | #include "azure_c_shared_utility/tickcounter.h" |
AzureIoTClient | 53:1e5a1ca1f274 | 12 | #include "azure_c_shared_utility/constbuffer.h" |
AzureIoTClient | 66:a419827cb051 | 13 | #include "azure_c_shared_utility/platform.h" |
AzureIoTClient | 16:deba40344375 | 14 | |
AzureIoTClient | 62:5a4cdacf5090 | 15 | #include "iothub_client_authorization.h" |
AzureIoTClient | 16:deba40344375 | 16 | #include "iothub_client_ll.h" |
AzureIoTClient | 61:8b85a4e797cf | 17 | #include "iothub_transport_ll.h" |
AzureIoTClient | 16:deba40344375 | 18 | #include "iothub_client_private.h" |
AzureIoTClient | 66:a419827cb051 | 19 | #include "iothub_client_options.h" |
AzureIoTClient | 33:b372b0efcd20 | 20 | #include "iothub_client_version.h" |
AzureIoTClient | 77:e4e36df9caee | 21 | #include "iothub_client_diagnostic.h" |
AzureIoTClient | 53:1e5a1ca1f274 | 22 | #include <stdint.h> |
AzureIoTClient | 43:038d8511e817 | 23 | |
AzureIoTClient | 78:74a8d3068204 | 24 | #ifdef USE_PROV_MODULE |
AzureIoTClient | 78:74a8d3068204 | 25 | #include "iothub_client_hsm_ll.h" |
AzureIoTClient | 75:86205ca63a59 | 26 | #endif |
AzureIoTClient | 75:86205ca63a59 | 27 | |
AzureIoTClient | 44:33dd78697616 | 28 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 29 | #include "iothub_client_ll_uploadtoblob.h" |
AzureIoTClient | 43:038d8511e817 | 30 | #endif |
Azure.IoT Build | 36:67300d5a4c1f | 31 | |
Azure.IoT Build | 45:54c11b1b1407 | 32 | #define LOG_ERROR_RESULT LogError("result = %s", ENUM_TO_STRING(IOTHUB_CLIENT_RESULT, result)); |
AzureIoTClient | 16:deba40344375 | 33 | #define INDEFINITE_TIME ((time_t)(-1)) |
AzureIoTClient | 16:deba40344375 | 34 | |
AzureIoTClient | 16:deba40344375 | 35 | DEFINE_ENUM_STRINGS(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_RESULT_VALUES); |
Azure.IoT Build | 45:54c11b1b1407 | 36 | DEFINE_ENUM_STRINGS(IOTHUB_CLIENT_CONFIRMATION_RESULT, IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES); |
AzureIoTClient | 16:deba40344375 | 37 | |
AzureIoTClient | 62:5a4cdacf5090 | 38 | #define CALLBACK_TYPE_VALUES \ |
AzureIoTClient | 62:5a4cdacf5090 | 39 | CALLBACK_TYPE_NONE, \ |
AzureIoTClient | 62:5a4cdacf5090 | 40 | CALLBACK_TYPE_SYNC, \ |
AzureIoTClient | 62:5a4cdacf5090 | 41 | CALLBACK_TYPE_ASYNC |
AzureIoTClient | 62:5a4cdacf5090 | 42 | |
AzureIoTClient | 62:5a4cdacf5090 | 43 | DEFINE_ENUM(CALLBACK_TYPE, CALLBACK_TYPE_VALUES) |
AzureIoTClient | 62:5a4cdacf5090 | 44 | DEFINE_ENUM_STRINGS(CALLBACK_TYPE, CALLBACK_TYPE_VALUES) |
AzureIoTClient | 61:8b85a4e797cf | 45 | |
AzureIoTClient | 62:5a4cdacf5090 | 46 | typedef struct IOTHUB_METHOD_CALLBACK_DATA_TAG |
AzureIoTClient | 62:5a4cdacf5090 | 47 | { |
AzureIoTClient | 62:5a4cdacf5090 | 48 | CALLBACK_TYPE type; |
AzureIoTClient | 62:5a4cdacf5090 | 49 | IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC callbackSync; |
AzureIoTClient | 62:5a4cdacf5090 | 50 | IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK callbackAsync; |
AzureIoTClient | 62:5a4cdacf5090 | 51 | void* userContextCallback; |
AzureIoTClient | 62:5a4cdacf5090 | 52 | }IOTHUB_METHOD_CALLBACK_DATA; |
AzureIoTClient | 61:8b85a4e797cf | 53 | |
AzureIoTClient | 61:8b85a4e797cf | 54 | typedef struct IOTHUB_MESSAGE_CALLBACK_DATA_TAG |
AzureIoTClient | 61:8b85a4e797cf | 55 | { |
AzureIoTClient | 62:5a4cdacf5090 | 56 | CALLBACK_TYPE type; |
AzureIoTClient | 61:8b85a4e797cf | 57 | IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC callbackSync; |
AzureIoTClient | 61:8b85a4e797cf | 58 | IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC_EX callbackAsync; |
AzureIoTClient | 62:5a4cdacf5090 | 59 | void* userContextCallback; |
AzureIoTClient | 61:8b85a4e797cf | 60 | }IOTHUB_MESSAGE_CALLBACK_DATA; |
AzureIoTClient | 61:8b85a4e797cf | 61 | |
AzureIoTClient | 16:deba40344375 | 62 | typedef struct IOTHUB_CLIENT_LL_HANDLE_DATA_TAG |
AzureIoTClient | 16:deba40344375 | 63 | { |
AzureIoTClient | 42:448eecc3676e | 64 | DLIST_ENTRY waitingToSend; |
AzureIoTClient | 53:1e5a1ca1f274 | 65 | DLIST_ENTRY iot_msg_queue; |
AzureIoTClient | 53:1e5a1ca1f274 | 66 | DLIST_ENTRY iot_ack_queue; |
AzureIoTClient | 42:448eecc3676e | 67 | TRANSPORT_LL_HANDLE transportHandle; |
AzureIoTClient | 42:448eecc3676e | 68 | bool isSharedTransport; |
AzureIoTClient | 42:448eecc3676e | 69 | IOTHUB_DEVICE_HANDLE deviceHandle; |
AzureIoTClient | 42:448eecc3676e | 70 | TRANSPORT_PROVIDER_FIELDS; |
AzureIoTClient | 61:8b85a4e797cf | 71 | IOTHUB_MESSAGE_CALLBACK_DATA messageCallback; |
AzureIoTClient | 62:5a4cdacf5090 | 72 | IOTHUB_METHOD_CALLBACK_DATA methodCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 73 | IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK conStatusCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 74 | void* conStatusUserContextCallback; |
AzureIoTClient | 42:448eecc3676e | 75 | time_t lastMessageReceiveTime; |
AzureIoTClient | 42:448eecc3676e | 76 | TICK_COUNTER_HANDLE tickCounter; /*shared tickcounter used to track message timeouts in waitingToSend list*/ |
Azure.IoT.Build | 54:6dcad9019a64 | 77 | tickcounter_ms_t currentMessageTimeout; |
AzureIoTClient | 53:1e5a1ca1f274 | 78 | uint64_t current_device_twin_timeout; |
AzureIoTClient | 53:1e5a1ca1f274 | 79 | IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK deviceTwinCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 80 | void* deviceTwinContextCallback; |
AzureIoTClient | 52:1cc3c6d07cad | 81 | IOTHUB_CLIENT_RETRY_POLICY retryPolicy; |
AzureIoTClient | 53:1e5a1ca1f274 | 82 | size_t retryTimeoutLimitInSeconds; |
AzureIoTClient | 44:33dd78697616 | 83 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 84 | IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE uploadToBlobHandle; |
AzureIoTClient | 43:038d8511e817 | 85 | #endif |
AzureIoTClient | 53:1e5a1ca1f274 | 86 | uint32_t data_msg_id; |
AzureIoTClient | 53:1e5a1ca1f274 | 87 | bool complete_twin_update_encountered; |
AzureIoTClient | 62:5a4cdacf5090 | 88 | IOTHUB_AUTHORIZATION_HANDLE authorization_module; |
AzureIoTClient | 66:a419827cb051 | 89 | STRING_HANDLE product_info; |
AzureIoTClient | 77:e4e36df9caee | 90 | IOTHUB_DIAGNOSTIC_SETTING_DATA diagnostic_setting; |
AzureIoTClient | 16:deba40344375 | 91 | }IOTHUB_CLIENT_LL_HANDLE_DATA; |
AzureIoTClient | 16:deba40344375 | 92 | |
AzureIoTClient | 16:deba40344375 | 93 | static const char HOSTNAME_TOKEN[] = "HostName"; |
AzureIoTClient | 16:deba40344375 | 94 | static const char DEVICEID_TOKEN[] = "DeviceId"; |
Azure.IoT Build | 45:54c11b1b1407 | 95 | static const char X509_TOKEN[] = "x509"; |
Azure.IoT Build | 45:54c11b1b1407 | 96 | static const char X509_TOKEN_ONLY_ACCEPTABLE_VALUE[] = "true"; |
AzureIoTClient | 16:deba40344375 | 97 | static const char DEVICEKEY_TOKEN[] = "SharedAccessKey"; |
AzureIoTClient | 40:1a94db9139ea | 98 | static const char DEVICESAS_TOKEN[] = "SharedAccessSignature"; |
AzureIoTClient | 16:deba40344375 | 99 | static const char PROTOCOL_GATEWAY_HOST[] = "GatewayHostName"; |
AzureIoTClient | 16:deba40344375 | 100 | |
AzureIoTClient | 62:5a4cdacf5090 | 101 | static void setTransportProtocol(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, TRANSPORT_PROVIDER* protocol) |
AzureIoTClient | 62:5a4cdacf5090 | 102 | { |
AzureIoTClient | 62:5a4cdacf5090 | 103 | handleData->IoTHubTransport_SendMessageDisposition = protocol->IoTHubTransport_SendMessageDisposition; |
AzureIoTClient | 62:5a4cdacf5090 | 104 | handleData->IoTHubTransport_GetHostname = protocol->IoTHubTransport_GetHostname; |
AzureIoTClient | 62:5a4cdacf5090 | 105 | handleData->IoTHubTransport_SetOption = protocol->IoTHubTransport_SetOption; |
AzureIoTClient | 62:5a4cdacf5090 | 106 | handleData->IoTHubTransport_Create = protocol->IoTHubTransport_Create; |
AzureIoTClient | 62:5a4cdacf5090 | 107 | handleData->IoTHubTransport_Destroy = protocol->IoTHubTransport_Destroy; |
AzureIoTClient | 62:5a4cdacf5090 | 108 | handleData->IoTHubTransport_Register = protocol->IoTHubTransport_Register; |
AzureIoTClient | 62:5a4cdacf5090 | 109 | handleData->IoTHubTransport_Unregister = protocol->IoTHubTransport_Unregister; |
AzureIoTClient | 62:5a4cdacf5090 | 110 | handleData->IoTHubTransport_Subscribe = protocol->IoTHubTransport_Subscribe; |
AzureIoTClient | 62:5a4cdacf5090 | 111 | handleData->IoTHubTransport_Unsubscribe = protocol->IoTHubTransport_Unsubscribe; |
AzureIoTClient | 62:5a4cdacf5090 | 112 | handleData->IoTHubTransport_DoWork = protocol->IoTHubTransport_DoWork; |
AzureIoTClient | 62:5a4cdacf5090 | 113 | handleData->IoTHubTransport_SetRetryPolicy = protocol->IoTHubTransport_SetRetryPolicy; |
AzureIoTClient | 62:5a4cdacf5090 | 114 | handleData->IoTHubTransport_GetSendStatus = protocol->IoTHubTransport_GetSendStatus; |
AzureIoTClient | 62:5a4cdacf5090 | 115 | handleData->IoTHubTransport_ProcessItem = protocol->IoTHubTransport_ProcessItem; |
AzureIoTClient | 62:5a4cdacf5090 | 116 | handleData->IoTHubTransport_Subscribe_DeviceTwin = protocol->IoTHubTransport_Subscribe_DeviceTwin; |
AzureIoTClient | 62:5a4cdacf5090 | 117 | handleData->IoTHubTransport_Unsubscribe_DeviceTwin = protocol->IoTHubTransport_Unsubscribe_DeviceTwin; |
AzureIoTClient | 62:5a4cdacf5090 | 118 | handleData->IoTHubTransport_Subscribe_DeviceMethod = protocol->IoTHubTransport_Subscribe_DeviceMethod; |
AzureIoTClient | 62:5a4cdacf5090 | 119 | handleData->IoTHubTransport_Unsubscribe_DeviceMethod = protocol->IoTHubTransport_Unsubscribe_DeviceMethod; |
AzureIoTClient | 62:5a4cdacf5090 | 120 | handleData->IoTHubTransport_DeviceMethod_Response = protocol->IoTHubTransport_DeviceMethod_Response; |
AzureIoTClient | 62:5a4cdacf5090 | 121 | } |
AzureIoTClient | 62:5a4cdacf5090 | 122 | |
AzureIoTClient | 53:1e5a1ca1f274 | 123 | static void device_twin_data_destroy(IOTHUB_DEVICE_TWIN* client_item) |
AzureIoTClient | 53:1e5a1ca1f274 | 124 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 125 | CONSTBUFFER_Destroy(client_item->report_data_handle); |
AzureIoTClient | 53:1e5a1ca1f274 | 126 | free(client_item); |
AzureIoTClient | 53:1e5a1ca1f274 | 127 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 128 | |
AzureIoTClient | 62:5a4cdacf5090 | 129 | static int create_blob_upload_module(IOTHUB_CLIENT_LL_HANDLE_DATA* handle_data, const IOTHUB_CLIENT_CONFIG* config) |
AzureIoTClient | 62:5a4cdacf5090 | 130 | { |
AzureIoTClient | 62:5a4cdacf5090 | 131 | int result; |
AzureIoTClient | 63:1bf1c2d60aab | 132 | (void)handle_data; |
AzureIoTClient | 63:1bf1c2d60aab | 133 | (void)config; |
AzureIoTClient | 62:5a4cdacf5090 | 134 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 62:5a4cdacf5090 | 135 | handle_data->uploadToBlobHandle = IoTHubClient_LL_UploadToBlob_Create(config); |
AzureIoTClient | 62:5a4cdacf5090 | 136 | if (handle_data->uploadToBlobHandle == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 137 | { |
AzureIoTClient | 62:5a4cdacf5090 | 138 | LogError("unable to IoTHubClient_LL_UploadToBlob_Create"); |
AzureIoTClient | 62:5a4cdacf5090 | 139 | result = __FAILURE__; |
AzureIoTClient | 62:5a4cdacf5090 | 140 | } |
AzureIoTClient | 62:5a4cdacf5090 | 141 | else |
AzureIoTClient | 62:5a4cdacf5090 | 142 | { |
AzureIoTClient | 62:5a4cdacf5090 | 143 | result = 0; |
AzureIoTClient | 62:5a4cdacf5090 | 144 | } |
AzureIoTClient | 62:5a4cdacf5090 | 145 | #else |
AzureIoTClient | 62:5a4cdacf5090 | 146 | result = 0; |
AzureIoTClient | 62:5a4cdacf5090 | 147 | #endif |
AzureIoTClient | 62:5a4cdacf5090 | 148 | return result; |
AzureIoTClient | 62:5a4cdacf5090 | 149 | } |
AzureIoTClient | 62:5a4cdacf5090 | 150 | |
AzureIoTClient | 62:5a4cdacf5090 | 151 | static void destroy_blob_upload_module(IOTHUB_CLIENT_LL_HANDLE_DATA* handle_data) |
AzureIoTClient | 62:5a4cdacf5090 | 152 | { |
AzureIoTClient | 63:1bf1c2d60aab | 153 | (void)handle_data; |
AzureIoTClient | 62:5a4cdacf5090 | 154 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 62:5a4cdacf5090 | 155 | /*Codes_SRS_IOTHUBCLIENT_LL_02_046: [ If creating the TICK_COUNTER_HANDLE fails then IoTHubClient_LL_Create shall fail and return NULL. ]*/ |
AzureIoTClient | 62:5a4cdacf5090 | 156 | IoTHubClient_LL_UploadToBlob_Destroy(handle_data->uploadToBlobHandle); |
AzureIoTClient | 62:5a4cdacf5090 | 157 | #endif |
AzureIoTClient | 62:5a4cdacf5090 | 158 | } |
AzureIoTClient | 62:5a4cdacf5090 | 159 | |
AzureIoTClient | 66:a419827cb051 | 160 | /*Codes_SRS_IOTHUBCLIENT_LL_10_032: ["product_info" - takes a char string as an argument to specify the product information(e.g. `"ProductName/ProductVersion"`). ]*/ |
AzureIoTClient | 66:a419827cb051 | 161 | /*Codes_SRS_IOTHUBCLIENT_LL_10_034: ["product_info" - shall store the given string concatenated with the sdk information and the platform information in the form(ProductInfo DeviceSDKName / DeviceSDKVersion(OSName OSVersion; Architecture). ]*/ |
AzureIoTClient | 66:a419827cb051 | 162 | static STRING_HANDLE make_product_info(const char* product) |
AzureIoTClient | 62:5a4cdacf5090 | 163 | { |
AzureIoTClient | 66:a419827cb051 | 164 | STRING_HANDLE result; |
AzureIoTClient | 66:a419827cb051 | 165 | STRING_HANDLE pfi = platform_get_platform_info(); |
AzureIoTClient | 66:a419827cb051 | 166 | if (pfi == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 167 | { |
AzureIoTClient | 66:a419827cb051 | 168 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 169 | } |
AzureIoTClient | 62:5a4cdacf5090 | 170 | else |
AzureIoTClient | 62:5a4cdacf5090 | 171 | { |
AzureIoTClient | 66:a419827cb051 | 172 | if (product == NULL) |
AzureIoTClient | 66:a419827cb051 | 173 | { |
AzureIoTClient | 66:a419827cb051 | 174 | result = STRING_construct_sprintf("%s %s", CLIENT_DEVICE_TYPE_PREFIX CLIENT_DEVICE_BACKSLASH IOTHUB_SDK_VERSION, STRING_c_str(pfi)); |
AzureIoTClient | 66:a419827cb051 | 175 | } |
AzureIoTClient | 66:a419827cb051 | 176 | else |
AzureIoTClient | 66:a419827cb051 | 177 | { |
AzureIoTClient | 66:a419827cb051 | 178 | result = STRING_construct_sprintf("%s %s %s", product, CLIENT_DEVICE_TYPE_PREFIX CLIENT_DEVICE_BACKSLASH IOTHUB_SDK_VERSION, STRING_c_str(pfi)); |
AzureIoTClient | 66:a419827cb051 | 179 | } |
AzureIoTClient | 66:a419827cb051 | 180 | STRING_delete(pfi); |
AzureIoTClient | 66:a419827cb051 | 181 | } |
AzureIoTClient | 66:a419827cb051 | 182 | return result; |
AzureIoTClient | 66:a419827cb051 | 183 | } |
AzureIoTClient | 62:5a4cdacf5090 | 184 | |
AzureIoTClient | 75:86205ca63a59 | 185 | static IOTHUB_CLIENT_LL_HANDLE_DATA* initialize_iothub_client(const IOTHUB_CLIENT_CONFIG* client_config, const IOTHUB_CLIENT_DEVICE_CONFIG* device_config, bool use_dev_auth) |
AzureIoTClient | 66:a419827cb051 | 186 | { |
AzureIoTClient | 66:a419827cb051 | 187 | IOTHUB_CLIENT_LL_HANDLE_DATA* result; |
AzureIoTClient | 77:e4e36df9caee | 188 | srand((unsigned int)time(NULL)); |
AzureIoTClient | 66:a419827cb051 | 189 | STRING_HANDLE product_info = make_product_info(NULL); |
AzureIoTClient | 66:a419827cb051 | 190 | if (product_info == NULL) |
AzureIoTClient | 66:a419827cb051 | 191 | { |
AzureIoTClient | 66:a419827cb051 | 192 | LogError("failed to initialize product info"); |
AzureIoTClient | 66:a419827cb051 | 193 | result = NULL; |
AzureIoTClient | 66:a419827cb051 | 194 | } |
AzureIoTClient | 66:a419827cb051 | 195 | else |
AzureIoTClient | 66:a419827cb051 | 196 | { |
AzureIoTClient | 66:a419827cb051 | 197 | result = (IOTHUB_CLIENT_LL_HANDLE_DATA*)malloc(sizeof(IOTHUB_CLIENT_LL_HANDLE_DATA)); |
AzureIoTClient | 66:a419827cb051 | 198 | if (result == NULL) |
AzureIoTClient | 63:1bf1c2d60aab | 199 | { |
AzureIoTClient | 66:a419827cb051 | 200 | LogError("failure allocating IOTHUB_CLIENT_LL_HANDLE_DATA"); |
AzureIoTClient | 66:a419827cb051 | 201 | STRING_delete(product_info); |
AzureIoTClient | 63:1bf1c2d60aab | 202 | } |
AzureIoTClient | 63:1bf1c2d60aab | 203 | else |
AzureIoTClient | 63:1bf1c2d60aab | 204 | { |
AzureIoTClient | 66:a419827cb051 | 205 | IOTHUB_CLIENT_CONFIG actual_config; |
AzureIoTClient | 66:a419827cb051 | 206 | const IOTHUB_CLIENT_CONFIG* config = NULL; |
AzureIoTClient | 66:a419827cb051 | 207 | char* IoTHubName = NULL; |
AzureIoTClient | 75:86205ca63a59 | 208 | char* IoTHubSuffix = NULL; |
AzureIoTClient | 66:a419827cb051 | 209 | |
AzureIoTClient | 66:a419827cb051 | 210 | memset(result, 0, sizeof(IOTHUB_CLIENT_LL_HANDLE_DATA)); |
AzureIoTClient | 75:86205ca63a59 | 211 | if (use_dev_auth) |
AzureIoTClient | 66:a419827cb051 | 212 | { |
AzureIoTClient | 75:86205ca63a59 | 213 | if ((result->authorization_module = IoTHubClient_Auth_CreateFromDeviceAuth(client_config->deviceId)) == NULL) |
AzureIoTClient | 66:a419827cb051 | 214 | { |
AzureIoTClient | 75:86205ca63a59 | 215 | LogError("Failed create authorization module"); |
AzureIoTClient | 66:a419827cb051 | 216 | free(result); |
AzureIoTClient | 75:86205ca63a59 | 217 | STRING_delete(product_info); |
AzureIoTClient | 66:a419827cb051 | 218 | result = NULL; |
AzureIoTClient | 66:a419827cb051 | 219 | } |
AzureIoTClient | 62:5a4cdacf5090 | 220 | } |
AzureIoTClient | 62:5a4cdacf5090 | 221 | else |
AzureIoTClient | 62:5a4cdacf5090 | 222 | { |
AzureIoTClient | 75:86205ca63a59 | 223 | const char* device_key; |
AzureIoTClient | 75:86205ca63a59 | 224 | const char* device_id; |
AzureIoTClient | 75:86205ca63a59 | 225 | const char* sas_token; |
AzureIoTClient | 75:86205ca63a59 | 226 | if (device_config == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 227 | { |
AzureIoTClient | 75:86205ca63a59 | 228 | device_key = client_config->deviceKey; |
AzureIoTClient | 75:86205ca63a59 | 229 | device_id = client_config->deviceId; |
AzureIoTClient | 75:86205ca63a59 | 230 | sas_token = client_config->deviceSasToken; |
AzureIoTClient | 62:5a4cdacf5090 | 231 | } |
AzureIoTClient | 62:5a4cdacf5090 | 232 | else |
AzureIoTClient | 62:5a4cdacf5090 | 233 | { |
AzureIoTClient | 75:86205ca63a59 | 234 | device_key = device_config->deviceKey; |
AzureIoTClient | 75:86205ca63a59 | 235 | device_id = device_config->deviceId; |
AzureIoTClient | 75:86205ca63a59 | 236 | sas_token = device_config->deviceSasToken; |
AzureIoTClient | 75:86205ca63a59 | 237 | } |
AzureIoTClient | 75:86205ca63a59 | 238 | |
AzureIoTClient | 75:86205ca63a59 | 239 | /* Codes_SRS_IOTHUBCLIENT_LL_07_029: [ IoTHubClient_LL_Create shall create the Auth module with the device_key, device_id, and/or deviceSasToken values ] */ |
AzureIoTClient | 75:86205ca63a59 | 240 | if ((result->authorization_module = IoTHubClient_Auth_Create(device_key, device_id, sas_token)) == NULL) |
AzureIoTClient | 75:86205ca63a59 | 241 | { |
AzureIoTClient | 75:86205ca63a59 | 242 | LogError("Failed create authorization module"); |
AzureIoTClient | 75:86205ca63a59 | 243 | free(result); |
AzureIoTClient | 75:86205ca63a59 | 244 | STRING_delete(product_info); |
AzureIoTClient | 75:86205ca63a59 | 245 | result = NULL; |
AzureIoTClient | 75:86205ca63a59 | 246 | } |
AzureIoTClient | 75:86205ca63a59 | 247 | } |
AzureIoTClient | 75:86205ca63a59 | 248 | |
AzureIoTClient | 75:86205ca63a59 | 249 | if (result != NULL) |
AzureIoTClient | 75:86205ca63a59 | 250 | { |
AzureIoTClient | 75:86205ca63a59 | 251 | if (client_config != NULL) |
AzureIoTClient | 75:86205ca63a59 | 252 | { |
AzureIoTClient | 75:86205ca63a59 | 253 | IOTHUBTRANSPORT_CONFIG lowerLayerConfig; |
AzureIoTClient | 75:86205ca63a59 | 254 | memset(&lowerLayerConfig, 0, sizeof(IOTHUBTRANSPORT_CONFIG)); |
AzureIoTClient | 75:86205ca63a59 | 255 | /*Codes_SRS_IOTHUBCLIENT_LL_02_006: [IoTHubClient_LL_Create shall populate a structure of type IOTHUBTRANSPORT_CONFIG with the information from config parameter and the previous DLIST and shall pass that to the underlying layer _Create function.]*/ |
AzureIoTClient | 75:86205ca63a59 | 256 | lowerLayerConfig.upperConfig = client_config; |
AzureIoTClient | 75:86205ca63a59 | 257 | lowerLayerConfig.waitingToSend = &(result->waitingToSend); |
AzureIoTClient | 75:86205ca63a59 | 258 | lowerLayerConfig.auth_module_handle = result->authorization_module; |
AzureIoTClient | 75:86205ca63a59 | 259 | |
AzureIoTClient | 75:86205ca63a59 | 260 | setTransportProtocol(result, (TRANSPORT_PROVIDER*)client_config->protocol()); |
AzureIoTClient | 75:86205ca63a59 | 261 | if ((result->transportHandle = result->IoTHubTransport_Create(&lowerLayerConfig)) == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 262 | { |
AzureIoTClient | 75:86205ca63a59 | 263 | /*Codes_SRS_IOTHUBCLIENT_LL_02_007: [If the underlaying layer _Create function fails them IoTHubClient_LL_Create shall fail and return NULL.] */ |
AzureIoTClient | 75:86205ca63a59 | 264 | LogError("underlying transport failed"); |
AzureIoTClient | 75:86205ca63a59 | 265 | destroy_blob_upload_module(result); |
AzureIoTClient | 75:86205ca63a59 | 266 | tickcounter_destroy(result->tickCounter); |
AzureIoTClient | 63:1bf1c2d60aab | 267 | IoTHubClient_Auth_Destroy(result->authorization_module); |
AzureIoTClient | 66:a419827cb051 | 268 | STRING_delete(product_info); |
AzureIoTClient | 62:5a4cdacf5090 | 269 | free(result); |
AzureIoTClient | 62:5a4cdacf5090 | 270 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 271 | } |
AzureIoTClient | 62:5a4cdacf5090 | 272 | else |
AzureIoTClient | 62:5a4cdacf5090 | 273 | { |
AzureIoTClient | 75:86205ca63a59 | 274 | /*Codes_SRS_IOTHUBCLIENT_LL_02_008: [Otherwise, IoTHubClient_LL_Create shall succeed and return a non-NULL handle.] */ |
AzureIoTClient | 75:86205ca63a59 | 275 | result->isSharedTransport = false; |
AzureIoTClient | 75:86205ca63a59 | 276 | config = client_config; |
AzureIoTClient | 75:86205ca63a59 | 277 | } |
AzureIoTClient | 75:86205ca63a59 | 278 | } |
AzureIoTClient | 75:86205ca63a59 | 279 | else |
AzureIoTClient | 75:86205ca63a59 | 280 | { |
AzureIoTClient | 75:86205ca63a59 | 281 | STRING_HANDLE transport_hostname = NULL; |
AzureIoTClient | 75:86205ca63a59 | 282 | |
AzureIoTClient | 75:86205ca63a59 | 283 | result->transportHandle = device_config->transportHandle; |
AzureIoTClient | 75:86205ca63a59 | 284 | setTransportProtocol(result, (TRANSPORT_PROVIDER*)device_config->protocol()); |
AzureIoTClient | 75:86205ca63a59 | 285 | |
AzureIoTClient | 75:86205ca63a59 | 286 | transport_hostname = result->IoTHubTransport_GetHostname(result->transportHandle); |
AzureIoTClient | 75:86205ca63a59 | 287 | if (transport_hostname == NULL) |
AzureIoTClient | 75:86205ca63a59 | 288 | { |
AzureIoTClient | 75:86205ca63a59 | 289 | /*Codes_SRS_IOTHUBCLIENT_LL_02_097: [ If creating the data structures fails or instantiating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateWithTransport shall fail and return NULL. ]*/ |
AzureIoTClient | 75:86205ca63a59 | 290 | LogError("unable to determine the transport IoTHub name"); |
AzureIoTClient | 75:86205ca63a59 | 291 | IoTHubClient_Auth_Destroy(result->authorization_module); |
AzureIoTClient | 75:86205ca63a59 | 292 | STRING_delete(product_info); |
AzureIoTClient | 75:86205ca63a59 | 293 | free(result); |
AzureIoTClient | 75:86205ca63a59 | 294 | result = NULL; |
AzureIoTClient | 75:86205ca63a59 | 295 | } |
AzureIoTClient | 75:86205ca63a59 | 296 | else |
AzureIoTClient | 75:86205ca63a59 | 297 | { |
AzureIoTClient | 75:86205ca63a59 | 298 | const char* hostname = STRING_c_str(transport_hostname); |
AzureIoTClient | 66:a419827cb051 | 299 | /*Codes_SRS_IOTHUBCLIENT_LL_02_096: [ IoTHubClient_LL_CreateWithTransport shall create the data structures needed to instantiate a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE. ]*/ |
AzureIoTClient | 75:86205ca63a59 | 300 | /*the first '.' says where the iothubname finishes*/ |
AzureIoTClient | 75:86205ca63a59 | 301 | const char* whereIsDot = strchr(hostname, '.'); |
AzureIoTClient | 75:86205ca63a59 | 302 | if (whereIsDot == NULL) |
AzureIoTClient | 66:a419827cb051 | 303 | { |
AzureIoTClient | 66:a419827cb051 | 304 | /*Codes_SRS_IOTHUBCLIENT_LL_02_097: [ If creating the data structures fails or instantiating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateWithTransport shall fail and return NULL. ]*/ |
AzureIoTClient | 75:86205ca63a59 | 305 | LogError("unable to determine the IoTHub name"); |
AzureIoTClient | 66:a419827cb051 | 306 | IoTHubClient_Auth_Destroy(result->authorization_module); |
AzureIoTClient | 66:a419827cb051 | 307 | STRING_delete(product_info); |
AzureIoTClient | 66:a419827cb051 | 308 | free(result); |
AzureIoTClient | 66:a419827cb051 | 309 | result = NULL; |
AzureIoTClient | 66:a419827cb051 | 310 | } |
AzureIoTClient | 66:a419827cb051 | 311 | else |
AzureIoTClient | 66:a419827cb051 | 312 | { |
AzureIoTClient | 75:86205ca63a59 | 313 | size_t suffix_len = strlen(whereIsDot); |
AzureIoTClient | 75:86205ca63a59 | 314 | /*Codes_SRS_IOTHUBCLIENT_LL_02_096: [ IoTHubClient_LL_CreateWithTransport shall create the data structures needed to instantiate a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE. ]*/ |
AzureIoTClient | 75:86205ca63a59 | 315 | IoTHubName = (char*)malloc(whereIsDot - hostname + 1); |
AzureIoTClient | 75:86205ca63a59 | 316 | if (IoTHubName == NULL) |
AzureIoTClient | 75:86205ca63a59 | 317 | { |
AzureIoTClient | 75:86205ca63a59 | 318 | /*Codes_SRS_IOTHUBCLIENT_LL_02_097: [ If creating the data structures fails or instantiating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateWithTransport shall fail and return NULL. ]*/ |
AzureIoTClient | 75:86205ca63a59 | 319 | LogError("unable to malloc"); |
AzureIoTClient | 75:86205ca63a59 | 320 | IoTHubClient_Auth_Destroy(result->authorization_module); |
AzureIoTClient | 75:86205ca63a59 | 321 | STRING_delete(product_info); |
AzureIoTClient | 75:86205ca63a59 | 322 | free(result); |
AzureIoTClient | 75:86205ca63a59 | 323 | result = NULL; |
AzureIoTClient | 75:86205ca63a59 | 324 | } |
AzureIoTClient | 75:86205ca63a59 | 325 | else if ((IoTHubSuffix = (char*)malloc(suffix_len + 1)) == NULL) |
AzureIoTClient | 75:86205ca63a59 | 326 | { |
AzureIoTClient | 75:86205ca63a59 | 327 | /*Codes_SRS_IOTHUBCLIENT_LL_02_097: [ If creating the data structures fails or instantiating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateWithTransport shall fail and return NULL. ]*/ |
AzureIoTClient | 75:86205ca63a59 | 328 | LogError("unable to malloc"); |
AzureIoTClient | 75:86205ca63a59 | 329 | IoTHubClient_Auth_Destroy(result->authorization_module); |
AzureIoTClient | 75:86205ca63a59 | 330 | STRING_delete(product_info); |
AzureIoTClient | 75:86205ca63a59 | 331 | free(result); |
AzureIoTClient | 75:86205ca63a59 | 332 | result = NULL; |
AzureIoTClient | 75:86205ca63a59 | 333 | } |
AzureIoTClient | 75:86205ca63a59 | 334 | else |
AzureIoTClient | 75:86205ca63a59 | 335 | { |
AzureIoTClient | 75:86205ca63a59 | 336 | memset(IoTHubName, 0, whereIsDot - hostname + 1); |
AzureIoTClient | 75:86205ca63a59 | 337 | (void)strncpy(IoTHubName, hostname, whereIsDot - hostname); |
AzureIoTClient | 75:86205ca63a59 | 338 | (void)strcpy(IoTHubSuffix, whereIsDot+1); |
AzureIoTClient | 62:5a4cdacf5090 | 339 | |
AzureIoTClient | 75:86205ca63a59 | 340 | actual_config.deviceId = device_config->deviceId; |
AzureIoTClient | 75:86205ca63a59 | 341 | actual_config.deviceKey = device_config->deviceKey; |
AzureIoTClient | 75:86205ca63a59 | 342 | actual_config.deviceSasToken = device_config->deviceSasToken; |
AzureIoTClient | 75:86205ca63a59 | 343 | actual_config.iotHubName = IoTHubName; |
AzureIoTClient | 75:86205ca63a59 | 344 | actual_config.iotHubSuffix = IoTHubSuffix; |
AzureIoTClient | 75:86205ca63a59 | 345 | actual_config.protocol = NULL; /*irrelevant to IoTHubClient_LL_UploadToBlob*/ |
AzureIoTClient | 75:86205ca63a59 | 346 | actual_config.protocolGatewayHostName = NULL; /*irrelevant to IoTHubClient_LL_UploadToBlob*/ |
AzureIoTClient | 62:5a4cdacf5090 | 347 | |
AzureIoTClient | 75:86205ca63a59 | 348 | config = &actual_config; |
AzureIoTClient | 62:5a4cdacf5090 | 349 | |
AzureIoTClient | 75:86205ca63a59 | 350 | /*Codes_SRS_IOTHUBCLIENT_LL_02_008: [Otherwise, IoTHubClient_LL_Create shall succeed and return a non-NULL handle.] */ |
AzureIoTClient | 75:86205ca63a59 | 351 | result->isSharedTransport = true; |
AzureIoTClient | 75:86205ca63a59 | 352 | } |
AzureIoTClient | 66:a419827cb051 | 353 | } |
AzureIoTClient | 62:5a4cdacf5090 | 354 | } |
AzureIoTClient | 75:86205ca63a59 | 355 | STRING_delete(transport_hostname); |
AzureIoTClient | 62:5a4cdacf5090 | 356 | } |
AzureIoTClient | 62:5a4cdacf5090 | 357 | } |
AzureIoTClient | 66:a419827cb051 | 358 | if (result != NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 359 | { |
AzureIoTClient | 66:a419827cb051 | 360 | if (create_blob_upload_module(result, config) != 0) |
AzureIoTClient | 62:5a4cdacf5090 | 361 | { |
AzureIoTClient | 66:a419827cb051 | 362 | LogError("unable to create blob upload"); |
AzureIoTClient | 73:c4d9077dd0a1 | 363 | // Codes_SRS_IOTHUBCLIENT_LL_09_010: [ If any failure occurs `IoTHubClient_LL_Create` shall destroy the `transportHandle` only if it has created it ] |
AzureIoTClient | 73:c4d9077dd0a1 | 364 | if (!result->isSharedTransport) |
AzureIoTClient | 73:c4d9077dd0a1 | 365 | { |
AzureIoTClient | 73:c4d9077dd0a1 | 366 | result->IoTHubTransport_Destroy(result->transportHandle); |
AzureIoTClient | 73:c4d9077dd0a1 | 367 | } |
AzureIoTClient | 62:5a4cdacf5090 | 368 | IoTHubClient_Auth_Destroy(result->authorization_module); |
AzureIoTClient | 66:a419827cb051 | 369 | STRING_delete(product_info); |
AzureIoTClient | 62:5a4cdacf5090 | 370 | free(result); |
AzureIoTClient | 62:5a4cdacf5090 | 371 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 372 | } |
AzureIoTClient | 62:5a4cdacf5090 | 373 | else |
AzureIoTClient | 62:5a4cdacf5090 | 374 | { |
AzureIoTClient | 66:a419827cb051 | 375 | if ((result->tickCounter = tickcounter_create()) == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 376 | { |
AzureIoTClient | 66:a419827cb051 | 377 | LogError("unable to get a tickcounter"); |
AzureIoTClient | 73:c4d9077dd0a1 | 378 | // Codes_SRS_IOTHUBCLIENT_LL_09_010: [ If any failure occurs `IoTHubClient_LL_Create` shall destroy the `transportHandle` only if it has created it ] |
AzureIoTClient | 73:c4d9077dd0a1 | 379 | if (!result->isSharedTransport) |
AzureIoTClient | 73:c4d9077dd0a1 | 380 | { |
AzureIoTClient | 73:c4d9077dd0a1 | 381 | result->IoTHubTransport_Destroy(result->transportHandle); |
AzureIoTClient | 73:c4d9077dd0a1 | 382 | } |
AzureIoTClient | 66:a419827cb051 | 383 | destroy_blob_upload_module(result); |
AzureIoTClient | 62:5a4cdacf5090 | 384 | IoTHubClient_Auth_Destroy(result->authorization_module); |
AzureIoTClient | 66:a419827cb051 | 385 | STRING_delete(product_info); |
AzureIoTClient | 62:5a4cdacf5090 | 386 | free(result); |
AzureIoTClient | 62:5a4cdacf5090 | 387 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 388 | } |
AzureIoTClient | 62:5a4cdacf5090 | 389 | else |
AzureIoTClient | 62:5a4cdacf5090 | 390 | { |
AzureIoTClient | 66:a419827cb051 | 391 | /*Codes_SRS_IOTHUBCLIENT_LL_02_004: [Otherwise IoTHubClient_LL_Create shall initialize a new DLIST (further called "waitingToSend") containing records with fields of the following types: IOTHUB_MESSAGE_HANDLE, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, void*.]*/ |
AzureIoTClient | 66:a419827cb051 | 392 | DList_InitializeListHead(&(result->waitingToSend)); |
AzureIoTClient | 66:a419827cb051 | 393 | DList_InitializeListHead(&(result->iot_msg_queue)); |
AzureIoTClient | 66:a419827cb051 | 394 | DList_InitializeListHead(&(result->iot_ack_queue)); |
AzureIoTClient | 66:a419827cb051 | 395 | result->messageCallback.type = CALLBACK_TYPE_NONE; |
AzureIoTClient | 66:a419827cb051 | 396 | result->lastMessageReceiveTime = INDEFINITE_TIME; |
AzureIoTClient | 66:a419827cb051 | 397 | result->data_msg_id = 1; |
AzureIoTClient | 66:a419827cb051 | 398 | result->product_info = product_info; |
AzureIoTClient | 66:a419827cb051 | 399 | |
AzureIoTClient | 66:a419827cb051 | 400 | IOTHUB_DEVICE_CONFIG deviceConfig; |
AzureIoTClient | 66:a419827cb051 | 401 | deviceConfig.deviceId = config->deviceId; |
AzureIoTClient | 66:a419827cb051 | 402 | deviceConfig.deviceKey = config->deviceKey; |
AzureIoTClient | 66:a419827cb051 | 403 | deviceConfig.deviceSasToken = config->deviceSasToken; |
AzureIoTClient | 66:a419827cb051 | 404 | deviceConfig.authorization_module = result->authorization_module; |
AzureIoTClient | 66:a419827cb051 | 405 | |
AzureIoTClient | 66:a419827cb051 | 406 | /*Codes_SRS_IOTHUBCLIENT_LL_17_008: [IoTHubClient_LL_Create shall call the transport _Register function with a populated structure of type IOTHUB_DEVICE_CONFIG and waitingToSend list.] */ |
AzureIoTClient | 66:a419827cb051 | 407 | if ((result->deviceHandle = result->IoTHubTransport_Register(result->transportHandle, &deviceConfig, result, &(result->waitingToSend))) == NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 408 | { |
AzureIoTClient | 66:a419827cb051 | 409 | LogError("Registering device in transport failed"); |
AzureIoTClient | 62:5a4cdacf5090 | 410 | IoTHubClient_Auth_Destroy(result->authorization_module); |
AzureIoTClient | 73:c4d9077dd0a1 | 411 | // Codes_SRS_IOTHUBCLIENT_LL_09_010: [ If any failure occurs `IoTHubClient_LL_Create` shall destroy the `transportHandle` only if it has created it ] |
AzureIoTClient | 73:c4d9077dd0a1 | 412 | if (!result->isSharedTransport) |
AzureIoTClient | 73:c4d9077dd0a1 | 413 | { |
AzureIoTClient | 73:c4d9077dd0a1 | 414 | result->IoTHubTransport_Destroy(result->transportHandle); |
AzureIoTClient | 73:c4d9077dd0a1 | 415 | } |
AzureIoTClient | 62:5a4cdacf5090 | 416 | destroy_blob_upload_module(result); |
AzureIoTClient | 62:5a4cdacf5090 | 417 | tickcounter_destroy(result->tickCounter); |
AzureIoTClient | 66:a419827cb051 | 418 | STRING_delete(product_info); |
AzureIoTClient | 62:5a4cdacf5090 | 419 | free(result); |
AzureIoTClient | 62:5a4cdacf5090 | 420 | result = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 421 | } |
AzureIoTClient | 66:a419827cb051 | 422 | else |
AzureIoTClient | 66:a419827cb051 | 423 | { |
AzureIoTClient | 66:a419827cb051 | 424 | /*Codes_SRS_IOTHUBCLIENT_LL_02_042: [ By default, messages shall not timeout. ]*/ |
AzureIoTClient | 66:a419827cb051 | 425 | result->currentMessageTimeout = 0; |
AzureIoTClient | 66:a419827cb051 | 426 | result->current_device_twin_timeout = 0; |
AzureIoTClient | 77:e4e36df9caee | 427 | |
AzureIoTClient | 77:e4e36df9caee | 428 | result->diagnostic_setting.currentMessageNumber = 0; |
AzureIoTClient | 77:e4e36df9caee | 429 | result->diagnostic_setting.diagSamplingPercentage = 0; |
AzureIoTClient | 66:a419827cb051 | 430 | /*Codes_SRS_IOTHUBCLIENT_LL_25_124: [ `IoTHubClient_LL_Create` shall set the default retry policy as Exponential backoff with jitter and if succeed and return a `non-NULL` handle. ]*/ |
AzureIoTClient | 66:a419827cb051 | 431 | if (IoTHubClient_LL_SetRetryPolicy(result, IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER, 0) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 66:a419827cb051 | 432 | { |
AzureIoTClient | 66:a419827cb051 | 433 | LogError("Setting default retry policy in transport failed"); |
AzureIoTClient | 66:a419827cb051 | 434 | result->IoTHubTransport_Unregister(result->deviceHandle); |
AzureIoTClient | 66:a419827cb051 | 435 | IoTHubClient_Auth_Destroy(result->authorization_module); |
AzureIoTClient | 73:c4d9077dd0a1 | 436 | // Codes_SRS_IOTHUBCLIENT_LL_09_010: [ If any failure occurs `IoTHubClient_LL_Create` shall destroy the `transportHandle` only if it has created it ] |
AzureIoTClient | 73:c4d9077dd0a1 | 437 | if (!result->isSharedTransport) |
AzureIoTClient | 73:c4d9077dd0a1 | 438 | { |
AzureIoTClient | 73:c4d9077dd0a1 | 439 | result->IoTHubTransport_Destroy(result->transportHandle); |
AzureIoTClient | 73:c4d9077dd0a1 | 440 | } |
AzureIoTClient | 66:a419827cb051 | 441 | destroy_blob_upload_module(result); |
AzureIoTClient | 66:a419827cb051 | 442 | tickcounter_destroy(result->tickCounter); |
AzureIoTClient | 66:a419827cb051 | 443 | STRING_delete(product_info); |
AzureIoTClient | 66:a419827cb051 | 444 | free(result); |
AzureIoTClient | 66:a419827cb051 | 445 | result = NULL; |
AzureIoTClient | 66:a419827cb051 | 446 | } |
AzureIoTClient | 66:a419827cb051 | 447 | } |
AzureIoTClient | 62:5a4cdacf5090 | 448 | } |
AzureIoTClient | 62:5a4cdacf5090 | 449 | } |
AzureIoTClient | 62:5a4cdacf5090 | 450 | } |
AzureIoTClient | 66:a419827cb051 | 451 | if (IoTHubName) |
AzureIoTClient | 66:a419827cb051 | 452 | { |
AzureIoTClient | 66:a419827cb051 | 453 | free(IoTHubName); |
AzureIoTClient | 66:a419827cb051 | 454 | } |
AzureIoTClient | 75:86205ca63a59 | 455 | if (IoTHubSuffix) |
AzureIoTClient | 66:a419827cb051 | 456 | { |
AzureIoTClient | 75:86205ca63a59 | 457 | free(IoTHubSuffix); |
AzureIoTClient | 66:a419827cb051 | 458 | } |
AzureIoTClient | 62:5a4cdacf5090 | 459 | } |
AzureIoTClient | 62:5a4cdacf5090 | 460 | } |
AzureIoTClient | 62:5a4cdacf5090 | 461 | return result; |
AzureIoTClient | 62:5a4cdacf5090 | 462 | } |
AzureIoTClient | 62:5a4cdacf5090 | 463 | |
AzureIoTClient | 53:1e5a1ca1f274 | 464 | static uint32_t get_next_item_id(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData) |
AzureIoTClient | 53:1e5a1ca1f274 | 465 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 466 | if (handleData->data_msg_id+1 >= UINT32_MAX) |
AzureIoTClient | 53:1e5a1ca1f274 | 467 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 468 | handleData->data_msg_id = 1; |
AzureIoTClient | 53:1e5a1ca1f274 | 469 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 470 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 471 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 472 | handleData->data_msg_id++; |
AzureIoTClient | 53:1e5a1ca1f274 | 473 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 474 | return handleData->data_msg_id; |
AzureIoTClient | 53:1e5a1ca1f274 | 475 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 476 | |
AzureIoTClient | 53:1e5a1ca1f274 | 477 | static IOTHUB_DEVICE_TWIN* dev_twin_data_create(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, uint32_t id, const unsigned char* reportedState, size_t size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reportedStateCallback, void* userContextCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 478 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 479 | IOTHUB_DEVICE_TWIN* result = (IOTHUB_DEVICE_TWIN*)malloc(sizeof(IOTHUB_DEVICE_TWIN) ); |
AzureIoTClient | 53:1e5a1ca1f274 | 480 | if (result != NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 481 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 482 | result->report_data_handle = CONSTBUFFER_Create(reportedState, size); |
AzureIoTClient | 53:1e5a1ca1f274 | 483 | if (result->report_data_handle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 484 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 485 | LogError("Failure allocating reported state data"); |
AzureIoTClient | 53:1e5a1ca1f274 | 486 | free(result); |
AzureIoTClient | 53:1e5a1ca1f274 | 487 | result = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 488 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 489 | else if (tickcounter_get_current_ms(handleData->tickCounter, &result->ms_timesOutAfter) != 0) |
AzureIoTClient | 53:1e5a1ca1f274 | 490 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 491 | LogError("Failure getting tickcount info"); |
AzureIoTClient | 53:1e5a1ca1f274 | 492 | CONSTBUFFER_Destroy(result->report_data_handle); |
AzureIoTClient | 53:1e5a1ca1f274 | 493 | free(result); |
AzureIoTClient | 53:1e5a1ca1f274 | 494 | result = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 495 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 496 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 497 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 498 | result->item_id = id; |
AzureIoTClient | 53:1e5a1ca1f274 | 499 | result->ms_timesOutAfter = 0; |
AzureIoTClient | 53:1e5a1ca1f274 | 500 | result->context = userContextCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 501 | result->reported_state_callback = reportedStateCallback; |
AzureIoTClient | 75:86205ca63a59 | 502 | result->client_handle = handleData; |
AzureIoTClient | 75:86205ca63a59 | 503 | result->device_handle = handleData->deviceHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 504 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 505 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 506 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 507 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 508 | LogError("Failure allocating device twin information"); |
AzureIoTClient | 53:1e5a1ca1f274 | 509 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 510 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 511 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 512 | |
AzureIoTClient | 75:86205ca63a59 | 513 | IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromDeviceAuth(const char* iothub_uri, const char* device_id, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol) |
AzureIoTClient | 75:86205ca63a59 | 514 | { |
AzureIoTClient | 75:86205ca63a59 | 515 | IOTHUB_CLIENT_LL_HANDLE result; |
AzureIoTClient | 75:86205ca63a59 | 516 | if (iothub_uri == NULL || protocol == NULL || device_id == NULL) |
AzureIoTClient | 75:86205ca63a59 | 517 | { |
AzureIoTClient | 75:86205ca63a59 | 518 | LogError("Input parameter is NULL: iothub_uri: %p protocol: %p device_id: %p", iothub_uri, protocol, device_id); |
AzureIoTClient | 75:86205ca63a59 | 519 | result = NULL; |
AzureIoTClient | 75:86205ca63a59 | 520 | } |
AzureIoTClient | 75:86205ca63a59 | 521 | else |
AzureIoTClient | 75:86205ca63a59 | 522 | { |
AzureIoTClient | 78:74a8d3068204 | 523 | #ifdef USE_PROV_MODULE |
AzureIoTClient | 75:86205ca63a59 | 524 | IOTHUB_CLIENT_CONFIG* config = (IOTHUB_CLIENT_CONFIG*)malloc(sizeof(IOTHUB_CLIENT_CONFIG)); |
AzureIoTClient | 75:86205ca63a59 | 525 | if (config == NULL) |
AzureIoTClient | 75:86205ca63a59 | 526 | { |
AzureIoTClient | 75:86205ca63a59 | 527 | /* Codes_SRS_IOTHUBCLIENT_LL_12_012: [If the allocation failed IoTHubClient_LL_CreateFromConnectionString returns NULL] */ |
AzureIoTClient | 75:86205ca63a59 | 528 | LogError("Malloc failed"); |
AzureIoTClient | 75:86205ca63a59 | 529 | result = NULL; |
AzureIoTClient | 75:86205ca63a59 | 530 | } |
AzureIoTClient | 75:86205ca63a59 | 531 | else |
AzureIoTClient | 75:86205ca63a59 | 532 | { |
AzureIoTClient | 75:86205ca63a59 | 533 | const char* iterator; |
AzureIoTClient | 75:86205ca63a59 | 534 | const char* initial; |
AzureIoTClient | 75:86205ca63a59 | 535 | char* iothub_name = NULL; |
AzureIoTClient | 75:86205ca63a59 | 536 | char* iothub_suffix = NULL; |
AzureIoTClient | 75:86205ca63a59 | 537 | |
AzureIoTClient | 75:86205ca63a59 | 538 | memset(config, 0, sizeof(IOTHUB_CLIENT_CONFIG) ); |
AzureIoTClient | 75:86205ca63a59 | 539 | config->protocol = protocol; |
AzureIoTClient | 75:86205ca63a59 | 540 | config->deviceId = device_id; |
AzureIoTClient | 75:86205ca63a59 | 541 | //config->useDeviceAuthKey = 1; |
AzureIoTClient | 75:86205ca63a59 | 542 | |
AzureIoTClient | 75:86205ca63a59 | 543 | // Find the iothub suffix |
AzureIoTClient | 75:86205ca63a59 | 544 | initial = iterator = iothub_uri; |
AzureIoTClient | 75:86205ca63a59 | 545 | while (iterator != NULL && *iterator != '\0') |
AzureIoTClient | 75:86205ca63a59 | 546 | { |
AzureIoTClient | 75:86205ca63a59 | 547 | if (*iterator == '.') |
AzureIoTClient | 75:86205ca63a59 | 548 | { |
AzureIoTClient | 75:86205ca63a59 | 549 | size_t length = iterator-initial; |
AzureIoTClient | 75:86205ca63a59 | 550 | iothub_name = (char*)malloc(length+1); |
AzureIoTClient | 75:86205ca63a59 | 551 | if (iothub_name != NULL) |
AzureIoTClient | 75:86205ca63a59 | 552 | { |
AzureIoTClient | 75:86205ca63a59 | 553 | memset(iothub_name, 0, length + 1); |
AzureIoTClient | 75:86205ca63a59 | 554 | memcpy(iothub_name, initial, length); |
AzureIoTClient | 75:86205ca63a59 | 555 | config->iotHubName = iothub_name; |
AzureIoTClient | 75:86205ca63a59 | 556 | |
AzureIoTClient | 75:86205ca63a59 | 557 | length = strlen(initial)-length-1; |
AzureIoTClient | 75:86205ca63a59 | 558 | iothub_suffix = (char*)malloc(length + 1); |
AzureIoTClient | 75:86205ca63a59 | 559 | if (iothub_suffix != NULL) |
AzureIoTClient | 75:86205ca63a59 | 560 | { |
AzureIoTClient | 75:86205ca63a59 | 561 | memset(iothub_suffix, 0, length + 1); |
AzureIoTClient | 75:86205ca63a59 | 562 | memcpy(iothub_suffix, iterator+1, length); |
AzureIoTClient | 75:86205ca63a59 | 563 | config->iotHubSuffix = iothub_suffix; |
AzureIoTClient | 75:86205ca63a59 | 564 | break; |
AzureIoTClient | 75:86205ca63a59 | 565 | } |
AzureIoTClient | 75:86205ca63a59 | 566 | else |
AzureIoTClient | 75:86205ca63a59 | 567 | { |
AzureIoTClient | 75:86205ca63a59 | 568 | LogError("Failed to allocate iothub suffix"); |
AzureIoTClient | 75:86205ca63a59 | 569 | free(iothub_name); |
AzureIoTClient | 75:86205ca63a59 | 570 | result = NULL; |
AzureIoTClient | 75:86205ca63a59 | 571 | } |
AzureIoTClient | 75:86205ca63a59 | 572 | } |
AzureIoTClient | 75:86205ca63a59 | 573 | else |
AzureIoTClient | 75:86205ca63a59 | 574 | { |
AzureIoTClient | 75:86205ca63a59 | 575 | LogError("Failed to allocate iothub name"); |
AzureIoTClient | 75:86205ca63a59 | 576 | result = NULL; |
AzureIoTClient | 75:86205ca63a59 | 577 | } |
AzureIoTClient | 75:86205ca63a59 | 578 | } |
AzureIoTClient | 75:86205ca63a59 | 579 | iterator++; |
AzureIoTClient | 75:86205ca63a59 | 580 | } |
AzureIoTClient | 75:86205ca63a59 | 581 | |
AzureIoTClient | 75:86205ca63a59 | 582 | if (config->iotHubName == NULL || config->iotHubSuffix == NULL) |
AzureIoTClient | 75:86205ca63a59 | 583 | { |
AzureIoTClient | 75:86205ca63a59 | 584 | LogError("initialize iothub client"); |
AzureIoTClient | 75:86205ca63a59 | 585 | result = NULL; |
AzureIoTClient | 75:86205ca63a59 | 586 | } |
AzureIoTClient | 75:86205ca63a59 | 587 | else |
AzureIoTClient | 75:86205ca63a59 | 588 | { |
AzureIoTClient | 75:86205ca63a59 | 589 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = initialize_iothub_client(config, NULL, true); |
AzureIoTClient | 75:86205ca63a59 | 590 | if (handleData == NULL) |
AzureIoTClient | 75:86205ca63a59 | 591 | { |
AzureIoTClient | 75:86205ca63a59 | 592 | LogError("initialize iothub client"); |
AzureIoTClient | 75:86205ca63a59 | 593 | result = NULL; |
AzureIoTClient | 75:86205ca63a59 | 594 | } |
AzureIoTClient | 75:86205ca63a59 | 595 | else |
AzureIoTClient | 75:86205ca63a59 | 596 | { |
AzureIoTClient | 75:86205ca63a59 | 597 | result = handleData; |
AzureIoTClient | 75:86205ca63a59 | 598 | } |
AzureIoTClient | 75:86205ca63a59 | 599 | } |
AzureIoTClient | 75:86205ca63a59 | 600 | |
AzureIoTClient | 75:86205ca63a59 | 601 | free(iothub_name); |
AzureIoTClient | 75:86205ca63a59 | 602 | free(iothub_suffix); |
AzureIoTClient | 75:86205ca63a59 | 603 | free(config); |
AzureIoTClient | 75:86205ca63a59 | 604 | } |
AzureIoTClient | 75:86205ca63a59 | 605 | #else |
AzureIoTClient | 78:74a8d3068204 | 606 | LogError("HSM module is not included"); |
AzureIoTClient | 75:86205ca63a59 | 607 | result = NULL; |
AzureIoTClient | 75:86205ca63a59 | 608 | #endif |
AzureIoTClient | 75:86205ca63a59 | 609 | } |
AzureIoTClient | 75:86205ca63a59 | 610 | return result; |
AzureIoTClient | 75:86205ca63a59 | 611 | } |
AzureIoTClient | 75:86205ca63a59 | 612 | |
AzureIoTClient | 16:deba40344375 | 613 | IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol) |
AzureIoTClient | 16:deba40344375 | 614 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 615 | IOTHUB_CLIENT_LL_HANDLE result; |
AzureIoTClient | 16:deba40344375 | 616 | |
AzureIoTClient | 42:448eecc3676e | 617 | /*Codes_SRS_IOTHUBCLIENT_LL_05_001: [IoTHubClient_LL_CreateFromConnectionString shall obtain the version string by a call to IoTHubClient_GetVersionString.]*/ |
AzureIoTClient | 42:448eecc3676e | 618 | /*Codes_SRS_IOTHUBCLIENT_LL_05_002: [IoTHubClient_LL_CreateFromConnectionString shall print the version string to standard output.]*/ |
AzureIoTClient | 42:448eecc3676e | 619 | LogInfo("IoT Hub SDK for C, version %s", IoTHubClient_GetVersionString()); |
AzureIoTClient | 16:deba40344375 | 620 | |
AzureIoTClient | 42:448eecc3676e | 621 | /* Codes_SRS_IOTHUBCLIENT_LL_12_003: [IoTHubClient_LL_CreateFromConnectionString shall verify the input parameter and if it is NULL then return NULL] */ |
AzureIoTClient | 42:448eecc3676e | 622 | if (connectionString == NULL) |
AzureIoTClient | 42:448eecc3676e | 623 | { |
AzureIoTClient | 42:448eecc3676e | 624 | LogError("Input parameter is NULL: connectionString"); |
AzureIoTClient | 53:1e5a1ca1f274 | 625 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 626 | } |
AzureIoTClient | 42:448eecc3676e | 627 | else if (protocol == NULL) |
AzureIoTClient | 42:448eecc3676e | 628 | { |
AzureIoTClient | 42:448eecc3676e | 629 | LogError("Input parameter is NULL: protocol"); |
AzureIoTClient | 53:1e5a1ca1f274 | 630 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 631 | } |
AzureIoTClient | 42:448eecc3676e | 632 | else |
AzureIoTClient | 42:448eecc3676e | 633 | { |
AzureIoTClient | 42:448eecc3676e | 634 | /* Codes_SRS_IOTHUBCLIENT_LL_12_004: [IoTHubClient_LL_CreateFromConnectionString shall allocate IOTHUB_CLIENT_CONFIG structure] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 635 | IOTHUB_CLIENT_CONFIG* config = (IOTHUB_CLIENT_CONFIG*) malloc(sizeof(IOTHUB_CLIENT_CONFIG)); |
AzureIoTClient | 42:448eecc3676e | 636 | if (config == NULL) |
AzureIoTClient | 42:448eecc3676e | 637 | { |
AzureIoTClient | 42:448eecc3676e | 638 | /* Codes_SRS_IOTHUBCLIENT_LL_12_012: [If the allocation failed IoTHubClient_LL_CreateFromConnectionString returns NULL] */ |
AzureIoTClient | 42:448eecc3676e | 639 | LogError("Malloc failed"); |
AzureIoTClient | 53:1e5a1ca1f274 | 640 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 641 | } |
AzureIoTClient | 42:448eecc3676e | 642 | else |
AzureIoTClient | 42:448eecc3676e | 643 | { |
AzureIoTClient | 42:448eecc3676e | 644 | STRING_TOKENIZER_HANDLE tokenizer1 = NULL; |
AzureIoTClient | 42:448eecc3676e | 645 | STRING_HANDLE connString = NULL; |
AzureIoTClient | 42:448eecc3676e | 646 | STRING_HANDLE tokenString = NULL; |
AzureIoTClient | 42:448eecc3676e | 647 | STRING_HANDLE valueString = NULL; |
AzureIoTClient | 42:448eecc3676e | 648 | STRING_HANDLE hostNameString = NULL; |
AzureIoTClient | 42:448eecc3676e | 649 | STRING_HANDLE hostSuffixString = NULL; |
AzureIoTClient | 42:448eecc3676e | 650 | STRING_HANDLE deviceIdString = NULL; |
AzureIoTClient | 42:448eecc3676e | 651 | STRING_HANDLE deviceKeyString = NULL; |
AzureIoTClient | 42:448eecc3676e | 652 | STRING_HANDLE deviceSasTokenString = NULL; |
AzureIoTClient | 42:448eecc3676e | 653 | STRING_HANDLE protocolGateway = NULL; |
AzureIoTClient | 16:deba40344375 | 654 | |
AzureIoTClient | 42:448eecc3676e | 655 | config->protocol = protocol; |
AzureIoTClient | 16:deba40344375 | 656 | |
AzureIoTClient | 42:448eecc3676e | 657 | config->iotHubName = NULL; |
AzureIoTClient | 42:448eecc3676e | 658 | config->iotHubSuffix = NULL; |
AzureIoTClient | 42:448eecc3676e | 659 | config->deviceId = NULL; |
AzureIoTClient | 42:448eecc3676e | 660 | config->deviceKey = NULL; |
AzureIoTClient | 42:448eecc3676e | 661 | config->deviceSasToken = NULL; |
AzureIoTClient | 40:1a94db9139ea | 662 | |
AzureIoTClient | 42:448eecc3676e | 663 | /* Codes_SRS_IOTHUBCLIENT_LL_04_002: [If it does not, it shall pass the protocolGatewayHostName NULL.] */ |
AzureIoTClient | 42:448eecc3676e | 664 | config->protocolGatewayHostName = NULL; |
AzureIoTClient | 16:deba40344375 | 665 | |
AzureIoTClient | 42:448eecc3676e | 666 | if ((connString = STRING_construct(connectionString)) == NULL) |
AzureIoTClient | 42:448eecc3676e | 667 | { |
AzureIoTClient | 42:448eecc3676e | 668 | LogError("Error constructing connectiong String"); |
AzureIoTClient | 53:1e5a1ca1f274 | 669 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 670 | } |
AzureIoTClient | 42:448eecc3676e | 671 | else if ((tokenizer1 = STRING_TOKENIZER_create(connString)) == NULL) |
AzureIoTClient | 42:448eecc3676e | 672 | { |
AzureIoTClient | 42:448eecc3676e | 673 | LogError("Error creating Tokenizer"); |
AzureIoTClient | 53:1e5a1ca1f274 | 674 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 675 | } |
AzureIoTClient | 42:448eecc3676e | 676 | else if ((tokenString = STRING_new()) == NULL) |
AzureIoTClient | 42:448eecc3676e | 677 | { |
AzureIoTClient | 42:448eecc3676e | 678 | LogError("Error creating Token String"); |
AzureIoTClient | 53:1e5a1ca1f274 | 679 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 680 | } |
AzureIoTClient | 42:448eecc3676e | 681 | else if ((valueString = STRING_new()) == NULL) |
AzureIoTClient | 42:448eecc3676e | 682 | { |
AzureIoTClient | 42:448eecc3676e | 683 | LogError("Error creating Value String"); |
AzureIoTClient | 53:1e5a1ca1f274 | 684 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 685 | } |
AzureIoTClient | 42:448eecc3676e | 686 | else if ((hostNameString = STRING_new()) == NULL) |
AzureIoTClient | 42:448eecc3676e | 687 | { |
AzureIoTClient | 42:448eecc3676e | 688 | LogError("Error creating HostName String"); |
AzureIoTClient | 53:1e5a1ca1f274 | 689 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 690 | } |
AzureIoTClient | 42:448eecc3676e | 691 | else if ((hostSuffixString = STRING_new()) == NULL) |
AzureIoTClient | 42:448eecc3676e | 692 | { |
AzureIoTClient | 42:448eecc3676e | 693 | LogError("Error creating HostSuffix String"); |
AzureIoTClient | 53:1e5a1ca1f274 | 694 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 695 | } |
AzureIoTClient | 42:448eecc3676e | 696 | /* Codes_SRS_IOTHUBCLIENT_LL_12_005: [IoTHubClient_LL_CreateFromConnectionString shall try to parse the connectionString input parameter for the following structure: "Key1=value1;key2=value2;key3=value3..."] */ |
Azure.IoT Build | 45:54c11b1b1407 | 697 | /* Codes_SRS_IOTHUBCLIENT_LL_12_006: [IoTHubClient_LL_CreateFromConnectionString shall verify the existence of the following Key/Value pairs in the connection string: HostName, DeviceId, SharedAccessKey, SharedAccessSignature or x509] */ |
AzureIoTClient | 42:448eecc3676e | 698 | else |
AzureIoTClient | 42:448eecc3676e | 699 | { |
Azure.IoT Build | 45:54c11b1b1407 | 700 | int isx509found = 0; |
AzureIoTClient | 42:448eecc3676e | 701 | while ((STRING_TOKENIZER_get_next_token(tokenizer1, tokenString, "=") == 0)) |
AzureIoTClient | 42:448eecc3676e | 702 | { |
AzureIoTClient | 42:448eecc3676e | 703 | if (STRING_TOKENIZER_get_next_token(tokenizer1, valueString, ";") != 0) |
AzureIoTClient | 42:448eecc3676e | 704 | { |
AzureIoTClient | 42:448eecc3676e | 705 | LogError("Tokenizer error"); |
AzureIoTClient | 42:448eecc3676e | 706 | break; |
AzureIoTClient | 42:448eecc3676e | 707 | } |
AzureIoTClient | 42:448eecc3676e | 708 | else |
AzureIoTClient | 42:448eecc3676e | 709 | { |
AzureIoTClient | 42:448eecc3676e | 710 | if (tokenString != NULL) |
AzureIoTClient | 42:448eecc3676e | 711 | { |
AzureIoTClient | 42:448eecc3676e | 712 | /* Codes_SRS_IOTHUBCLIENT_LL_12_010: [IoTHubClient_LL_CreateFromConnectionString shall fill up the IOTHUB_CLIENT_CONFIG structure using the following mapping: iotHubName = Name, iotHubSuffix = Suffix, deviceId = DeviceId, deviceKey = SharedAccessKey or deviceSasToken = SharedAccessSignature] */ |
AzureIoTClient | 42:448eecc3676e | 713 | const char* s_token = STRING_c_str(tokenString); |
AzureIoTClient | 42:448eecc3676e | 714 | if (strcmp(s_token, HOSTNAME_TOKEN) == 0) |
AzureIoTClient | 42:448eecc3676e | 715 | { |
AzureIoTClient | 42:448eecc3676e | 716 | /* Codes_SRS_IOTHUBCLIENT_LL_12_009: [IoTHubClient_LL_CreateFromConnectionString shall split the value of HostName to Name and Suffix using the first "." as a separator] */ |
AzureIoTClient | 42:448eecc3676e | 717 | STRING_TOKENIZER_HANDLE tokenizer2 = NULL; |
AzureIoTClient | 42:448eecc3676e | 718 | if ((tokenizer2 = STRING_TOKENIZER_create(valueString)) == NULL) |
AzureIoTClient | 42:448eecc3676e | 719 | { |
AzureIoTClient | 42:448eecc3676e | 720 | LogError("Error creating Tokenizer"); |
AzureIoTClient | 42:448eecc3676e | 721 | break; |
AzureIoTClient | 42:448eecc3676e | 722 | } |
AzureIoTClient | 42:448eecc3676e | 723 | else |
AzureIoTClient | 42:448eecc3676e | 724 | { |
AzureIoTClient | 42:448eecc3676e | 725 | /* Codes_SRS_IOTHUBCLIENT_LL_12_015: [If the string split failed, IoTHubClient_LL_CreateFromConnectionString returns NULL ] */ |
AzureIoTClient | 42:448eecc3676e | 726 | if (STRING_TOKENIZER_get_next_token(tokenizer2, hostNameString, ".") != 0) |
AzureIoTClient | 42:448eecc3676e | 727 | { |
AzureIoTClient | 42:448eecc3676e | 728 | LogError("Tokenizer error"); |
AzureIoTClient | 42:448eecc3676e | 729 | STRING_TOKENIZER_destroy(tokenizer2); |
AzureIoTClient | 42:448eecc3676e | 730 | break; |
AzureIoTClient | 42:448eecc3676e | 731 | } |
AzureIoTClient | 42:448eecc3676e | 732 | else |
AzureIoTClient | 42:448eecc3676e | 733 | { |
AzureIoTClient | 42:448eecc3676e | 734 | config->iotHubName = STRING_c_str(hostNameString); |
AzureIoTClient | 42:448eecc3676e | 735 | if (STRING_TOKENIZER_get_next_token(tokenizer2, hostSuffixString, ";") != 0) |
AzureIoTClient | 42:448eecc3676e | 736 | { |
AzureIoTClient | 42:448eecc3676e | 737 | LogError("Tokenizer error"); |
AzureIoTClient | 42:448eecc3676e | 738 | STRING_TOKENIZER_destroy(tokenizer2); |
AzureIoTClient | 42:448eecc3676e | 739 | break; |
AzureIoTClient | 42:448eecc3676e | 740 | } |
AzureIoTClient | 42:448eecc3676e | 741 | else |
AzureIoTClient | 42:448eecc3676e | 742 | { |
AzureIoTClient | 42:448eecc3676e | 743 | config->iotHubSuffix = STRING_c_str(hostSuffixString); |
AzureIoTClient | 42:448eecc3676e | 744 | } |
AzureIoTClient | 42:448eecc3676e | 745 | } |
AzureIoTClient | 42:448eecc3676e | 746 | STRING_TOKENIZER_destroy(tokenizer2); |
AzureIoTClient | 42:448eecc3676e | 747 | } |
AzureIoTClient | 42:448eecc3676e | 748 | } |
AzureIoTClient | 42:448eecc3676e | 749 | else if (strcmp(s_token, DEVICEID_TOKEN) == 0) |
AzureIoTClient | 42:448eecc3676e | 750 | { |
AzureIoTClient | 42:448eecc3676e | 751 | deviceIdString = STRING_clone(valueString); |
AzureIoTClient | 42:448eecc3676e | 752 | if (deviceIdString != NULL) |
AzureIoTClient | 42:448eecc3676e | 753 | { |
AzureIoTClient | 42:448eecc3676e | 754 | config->deviceId = STRING_c_str(deviceIdString); |
AzureIoTClient | 42:448eecc3676e | 755 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 756 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 757 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 758 | LogError("Failure cloning device id string"); |
AzureIoTClient | 53:1e5a1ca1f274 | 759 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 760 | } |
AzureIoTClient | 42:448eecc3676e | 761 | } |
AzureIoTClient | 42:448eecc3676e | 762 | else if (strcmp(s_token, DEVICEKEY_TOKEN) == 0) |
AzureIoTClient | 42:448eecc3676e | 763 | { |
AzureIoTClient | 42:448eecc3676e | 764 | deviceKeyString = STRING_clone(valueString); |
AzureIoTClient | 42:448eecc3676e | 765 | if (deviceKeyString != NULL) |
AzureIoTClient | 42:448eecc3676e | 766 | { |
AzureIoTClient | 42:448eecc3676e | 767 | config->deviceKey = STRING_c_str(deviceKeyString); |
AzureIoTClient | 42:448eecc3676e | 768 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 769 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 770 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 771 | LogError("Failure cloning device key string"); |
AzureIoTClient | 53:1e5a1ca1f274 | 772 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 773 | } |
AzureIoTClient | 42:448eecc3676e | 774 | } |
AzureIoTClient | 42:448eecc3676e | 775 | else if (strcmp(s_token, DEVICESAS_TOKEN) == 0) |
AzureIoTClient | 42:448eecc3676e | 776 | { |
AzureIoTClient | 42:448eecc3676e | 777 | deviceSasTokenString = STRING_clone(valueString); |
AzureIoTClient | 42:448eecc3676e | 778 | if (deviceSasTokenString != NULL) |
AzureIoTClient | 42:448eecc3676e | 779 | { |
AzureIoTClient | 42:448eecc3676e | 780 | config->deviceSasToken = STRING_c_str(deviceSasTokenString); |
AzureIoTClient | 42:448eecc3676e | 781 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 782 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 783 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 784 | LogError("Failure cloning device sasToken string"); |
AzureIoTClient | 53:1e5a1ca1f274 | 785 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 786 | } |
AzureIoTClient | 42:448eecc3676e | 787 | } |
Azure.IoT Build | 45:54c11b1b1407 | 788 | else if (strcmp(s_token, X509_TOKEN) == 0) |
Azure.IoT Build | 45:54c11b1b1407 | 789 | { |
Azure.IoT Build | 45:54c11b1b1407 | 790 | if (strcmp(STRING_c_str(valueString), X509_TOKEN_ONLY_ACCEPTABLE_VALUE) != 0) |
Azure.IoT Build | 45:54c11b1b1407 | 791 | { |
Azure.IoT Build | 45:54c11b1b1407 | 792 | LogError("x509 option has wrong value, the only acceptable one is \"true\""); |
AzureIoTClient | 53:1e5a1ca1f274 | 793 | break; |
Azure.IoT Build | 45:54c11b1b1407 | 794 | } |
Azure.IoT Build | 45:54c11b1b1407 | 795 | else |
Azure.IoT Build | 45:54c11b1b1407 | 796 | { |
Azure.IoT Build | 45:54c11b1b1407 | 797 | isx509found = 1; |
Azure.IoT Build | 45:54c11b1b1407 | 798 | } |
Azure.IoT Build | 45:54c11b1b1407 | 799 | } |
AzureIoTClient | 42:448eecc3676e | 800 | /* Codes_SRS_IOTHUBCLIENT_LL_04_001: [IoTHubClient_LL_CreateFromConnectionString shall verify the existence of key/value pair GatewayHostName. If it does exist it shall pass the value to IoTHubClient_LL_Create API.] */ |
AzureIoTClient | 42:448eecc3676e | 801 | else if (strcmp(s_token, PROTOCOL_GATEWAY_HOST) == 0) |
AzureIoTClient | 42:448eecc3676e | 802 | { |
AzureIoTClient | 42:448eecc3676e | 803 | protocolGateway = STRING_clone(valueString); |
AzureIoTClient | 42:448eecc3676e | 804 | if (protocolGateway != NULL) |
AzureIoTClient | 42:448eecc3676e | 805 | { |
AzureIoTClient | 42:448eecc3676e | 806 | config->protocolGatewayHostName = STRING_c_str(protocolGateway); |
AzureIoTClient | 42:448eecc3676e | 807 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 808 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 809 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 810 | LogError("Failure cloning protocol Gateway Name"); |
AzureIoTClient | 53:1e5a1ca1f274 | 811 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 812 | } |
AzureIoTClient | 42:448eecc3676e | 813 | } |
AzureIoTClient | 42:448eecc3676e | 814 | } |
AzureIoTClient | 42:448eecc3676e | 815 | } |
AzureIoTClient | 42:448eecc3676e | 816 | } |
AzureIoTClient | 42:448eecc3676e | 817 | /* parsing is done - check the result */ |
AzureIoTClient | 42:448eecc3676e | 818 | if (config->iotHubName == NULL) |
AzureIoTClient | 42:448eecc3676e | 819 | { |
AzureIoTClient | 42:448eecc3676e | 820 | LogError("iotHubName is not found"); |
AzureIoTClient | 53:1e5a1ca1f274 | 821 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 822 | } |
AzureIoTClient | 42:448eecc3676e | 823 | else if (config->iotHubSuffix == NULL) |
AzureIoTClient | 42:448eecc3676e | 824 | { |
AzureIoTClient | 42:448eecc3676e | 825 | LogError("iotHubSuffix is not found"); |
AzureIoTClient | 53:1e5a1ca1f274 | 826 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 827 | } |
AzureIoTClient | 42:448eecc3676e | 828 | else if (config->deviceId == NULL) |
AzureIoTClient | 42:448eecc3676e | 829 | { |
AzureIoTClient | 42:448eecc3676e | 830 | LogError("deviceId is not found"); |
AzureIoTClient | 53:1e5a1ca1f274 | 831 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 832 | } |
Azure.IoT Build | 45:54c11b1b1407 | 833 | else if (!( |
Azure.IoT Build | 45:54c11b1b1407 | 834 | ((!isx509found) && (config->deviceSasToken == NULL) ^ (config->deviceKey == NULL)) || |
Azure.IoT Build | 45:54c11b1b1407 | 835 | ((isx509found) && (config->deviceSasToken == NULL) && (config->deviceKey == NULL)) |
Azure.IoT Build | 45:54c11b1b1407 | 836 | )) |
AzureIoTClient | 42:448eecc3676e | 837 | { |
Azure.IoT Build | 45:54c11b1b1407 | 838 | LogError("invalid combination of x509, deviceSasToken and deviceKey"); |
AzureIoTClient | 53:1e5a1ca1f274 | 839 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 840 | } |
AzureIoTClient | 42:448eecc3676e | 841 | else |
AzureIoTClient | 42:448eecc3676e | 842 | { |
AzureIoTClient | 42:448eecc3676e | 843 | /* Codes_SRS_IOTHUBCLIENT_LL_12_011: [IoTHubClient_LL_CreateFromConnectionString shall call into the IoTHubClient_LL_Create API with the current structure and returns with the return value of it] */ |
AzureIoTClient | 75:86205ca63a59 | 844 | result = initialize_iothub_client(config, NULL, false); |
AzureIoTClient | 42:448eecc3676e | 845 | if (result == NULL) |
AzureIoTClient | 42:448eecc3676e | 846 | { |
AzureIoTClient | 42:448eecc3676e | 847 | LogError("IoTHubClient_LL_Create failed"); |
AzureIoTClient | 42:448eecc3676e | 848 | } |
AzureIoTClient | 42:448eecc3676e | 849 | else |
AzureIoTClient | 42:448eecc3676e | 850 | { |
AzureIoTClient | 42:448eecc3676e | 851 | /*return as is*/ |
AzureIoTClient | 42:448eecc3676e | 852 | } |
AzureIoTClient | 42:448eecc3676e | 853 | } |
AzureIoTClient | 42:448eecc3676e | 854 | } |
AzureIoTClient | 42:448eecc3676e | 855 | if (deviceSasTokenString != NULL) |
AzureIoTClient | 42:448eecc3676e | 856 | STRING_delete(deviceSasTokenString); |
AzureIoTClient | 42:448eecc3676e | 857 | if (deviceKeyString != NULL) |
AzureIoTClient | 42:448eecc3676e | 858 | STRING_delete(deviceKeyString); |
AzureIoTClient | 42:448eecc3676e | 859 | if (deviceIdString != NULL) |
AzureIoTClient | 42:448eecc3676e | 860 | STRING_delete(deviceIdString); |
AzureIoTClient | 42:448eecc3676e | 861 | if (hostSuffixString != NULL) |
AzureIoTClient | 42:448eecc3676e | 862 | STRING_delete(hostSuffixString); |
AzureIoTClient | 42:448eecc3676e | 863 | if (hostNameString != NULL) |
AzureIoTClient | 42:448eecc3676e | 864 | STRING_delete(hostNameString); |
AzureIoTClient | 42:448eecc3676e | 865 | if (valueString != NULL) |
AzureIoTClient | 42:448eecc3676e | 866 | STRING_delete(valueString); |
AzureIoTClient | 42:448eecc3676e | 867 | if (tokenString != NULL) |
AzureIoTClient | 42:448eecc3676e | 868 | STRING_delete(tokenString); |
AzureIoTClient | 42:448eecc3676e | 869 | if (connString != NULL) |
AzureIoTClient | 42:448eecc3676e | 870 | STRING_delete(connString); |
AzureIoTClient | 42:448eecc3676e | 871 | if (protocolGateway != NULL) |
AzureIoTClient | 42:448eecc3676e | 872 | STRING_delete(protocolGateway); |
AzureIoTClient | 16:deba40344375 | 873 | |
AzureIoTClient | 42:448eecc3676e | 874 | if (tokenizer1 != NULL) |
AzureIoTClient | 42:448eecc3676e | 875 | STRING_TOKENIZER_destroy(tokenizer1); |
AzureIoTClient | 16:deba40344375 | 876 | |
AzureIoTClient | 42:448eecc3676e | 877 | free(config); |
AzureIoTClient | 42:448eecc3676e | 878 | } |
AzureIoTClient | 42:448eecc3676e | 879 | } |
AzureIoTClient | 42:448eecc3676e | 880 | return result; |
AzureIoTClient | 16:deba40344375 | 881 | } |
AzureIoTClient | 16:deba40344375 | 882 | |
AzureIoTClient | 16:deba40344375 | 883 | IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_Create(const IOTHUB_CLIENT_CONFIG* config) |
AzureIoTClient | 16:deba40344375 | 884 | { |
AzureIoTClient | 42:448eecc3676e | 885 | IOTHUB_CLIENT_LL_HANDLE result; |
AzureIoTClient | 42:448eecc3676e | 886 | /*Codes_SRS_IOTHUBCLIENT_LL_02_001: [IoTHubClient_LL_Create shall return NULL if config parameter is NULL or protocol field is NULL.]*/ |
AzureIoTClient | 42:448eecc3676e | 887 | if( |
AzureIoTClient | 42:448eecc3676e | 888 | (config == NULL) || |
AzureIoTClient | 42:448eecc3676e | 889 | (config->protocol == NULL) |
AzureIoTClient | 42:448eecc3676e | 890 | ) |
AzureIoTClient | 42:448eecc3676e | 891 | { |
AzureIoTClient | 42:448eecc3676e | 892 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 893 | LogError("invalid configuration (NULL detected)"); |
AzureIoTClient | 42:448eecc3676e | 894 | } |
AzureIoTClient | 42:448eecc3676e | 895 | else |
AzureIoTClient | 42:448eecc3676e | 896 | { |
AzureIoTClient | 75:86205ca63a59 | 897 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = initialize_iothub_client(config, NULL, false); |
AzureIoTClient | 42:448eecc3676e | 898 | if (handleData == NULL) |
AzureIoTClient | 42:448eecc3676e | 899 | { |
AzureIoTClient | 62:5a4cdacf5090 | 900 | LogError("initialize iothub client"); |
AzureIoTClient | 42:448eecc3676e | 901 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 902 | } |
AzureIoTClient | 42:448eecc3676e | 903 | else |
AzureIoTClient | 42:448eecc3676e | 904 | { |
AzureIoTClient | 62:5a4cdacf5090 | 905 | result = handleData; |
AzureIoTClient | 42:448eecc3676e | 906 | } |
AzureIoTClient | 42:448eecc3676e | 907 | } |
AzureIoTClient | 16:deba40344375 | 908 | |
AzureIoTClient | 42:448eecc3676e | 909 | return result; |
AzureIoTClient | 16:deba40344375 | 910 | } |
AzureIoTClient | 16:deba40344375 | 911 | |
Azure.IoT Build | 36:67300d5a4c1f | 912 | IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateWithTransport(const IOTHUB_CLIENT_DEVICE_CONFIG * config) |
Azure.IoT Build | 36:67300d5a4c1f | 913 | { |
AzureIoTClient | 42:448eecc3676e | 914 | IOTHUB_CLIENT_LL_HANDLE result; |
AzureIoTClient | 42:448eecc3676e | 915 | /*Codes_SRS_IOTHUBCLIENT_LL_17_001: [IoTHubClient_LL_CreateWithTransport shall return NULL if config parameter is NULL, or protocol field is NULL or transportHandle is NULL.]*/ |
AzureIoTClient | 42:448eecc3676e | 916 | if ( |
AzureIoTClient | 42:448eecc3676e | 917 | (config == NULL) || |
AzureIoTClient | 42:448eecc3676e | 918 | (config->protocol == NULL) || |
Azure.IoT Build | 45:54c11b1b1407 | 919 | (config->transportHandle == NULL) || |
Azure.IoT Build | 45:54c11b1b1407 | 920 | /*Codes_SRS_IOTHUBCLIENT_LL_02_098: [ IoTHubClient_LL_CreateWithTransport shall fail and return NULL if both config->deviceKey AND config->deviceSasToken are NULL. ]*/ |
Azure.IoT Build | 45:54c11b1b1407 | 921 | ((config->deviceKey == NULL) && (config->deviceSasToken == NULL)) |
AzureIoTClient | 42:448eecc3676e | 922 | ) |
AzureIoTClient | 42:448eecc3676e | 923 | { |
AzureIoTClient | 42:448eecc3676e | 924 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 925 | LogError("invalid configuration (NULL detected)"); |
AzureIoTClient | 42:448eecc3676e | 926 | } |
AzureIoTClient | 42:448eecc3676e | 927 | else |
AzureIoTClient | 42:448eecc3676e | 928 | { |
AzureIoTClient | 75:86205ca63a59 | 929 | result = initialize_iothub_client(NULL, config, false); |
AzureIoTClient | 42:448eecc3676e | 930 | } |
AzureIoTClient | 42:448eecc3676e | 931 | return result; |
Azure.IoT Build | 36:67300d5a4c1f | 932 | } |
Azure.IoT Build | 36:67300d5a4c1f | 933 | |
AzureIoTClient | 16:deba40344375 | 934 | void IoTHubClient_LL_Destroy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle) |
AzureIoTClient | 16:deba40344375 | 935 | { |
AzureIoTClient | 42:448eecc3676e | 936 | /*Codes_SRS_IOTHUBCLIENT_LL_02_009: [IoTHubClient_LL_Destroy shall do nothing if parameter iotHubClientHandle is NULL.]*/ |
AzureIoTClient | 42:448eecc3676e | 937 | if (iotHubClientHandle != NULL) |
AzureIoTClient | 42:448eecc3676e | 938 | { |
AzureIoTClient | 42:448eecc3676e | 939 | PDLIST_ENTRY unsend; |
AzureIoTClient | 42:448eecc3676e | 940 | /*Codes_SRS_IOTHUBCLIENT_LL_17_010: [IoTHubClient_LL_Destroy shall call the underlaying layer's _Unregister function] */ |
AzureIoTClient | 42:448eecc3676e | 941 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 42:448eecc3676e | 942 | handleData->IoTHubTransport_Unregister(handleData->deviceHandle); |
AzureIoTClient | 42:448eecc3676e | 943 | if (handleData->isSharedTransport == false) |
AzureIoTClient | 42:448eecc3676e | 944 | { |
AzureIoTClient | 42:448eecc3676e | 945 | /*Codes_SRS_IOTHUBCLIENT_LL_02_010: [If iotHubClientHandle was not created by IoTHubClient_LL_CreateWithTransport, IoTHubClient_LL_Destroy shall call the underlaying layer's _Destroy function.] */ |
AzureIoTClient | 42:448eecc3676e | 946 | handleData->IoTHubTransport_Destroy(handleData->transportHandle); |
AzureIoTClient | 42:448eecc3676e | 947 | } |
AzureIoTClient | 42:448eecc3676e | 948 | /*if any, remove the items currently not send*/ |
AzureIoTClient | 42:448eecc3676e | 949 | while ((unsend = DList_RemoveHeadList(&(handleData->waitingToSend))) != &(handleData->waitingToSend)) |
AzureIoTClient | 42:448eecc3676e | 950 | { |
AzureIoTClient | 42:448eecc3676e | 951 | IOTHUB_MESSAGE_LIST* temp = containingRecord(unsend, IOTHUB_MESSAGE_LIST, entry); |
AzureIoTClient | 42:448eecc3676e | 952 | /*Codes_SRS_IOTHUBCLIENT_LL_02_033: [Otherwise, IoTHubClient_LL_Destroy shall complete all the event message callbacks that are in the waitingToSend list with the result IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY.] */ |
AzureIoTClient | 42:448eecc3676e | 953 | if (temp->callback != NULL) |
AzureIoTClient | 42:448eecc3676e | 954 | { |
AzureIoTClient | 42:448eecc3676e | 955 | temp->callback(IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY, temp->context); |
AzureIoTClient | 42:448eecc3676e | 956 | } |
AzureIoTClient | 42:448eecc3676e | 957 | IoTHubMessage_Destroy(temp->messageHandle); |
AzureIoTClient | 42:448eecc3676e | 958 | free(temp); |
AzureIoTClient | 42:448eecc3676e | 959 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 960 | |
AzureIoTClient | 53:1e5a1ca1f274 | 961 | /* Codes_SRS_IOTHUBCLIENT_LL_07_007: [ IoTHubClient_LL_Destroy shall iterate the device twin queues and destroy any remaining items. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 962 | while ((unsend = DList_RemoveHeadList(&(handleData->iot_msg_queue))) != &(handleData->iot_msg_queue)) |
AzureIoTClient | 53:1e5a1ca1f274 | 963 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 964 | IOTHUB_DEVICE_TWIN* temp = containingRecord(unsend, IOTHUB_DEVICE_TWIN, entry); |
AzureIoTClient | 53:1e5a1ca1f274 | 965 | device_twin_data_destroy(temp); |
AzureIoTClient | 53:1e5a1ca1f274 | 966 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 967 | while ((unsend = DList_RemoveHeadList(&(handleData->iot_ack_queue))) != &(handleData->iot_ack_queue)) |
AzureIoTClient | 53:1e5a1ca1f274 | 968 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 969 | IOTHUB_DEVICE_TWIN* temp = containingRecord(unsend, IOTHUB_DEVICE_TWIN, entry); |
AzureIoTClient | 53:1e5a1ca1f274 | 970 | device_twin_data_destroy(temp); |
AzureIoTClient | 53:1e5a1ca1f274 | 971 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 972 | |
AzureIoTClient | 42:448eecc3676e | 973 | /*Codes_SRS_IOTHUBCLIENT_LL_17_011: [IoTHubClient_LL_Destroy shall free the resources allocated by IoTHubClient (if any).] */ |
AzureIoTClient | 62:5a4cdacf5090 | 974 | IoTHubClient_Auth_Destroy(handleData->authorization_module); |
AzureIoTClient | 42:448eecc3676e | 975 | tickcounter_destroy(handleData->tickCounter); |
AzureIoTClient | 44:33dd78697616 | 976 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 977 | IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle); |
AzureIoTClient | 43:038d8511e817 | 978 | #endif |
AzureIoTClient | 66:a419827cb051 | 979 | STRING_delete(handleData->product_info); |
AzureIoTClient | 42:448eecc3676e | 980 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 981 | } |
AzureIoTClient | 16:deba40344375 | 982 | } |
AzureIoTClient | 16:deba40344375 | 983 | |
Azure.IoT Build | 36:67300d5a4c1f | 984 | /*Codes_SRS_IOTHUBCLIENT_LL_02_044: [ Messages already delivered to IoTHubClient_LL shall not have their timeouts modified by a new call to IoTHubClient_LL_SetOption. ]*/ |
Azure.IoT Build | 36:67300d5a4c1f | 985 | /*returns 0 on success, any other value is error*/ |
Azure.IoT Build | 36:67300d5a4c1f | 986 | static int attach_ms_timesOutAfter(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, IOTHUB_MESSAGE_LIST *newEntry) |
Azure.IoT Build | 36:67300d5a4c1f | 987 | { |
AzureIoTClient | 42:448eecc3676e | 988 | int result; |
AzureIoTClient | 42:448eecc3676e | 989 | /*Codes_SRS_IOTHUBCLIENT_LL_02_043: [ Calling IoTHubClient_LL_SetOption with value set to "0" shall disable the timeout mechanism for all new messages. ]*/ |
AzureIoTClient | 42:448eecc3676e | 990 | if (handleData->currentMessageTimeout == 0) |
AzureIoTClient | 42:448eecc3676e | 991 | { |
AzureIoTClient | 42:448eecc3676e | 992 | newEntry->ms_timesOutAfter = 0; /*do not timeout*/ |
AzureIoTClient | 42:448eecc3676e | 993 | result = 0; |
AzureIoTClient | 42:448eecc3676e | 994 | } |
AzureIoTClient | 42:448eecc3676e | 995 | else |
AzureIoTClient | 42:448eecc3676e | 996 | { |
AzureIoTClient | 78:74a8d3068204 | 997 | /*Codes_SRS_IOTHUBCLIENT_LL_02_039: [ "messageTimeout" - once IoTHubClient_LL_SendEventAsync is called the message shall timeout after value miliseconds. Value is a pointer to a tickcounter_ms_t. ]*/ |
AzureIoTClient | 42:448eecc3676e | 998 | if (tickcounter_get_current_ms(handleData->tickCounter, &newEntry->ms_timesOutAfter) != 0) |
AzureIoTClient | 42:448eecc3676e | 999 | { |
AzureIoTClient | 60:41648c4e7036 | 1000 | result = __FAILURE__; |
AzureIoTClient | 42:448eecc3676e | 1001 | LogError("unable to get the current relative tickcount"); |
AzureIoTClient | 42:448eecc3676e | 1002 | } |
AzureIoTClient | 42:448eecc3676e | 1003 | else |
AzureIoTClient | 42:448eecc3676e | 1004 | { |
AzureIoTClient | 42:448eecc3676e | 1005 | newEntry->ms_timesOutAfter += handleData->currentMessageTimeout; |
AzureIoTClient | 42:448eecc3676e | 1006 | result = 0; |
AzureIoTClient | 42:448eecc3676e | 1007 | } |
AzureIoTClient | 42:448eecc3676e | 1008 | } |
AzureIoTClient | 42:448eecc3676e | 1009 | return result; |
Azure.IoT Build | 36:67300d5a4c1f | 1010 | } |
Azure.IoT Build | 36:67300d5a4c1f | 1011 | |
AzureIoTClient | 16:deba40344375 | 1012 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SendEventAsync(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK eventConfirmationCallback, void* userContextCallback) |
AzureIoTClient | 16:deba40344375 | 1013 | { |
AzureIoTClient | 42:448eecc3676e | 1014 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 42:448eecc3676e | 1015 | /*Codes_SRS_IOTHUBCLIENT_LL_02_011: [IoTHubClient_LL_SendEventAsync shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle or eventMessageHandle is NULL.]*/ |
AzureIoTClient | 42:448eecc3676e | 1016 | if ( |
AzureIoTClient | 42:448eecc3676e | 1017 | (iotHubClientHandle == NULL) || |
AzureIoTClient | 42:448eecc3676e | 1018 | (eventMessageHandle == NULL) || |
AzureIoTClient | 42:448eecc3676e | 1019 | /*Codes_SRS_IOTHUBCLIENT_LL_02_012: [IoTHubClient_LL_SendEventAsync shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter eventConfirmationCallback is NULL and userContextCallback is not NULL.] */ |
AzureIoTClient | 42:448eecc3676e | 1020 | ((eventConfirmationCallback == NULL) && (userContextCallback != NULL)) |
AzureIoTClient | 42:448eecc3676e | 1021 | ) |
AzureIoTClient | 42:448eecc3676e | 1022 | { |
AzureIoTClient | 42:448eecc3676e | 1023 | result = IOTHUB_CLIENT_INVALID_ARG; |
Azure.IoT Build | 45:54c11b1b1407 | 1024 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 1025 | } |
AzureIoTClient | 42:448eecc3676e | 1026 | else |
AzureIoTClient | 42:448eecc3676e | 1027 | { |
AzureIoTClient | 42:448eecc3676e | 1028 | IOTHUB_MESSAGE_LIST *newEntry = (IOTHUB_MESSAGE_LIST*)malloc(sizeof(IOTHUB_MESSAGE_LIST)); |
AzureIoTClient | 42:448eecc3676e | 1029 | if (newEntry == NULL) |
AzureIoTClient | 42:448eecc3676e | 1030 | { |
AzureIoTClient | 42:448eecc3676e | 1031 | result = IOTHUB_CLIENT_ERROR; |
Azure.IoT Build | 45:54c11b1b1407 | 1032 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 1033 | } |
AzureIoTClient | 42:448eecc3676e | 1034 | else |
AzureIoTClient | 42:448eecc3676e | 1035 | { |
AzureIoTClient | 42:448eecc3676e | 1036 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 40:1a94db9139ea | 1037 | |
AzureIoTClient | 42:448eecc3676e | 1038 | if (attach_ms_timesOutAfter(handleData, newEntry) != 0) |
AzureIoTClient | 42:448eecc3676e | 1039 | { |
AzureIoTClient | 42:448eecc3676e | 1040 | result = IOTHUB_CLIENT_ERROR; |
Azure.IoT Build | 45:54c11b1b1407 | 1041 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 1042 | free(newEntry); |
AzureIoTClient | 42:448eecc3676e | 1043 | } |
AzureIoTClient | 42:448eecc3676e | 1044 | else |
AzureIoTClient | 42:448eecc3676e | 1045 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1046 | /*Codes_SRS_IOTHUBCLIENT_LL_02_013: [IoTHubClient_LL_SendEventAsync shall add the DLIST waitingToSend a new record cloning the information from eventMessageHandle, eventConfirmationCallback, userContextCallback.]*/ |
AzureIoTClient | 42:448eecc3676e | 1047 | if ((newEntry->messageHandle = IoTHubMessage_Clone(eventMessageHandle)) == NULL) |
AzureIoTClient | 42:448eecc3676e | 1048 | { |
AzureIoTClient | 42:448eecc3676e | 1049 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 1050 | free(newEntry); |
Azure.IoT Build | 45:54c11b1b1407 | 1051 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 1052 | } |
AzureIoTClient | 77:e4e36df9caee | 1053 | else if (IoTHubClient_Diagnostic_AddIfNecessary(&handleData->diagnostic_setting, newEntry->messageHandle) != 0) |
AzureIoTClient | 77:e4e36df9caee | 1054 | { |
AzureIoTClient | 77:e4e36df9caee | 1055 | /*Codes_SRS_IOTHUBCLIENT_LL_02_014: [If cloning and/or adding the information/diagnostic fails for any reason, IoTHubClient_LL_SendEventAsync shall fail and return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 77:e4e36df9caee | 1056 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 77:e4e36df9caee | 1057 | IoTHubMessage_Destroy(newEntry->messageHandle); |
AzureIoTClient | 77:e4e36df9caee | 1058 | free(newEntry); |
AzureIoTClient | 77:e4e36df9caee | 1059 | LOG_ERROR_RESULT; |
AzureIoTClient | 77:e4e36df9caee | 1060 | } |
AzureIoTClient | 42:448eecc3676e | 1061 | else |
AzureIoTClient | 42:448eecc3676e | 1062 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1063 | /*Codes_SRS_IOTHUBCLIENT_LL_02_013: [IoTHubClient_LL_SendEventAsync shall add the DLIST waitingToSend a new record cloning the information from eventMessageHandle, eventConfirmationCallback, userContextCallback.]*/ |
AzureIoTClient | 42:448eecc3676e | 1064 | newEntry->callback = eventConfirmationCallback; |
AzureIoTClient | 42:448eecc3676e | 1065 | newEntry->context = userContextCallback; |
AzureIoTClient | 46:6a69294b6119 | 1066 | DList_InsertTailList(&(iotHubClientHandle->waitingToSend), &(newEntry->entry)); |
AzureIoTClient | 42:448eecc3676e | 1067 | /*Codes_SRS_IOTHUBCLIENT_LL_02_015: [Otherwise IoTHubClient_LL_SendEventAsync shall succeed and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 42:448eecc3676e | 1068 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 42:448eecc3676e | 1069 | } |
AzureIoTClient | 42:448eecc3676e | 1070 | } |
AzureIoTClient | 42:448eecc3676e | 1071 | } |
AzureIoTClient | 42:448eecc3676e | 1072 | } |
AzureIoTClient | 42:448eecc3676e | 1073 | return result; |
AzureIoTClient | 16:deba40344375 | 1074 | } |
AzureIoTClient | 16:deba40344375 | 1075 | |
AzureIoTClient | 16:deba40344375 | 1076 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetMessageCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback) |
AzureIoTClient | 16:deba40344375 | 1077 | { |
AzureIoTClient | 42:448eecc3676e | 1078 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 42:448eecc3676e | 1079 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 42:448eecc3676e | 1080 | { |
AzureIoTClient | 61:8b85a4e797cf | 1081 | /*Codes_SRS_IOTHUBCLIENT_LL_02_016: [IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.] */ |
AzureIoTClient | 61:8b85a4e797cf | 1082 | LogError("Invalid argument - iotHubClientHandle is NULL"); |
AzureIoTClient | 42:448eecc3676e | 1083 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 42:448eecc3676e | 1084 | } |
AzureIoTClient | 42:448eecc3676e | 1085 | else |
AzureIoTClient | 42:448eecc3676e | 1086 | { |
AzureIoTClient | 42:448eecc3676e | 1087 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 42:448eecc3676e | 1088 | if (messageCallback == NULL) |
AzureIoTClient | 42:448eecc3676e | 1089 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1090 | if (handleData->messageCallback.type == CALLBACK_TYPE_NONE) |
AzureIoTClient | 61:8b85a4e797cf | 1091 | { |
AzureIoTClient | 61:8b85a4e797cf | 1092 | /*Codes_SRS_IOTHUBCLIENT_LL_10_010: [If parameter messageCallback is NULL and the _SetMessageCallback had not been called to subscribe for messages, then IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 61:8b85a4e797cf | 1093 | LogError("not currently set to accept or process incoming messages."); |
AzureIoTClient | 61:8b85a4e797cf | 1094 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 61:8b85a4e797cf | 1095 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1096 | else if (handleData->messageCallback.type == CALLBACK_TYPE_ASYNC) |
AzureIoTClient | 61:8b85a4e797cf | 1097 | { |
AzureIoTClient | 61:8b85a4e797cf | 1098 | /*Codes_SRS_IOTHUBCLIENT_LL_10_010: [If parameter messageCallback is NULL and the _SetMessageCallback had not been called to subscribe for messages, then IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1099 | LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetMessageCallback_Ex function."); |
AzureIoTClient | 61:8b85a4e797cf | 1100 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 61:8b85a4e797cf | 1101 | } |
AzureIoTClient | 61:8b85a4e797cf | 1102 | else |
AzureIoTClient | 61:8b85a4e797cf | 1103 | { |
AzureIoTClient | 61:8b85a4e797cf | 1104 | /*Codes_SRS_IOTHUBCLIENT_LL_02_019: [If parameter messageCallback is NULL then IoTHubClient_LL_SetMessageCallback shall call the underlying layer's _Unsubscribe function and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 61:8b85a4e797cf | 1105 | handleData->IoTHubTransport_Unsubscribe(handleData->deviceHandle); |
AzureIoTClient | 62:5a4cdacf5090 | 1106 | handleData->messageCallback.type = CALLBACK_TYPE_NONE; |
AzureIoTClient | 61:8b85a4e797cf | 1107 | handleData->messageCallback.callbackSync = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 1108 | handleData->messageCallback.callbackAsync = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1109 | handleData->messageCallback.userContextCallback = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 1110 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 61:8b85a4e797cf | 1111 | } |
AzureIoTClient | 42:448eecc3676e | 1112 | } |
AzureIoTClient | 42:448eecc3676e | 1113 | else |
AzureIoTClient | 42:448eecc3676e | 1114 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1115 | if (handleData->messageCallback.type == CALLBACK_TYPE_ASYNC) |
AzureIoTClient | 42:448eecc3676e | 1116 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1117 | /* Codes_SRS_IOTHUBCLIENT_LL_10_011: [If parameter messageCallback is non-NULL and the _SetMessageCallback_Ex had been used to susbscribe for messages, then IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1118 | LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetMessageCallback_Ex function before subscribing with MessageCallback."); |
AzureIoTClient | 61:8b85a4e797cf | 1119 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 1120 | } |
AzureIoTClient | 42:448eecc3676e | 1121 | else |
AzureIoTClient | 42:448eecc3676e | 1122 | { |
AzureIoTClient | 61:8b85a4e797cf | 1123 | if (handleData->IoTHubTransport_Subscribe(handleData->deviceHandle) == 0) |
AzureIoTClient | 61:8b85a4e797cf | 1124 | { |
AzureIoTClient | 61:8b85a4e797cf | 1125 | /*Codes_SRS_IOTHUBCLIENT_LL_02_017: [If parameter messageCallback is non-NULL then IoTHubClient_LL_SetMessageCallback shall call the underlying layer's _Subscribe function.]*/ |
AzureIoTClient | 62:5a4cdacf5090 | 1126 | handleData->messageCallback.type = CALLBACK_TYPE_SYNC; |
AzureIoTClient | 61:8b85a4e797cf | 1127 | handleData->messageCallback.callbackSync = messageCallback; |
AzureIoTClient | 62:5a4cdacf5090 | 1128 | handleData->messageCallback.userContextCallback = userContextCallback; |
AzureIoTClient | 61:8b85a4e797cf | 1129 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 61:8b85a4e797cf | 1130 | } |
AzureIoTClient | 61:8b85a4e797cf | 1131 | else |
AzureIoTClient | 61:8b85a4e797cf | 1132 | { |
AzureIoTClient | 61:8b85a4e797cf | 1133 | /*Codes_SRS_IOTHUBCLIENT_LL_02_018: [If the underlying layer's _Subscribe function fails, then IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_ERROR. Otherwise IoTHubClient_LL_SetMessageCallback shall succeed and return IOTHUB_CLIENT_OK.]*/ |
AzureIoTClient | 62:5a4cdacf5090 | 1134 | LogError("IoTHubTransport_Subscribe failed"); |
AzureIoTClient | 62:5a4cdacf5090 | 1135 | handleData->messageCallback.type = CALLBACK_TYPE_NONE; |
AzureIoTClient | 61:8b85a4e797cf | 1136 | handleData->messageCallback.callbackSync = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 1137 | handleData->messageCallback.callbackAsync = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1138 | handleData->messageCallback.userContextCallback = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 1139 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 61:8b85a4e797cf | 1140 | } |
AzureIoTClient | 42:448eecc3676e | 1141 | } |
AzureIoTClient | 42:448eecc3676e | 1142 | } |
AzureIoTClient | 42:448eecc3676e | 1143 | } |
AzureIoTClient | 61:8b85a4e797cf | 1144 | return result; |
AzureIoTClient | 61:8b85a4e797cf | 1145 | } |
AzureIoTClient | 40:1a94db9139ea | 1146 | |
AzureIoTClient | 62:5a4cdacf5090 | 1147 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetMessageCallback_Ex(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC_EX messageCallback, void* userContextCallback) |
AzureIoTClient | 61:8b85a4e797cf | 1148 | { |
AzureIoTClient | 61:8b85a4e797cf | 1149 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 61:8b85a4e797cf | 1150 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 1151 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1152 | /*Codes_SRS_IOTHUBCLIENT_LL_10_021: [IoTHubClient_LL_SetMessageCallback_Ex shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.]*/ |
AzureIoTClient | 61:8b85a4e797cf | 1153 | LogError("Invalid argument - iotHubClientHandle is NULL"); |
AzureIoTClient | 61:8b85a4e797cf | 1154 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 61:8b85a4e797cf | 1155 | } |
AzureIoTClient | 61:8b85a4e797cf | 1156 | else |
AzureIoTClient | 61:8b85a4e797cf | 1157 | { |
AzureIoTClient | 61:8b85a4e797cf | 1158 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 61:8b85a4e797cf | 1159 | if (messageCallback == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 1160 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1161 | if (handleData->messageCallback.type == CALLBACK_TYPE_NONE) |
AzureIoTClient | 61:8b85a4e797cf | 1162 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1163 | /*Codes_SRS_IOTHUBCLIENT_LL_10_018: [If parameter messageCallback is NULL and IoTHubClient_LL_SetMessageCallback_Ex had not been used to subscribe for messages, then IoTHubClient_LL_SetMessageCallback_Ex shall fail and return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 61:8b85a4e797cf | 1164 | LogError("not currently set to accept or process incoming messages."); |
AzureIoTClient | 61:8b85a4e797cf | 1165 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 61:8b85a4e797cf | 1166 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1167 | else if (handleData->messageCallback.type == CALLBACK_TYPE_SYNC) |
AzureIoTClient | 61:8b85a4e797cf | 1168 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1169 | /*Codes_SRS_IOTHUBCLIENT_LL_10_019: [If parameter messageCallback is NULL and IoTHubClient_LL_SetMessageCallback had been used to subscribe for messages, then IoTHubClient_LL_SetMessageCallback_Ex shall fail and return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 61:8b85a4e797cf | 1170 | LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetMessageCallback function."); |
AzureIoTClient | 61:8b85a4e797cf | 1171 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 61:8b85a4e797cf | 1172 | } |
AzureIoTClient | 61:8b85a4e797cf | 1173 | else |
AzureIoTClient | 61:8b85a4e797cf | 1174 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1175 | /*Codes_SRS_IOTHUBCLIENT_LL_10_023: [If parameter messageCallback is NULL then IoTHubClient_LL_SetMessageCallback_Ex shall call the underlying layer's _Unsubscribe function and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 61:8b85a4e797cf | 1176 | handleData->IoTHubTransport_Unsubscribe(handleData->deviceHandle); |
AzureIoTClient | 62:5a4cdacf5090 | 1177 | handleData->messageCallback.type = CALLBACK_TYPE_NONE; |
AzureIoTClient | 61:8b85a4e797cf | 1178 | handleData->messageCallback.callbackSync = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 1179 | handleData->messageCallback.callbackAsync = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1180 | handleData->messageCallback.userContextCallback = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 1181 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 61:8b85a4e797cf | 1182 | } |
AzureIoTClient | 61:8b85a4e797cf | 1183 | } |
AzureIoTClient | 61:8b85a4e797cf | 1184 | else |
AzureIoTClient | 61:8b85a4e797cf | 1185 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1186 | if (handleData->messageCallback.type == CALLBACK_TYPE_SYNC) |
AzureIoTClient | 61:8b85a4e797cf | 1187 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1188 | /*Codes_SRS_IOTHUBCLIENT_LL_10_020: [If parameter messageCallback is non-NULL, and IoTHubClient_LL_SetMessageCallback had been used to subscribe for messages, then IoTHubClient_LL_SetMessageCallback_Ex shall fail and return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 61:8b85a4e797cf | 1189 | LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_MessageCallbackEx function before subscribing with MessageCallback."); |
AzureIoTClient | 61:8b85a4e797cf | 1190 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 61:8b85a4e797cf | 1191 | } |
AzureIoTClient | 61:8b85a4e797cf | 1192 | else |
AzureIoTClient | 61:8b85a4e797cf | 1193 | { |
AzureIoTClient | 61:8b85a4e797cf | 1194 | if (handleData->IoTHubTransport_Subscribe(handleData->deviceHandle) == 0) |
AzureIoTClient | 61:8b85a4e797cf | 1195 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1196 | /*Codes_SRS_IOTHUBCLIENT_LL_10_024: [If parameter messageCallback is non-NULL then IoTHubClient_LL_SetMessageCallback_Ex shall call the underlying layer's _Subscribe function.]*/ |
AzureIoTClient | 62:5a4cdacf5090 | 1197 | handleData->messageCallback.type = CALLBACK_TYPE_ASYNC; |
AzureIoTClient | 61:8b85a4e797cf | 1198 | handleData->messageCallback.callbackAsync = messageCallback; |
AzureIoTClient | 62:5a4cdacf5090 | 1199 | handleData->messageCallback.userContextCallback = userContextCallback; |
AzureIoTClient | 61:8b85a4e797cf | 1200 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 61:8b85a4e797cf | 1201 | } |
AzureIoTClient | 61:8b85a4e797cf | 1202 | else |
AzureIoTClient | 61:8b85a4e797cf | 1203 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1204 | /*Codes_SRS_IOTHUBCLIENT_LL_10_025: [If the underlying layer's _Subscribe function fails, then IoTHubClient_LL_SetMessageCallback_Ex shall fail and return IOTHUB_CLIENT_ERROR. Otherwise IoTHubClient_LL_SetMessageCallback_Ex shall succeed and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1205 | LogError("IoTHubTransport_Subscribe failed"); |
AzureIoTClient | 62:5a4cdacf5090 | 1206 | handleData->messageCallback.type = CALLBACK_TYPE_NONE; |
AzureIoTClient | 61:8b85a4e797cf | 1207 | handleData->messageCallback.callbackSync = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 1208 | handleData->messageCallback.callbackAsync = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1209 | handleData->messageCallback.userContextCallback = NULL; |
AzureIoTClient | 61:8b85a4e797cf | 1210 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 61:8b85a4e797cf | 1211 | } |
AzureIoTClient | 61:8b85a4e797cf | 1212 | } |
AzureIoTClient | 61:8b85a4e797cf | 1213 | } |
AzureIoTClient | 61:8b85a4e797cf | 1214 | } |
AzureIoTClient | 61:8b85a4e797cf | 1215 | return result; |
AzureIoTClient | 61:8b85a4e797cf | 1216 | } |
AzureIoTClient | 61:8b85a4e797cf | 1217 | |
AzureIoTClient | 61:8b85a4e797cf | 1218 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SendMessageDisposition(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, MESSAGE_CALLBACK_INFO* message_data, IOTHUBMESSAGE_DISPOSITION_RESULT disposition) |
AzureIoTClient | 61:8b85a4e797cf | 1219 | { |
AzureIoTClient | 61:8b85a4e797cf | 1220 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 61:8b85a4e797cf | 1221 | if ((iotHubClientHandle == NULL) || (message_data == NULL)) |
AzureIoTClient | 61:8b85a4e797cf | 1222 | { |
AzureIoTClient | 61:8b85a4e797cf | 1223 | /*Codes_SRS_IOTHUBCLIENT_LL_10_026: [IoTHubClient_LL_SendMessageDisposition shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.]*/ |
AzureIoTClient | 61:8b85a4e797cf | 1224 | LogError("Invalid argument handle=%p, message=%p", iotHubClientHandle, message_data); |
AzureIoTClient | 61:8b85a4e797cf | 1225 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 61:8b85a4e797cf | 1226 | } |
AzureIoTClient | 61:8b85a4e797cf | 1227 | else |
AzureIoTClient | 61:8b85a4e797cf | 1228 | { |
AzureIoTClient | 61:8b85a4e797cf | 1229 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 61:8b85a4e797cf | 1230 | /*Codes_SRS_IOTHUBCLIENT_LL_10_027: [IoTHubClient_LL_SendMessageDisposition shall return the result from calling the underlying layer's _Send_Message_Disposition.]*/ |
AzureIoTClient | 61:8b85a4e797cf | 1231 | result = handleData->IoTHubTransport_SendMessageDisposition(message_data, disposition); |
AzureIoTClient | 61:8b85a4e797cf | 1232 | } |
AzureIoTClient | 42:448eecc3676e | 1233 | return result; |
AzureIoTClient | 16:deba40344375 | 1234 | } |
AzureIoTClient | 16:deba40344375 | 1235 | |
Azure.IoT Build | 36:67300d5a4c1f | 1236 | static void DoTimeouts(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData) |
Azure.IoT Build | 36:67300d5a4c1f | 1237 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1238 | tickcounter_ms_t nowTick; |
AzureIoTClient | 42:448eecc3676e | 1239 | if (tickcounter_get_current_ms(handleData->tickCounter, &nowTick) != 0) |
AzureIoTClient | 42:448eecc3676e | 1240 | { |
AzureIoTClient | 42:448eecc3676e | 1241 | LogError("unable to get the current ms, timeouts will not be processed"); |
AzureIoTClient | 42:448eecc3676e | 1242 | } |
AzureIoTClient | 42:448eecc3676e | 1243 | else |
AzureIoTClient | 42:448eecc3676e | 1244 | { |
AzureIoTClient | 42:448eecc3676e | 1245 | DLIST_ENTRY* currentItemInWaitingToSend = handleData->waitingToSend.Flink; |
AzureIoTClient | 42:448eecc3676e | 1246 | while (currentItemInWaitingToSend != &(handleData->waitingToSend)) /*while we are not at the end of the list*/ |
AzureIoTClient | 42:448eecc3676e | 1247 | { |
AzureIoTClient | 42:448eecc3676e | 1248 | IOTHUB_MESSAGE_LIST* fullEntry = containingRecord(currentItemInWaitingToSend, IOTHUB_MESSAGE_LIST, entry); |
AzureIoTClient | 42:448eecc3676e | 1249 | /*Codes_SRS_IOTHUBCLIENT_LL_02_041: [ If more than value miliseconds have passed since the call to IoTHubClient_LL_SendEventAsync then the message callback shall be called with a status code of IOTHUB_CLIENT_CONFIRMATION_TIMEOUT. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1250 | if ((fullEntry->ms_timesOutAfter != 0) && (fullEntry->ms_timesOutAfter < nowTick)) |
AzureIoTClient | 42:448eecc3676e | 1251 | { |
AzureIoTClient | 42:448eecc3676e | 1252 | PDLIST_ENTRY theNext = currentItemInWaitingToSend->Flink; /*need to save the next item, because the below operations are destructive*/ |
AzureIoTClient | 42:448eecc3676e | 1253 | DList_RemoveEntryList(currentItemInWaitingToSend); |
AzureIoTClient | 42:448eecc3676e | 1254 | if (fullEntry->callback != NULL) |
AzureIoTClient | 42:448eecc3676e | 1255 | { |
AzureIoTClient | 42:448eecc3676e | 1256 | fullEntry->callback(IOTHUB_CLIENT_CONFIRMATION_MESSAGE_TIMEOUT, fullEntry->context); |
AzureIoTClient | 42:448eecc3676e | 1257 | } |
AzureIoTClient | 42:448eecc3676e | 1258 | IoTHubMessage_Destroy(fullEntry->messageHandle); /*because it has been cloned*/ |
AzureIoTClient | 42:448eecc3676e | 1259 | free(fullEntry); |
AzureIoTClient | 42:448eecc3676e | 1260 | currentItemInWaitingToSend = theNext; |
AzureIoTClient | 42:448eecc3676e | 1261 | } |
AzureIoTClient | 42:448eecc3676e | 1262 | else |
AzureIoTClient | 42:448eecc3676e | 1263 | { |
AzureIoTClient | 42:448eecc3676e | 1264 | currentItemInWaitingToSend = currentItemInWaitingToSend->Flink; |
AzureIoTClient | 42:448eecc3676e | 1265 | } |
AzureIoTClient | 42:448eecc3676e | 1266 | } |
AzureIoTClient | 42:448eecc3676e | 1267 | } |
Azure.IoT Build | 36:67300d5a4c1f | 1268 | } |
Azure.IoT Build | 36:67300d5a4c1f | 1269 | |
AzureIoTClient | 16:deba40344375 | 1270 | void IoTHubClient_LL_DoWork(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle) |
AzureIoTClient | 16:deba40344375 | 1271 | { |
AzureIoTClient | 42:448eecc3676e | 1272 | /*Codes_SRS_IOTHUBCLIENT_LL_02_020: [If parameter iotHubClientHandle is NULL then IoTHubClient_LL_DoWork shall not perform any action.] */ |
AzureIoTClient | 42:448eecc3676e | 1273 | if (iotHubClientHandle != NULL) |
AzureIoTClient | 42:448eecc3676e | 1274 | { |
AzureIoTClient | 42:448eecc3676e | 1275 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 42:448eecc3676e | 1276 | DoTimeouts(handleData); |
AzureIoTClient | 42:448eecc3676e | 1277 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1278 | /*Codes_SRS_IOTHUBCLIENT_LL_07_008: [ IoTHubClient_LL_DoWork shall iterate the message queue and execute the underlying transports IoTHubTransport_ProcessItem function for each item. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1279 | DLIST_ENTRY* client_item = handleData->iot_msg_queue.Flink; |
AzureIoTClient | 53:1e5a1ca1f274 | 1280 | while (client_item != &(handleData->iot_msg_queue)) /*while we are not at the end of the list*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1281 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1282 | PDLIST_ENTRY next_item = client_item->Flink; |
AzureIoTClient | 53:1e5a1ca1f274 | 1283 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1284 | IOTHUB_DEVICE_TWIN* queue_data = containingRecord(client_item, IOTHUB_DEVICE_TWIN, entry); |
AzureIoTClient | 53:1e5a1ca1f274 | 1285 | IOTHUB_IDENTITY_INFO identity_info; |
AzureIoTClient | 53:1e5a1ca1f274 | 1286 | identity_info.device_twin = queue_data; |
AzureIoTClient | 53:1e5a1ca1f274 | 1287 | IOTHUB_PROCESS_ITEM_RESULT process_results = handleData->IoTHubTransport_ProcessItem(handleData->transportHandle, IOTHUB_TYPE_DEVICE_TWIN, &identity_info); |
AzureIoTClient | 53:1e5a1ca1f274 | 1288 | if (process_results == IOTHUB_PROCESS_CONTINUE || process_results == IOTHUB_PROCESS_NOT_CONNECTED) |
AzureIoTClient | 53:1e5a1ca1f274 | 1289 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1290 | /*Codes_SRS_IOTHUBCLIENT_LL_07_010: [ If 'IoTHubTransport_ProcessItem' returns IOTHUB_PROCESS_CONTINUE or IOTHUB_PROCESS_NOT_CONNECTED IoTHubClient_LL_DoWork shall continue on to call the underlaying layer's _DoWork function. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1291 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 1292 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1293 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1294 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1295 | DList_RemoveEntryList(client_item); |
AzureIoTClient | 53:1e5a1ca1f274 | 1296 | if (process_results == IOTHUB_PROCESS_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 1297 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1298 | /*Codes_SRS_IOTHUBCLIENT_LL_07_011: [ If 'IoTHubTransport_ProcessItem' returns IOTHUB_PROCESS_OK IoTHubClient_LL_DoWork shall add the IOTHUB_DEVICE_TWIN to the ack queue. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1299 | DList_InsertTailList(&(iotHubClientHandle->iot_ack_queue), &(queue_data->entry)); |
AzureIoTClient | 53:1e5a1ca1f274 | 1300 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1301 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1302 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1303 | /*Codes_SRS_IOTHUBCLIENT_LL_07_012: [ If 'IoTHubTransport_ProcessItem' returns any other value IoTHubClient_LL_DoWork shall destroy the IOTHUB_DEVICE_TWIN item. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1304 | LogError("Failure queue processing item"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1305 | device_twin_data_destroy(queue_data); |
AzureIoTClient | 53:1e5a1ca1f274 | 1306 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1307 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1308 | // Move along to the next item |
AzureIoTClient | 53:1e5a1ca1f274 | 1309 | client_item = next_item; |
AzureIoTClient | 53:1e5a1ca1f274 | 1310 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1311 | |
AzureIoTClient | 42:448eecc3676e | 1312 | /*Codes_SRS_IOTHUBCLIENT_LL_02_021: [Otherwise, IoTHubClient_LL_DoWork shall invoke the underlaying layer's _DoWork function.]*/ |
AzureIoTClient | 42:448eecc3676e | 1313 | handleData->IoTHubTransport_DoWork(handleData->transportHandle, iotHubClientHandle); |
AzureIoTClient | 42:448eecc3676e | 1314 | } |
AzureIoTClient | 16:deba40344375 | 1315 | } |
AzureIoTClient | 16:deba40344375 | 1316 | |
AzureIoTClient | 16:deba40344375 | 1317 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetSendStatus(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus) |
AzureIoTClient | 16:deba40344375 | 1318 | { |
AzureIoTClient | 42:448eecc3676e | 1319 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 16:deba40344375 | 1320 | |
AzureIoTClient | 42:448eecc3676e | 1321 | /* Codes_SRS_IOTHUBCLIENT_09_007: [IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL parameter] */ |
AzureIoTClient | 42:448eecc3676e | 1322 | if (iotHubClientHandle == NULL || iotHubClientStatus == NULL) |
AzureIoTClient | 42:448eecc3676e | 1323 | { |
AzureIoTClient | 42:448eecc3676e | 1324 | result = IOTHUB_CLIENT_INVALID_ARG; |
Azure.IoT Build | 45:54c11b1b1407 | 1325 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 1326 | } |
AzureIoTClient | 42:448eecc3676e | 1327 | else |
AzureIoTClient | 42:448eecc3676e | 1328 | { |
AzureIoTClient | 42:448eecc3676e | 1329 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 16:deba40344375 | 1330 | |
AzureIoTClient | 42:448eecc3676e | 1331 | /* Codes_SRS_IOTHUBCLIENT_09_008: [IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_OK and status IOTHUB_CLIENT_SEND_STATUS_IDLE if there is currently no items to be sent] */ |
AzureIoTClient | 42:448eecc3676e | 1332 | /* Codes_SRS_IOTHUBCLIENT_09_009: [IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_OK and status IOTHUB_CLIENT_SEND_STATUS_BUSY if there are currently items to be sent] */ |
AzureIoTClient | 42:448eecc3676e | 1333 | result = handleData->IoTHubTransport_GetSendStatus(handleData->deviceHandle, iotHubClientStatus); |
AzureIoTClient | 42:448eecc3676e | 1334 | } |
AzureIoTClient | 16:deba40344375 | 1335 | |
AzureIoTClient | 42:448eecc3676e | 1336 | return result; |
AzureIoTClient | 16:deba40344375 | 1337 | } |
AzureIoTClient | 16:deba40344375 | 1338 | |
Azure.IoT Build | 45:54c11b1b1407 | 1339 | void IoTHubClient_LL_SendComplete(IOTHUB_CLIENT_LL_HANDLE handle, PDLIST_ENTRY completed, IOTHUB_CLIENT_CONFIRMATION_RESULT result) |
AzureIoTClient | 16:deba40344375 | 1340 | { |
AzureIoTClient | 42:448eecc3676e | 1341 | /*Codes_SRS_IOTHUBCLIENT_LL_02_022: [If parameter completed is NULL, or parameter handle is NULL then IoTHubClient_LL_SendBatch shall return.]*/ |
AzureIoTClient | 42:448eecc3676e | 1342 | if ( |
AzureIoTClient | 42:448eecc3676e | 1343 | (handle == NULL) || |
AzureIoTClient | 42:448eecc3676e | 1344 | (completed == NULL) |
AzureIoTClient | 42:448eecc3676e | 1345 | ) |
AzureIoTClient | 42:448eecc3676e | 1346 | { |
AzureIoTClient | 42:448eecc3676e | 1347 | /*"shall return"*/ |
AzureIoTClient | 42:448eecc3676e | 1348 | LogError("invalid arg"); |
AzureIoTClient | 42:448eecc3676e | 1349 | } |
AzureIoTClient | 42:448eecc3676e | 1350 | else |
AzureIoTClient | 42:448eecc3676e | 1351 | { |
Azure.IoT Build | 45:54c11b1b1407 | 1352 | /*Codes_SRS_IOTHUBCLIENT_LL_02_027: [If parameter result is IOTHUB_CLIENT_CONFIRMATION_ERROR then IoTHubClient_LL_SendComplete shall call all the non-NULL callbacks with the result parameter set to IOTHUB_CLIENT_CONFIRMATION_ERROR and the context set to the context passed originally in the SendEventAsync call.] */ |
Azure.IoT Build | 45:54c11b1b1407 | 1353 | /*Codes_SRS_IOTHUBCLIENT_LL_02_025: [If parameter result is IOTHUB_CLIENT_CONFIRMATION_OK then IoTHubClient_LL_SendComplete shall call all the non-NULL callbacks with the result parameter set to IOTHUB_CLIENT_CONFIRMATION_OK and the context set to the context passed originally in the SendEventAsync call.]*/ |
AzureIoTClient | 42:448eecc3676e | 1354 | PDLIST_ENTRY oldest; |
AzureIoTClient | 42:448eecc3676e | 1355 | while ((oldest = DList_RemoveHeadList(completed)) != completed) |
AzureIoTClient | 42:448eecc3676e | 1356 | { |
AzureIoTClient | 42:448eecc3676e | 1357 | IOTHUB_MESSAGE_LIST* messageList = (IOTHUB_MESSAGE_LIST*)containingRecord(oldest, IOTHUB_MESSAGE_LIST, entry); |
AzureIoTClient | 42:448eecc3676e | 1358 | /*Codes_SRS_IOTHUBCLIENT_LL_02_026: [If any callback is NULL then there shall not be a callback call.]*/ |
AzureIoTClient | 42:448eecc3676e | 1359 | if (messageList->callback != NULL) |
AzureIoTClient | 42:448eecc3676e | 1360 | { |
Azure.IoT Build | 45:54c11b1b1407 | 1361 | messageList->callback(result, messageList->context); |
AzureIoTClient | 42:448eecc3676e | 1362 | } |
AzureIoTClient | 42:448eecc3676e | 1363 | IoTHubMessage_Destroy(messageList->messageHandle); |
AzureIoTClient | 42:448eecc3676e | 1364 | free(messageList); |
AzureIoTClient | 42:448eecc3676e | 1365 | } |
AzureIoTClient | 42:448eecc3676e | 1366 | } |
AzureIoTClient | 16:deba40344375 | 1367 | } |
AzureIoTClient | 16:deba40344375 | 1368 | |
AzureIoTClient | 55:59b527ab3452 | 1369 | int IoTHubClient_LL_DeviceMethodComplete(IOTHUB_CLIENT_LL_HANDLE handle, const char* method_name, const unsigned char* payLoad, size_t size, METHOD_HANDLE response_id) |
AzureIoTClient | 53:1e5a1ca1f274 | 1370 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1371 | int result; |
AzureIoTClient | 55:59b527ab3452 | 1372 | if (handle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1373 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1374 | /* Codes_SRS_IOTHUBCLIENT_LL_07_017: [ If handle or response is NULL then IoTHubClient_LL_DeviceMethodComplete shall return 500. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1375 | LogError("Invalid argument handle=%p", handle); |
AzureIoTClient | 60:41648c4e7036 | 1376 | result = __FAILURE__; |
AzureIoTClient | 53:1e5a1ca1f274 | 1377 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1378 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1379 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1380 | /* Codes_SRS_IOTHUBCLIENT_LL_07_018: [ If deviceMethodCallback is not NULL IoTHubClient_LL_DeviceMethodComplete shall execute deviceMethodCallback and return the status. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1381 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle; |
AzureIoTClient | 62:5a4cdacf5090 | 1382 | switch (handleData->methodCallback.type) |
AzureIoTClient | 53:1e5a1ca1f274 | 1383 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1384 | case CALLBACK_TYPE_SYNC: |
AzureIoTClient | 53:1e5a1ca1f274 | 1385 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1386 | unsigned char* payload_resp = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1387 | size_t response_size = 0; |
AzureIoTClient | 62:5a4cdacf5090 | 1388 | result = handleData->methodCallback.callbackSync(method_name, payLoad, size, &payload_resp, &response_size, handleData->methodCallback.userContextCallback); |
AzureIoTClient | 62:5a4cdacf5090 | 1389 | /* Codes_SRS_IOTHUBCLIENT_LL_07_020: [ deviceMethodCallback shall build the BUFFER_HANDLE with the response payload from the IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC callback. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1390 | if (payload_resp != NULL && response_size > 0) |
AzureIoTClient | 62:5a4cdacf5090 | 1391 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1392 | result = handleData->IoTHubTransport_DeviceMethod_Response(handleData->deviceHandle, response_id, payload_resp, response_size, result); |
AzureIoTClient | 62:5a4cdacf5090 | 1393 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1394 | else |
AzureIoTClient | 62:5a4cdacf5090 | 1395 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1396 | result = __FAILURE__; |
AzureIoTClient | 62:5a4cdacf5090 | 1397 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1398 | if (payload_resp != NULL) |
AzureIoTClient | 62:5a4cdacf5090 | 1399 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1400 | free(payload_resp); |
AzureIoTClient | 62:5a4cdacf5090 | 1401 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1402 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 1403 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1404 | case CALLBACK_TYPE_ASYNC: |
AzureIoTClient | 62:5a4cdacf5090 | 1405 | result = handleData->methodCallback.callbackAsync(method_name, payLoad, size, response_id, handleData->methodCallback.userContextCallback); |
AzureIoTClient | 62:5a4cdacf5090 | 1406 | break; |
AzureIoTClient | 62:5a4cdacf5090 | 1407 | default: |
AzureIoTClient | 62:5a4cdacf5090 | 1408 | /* Codes_SRS_IOTHUBCLIENT_LL_07_019: [ If deviceMethodCallback is NULL IoTHubClient_LL_DeviceMethodComplete shall return 404. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1409 | result = 0; |
AzureIoTClient | 62:5a4cdacf5090 | 1410 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 1411 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1412 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1413 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1414 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1415 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1416 | void IoTHubClient_LL_RetrievePropertyComplete(IOTHUB_CLIENT_LL_HANDLE handle, DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char* payLoad, size_t size) |
AzureIoTClient | 53:1e5a1ca1f274 | 1417 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1418 | if (handle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1419 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1420 | /* Codes_SRS_IOTHUBCLIENT_LL_07_013: [ If handle is NULL then IoTHubClient_LL_RetrievePropertyComplete shall do nothing.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1421 | LogError("Invalid argument handle=%p", handle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1422 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1423 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1424 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1425 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1426 | /* Codes_SRS_IOTHUBCLIENT_LL_07_014: [ If deviceTwinCallback is NULL then IoTHubClient_LL_RetrievePropertyComplete shall do nothing.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1427 | if (handleData->deviceTwinCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 1428 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1429 | /* Codes_SRS_IOTHUBCLIENT_LL_07_015: [ If the the update_state parameter is DEVICE_TWIN_UPDATE_PARTIAL and a DEVICE_TWIN_UPDATE_COMPLETE has not been previously recieved then IoTHubClient_LL_RetrievePropertyComplete shall do nothing.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1430 | if (update_state == DEVICE_TWIN_UPDATE_COMPLETE) |
AzureIoTClient | 53:1e5a1ca1f274 | 1431 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1432 | handleData->complete_twin_update_encountered = true; |
AzureIoTClient | 53:1e5a1ca1f274 | 1433 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1434 | if (handleData->complete_twin_update_encountered) |
AzureIoTClient | 53:1e5a1ca1f274 | 1435 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1436 | /* Codes_SRS_IOTHUBCLIENT_LL_07_016: [ If deviceTwinCallback is set and DEVICE_TWIN_UPDATE_COMPLETE has been encountered then IoTHubClient_LL_RetrievePropertyComplete shall call deviceTwinCallback.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1437 | handleData->deviceTwinCallback(update_state, payLoad, size, handleData->deviceTwinContextCallback); |
AzureIoTClient | 53:1e5a1ca1f274 | 1438 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1439 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1440 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1441 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1442 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1443 | void IoTHubClient_LL_ReportedStateComplete(IOTHUB_CLIENT_LL_HANDLE handle, uint32_t item_id, int status_code) |
AzureIoTClient | 53:1e5a1ca1f274 | 1444 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1445 | /* Codes_SRS_IOTHUBCLIENT_LL_07_002: [ if handle or queue_handle are NULL then IoTHubClient_LL_ReportedStateComplete shall do nothing. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1446 | if (handle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1447 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1448 | /*"shall return"*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1449 | LogError("Invalid argument handle=%p", handle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1450 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1451 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1452 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1453 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1454 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1455 | /* Codes_SRS_IOTHUBCLIENT_LL_07_003: [ IoTHubClient_LL_ReportedStateComplete shall enumerate through the IOTHUB_DEVICE_TWIN structures in queue_handle. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1456 | DLIST_ENTRY* client_item = handleData->iot_ack_queue.Flink; |
AzureIoTClient | 53:1e5a1ca1f274 | 1457 | while (client_item != &(handleData->iot_ack_queue)) /*while we are not at the end of the list*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1458 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1459 | PDLIST_ENTRY next_item = client_item->Flink; |
AzureIoTClient | 53:1e5a1ca1f274 | 1460 | IOTHUB_DEVICE_TWIN* queue_data = containingRecord(client_item, IOTHUB_DEVICE_TWIN, entry); |
AzureIoTClient | 53:1e5a1ca1f274 | 1461 | if (queue_data->item_id == item_id) |
AzureIoTClient | 53:1e5a1ca1f274 | 1462 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1463 | if (queue_data->reported_state_callback != NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1464 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1465 | queue_data->reported_state_callback(status_code, queue_data->context); |
AzureIoTClient | 53:1e5a1ca1f274 | 1466 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1467 | /*Codes_SRS_IOTHUBCLIENT_LL_07_009: [ IoTHubClient_LL_ReportedStateComplete shall remove the IOTHUB_DEVICE_TWIN item from the ack queue.]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1468 | DList_RemoveEntryList(client_item); |
AzureIoTClient | 53:1e5a1ca1f274 | 1469 | device_twin_data_destroy(queue_data); |
AzureIoTClient | 53:1e5a1ca1f274 | 1470 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 1471 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1472 | client_item = next_item; |
AzureIoTClient | 53:1e5a1ca1f274 | 1473 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1474 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1475 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1476 | |
AzureIoTClient | 61:8b85a4e797cf | 1477 | bool IoTHubClient_LL_MessageCallback(IOTHUB_CLIENT_LL_HANDLE handle, MESSAGE_CALLBACK_INFO* messageData) |
AzureIoTClient | 16:deba40344375 | 1478 | { |
AzureIoTClient | 61:8b85a4e797cf | 1479 | bool result; |
AzureIoTClient | 61:8b85a4e797cf | 1480 | if ((handle == NULL) || messageData == NULL) |
AzureIoTClient | 42:448eecc3676e | 1481 | { |
AzureIoTClient | 61:8b85a4e797cf | 1482 | /*Codes_SRS_IOTHUBCLIENT_LL_02_029: [If parameter handle is NULL then IoTHubClient_LL_MessageCallback shall return IOTHUBMESSAGE_ABANDONED.] */ |
AzureIoTClient | 61:8b85a4e797cf | 1483 | LogError("invalid argument: handle(%p), messageData(%p)", handle, messageData); |
AzureIoTClient | 61:8b85a4e797cf | 1484 | result = false; |
AzureIoTClient | 61:8b85a4e797cf | 1485 | } |
AzureIoTClient | 61:8b85a4e797cf | 1486 | else if (messageData->messageHandle == NULL) |
AzureIoTClient | 61:8b85a4e797cf | 1487 | { |
AzureIoTClient | 61:8b85a4e797cf | 1488 | /*Codes_SRS_IOTHUBCLIENT_LL_10_004: [If messageHandle field of paramger messageData is NULL then IoTHubClient_LL_MessageCallback shall return IOTHUBMESSAGE_ABANDONED.] */ |
AzureIoTClient | 61:8b85a4e797cf | 1489 | LogError("invalid argument messageData->messageHandle(NULL)"); |
AzureIoTClient | 61:8b85a4e797cf | 1490 | result = false; |
AzureIoTClient | 42:448eecc3676e | 1491 | } |
AzureIoTClient | 42:448eecc3676e | 1492 | else |
AzureIoTClient | 42:448eecc3676e | 1493 | { |
AzureIoTClient | 42:448eecc3676e | 1494 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle; |
AzureIoTClient | 16:deba40344375 | 1495 | |
AzureIoTClient | 42:448eecc3676e | 1496 | /* Codes_SRS_IOTHUBCLIENT_LL_09_004: [IoTHubClient_LL_GetLastMessageReceiveTime shall return lastMessageReceiveTime in localtime] */ |
AzureIoTClient | 42:448eecc3676e | 1497 | handleData->lastMessageReceiveTime = get_time(NULL); |
AzureIoTClient | 62:5a4cdacf5090 | 1498 | switch (handleData->messageCallback.type) |
AzureIoTClient | 42:448eecc3676e | 1499 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1500 | case CALLBACK_TYPE_NONE: |
AzureIoTClient | 61:8b85a4e797cf | 1501 | { |
AzureIoTClient | 61:8b85a4e797cf | 1502 | /*Codes_SRS_IOTHUBCLIENT_LL_02_032: [If the client is not subscribed to receive messages then IoTHubClient_LL_MessageCallback shall return false.] */ |
AzureIoTClient | 61:8b85a4e797cf | 1503 | LogError("Invalid workflow - not currently set up to accept messages"); |
AzureIoTClient | 61:8b85a4e797cf | 1504 | result = false; |
AzureIoTClient | 61:8b85a4e797cf | 1505 | break; |
AzureIoTClient | 61:8b85a4e797cf | 1506 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1507 | case CALLBACK_TYPE_SYNC: |
AzureIoTClient | 61:8b85a4e797cf | 1508 | { |
AzureIoTClient | 61:8b85a4e797cf | 1509 | /*Codes_SRS_IOTHUBCLIENT_LL_02_030: [If messageCallbackType is LEGACY then IoTHubClient_LL_MessageCallback shall invoke the last callback function (the parameter messageCallback to IoTHubClient_LL_SetMessageCallback) passing the message and the passed userContextCallback.]*/ |
AzureIoTClient | 62:5a4cdacf5090 | 1510 | IOTHUBMESSAGE_DISPOSITION_RESULT cb_result = handleData->messageCallback.callbackSync(messageData->messageHandle, handleData->messageCallback.userContextCallback); |
AzureIoTClient | 61:8b85a4e797cf | 1511 | |
AzureIoTClient | 61:8b85a4e797cf | 1512 | /*Codes_SRS_IOTHUBCLIENT_LL_10_007: [If messageCallbackType is LEGACY then IoTHubClient_LL_MessageCallback shall send the message disposition as returned by the client to the underlying layer.] */ |
AzureIoTClient | 61:8b85a4e797cf | 1513 | if (handleData->IoTHubTransport_SendMessageDisposition(messageData, cb_result) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 61:8b85a4e797cf | 1514 | { |
AzureIoTClient | 61:8b85a4e797cf | 1515 | LogError("IoTHubTransport_SendMessageDisposition failed"); |
AzureIoTClient | 61:8b85a4e797cf | 1516 | } |
AzureIoTClient | 61:8b85a4e797cf | 1517 | result = true; |
AzureIoTClient | 61:8b85a4e797cf | 1518 | break; |
AzureIoTClient | 61:8b85a4e797cf | 1519 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1520 | case CALLBACK_TYPE_ASYNC: |
AzureIoTClient | 61:8b85a4e797cf | 1521 | { |
AzureIoTClient | 61:8b85a4e797cf | 1522 | /* Codes_SRS_IOTHUBCLIENT_LL_10_009: [If messageCallbackType is ASYNC then IoTHubClient_LL_MessageCallback shall return what messageCallbacEx returns.] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1523 | result = handleData->messageCallback.callbackAsync(messageData, handleData->messageCallback.userContextCallback); |
AzureIoTClient | 61:8b85a4e797cf | 1524 | if (!result) |
AzureIoTClient | 61:8b85a4e797cf | 1525 | { |
AzureIoTClient | 61:8b85a4e797cf | 1526 | LogError("messageCallbackEx failed"); |
AzureIoTClient | 61:8b85a4e797cf | 1527 | } |
AzureIoTClient | 61:8b85a4e797cf | 1528 | break; |
AzureIoTClient | 61:8b85a4e797cf | 1529 | } |
AzureIoTClient | 61:8b85a4e797cf | 1530 | default: |
AzureIoTClient | 61:8b85a4e797cf | 1531 | { |
AzureIoTClient | 61:8b85a4e797cf | 1532 | LogError("Invalid state"); |
AzureIoTClient | 61:8b85a4e797cf | 1533 | result = false; |
AzureIoTClient | 61:8b85a4e797cf | 1534 | break; |
AzureIoTClient | 61:8b85a4e797cf | 1535 | } |
AzureIoTClient | 42:448eecc3676e | 1536 | } |
AzureIoTClient | 42:448eecc3676e | 1537 | } |
AzureIoTClient | 61:8b85a4e797cf | 1538 | return result; |
AzureIoTClient | 16:deba40344375 | 1539 | } |
AzureIoTClient | 16:deba40344375 | 1540 | |
AzureIoTClient | 61:8b85a4e797cf | 1541 | void IoTHubClient_LL_ConnectionStatusCallBack(IOTHUB_CLIENT_LL_HANDLE handle, IOTHUB_CLIENT_CONNECTION_STATUS status, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason) |
AzureIoTClient | 52:1cc3c6d07cad | 1542 | { |
AzureIoTClient | 61:8b85a4e797cf | 1543 | /*Codes_SRS_IOTHUBCLIENT_LL_25_113: [If parameter connectionStatus is NULL or parameter handle is NULL then IoTHubClient_LL_ConnectionStatusCallBack shall return.]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1544 | if (handle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1545 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1546 | /*"shall return"*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1547 | LogError("invalid arg"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1548 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1549 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1550 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1551 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1552 | |
AzureIoTClient | 61:8b85a4e797cf | 1553 | /*Codes_SRS_IOTHUBCLIENT_LL_25_114: [IoTHubClient_LL_ConnectionStatusCallBack shall call non-callback set by the user from IoTHubClient_LL_SetConnectionStatusCallback passing the status, reason and the passed userContextCallback.]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1554 | if (handleData->conStatusCallback != NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1555 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1556 | handleData->conStatusCallback(status, reason, handleData->conStatusUserContextCallback); |
AzureIoTClient | 53:1e5a1ca1f274 | 1557 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1558 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1559 | |
AzureIoTClient | 52:1cc3c6d07cad | 1560 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1561 | |
AzureIoTClient | 52:1cc3c6d07cad | 1562 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetConnectionStatusCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK connectionStatusCallback, void * userContextCallback) |
AzureIoTClient | 52:1cc3c6d07cad | 1563 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1564 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1565 | /*Codes_SRS_IOTHUBCLIENT_LL_25_111: [IoTHubClient_LL_SetConnectionStatusCallback shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL parameter iotHubClientHandle**]** */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1566 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1567 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1568 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1569 | LOG_ERROR_RESULT; |
AzureIoTClient | 53:1e5a1ca1f274 | 1570 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1571 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1572 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1573 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1574 | /*Codes_SRS_IOTHUBCLIENT_LL_25_112: [IoTHubClient_LL_SetConnectionStatusCallback shall return IOTHUB_CLIENT_OK and save the callback and userContext as a member of the handle.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1575 | handleData->conStatusCallback = connectionStatusCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 1576 | handleData->conStatusUserContextCallback = userContextCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 1577 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1578 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1579 | |
AzureIoTClient | 52:1cc3c6d07cad | 1580 | return result; |
AzureIoTClient | 52:1cc3c6d07cad | 1581 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1582 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1583 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds) |
AzureIoTClient | 52:1cc3c6d07cad | 1584 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1585 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1586 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 52:1cc3c6d07cad | 1587 | |
AzureIoTClient | 62:5a4cdacf5090 | 1588 | /* Codes_SRS_IOTHUBCLIENT_LL_25_116: [If iotHubClientHandle, retryPolicy or retryTimeoutLimitinSeconds is NULL, IoTHubClient_LL_GetRetryPolicy shall return IOTHUB_CLIENT_INVALID_ARG]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1589 | if (handleData == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1590 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1591 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1592 | LOG_ERROR_RESULT; |
AzureIoTClient | 53:1e5a1ca1f274 | 1593 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1594 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1595 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1596 | if (handleData->transportHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1597 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1598 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1599 | LOG_ERROR_RESULT; |
AzureIoTClient | 53:1e5a1ca1f274 | 1600 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1601 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1602 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1603 | if (handleData->IoTHubTransport_SetRetryPolicy(handleData->transportHandle, retryPolicy, retryTimeoutLimitInSeconds) != 0) |
AzureIoTClient | 53:1e5a1ca1f274 | 1604 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1605 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1606 | LOG_ERROR_RESULT; |
AzureIoTClient | 53:1e5a1ca1f274 | 1607 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1608 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1609 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1610 | /* Codes_SRS_IOTHUBCLIENT_LL_25_118: [IoTHubClient_LL_SetRetryPolicy shall save connection retry policies specified by the user to retryPolicy in struct IOTHUB_CLIENT_LL_HANDLE_DATA] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1611 | /* Codes_SRS_IOTHUBCLIENT_LL_25_119: [IoTHubClient_LL_SetRetryPolicy shall save retryTimeoutLimitInSeconds in seconds to retryTimeout in struct IOTHUB_CLIENT_LL_HANDLE_DATA] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1612 | handleData->retryPolicy = retryPolicy; |
AzureIoTClient | 53:1e5a1ca1f274 | 1613 | handleData->retryTimeoutLimitInSeconds = retryTimeoutLimitInSeconds; |
AzureIoTClient | 53:1e5a1ca1f274 | 1614 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1615 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1616 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1617 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1618 | return result; |
AzureIoTClient | 52:1cc3c6d07cad | 1619 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1620 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1621 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY* retryPolicy, size_t* retryTimeoutLimitInSeconds) |
AzureIoTClient | 52:1cc3c6d07cad | 1622 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1623 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1624 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1625 | /* Codes_SRS_IOTHUBCLIENT_LL_09_001: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INVALID_ARG if any of the arguments is NULL] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1626 | if (iotHubClientHandle == NULL || retryPolicy == NULL || retryTimeoutLimitInSeconds == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1627 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1628 | LogError("Invalid parameter IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle = %p, IOTHUB_CLIENT_RETRY_POLICY* retryPolicy = %p, size_t* retryTimeoutLimitInSeconds = %p", iotHubClientHandle, retryPolicy, retryTimeoutLimitInSeconds); |
AzureIoTClient | 53:1e5a1ca1f274 | 1629 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1630 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1631 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1632 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1633 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 62:5a4cdacf5090 | 1634 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1635 | *retryPolicy = handleData->retryPolicy; |
AzureIoTClient | 53:1e5a1ca1f274 | 1636 | *retryTimeoutLimitInSeconds = handleData->retryTimeoutLimitInSeconds; |
AzureIoTClient | 53:1e5a1ca1f274 | 1637 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1638 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1639 | |
AzureIoTClient | 52:1cc3c6d07cad | 1640 | return result; |
AzureIoTClient | 52:1cc3c6d07cad | 1641 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1642 | |
AzureIoTClient | 16:deba40344375 | 1643 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetLastMessageReceiveTime(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime) |
AzureIoTClient | 16:deba40344375 | 1644 | { |
AzureIoTClient | 42:448eecc3676e | 1645 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 42:448eecc3676e | 1646 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 16:deba40344375 | 1647 | |
AzureIoTClient | 42:448eecc3676e | 1648 | /* Codes_SRS_IOTHUBCLIENT_LL_09_001: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INVALID_ARG if any of the arguments is NULL] */ |
AzureIoTClient | 42:448eecc3676e | 1649 | if (handleData == NULL || lastMessageReceiveTime == NULL) |
AzureIoTClient | 42:448eecc3676e | 1650 | { |
AzureIoTClient | 42:448eecc3676e | 1651 | result = IOTHUB_CLIENT_INVALID_ARG; |
Azure.IoT Build | 45:54c11b1b1407 | 1652 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 1653 | } |
AzureIoTClient | 42:448eecc3676e | 1654 | else |
AzureIoTClient | 42:448eecc3676e | 1655 | { |
AzureIoTClient | 42:448eecc3676e | 1656 | /* Codes_SRS_IOTHUBCLIENT_LL_09_002: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INDEFINITE_TIME - and not set 'lastMessageReceiveTime' - if it is unable to provide the time for the last commands] */ |
AzureIoTClient | 42:448eecc3676e | 1657 | if (handleData->lastMessageReceiveTime == INDEFINITE_TIME) |
AzureIoTClient | 42:448eecc3676e | 1658 | { |
AzureIoTClient | 42:448eecc3676e | 1659 | result = IOTHUB_CLIENT_INDEFINITE_TIME; |
Azure.IoT Build | 45:54c11b1b1407 | 1660 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 1661 | } |
AzureIoTClient | 42:448eecc3676e | 1662 | else |
AzureIoTClient | 42:448eecc3676e | 1663 | { |
AzureIoTClient | 42:448eecc3676e | 1664 | /* Codes_SRS_IOTHUBCLIENT_LL_09_003: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_OK if it wrote in the lastMessageReceiveTime the time when the last command was received] */ |
AzureIoTClient | 42:448eecc3676e | 1665 | /* Codes_SRS_IOTHUBCLIENT_LL_09_004: [IoTHubClient_LL_GetLastMessageReceiveTime shall return lastMessageReceiveTime in localtime] */ |
AzureIoTClient | 42:448eecc3676e | 1666 | *lastMessageReceiveTime = handleData->lastMessageReceiveTime; |
AzureIoTClient | 42:448eecc3676e | 1667 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 42:448eecc3676e | 1668 | } |
AzureIoTClient | 42:448eecc3676e | 1669 | } |
AzureIoTClient | 16:deba40344375 | 1670 | |
AzureIoTClient | 42:448eecc3676e | 1671 | return result; |
AzureIoTClient | 16:deba40344375 | 1672 | } |
AzureIoTClient | 16:deba40344375 | 1673 | |
AzureIoTClient | 16:deba40344375 | 1674 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetOption(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* optionName, const void* value) |
AzureIoTClient | 16:deba40344375 | 1675 | { |
AzureIoTClient | 40:1a94db9139ea | 1676 | |
AzureIoTClient | 42:448eecc3676e | 1677 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 42:448eecc3676e | 1678 | /*Codes_SRS_IOTHUBCLIENT_LL_02_034: [If iotHubClientHandle is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.]*/ |
AzureIoTClient | 42:448eecc3676e | 1679 | /*Codes_SRS_IOTHUBCLIENT_LL_02_035: [If optionName is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */ |
AzureIoTClient | 42:448eecc3676e | 1680 | /*Codes_SRS_IOTHUBCLIENT_LL_02_036: [If value is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */ |
AzureIoTClient | 42:448eecc3676e | 1681 | if ( |
AzureIoTClient | 42:448eecc3676e | 1682 | (iotHubClientHandle == NULL) || |
AzureIoTClient | 42:448eecc3676e | 1683 | (optionName == NULL) || |
AzureIoTClient | 42:448eecc3676e | 1684 | (value == NULL) |
AzureIoTClient | 42:448eecc3676e | 1685 | ) |
AzureIoTClient | 42:448eecc3676e | 1686 | { |
AzureIoTClient | 42:448eecc3676e | 1687 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 42:448eecc3676e | 1688 | LogError("invalid argument (NULL)"); |
AzureIoTClient | 42:448eecc3676e | 1689 | } |
AzureIoTClient | 42:448eecc3676e | 1690 | else |
AzureIoTClient | 42:448eecc3676e | 1691 | { |
AzureIoTClient | 42:448eecc3676e | 1692 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 42:448eecc3676e | 1693 | |
AzureIoTClient | 78:74a8d3068204 | 1694 | /*Codes_SRS_IOTHUBCLIENT_LL_02_039: [ "messageTimeout" - once IoTHubClient_LL_SendEventAsync is called the message shall timeout after value miliseconds. Value is a pointer to a tickcounter_ms_t. ]*/ |
AzureIoTClient | 70:875388a7d419 | 1695 | if (strcmp(optionName, OPTION_MESSAGE_TIMEOUT) == 0) |
AzureIoTClient | 42:448eecc3676e | 1696 | { |
AzureIoTClient | 42:448eecc3676e | 1697 | /*this is an option handled by IoTHubClient_LL*/ |
AzureIoTClient | 42:448eecc3676e | 1698 | /*Codes_SRS_IOTHUBCLIENT_LL_02_043: [ Calling IoTHubClient_LL_SetOption with value set to "0" shall disable the timeout mechanism for all new messages. ]*/ |
Azure.IoT.Build | 54:6dcad9019a64 | 1699 | handleData->currentMessageTimeout = *(const tickcounter_ms_t*)value; |
AzureIoTClient | 42:448eecc3676e | 1700 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 42:448eecc3676e | 1701 | } |
AzureIoTClient | 66:a419827cb051 | 1702 | else if (strcmp(optionName, OPTION_PRODUCT_INFO) == 0) |
AzureIoTClient | 66:a419827cb051 | 1703 | { |
AzureIoTClient | 66:a419827cb051 | 1704 | /*Codes_SRS_IOTHUBCLIENT_LL_10_033: [repeat calls with "product_info" will erase the previously set product information if applicatble. ]*/ |
AzureIoTClient | 66:a419827cb051 | 1705 | if (handleData->product_info != NULL) |
AzureIoTClient | 66:a419827cb051 | 1706 | { |
AzureIoTClient | 66:a419827cb051 | 1707 | STRING_delete(handleData->product_info); |
AzureIoTClient | 66:a419827cb051 | 1708 | handleData->product_info = NULL; |
AzureIoTClient | 66:a419827cb051 | 1709 | } |
AzureIoTClient | 66:a419827cb051 | 1710 | |
AzureIoTClient | 66:a419827cb051 | 1711 | /*Codes_SRS_IOTHUBCLIENT_LL_10_035: [If string concatenation fails, `IoTHubClient_LL_SetOption` shall return `IOTHUB_CLIENT_ERRROR`. Otherwise, `IOTHUB_CLIENT_OK` shall be returned. ]*/ |
AzureIoTClient | 66:a419827cb051 | 1712 | handleData->product_info = make_product_info((const char*)value); |
AzureIoTClient | 66:a419827cb051 | 1713 | if (handleData->product_info == NULL) |
AzureIoTClient | 66:a419827cb051 | 1714 | { |
AzureIoTClient | 66:a419827cb051 | 1715 | LogError("STRING_construct_sprintf failed"); |
AzureIoTClient | 66:a419827cb051 | 1716 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 66:a419827cb051 | 1717 | } |
AzureIoTClient | 66:a419827cb051 | 1718 | else |
AzureIoTClient | 66:a419827cb051 | 1719 | { |
AzureIoTClient | 66:a419827cb051 | 1720 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 66:a419827cb051 | 1721 | } |
AzureIoTClient | 66:a419827cb051 | 1722 | } |
AzureIoTClient | 77:e4e36df9caee | 1723 | else if (strcmp(optionName, OPTION_DIAGNOSTIC_SAMPLING_PERCENTAGE) == 0) |
AzureIoTClient | 77:e4e36df9caee | 1724 | { |
AzureIoTClient | 77:e4e36df9caee | 1725 | uint32_t percentage = *(uint32_t*)value; |
AzureIoTClient | 77:e4e36df9caee | 1726 | if (percentage > 100) |
AzureIoTClient | 77:e4e36df9caee | 1727 | { |
AzureIoTClient | 77:e4e36df9caee | 1728 | /*Codes_SRS_IOTHUBCLIENT_LL_10_036: [Calling IoTHubClient_LL_SetOption with value > 100 shall return `IOTHUB_CLIENT_ERRROR`. ]*/ |
AzureIoTClient | 77:e4e36df9caee | 1729 | LogError("The value of diag_sampling_percentage is out of range [0, 100]: %u", percentage); |
AzureIoTClient | 77:e4e36df9caee | 1730 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 77:e4e36df9caee | 1731 | } |
AzureIoTClient | 77:e4e36df9caee | 1732 | else |
AzureIoTClient | 77:e4e36df9caee | 1733 | { |
AzureIoTClient | 77:e4e36df9caee | 1734 | /*Codes_SRS_IOTHUBCLIENT_LL_10_037: [Calling IoTHubClient_LL_SetOption with value between [0, 100] shall return `IOTHUB_CLIENT_OK`. ]*/ |
AzureIoTClient | 77:e4e36df9caee | 1735 | handleData->diagnostic_setting.diagSamplingPercentage = percentage; |
AzureIoTClient | 77:e4e36df9caee | 1736 | handleData->diagnostic_setting.currentMessageNumber = 0; |
AzureIoTClient | 77:e4e36df9caee | 1737 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 77:e4e36df9caee | 1738 | } |
AzureIoTClient | 77:e4e36df9caee | 1739 | } |
AzureIoTClient | 42:448eecc3676e | 1740 | else |
AzureIoTClient | 42:448eecc3676e | 1741 | { |
AzureIoTClient | 46:6a69294b6119 | 1742 | |
AzureIoTClient | 46:6a69294b6119 | 1743 | /*Codes_SRS_IOTHUBCLIENT_LL_02_099: [ IoTHubClient_LL_SetOption shall return according to the table below ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1744 | IOTHUB_CLIENT_RESULT uploadToBlob_result; |
AzureIoTClient | 46:6a69294b6119 | 1745 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 46:6a69294b6119 | 1746 | uploadToBlob_result = IoTHubClient_LL_UploadToBlob_SetOption(handleData->uploadToBlobHandle, optionName, value); |
AzureIoTClient | 46:6a69294b6119 | 1747 | if(uploadToBlob_result == IOTHUB_CLIENT_ERROR) |
AzureIoTClient | 46:6a69294b6119 | 1748 | { |
AzureIoTClient | 46:6a69294b6119 | 1749 | LogError("unable to IoTHubClient_LL_UploadToBlob_SetOption"); |
AzureIoTClient | 46:6a69294b6119 | 1750 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 46:6a69294b6119 | 1751 | } |
AzureIoTClient | 46:6a69294b6119 | 1752 | #else |
AzureIoTClient | 46:6a69294b6119 | 1753 | uploadToBlob_result = IOTHUB_CLIENT_INVALID_ARG; /*harmless value (IOTHUB_CLIENT_INVALID_ARG)in the case when uploadtoblob is not compiled in, otherwise whatever IoTHubClient_LL_UploadToBlob_SetOption returned*/ |
AzureIoTClient | 46:6a69294b6119 | 1754 | #endif /*DONT_USE_UPLOADTOBLOB*/ |
AzureIoTClient | 16:deba40344375 | 1755 | |
AzureIoTClient | 70:875388a7d419 | 1756 | /*Codes_SRS_IOTHUBCLIENT_LL_12_023: [** `c2d_keep_alive_freq_secs` - shall set the cloud to device keep alive frequency(in seconds) for the connection. Zero means keep alive will not be sent. ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1757 | result = |
AzureIoTClient | 46:6a69294b6119 | 1758 | /*based on uploadToBlob_result value this is what happens:*/ |
AzureIoTClient | 46:6a69294b6119 | 1759 | /*IOTHUB_CLIENT_INVALID_ARG always returns what IoTHubTransport_SetOption returns*/ |
AzureIoTClient | 46:6a69294b6119 | 1760 | /*IOTHUB_CLIENT_ERROR always returns IOTHUB_CLIENT_ERROR */ |
AzureIoTClient | 46:6a69294b6119 | 1761 | /*IOTHUB_CLIENT_OK returns OK |
AzureIoTClient | 46:6a69294b6119 | 1762 | IOTHUB_CLIENT_OK if IoTHubTransport_SetOption returns OK or INVALID_ARG |
AzureIoTClient | 46:6a69294b6119 | 1763 | IOTHUB_CLIENT_ERROR if IoTHubTransport_SetOption returns ERROR*/ |
AzureIoTClient | 46:6a69294b6119 | 1764 | |
AzureIoTClient | 46:6a69294b6119 | 1765 | (uploadToBlob_result == IOTHUB_CLIENT_INVALID_ARG) ? handleData->IoTHubTransport_SetOption(handleData->transportHandle, optionName, value) : |
AzureIoTClient | 46:6a69294b6119 | 1766 | (uploadToBlob_result == IOTHUB_CLIENT_ERROR) ? IOTHUB_CLIENT_ERROR : |
AzureIoTClient | 46:6a69294b6119 | 1767 | (handleData->IoTHubTransport_SetOption(handleData->transportHandle, optionName, value) == IOTHUB_CLIENT_ERROR) ? IOTHUB_CLIENT_ERROR : IOTHUB_CLIENT_OK; |
AzureIoTClient | 46:6a69294b6119 | 1768 | |
AzureIoTClient | 47:aaa262b5f898 | 1769 | if (result != IOTHUB_CLIENT_OK) |
AzureIoTClient | 47:aaa262b5f898 | 1770 | { |
AzureIoTClient | 47:aaa262b5f898 | 1771 | LogError("underlying transport failed, returned = %s", ENUM_TO_STRING(IOTHUB_CLIENT_RESULT, result)); |
AzureIoTClient | 42:448eecc3676e | 1772 | } |
AzureIoTClient | 47:aaa262b5f898 | 1773 | } |
AzureIoTClient | 42:448eecc3676e | 1774 | } |
AzureIoTClient | 42:448eecc3676e | 1775 | return result; |
AzureIoTClient | 42:448eecc3676e | 1776 | } |
AzureIoTClient | 16:deba40344375 | 1777 | |
AzureIoTClient | 66:a419827cb051 | 1778 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetOption(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* optionName, void** value) |
AzureIoTClient | 66:a419827cb051 | 1779 | { |
AzureIoTClient | 66:a419827cb051 | 1780 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 66:a419827cb051 | 1781 | |
AzureIoTClient | 66:a419827cb051 | 1782 | if ((iotHubClientHandle == NULL) || (optionName == NULL) || (value == NULL)) |
AzureIoTClient | 66:a419827cb051 | 1783 | { |
AzureIoTClient | 66:a419827cb051 | 1784 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 66:a419827cb051 | 1785 | LogError("invalid argument iotHubClientHandle(%p); optionName(%p); value(%p)", iotHubClientHandle, optionName, value); |
AzureIoTClient | 66:a419827cb051 | 1786 | } |
AzureIoTClient | 66:a419827cb051 | 1787 | else if (strcmp(optionName, OPTION_PRODUCT_INFO) == 0) |
AzureIoTClient | 66:a419827cb051 | 1788 | { |
AzureIoTClient | 66:a419827cb051 | 1789 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 66:a419827cb051 | 1790 | *value = iotHubClientHandle->product_info; |
AzureIoTClient | 66:a419827cb051 | 1791 | } |
AzureIoTClient | 66:a419827cb051 | 1792 | else |
AzureIoTClient | 66:a419827cb051 | 1793 | { |
AzureIoTClient | 66:a419827cb051 | 1794 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 66:a419827cb051 | 1795 | LogError("invalid argument (%s)", optionName); |
AzureIoTClient | 66:a419827cb051 | 1796 | } |
AzureIoTClient | 66:a419827cb051 | 1797 | return result; |
AzureIoTClient | 66:a419827cb051 | 1798 | } |
AzureIoTClient | 66:a419827cb051 | 1799 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1800 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetDeviceTwinCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK deviceTwinCallback, void* userContextCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 1801 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1802 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1803 | /* Codes_SRS_IOTHUBCLIENT_LL_10_001: [ IoTHubClient_LL_SetDeviceTwinCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1804 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1805 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1806 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1807 | LogError("Invalid argument specified iothubClientHandle=%p", iotHubClientHandle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1808 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1809 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1810 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1811 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1812 | if (deviceTwinCallback == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1813 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1814 | /* Codes_SRS_IOTHUBCLIENT_LL_10_006: [ If deviceTwinCallback is NULL, then IoTHubClient_LL_SetDeviceTwinCallback shall call the underlying layer's _Unsubscribe function and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1815 | handleData->IoTHubTransport_Unsubscribe_DeviceTwin(handleData->transportHandle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1816 | handleData->deviceTwinCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 1817 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1818 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1819 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1820 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1821 | /* Codes_SRS_IOTHUBCLIENT_LL_10_002: [ If deviceTwinCallback is not NULL, then IoTHubClient_LL_SetDeviceTwinCallback shall call the underlying layer's _Subscribe function.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1822 | if (handleData->IoTHubTransport_Subscribe_DeviceTwin(handleData->transportHandle) == 0) |
AzureIoTClient | 53:1e5a1ca1f274 | 1823 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1824 | handleData->deviceTwinCallback = deviceTwinCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 1825 | handleData->deviceTwinContextCallback = userContextCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 1826 | /* Codes_SRS_IOTHUBCLIENT_LL_10_005: [ Otherwise IoTHubClient_LL_SetDeviceTwinCallback shall succeed and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1827 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1828 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1829 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1830 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1831 | /* Codes_SRS_IOTHUBCLIENT_LL_10_003: [ If the underlying layer's _Subscribe function fails, then IoTHubClient_LL_SetDeviceTwinCallback shall fail and return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1832 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1833 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1834 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1835 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1836 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1837 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1838 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1839 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SendReportedState(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const unsigned char* reportedState, size_t size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reportedStateCallback, void* userContextCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 1840 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1841 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1842 | /* Codes_SRS_IOTHUBCLIENT_LL_10_012: [ IoTHubClient_LL_SendReportedState shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1843 | /* Codes_SRS_IOTHUBCLIENT_LL_10_013: [ IoTHubClient_LL_SendReportedState shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter reportedState is NULL] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1844 | /* Codes_SRS_IOTHUBCLIENT_LL_07_005: [ IoTHubClient_LL_SendReportedState shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter size is equal to 0. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1845 | if (iotHubClientHandle == NULL || (reportedState == NULL || size == 0) ) |
AzureIoTClient | 53:1e5a1ca1f274 | 1846 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1847 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1848 | LogError("Invalid argument specified iothubClientHandle=%p, reportedState=%p, size=%zu", iotHubClientHandle, reportedState, size); |
AzureIoTClient | 53:1e5a1ca1f274 | 1849 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1850 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1851 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1852 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1853 | /* Codes_SRS_IOTHUBCLIENT_LL_10_014: [IoTHubClient_LL_SendReportedState shall construct and queue the reported a Device_Twin structure for transmition by the underlying transport.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1854 | IOTHUB_DEVICE_TWIN* client_data = dev_twin_data_create(handleData, get_next_item_id(handleData), reportedState, size, reportedStateCallback, userContextCallback); |
AzureIoTClient | 53:1e5a1ca1f274 | 1855 | if (client_data == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1856 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1857 | /* Codes_SRS_IOTHUBCLIENT_LL_10_015: [If any error is encountered IoTHubClient_LL_SendReportedState shall return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1858 | LogError("Failure constructing device twin data"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1859 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1860 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1861 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1862 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1863 | if (handleData->IoTHubTransport_Subscribe_DeviceTwin(handleData->transportHandle) != 0) |
AzureIoTClient | 53:1e5a1ca1f274 | 1864 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1865 | LogError("Failure adding device twin data to queue"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1866 | device_twin_data_destroy(client_data); |
AzureIoTClient | 53:1e5a1ca1f274 | 1867 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1868 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1869 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1870 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1871 | /* Codes_SRS_IOTHUBCLIENT_LL_07_001: [ IoTHubClient_LL_SendReportedState shall queue the constructed reportedState data to be consumed by the targeted transport. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1872 | DList_InsertTailList(&(iotHubClientHandle->iot_msg_queue), &(client_data->entry)); |
AzureIoTClient | 53:1e5a1ca1f274 | 1873 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1874 | /* Codes_SRS_IOTHUBCLIENT_LL_10_016: [ Otherwise IoTHubClient_LL_SendReportedState shall succeed and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1875 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1876 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1877 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1878 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1879 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1880 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1881 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1882 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetDeviceMethodCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC deviceMethodCallback, void* userContextCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 1883 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1884 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1885 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1886 | /*Codes_SRS_IOTHUBCLIENT_LL_12_017: [ IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1887 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1888 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1889 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1890 | LOG_ERROR_RESULT; |
AzureIoTClient | 53:1e5a1ca1f274 | 1891 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1892 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1893 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1894 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1895 | if (deviceMethodCallback == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1896 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1897 | if (handleData->methodCallback.type == CALLBACK_TYPE_NONE) |
AzureIoTClient | 62:5a4cdacf5090 | 1898 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1899 | /* Codes_SRS_IOTHUBCLIENT_LL_10_029: [ If deviceMethodCallback is NULL and the client is not subscribed to receive method calls, IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1900 | LogError("not currently set to accept or process incoming messages."); |
AzureIoTClient | 62:5a4cdacf5090 | 1901 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 62:5a4cdacf5090 | 1902 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1903 | else if (handleData->methodCallback.type == CALLBACK_TYPE_ASYNC) |
AzureIoTClient | 62:5a4cdacf5090 | 1904 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1905 | /* Codes_SRS_IOTHUBCLIENT_LL_10_028: [If the user has subscribed using IoTHubClient_LL_SetDeviceMethodCallback_Ex, IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1906 | LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetDeviceMethodCallback_Ex function."); |
AzureIoTClient | 62:5a4cdacf5090 | 1907 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 62:5a4cdacf5090 | 1908 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1909 | else |
AzureIoTClient | 62:5a4cdacf5090 | 1910 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1911 | /*Codes_SRS_IOTHUBCLIENT_LL_02_019: [If parameter messageCallback is NULL then IoTHubClient_LL_SetMessageCallback shall call the underlying layer's _Unsubscribe function and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1912 | /*Codes_SRS_IOTHUBCLIENT_LL_12_018: [If deviceMethodCallback is NULL, then IoTHubClient_LL_SetDeviceMethodCallback shall call the underlying layer's IoTHubTransport_Unsubscribe_DeviceMethod function and return IOTHUB_CLIENT_OK. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1913 | /*Codes_SRS_IOTHUBCLIENT_LL_12_022: [ Otherwise IoTHubClient_LL_SetDeviceMethodCallback shall succeed and return IOTHUB_CLIENT_OK. ]*/ |
AzureIoTClient | 62:5a4cdacf5090 | 1914 | handleData->IoTHubTransport_Unsubscribe_DeviceMethod(handleData->transportHandle); |
AzureIoTClient | 62:5a4cdacf5090 | 1915 | handleData->methodCallback.type = CALLBACK_TYPE_NONE; |
AzureIoTClient | 62:5a4cdacf5090 | 1916 | handleData->methodCallback.callbackSync = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1917 | handleData->methodCallback.userContextCallback = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1918 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 62:5a4cdacf5090 | 1919 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1920 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1921 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1922 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1923 | if (handleData->methodCallback.type == CALLBACK_TYPE_ASYNC) |
AzureIoTClient | 53:1e5a1ca1f274 | 1924 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1925 | /* Codes_SRS_IOTHUBCLIENT_LL_10_028: [If the user has subscribed using IoTHubClient_LL_SetDeviceMethodCallback_Ex, IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1926 | LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetDeviceMethodCallback_Ex function before subscribing with IoTHubClient_LL_SetDeviceMethodCallback."); |
AzureIoTClient | 62:5a4cdacf5090 | 1927 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1928 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1929 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1930 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1931 | /*Codes_SRS_IOTHUBCLIENT_LL_12_019: [ If deviceMethodCallback is not NULL, then IoTHubClient_LL_SetDeviceMethodCallback shall call the underlying layer's IoTHubTransport_Subscribe_DeviceMethod function. ]*/ |
AzureIoTClient | 62:5a4cdacf5090 | 1932 | if (handleData->IoTHubTransport_Subscribe_DeviceMethod(handleData->deviceHandle) == 0) |
AzureIoTClient | 62:5a4cdacf5090 | 1933 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1934 | /*Codes_SRS_IOTHUBCLIENT_LL_12_022: [ Otherwise IoTHubClient_LL_SetDeviceMethodCallback shall succeed and return IOTHUB_CLIENT_OK. ]*/ |
AzureIoTClient | 62:5a4cdacf5090 | 1935 | handleData->methodCallback.type = CALLBACK_TYPE_SYNC; |
AzureIoTClient | 62:5a4cdacf5090 | 1936 | handleData->methodCallback.callbackSync = deviceMethodCallback; |
AzureIoTClient | 62:5a4cdacf5090 | 1937 | handleData->methodCallback.callbackAsync = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1938 | handleData->methodCallback.userContextCallback = userContextCallback; |
AzureIoTClient | 62:5a4cdacf5090 | 1939 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 62:5a4cdacf5090 | 1940 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1941 | else |
AzureIoTClient | 62:5a4cdacf5090 | 1942 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1943 | /*Codes_SRS_IOTHUBCLIENT_LL_12_020: [ If the underlying layer's IoTHubTransport_Subscribe_DeviceMethod function fails, then IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 62:5a4cdacf5090 | 1944 | /*Codes_SRS_IOTHUBCLIENT_LL_12_021: [ If adding the information fails for any reason, IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 62:5a4cdacf5090 | 1945 | LogError("IoTHubTransport_Subscribe_DeviceMethod failed"); |
AzureIoTClient | 62:5a4cdacf5090 | 1946 | handleData->methodCallback.type = CALLBACK_TYPE_NONE; |
AzureIoTClient | 62:5a4cdacf5090 | 1947 | handleData->methodCallback.callbackAsync = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1948 | handleData->methodCallback.callbackSync = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1949 | handleData->methodCallback.userContextCallback = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1950 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 62:5a4cdacf5090 | 1951 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1952 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1953 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1954 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1955 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1956 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1957 | |
AzureIoTClient | 55:59b527ab3452 | 1958 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetDeviceMethodCallback_Ex(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK inboundDeviceMethodCallback, void* userContextCallback) |
AzureIoTClient | 55:59b527ab3452 | 1959 | { |
AzureIoTClient | 55:59b527ab3452 | 1960 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 55:59b527ab3452 | 1961 | /* Codes_SRS_IOTHUBCLIENT_LL_07_021: [ If handle is NULL then IoTHubClient_LL_SetDeviceMethodCallback_Ex shall return IOTHUB_CLIENT_INVALID_ARG.] */ |
AzureIoTClient | 55:59b527ab3452 | 1962 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 55:59b527ab3452 | 1963 | { |
AzureIoTClient | 55:59b527ab3452 | 1964 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 55:59b527ab3452 | 1965 | LOG_ERROR_RESULT; |
AzureIoTClient | 55:59b527ab3452 | 1966 | } |
AzureIoTClient | 55:59b527ab3452 | 1967 | else |
AzureIoTClient | 55:59b527ab3452 | 1968 | { |
AzureIoTClient | 55:59b527ab3452 | 1969 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 55:59b527ab3452 | 1970 | if (inboundDeviceMethodCallback == NULL) |
AzureIoTClient | 55:59b527ab3452 | 1971 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1972 | if (handleData->methodCallback.type == CALLBACK_TYPE_NONE) |
AzureIoTClient | 62:5a4cdacf5090 | 1973 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1974 | /* Codes_SRS_IOTHUBCLIENT_LL_10_030: [ If deviceMethodCallback is NULL and the client is not subscribed to receive method calls, IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1975 | LogError("not currently set to accept or process incoming messages."); |
AzureIoTClient | 62:5a4cdacf5090 | 1976 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 62:5a4cdacf5090 | 1977 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1978 | else if (handleData->methodCallback.type == CALLBACK_TYPE_SYNC) |
AzureIoTClient | 62:5a4cdacf5090 | 1979 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1980 | /* Codes_SRS_IOTHUBCLIENT_LL_10_031: [If the user has subscribed using IoTHubClient_LL_SetDeviceMethodCallback, IoTHubClient_LL_SetDeviceMethodCallback_Ex shall fail and return IOTHUB_CLIENT_ERROR. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1981 | LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetDeviceMethodCallback function."); |
AzureIoTClient | 62:5a4cdacf5090 | 1982 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 62:5a4cdacf5090 | 1983 | } |
AzureIoTClient | 62:5a4cdacf5090 | 1984 | else |
AzureIoTClient | 62:5a4cdacf5090 | 1985 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1986 | /* Codes_SRS_IOTHUBCLIENT_LL_07_022: [ If inboundDeviceMethodCallback is NULL then IoTHubClient_LL_SetDeviceMethodCallback_Ex shall call the underlying layer's IoTHubTransport_Unsubscribe_DeviceMethod function and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1987 | handleData->IoTHubTransport_Unsubscribe_DeviceMethod(handleData->transportHandle); |
AzureIoTClient | 62:5a4cdacf5090 | 1988 | handleData->methodCallback.type = CALLBACK_TYPE_NONE; |
AzureIoTClient | 62:5a4cdacf5090 | 1989 | handleData->methodCallback.callbackAsync = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1990 | handleData->methodCallback.userContextCallback = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 1991 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 62:5a4cdacf5090 | 1992 | } |
AzureIoTClient | 55:59b527ab3452 | 1993 | } |
AzureIoTClient | 55:59b527ab3452 | 1994 | else |
AzureIoTClient | 55:59b527ab3452 | 1995 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1996 | if (handleData->methodCallback.type == CALLBACK_TYPE_SYNC) |
AzureIoTClient | 55:59b527ab3452 | 1997 | { |
AzureIoTClient | 62:5a4cdacf5090 | 1998 | /* Codes_SRS_IOTHUBCLIENT_LL_10_031: [If the user has subscribed using IoTHubClient_LL_SetDeviceMethodCallback, IoTHubClient_LL_SetDeviceMethodCallback_Ex shall fail and return IOTHUB_CLIENT_ERROR. ] */ |
AzureIoTClient | 62:5a4cdacf5090 | 1999 | LogError("Invalid workflow sequence. Please unsubscribe using the IoTHubClient_LL_SetDeviceMethodCallback function before subscribing with IoTHubClient_LL_SetDeviceMethodCallback_Ex."); |
AzureIoTClient | 62:5a4cdacf5090 | 2000 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 55:59b527ab3452 | 2001 | } |
AzureIoTClient | 55:59b527ab3452 | 2002 | else |
AzureIoTClient | 55:59b527ab3452 | 2003 | { |
AzureIoTClient | 62:5a4cdacf5090 | 2004 | /* Codes_SRS_IOTHUBCLIENT_LL_07_023: [ If inboundDeviceMethodCallback is non-NULL then IoTHubClient_LL_SetDeviceMethodCallback_Ex shall call the underlying layer's IoTHubTransport_Subscribe_DeviceMethod function.]*/ |
AzureIoTClient | 62:5a4cdacf5090 | 2005 | if (handleData->IoTHubTransport_Subscribe_DeviceMethod(handleData->deviceHandle) == 0) |
AzureIoTClient | 62:5a4cdacf5090 | 2006 | { |
AzureIoTClient | 62:5a4cdacf5090 | 2007 | handleData->methodCallback.type = CALLBACK_TYPE_ASYNC; |
AzureIoTClient | 62:5a4cdacf5090 | 2008 | handleData->methodCallback.callbackAsync = inboundDeviceMethodCallback; |
AzureIoTClient | 62:5a4cdacf5090 | 2009 | handleData->methodCallback.callbackSync = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 2010 | handleData->methodCallback.userContextCallback = userContextCallback; |
AzureIoTClient | 62:5a4cdacf5090 | 2011 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 62:5a4cdacf5090 | 2012 | } |
AzureIoTClient | 62:5a4cdacf5090 | 2013 | else |
AzureIoTClient | 62:5a4cdacf5090 | 2014 | { |
AzureIoTClient | 62:5a4cdacf5090 | 2015 | /* Codes_SRS_IOTHUBCLIENT_LL_07_025: [ If any error is encountered then IoTHubClient_LL_SetDeviceMethodCallback_Ex shall return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 62:5a4cdacf5090 | 2016 | LogError("IoTHubTransport_Subscribe_DeviceMethod failed"); |
AzureIoTClient | 62:5a4cdacf5090 | 2017 | handleData->methodCallback.type = CALLBACK_TYPE_NONE; |
AzureIoTClient | 62:5a4cdacf5090 | 2018 | handleData->methodCallback.callbackAsync = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 2019 | handleData->methodCallback.callbackSync = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 2020 | handleData->methodCallback.userContextCallback = NULL; |
AzureIoTClient | 62:5a4cdacf5090 | 2021 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 62:5a4cdacf5090 | 2022 | } |
AzureIoTClient | 55:59b527ab3452 | 2023 | } |
AzureIoTClient | 55:59b527ab3452 | 2024 | } |
AzureIoTClient | 55:59b527ab3452 | 2025 | } |
AzureIoTClient | 55:59b527ab3452 | 2026 | return result; |
AzureIoTClient | 55:59b527ab3452 | 2027 | } |
AzureIoTClient | 55:59b527ab3452 | 2028 | |
AzureIoTClient | 55:59b527ab3452 | 2029 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_DeviceMethodResponse(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, METHOD_HANDLE methodId, const unsigned char* response, size_t response_size, int status_response) |
AzureIoTClient | 55:59b527ab3452 | 2030 | { |
AzureIoTClient | 55:59b527ab3452 | 2031 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 55:59b527ab3452 | 2032 | /* Codes_SRS_IOTHUBCLIENT_LL_07_026: [ If handle or methodId is NULL then IoTHubClient_LL_DeviceMethodResponse shall return IOTHUB_CLIENT_INVALID_ARG.] */ |
AzureIoTClient | 55:59b527ab3452 | 2033 | if (iotHubClientHandle == NULL || methodId == NULL) |
AzureIoTClient | 55:59b527ab3452 | 2034 | { |
AzureIoTClient | 55:59b527ab3452 | 2035 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 55:59b527ab3452 | 2036 | LOG_ERROR_RESULT; |
AzureIoTClient | 55:59b527ab3452 | 2037 | } |
AzureIoTClient | 55:59b527ab3452 | 2038 | else |
AzureIoTClient | 55:59b527ab3452 | 2039 | { |
AzureIoTClient | 55:59b527ab3452 | 2040 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 55:59b527ab3452 | 2041 | /* Codes_SRS_IOTHUBCLIENT_LL_07_027: [ IoTHubClient_LL_DeviceMethodResponse shall call the IoTHubTransport_DeviceMethod_Response transport function.] */ |
AzureIoTClient | 55:59b527ab3452 | 2042 | if (handleData->IoTHubTransport_DeviceMethod_Response(handleData->deviceHandle, methodId, response, response_size, status_response) != 0) |
AzureIoTClient | 55:59b527ab3452 | 2043 | { |
AzureIoTClient | 55:59b527ab3452 | 2044 | LogError("IoTHubTransport_DeviceMethod_Response failed"); |
AzureIoTClient | 55:59b527ab3452 | 2045 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 55:59b527ab3452 | 2046 | } |
AzureIoTClient | 55:59b527ab3452 | 2047 | else |
AzureIoTClient | 55:59b527ab3452 | 2048 | { |
AzureIoTClient | 55:59b527ab3452 | 2049 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 55:59b527ab3452 | 2050 | } |
AzureIoTClient | 55:59b527ab3452 | 2051 | } |
AzureIoTClient | 55:59b527ab3452 | 2052 | return result; |
AzureIoTClient | 55:59b527ab3452 | 2053 | } |
AzureIoTClient | 55:59b527ab3452 | 2054 | |
AzureIoTClient | 44:33dd78697616 | 2055 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 2056 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_UploadToBlob(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* destinationFileName, const unsigned char* source, size_t size) |
AzureIoTClient | 42:448eecc3676e | 2057 | { |
AzureIoTClient | 42:448eecc3676e | 2058 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 42:448eecc3676e | 2059 | /*Codes_SRS_IOTHUBCLIENT_LL_02_061: [ If iotHubClientHandle is NULL then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 2060 | /*Codes_SRS_IOTHUBCLIENT_LL_02_062: [ If destinationFileName is NULL then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 2061 | if ( |
AzureIoTClient | 42:448eecc3676e | 2062 | (iotHubClientHandle == NULL) || |
AzureIoTClient | 42:448eecc3676e | 2063 | (destinationFileName == NULL) || |
AzureIoTClient | 42:448eecc3676e | 2064 | ((source == NULL) && (size >0)) |
AzureIoTClient | 42:448eecc3676e | 2065 | ) |
AzureIoTClient | 42:448eecc3676e | 2066 | { |
AzureIoTClient | 42:448eecc3676e | 2067 | LogError("invalid parameters IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle=%p, const char* destinationFileName=%s, const unsigned char* source=%p, size_t size=%zu", iotHubClientHandle, destinationFileName, source, size); |
AzureIoTClient | 42:448eecc3676e | 2068 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 42:448eecc3676e | 2069 | } |
AzureIoTClient | 42:448eecc3676e | 2070 | else |
AzureIoTClient | 42:448eecc3676e | 2071 | { |
AzureIoTClient | 42:448eecc3676e | 2072 | result = IoTHubClient_LL_UploadToBlob_Impl(iotHubClientHandle->uploadToBlobHandle, destinationFileName, source, size); |
AzureIoTClient | 42:448eecc3676e | 2073 | } |
AzureIoTClient | 42:448eecc3676e | 2074 | return result; |
AzureIoTClient | 16:deba40344375 | 2075 | } |
AzureIoTClient | 43:038d8511e817 | 2076 | #endif |