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

Committer:
AzureIoTClient
Date:
Fri Mar 24 16:35:32 2017 -0700
Revision:
62:5a4cdacf5090
Parent:
61:8b85a4e797cf
Child:
66:a419827cb051
1.1.10

Who changed what in which revision?

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