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.c@60:41648c4e7036, 2017-02-24 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Fri Feb 24 14:00:43 2017 -0800
- Revision:
- 60:41648c4e7036
- Parent:
- 59:7e89be231352
- Child:
- 61:8b85a4e797cf
1.1.8
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 | 54:6dcad9019a64 | 5 | #include "azure_c_shared_utility/umock_c_prod.h" |
Azure.IoT Build | 38:a05929a75111 | 6 | #include "azure_c_shared_utility/gballoc.h" |
AzureIoTClient | 16:deba40344375 | 7 | |
AzureIoTClient | 16:deba40344375 | 8 | #include <signal.h> |
Azure.IoT Build | 35:ceed20da4ba6 | 9 | #include <stddef.h> |
AzureIoTClient | 60:41648c4e7036 | 10 | #include "azure_c_shared_utility/optimize_size.h" |
Azure.IoT Build | 38:a05929a75111 | 11 | #include "azure_c_shared_utility/crt_abstractions.h" |
AzureIoTClient | 16:deba40344375 | 12 | #include "iothub_client.h" |
AzureIoTClient | 16:deba40344375 | 13 | #include "iothub_client_ll.h" |
Azure.IoT Build | 37:18310e4d888d | 14 | #include "iothubtransport.h" |
Azure.IoT Build | 38:a05929a75111 | 15 | #include "azure_c_shared_utility/threadapi.h" |
Azure.IoT Build | 38:a05929a75111 | 16 | #include "azure_c_shared_utility/lock.h" |
Azure.IoT Build | 45:54c11b1b1407 | 17 | #include "azure_c_shared_utility/xlogging.h" |
AzureIoTClient | 52:1cc3c6d07cad | 18 | #include "azure_c_shared_utility/singlylinkedlist.h" |
Azure.IoT.Build | 54:6dcad9019a64 | 19 | #include "azure_c_shared_utility/vector.h" |
AzureIoTClient | 16:deba40344375 | 20 | |
AzureIoTClient | 55:59b527ab3452 | 21 | struct IOTHUB_QUEUE_CONTEXT_TAG; |
AzureIoTClient | 55:59b527ab3452 | 22 | |
AzureIoTClient | 16:deba40344375 | 23 | typedef struct IOTHUB_CLIENT_INSTANCE_TAG |
AzureIoTClient | 16:deba40344375 | 24 | { |
AzureIoTClient | 16:deba40344375 | 25 | IOTHUB_CLIENT_LL_HANDLE IoTHubClientLLHandle; |
AzureIoTClient | 42:448eecc3676e | 26 | TRANSPORT_HANDLE TransportHandle; |
AzureIoTClient | 16:deba40344375 | 27 | THREAD_HANDLE ThreadHandle; |
AzureIoTClient | 16:deba40344375 | 28 | LOCK_HANDLE LockHandle; |
AzureIoTClient | 16:deba40344375 | 29 | sig_atomic_t StopThread; |
AzureIoTClient | 44:33dd78697616 | 30 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 52:1cc3c6d07cad | 31 | SINGLYLINKEDLIST_HANDLE savedDataToBeCleaned; /*list containing UPLOADTOBLOB_SAVED_DATA*/ |
AzureIoTClient | 43:038d8511e817 | 32 | #endif |
Azure.IoT.Build | 54:6dcad9019a64 | 33 | int created_with_transport_handle; |
Azure.IoT.Build | 54:6dcad9019a64 | 34 | VECTOR_HANDLE saved_user_callback_list; |
Azure.IoT.Build | 54:6dcad9019a64 | 35 | IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK desired_state_callback; |
Azure.IoT.Build | 54:6dcad9019a64 | 36 | IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK event_confirm_callback; |
Azure.IoT.Build | 54:6dcad9019a64 | 37 | IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reported_state_callback; |
Azure.IoT.Build | 54:6dcad9019a64 | 38 | IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK connection_status_callback; |
AzureIoTClient | 55:59b527ab3452 | 39 | IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK device_method_callback; |
AzureIoTClient | 55:59b527ab3452 | 40 | struct IOTHUB_QUEUE_CONTEXT_TAG* devicetwin_user_context; |
AzureIoTClient | 55:59b527ab3452 | 41 | struct IOTHUB_QUEUE_CONTEXT_TAG* connection_status_user_context; |
AzureIoTClient | 16:deba40344375 | 42 | } IOTHUB_CLIENT_INSTANCE; |
AzureIoTClient | 16:deba40344375 | 43 | |
AzureIoTClient | 44:33dd78697616 | 44 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 45 | typedef struct UPLOADTOBLOB_SAVED_DATA_TAG |
AzureIoTClient | 42:448eecc3676e | 46 | { |
AzureIoTClient | 42:448eecc3676e | 47 | unsigned char* source; |
AzureIoTClient | 42:448eecc3676e | 48 | size_t size; |
AzureIoTClient | 42:448eecc3676e | 49 | char* destinationFileName; |
AzureIoTClient | 42:448eecc3676e | 50 | IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK iotHubClientFileUploadCallback; |
AzureIoTClient | 42:448eecc3676e | 51 | void* context; |
AzureIoTClient | 42:448eecc3676e | 52 | THREAD_HANDLE uploadingThreadHandle; |
AzureIoTClient | 42:448eecc3676e | 53 | IOTHUB_CLIENT_HANDLE iotHubClientHandle; |
AzureIoTClient | 42:448eecc3676e | 54 | LOCK_HANDLE lockGarbage; |
AzureIoTClient | 42:448eecc3676e | 55 | int canBeGarbageCollected; /*flag indicating that the UPLOADTOBLOB_SAVED_DATA structure can be freed because the thread deadling with it finished*/ |
AzureIoTClient | 42:448eecc3676e | 56 | }UPLOADTOBLOB_SAVED_DATA; |
AzureIoTClient | 43:038d8511e817 | 57 | #endif |
AzureIoTClient | 42:448eecc3676e | 58 | |
Azure.IoT.Build | 54:6dcad9019a64 | 59 | #define USER_CALLBACK_TYPE_VALUES \ |
Azure.IoT.Build | 54:6dcad9019a64 | 60 | CALLBACK_TYPE_DEVICE_TWIN, \ |
Azure.IoT.Build | 54:6dcad9019a64 | 61 | CALLBACK_TYPE_EVENT_CONFIRM, \ |
Azure.IoT.Build | 54:6dcad9019a64 | 62 | CALLBACK_TYPE_REPORTED_STATE, \ |
AzureIoTClient | 55:59b527ab3452 | 63 | CALLBACK_TYPE_CONNECTION_STATUS, \ |
AzureIoTClient | 55:59b527ab3452 | 64 | CALLBACK_TYPE_DEVICE_METHOD |
Azure.IoT.Build | 54:6dcad9019a64 | 65 | |
Azure.IoT.Build | 54:6dcad9019a64 | 66 | DEFINE_ENUM(USER_CALLBACK_TYPE, USER_CALLBACK_TYPE_VALUES) |
AzureIoTClient | 56:fdda9c1244e4 | 67 | DEFINE_ENUM_STRINGS(USER_CALLBACK_TYPE, USER_CALLBACK_TYPE_VALUES) |
Azure.IoT.Build | 54:6dcad9019a64 | 68 | |
Azure.IoT.Build | 54:6dcad9019a64 | 69 | typedef struct DEVICE_TWIN_CALLBACK_INFO_TAG |
Azure.IoT.Build | 54:6dcad9019a64 | 70 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 71 | DEVICE_TWIN_UPDATE_STATE update_state; |
Azure.IoT.Build | 54:6dcad9019a64 | 72 | unsigned char* payLoad; |
Azure.IoT.Build | 54:6dcad9019a64 | 73 | size_t size; |
Azure.IoT.Build | 54:6dcad9019a64 | 74 | } DEVICE_TWIN_CALLBACK_INFO; |
Azure.IoT.Build | 54:6dcad9019a64 | 75 | |
Azure.IoT.Build | 54:6dcad9019a64 | 76 | typedef struct EVENT_CONFIRM_CALLBACK_INFO_TAG |
Azure.IoT.Build | 54:6dcad9019a64 | 77 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 78 | IOTHUB_CLIENT_CONFIRMATION_RESULT confirm_result; |
Azure.IoT.Build | 54:6dcad9019a64 | 79 | } EVENT_CONFIRM_CALLBACK_INFO; |
Azure.IoT.Build | 54:6dcad9019a64 | 80 | |
Azure.IoT.Build | 54:6dcad9019a64 | 81 | typedef struct REPORTED_STATE_CALLBACK_INFO_TAG |
Azure.IoT.Build | 54:6dcad9019a64 | 82 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 83 | int status_code; |
Azure.IoT.Build | 54:6dcad9019a64 | 84 | } REPORTED_STATE_CALLBACK_INFO; |
Azure.IoT.Build | 54:6dcad9019a64 | 85 | |
Azure.IoT.Build | 54:6dcad9019a64 | 86 | typedef struct CONNECTION_STATUS_CALLBACK_INFO_TAG |
Azure.IoT.Build | 54:6dcad9019a64 | 87 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 88 | IOTHUB_CLIENT_CONNECTION_STATUS connection_status; |
Azure.IoT.Build | 54:6dcad9019a64 | 89 | IOTHUB_CLIENT_CONNECTION_STATUS_REASON status_reason; |
Azure.IoT.Build | 54:6dcad9019a64 | 90 | } CONNECTION_STATUS_CALLBACK_INFO; |
Azure.IoT.Build | 54:6dcad9019a64 | 91 | |
Azure.IoT.Build | 54:6dcad9019a64 | 92 | typedef struct METHOD_CALLBACK_INFO_TAG |
Azure.IoT.Build | 54:6dcad9019a64 | 93 | { |
AzureIoTClient | 55:59b527ab3452 | 94 | STRING_HANDLE method_name; |
AzureIoTClient | 55:59b527ab3452 | 95 | BUFFER_HANDLE payload; |
AzureIoTClient | 55:59b527ab3452 | 96 | METHOD_HANDLE method_id; |
Azure.IoT.Build | 54:6dcad9019a64 | 97 | } METHOD_CALLBACK_INFO; |
Azure.IoT.Build | 54:6dcad9019a64 | 98 | |
Azure.IoT.Build | 54:6dcad9019a64 | 99 | typedef struct USER_CALLBACK_INFO_TAG |
Azure.IoT.Build | 54:6dcad9019a64 | 100 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 101 | USER_CALLBACK_TYPE type; |
Azure.IoT.Build | 54:6dcad9019a64 | 102 | void* userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 103 | union IOTHUB_CALLBACK |
Azure.IoT.Build | 54:6dcad9019a64 | 104 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 105 | DEVICE_TWIN_CALLBACK_INFO dev_twin_cb_info; |
Azure.IoT.Build | 54:6dcad9019a64 | 106 | EVENT_CONFIRM_CALLBACK_INFO event_confirm_cb_info; |
Azure.IoT.Build | 54:6dcad9019a64 | 107 | REPORTED_STATE_CALLBACK_INFO reported_state_cb_info; |
Azure.IoT.Build | 54:6dcad9019a64 | 108 | CONNECTION_STATUS_CALLBACK_INFO connection_status_cb_info; |
AzureIoTClient | 55:59b527ab3452 | 109 | METHOD_CALLBACK_INFO method_cb_info; |
Azure.IoT.Build | 54:6dcad9019a64 | 110 | } iothub_callback; |
Azure.IoT.Build | 54:6dcad9019a64 | 111 | } USER_CALLBACK_INFO; |
Azure.IoT.Build | 54:6dcad9019a64 | 112 | |
Azure.IoT.Build | 54:6dcad9019a64 | 113 | typedef struct IOTHUB_QUEUE_CONTEXT_TAG |
Azure.IoT.Build | 54:6dcad9019a64 | 114 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 115 | IOTHUB_CLIENT_INSTANCE* iotHubClientHandle; |
Azure.IoT.Build | 54:6dcad9019a64 | 116 | void* userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 117 | } IOTHUB_QUEUE_CONTEXT; |
Azure.IoT.Build | 54:6dcad9019a64 | 118 | |
Azure.IoT Build | 35:ceed20da4ba6 | 119 | /*used by unittests only*/ |
Azure.IoT Build | 35:ceed20da4ba6 | 120 | const size_t IoTHubClient_ThreadTerminationOffset = offsetof(IOTHUB_CLIENT_INSTANCE, StopThread); |
Azure.IoT Build | 35:ceed20da4ba6 | 121 | |
AzureIoTClient | 44:33dd78697616 | 122 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 123 | /*this function is called from _Destroy and from ScheduleWork_Thread to join finished blobUpload threads and free that memory*/ |
AzureIoTClient | 42:448eecc3676e | 124 | static void garbageCollectorImpl(IOTHUB_CLIENT_INSTANCE* iotHubClientInstance) |
AzureIoTClient | 42:448eecc3676e | 125 | { |
AzureIoTClient | 42:448eecc3676e | 126 | /*see if any savedData structures can be disposed of*/ |
AzureIoTClient | 42:448eecc3676e | 127 | /*Codes_SRS_IOTHUBCLIENT_02_072: [ All threads marked as disposable (upon completion of a file upload) shall be joined and the data structures build for them shall be freed. ]*/ |
AzureIoTClient | 52:1cc3c6d07cad | 128 | LIST_ITEM_HANDLE item = singlylinkedlist_get_head_item(iotHubClientInstance->savedDataToBeCleaned); |
AzureIoTClient | 42:448eecc3676e | 129 | while (item != NULL) |
AzureIoTClient | 42:448eecc3676e | 130 | { |
AzureIoTClient | 52:1cc3c6d07cad | 131 | const UPLOADTOBLOB_SAVED_DATA* savedData = (const UPLOADTOBLOB_SAVED_DATA*)singlylinkedlist_item_get_value(item); |
AzureIoTClient | 42:448eecc3676e | 132 | LIST_ITEM_HANDLE old_item = item; |
AzureIoTClient | 52:1cc3c6d07cad | 133 | item = singlylinkedlist_get_next_item(item); |
AzureIoTClient | 42:448eecc3676e | 134 | |
AzureIoTClient | 42:448eecc3676e | 135 | if (Lock(savedData->lockGarbage) != LOCK_OK) |
AzureIoTClient | 42:448eecc3676e | 136 | { |
AzureIoTClient | 43:038d8511e817 | 137 | LogError("unable to Lock"); |
AzureIoTClient | 42:448eecc3676e | 138 | } |
AzureIoTClient | 42:448eecc3676e | 139 | else |
AzureIoTClient | 42:448eecc3676e | 140 | { |
AzureIoTClient | 42:448eecc3676e | 141 | if (savedData->canBeGarbageCollected == 1) |
AzureIoTClient | 42:448eecc3676e | 142 | { |
AzureIoTClient | 42:448eecc3676e | 143 | int notUsed; |
AzureIoTClient | 42:448eecc3676e | 144 | if (ThreadAPI_Join(savedData->uploadingThreadHandle, ¬Used) != THREADAPI_OK) |
AzureIoTClient | 42:448eecc3676e | 145 | { |
AzureIoTClient | 42:448eecc3676e | 146 | LogError("unable to ThreadAPI_Join"); |
AzureIoTClient | 42:448eecc3676e | 147 | } |
AzureIoTClient | 52:1cc3c6d07cad | 148 | (void)singlylinkedlist_remove(iotHubClientInstance->savedDataToBeCleaned, old_item); |
AzureIoTClient | 42:448eecc3676e | 149 | free((void*)savedData->source); |
AzureIoTClient | 42:448eecc3676e | 150 | free((void*)savedData->destinationFileName); |
AzureIoTClient | 42:448eecc3676e | 151 | |
AzureIoTClient | 42:448eecc3676e | 152 | if (Unlock(savedData->lockGarbage) != LOCK_OK) |
AzureIoTClient | 42:448eecc3676e | 153 | { |
AzureIoTClient | 42:448eecc3676e | 154 | LogError("unable to unlock after locking"); |
AzureIoTClient | 42:448eecc3676e | 155 | } |
AzureIoTClient | 42:448eecc3676e | 156 | (void)Lock_Deinit(savedData->lockGarbage); |
AzureIoTClient | 42:448eecc3676e | 157 | free((void*)savedData); |
AzureIoTClient | 42:448eecc3676e | 158 | } |
AzureIoTClient | 42:448eecc3676e | 159 | else |
AzureIoTClient | 42:448eecc3676e | 160 | { |
AzureIoTClient | 42:448eecc3676e | 161 | if (Unlock(savedData->lockGarbage) != LOCK_OK) |
AzureIoTClient | 42:448eecc3676e | 162 | { |
AzureIoTClient | 42:448eecc3676e | 163 | LogError("unable to unlock after locking"); |
AzureIoTClient | 42:448eecc3676e | 164 | } |
AzureIoTClient | 42:448eecc3676e | 165 | } |
AzureIoTClient | 42:448eecc3676e | 166 | } |
AzureIoTClient | 42:448eecc3676e | 167 | } |
AzureIoTClient | 42:448eecc3676e | 168 | } |
AzureIoTClient | 43:038d8511e817 | 169 | #endif |
AzureIoTClient | 42:448eecc3676e | 170 | |
Azure.IoT.Build | 54:6dcad9019a64 | 171 | static IOTHUBMESSAGE_DISPOSITION_RESULT iothub_ll_message_callback(IOTHUB_MESSAGE_HANDLE message, void* userContextCallback) |
Azure.IoT.Build | 54:6dcad9019a64 | 172 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 173 | (void)message; |
Azure.IoT.Build | 54:6dcad9019a64 | 174 | (void)userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 175 | return IOTHUBMESSAGE_ABANDONED; |
Azure.IoT.Build | 54:6dcad9019a64 | 176 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 177 | |
AzureIoTClient | 55:59b527ab3452 | 178 | static int iothub_ll_inbound_device_method_callback(const char* method_name, const unsigned char* payload, size_t size, METHOD_HANDLE method_id, void* userContextCallback) |
Azure.IoT.Build | 54:6dcad9019a64 | 179 | { |
AzureIoTClient | 55:59b527ab3452 | 180 | int result; |
AzureIoTClient | 55:59b527ab3452 | 181 | IOTHUB_QUEUE_CONTEXT* queue_context = (IOTHUB_QUEUE_CONTEXT*)userContextCallback; |
AzureIoTClient | 55:59b527ab3452 | 182 | /* Codes_SRS_IOTHUB_MQTT_TRANSPORT_07_001: [ if userContextCallback is NULL, IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK shall return a nonNULL value. ] */ |
AzureIoTClient | 55:59b527ab3452 | 183 | if (queue_context != NULL) |
AzureIoTClient | 55:59b527ab3452 | 184 | { |
AzureIoTClient | 55:59b527ab3452 | 185 | /* Codes_SRS_IOTHUB_MQTT_TRANSPORT_07_002: [ IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK shall copy the method_name and payload. ] */ |
AzureIoTClient | 55:59b527ab3452 | 186 | USER_CALLBACK_INFO queue_cb_info; |
AzureIoTClient | 55:59b527ab3452 | 187 | queue_cb_info.type = CALLBACK_TYPE_DEVICE_METHOD; |
AzureIoTClient | 55:59b527ab3452 | 188 | queue_cb_info.userContextCallback = queue_context->userContextCallback; |
AzureIoTClient | 55:59b527ab3452 | 189 | queue_cb_info.iothub_callback.method_cb_info.method_id = method_id; |
AzureIoTClient | 55:59b527ab3452 | 190 | if ( (queue_cb_info.iothub_callback.method_cb_info.method_name = STRING_construct(method_name)) == NULL) |
AzureIoTClient | 55:59b527ab3452 | 191 | { |
AzureIoTClient | 55:59b527ab3452 | 192 | /* Codes_SRS_IOTHUB_MQTT_TRANSPORT_07_003: [ If a failure is encountered IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK shall return a non-NULL value. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 193 | LogError("Failure: STRING_construct"); |
AzureIoTClient | 60:41648c4e7036 | 194 | result = __FAILURE__; |
AzureIoTClient | 55:59b527ab3452 | 195 | } |
AzureIoTClient | 55:59b527ab3452 | 196 | else if ((queue_cb_info.iothub_callback.method_cb_info.payload = BUFFER_create(payload, size)) == NULL) |
AzureIoTClient | 55:59b527ab3452 | 197 | { |
AzureIoTClient | 55:59b527ab3452 | 198 | STRING_delete(queue_cb_info.iothub_callback.method_cb_info.method_name); |
AzureIoTClient | 55:59b527ab3452 | 199 | /* Codes_SRS_IOTHUB_MQTT_TRANSPORT_07_003: [ If a failure is encountered IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK shall return a non-NULL value. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 200 | LogError("Failure: BUFFER_create"); |
AzureIoTClient | 60:41648c4e7036 | 201 | result = __FAILURE__; |
AzureIoTClient | 55:59b527ab3452 | 202 | } |
AzureIoTClient | 55:59b527ab3452 | 203 | else if (VECTOR_push_back(queue_context->iotHubClientHandle->saved_user_callback_list, &queue_cb_info, 1) != 0) |
AzureIoTClient | 55:59b527ab3452 | 204 | { |
AzureIoTClient | 55:59b527ab3452 | 205 | STRING_delete(queue_cb_info.iothub_callback.method_cb_info.method_name); |
AzureIoTClient | 55:59b527ab3452 | 206 | BUFFER_delete(queue_cb_info.iothub_callback.method_cb_info.payload); |
AzureIoTClient | 55:59b527ab3452 | 207 | /* Codes_SRS_IOTHUB_MQTT_TRANSPORT_07_003: [ If a failure is encountered IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK shall return a non-NULL value. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 208 | LogError("connection status callback vector push failed."); |
AzureIoTClient | 60:41648c4e7036 | 209 | result = __FAILURE__; |
AzureIoTClient | 55:59b527ab3452 | 210 | } |
AzureIoTClient | 55:59b527ab3452 | 211 | else |
AzureIoTClient | 55:59b527ab3452 | 212 | { |
AzureIoTClient | 55:59b527ab3452 | 213 | /*Codes_SRS_IOTHUB_MQTT_TRANSPORT_07_004: [ On success IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK shall return a 0 value. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 214 | result = 0; |
AzureIoTClient | 55:59b527ab3452 | 215 | } |
AzureIoTClient | 55:59b527ab3452 | 216 | free(queue_context); |
AzureIoTClient | 55:59b527ab3452 | 217 | } |
AzureIoTClient | 55:59b527ab3452 | 218 | else |
AzureIoTClient | 55:59b527ab3452 | 219 | { |
AzureIoTClient | 55:59b527ab3452 | 220 | /* Codes_SRS_IOTHUB_MQTT_TRANSPORT_07_003: [ If a failure is encountered IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK shall return a non-NULL value. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 221 | LogError("Invalid parameter: userContextCallback NULL"); |
AzureIoTClient | 60:41648c4e7036 | 222 | result = __FAILURE__; |
AzureIoTClient | 55:59b527ab3452 | 223 | } |
AzureIoTClient | 55:59b527ab3452 | 224 | return result; |
Azure.IoT.Build | 54:6dcad9019a64 | 225 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 226 | |
Azure.IoT.Build | 54:6dcad9019a64 | 227 | static void iothub_ll_connection_status_callback(IOTHUB_CLIENT_CONNECTION_STATUS result, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason, void* userContextCallback) |
Azure.IoT.Build | 54:6dcad9019a64 | 228 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 229 | IOTHUB_QUEUE_CONTEXT* queue_context = (IOTHUB_QUEUE_CONTEXT*)userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 230 | if (queue_context != NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 231 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 232 | USER_CALLBACK_INFO queue_cb_info; |
Azure.IoT.Build | 54:6dcad9019a64 | 233 | queue_cb_info.type = CALLBACK_TYPE_CONNECTION_STATUS; |
Azure.IoT.Build | 54:6dcad9019a64 | 234 | queue_cb_info.userContextCallback = queue_context->userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 235 | queue_cb_info.iothub_callback.connection_status_cb_info.status_reason = reason; |
Azure.IoT.Build | 54:6dcad9019a64 | 236 | queue_cb_info.iothub_callback.connection_status_cb_info.connection_status = result; |
Azure.IoT.Build | 54:6dcad9019a64 | 237 | if (VECTOR_push_back(queue_context->iotHubClientHandle->saved_user_callback_list, &queue_cb_info, 1) != 0) |
Azure.IoT.Build | 54:6dcad9019a64 | 238 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 239 | LogError("connection status callback vector push failed."); |
Azure.IoT.Build | 54:6dcad9019a64 | 240 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 241 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 242 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 243 | |
Azure.IoT.Build | 54:6dcad9019a64 | 244 | static void iothub_ll_event_confirm_callback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback) |
Azure.IoT.Build | 54:6dcad9019a64 | 245 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 246 | IOTHUB_QUEUE_CONTEXT* queue_context = (IOTHUB_QUEUE_CONTEXT*)userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 247 | if (queue_context != NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 248 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 249 | USER_CALLBACK_INFO queue_cb_info; |
Azure.IoT.Build | 54:6dcad9019a64 | 250 | queue_cb_info.type = CALLBACK_TYPE_EVENT_CONFIRM; |
Azure.IoT.Build | 54:6dcad9019a64 | 251 | queue_cb_info.userContextCallback = queue_context->userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 252 | queue_cb_info.iothub_callback.event_confirm_cb_info.confirm_result = result; |
Azure.IoT.Build | 54:6dcad9019a64 | 253 | if (VECTOR_push_back(queue_context->iotHubClientHandle->saved_user_callback_list, &queue_cb_info, 1) != 0) |
Azure.IoT.Build | 54:6dcad9019a64 | 254 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 255 | LogError("event confirm callback vector push failed."); |
Azure.IoT.Build | 54:6dcad9019a64 | 256 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 257 | free(queue_context); |
Azure.IoT.Build | 54:6dcad9019a64 | 258 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 259 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 260 | |
Azure.IoT.Build | 54:6dcad9019a64 | 261 | static void iothub_ll_reported_state_callback(int status_code, void* userContextCallback) |
Azure.IoT.Build | 54:6dcad9019a64 | 262 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 263 | IOTHUB_QUEUE_CONTEXT* queue_context = (IOTHUB_QUEUE_CONTEXT*)userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 264 | if (queue_context != NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 265 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 266 | USER_CALLBACK_INFO queue_cb_info; |
Azure.IoT.Build | 54:6dcad9019a64 | 267 | queue_cb_info.type = CALLBACK_TYPE_REPORTED_STATE; |
Azure.IoT.Build | 54:6dcad9019a64 | 268 | queue_cb_info.userContextCallback = queue_context->userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 269 | queue_cb_info.iothub_callback.reported_state_cb_info.status_code = status_code; |
Azure.IoT.Build | 54:6dcad9019a64 | 270 | if (VECTOR_push_back(queue_context->iotHubClientHandle->saved_user_callback_list, &queue_cb_info, 1) != 0) |
Azure.IoT.Build | 54:6dcad9019a64 | 271 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 272 | LogError("reported state callback vector push failed."); |
Azure.IoT.Build | 54:6dcad9019a64 | 273 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 274 | free(queue_context); |
Azure.IoT.Build | 54:6dcad9019a64 | 275 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 276 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 277 | |
Azure.IoT.Build | 54:6dcad9019a64 | 278 | static void iothub_ll_device_twin_callback(DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char* payLoad, size_t size, void* userContextCallback) |
Azure.IoT.Build | 54:6dcad9019a64 | 279 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 280 | IOTHUB_QUEUE_CONTEXT* queue_context = (IOTHUB_QUEUE_CONTEXT*)userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 281 | if (queue_context != NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 282 | { |
AzureIoTClient | 55:59b527ab3452 | 283 | int push_to_vector; |
AzureIoTClient | 55:59b527ab3452 | 284 | |
Azure.IoT.Build | 54:6dcad9019a64 | 285 | USER_CALLBACK_INFO queue_cb_info; |
Azure.IoT.Build | 54:6dcad9019a64 | 286 | queue_cb_info.type = CALLBACK_TYPE_DEVICE_TWIN; |
Azure.IoT.Build | 54:6dcad9019a64 | 287 | queue_cb_info.userContextCallback = queue_context->userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 288 | queue_cb_info.iothub_callback.dev_twin_cb_info.update_state = update_state; |
Azure.IoT.Build | 54:6dcad9019a64 | 289 | if (payLoad == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 290 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 291 | queue_cb_info.iothub_callback.dev_twin_cb_info.payLoad = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 292 | queue_cb_info.iothub_callback.dev_twin_cb_info.size = 0; |
AzureIoTClient | 55:59b527ab3452 | 293 | push_to_vector = 0; |
Azure.IoT.Build | 54:6dcad9019a64 | 294 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 295 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 296 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 297 | queue_cb_info.iothub_callback.dev_twin_cb_info.payLoad = (unsigned char*)malloc(size); |
Azure.IoT.Build | 54:6dcad9019a64 | 298 | if (queue_cb_info.iothub_callback.dev_twin_cb_info.payLoad == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 299 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 300 | LogError("failure allocating payload in device twin callback."); |
Azure.IoT.Build | 54:6dcad9019a64 | 301 | queue_cb_info.iothub_callback.dev_twin_cb_info.size = 0; |
AzureIoTClient | 60:41648c4e7036 | 302 | push_to_vector = __FAILURE__; |
Azure.IoT.Build | 54:6dcad9019a64 | 303 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 304 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 305 | { |
AzureIoTClient | 55:59b527ab3452 | 306 | (void)memcpy(queue_cb_info.iothub_callback.dev_twin_cb_info.payLoad, payLoad, size); |
Azure.IoT.Build | 54:6dcad9019a64 | 307 | queue_cb_info.iothub_callback.dev_twin_cb_info.size = size; |
AzureIoTClient | 55:59b527ab3452 | 308 | push_to_vector = 0; |
Azure.IoT.Build | 54:6dcad9019a64 | 309 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 310 | } |
AzureIoTClient | 55:59b527ab3452 | 311 | if (push_to_vector == 0) |
Azure.IoT.Build | 54:6dcad9019a64 | 312 | { |
AzureIoTClient | 55:59b527ab3452 | 313 | if (VECTOR_push_back(queue_context->iotHubClientHandle->saved_user_callback_list, &queue_cb_info, 1) != 0) |
AzureIoTClient | 55:59b527ab3452 | 314 | { |
AzureIoTClient | 55:59b527ab3452 | 315 | if (queue_cb_info.iothub_callback.dev_twin_cb_info.payLoad != NULL) |
AzureIoTClient | 55:59b527ab3452 | 316 | { |
AzureIoTClient | 55:59b527ab3452 | 317 | free(queue_cb_info.iothub_callback.dev_twin_cb_info.payLoad); |
AzureIoTClient | 55:59b527ab3452 | 318 | } |
AzureIoTClient | 55:59b527ab3452 | 319 | LogError("device twin callback userContextCallback vector push failed."); |
AzureIoTClient | 55:59b527ab3452 | 320 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 321 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 322 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 323 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 324 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 325 | LogError("device twin callback userContextCallback NULL"); |
Azure.IoT.Build | 54:6dcad9019a64 | 326 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 327 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 328 | |
Azure.IoT.Build | 54:6dcad9019a64 | 329 | static void dispatch_user_callbacks(IOTHUB_CLIENT_INSTANCE* iotHubClientInstance) |
Azure.IoT.Build | 54:6dcad9019a64 | 330 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 331 | if (Lock(iotHubClientInstance->LockHandle) == LOCK_OK) |
Azure.IoT.Build | 54:6dcad9019a64 | 332 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 333 | size_t callbacks_length = VECTOR_size(iotHubClientInstance->saved_user_callback_list); |
AzureIoTClient | 57:4524910c6445 | 334 | size_t index = 0; |
AzureIoTClient | 57:4524910c6445 | 335 | for (index = 0; index < callbacks_length; index++) |
Azure.IoT.Build | 54:6dcad9019a64 | 336 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 337 | USER_CALLBACK_INFO* queued_cb = (USER_CALLBACK_INFO*)VECTOR_element(iotHubClientInstance->saved_user_callback_list, index); |
Azure.IoT.Build | 54:6dcad9019a64 | 338 | if (queued_cb != NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 339 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 340 | switch (queued_cb->type) |
Azure.IoT.Build | 54:6dcad9019a64 | 341 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 342 | case CALLBACK_TYPE_DEVICE_TWIN: |
Azure.IoT.Build | 54:6dcad9019a64 | 343 | if (iotHubClientInstance->desired_state_callback) |
Azure.IoT.Build | 54:6dcad9019a64 | 344 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 345 | (void)Unlock(iotHubClientInstance->LockHandle); |
Azure.IoT.Build | 54:6dcad9019a64 | 346 | iotHubClientInstance->desired_state_callback(queued_cb->iothub_callback.dev_twin_cb_info.update_state, queued_cb->iothub_callback.dev_twin_cb_info.payLoad, queued_cb->iothub_callback.dev_twin_cb_info.size, queued_cb->userContextCallback); |
Azure.IoT.Build | 54:6dcad9019a64 | 347 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
Azure.IoT.Build | 54:6dcad9019a64 | 348 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 349 | LogError("Failed locking desired callback"); |
Azure.IoT.Build | 54:6dcad9019a64 | 350 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 351 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 352 | if (queued_cb->iothub_callback.dev_twin_cb_info.payLoad) |
Azure.IoT.Build | 54:6dcad9019a64 | 353 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 354 | free(queued_cb->iothub_callback.dev_twin_cb_info.payLoad); |
Azure.IoT.Build | 54:6dcad9019a64 | 355 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 356 | break; |
Azure.IoT.Build | 54:6dcad9019a64 | 357 | case CALLBACK_TYPE_EVENT_CONFIRM: |
Azure.IoT.Build | 54:6dcad9019a64 | 358 | if (iotHubClientInstance->event_confirm_callback) |
Azure.IoT.Build | 54:6dcad9019a64 | 359 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 360 | (void)Unlock(iotHubClientInstance->LockHandle); |
Azure.IoT.Build | 54:6dcad9019a64 | 361 | iotHubClientInstance->event_confirm_callback(queued_cb->iothub_callback.event_confirm_cb_info.confirm_result, queued_cb->userContextCallback); |
Azure.IoT.Build | 54:6dcad9019a64 | 362 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
Azure.IoT.Build | 54:6dcad9019a64 | 363 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 364 | LogError("Failed locking after event confirm callback"); |
Azure.IoT.Build | 54:6dcad9019a64 | 365 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 366 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 367 | break; |
Azure.IoT.Build | 54:6dcad9019a64 | 368 | case CALLBACK_TYPE_REPORTED_STATE: |
Azure.IoT.Build | 54:6dcad9019a64 | 369 | if (iotHubClientInstance->reported_state_callback) |
Azure.IoT.Build | 54:6dcad9019a64 | 370 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 371 | (void)Unlock(iotHubClientInstance->LockHandle); |
Azure.IoT.Build | 54:6dcad9019a64 | 372 | iotHubClientInstance->reported_state_callback(queued_cb->iothub_callback.reported_state_cb_info.status_code, queued_cb->userContextCallback); |
Azure.IoT.Build | 54:6dcad9019a64 | 373 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
Azure.IoT.Build | 54:6dcad9019a64 | 374 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 375 | LogError("Failed locking after reported state callback"); |
Azure.IoT.Build | 54:6dcad9019a64 | 376 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 377 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 378 | break; |
Azure.IoT.Build | 54:6dcad9019a64 | 379 | case CALLBACK_TYPE_CONNECTION_STATUS: |
Azure.IoT.Build | 54:6dcad9019a64 | 380 | if (iotHubClientInstance->connection_status_callback) |
Azure.IoT.Build | 54:6dcad9019a64 | 381 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 382 | (void)Unlock(iotHubClientInstance->LockHandle); |
Azure.IoT.Build | 54:6dcad9019a64 | 383 | iotHubClientInstance->connection_status_callback(queued_cb->iothub_callback.connection_status_cb_info.connection_status, queued_cb->iothub_callback.connection_status_cb_info.status_reason, queued_cb->userContextCallback); |
Azure.IoT.Build | 54:6dcad9019a64 | 384 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
Azure.IoT.Build | 54:6dcad9019a64 | 385 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 386 | LogError("Failed locking after connection status callback"); |
Azure.IoT.Build | 54:6dcad9019a64 | 387 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 388 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 389 | break; |
AzureIoTClient | 55:59b527ab3452 | 390 | case CALLBACK_TYPE_DEVICE_METHOD: |
AzureIoTClient | 56:fdda9c1244e4 | 391 | if (iotHubClientInstance->device_method_callback) |
AzureIoTClient | 55:59b527ab3452 | 392 | { |
AzureIoTClient | 55:59b527ab3452 | 393 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 55:59b527ab3452 | 394 | const char* method_name = STRING_c_str(queued_cb->iothub_callback.method_cb_info.method_name); |
AzureIoTClient | 55:59b527ab3452 | 395 | const unsigned char* payload = BUFFER_u_char(queued_cb->iothub_callback.method_cb_info.payload); |
AzureIoTClient | 55:59b527ab3452 | 396 | size_t payload_len = BUFFER_length(queued_cb->iothub_callback.method_cb_info.payload); |
AzureIoTClient | 55:59b527ab3452 | 397 | iotHubClientInstance->device_method_callback(method_name, payload, payload_len, queued_cb->iothub_callback.method_cb_info.method_id, queued_cb->userContextCallback); |
AzureIoTClient | 55:59b527ab3452 | 398 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 55:59b527ab3452 | 399 | { |
AzureIoTClient | 55:59b527ab3452 | 400 | LogError("Failed locking after connection status callback"); |
AzureIoTClient | 55:59b527ab3452 | 401 | } |
AzureIoTClient | 55:59b527ab3452 | 402 | BUFFER_delete(queued_cb->iothub_callback.method_cb_info.payload); |
AzureIoTClient | 55:59b527ab3452 | 403 | STRING_delete(queued_cb->iothub_callback.method_cb_info.method_name); |
AzureIoTClient | 55:59b527ab3452 | 404 | } |
AzureIoTClient | 55:59b527ab3452 | 405 | break; |
AzureIoTClient | 56:fdda9c1244e4 | 406 | default: |
AzureIoTClient | 56:fdda9c1244e4 | 407 | LogError("Invalid callback type '%s'", ENUM_TO_STRING(USER_CALLBACK_TYPE, queued_cb->type)); |
AzureIoTClient | 56:fdda9c1244e4 | 408 | break; |
Azure.IoT.Build | 54:6dcad9019a64 | 409 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 410 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 411 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 412 | VECTOR_clear(iotHubClientInstance->saved_user_callback_list); |
Azure.IoT.Build | 54:6dcad9019a64 | 413 | (void)Unlock(iotHubClientInstance->LockHandle); |
Azure.IoT.Build | 54:6dcad9019a64 | 414 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 415 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 416 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 417 | LogError("Unable to aquire lock"); |
Azure.IoT.Build | 54:6dcad9019a64 | 418 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 419 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 420 | |
AzureIoTClient | 16:deba40344375 | 421 | static int ScheduleWork_Thread(void* threadArgument) |
AzureIoTClient | 16:deba40344375 | 422 | { |
AzureIoTClient | 16:deba40344375 | 423 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)threadArgument; |
AzureIoTClient | 42:448eecc3676e | 424 | |
Azure.IoT Build | 37:18310e4d888d | 425 | while (1) |
AzureIoTClient | 16:deba40344375 | 426 | { |
AzureIoTClient | 16:deba40344375 | 427 | if (Lock(iotHubClientInstance->LockHandle) == LOCK_OK) |
AzureIoTClient | 16:deba40344375 | 428 | { |
Azure.IoT Build | 37:18310e4d888d | 429 | /*Codes_SRS_IOTHUBCLIENT_01_038: [ The thread shall exit when IoTHubClient_Destroy is called. ]*/ |
Azure.IoT Build | 37:18310e4d888d | 430 | if (iotHubClientInstance->StopThread) |
Azure.IoT Build | 37:18310e4d888d | 431 | { |
Azure.IoT Build | 37:18310e4d888d | 432 | (void)Unlock(iotHubClientInstance->LockHandle); |
Azure.IoT Build | 37:18310e4d888d | 433 | break; /*gets out of the thread*/ |
Azure.IoT Build | 37:18310e4d888d | 434 | } |
Azure.IoT Build | 37:18310e4d888d | 435 | else |
Azure.IoT Build | 37:18310e4d888d | 436 | { |
Azure.IoT Build | 37:18310e4d888d | 437 | /* Codes_SRS_IOTHUBCLIENT_01_037: [The thread created by IoTHubClient_SendEvent or IoTHubClient_SetMessageCallback shall call IoTHubClient_LL_DoWork every 1 ms.] */ |
Azure.IoT Build | 37:18310e4d888d | 438 | /* Codes_SRS_IOTHUBCLIENT_01_039: [All calls to IoTHubClient_LL_DoWork shall be protected by the lock created in IotHubClient_Create.] */ |
Azure.IoT Build | 37:18310e4d888d | 439 | IoTHubClient_LL_DoWork(iotHubClientInstance->IoTHubClientLLHandle); |
AzureIoTClient | 42:448eecc3676e | 440 | |
AzureIoTClient | 44:33dd78697616 | 441 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 442 | garbageCollectorImpl(iotHubClientInstance); |
AzureIoTClient | 43:038d8511e817 | 443 | #endif |
Azure.IoT Build | 37:18310e4d888d | 444 | (void)Unlock(iotHubClientInstance->LockHandle); |
Azure.IoT Build | 37:18310e4d888d | 445 | } |
AzureIoTClient | 16:deba40344375 | 446 | } |
Azure.IoT Build | 37:18310e4d888d | 447 | else |
Azure.IoT Build | 37:18310e4d888d | 448 | { |
Azure.IoT Build | 37:18310e4d888d | 449 | /*Codes_SRS_IOTHUBCLIENT_01_040: [If acquiring the lock fails, IoTHubClient_LL_DoWork shall not be called.]*/ |
Azure.IoT Build | 37:18310e4d888d | 450 | /*no code, shall retry*/ |
Azure.IoT Build | 37:18310e4d888d | 451 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 452 | dispatch_user_callbacks(iotHubClientInstance); |
Azure.IoT Build | 37:18310e4d888d | 453 | (void)ThreadAPI_Sleep(1); |
AzureIoTClient | 16:deba40344375 | 454 | } |
AzureIoTClient | 42:448eecc3676e | 455 | |
AzureIoTClient | 16:deba40344375 | 456 | return 0; |
AzureIoTClient | 16:deba40344375 | 457 | } |
AzureIoTClient | 16:deba40344375 | 458 | |
Azure.IoT Build | 37:18310e4d888d | 459 | static IOTHUB_CLIENT_RESULT StartWorkerThreadIfNeeded(IOTHUB_CLIENT_INSTANCE* iotHubClientInstance) |
AzureIoTClient | 16:deba40344375 | 460 | { |
AzureIoTClient | 42:448eecc3676e | 461 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 42:448eecc3676e | 462 | if (iotHubClientInstance->TransportHandle == NULL) |
AzureIoTClient | 42:448eecc3676e | 463 | { |
AzureIoTClient | 42:448eecc3676e | 464 | if (iotHubClientInstance->ThreadHandle == NULL) |
AzureIoTClient | 42:448eecc3676e | 465 | { |
AzureIoTClient | 42:448eecc3676e | 466 | iotHubClientInstance->StopThread = 0; |
AzureIoTClient | 42:448eecc3676e | 467 | if (ThreadAPI_Create(&iotHubClientInstance->ThreadHandle, ScheduleWork_Thread, iotHubClientInstance) != THREADAPI_OK) |
AzureIoTClient | 42:448eecc3676e | 468 | { |
AzureIoTClient | 42:448eecc3676e | 469 | iotHubClientInstance->ThreadHandle = NULL; |
AzureIoTClient | 42:448eecc3676e | 470 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 471 | } |
AzureIoTClient | 42:448eecc3676e | 472 | else |
AzureIoTClient | 42:448eecc3676e | 473 | { |
AzureIoTClient | 42:448eecc3676e | 474 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 42:448eecc3676e | 475 | } |
AzureIoTClient | 42:448eecc3676e | 476 | } |
AzureIoTClient | 42:448eecc3676e | 477 | else |
AzureIoTClient | 42:448eecc3676e | 478 | { |
AzureIoTClient | 42:448eecc3676e | 479 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 42:448eecc3676e | 480 | } |
AzureIoTClient | 42:448eecc3676e | 481 | } |
AzureIoTClient | 42:448eecc3676e | 482 | else |
AzureIoTClient | 42:448eecc3676e | 483 | { |
AzureIoTClient | 42:448eecc3676e | 484 | /*Codes_SRS_IOTHUBCLIENT_17_012: [ If the transport connection is shared, the thread shall be started by calling IoTHubTransport_StartWorkerThread. ]*/ |
AzureIoTClient | 42:448eecc3676e | 485 | /*Codes_SRS_IOTHUBCLIENT_17_011: [ If the transport connection is shared, the thread shall be started by calling IoTHubTransport_StartWorkerThread*/ |
AzureIoTClient | 42:448eecc3676e | 486 | result = IoTHubTransport_StartWorkerThread(iotHubClientInstance->TransportHandle, iotHubClientInstance); |
AzureIoTClient | 42:448eecc3676e | 487 | } |
AzureIoTClient | 42:448eecc3676e | 488 | return result; |
AzureIoTClient | 16:deba40344375 | 489 | } |
AzureIoTClient | 16:deba40344375 | 490 | |
Azure.IoT.Build | 54:6dcad9019a64 | 491 | static IOTHUB_CLIENT_INSTANCE* create_iothub_instance(const IOTHUB_CLIENT_CONFIG* config, TRANSPORT_HANDLE transportHandle, const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol) |
AzureIoTClient | 16:deba40344375 | 492 | { |
AzureIoTClient | 16:deba40344375 | 493 | IOTHUB_CLIENT_INSTANCE* result = (IOTHUB_CLIENT_INSTANCE*)malloc(sizeof(IOTHUB_CLIENT_INSTANCE)); |
AzureIoTClient | 16:deba40344375 | 494 | |
AzureIoTClient | 16:deba40344375 | 495 | /* Codes_SRS_IOTHUBCLIENT_01_004: [If allocating memory for the new IoTHubClient instance fails, then IoTHubClient_Create shall return NULL.] */ |
AzureIoTClient | 16:deba40344375 | 496 | if (result != NULL) |
AzureIoTClient | 16:deba40344375 | 497 | { |
AzureIoTClient | 16:deba40344375 | 498 | /* Codes_SRS_IOTHUBCLIENT_01_029: [IoTHubClient_Create shall create a lock object to be used later for serializing IoTHubClient calls.] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 499 | if ( (result->saved_user_callback_list = VECTOR_create(sizeof(USER_CALLBACK_INFO)) ) == NULL) |
AzureIoTClient | 16:deba40344375 | 500 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 501 | LogError("Failed creating VECTOR"); |
AzureIoTClient | 16:deba40344375 | 502 | free(result); |
AzureIoTClient | 16:deba40344375 | 503 | result = NULL; |
AzureIoTClient | 16:deba40344375 | 504 | } |
AzureIoTClient | 16:deba40344375 | 505 | else |
AzureIoTClient | 16:deba40344375 | 506 | { |
AzureIoTClient | 44:33dd78697616 | 507 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 52:1cc3c6d07cad | 508 | /*Codes_SRS_IOTHUBCLIENT_02_060: [ IoTHubClient_Create shall create a SINGLYLINKEDLIST_HANDLE containing THREAD_HANDLE (created by future calls to IoTHubClient_UploadToBlobAsync). ]*/ |
AzureIoTClient | 52:1cc3c6d07cad | 509 | if ((result->savedDataToBeCleaned = singlylinkedlist_create()) == NULL) |
AzureIoTClient | 16:deba40344375 | 510 | { |
AzureIoTClient | 52:1cc3c6d07cad | 511 | /*Codes_SRS_IOTHUBCLIENT_02_061: [ If creating the SINGLYLINKEDLIST_HANDLE fails then IoTHubClient_Create shall fail and return NULL. ]*/ |
AzureIoTClient | 52:1cc3c6d07cad | 512 | LogError("unable to singlylinkedlist_create"); |
Azure.IoT.Build | 54:6dcad9019a64 | 513 | VECTOR_destroy(result->saved_user_callback_list); |
AzureIoTClient | 16:deba40344375 | 514 | free(result); |
AzureIoTClient | 16:deba40344375 | 515 | result = NULL; |
AzureIoTClient | 16:deba40344375 | 516 | } |
AzureIoTClient | 42:448eecc3676e | 517 | else |
AzureIoTClient | 43:038d8511e817 | 518 | #endif |
AzureIoTClient | 42:448eecc3676e | 519 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 520 | result->TransportHandle = transportHandle; |
Azure.IoT.Build | 54:6dcad9019a64 | 521 | result->created_with_transport_handle = 0; |
Azure.IoT.Build | 54:6dcad9019a64 | 522 | if (config != NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 523 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 524 | if (transportHandle != NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 525 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 526 | /*Codes_SRS_IOTHUBCLIENT_17_005: [ IoTHubClient_CreateWithTransport shall call IoTHubTransport_GetLock to get the transport lock to be used later for serializing IoTHubClient calls. ]*/ |
Azure.IoT.Build | 54:6dcad9019a64 | 527 | result->LockHandle = IoTHubTransport_GetLock(transportHandle); |
Azure.IoT.Build | 54:6dcad9019a64 | 528 | if (result->LockHandle == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 529 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 530 | LogError("unable to IoTHubTransport_GetLock"); |
Azure.IoT.Build | 54:6dcad9019a64 | 531 | result->IoTHubClientLLHandle = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 532 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 533 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 534 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 535 | IOTHUB_CLIENT_DEVICE_CONFIG deviceConfig; |
Azure.IoT.Build | 54:6dcad9019a64 | 536 | deviceConfig.deviceId = config->deviceId; |
Azure.IoT.Build | 54:6dcad9019a64 | 537 | deviceConfig.deviceKey = config->deviceKey; |
Azure.IoT.Build | 54:6dcad9019a64 | 538 | deviceConfig.protocol = config->protocol; |
Azure.IoT.Build | 54:6dcad9019a64 | 539 | deviceConfig.deviceSasToken = config->deviceSasToken; |
Azure.IoT.Build | 54:6dcad9019a64 | 540 | |
Azure.IoT.Build | 54:6dcad9019a64 | 541 | /*Codes_SRS_IOTHUBCLIENT_17_003: [ IoTHubClient_CreateWithTransport shall call IoTHubTransport_GetLLTransport on transportHandle to get lower layer transport. ]*/ |
Azure.IoT.Build | 54:6dcad9019a64 | 542 | deviceConfig.transportHandle = IoTHubTransport_GetLLTransport(transportHandle); |
Azure.IoT.Build | 54:6dcad9019a64 | 543 | if (deviceConfig.transportHandle == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 544 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 545 | LogError("unable to IoTHubTransport_GetLLTransport"); |
Azure.IoT.Build | 54:6dcad9019a64 | 546 | result->IoTHubClientLLHandle = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 547 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 548 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 549 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 550 | if (Lock(result->LockHandle) != LOCK_OK) |
Azure.IoT.Build | 54:6dcad9019a64 | 551 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 552 | LogError("unable to Lock"); |
Azure.IoT.Build | 54:6dcad9019a64 | 553 | result->IoTHubClientLLHandle = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 554 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 555 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 556 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 557 | /*Codes_SRS_IOTHUBCLIENT_17_007: [ IoTHubClient_CreateWithTransport shall instantiate a new IoTHubClient_LL instance by calling IoTHubClient_LL_CreateWithTransport and passing the lower layer transport and config argument. ]*/ |
Azure.IoT.Build | 54:6dcad9019a64 | 558 | result->IoTHubClientLLHandle = IoTHubClient_LL_CreateWithTransport(&deviceConfig); |
Azure.IoT.Build | 54:6dcad9019a64 | 559 | result->created_with_transport_handle = 1; |
Azure.IoT.Build | 54:6dcad9019a64 | 560 | if (Unlock(result->LockHandle) != LOCK_OK) |
Azure.IoT.Build | 54:6dcad9019a64 | 561 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 562 | LogError("unable to Unlock"); |
Azure.IoT.Build | 54:6dcad9019a64 | 563 | result->IoTHubClientLLHandle = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 564 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 565 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 566 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 567 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 568 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 569 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 570 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 571 | result->LockHandle = Lock_Init(); |
Azure.IoT.Build | 54:6dcad9019a64 | 572 | if (result->LockHandle == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 573 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 574 | /* Codes_SRS_IOTHUBCLIENT_01_030: [If creating the lock fails, then IoTHubClient_Create shall return NULL.] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 575 | /* Codes_SRS_IOTHUBCLIENT_01_031: [If IoTHubClient_Create fails, all resources allocated by it shall be freed.] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 576 | LogError("Failure creating Lock object"); |
Azure.IoT.Build | 54:6dcad9019a64 | 577 | result->IoTHubClientLLHandle = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 578 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 579 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 580 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 581 | /* Codes_SRS_IOTHUBCLIENT_01_002: [IoTHubClient_Create shall instantiate a new IoTHubClient_LL instance by calling IoTHubClient_LL_Create and passing the config argument.] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 582 | result->IoTHubClientLLHandle = IoTHubClient_LL_Create(config); |
Azure.IoT.Build | 54:6dcad9019a64 | 583 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 584 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 585 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 586 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 587 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 588 | result->LockHandle = Lock_Init(); |
Azure.IoT.Build | 54:6dcad9019a64 | 589 | if (result->LockHandle == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 590 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 591 | /* Codes_SRS_IOTHUBCLIENT_01_030: [If creating the lock fails, then IoTHubClient_Create shall return NULL.] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 592 | /* Codes_SRS_IOTHUBCLIENT_01_031: [If IoTHubClient_Create fails, all resources allocated by it shall be freed.] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 593 | LogError("Failure creating Lock object"); |
Azure.IoT.Build | 54:6dcad9019a64 | 594 | result->IoTHubClientLLHandle = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 595 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 596 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 597 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 598 | /* Codes_SRS_IOTHUBCLIENT_12_006: [IoTHubClient_CreateFromConnectionString shall instantiate a new IoTHubClient_LL instance by calling IoTHubClient_LL_CreateFromConnectionString and passing the connectionString] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 599 | result->IoTHubClientLLHandle = IoTHubClient_LL_CreateFromConnectionString(connectionString, protocol); |
Azure.IoT.Build | 54:6dcad9019a64 | 600 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 601 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 602 | |
AzureIoTClient | 42:448eecc3676e | 603 | if (result->IoTHubClientLLHandle == NULL) |
AzureIoTClient | 42:448eecc3676e | 604 | { |
AzureIoTClient | 42:448eecc3676e | 605 | /* Codes_SRS_IOTHUBCLIENT_01_003: [If IoTHubClient_LL_Create fails, then IoTHubClient_Create shall return NULL.] */ |
AzureIoTClient | 42:448eecc3676e | 606 | /* Codes_SRS_IOTHUBCLIENT_01_031: [If IoTHubClient_Create fails, all resources allocated by it shall be freed.] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 607 | /* Codes_SRS_IOTHUBCLIENT_17_006: [ If IoTHubTransport_GetLock fails, then IoTHubClient_CreateWithTransport shall return NULL. ]*/ |
Azure.IoT.Build | 54:6dcad9019a64 | 608 | if (transportHandle == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 609 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 610 | Lock_Deinit(result->LockHandle); |
Azure.IoT.Build | 54:6dcad9019a64 | 611 | } |
AzureIoTClient | 44:33dd78697616 | 612 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 52:1cc3c6d07cad | 613 | singlylinkedlist_destroy(result->savedDataToBeCleaned); |
AzureIoTClient | 43:038d8511e817 | 614 | #endif |
Azure.IoT.Build | 54:6dcad9019a64 | 615 | LogError("Failure creating iothub handle"); |
Azure.IoT.Build | 54:6dcad9019a64 | 616 | VECTOR_destroy(result->saved_user_callback_list); |
AzureIoTClient | 42:448eecc3676e | 617 | free(result); |
AzureIoTClient | 42:448eecc3676e | 618 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 619 | } |
AzureIoTClient | 42:448eecc3676e | 620 | else |
AzureIoTClient | 42:448eecc3676e | 621 | { |
AzureIoTClient | 42:448eecc3676e | 622 | result->ThreadHandle = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 623 | result->desired_state_callback = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 624 | result->event_confirm_callback = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 625 | result->reported_state_callback = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 626 | result->devicetwin_user_context = NULL; |
AzureIoTClient | 55:59b527ab3452 | 627 | result->connection_status_callback = NULL; |
AzureIoTClient | 55:59b527ab3452 | 628 | result->connection_status_user_context = NULL; |
AzureIoTClient | 42:448eecc3676e | 629 | } |
AzureIoTClient | 42:448eecc3676e | 630 | } |
AzureIoTClient | 16:deba40344375 | 631 | } |
AzureIoTClient | 16:deba40344375 | 632 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 633 | return result; |
Azure.IoT.Build | 54:6dcad9019a64 | 634 | } |
AzureIoTClient | 16:deba40344375 | 635 | |
Azure.IoT.Build | 54:6dcad9019a64 | 636 | IOTHUB_CLIENT_HANDLE IoTHubClient_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol) |
Azure.IoT.Build | 54:6dcad9019a64 | 637 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 638 | IOTHUB_CLIENT_INSTANCE* result; |
Azure.IoT.Build | 54:6dcad9019a64 | 639 | |
Azure.IoT.Build | 54:6dcad9019a64 | 640 | /* Codes_SRS_IOTHUBCLIENT_12_003: [IoTHubClient_CreateFromConnectionString shall verify all input parameters and if any is NULL then return NULL] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 641 | if (connectionString == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 642 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 643 | LogError("Input parameter is NULL: connectionString"); |
Azure.IoT.Build | 54:6dcad9019a64 | 644 | result = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 645 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 646 | else if (protocol == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 647 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 648 | LogError("Input parameter is NULL: protocol"); |
Azure.IoT.Build | 54:6dcad9019a64 | 649 | result = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 650 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 651 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 652 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 653 | result = create_iothub_instance(NULL, NULL, connectionString, protocol); |
Azure.IoT.Build | 54:6dcad9019a64 | 654 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 655 | return result; |
Azure.IoT.Build | 54:6dcad9019a64 | 656 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 657 | |
Azure.IoT.Build | 54:6dcad9019a64 | 658 | IOTHUB_CLIENT_HANDLE IoTHubClient_Create(const IOTHUB_CLIENT_CONFIG* config) |
Azure.IoT.Build | 54:6dcad9019a64 | 659 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 660 | IOTHUB_CLIENT_INSTANCE* result; |
Azure.IoT.Build | 54:6dcad9019a64 | 661 | if (config == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 662 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 663 | LogError("Input parameter is NULL: IOTHUB_CLIENT_CONFIG"); |
Azure.IoT.Build | 54:6dcad9019a64 | 664 | result = NULL; |
Azure.IoT.Build | 54:6dcad9019a64 | 665 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 666 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 667 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 668 | result = create_iothub_instance(config, NULL, NULL, NULL); |
Azure.IoT.Build | 54:6dcad9019a64 | 669 | } |
AzureIoTClient | 16:deba40344375 | 670 | return result; |
AzureIoTClient | 16:deba40344375 | 671 | } |
AzureIoTClient | 16:deba40344375 | 672 | |
Azure.IoT Build | 37:18310e4d888d | 673 | IOTHUB_CLIENT_HANDLE IoTHubClient_CreateWithTransport(TRANSPORT_HANDLE transportHandle, const IOTHUB_CLIENT_CONFIG* config) |
Azure.IoT Build | 37:18310e4d888d | 674 | { |
AzureIoTClient | 42:448eecc3676e | 675 | IOTHUB_CLIENT_INSTANCE* result; |
AzureIoTClient | 42:448eecc3676e | 676 | /*Codes_SRS_IOTHUBCLIENT_17_013: [ IoTHubClient_CreateWithTransport shall return NULL if transportHandle is NULL. ]*/ |
AzureIoTClient | 42:448eecc3676e | 677 | /*Codes_SRS_IOTHUBCLIENT_17_014: [ IoTHubClient_CreateWithTransport shall return NULL if config is NULL. ]*/ |
AzureIoTClient | 42:448eecc3676e | 678 | if (transportHandle == NULL || config == NULL) |
AzureIoTClient | 42:448eecc3676e | 679 | { |
AzureIoTClient | 43:038d8511e817 | 680 | LogError("invalid parameter TRANSPORT_HANDLE transportHandle=%p, const IOTHUB_CLIENT_CONFIG* config=%p", transportHandle, config); |
AzureIoTClient | 42:448eecc3676e | 681 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 682 | } |
AzureIoTClient | 42:448eecc3676e | 683 | else |
AzureIoTClient | 42:448eecc3676e | 684 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 685 | result = create_iothub_instance(config, transportHandle, NULL, NULL); |
AzureIoTClient | 42:448eecc3676e | 686 | } |
AzureIoTClient | 42:448eecc3676e | 687 | return result; |
Azure.IoT Build | 37:18310e4d888d | 688 | } |
Azure.IoT Build | 37:18310e4d888d | 689 | |
AzureIoTClient | 16:deba40344375 | 690 | /* Codes_SRS_IOTHUBCLIENT_01_005: [IoTHubClient_Destroy shall free all resources associated with the iotHubClientHandle instance.] */ |
AzureIoTClient | 18:1e9adb15c645 | 691 | void IoTHubClient_Destroy(IOTHUB_CLIENT_HANDLE iotHubClientHandle) |
AzureIoTClient | 16:deba40344375 | 692 | { |
AzureIoTClient | 16:deba40344375 | 693 | /* Codes_SRS_IOTHUBCLIENT_01_008: [IoTHubClient_Destroy shall do nothing if parameter iotHubClientHandle is NULL.] */ |
AzureIoTClient | 16:deba40344375 | 694 | if (iotHubClientHandle != NULL) |
AzureIoTClient | 16:deba40344375 | 695 | { |
AzureIoTClient | 42:448eecc3676e | 696 | bool okToJoin; |
AzureIoTClient | 55:59b527ab3452 | 697 | size_t vector_size; |
Azure.IoT Build | 37:18310e4d888d | 698 | |
AzureIoTClient | 16:deba40344375 | 699 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 16:deba40344375 | 700 | |
AzureIoTClient | 42:448eecc3676e | 701 | /*Codes_SRS_IOTHUBCLIENT_02_043: [ IoTHubClient_Destroy shall lock the serializing lock and signal the worker thread (if any) to end ]*/ |
AzureIoTClient | 42:448eecc3676e | 702 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 42:448eecc3676e | 703 | { |
AzureIoTClient | 42:448eecc3676e | 704 | LogError("unable to Lock - - will still proceed to try to end the thread without locking"); |
AzureIoTClient | 42:448eecc3676e | 705 | } |
AzureIoTClient | 42:448eecc3676e | 706 | |
AzureIoTClient | 44:33dd78697616 | 707 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 708 | /*Codes_SRS_IOTHUBCLIENT_02_069: [ IoTHubClient_Destroy shall free all data created by IoTHubClient_UploadToBlobAsync ]*/ |
AzureIoTClient | 42:448eecc3676e | 709 | /*wait for all uploading threads to finish*/ |
AzureIoTClient | 52:1cc3c6d07cad | 710 | while (singlylinkedlist_get_head_item(iotHubClientInstance->savedDataToBeCleaned) != NULL) |
AzureIoTClient | 42:448eecc3676e | 711 | { |
AzureIoTClient | 42:448eecc3676e | 712 | garbageCollectorImpl(iotHubClientInstance); |
AzureIoTClient | 42:448eecc3676e | 713 | } |
AzureIoTClient | 43:038d8511e817 | 714 | #endif |
AzureIoTClient | 16:deba40344375 | 715 | if (iotHubClientInstance->ThreadHandle != NULL) |
AzureIoTClient | 16:deba40344375 | 716 | { |
AzureIoTClient | 42:448eecc3676e | 717 | iotHubClientInstance->StopThread = 1; |
AzureIoTClient | 42:448eecc3676e | 718 | okToJoin = true; |
AzureIoTClient | 42:448eecc3676e | 719 | } |
AzureIoTClient | 42:448eecc3676e | 720 | else |
AzureIoTClient | 42:448eecc3676e | 721 | { |
AzureIoTClient | 42:448eecc3676e | 722 | okToJoin = false; |
AzureIoTClient | 16:deba40344375 | 723 | } |
Azure.IoT Build | 37:18310e4d888d | 724 | |
AzureIoTClient | 42:448eecc3676e | 725 | if (iotHubClientInstance->TransportHandle != NULL) |
AzureIoTClient | 42:448eecc3676e | 726 | { |
AzureIoTClient | 42:448eecc3676e | 727 | /*Codes_SRS_IOTHUBCLIENT_01_007: [ The thread created as part of executing IoTHubClient_SendEventAsync or IoTHubClient_SetNotificationMessageCallback shall be joined. ]*/ |
AzureIoTClient | 42:448eecc3676e | 728 | okToJoin = IoTHubTransport_SignalEndWorkerThread(iotHubClientInstance->TransportHandle, iotHubClientHandle); |
AzureIoTClient | 42:448eecc3676e | 729 | } |
AzureIoTClient | 16:deba40344375 | 730 | |
AzureIoTClient | 16:deba40344375 | 731 | /* Codes_SRS_IOTHUBCLIENT_01_006: [That includes destroying the IoTHubClient_LL instance by calling IoTHubClient_LL_Destroy.] */ |
AzureIoTClient | 16:deba40344375 | 732 | IoTHubClient_LL_Destroy(iotHubClientInstance->IoTHubClientLLHandle); |
AzureIoTClient | 16:deba40344375 | 733 | |
AzureIoTClient | 44:33dd78697616 | 734 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 43:038d8511e817 | 735 | if (iotHubClientInstance->savedDataToBeCleaned != NULL) |
AzureIoTClient | 43:038d8511e817 | 736 | { |
AzureIoTClient | 52:1cc3c6d07cad | 737 | singlylinkedlist_destroy(iotHubClientInstance->savedDataToBeCleaned); |
AzureIoTClient | 43:038d8511e817 | 738 | } |
AzureIoTClient | 43:038d8511e817 | 739 | #endif |
AzureIoTClient | 43:038d8511e817 | 740 | |
AzureIoTClient | 42:448eecc3676e | 741 | /*Codes_SRS_IOTHUBCLIENT_02_045: [ IoTHubClient_Destroy shall unlock the serializing lock. ]*/ |
AzureIoTClient | 42:448eecc3676e | 742 | if (Unlock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 42:448eecc3676e | 743 | { |
AzureIoTClient | 42:448eecc3676e | 744 | LogError("unable to Unlock"); |
AzureIoTClient | 42:448eecc3676e | 745 | } |
Azure.IoT Build | 37:18310e4d888d | 746 | |
AzureIoTClient | 42:448eecc3676e | 747 | if (okToJoin == true) |
AzureIoTClient | 42:448eecc3676e | 748 | { |
AzureIoTClient | 42:448eecc3676e | 749 | if (iotHubClientInstance->ThreadHandle != NULL) |
AzureIoTClient | 42:448eecc3676e | 750 | { |
AzureIoTClient | 42:448eecc3676e | 751 | int res; |
AzureIoTClient | 42:448eecc3676e | 752 | /*Codes_SRS_IOTHUBCLIENT_01_007: [ The thread created as part of executing IoTHubClient_SendEventAsync or IoTHubClient_SetNotificationMessageCallback shall be joined. ]*/ |
AzureIoTClient | 42:448eecc3676e | 753 | if (ThreadAPI_Join(iotHubClientInstance->ThreadHandle, &res) != THREADAPI_OK) |
AzureIoTClient | 42:448eecc3676e | 754 | { |
AzureIoTClient | 42:448eecc3676e | 755 | LogError("ThreadAPI_Join failed"); |
AzureIoTClient | 42:448eecc3676e | 756 | } |
AzureIoTClient | 42:448eecc3676e | 757 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 758 | |
AzureIoTClient | 42:448eecc3676e | 759 | if (iotHubClientInstance->TransportHandle != NULL) |
AzureIoTClient | 42:448eecc3676e | 760 | { |
AzureIoTClient | 42:448eecc3676e | 761 | /*Codes_SRS_IOTHUBCLIENT_01_007: [ The thread created as part of executing IoTHubClient_SendEventAsync or IoTHubClient_SetNotificationMessageCallback shall be joined. ]*/ |
AzureIoTClient | 42:448eecc3676e | 762 | IoTHubTransport_JoinWorkerThread(iotHubClientInstance->TransportHandle, iotHubClientHandle); |
AzureIoTClient | 42:448eecc3676e | 763 | } |
AzureIoTClient | 42:448eecc3676e | 764 | } |
AzureIoTClient | 42:448eecc3676e | 765 | |
AzureIoTClient | 55:59b527ab3452 | 766 | vector_size = VECTOR_size(iotHubClientInstance->saved_user_callback_list); |
AzureIoTClient | 57:4524910c6445 | 767 | size_t index = 0; |
AzureIoTClient | 57:4524910c6445 | 768 | for (index = 0; index < vector_size; index++) |
AzureIoTClient | 55:59b527ab3452 | 769 | { |
AzureIoTClient | 55:59b527ab3452 | 770 | USER_CALLBACK_INFO* queue_cb_info = (USER_CALLBACK_INFO*)VECTOR_element(iotHubClientInstance->saved_user_callback_list, index); |
AzureIoTClient | 55:59b527ab3452 | 771 | if (queue_cb_info != NULL) |
AzureIoTClient | 55:59b527ab3452 | 772 | { |
AzureIoTClient | 55:59b527ab3452 | 773 | if (queue_cb_info->type == CALLBACK_TYPE_DEVICE_METHOD) |
AzureIoTClient | 55:59b527ab3452 | 774 | { |
AzureIoTClient | 55:59b527ab3452 | 775 | STRING_delete(queue_cb_info->iothub_callback.method_cb_info.method_name); |
AzureIoTClient | 55:59b527ab3452 | 776 | BUFFER_delete(queue_cb_info->iothub_callback.method_cb_info.payload); |
AzureIoTClient | 55:59b527ab3452 | 777 | } |
AzureIoTClient | 55:59b527ab3452 | 778 | else if (queue_cb_info->type == CALLBACK_TYPE_DEVICE_TWIN) |
AzureIoTClient | 55:59b527ab3452 | 779 | { |
AzureIoTClient | 55:59b527ab3452 | 780 | if (queue_cb_info->iothub_callback.dev_twin_cb_info.payLoad != NULL) |
AzureIoTClient | 55:59b527ab3452 | 781 | { |
AzureIoTClient | 55:59b527ab3452 | 782 | free(queue_cb_info->iothub_callback.dev_twin_cb_info.payLoad); |
AzureIoTClient | 55:59b527ab3452 | 783 | } |
AzureIoTClient | 55:59b527ab3452 | 784 | } |
AzureIoTClient | 59:7e89be231352 | 785 | else if (queue_cb_info->type == CALLBACK_TYPE_EVENT_CONFIRM) |
AzureIoTClient | 59:7e89be231352 | 786 | { |
AzureIoTClient | 59:7e89be231352 | 787 | if (iotHubClientInstance->event_confirm_callback) |
AzureIoTClient | 59:7e89be231352 | 788 | { |
AzureIoTClient | 59:7e89be231352 | 789 | iotHubClientInstance->event_confirm_callback(queue_cb_info->iothub_callback.event_confirm_cb_info.confirm_result, queue_cb_info->userContextCallback); |
AzureIoTClient | 59:7e89be231352 | 790 | } |
AzureIoTClient | 59:7e89be231352 | 791 | } |
AzureIoTClient | 55:59b527ab3452 | 792 | } |
AzureIoTClient | 55:59b527ab3452 | 793 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 794 | VECTOR_destroy(iotHubClientInstance->saved_user_callback_list); |
Azure.IoT.Build | 54:6dcad9019a64 | 795 | |
AzureIoTClient | 42:448eecc3676e | 796 | if (iotHubClientInstance->TransportHandle == NULL) |
AzureIoTClient | 42:448eecc3676e | 797 | { |
AzureIoTClient | 42:448eecc3676e | 798 | /* Codes_SRS_IOTHUBCLIENT_01_032: [If the lock was allocated in IoTHubClient_Create, it shall be also freed..] */ |
AzureIoTClient | 42:448eecc3676e | 799 | Lock_Deinit(iotHubClientInstance->LockHandle); |
AzureIoTClient | 42:448eecc3676e | 800 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 801 | if (iotHubClientInstance->devicetwin_user_context != NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 802 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 803 | free(iotHubClientInstance->devicetwin_user_context); |
Azure.IoT.Build | 54:6dcad9019a64 | 804 | } |
AzureIoTClient | 55:59b527ab3452 | 805 | if (iotHubClientInstance->connection_status_user_context != NULL) |
AzureIoTClient | 55:59b527ab3452 | 806 | { |
AzureIoTClient | 55:59b527ab3452 | 807 | free(iotHubClientInstance->connection_status_user_context); |
AzureIoTClient | 55:59b527ab3452 | 808 | } |
AzureIoTClient | 16:deba40344375 | 809 | free(iotHubClientInstance); |
AzureIoTClient | 16:deba40344375 | 810 | } |
AzureIoTClient | 16:deba40344375 | 811 | } |
AzureIoTClient | 16:deba40344375 | 812 | |
AzureIoTClient | 16:deba40344375 | 813 | IOTHUB_CLIENT_RESULT IoTHubClient_SendEventAsync(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK eventConfirmationCallback, void* userContextCallback) |
AzureIoTClient | 16:deba40344375 | 814 | { |
AzureIoTClient | 16:deba40344375 | 815 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 16:deba40344375 | 816 | |
AzureIoTClient | 16:deba40344375 | 817 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 16:deba40344375 | 818 | { |
AzureIoTClient | 16:deba40344375 | 819 | /* Codes_SRS_IOTHUBCLIENT_01_011: [If iotHubClientHandle is NULL, IoTHubClient_SendEventAsync shall return IOTHUB_CLIENT_INVALID_ARG.] */ |
AzureIoTClient | 16:deba40344375 | 820 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 39:2719651a5bee | 821 | LogError("NULL iothubClientHandle"); |
AzureIoTClient | 16:deba40344375 | 822 | } |
AzureIoTClient | 16:deba40344375 | 823 | else |
AzureIoTClient | 16:deba40344375 | 824 | { |
AzureIoTClient | 16:deba40344375 | 825 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 16:deba40344375 | 826 | |
AzureIoTClient | 16:deba40344375 | 827 | /* Codes_SRS_IOTHUBCLIENT_01_025: [IoTHubClient_SendEventAsync shall be made thread-safe by using the lock created in IoTHubClient_Create.] */ |
AzureIoTClient | 16:deba40344375 | 828 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 16:deba40344375 | 829 | { |
AzureIoTClient | 16:deba40344375 | 830 | /* Codes_SRS_IOTHUBCLIENT_01_026: [If acquiring the lock fails, IoTHubClient_SendEventAsync shall return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 16:deba40344375 | 831 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 39:2719651a5bee | 832 | LogError("Could not acquire lock"); |
AzureIoTClient | 16:deba40344375 | 833 | } |
AzureIoTClient | 16:deba40344375 | 834 | else |
AzureIoTClient | 16:deba40344375 | 835 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 836 | if (iotHubClientInstance->created_with_transport_handle == 0) |
Azure.IoT.Build | 54:6dcad9019a64 | 837 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 838 | iotHubClientInstance->event_confirm_callback = eventConfirmationCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 839 | } |
AzureIoTClient | 16:deba40344375 | 840 | /* Codes_SRS_IOTHUBCLIENT_01_009: [IoTHubClient_SendEventAsync shall start the worker thread if it was not previously started.] */ |
Azure.IoT Build | 37:18310e4d888d | 841 | if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 16:deba40344375 | 842 | { |
AzureIoTClient | 16:deba40344375 | 843 | /* Codes_SRS_IOTHUBCLIENT_01_010: [If starting the thread fails, IoTHubClient_SendEventAsync shall return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 16:deba40344375 | 844 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 39:2719651a5bee | 845 | LogError("Could not start worker thread"); |
AzureIoTClient | 16:deba40344375 | 846 | } |
AzureIoTClient | 16:deba40344375 | 847 | else |
AzureIoTClient | 16:deba40344375 | 848 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 849 | if (iotHubClientInstance->created_with_transport_handle != 0 || eventConfirmationCallback == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 850 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 851 | result = IoTHubClient_LL_SendEventAsync(iotHubClientInstance->IoTHubClientLLHandle, eventMessageHandle, eventConfirmationCallback, userContextCallback); |
Azure.IoT.Build | 54:6dcad9019a64 | 852 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 853 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 854 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 855 | /* Codes_SRS_IOTHUBCLIENT_07_001: [ IoTHubClient_SendEventAsync shall allocate a IOTHUB_QUEUE_CONTEXT object to be sent to the IoTHubClient_LL_SendEventAsync function as a user context. ] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 856 | IOTHUB_QUEUE_CONTEXT* queue_context = (IOTHUB_QUEUE_CONTEXT*)malloc(sizeof(IOTHUB_QUEUE_CONTEXT)); |
Azure.IoT.Build | 54:6dcad9019a64 | 857 | if (queue_context == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 858 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 859 | result = IOTHUB_CLIENT_ERROR; |
Azure.IoT.Build | 54:6dcad9019a64 | 860 | LogError("Failed allocating QUEUE_CONTEXT"); |
Azure.IoT.Build | 54:6dcad9019a64 | 861 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 862 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 863 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 864 | queue_context->iotHubClientHandle = iotHubClientInstance; |
Azure.IoT.Build | 54:6dcad9019a64 | 865 | queue_context->userContextCallback = userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 866 | /* Codes_SRS_IOTHUBCLIENT_01_012: [IoTHubClient_SendEventAsync shall call IoTHubClient_LL_SendEventAsync, while passing the IoTHubClient_LL handle created by IoTHubClient_Create and the parameters eventMessageHandle, eventConfirmationCallback and userContextCallback.] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 867 | /* Codes_SRS_IOTHUBCLIENT_01_013: [When IoTHubClient_LL_SendEventAsync is called, IoTHubClient_SendEventAsync shall return the result of IoTHubClient_LL_SendEventAsync.] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 868 | result = IoTHubClient_LL_SendEventAsync(iotHubClientInstance->IoTHubClientLLHandle, eventMessageHandle, iothub_ll_event_confirm_callback, queue_context); |
Azure.IoT.Build | 54:6dcad9019a64 | 869 | if (result != IOTHUB_CLIENT_OK) |
Azure.IoT.Build | 54:6dcad9019a64 | 870 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 871 | LogError("IoTHubClient_LL_SendEventAsync failed"); |
Azure.IoT.Build | 54:6dcad9019a64 | 872 | free(queue_context); |
Azure.IoT.Build | 54:6dcad9019a64 | 873 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 874 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 875 | } |
AzureIoTClient | 16:deba40344375 | 876 | } |
AzureIoTClient | 16:deba40344375 | 877 | |
AzureIoTClient | 16:deba40344375 | 878 | /* Codes_SRS_IOTHUBCLIENT_01_025: [IoTHubClient_SendEventAsync shall be made thread-safe by using the lock created in IoTHubClient_Create.] */ |
AzureIoTClient | 16:deba40344375 | 879 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 16:deba40344375 | 880 | } |
AzureIoTClient | 16:deba40344375 | 881 | } |
AzureIoTClient | 16:deba40344375 | 882 | |
AzureIoTClient | 16:deba40344375 | 883 | return result; |
AzureIoTClient | 16:deba40344375 | 884 | } |
AzureIoTClient | 16:deba40344375 | 885 | |
AzureIoTClient | 16:deba40344375 | 886 | IOTHUB_CLIENT_RESULT IoTHubClient_GetSendStatus(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus) |
AzureIoTClient | 16:deba40344375 | 887 | { |
AzureIoTClient | 16:deba40344375 | 888 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 16:deba40344375 | 889 | |
AzureIoTClient | 16:deba40344375 | 890 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 16:deba40344375 | 891 | { |
AzureIoTClient | 16:deba40344375 | 892 | /* Codes_SRS_IOTHUBCLIENT_01_023: [If iotHubClientHandle is NULL, IoTHubClient_ GetSendStatus shall return IOTHUB_CLIENT_INVALID_ARG.] */ |
AzureIoTClient | 16:deba40344375 | 893 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 39:2719651a5bee | 894 | LogError("NULL iothubClientHandle"); |
AzureIoTClient | 16:deba40344375 | 895 | } |
AzureIoTClient | 16:deba40344375 | 896 | else |
AzureIoTClient | 16:deba40344375 | 897 | { |
AzureIoTClient | 16:deba40344375 | 898 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 16:deba40344375 | 899 | |
AzureIoTClient | 16:deba40344375 | 900 | /* Codes_SRS_IOTHUBCLIENT_01_033: [IoTHubClient_GetSendStatus shall be made thread-safe by using the lock created in IoTHubClient_Create.] */ |
AzureIoTClient | 16:deba40344375 | 901 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 16:deba40344375 | 902 | { |
AzureIoTClient | 16:deba40344375 | 903 | /* Codes_SRS_IOTHUBCLIENT_01_034: [If acquiring the lock fails, IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 16:deba40344375 | 904 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 39:2719651a5bee | 905 | LogError("Could not acquire lock"); |
AzureIoTClient | 16:deba40344375 | 906 | } |
AzureIoTClient | 16:deba40344375 | 907 | else |
AzureIoTClient | 16:deba40344375 | 908 | { |
AzureIoTClient | 16:deba40344375 | 909 | /* Codes_SRS_IOTHUBCLIENT_01_022: [IoTHubClient_GetSendStatus shall call IoTHubClient_LL_GetSendStatus, while passing the IoTHubClient_LL handle created by IoTHubClient_Create and the parameter iotHubClientStatus.] */ |
AzureIoTClient | 16:deba40344375 | 910 | /* Codes_SRS_IOTHUBCLIENT_01_024: [Otherwise, IoTHubClient_GetSendStatus shall return the result of IoTHubClient_LL_GetSendStatus.] */ |
AzureIoTClient | 16:deba40344375 | 911 | result = IoTHubClient_LL_GetSendStatus(iotHubClientInstance->IoTHubClientLLHandle, iotHubClientStatus); |
AzureIoTClient | 16:deba40344375 | 912 | |
AzureIoTClient | 16:deba40344375 | 913 | /* Codes_SRS_IOTHUBCLIENT_01_033: [IoTHubClient_GetSendStatus shall be made thread-safe by using the lock created in IoTHubClient_Create.] */ |
AzureIoTClient | 16:deba40344375 | 914 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 16:deba40344375 | 915 | } |
AzureIoTClient | 16:deba40344375 | 916 | } |
AzureIoTClient | 16:deba40344375 | 917 | |
AzureIoTClient | 16:deba40344375 | 918 | return result; |
AzureIoTClient | 16:deba40344375 | 919 | } |
AzureIoTClient | 16:deba40344375 | 920 | |
AzureIoTClient | 16:deba40344375 | 921 | IOTHUB_CLIENT_RESULT IoTHubClient_SetMessageCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback) |
AzureIoTClient | 16:deba40344375 | 922 | { |
AzureIoTClient | 16:deba40344375 | 923 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 16:deba40344375 | 924 | |
AzureIoTClient | 16:deba40344375 | 925 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 16:deba40344375 | 926 | { |
AzureIoTClient | 16:deba40344375 | 927 | /* Codes_SRS_IOTHUBCLIENT_01_016: [If iotHubClientHandle is NULL, IoTHubClient_SetMessageCallback shall return IOTHUB_CLIENT_INVALID_ARG.] */ |
AzureIoTClient | 16:deba40344375 | 928 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 39:2719651a5bee | 929 | LogError("NULL iothubClientHandle"); |
AzureIoTClient | 16:deba40344375 | 930 | } |
AzureIoTClient | 16:deba40344375 | 931 | else |
AzureIoTClient | 16:deba40344375 | 932 | { |
AzureIoTClient | 16:deba40344375 | 933 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 16:deba40344375 | 934 | |
AzureIoTClient | 16:deba40344375 | 935 | /* Codes_SRS_IOTHUBCLIENT_01_027: [IoTHubClient_SetMessageCallback shall be made thread-safe by using the lock created in IoTHubClient_Create.] */ |
AzureIoTClient | 16:deba40344375 | 936 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 16:deba40344375 | 937 | { |
AzureIoTClient | 16:deba40344375 | 938 | /* Codes_SRS_IOTHUBCLIENT_01_028: [If acquiring the lock fails, IoTHubClient_SetMessageCallback shall return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 16:deba40344375 | 939 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 39:2719651a5bee | 940 | LogError("Could not acquire lock"); |
AzureIoTClient | 16:deba40344375 | 941 | } |
AzureIoTClient | 16:deba40344375 | 942 | else |
AzureIoTClient | 16:deba40344375 | 943 | { |
AzureIoTClient | 16:deba40344375 | 944 | /* Codes_SRS_IOTHUBCLIENT_01_014: [IoTHubClient_SetMessageCallback shall start the worker thread if it was not previously started.] */ |
Azure.IoT Build | 37:18310e4d888d | 945 | if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 16:deba40344375 | 946 | { |
AzureIoTClient | 16:deba40344375 | 947 | /* Codes_SRS_IOTHUBCLIENT_01_015: [If starting the thread fails, IoTHubClient_SetMessageCallback shall return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 16:deba40344375 | 948 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 39:2719651a5bee | 949 | LogError("Could not start worker thread"); |
AzureIoTClient | 16:deba40344375 | 950 | } |
AzureIoTClient | 16:deba40344375 | 951 | else |
AzureIoTClient | 16:deba40344375 | 952 | { |
AzureIoTClient | 16:deba40344375 | 953 | /* Codes_SRS_IOTHUBCLIENT_01_017: [IoTHubClient_SetMessageCallback shall call IoTHubClient_LL_SetMessageCallback, while passing the IoTHubClient_LL handle created by IoTHubClient_Create and the parameters messageCallback and userContextCallback.] */ |
AzureIoTClient | 16:deba40344375 | 954 | result = IoTHubClient_LL_SetMessageCallback(iotHubClientInstance->IoTHubClientLLHandle, messageCallback, userContextCallback); |
AzureIoTClient | 16:deba40344375 | 955 | } |
AzureIoTClient | 16:deba40344375 | 956 | |
AzureIoTClient | 16:deba40344375 | 957 | /* Codes_SRS_IOTHUBCLIENT_01_027: [IoTHubClient_SetMessageCallback shall be made thread-safe by using the lock created in IoTHubClient_Create.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 958 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 16:deba40344375 | 959 | } |
AzureIoTClient | 16:deba40344375 | 960 | } |
AzureIoTClient | 16:deba40344375 | 961 | |
AzureIoTClient | 16:deba40344375 | 962 | return result; |
AzureIoTClient | 16:deba40344375 | 963 | } |
AzureIoTClient | 16:deba40344375 | 964 | |
AzureIoTClient | 53:1e5a1ca1f274 | 965 | IOTHUB_CLIENT_RESULT IoTHubClient_SetConnectionStatusCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK connectionStatusCallback, void * userContextCallback) |
AzureIoTClient | 52:1cc3c6d07cad | 966 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 967 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 968 | |
AzureIoTClient | 53:1e5a1ca1f274 | 969 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 970 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 971 | /* Codes_SRS_IOTHUBCLIENT_25_076: [** If `iotHubClientHandle` is `NULL`, `IoTHubClient_SetRetryPolicy` shall return `IOTHUB_CLIENT_INVALID_ARG`. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 972 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 973 | LogError("NULL iothubClientHandle"); |
AzureIoTClient | 53:1e5a1ca1f274 | 974 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 975 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 976 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 977 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 52:1cc3c6d07cad | 978 | |
AzureIoTClient | 53:1e5a1ca1f274 | 979 | /* Codes_SRS_IOTHUBCLIENT_25_087: [ `IoTHubClient_SetConnectionStatusCallback` shall be made thread-safe by using the lock created in `IoTHubClient_Create`. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 980 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 981 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 982 | /* Codes_SRS_IOTHUBCLIENT_25_088: [ If acquiring the lock fails, `IoTHubClient_SetConnectionStatusCallback` shall return `IOTHUB_CLIENT_ERROR`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 983 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 984 | LogError("Could not acquire lock"); |
AzureIoTClient | 53:1e5a1ca1f274 | 985 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 986 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 987 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 988 | if (iotHubClientInstance->created_with_transport_handle == 0) |
Azure.IoT.Build | 54:6dcad9019a64 | 989 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 990 | iotHubClientInstance->connection_status_callback = connectionStatusCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 991 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 992 | /* Codes_SRS_IOTHUBCLIENT_25_081: [ `IoTHubClient_SetConnectionStatusCallback` shall start the worker thread if it was not previously started. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 993 | if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 994 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 995 | /* Codes_SRS_IOTHUBCLIENT_25_083: [ If starting the thread fails, `IoTHubClient_SetConnectionStatusCallback` shall return `IOTHUB_CLIENT_ERROR`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 996 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 997 | LogError("Could not start worker thread"); |
AzureIoTClient | 53:1e5a1ca1f274 | 998 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 999 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1000 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1001 | if (iotHubClientInstance->created_with_transport_handle != 0 || connectionStatusCallback == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 1002 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1003 | /* Codes_SRS_IOTHUBCLIENT_25_085: [ `IoTHubClient_SetConnectionStatusCallback` shall call `IoTHubClient_LL_SetConnectionStatusCallback`, while passing the `IoTHubClient_LL` handle created by `IoTHubClient_Create` and the parameters `connectionStatusCallback` and `userContextCallback`. ]*/ |
Azure.IoT.Build | 54:6dcad9019a64 | 1004 | result = IoTHubClient_LL_SetConnectionStatusCallback(iotHubClientInstance->IoTHubClientLLHandle, connectionStatusCallback, userContextCallback); |
Azure.IoT.Build | 54:6dcad9019a64 | 1005 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 1006 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 1007 | { |
AzureIoTClient | 55:59b527ab3452 | 1008 | if (iotHubClientInstance->connection_status_user_context != NULL) |
AzureIoTClient | 55:59b527ab3452 | 1009 | { |
AzureIoTClient | 55:59b527ab3452 | 1010 | free(iotHubClientInstance->connection_status_user_context); |
AzureIoTClient | 55:59b527ab3452 | 1011 | } |
AzureIoTClient | 55:59b527ab3452 | 1012 | iotHubClientInstance->connection_status_user_context = (IOTHUB_QUEUE_CONTEXT*)malloc(sizeof(IOTHUB_QUEUE_CONTEXT)); |
AzureIoTClient | 55:59b527ab3452 | 1013 | if (iotHubClientInstance->connection_status_user_context == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 1014 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1015 | result = IOTHUB_CLIENT_ERROR; |
Azure.IoT.Build | 54:6dcad9019a64 | 1016 | LogError("Failed allocating QUEUE_CONTEXT"); |
Azure.IoT.Build | 54:6dcad9019a64 | 1017 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 1018 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 1019 | { |
AzureIoTClient | 55:59b527ab3452 | 1020 | iotHubClientInstance->connection_status_user_context->iotHubClientHandle = iotHubClientInstance; |
AzureIoTClient | 55:59b527ab3452 | 1021 | iotHubClientInstance->connection_status_user_context->userContextCallback = userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 1022 | |
Azure.IoT.Build | 54:6dcad9019a64 | 1023 | /* Codes_SRS_IOTHUBCLIENT_25_085: [ `IoTHubClient_SetConnectionStatusCallback` shall call `IoTHubClient_LL_SetConnectionStatusCallback`, while passing the `IoTHubClient_LL` handle created by `IoTHubClient_Create` and the parameters `connectionStatusCallback` and `userContextCallback`. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 1024 | result = IoTHubClient_LL_SetConnectionStatusCallback(iotHubClientInstance->IoTHubClientLLHandle, iothub_ll_connection_status_callback, iotHubClientInstance->connection_status_user_context); |
Azure.IoT.Build | 54:6dcad9019a64 | 1025 | if (result != IOTHUB_CLIENT_OK) |
Azure.IoT.Build | 54:6dcad9019a64 | 1026 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1027 | LogError("IoTHubClient_LL_SetConnectionStatusCallback failed"); |
AzureIoTClient | 55:59b527ab3452 | 1028 | free(iotHubClientInstance->connection_status_user_context); |
Azure.IoT.Build | 54:6dcad9019a64 | 1029 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 1030 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 1031 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1032 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1033 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1034 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1035 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1036 | return result; |
AzureIoTClient | 52:1cc3c6d07cad | 1037 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1038 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1039 | IOTHUB_CLIENT_RESULT IoTHubClient_SetRetryPolicy(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds) |
AzureIoTClient | 52:1cc3c6d07cad | 1040 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1041 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1042 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1043 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1044 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1045 | /* Codes_SRS_IOTHUBCLIENT_25_076: [** If `iotHubClientHandle` is `NULL`, `IoTHubClient_SetRetryPolicy` shall return `IOTHUB_CLIENT_INVALID_ARG`. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1046 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1047 | LogError("NULL iothubClientHandle"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1048 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1049 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1050 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1051 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1052 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1053 | /* Codes_SRS_IOTHUBCLIENT_25_079: [ `IoTHubClient_SetRetryPolicy` shall be made thread-safe by using the lock created in `IoTHubClient_Create`.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1054 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 1055 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1056 | /* Codes_SRS_IOTHUBCLIENT_25_080: [ If acquiring the lock fails, `IoTHubClient_SetRetryPolicy` shall return `IOTHUB_CLIENT_ERROR`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1057 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1058 | LogError("Could not acquire lock"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1059 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1060 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1061 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1062 | /* Codes_SRS_IOTHUBCLIENT_25_073: [ `IoTHubClient_SetRetryPolicy` shall start the worker thread if it was not previously started. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1063 | if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 1064 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1065 | /* Codes_SRS_IOTHUBCLIENT_25_075: [ If starting the thread fails, `IoTHubClient_SetRetryPolicy` shall return `IOTHUB_CLIENT_ERROR`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1066 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1067 | LogError("Could not start worker thread"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1068 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1069 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1070 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1071 | /* Codes_SRS_IOTHUBCLIENT_25_077: [ `IoTHubClient_SetRetryPolicy` shall call `IoTHubClient_LL_SetRetryPolicy`, while passing the `IoTHubClient_LL` handle created by `IoTHubClient_Create` and the parameters `retryPolicy` and `retryTimeoutLimitinSeconds`.]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1072 | result = IoTHubClient_LL_SetRetryPolicy(iotHubClientInstance->IoTHubClientLLHandle, retryPolicy, retryTimeoutLimitInSeconds); |
AzureIoTClient | 53:1e5a1ca1f274 | 1073 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1074 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1075 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1076 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1077 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1078 | |
AzureIoTClient | 52:1cc3c6d07cad | 1079 | return result; |
AzureIoTClient | 52:1cc3c6d07cad | 1080 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1081 | |
Azure.IoT.Build | 54:6dcad9019a64 | 1082 | IOTHUB_CLIENT_RESULT IoTHubClient_GetRetryPolicy(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY* retryPolicy, size_t* retryTimeoutLimitInSeconds) |
AzureIoTClient | 52:1cc3c6d07cad | 1083 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1084 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1085 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1086 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1087 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1088 | /* Codes_SRS_IOTHUBCLIENT_25_092: [ If `iotHubClientHandle` is `NULL`, `IoTHubClient_GetRetryPolicy` shall return `IOTHUB_CLIENT_INVALID_ARG`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1089 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1090 | LogError("NULL iothubClientHandle"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1091 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1092 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1093 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1094 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1095 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1096 | /* Codes_SRS_IOTHUBCLIENT_25_095: [ `IoTHubClient_GetRetryPolicy` shall be made thread-safe by using the lock created in `IoTHubClient_Create`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1097 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 1098 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1099 | /* Codes_SRS_IOTHUBCLIENT_25_096: [ If acquiring the lock fails, `IoTHubClient_GetRetryPolicy` shall return `IOTHUB_CLIENT_ERROR`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1100 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1101 | LogError("Could not acquire lock"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1102 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1103 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1104 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1105 | /* Codes_SRS_IOTHUBCLIENT_25_089: [ `IoTHubClient_GetRetryPolicy` shall start the worker thread if it was not previously started.]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1106 | if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 1107 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1108 | /* Codes_SRS_IOTHUBCLIENT_25_091: [ If starting the thread fails, `IoTHubClient_GetRetryPolicy` shall return `IOTHUB_CLIENT_ERROR`.]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1109 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1110 | LogError("Could not start worker thread"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1111 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1112 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1113 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1114 | /* Codes_SRS_IOTHUBCLIENT_25_093: [ `IoTHubClient_GetRetryPolicy` shall call `IoTHubClient_LL_GetRetryPolicy`, while passing the `IoTHubClient_LL` handle created by `IoTHubClient_Create` and the parameters `connectionStatusCallback` and `userContextCallback`.]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1115 | result = IoTHubClient_LL_GetRetryPolicy(iotHubClientInstance->IoTHubClientLLHandle, retryPolicy, retryTimeoutLimitInSeconds); |
AzureIoTClient | 53:1e5a1ca1f274 | 1116 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1117 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1118 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1119 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1120 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1121 | |
AzureIoTClient | 52:1cc3c6d07cad | 1122 | return result; |
AzureIoTClient | 52:1cc3c6d07cad | 1123 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1124 | |
AzureIoTClient | 16:deba40344375 | 1125 | IOTHUB_CLIENT_RESULT IoTHubClient_GetLastMessageReceiveTime(IOTHUB_CLIENT_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime) |
AzureIoTClient | 16:deba40344375 | 1126 | { |
AzureIoTClient | 16:deba40344375 | 1127 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 16:deba40344375 | 1128 | |
AzureIoTClient | 16:deba40344375 | 1129 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 16:deba40344375 | 1130 | { |
AzureIoTClient | 16:deba40344375 | 1131 | /* Codes_SRS_IOTHUBCLIENT_01_020: [If iotHubClientHandle is NULL, IoTHubClient_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INVALID_ARG.] */ |
AzureIoTClient | 16:deba40344375 | 1132 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 39:2719651a5bee | 1133 | LogError("NULL iothubClientHandle"); |
AzureIoTClient | 16:deba40344375 | 1134 | } |
AzureIoTClient | 16:deba40344375 | 1135 | else |
AzureIoTClient | 16:deba40344375 | 1136 | { |
AzureIoTClient | 16:deba40344375 | 1137 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 16:deba40344375 | 1138 | |
AzureIoTClient | 16:deba40344375 | 1139 | /* Codes_SRS_IOTHUBCLIENT_01_035: [IoTHubClient_GetLastMessageReceiveTime shall be made thread-safe by using the lock created in IoTHubClient_Create.] */ |
AzureIoTClient | 16:deba40344375 | 1140 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 16:deba40344375 | 1141 | { |
AzureIoTClient | 16:deba40344375 | 1142 | /* Codes_SRS_IOTHUBCLIENT_01_036: [If acquiring the lock fails, IoTHubClient_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 16:deba40344375 | 1143 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 39:2719651a5bee | 1144 | LogError("Could not acquire lock"); |
AzureIoTClient | 16:deba40344375 | 1145 | } |
AzureIoTClient | 16:deba40344375 | 1146 | else |
AzureIoTClient | 16:deba40344375 | 1147 | { |
AzureIoTClient | 16:deba40344375 | 1148 | /* Codes_SRS_IOTHUBCLIENT_01_019: [IoTHubClient_GetLastMessageReceiveTime shall call IoTHubClient_LL_GetLastMessageReceiveTime, while passing the IoTHubClient_LL handle created by IoTHubClient_Create and the parameter lastMessageReceiveTime.] */ |
AzureIoTClient | 16:deba40344375 | 1149 | /* Codes_SRS_IOTHUBCLIENT_01_021: [Otherwise, IoTHubClient_GetLastMessageReceiveTime shall return the result of IoTHubClient_LL_GetLastMessageReceiveTime.] */ |
AzureIoTClient | 16:deba40344375 | 1150 | result = IoTHubClient_LL_GetLastMessageReceiveTime(iotHubClientInstance->IoTHubClientLLHandle, lastMessageReceiveTime); |
AzureIoTClient | 16:deba40344375 | 1151 | |
AzureIoTClient | 16:deba40344375 | 1152 | /* Codes_SRS_IOTHUBCLIENT_01_035: [IoTHubClient_GetLastMessageReceiveTime shall be made thread-safe by using the lock created in IoTHubClient_Create.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1153 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 16:deba40344375 | 1154 | } |
AzureIoTClient | 16:deba40344375 | 1155 | } |
AzureIoTClient | 16:deba40344375 | 1156 | |
AzureIoTClient | 16:deba40344375 | 1157 | return result; |
AzureIoTClient | 16:deba40344375 | 1158 | } |
AzureIoTClient | 16:deba40344375 | 1159 | |
AzureIoTClient | 16:deba40344375 | 1160 | IOTHUB_CLIENT_RESULT IoTHubClient_SetOption(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const char* optionName, const void* value) |
AzureIoTClient | 16:deba40344375 | 1161 | { |
AzureIoTClient | 16:deba40344375 | 1162 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 16:deba40344375 | 1163 | /*Codes_SRS_IOTHUBCLIENT_02_034: [If parameter iotHubClientHandle is NULL then IoTHubClient_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */ |
AzureIoTClient | 42:448eecc3676e | 1164 | /*Codes_SRS_IOTHUBCLIENT_02_035: [ If parameter optionName is NULL then IoTHubClient_SetOption shall return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1165 | /*Codes_SRS_IOTHUBCLIENT_02_036: [ If parameter value is NULL then IoTHubClient_SetOption shall return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 16:deba40344375 | 1166 | if ( |
AzureIoTClient | 16:deba40344375 | 1167 | (iotHubClientHandle == NULL) || |
AzureIoTClient | 16:deba40344375 | 1168 | (optionName == NULL) || |
AzureIoTClient | 16:deba40344375 | 1169 | (value == NULL) |
AzureIoTClient | 16:deba40344375 | 1170 | ) |
AzureIoTClient | 16:deba40344375 | 1171 | { |
AzureIoTClient | 16:deba40344375 | 1172 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1173 | LogError("invalid arg (NULL)"); |
AzureIoTClient | 16:deba40344375 | 1174 | } |
AzureIoTClient | 16:deba40344375 | 1175 | else |
AzureIoTClient | 16:deba40344375 | 1176 | { |
AzureIoTClient | 16:deba40344375 | 1177 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 16:deba40344375 | 1178 | |
AzureIoTClient | 40:1a94db9139ea | 1179 | /* Codes_SRS_IOTHUBCLIENT_01_041: [ IoTHubClient_SetOption shall be made thread-safe by using the lock created in IoTHubClient_Create. ]*/ |
AzureIoTClient | 40:1a94db9139ea | 1180 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 40:1a94db9139ea | 1181 | { |
AzureIoTClient | 40:1a94db9139ea | 1182 | /* Codes_SRS_IOTHUBCLIENT_01_042: [ If acquiring the lock fails, IoTHubClient_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 40:1a94db9139ea | 1183 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 40:1a94db9139ea | 1184 | LogError("Could not acquire lock"); |
AzureIoTClient | 40:1a94db9139ea | 1185 | } |
AzureIoTClient | 40:1a94db9139ea | 1186 | else |
AzureIoTClient | 16:deba40344375 | 1187 | { |
AzureIoTClient | 40:1a94db9139ea | 1188 | /*Codes_SRS_IOTHUBCLIENT_02_038: [If optionName doesn't match one of the options handled by this module then IoTHubClient_SetOption shall call IoTHubClient_LL_SetOption passing the same parameters and return what IoTHubClient_LL_SetOption returns.] */ |
AzureIoTClient | 40:1a94db9139ea | 1189 | result = IoTHubClient_LL_SetOption(iotHubClientInstance->IoTHubClientLLHandle, optionName, value); |
AzureIoTClient | 40:1a94db9139ea | 1190 | if (result != IOTHUB_CLIENT_OK) |
AzureIoTClient | 40:1a94db9139ea | 1191 | { |
AzureIoTClient | 40:1a94db9139ea | 1192 | LogError("IoTHubClient_LL_SetOption failed"); |
AzureIoTClient | 40:1a94db9139ea | 1193 | } |
AzureIoTClient | 40:1a94db9139ea | 1194 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1195 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1196 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1197 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1198 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1199 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1200 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1201 | IOTHUB_CLIENT_RESULT IoTHubClient_SetDeviceTwinCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK deviceTwinCallback, void* userContextCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 1202 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1203 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1204 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1205 | /*Codes_SRS_IOTHUBCLIENT_10_001: [** `IoTHubClient_SetDeviceTwinCallback` shall fail and return `IOTHUB_CLIENT_INVALID_ARG` if parameter `iotHubClientHandle` is `NULL`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1206 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1207 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1208 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1209 | LogError("invalid arg (NULL)"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1210 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1211 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1212 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1213 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1214 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1215 | /*Codes_SRS_IOTHUBCLIENT_10_020: [** `IoTHubClient_SetDeviceTwinCallback` shall be made thread - safe by using the lock created in IoTHubClient_Create. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1216 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 1217 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1218 | /*Codes_SRS_IOTHUBCLIENT_10_002: [** If acquiring the lock fails, `IoTHubClient_SetDeviceTwinCallback` shall return `IOTHUB_CLIENT_ERROR`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1219 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1220 | LogError("Could not acquire lock"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1221 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1222 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1223 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1224 | if (iotHubClientInstance->created_with_transport_handle == 0) |
Azure.IoT.Build | 54:6dcad9019a64 | 1225 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1226 | iotHubClientInstance->desired_state_callback = deviceTwinCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 1227 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1228 | /*Codes_SRS_IOTHUBCLIENT_10_003: [** If the transport connection is shared, the thread shall be started by calling `IoTHubTransport_StartWorkerThread`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1229 | if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 1230 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1231 | /*Codes_SRS_IOTHUBCLIENT_10_004: [** If starting the thread fails, `IoTHubClient_SetDeviceTwinCallback` shall return `IOTHUB_CLIENT_ERROR`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1232 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1233 | LogError("Could not start worker thread"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1234 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1235 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1236 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1237 | if (iotHubClientInstance->created_with_transport_handle != 0 || deviceTwinCallback == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 1238 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1239 | /*Codes_SRS_IOTHUBCLIENT_10_005: [** `IoTHubClient_LL_SetDeviceTwinCallback` shall call `IoTHubClient_LL_SetDeviceTwinCallback`, while passing the `IoTHubClient_LL handle` created by `IoTHubClient_LL_Create` along with the parameters `reportedStateCallback` and `userContextCallback`. ]*/ |
Azure.IoT.Build | 54:6dcad9019a64 | 1240 | result = IoTHubClient_LL_SetDeviceTwinCallback(iotHubClientInstance->IoTHubClientLLHandle, deviceTwinCallback, userContextCallback); |
Azure.IoT.Build | 54:6dcad9019a64 | 1241 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 1242 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1243 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1244 | if (iotHubClientInstance->devicetwin_user_context != NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 1245 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1246 | free(iotHubClientInstance->devicetwin_user_context); |
Azure.IoT.Build | 54:6dcad9019a64 | 1247 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 1248 | |
Azure.IoT.Build | 54:6dcad9019a64 | 1249 | /*Codes_SRS_IOTHUBCLIENT_07_002: [ IoTHubClient_SetDeviceTwinCallback shall allocate a IOTHUB_QUEUE_CONTEXT object to be sent to the IoTHubClient_LL_SetDeviceTwinCallback function as a user context. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 1250 | iotHubClientInstance->devicetwin_user_context = (IOTHUB_QUEUE_CONTEXT*)malloc(sizeof(IOTHUB_QUEUE_CONTEXT)); |
Azure.IoT.Build | 54:6dcad9019a64 | 1251 | if (iotHubClientInstance->devicetwin_user_context == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 1252 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1253 | result = IOTHUB_CLIENT_ERROR; |
Azure.IoT.Build | 54:6dcad9019a64 | 1254 | LogError("Failed allocating QUEUE_CONTEXT"); |
Azure.IoT.Build | 54:6dcad9019a64 | 1255 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 1256 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 1257 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1258 | /*Codes_SRS_IOTHUBCLIENT_10_005: [** `IoTHubClient_LL_SetDeviceTwinCallback` shall call `IoTHubClient_LL_SetDeviceTwinCallback`, while passing the `IoTHubClient_LL handle` created by `IoTHubClient_LL_Create` along with the parameters `iothub_ll_device_twin_callback` and IOTHUB_QUEUE_CONTEXT variable. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 1259 | iotHubClientInstance->devicetwin_user_context->iotHubClientHandle = iotHubClientInstance; |
AzureIoTClient | 55:59b527ab3452 | 1260 | iotHubClientInstance->devicetwin_user_context->userContextCallback = userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 1261 | result = IoTHubClient_LL_SetDeviceTwinCallback(iotHubClientInstance->IoTHubClientLLHandle, iothub_ll_device_twin_callback, iotHubClientInstance->devicetwin_user_context); |
Azure.IoT.Build | 54:6dcad9019a64 | 1262 | if (result != IOTHUB_CLIENT_OK) |
Azure.IoT.Build | 54:6dcad9019a64 | 1263 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1264 | LogError("IoTHubClient_LL_SetDeviceTwinCallback failed"); |
Azure.IoT.Build | 54:6dcad9019a64 | 1265 | free(iotHubClientInstance->devicetwin_user_context); |
Azure.IoT.Build | 54:6dcad9019a64 | 1266 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 1267 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1268 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1269 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1270 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 16:deba40344375 | 1271 | } |
AzureIoTClient | 16:deba40344375 | 1272 | } |
AzureIoTClient | 16:deba40344375 | 1273 | return result; |
AzureIoTClient | 16:deba40344375 | 1274 | } |
AzureIoTClient | 42:448eecc3676e | 1275 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1276 | IOTHUB_CLIENT_RESULT IoTHubClient_SendReportedState(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const unsigned char* reportedState, size_t size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reportedStateCallback, void* userContextCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 1277 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1278 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1279 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1280 | /*Codes_SRS_IOTHUBCLIENT_10_013: [** If `iotHubClientHandle` is `NULL`, `IoTHubClient_SendReportedState` shall return `IOTHUB_CLIENT_INVALID_ARG`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1281 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1282 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1283 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1284 | LogError("invalid arg (NULL)"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1285 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1286 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1287 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1288 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1289 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1290 | /*Codes_SRS_IOTHUBCLIENT_10_021: [** `IoTHubClient_SendReportedState` shall be made thread-safe by using the lock created in IoTHubClient_Create. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1291 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 1292 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1293 | /*Codes_SRS_IOTHUBCLIENT_10_014: [** If acquiring the lock fails, `IoTHubClient_SendReportedState` shall return `IOTHUB_CLIENT_ERROR`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1294 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1295 | LogError("Could not acquire lock"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1296 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1297 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1298 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1299 | if (iotHubClientInstance->created_with_transport_handle == 0) |
Azure.IoT.Build | 54:6dcad9019a64 | 1300 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1301 | iotHubClientInstance->reported_state_callback = reportedStateCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 1302 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1303 | /*Codes_SRS_IOTHUBCLIENT_10_015: [** If the transport connection is shared, the thread shall be started by calling `IoTHubTransport_StartWorkerThread`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1304 | if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 1305 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1306 | /*Codes_SRS_IOTHUBCLIENT_10_016: [** If starting the thread fails, `IoTHubClient_SendReportedState` shall return `IOTHUB_CLIENT_ERROR`. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1307 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1308 | LogError("Could not start worker thread"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1309 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1310 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1311 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1312 | if (iotHubClientInstance->created_with_transport_handle != 0 || reportedStateCallback == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 1313 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1314 | /*Codes_SRS_IOTHUBCLIENT_10_017: [** `IoTHubClient_SendReportedState` shall call `IoTHubClient_LL_SendReportedState`, while passing the `IoTHubClient_LL handle` created by `IoTHubClient_LL_Create` along with the parameters `reportedState`, `size`, `reportedStateCallback`, and `userContextCallback`. ]*/ |
Azure.IoT.Build | 54:6dcad9019a64 | 1315 | /*Codes_SRS_IOTHUBCLIENT_10_018: [** When `IoTHubClient_LL_SendReportedState` is called, `IoTHubClient_SendReportedState` shall return the result of `IoTHubClient_LL_SendReportedState`. **]*/ |
Azure.IoT.Build | 54:6dcad9019a64 | 1316 | result = IoTHubClient_LL_SendReportedState(iotHubClientInstance->IoTHubClientLLHandle, reportedState, size, reportedStateCallback, userContextCallback); |
Azure.IoT.Build | 54:6dcad9019a64 | 1317 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 1318 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1319 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1320 | /* Codes_SRS_IOTHUBCLIENT_07_003: [ IoTHubClient_SendReportedState shall allocate a IOTHUB_QUEUE_CONTEXT object to be sent to the IoTHubClient_LL_SendReportedState function as a user context. ] */ |
Azure.IoT.Build | 54:6dcad9019a64 | 1321 | IOTHUB_QUEUE_CONTEXT* queue_context = (IOTHUB_QUEUE_CONTEXT*)malloc(sizeof(IOTHUB_QUEUE_CONTEXT)); |
Azure.IoT.Build | 54:6dcad9019a64 | 1322 | if (queue_context == NULL) |
Azure.IoT.Build | 54:6dcad9019a64 | 1323 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1324 | result = IOTHUB_CLIENT_ERROR; |
Azure.IoT.Build | 54:6dcad9019a64 | 1325 | LogError("Failed allocating QUEUE_CONTEXT"); |
Azure.IoT.Build | 54:6dcad9019a64 | 1326 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 1327 | else |
Azure.IoT.Build | 54:6dcad9019a64 | 1328 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1329 | queue_context->iotHubClientHandle = iotHubClientInstance; |
Azure.IoT.Build | 54:6dcad9019a64 | 1330 | queue_context->userContextCallback = userContextCallback; |
Azure.IoT.Build | 54:6dcad9019a64 | 1331 | /*Codes_SRS_IOTHUBCLIENT_10_017: [** `IoTHubClient_SendReportedState` shall call `IoTHubClient_LL_SendReportedState`, while passing the `IoTHubClient_LL handle` created by `IoTHubClient_LL_Create` along with the parameters `reportedState`, `size`, `iothub_ll_reported_state_callback` and IOTHUB_QUEUE_CONTEXT variable. ]*/ |
Azure.IoT.Build | 54:6dcad9019a64 | 1332 | /*Codes_SRS_IOTHUBCLIENT_10_018: [** When `IoTHubClient_LL_SendReportedState` is called, `IoTHubClient_SendReportedState` shall return the result of `IoTHubClient_LL_SendReportedState`. **]*/ |
Azure.IoT.Build | 54:6dcad9019a64 | 1333 | result = IoTHubClient_LL_SendReportedState(iotHubClientInstance->IoTHubClientLLHandle, reportedState, size, iothub_ll_reported_state_callback, queue_context); |
Azure.IoT.Build | 54:6dcad9019a64 | 1334 | if (result != IOTHUB_CLIENT_OK) |
Azure.IoT.Build | 54:6dcad9019a64 | 1335 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1336 | LogError("IoTHubClient_LL_SendReportedState failed"); |
Azure.IoT.Build | 54:6dcad9019a64 | 1337 | free(queue_context); |
Azure.IoT.Build | 54:6dcad9019a64 | 1338 | } |
Azure.IoT.Build | 54:6dcad9019a64 | 1339 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1340 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1341 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1342 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1343 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1344 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1345 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1346 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1347 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1348 | IOTHUB_CLIENT_RESULT IoTHubClient_SetDeviceMethodCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC deviceMethodCallback, void* userContextCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 1349 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1350 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1351 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1352 | /*Codes_SRS_IOTHUBCLIENT_12_012: [ If iotHubClientHandle is NULL, IoTHubClient_SetDeviceMethodCallback shall return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1353 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1354 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1355 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1356 | LogError("invalid arg (NULL)"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1357 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1358 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1359 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1360 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1361 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1362 | /*Codes_SRS_IOTHUBCLIENT_12_018: [ IoTHubClient_SetDeviceMethodCallback shall be made thread-safe by using the lock created in IoTHubClient_Create. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1363 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 1364 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1365 | /*Codes_SRS_IOTHUBCLIENT_12_013: [ If acquiring the lock fails, IoTHubClient_SetDeviceMethodCallback shall return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1366 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1367 | LogError("Could not acquire lock"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1368 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1369 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1370 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1371 | /*Codes_SRS_IOTHUBCLIENT_12_014: [ If the transport handle is null and the worker thread is not initialized, the thread shall be started by calling IoTHubTransport_StartWorkerThread. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1372 | if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 1373 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1374 | /*Codes_SRS_IOTHUBCLIENT_12_015: [ If starting the thread fails, IoTHubClient_SetDeviceMethodCallback shall return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1375 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1376 | LogError("Could not start worker thread"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1377 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1378 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1379 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1380 | /*Codes_SRS_IOTHUBCLIENT_12_016: [ IoTHubClient_SetDeviceMethodCallback shall call IoTHubClient_LL_SetDeviceMethodCallback, while passing the IoTHubClient_LL_handle created by IoTHubClient_LL_Create along with the parameters deviceMethodCallback and userContextCallback. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1381 | /*Codes_SRS_IOTHUBCLIENT_12_017: [ When IoTHubClient_LL_SetDeviceMethodCallback is called, IoTHubClient_SetDeviceMethodCallback shall return the result of IoTHubClient_LL_SetDeviceMethodCallback. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1382 | result = IoTHubClient_LL_SetDeviceMethodCallback(iotHubClientInstance->IoTHubClientLLHandle, deviceMethodCallback, userContextCallback); |
AzureIoTClient | 53:1e5a1ca1f274 | 1383 | if (result != IOTHUB_CLIENT_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 1384 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1385 | LogError("IoTHubClient_LL_SetDeviceMethodCallback failed"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1386 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1387 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1388 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1389 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1390 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1391 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1392 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1393 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1394 | |
AzureIoTClient | 55:59b527ab3452 | 1395 | IOTHUB_CLIENT_RESULT IoTHubClient_SetDeviceMethodCallback_Ex(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK inboundDeviceMethodCallback, void* userContextCallback) |
AzureIoTClient | 55:59b527ab3452 | 1396 | { |
AzureIoTClient | 55:59b527ab3452 | 1397 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 55:59b527ab3452 | 1398 | |
AzureIoTClient | 55:59b527ab3452 | 1399 | /*Codes_SRS_IOTHUBCLIENT_07_001: [ If iotHubClientHandle is NULL, IoTHubClient_SetDeviceMethodCallback_Ex shall return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 1400 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 55:59b527ab3452 | 1401 | { |
AzureIoTClient | 55:59b527ab3452 | 1402 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 55:59b527ab3452 | 1403 | LogError("invalid arg (NULL)"); |
AzureIoTClient | 55:59b527ab3452 | 1404 | } |
AzureIoTClient | 55:59b527ab3452 | 1405 | else |
AzureIoTClient | 55:59b527ab3452 | 1406 | { |
AzureIoTClient | 55:59b527ab3452 | 1407 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 55:59b527ab3452 | 1408 | |
AzureIoTClient | 55:59b527ab3452 | 1409 | /*Codes_SRS_IOTHUBCLIENT_07_007: [ IoTHubClient_SetDeviceMethodCallback_Ex shall be made thread-safe by using the lock created in IoTHubClient_Create. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 1410 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 55:59b527ab3452 | 1411 | { |
AzureIoTClient | 55:59b527ab3452 | 1412 | /*Codes_SRS_IOTHUBCLIENT_07_002: [ If acquiring the lock fails, IoTHubClient_SetDeviceMethodCallback_Ex shall return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 1413 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 55:59b527ab3452 | 1414 | LogError("Could not acquire lock"); |
AzureIoTClient | 55:59b527ab3452 | 1415 | } |
AzureIoTClient | 55:59b527ab3452 | 1416 | else |
AzureIoTClient | 55:59b527ab3452 | 1417 | { |
AzureIoTClient | 55:59b527ab3452 | 1418 | if (iotHubClientInstance->created_with_transport_handle == 0) |
AzureIoTClient | 55:59b527ab3452 | 1419 | { |
AzureIoTClient | 55:59b527ab3452 | 1420 | iotHubClientInstance->device_method_callback = inboundDeviceMethodCallback; |
AzureIoTClient | 55:59b527ab3452 | 1421 | } |
AzureIoTClient | 55:59b527ab3452 | 1422 | /*Codes_SRS_IOTHUBCLIENT_07_003: [ If the transport handle is NULL and the worker thread is not initialized, the thread shall be started by calling IoTHubTransport_StartWorkerThread. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 1423 | if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 55:59b527ab3452 | 1424 | { |
AzureIoTClient | 55:59b527ab3452 | 1425 | /*Codes_SRS_IOTHUBCLIENT_07_004: [ If starting the thread fails, IoTHubClient_SetDeviceMethodCallback_Ex shall return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 1426 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 55:59b527ab3452 | 1427 | LogError("Could not start worker thread"); |
AzureIoTClient | 55:59b527ab3452 | 1428 | } |
AzureIoTClient | 55:59b527ab3452 | 1429 | else |
AzureIoTClient | 55:59b527ab3452 | 1430 | { |
AzureIoTClient | 55:59b527ab3452 | 1431 | if (iotHubClientInstance->created_with_transport_handle != 0 || inboundDeviceMethodCallback == NULL) |
AzureIoTClient | 55:59b527ab3452 | 1432 | { |
AzureIoTClient | 55:59b527ab3452 | 1433 | /* Codes_SRS_IOTHUBCLIENT_07_008: [ If inboundDeviceMethodCallback is NULL, IoTHubClient_SetDeviceMethodCallback_Ex shall call IoTHubClient_LL_SetDeviceMethodCallback_Ex, passing NULL for the iothub_ll_inbound_device_method_callback. ] */ |
AzureIoTClient | 55:59b527ab3452 | 1434 | result = IoTHubClient_LL_SetDeviceMethodCallback_Ex(iotHubClientInstance->IoTHubClientLLHandle, NULL, NULL); |
AzureIoTClient | 55:59b527ab3452 | 1435 | } |
AzureIoTClient | 55:59b527ab3452 | 1436 | else |
AzureIoTClient | 55:59b527ab3452 | 1437 | { |
AzureIoTClient | 55:59b527ab3452 | 1438 | IOTHUB_QUEUE_CONTEXT* queue_context = (IOTHUB_QUEUE_CONTEXT*)malloc(sizeof(IOTHUB_QUEUE_CONTEXT)); |
AzureIoTClient | 55:59b527ab3452 | 1439 | if (queue_context == NULL) |
AzureIoTClient | 55:59b527ab3452 | 1440 | { |
AzureIoTClient | 55:59b527ab3452 | 1441 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 55:59b527ab3452 | 1442 | LogError("Failed allocating QUEUE_CONTEXT"); |
AzureIoTClient | 55:59b527ab3452 | 1443 | } |
AzureIoTClient | 55:59b527ab3452 | 1444 | else |
AzureIoTClient | 55:59b527ab3452 | 1445 | { |
AzureIoTClient | 55:59b527ab3452 | 1446 | /*Codes_SRS_IOTHUBCLIENT_07_005: [ IoTHubClient_SetDeviceMethodCallback_Ex shall call IoTHubClient_LL_SetDeviceMethodCallback_Ex, while passing the IoTHubClient_LL_handle created by IoTHubClient_LL_Create along with the parameters iothub_ll_inbound_device_method_callback and IOTHUB_QUEUE_CONTEXT. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 1447 | queue_context->iotHubClientHandle = iotHubClientInstance; |
AzureIoTClient | 55:59b527ab3452 | 1448 | queue_context->userContextCallback = userContextCallback; |
AzureIoTClient | 55:59b527ab3452 | 1449 | /* Codes_SRS_IOTHUBCLIENT_07_006: [ When IoTHubClient_LL_SetDeviceMethodCallback_Ex is called, IoTHubClient_SetDeviceMethodCallback_Ex shall return the result of IoTHubClient_LL_SetDeviceMethodCallback_Ex. ] */ |
AzureIoTClient | 55:59b527ab3452 | 1450 | result = IoTHubClient_LL_SetDeviceMethodCallback_Ex(iotHubClientInstance->IoTHubClientLLHandle, iothub_ll_inbound_device_method_callback, queue_context); |
AzureIoTClient | 55:59b527ab3452 | 1451 | if (result != IOTHUB_CLIENT_OK) |
AzureIoTClient | 55:59b527ab3452 | 1452 | { |
AzureIoTClient | 55:59b527ab3452 | 1453 | LogError("IoTHubClient_LL_SetDeviceMethodCallback failed"); |
AzureIoTClient | 55:59b527ab3452 | 1454 | free(queue_context); |
AzureIoTClient | 55:59b527ab3452 | 1455 | } |
AzureIoTClient | 55:59b527ab3452 | 1456 | } |
AzureIoTClient | 55:59b527ab3452 | 1457 | } |
AzureIoTClient | 55:59b527ab3452 | 1458 | } |
AzureIoTClient | 55:59b527ab3452 | 1459 | |
AzureIoTClient | 55:59b527ab3452 | 1460 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 55:59b527ab3452 | 1461 | } |
AzureIoTClient | 55:59b527ab3452 | 1462 | } |
AzureIoTClient | 55:59b527ab3452 | 1463 | return result; |
AzureIoTClient | 55:59b527ab3452 | 1464 | } |
AzureIoTClient | 55:59b527ab3452 | 1465 | |
AzureIoTClient | 55:59b527ab3452 | 1466 | IOTHUB_CLIENT_RESULT IoTHubClient_DeviceMethodResponse(IOTHUB_CLIENT_HANDLE iotHubClientHandle, METHOD_HANDLE methodId, const unsigned char* response, size_t respSize, int statusCode) |
AzureIoTClient | 55:59b527ab3452 | 1467 | { |
AzureIoTClient | 55:59b527ab3452 | 1468 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 55:59b527ab3452 | 1469 | |
AzureIoTClient | 55:59b527ab3452 | 1470 | /*Codes_SRS_IOTHUBCLIENT_12_012: [ If iotHubClientHandle is NULL, IoTHubClient_SetDeviceMethodCallback shall return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 1471 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 55:59b527ab3452 | 1472 | { |
AzureIoTClient | 55:59b527ab3452 | 1473 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 55:59b527ab3452 | 1474 | LogError("invalid arg (NULL)"); |
AzureIoTClient | 55:59b527ab3452 | 1475 | } |
AzureIoTClient | 55:59b527ab3452 | 1476 | else |
AzureIoTClient | 55:59b527ab3452 | 1477 | { |
AzureIoTClient | 55:59b527ab3452 | 1478 | IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
AzureIoTClient | 55:59b527ab3452 | 1479 | |
AzureIoTClient | 55:59b527ab3452 | 1480 | /*Codes_SRS_IOTHUBCLIENT_12_018: [ IoTHubClient_SetDeviceMethodCallback shall be made thread-safe by using the lock created in IoTHubClient_Create. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 1481 | if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK) |
AzureIoTClient | 55:59b527ab3452 | 1482 | { |
AzureIoTClient | 55:59b527ab3452 | 1483 | /*Codes_SRS_IOTHUBCLIENT_12_013: [ If acquiring the lock fails, IoTHubClient_SetDeviceMethodCallback shall return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 55:59b527ab3452 | 1484 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 55:59b527ab3452 | 1485 | LogError("Could not acquire lock"); |
AzureIoTClient | 55:59b527ab3452 | 1486 | } |
AzureIoTClient | 55:59b527ab3452 | 1487 | else |
AzureIoTClient | 55:59b527ab3452 | 1488 | { |
AzureIoTClient | 55:59b527ab3452 | 1489 | result = IoTHubClient_LL_DeviceMethodResponse(iotHubClientInstance->IoTHubClientLLHandle, methodId, response, respSize, statusCode); |
AzureIoTClient | 55:59b527ab3452 | 1490 | if (result != IOTHUB_CLIENT_OK) |
AzureIoTClient | 55:59b527ab3452 | 1491 | { |
AzureIoTClient | 55:59b527ab3452 | 1492 | LogError("IoTHubClient_LL_DeviceMethodResponse failed"); |
AzureIoTClient | 55:59b527ab3452 | 1493 | } |
AzureIoTClient | 55:59b527ab3452 | 1494 | (void)Unlock(iotHubClientInstance->LockHandle); |
AzureIoTClient | 55:59b527ab3452 | 1495 | } |
AzureIoTClient | 55:59b527ab3452 | 1496 | } |
AzureIoTClient | 55:59b527ab3452 | 1497 | return result; |
AzureIoTClient | 55:59b527ab3452 | 1498 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1499 | |
AzureIoTClient | 44:33dd78697616 | 1500 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 1501 | static int uploadingThread(void *data) |
AzureIoTClient | 42:448eecc3676e | 1502 | { |
AzureIoTClient | 42:448eecc3676e | 1503 | UPLOADTOBLOB_SAVED_DATA* savedData = (UPLOADTOBLOB_SAVED_DATA*)data; |
AzureIoTClient | 42:448eecc3676e | 1504 | |
AzureIoTClient | 42:448eecc3676e | 1505 | /*it so happens that IoTHubClient_LL_UploadToBlob is thread-safe because there's no saved state in the handle and there are no globals, so no need to protect it*/ |
AzureIoTClient | 42:448eecc3676e | 1506 | /*not having it protected means multiple simultaneous uploads can happen*/ |
AzureIoTClient | 42:448eecc3676e | 1507 | /*Codes_SRS_IOTHUBCLIENT_02_054: [ The thread shall call IoTHubClient_LL_UploadToBlob passing the information packed in the structure. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1508 | if (IoTHubClient_LL_UploadToBlob(savedData->iotHubClientHandle->IoTHubClientLLHandle, savedData->destinationFileName, savedData->source, savedData->size) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 42:448eecc3676e | 1509 | { |
AzureIoTClient | 42:448eecc3676e | 1510 | LogError("unable to IoTHubClient_LL_UploadToBlob"); |
AzureIoTClient | 42:448eecc3676e | 1511 | /*call the callback*/ |
AzureIoTClient | 42:448eecc3676e | 1512 | if (savedData->iotHubClientFileUploadCallback != NULL) |
AzureIoTClient | 42:448eecc3676e | 1513 | { |
AzureIoTClient | 42:448eecc3676e | 1514 | /*Codes_SRS_IOTHUBCLIENT_02_055: [ If IoTHubClient_LL_UploadToBlob fails then the thread shall call iotHubClientFileUploadCallbackInternal passing as result FILE_UPLOAD_ERROR and as context the structure from SRS IOTHUBCLIENT 02 051. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1515 | savedData->iotHubClientFileUploadCallback(FILE_UPLOAD_ERROR, savedData->context); |
AzureIoTClient | 42:448eecc3676e | 1516 | } |
AzureIoTClient | 42:448eecc3676e | 1517 | } |
AzureIoTClient | 42:448eecc3676e | 1518 | else |
AzureIoTClient | 42:448eecc3676e | 1519 | { |
AzureIoTClient | 42:448eecc3676e | 1520 | if (savedData->iotHubClientFileUploadCallback != NULL) |
AzureIoTClient | 42:448eecc3676e | 1521 | { |
AzureIoTClient | 42:448eecc3676e | 1522 | /*Codes_SRS_IOTHUBCLIENT_02_056: [ Otherwise the thread iotHubClientFileUploadCallbackInternal passing as result FILE_UPLOAD_OK and the structure from SRS IOTHUBCLIENT 02 051. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1523 | savedData->iotHubClientFileUploadCallback(FILE_UPLOAD_OK, savedData->context); |
AzureIoTClient | 42:448eecc3676e | 1524 | } |
AzureIoTClient | 42:448eecc3676e | 1525 | } |
AzureIoTClient | 42:448eecc3676e | 1526 | |
AzureIoTClient | 42:448eecc3676e | 1527 | /*Codes_SRS_IOTHUBCLIENT_02_071: [ The thread shall mark itself as disposable. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1528 | if (Lock(savedData->lockGarbage) != LOCK_OK) |
AzureIoTClient | 42:448eecc3676e | 1529 | { |
AzureIoTClient | 42:448eecc3676e | 1530 | LogError("unable to Lock - trying anyway"); |
AzureIoTClient | 42:448eecc3676e | 1531 | savedData->canBeGarbageCollected = 1; |
AzureIoTClient | 42:448eecc3676e | 1532 | } |
AzureIoTClient | 42:448eecc3676e | 1533 | else |
AzureIoTClient | 42:448eecc3676e | 1534 | { |
AzureIoTClient | 42:448eecc3676e | 1535 | savedData->canBeGarbageCollected = 1; |
AzureIoTClient | 42:448eecc3676e | 1536 | |
AzureIoTClient | 42:448eecc3676e | 1537 | if (Unlock(savedData->lockGarbage) != LOCK_OK) |
AzureIoTClient | 42:448eecc3676e | 1538 | { |
AzureIoTClient | 42:448eecc3676e | 1539 | LogError("unable to Unlock after locking"); |
AzureIoTClient | 42:448eecc3676e | 1540 | } |
AzureIoTClient | 42:448eecc3676e | 1541 | } |
AzureIoTClient | 42:448eecc3676e | 1542 | return 0; |
AzureIoTClient | 42:448eecc3676e | 1543 | } |
AzureIoTClient | 43:038d8511e817 | 1544 | #endif |
AzureIoTClient | 42:448eecc3676e | 1545 | |
AzureIoTClient | 44:33dd78697616 | 1546 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 1547 | IOTHUB_CLIENT_RESULT IoTHubClient_UploadToBlobAsync(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const char* destinationFileName, const unsigned char* source, size_t size, IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK iotHubClientFileUploadCallback, void* context) |
AzureIoTClient | 42:448eecc3676e | 1548 | { |
AzureIoTClient | 42:448eecc3676e | 1549 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 42:448eecc3676e | 1550 | /*Codes_SRS_IOTHUBCLIENT_02_047: [ If iotHubClientHandle is NULL then IoTHubClient_UploadToBlobAsync shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1551 | /*Codes_SRS_IOTHUBCLIENT_02_048: [ If destinationFileName is NULL then IoTHubClient_UploadToBlobAsync shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1552 | /*Codes_SRS_IOTHUBCLIENT_02_049: [ If source is NULL and size is greated than 0 then IoTHubClient_UploadToBlobAsync shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1553 | if ( |
AzureIoTClient | 42:448eecc3676e | 1554 | (iotHubClientHandle == NULL) || |
AzureIoTClient | 42:448eecc3676e | 1555 | (destinationFileName == NULL) || |
AzureIoTClient | 42:448eecc3676e | 1556 | ((source == NULL) && (size > 0)) |
AzureIoTClient | 42:448eecc3676e | 1557 | ) |
AzureIoTClient | 42:448eecc3676e | 1558 | { |
AzureIoTClient | 42:448eecc3676e | 1559 | LogError("invalid parameters IOTHUB_CLIENT_HANDLE iotHubClientHandle = %p , const char* destinationFileName = %s, const unsigned char* source= %p, size_t size = %zu, IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK iotHubClientFileUploadCallback = %p, void* context = %p", |
AzureIoTClient | 42:448eecc3676e | 1560 | iotHubClientHandle, |
AzureIoTClient | 42:448eecc3676e | 1561 | destinationFileName, |
AzureIoTClient | 42:448eecc3676e | 1562 | source, |
AzureIoTClient | 42:448eecc3676e | 1563 | size, |
AzureIoTClient | 42:448eecc3676e | 1564 | iotHubClientFileUploadCallback, |
AzureIoTClient | 42:448eecc3676e | 1565 | context |
AzureIoTClient | 42:448eecc3676e | 1566 | ); |
AzureIoTClient | 42:448eecc3676e | 1567 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 42:448eecc3676e | 1568 | } |
AzureIoTClient | 42:448eecc3676e | 1569 | else |
AzureIoTClient | 42:448eecc3676e | 1570 | { |
AzureIoTClient | 42:448eecc3676e | 1571 | /*Codes_SRS_IOTHUBCLIENT_02_051: [IoTHubClient_UploadToBlobAsync shall copy the souce, size, iotHubClientFileUploadCallback, context into a structure.]*/ |
AzureIoTClient | 42:448eecc3676e | 1572 | UPLOADTOBLOB_SAVED_DATA *savedData = (UPLOADTOBLOB_SAVED_DATA *)malloc(sizeof(UPLOADTOBLOB_SAVED_DATA)); |
AzureIoTClient | 42:448eecc3676e | 1573 | if (savedData == NULL) |
AzureIoTClient | 42:448eecc3676e | 1574 | { |
AzureIoTClient | 42:448eecc3676e | 1575 | /*Codes_SRS_IOTHUBCLIENT_02_053: [ If copying to the structure or spawning the thread fails, then IoTHubClient_UploadToBlobAsync shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1576 | LogError("unable to malloc - oom"); |
AzureIoTClient | 42:448eecc3676e | 1577 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 1578 | } |
AzureIoTClient | 42:448eecc3676e | 1579 | else |
AzureIoTClient | 42:448eecc3676e | 1580 | { |
AzureIoTClient | 42:448eecc3676e | 1581 | if (mallocAndStrcpy_s((char**)&savedData->destinationFileName, destinationFileName) != 0) |
AzureIoTClient | 42:448eecc3676e | 1582 | { |
AzureIoTClient | 42:448eecc3676e | 1583 | /*Codes_SRS_IOTHUBCLIENT_02_053: [ If copying to the structure or spawning the thread fails, then IoTHubClient_UploadToBlobAsync shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1584 | LogError("unable to mallocAndStrcpy_s"); |
AzureIoTClient | 42:448eecc3676e | 1585 | free(savedData); |
AzureIoTClient | 42:448eecc3676e | 1586 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 1587 | } |
AzureIoTClient | 42:448eecc3676e | 1588 | else |
AzureIoTClient | 42:448eecc3676e | 1589 | { |
AzureIoTClient | 42:448eecc3676e | 1590 | savedData->size = size; |
AzureIoTClient | 42:448eecc3676e | 1591 | int sourceCloned; |
AzureIoTClient | 42:448eecc3676e | 1592 | if (size == 0) |
AzureIoTClient | 42:448eecc3676e | 1593 | { |
AzureIoTClient | 42:448eecc3676e | 1594 | savedData->source = NULL; |
AzureIoTClient | 42:448eecc3676e | 1595 | sourceCloned = 1; |
AzureIoTClient | 42:448eecc3676e | 1596 | } |
AzureIoTClient | 42:448eecc3676e | 1597 | else |
AzureIoTClient | 42:448eecc3676e | 1598 | { |
AzureIoTClient | 42:448eecc3676e | 1599 | savedData->source = (unsigned char*)malloc(size); |
AzureIoTClient | 42:448eecc3676e | 1600 | if (savedData->source == NULL) |
AzureIoTClient | 42:448eecc3676e | 1601 | { |
AzureIoTClient | 42:448eecc3676e | 1602 | /*Codes_SRS_IOTHUBCLIENT_02_053: [ If copying to the structure or spawning the thread fails, then IoTHubClient_UploadToBlobAsync shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1603 | LogError("unable to malloc - oom"); |
AzureIoTClient | 42:448eecc3676e | 1604 | free(savedData->destinationFileName); |
AzureIoTClient | 42:448eecc3676e | 1605 | free(savedData); |
AzureIoTClient | 42:448eecc3676e | 1606 | sourceCloned = 0; |
AzureIoTClient | 42:448eecc3676e | 1607 | } |
AzureIoTClient | 42:448eecc3676e | 1608 | else |
AzureIoTClient | 42:448eecc3676e | 1609 | { |
AzureIoTClient | 42:448eecc3676e | 1610 | sourceCloned = 1; |
AzureIoTClient | 42:448eecc3676e | 1611 | } |
AzureIoTClient | 42:448eecc3676e | 1612 | } |
AzureIoTClient | 42:448eecc3676e | 1613 | |
AzureIoTClient | 42:448eecc3676e | 1614 | if (sourceCloned == 0) |
AzureIoTClient | 42:448eecc3676e | 1615 | { |
AzureIoTClient | 42:448eecc3676e | 1616 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 1617 | } |
AzureIoTClient | 42:448eecc3676e | 1618 | else |
AzureIoTClient | 42:448eecc3676e | 1619 | { |
Azure.IoT.Build | 54:6dcad9019a64 | 1620 | IOTHUB_CLIENT_INSTANCE* iotHubClientHandleData = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle; |
Azure.IoT.Build | 54:6dcad9019a64 | 1621 | |
AzureIoTClient | 42:448eecc3676e | 1622 | savedData->iotHubClientFileUploadCallback = iotHubClientFileUploadCallback; |
AzureIoTClient | 42:448eecc3676e | 1623 | savedData->context = context; |
AzureIoTClient | 58:15b0d29b2667 | 1624 | (void)memcpy(savedData->source, source, size); |
Azure.IoT.Build | 54:6dcad9019a64 | 1625 | |
AzureIoTClient | 42:448eecc3676e | 1626 | if (Lock(iotHubClientHandleData->LockHandle) != LOCK_OK) /*locking because the next statement is changing blobThreadsToBeJoined*/ |
AzureIoTClient | 42:448eecc3676e | 1627 | { |
AzureIoTClient | 42:448eecc3676e | 1628 | LogError("unable to lock"); |
AzureIoTClient | 42:448eecc3676e | 1629 | free(savedData->source); |
AzureIoTClient | 42:448eecc3676e | 1630 | free(savedData->destinationFileName); |
AzureIoTClient | 42:448eecc3676e | 1631 | free(savedData); |
AzureIoTClient | 42:448eecc3676e | 1632 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 1633 | } |
AzureIoTClient | 42:448eecc3676e | 1634 | else |
AzureIoTClient | 42:448eecc3676e | 1635 | { |
AzureIoTClient | 42:448eecc3676e | 1636 | if ((result = StartWorkerThreadIfNeeded(iotHubClientHandleData)) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 42:448eecc3676e | 1637 | { |
AzureIoTClient | 42:448eecc3676e | 1638 | free(savedData->source); |
AzureIoTClient | 42:448eecc3676e | 1639 | free(savedData->destinationFileName); |
AzureIoTClient | 42:448eecc3676e | 1640 | free(savedData); |
AzureIoTClient | 42:448eecc3676e | 1641 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 1642 | LogError("Could not start worker thread"); |
AzureIoTClient | 42:448eecc3676e | 1643 | } |
AzureIoTClient | 42:448eecc3676e | 1644 | else |
AzureIoTClient | 42:448eecc3676e | 1645 | { |
AzureIoTClient | 42:448eecc3676e | 1646 | /*Codes_SRS_IOTHUBCLIENT_02_058: [ IoTHubClient_UploadToBlobAsync shall add the structure to the list of structures that need to be cleaned once file upload finishes. ]*/ |
AzureIoTClient | 52:1cc3c6d07cad | 1647 | LIST_ITEM_HANDLE item = singlylinkedlist_add(iotHubClientHandleData->savedDataToBeCleaned, savedData); |
AzureIoTClient | 42:448eecc3676e | 1648 | if (item == NULL) |
AzureIoTClient | 42:448eecc3676e | 1649 | { |
AzureIoTClient | 52:1cc3c6d07cad | 1650 | LogError("unable to singlylinkedlist_add"); |
AzureIoTClient | 42:448eecc3676e | 1651 | free(savedData->source); |
AzureIoTClient | 42:448eecc3676e | 1652 | free(savedData->destinationFileName); |
AzureIoTClient | 42:448eecc3676e | 1653 | free(savedData); |
AzureIoTClient | 42:448eecc3676e | 1654 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 1655 | } |
AzureIoTClient | 42:448eecc3676e | 1656 | else |
AzureIoTClient | 42:448eecc3676e | 1657 | { |
AzureIoTClient | 42:448eecc3676e | 1658 | savedData->iotHubClientHandle = iotHubClientHandle; |
AzureIoTClient | 42:448eecc3676e | 1659 | savedData->canBeGarbageCollected = 0; |
AzureIoTClient | 42:448eecc3676e | 1660 | if ((savedData->lockGarbage = Lock_Init()) == NULL) |
AzureIoTClient | 42:448eecc3676e | 1661 | { |
AzureIoTClient | 52:1cc3c6d07cad | 1662 | (void)singlylinkedlist_remove(iotHubClientHandleData->savedDataToBeCleaned, item); |
AzureIoTClient | 42:448eecc3676e | 1663 | free(savedData->source); |
AzureIoTClient | 42:448eecc3676e | 1664 | free(savedData->destinationFileName); |
AzureIoTClient | 42:448eecc3676e | 1665 | free(savedData); |
AzureIoTClient | 42:448eecc3676e | 1666 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 1667 | LogError("unable to Lock_Init"); |
AzureIoTClient | 42:448eecc3676e | 1668 | } |
AzureIoTClient | 42:448eecc3676e | 1669 | else |
AzureIoTClient | 42:448eecc3676e | 1670 | { |
AzureIoTClient | 42:448eecc3676e | 1671 | /*Codes_SRS_IOTHUBCLIENT_02_052: [ IoTHubClient_UploadToBlobAsync shall spawn a thread passing the structure build in SRS IOTHUBCLIENT 02 051 as thread data.]*/ |
AzureIoTClient | 42:448eecc3676e | 1672 | if (ThreadAPI_Create(&savedData->uploadingThreadHandle, uploadingThread, savedData) != THREADAPI_OK) |
AzureIoTClient | 42:448eecc3676e | 1673 | { |
AzureIoTClient | 42:448eecc3676e | 1674 | /*Codes_SRS_IOTHUBCLIENT_02_053: [ If copying to the structure or spawning the thread fails, then IoTHubClient_UploadToBlobAsync shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1675 | LogError("unablet to ThreadAPI_Create"); |
AzureIoTClient | 42:448eecc3676e | 1676 | (void)Lock_Deinit(savedData->lockGarbage); |
AzureIoTClient | 52:1cc3c6d07cad | 1677 | (void)singlylinkedlist_remove(iotHubClientHandleData->savedDataToBeCleaned, item); |
AzureIoTClient | 42:448eecc3676e | 1678 | free(savedData->source); |
AzureIoTClient | 42:448eecc3676e | 1679 | free(savedData->destinationFileName); |
AzureIoTClient | 42:448eecc3676e | 1680 | free(savedData); |
AzureIoTClient | 42:448eecc3676e | 1681 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 1682 | } |
AzureIoTClient | 42:448eecc3676e | 1683 | else |
AzureIoTClient | 42:448eecc3676e | 1684 | { |
AzureIoTClient | 42:448eecc3676e | 1685 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 42:448eecc3676e | 1686 | } |
AzureIoTClient | 42:448eecc3676e | 1687 | } |
AzureIoTClient | 42:448eecc3676e | 1688 | } |
AzureIoTClient | 42:448eecc3676e | 1689 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1690 | (void)Unlock(iotHubClientHandleData->LockHandle); |
AzureIoTClient | 42:448eecc3676e | 1691 | } |
AzureIoTClient | 42:448eecc3676e | 1692 | } |
AzureIoTClient | 42:448eecc3676e | 1693 | } |
AzureIoTClient | 42:448eecc3676e | 1694 | } |
AzureIoTClient | 42:448eecc3676e | 1695 | } |
AzureIoTClient | 42:448eecc3676e | 1696 | return result; |
AzureIoTClient | 42:448eecc3676e | 1697 | } |
AzureIoTClient | 44:33dd78697616 | 1698 | #endif /*DONT_USE_UPLOADTOBLOB*/ |