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