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