corrected version (with typedef struct IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA* IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE;) included in the sources

Dependents:   STM32F746_iothub_client_sample_mqtt

Fork of iothub_client by Azure IoT

Committer:
Azure.IoT Build
Date:
Fri Apr 08 13:24:33 2016 -0700
Revision:
38:a05929a75111
Parent:
37:18310e4d888d
Child:
39:2719651a5bee
1.0.4

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>
AzureIoTClient 16:deba40344375 5 #ifdef _CRTDBG_MAP_ALLOC
AzureIoTClient 16:deba40344375 6 #include <crtdbg.h>
AzureIoTClient 16:deba40344375 7 #endif
Azure.IoT Build 38:a05929a75111 8 #include "azure_c_shared_utility/gballoc.h"
AzureIoTClient 16:deba40344375 9
AzureIoTClient 16:deba40344375 10 #include <stdlib.h>
AzureIoTClient 16:deba40344375 11 #include <signal.h>
Azure.IoT Build 35:ceed20da4ba6 12 #include <stddef.h>
Azure.IoT Build 38:a05929a75111 13 #include "azure_c_shared_utility/crt_abstractions.h"
AzureIoTClient 16:deba40344375 14 #include "iothub_client.h"
AzureIoTClient 16:deba40344375 15 #include "iothub_client_ll.h"
Azure.IoT Build 37:18310e4d888d 16 #include "iothubtransport.h"
Azure.IoT Build 38:a05929a75111 17 #include "azure_c_shared_utility/threadapi.h"
Azure.IoT Build 38:a05929a75111 18 #include "azure_c_shared_utility/lock.h"
Azure.IoT Build 38:a05929a75111 19 #include "azure_c_shared_utility/iot_logging.h"
AzureIoTClient 16:deba40344375 20
AzureIoTClient 16:deba40344375 21 typedef struct IOTHUB_CLIENT_INSTANCE_TAG
AzureIoTClient 16:deba40344375 22 {
AzureIoTClient 16:deba40344375 23 IOTHUB_CLIENT_LL_HANDLE IoTHubClientLLHandle;
Azure.IoT Build 37:18310e4d888d 24 TRANSPORT_HANDLE TransportHandle;
AzureIoTClient 16:deba40344375 25 THREAD_HANDLE ThreadHandle;
AzureIoTClient 16:deba40344375 26 LOCK_HANDLE LockHandle;
AzureIoTClient 16:deba40344375 27 sig_atomic_t StopThread;
AzureIoTClient 16:deba40344375 28 } IOTHUB_CLIENT_INSTANCE;
AzureIoTClient 16:deba40344375 29
Azure.IoT Build 35:ceed20da4ba6 30 /*used by unittests only*/
Azure.IoT Build 35:ceed20da4ba6 31 const size_t IoTHubClient_ThreadTerminationOffset = offsetof(IOTHUB_CLIENT_INSTANCE, StopThread);
Azure.IoT Build 35:ceed20da4ba6 32
AzureIoTClient 16:deba40344375 33 static int ScheduleWork_Thread(void* threadArgument)
AzureIoTClient 16:deba40344375 34 {
AzureIoTClient 16:deba40344375 35 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)threadArgument;
AzureIoTClient 16:deba40344375 36
Azure.IoT Build 37:18310e4d888d 37 while (1)
AzureIoTClient 16:deba40344375 38 {
AzureIoTClient 16:deba40344375 39 if (Lock(iotHubClientInstance->LockHandle) == LOCK_OK)
AzureIoTClient 16:deba40344375 40 {
Azure.IoT Build 37:18310e4d888d 41 /*Codes_SRS_IOTHUBCLIENT_01_038: [ The thread shall exit when IoTHubClient_Destroy is called. ]*/
Azure.IoT Build 37:18310e4d888d 42 if (iotHubClientInstance->StopThread)
Azure.IoT Build 37:18310e4d888d 43 {
Azure.IoT Build 37:18310e4d888d 44 (void)Unlock(iotHubClientInstance->LockHandle);
Azure.IoT Build 37:18310e4d888d 45 break; /*gets out of the thread*/
Azure.IoT Build 37:18310e4d888d 46 }
Azure.IoT Build 37:18310e4d888d 47 else
Azure.IoT Build 37:18310e4d888d 48 {
Azure.IoT Build 37:18310e4d888d 49 /* 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 50 /* 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 51 IoTHubClient_LL_DoWork(iotHubClientInstance->IoTHubClientLLHandle);
Azure.IoT Build 37:18310e4d888d 52 (void)Unlock(iotHubClientInstance->LockHandle);
Azure.IoT Build 37:18310e4d888d 53 }
AzureIoTClient 16:deba40344375 54 }
Azure.IoT Build 37:18310e4d888d 55 else
Azure.IoT Build 37:18310e4d888d 56 {
Azure.IoT Build 37:18310e4d888d 57 /*Codes_SRS_IOTHUBCLIENT_01_040: [If acquiring the lock fails, IoTHubClient_LL_DoWork shall not be called.]*/
Azure.IoT Build 37:18310e4d888d 58 /*no code, shall retry*/
Azure.IoT Build 37:18310e4d888d 59 }
Azure.IoT Build 37:18310e4d888d 60 (void)ThreadAPI_Sleep(1);
AzureIoTClient 16:deba40344375 61 }
Azure.IoT Build 37:18310e4d888d 62
AzureIoTClient 16:deba40344375 63 return 0;
AzureIoTClient 16:deba40344375 64 }
AzureIoTClient 16:deba40344375 65
Azure.IoT Build 37:18310e4d888d 66 static IOTHUB_CLIENT_RESULT StartWorkerThreadIfNeeded(IOTHUB_CLIENT_INSTANCE* iotHubClientInstance)
AzureIoTClient 16:deba40344375 67 {
Azure.IoT Build 37:18310e4d888d 68 IOTHUB_CLIENT_RESULT result;
Azure.IoT Build 37:18310e4d888d 69 if (iotHubClientInstance->TransportHandle == NULL)
Azure.IoT Build 37:18310e4d888d 70 {
Azure.IoT Build 37:18310e4d888d 71 if (iotHubClientInstance->ThreadHandle == NULL)
Azure.IoT Build 37:18310e4d888d 72 {
Azure.IoT Build 37:18310e4d888d 73 iotHubClientInstance->StopThread = 0;
Azure.IoT Build 37:18310e4d888d 74 if (ThreadAPI_Create(&iotHubClientInstance->ThreadHandle, ScheduleWork_Thread, iotHubClientInstance) != THREADAPI_OK)
Azure.IoT Build 37:18310e4d888d 75 {
Azure.IoT Build 37:18310e4d888d 76 iotHubClientInstance->ThreadHandle = NULL;
Azure.IoT Build 37:18310e4d888d 77 result = IOTHUB_CLIENT_ERROR;
Azure.IoT Build 37:18310e4d888d 78 }
Azure.IoT Build 37:18310e4d888d 79 else
Azure.IoT Build 37:18310e4d888d 80 {
Azure.IoT Build 37:18310e4d888d 81 result = IOTHUB_CLIENT_OK;
Azure.IoT Build 37:18310e4d888d 82 }
Azure.IoT Build 37:18310e4d888d 83 }
Azure.IoT Build 37:18310e4d888d 84 else
Azure.IoT Build 37:18310e4d888d 85 {
Azure.IoT Build 37:18310e4d888d 86 result = IOTHUB_CLIENT_OK;
Azure.IoT Build 37:18310e4d888d 87 }
Azure.IoT Build 37:18310e4d888d 88 }
Azure.IoT Build 37:18310e4d888d 89 else
Azure.IoT Build 37:18310e4d888d 90 {
Azure.IoT Build 37:18310e4d888d 91 /*Codes_SRS_IOTHUBCLIENT_17_012: [ If the transport connection is shared, the thread shall be started by calling IoTHubTransport_StartWorkerThread. ]*/
Azure.IoT Build 37:18310e4d888d 92 /*Codes_SRS_IOTHUBCLIENT_17_011: [ If the transport connection is shared, the thread shall be started by calling IoTHubTransport_StartWorkerThread*/
Azure.IoT Build 37:18310e4d888d 93
Azure.IoT Build 37:18310e4d888d 94 result = IoTHubTransport_StartWorkerThread(iotHubClientInstance->TransportHandle, iotHubClientInstance);
Azure.IoT Build 37:18310e4d888d 95 }
Azure.IoT Build 37:18310e4d888d 96 return result;
AzureIoTClient 16:deba40344375 97 }
AzureIoTClient 16:deba40344375 98
AzureIoTClient 16:deba40344375 99 IOTHUB_CLIENT_HANDLE IoTHubClient_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol)
AzureIoTClient 16:deba40344375 100 {
AzureIoTClient 16:deba40344375 101 IOTHUB_CLIENT_INSTANCE* result = NULL;
AzureIoTClient 16:deba40344375 102
AzureIoTClient 16:deba40344375 103 /* Codes_SRS_IOTHUBCLIENT_12_003: [IoTHubClient_CreateFromConnectionString shall verify the input parameter and if it is NULL then return NULL] */
AzureIoTClient 16:deba40344375 104 if (connectionString == NULL)
AzureIoTClient 16:deba40344375 105 {
AzureIoTClient 16:deba40344375 106 LogError("Input parameter is NULL: connectionString\r\n");
AzureIoTClient 16:deba40344375 107 }
AzureIoTClient 16:deba40344375 108 else if (protocol == NULL)
AzureIoTClient 16:deba40344375 109 {
AzureIoTClient 16:deba40344375 110 LogError("Input parameter is NULL: protocol\r\n");
AzureIoTClient 16:deba40344375 111 }
AzureIoTClient 16:deba40344375 112 else
AzureIoTClient 16:deba40344375 113 {
AzureIoTClient 16:deba40344375 114 /* Codes_SRS_IOTHUBCLIENT_12_004: [IoTHubClient_CreateFromConnectionString shall allocate a new IoTHubClient instance.] */
AzureIoTClient 16:deba40344375 115 result = malloc(sizeof(IOTHUB_CLIENT_INSTANCE));
AzureIoTClient 16:deba40344375 116
AzureIoTClient 16:deba40344375 117 /* Codes_SRS_IOTHUBCLIENT_12_011: [If the allocation failed, IoTHubClient_CreateFromConnectionString returns NULL] */
AzureIoTClient 16:deba40344375 118 if (result == NULL)
AzureIoTClient 16:deba40344375 119 {
AzureIoTClient 16:deba40344375 120 LogError("Malloc failed\r\n");
AzureIoTClient 16:deba40344375 121 }
AzureIoTClient 16:deba40344375 122 else
AzureIoTClient 16:deba40344375 123 {
Azure.IoT Build 37:18310e4d888d 124 /* Codes_SRS_IOTHUBCLIENT_12_005: [IoTHubClient_CreateFromConnectionString shall create a lock object to be used later for serializing IoTHubClient calls] */
Azure.IoT Build 37:18310e4d888d 125 result->LockHandle = Lock_Init();
Azure.IoT Build 37:18310e4d888d 126 if (result->LockHandle == NULL)
AzureIoTClient 16:deba40344375 127 {
Azure.IoT Build 37:18310e4d888d 128 /* Codes_SRS_IOTHUBCLIENT_12_009: [If lock creation failed, IoTHubClient_CreateFromConnectionString shall do clean up and return NULL] */
AzureIoTClient 16:deba40344375 129 free(result);
AzureIoTClient 16:deba40344375 130 result = NULL;
Azure.IoT Build 37:18310e4d888d 131 LogError("Lock_Init failed\r\n");
AzureIoTClient 16:deba40344375 132 }
AzureIoTClient 16:deba40344375 133 else
Azure.IoT Build 37:18310e4d888d 134 {
Azure.IoT Build 37:18310e4d888d 135 /* 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 37:18310e4d888d 136 result->IoTHubClientLLHandle = IoTHubClient_LL_CreateFromConnectionString(connectionString, protocol);
Azure.IoT Build 37:18310e4d888d 137 if (result->IoTHubClientLLHandle == NULL)
Azure.IoT Build 37:18310e4d888d 138 {
Azure.IoT Build 37:18310e4d888d 139 /* Codes_SRS_IOTHUBCLIENT_12_010: [If IoTHubClient_LL_CreateFromConnectionString fails then IoTHubClient_CreateFromConnectionString shall do clean - up and return NULL] */
Azure.IoT Build 37:18310e4d888d 140 Lock_Deinit(result->LockHandle);
Azure.IoT Build 37:18310e4d888d 141 free(result);
Azure.IoT Build 37:18310e4d888d 142 result = NULL;
Azure.IoT Build 37:18310e4d888d 143 LogError("IoTHubClient_LL_CreateFromConnectionString failed\r\n");
Azure.IoT Build 37:18310e4d888d 144 }
Azure.IoT Build 37:18310e4d888d 145 else
Azure.IoT Build 37:18310e4d888d 146 {
Azure.IoT Build 37:18310e4d888d 147 result->ThreadHandle = NULL;
Azure.IoT Build 37:18310e4d888d 148 result->TransportHandle = NULL;
Azure.IoT Build 37:18310e4d888d 149 }
AzureIoTClient 16:deba40344375 150 }
Azure.IoT Build 37:18310e4d888d 151
AzureIoTClient 16:deba40344375 152 }
AzureIoTClient 16:deba40344375 153 }
AzureIoTClient 16:deba40344375 154 return result;
AzureIoTClient 16:deba40344375 155 }
AzureIoTClient 16:deba40344375 156
AzureIoTClient 16:deba40344375 157
AzureIoTClient 16:deba40344375 158 IOTHUB_CLIENT_HANDLE IoTHubClient_Create(const IOTHUB_CLIENT_CONFIG* config)
AzureIoTClient 16:deba40344375 159 {
AzureIoTClient 16:deba40344375 160 /* Codes_SRS_IOTHUBCLIENT_01_001: [IoTHubClient_Create shall allocate a new IoTHubClient instance and return a non-NULL handle to it.] */
AzureIoTClient 16:deba40344375 161 IOTHUB_CLIENT_INSTANCE* result = (IOTHUB_CLIENT_INSTANCE*)malloc(sizeof(IOTHUB_CLIENT_INSTANCE));
AzureIoTClient 16:deba40344375 162
AzureIoTClient 16:deba40344375 163 /* Codes_SRS_IOTHUBCLIENT_01_004: [If allocating memory for the new IoTHubClient instance fails, then IoTHubClient_Create shall return NULL.] */
AzureIoTClient 16:deba40344375 164 if (result != NULL)
AzureIoTClient 16:deba40344375 165 {
AzureIoTClient 16:deba40344375 166 /* Codes_SRS_IOTHUBCLIENT_01_029: [IoTHubClient_Create shall create a lock object to be used later for serializing IoTHubClient calls.] */
AzureIoTClient 16:deba40344375 167 result->LockHandle = Lock_Init();
AzureIoTClient 16:deba40344375 168 if (result->LockHandle == NULL)
AzureIoTClient 16:deba40344375 169 {
AzureIoTClient 16:deba40344375 170 /* Codes_SRS_IOTHUBCLIENT_01_030: [If creating the lock fails, then IoTHubClient_Create shall return NULL.] */
AzureIoTClient 16:deba40344375 171 /* Codes_SRS_IOTHUBCLIENT_01_031: [If IoTHubClient_Create fails, all resources allocated by it shall be freed.] */
AzureIoTClient 16:deba40344375 172 free(result);
AzureIoTClient 16:deba40344375 173 result = NULL;
AzureIoTClient 16:deba40344375 174 }
AzureIoTClient 16:deba40344375 175 else
AzureIoTClient 16:deba40344375 176 {
AzureIoTClient 16:deba40344375 177 /* Codes_SRS_IOTHUBCLIENT_01_002: [IoTHubClient_Create shall instantiate a new IoTHubClient_LL instance by calling IoTHubClient_LL_Create and passing the config argument.] */
AzureIoTClient 16:deba40344375 178 result->IoTHubClientLLHandle = IoTHubClient_LL_Create(config);
AzureIoTClient 16:deba40344375 179 if (result->IoTHubClientLLHandle == NULL)
AzureIoTClient 16:deba40344375 180 {
AzureIoTClient 16:deba40344375 181 /* Codes_SRS_IOTHUBCLIENT_01_003: [If IoTHubClient_LL_Create fails, then IoTHubClient_Create shall return NULL.] */
AzureIoTClient 16:deba40344375 182 /* Codes_SRS_IOTHUBCLIENT_01_031: [If IoTHubClient_Create fails, all resources allocated by it shall be freed.] */
AzureIoTClient 16:deba40344375 183 Lock_Deinit(result->LockHandle);
AzureIoTClient 16:deba40344375 184 free(result);
AzureIoTClient 16:deba40344375 185 result = NULL;
AzureIoTClient 16:deba40344375 186 }
Azure.IoT Build 37:18310e4d888d 187 else
Azure.IoT Build 37:18310e4d888d 188 {
Azure.IoT Build 37:18310e4d888d 189 result->TransportHandle = NULL;
Azure.IoT Build 37:18310e4d888d 190 result->ThreadHandle = NULL;
Azure.IoT Build 37:18310e4d888d 191 }
AzureIoTClient 16:deba40344375 192 }
AzureIoTClient 16:deba40344375 193 }
AzureIoTClient 16:deba40344375 194
AzureIoTClient 16:deba40344375 195 return result;
AzureIoTClient 16:deba40344375 196 }
AzureIoTClient 16:deba40344375 197
Azure.IoT Build 37:18310e4d888d 198 IOTHUB_CLIENT_HANDLE IoTHubClient_CreateWithTransport(TRANSPORT_HANDLE transportHandle, const IOTHUB_CLIENT_CONFIG* config)
Azure.IoT Build 37:18310e4d888d 199 {
Azure.IoT Build 37:18310e4d888d 200 IOTHUB_CLIENT_INSTANCE* result;
Azure.IoT Build 37:18310e4d888d 201 /*Codes_SRS_IOTHUBCLIENT_17_013: [ IoTHubClient_CreateWithTransport shall return NULL if transportHandle is NULL. ]*/
Azure.IoT Build 37:18310e4d888d 202 /*Codes_SRS_IOTHUBCLIENT_17_014: [ IoTHubClient_CreateWithTransport shall return NULL if config is NULL. ]*/
Azure.IoT Build 37:18310e4d888d 203 if (transportHandle == NULL || config == NULL)
Azure.IoT Build 37:18310e4d888d 204 {
Azure.IoT Build 37:18310e4d888d 205 result = NULL;
Azure.IoT Build 37:18310e4d888d 206 }
Azure.IoT Build 37:18310e4d888d 207 else
Azure.IoT Build 37:18310e4d888d 208 {
Azure.IoT Build 37:18310e4d888d 209 /*Codes_SRS_IOTHUBCLIENT_17_001: [ IoTHubClient_CreateWithTransport shall allocate a new IoTHubClient instance and return a non-NULL handle to it. ]*/
Azure.IoT Build 37:18310e4d888d 210 result = (IOTHUB_CLIENT_INSTANCE*)malloc(sizeof(IOTHUB_CLIENT_INSTANCE));
Azure.IoT Build 37:18310e4d888d 211 /*Codes_SRS_IOTHUBCLIENT_17_002: [ If allocating memory for the new IoTHubClient instance fails, then IoTHubClient_CreateWithTransport shall return NULL. ]*/
Azure.IoT Build 37:18310e4d888d 212 if (result != NULL)
Azure.IoT Build 37:18310e4d888d 213 {
Azure.IoT Build 37:18310e4d888d 214 result->ThreadHandle = NULL;
Azure.IoT Build 37:18310e4d888d 215 result->TransportHandle = transportHandle;
Azure.IoT Build 37:18310e4d888d 216 /*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 37:18310e4d888d 217 LOCK_HANDLE transportLock = IoTHubTransport_GetLock(transportHandle);
Azure.IoT Build 37:18310e4d888d 218 result->LockHandle = transportLock;
Azure.IoT Build 37:18310e4d888d 219 if (result->LockHandle == NULL)
Azure.IoT Build 37:18310e4d888d 220 {
Azure.IoT Build 37:18310e4d888d 221 /*Codes_SRS_IOTHUBCLIENT_17_006: [ If IoTHubTransport_GetLock fails, then IoTHubClient_CreateWithTransport shall return NULL. ]*/
Azure.IoT Build 37:18310e4d888d 222 free(result);
Azure.IoT Build 37:18310e4d888d 223 result = NULL;
Azure.IoT Build 37:18310e4d888d 224 }
Azure.IoT Build 37:18310e4d888d 225 else
Azure.IoT Build 37:18310e4d888d 226 {
Azure.IoT Build 37:18310e4d888d 227 IOTHUB_CLIENT_DEVICE_CONFIG deviceConfig;
Azure.IoT Build 37:18310e4d888d 228 deviceConfig.deviceId = config->deviceId;
Azure.IoT Build 37:18310e4d888d 229 deviceConfig.deviceKey = config->deviceKey;
Azure.IoT Build 37:18310e4d888d 230 deviceConfig.protocol = config->protocol;
Azure.IoT Build 37:18310e4d888d 231
Azure.IoT Build 37:18310e4d888d 232 /*Codes_SRS_IOTHUBCLIENT_17_003: [ IoTHubClient_CreateWithTransport shall call IoTHubTransport_GetLLTransport on transportHandle to get lower layer transport. ]*/
Azure.IoT Build 37:18310e4d888d 233 deviceConfig.transportHandle = IoTHubTransport_GetLLTransport(transportHandle);
Azure.IoT Build 37:18310e4d888d 234
Azure.IoT Build 37:18310e4d888d 235 if (deviceConfig.transportHandle == NULL)
Azure.IoT Build 37:18310e4d888d 236 {
Azure.IoT Build 37:18310e4d888d 237 /*Codes_SRS_IOTHUBCLIENT_17_004: [ If IoTHubTransport_GetLLTransport fails, then IoTHubClient_CreateWithTransport shall return NULL. ]*/
Azure.IoT Build 37:18310e4d888d 238 free(result);
Azure.IoT Build 37:18310e4d888d 239 result = NULL;
Azure.IoT Build 37:18310e4d888d 240 }
Azure.IoT Build 37:18310e4d888d 241 else
Azure.IoT Build 37:18310e4d888d 242 {
Azure.IoT Build 37:18310e4d888d 243 if (Lock(transportLock) != LOCK_OK)
Azure.IoT Build 37:18310e4d888d 244 {
Azure.IoT Build 37:18310e4d888d 245 free(result);
Azure.IoT Build 37:18310e4d888d 246 result = NULL;
Azure.IoT Build 37:18310e4d888d 247 }
Azure.IoT Build 37:18310e4d888d 248 else
Azure.IoT Build 37:18310e4d888d 249 {
Azure.IoT Build 37:18310e4d888d 250 /*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 37:18310e4d888d 251 result->IoTHubClientLLHandle = IoTHubClient_LL_CreateWithTransport(&deviceConfig);
Azure.IoT Build 37:18310e4d888d 252 if (result->IoTHubClientLLHandle == NULL)
Azure.IoT Build 37:18310e4d888d 253 {
Azure.IoT Build 37:18310e4d888d 254 /*Codes_SRS_IOTHUBCLIENT_17_008: [ If IoTHubClient_LL_CreateWithTransport fails, then IoTHubClient_Create shall return NULL. ]*/
Azure.IoT Build 37:18310e4d888d 255 /*Codes_SRS_IOTHUBCLIENT_17_009: [ If IoTHubClient_LL_CreateWithTransport fails, all resources allocated by it shall be freed. ]*/
Azure.IoT Build 37:18310e4d888d 256 free(result);
Azure.IoT Build 37:18310e4d888d 257 result = NULL;
Azure.IoT Build 37:18310e4d888d 258 }
Azure.IoT Build 37:18310e4d888d 259
Azure.IoT Build 37:18310e4d888d 260 if (Unlock(transportLock) != LOCK_OK)
Azure.IoT Build 37:18310e4d888d 261 {
Azure.IoT Build 37:18310e4d888d 262 LogError("unable to Unlock");
Azure.IoT Build 37:18310e4d888d 263 }
Azure.IoT Build 37:18310e4d888d 264 }
Azure.IoT Build 37:18310e4d888d 265
Azure.IoT Build 37:18310e4d888d 266 }
Azure.IoT Build 37:18310e4d888d 267 }
Azure.IoT Build 37:18310e4d888d 268 }
Azure.IoT Build 37:18310e4d888d 269 }
Azure.IoT Build 37:18310e4d888d 270
Azure.IoT Build 37:18310e4d888d 271 return result;
Azure.IoT Build 37:18310e4d888d 272 }
Azure.IoT Build 37:18310e4d888d 273
AzureIoTClient 16:deba40344375 274 /* Codes_SRS_IOTHUBCLIENT_01_005: [IoTHubClient_Destroy shall free all resources associated with the iotHubClientHandle instance.] */
AzureIoTClient 18:1e9adb15c645 275 void IoTHubClient_Destroy(IOTHUB_CLIENT_HANDLE iotHubClientHandle)
AzureIoTClient 16:deba40344375 276 {
AzureIoTClient 16:deba40344375 277 /* Codes_SRS_IOTHUBCLIENT_01_008: [IoTHubClient_Destroy shall do nothing if parameter iotHubClientHandle is NULL.] */
AzureIoTClient 16:deba40344375 278 if (iotHubClientHandle != NULL)
AzureIoTClient 16:deba40344375 279 {
Azure.IoT Build 37:18310e4d888d 280 bool okToJoin;
Azure.IoT Build 37:18310e4d888d 281
AzureIoTClient 16:deba40344375 282 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 283
Azure.IoT Build 37:18310e4d888d 284 /*Codes_SRS_IOTHUBCLIENT_02_043: [ IoTHubClient_Destroy shall lock the serializing lock and signal the worker thread (if any) to end ]*/
Azure.IoT Build 37:18310e4d888d 285 if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
Azure.IoT Build 37:18310e4d888d 286 {
Azure.IoT Build 37:18310e4d888d 287 LogError("unable to Lock - - will still proceed to try to end the thread without locking");
Azure.IoT Build 37:18310e4d888d 288 }
Azure.IoT Build 37:18310e4d888d 289
AzureIoTClient 16:deba40344375 290 if (iotHubClientInstance->ThreadHandle != NULL)
AzureIoTClient 16:deba40344375 291 {
Azure.IoT Build 37:18310e4d888d 292 iotHubClientInstance->StopThread = 1;
Azure.IoT Build 37:18310e4d888d 293 okToJoin = true;
AzureIoTClient 16:deba40344375 294 }
Azure.IoT Build 37:18310e4d888d 295 else
Azure.IoT Build 37:18310e4d888d 296 {
Azure.IoT Build 37:18310e4d888d 297 okToJoin = false;
Azure.IoT Build 37:18310e4d888d 298 }
Azure.IoT Build 37:18310e4d888d 299
Azure.IoT Build 37:18310e4d888d 300 if (iotHubClientInstance->TransportHandle != NULL)
Azure.IoT Build 37:18310e4d888d 301 {
Azure.IoT Build 37:18310e4d888d 302 /*Codes_SRS_IOTHUBCLIENT_01_007: [ The thread created as part of executing IoTHubClient_SendEventAsync or IoTHubClient_SetNotificationMessageCallback shall be joined. ]*/
Azure.IoT Build 37:18310e4d888d 303 okToJoin = IoTHubTransport_SignalEndWorkerThread(iotHubClientInstance->TransportHandle, iotHubClientHandle);
Azure.IoT Build 37:18310e4d888d 304 }
AzureIoTClient 16:deba40344375 305
AzureIoTClient 16:deba40344375 306 /* Codes_SRS_IOTHUBCLIENT_01_006: [That includes destroying the IoTHubClient_LL instance by calling IoTHubClient_LL_Destroy.] */
AzureIoTClient 16:deba40344375 307 IoTHubClient_LL_Destroy(iotHubClientInstance->IoTHubClientLLHandle);
AzureIoTClient 16:deba40344375 308
Azure.IoT Build 37:18310e4d888d 309 /*Codes_SRS_IOTHUBCLIENT_02_045: [ IoTHubClient_Destroy shall unlock the serializing lock. ]*/
Azure.IoT Build 37:18310e4d888d 310 if (Unlock(iotHubClientInstance->LockHandle) != LOCK_OK)
Azure.IoT Build 37:18310e4d888d 311 {
Azure.IoT Build 37:18310e4d888d 312 LogError("unable to Unlock");
Azure.IoT Build 37:18310e4d888d 313 }
Azure.IoT Build 37:18310e4d888d 314
Azure.IoT Build 37:18310e4d888d 315 if (okToJoin == true)
Azure.IoT Build 37:18310e4d888d 316 {
Azure.IoT Build 37:18310e4d888d 317 if (iotHubClientInstance->ThreadHandle != NULL)
Azure.IoT Build 37:18310e4d888d 318 {
Azure.IoT Build 37:18310e4d888d 319 int res;
Azure.IoT Build 37:18310e4d888d 320 /*Codes_SRS_IOTHUBCLIENT_01_007: [ The thread created as part of executing IoTHubClient_SendEventAsync or IoTHubClient_SetNotificationMessageCallback shall be joined. ]*/
Azure.IoT Build 37:18310e4d888d 321 if (ThreadAPI_Join(iotHubClientInstance->ThreadHandle, &res) != THREADAPI_OK)
Azure.IoT Build 37:18310e4d888d 322 {
Azure.IoT Build 37:18310e4d888d 323 LogError("ThreadAPI_Join failed\r\n");
Azure.IoT Build 37:18310e4d888d 324 }
Azure.IoT Build 37:18310e4d888d 325 }
Azure.IoT Build 37:18310e4d888d 326 if (iotHubClientInstance->TransportHandle != NULL)
Azure.IoT Build 37:18310e4d888d 327 {
Azure.IoT Build 37:18310e4d888d 328 /*Codes_SRS_IOTHUBCLIENT_01_007: [ The thread created as part of executing IoTHubClient_SendEventAsync or IoTHubClient_SetNotificationMessageCallback shall be joined. ]*/
Azure.IoT Build 37:18310e4d888d 329 IoTHubTransport_JoinWorkerThread(iotHubClientInstance->TransportHandle, iotHubClientHandle);
Azure.IoT Build 37:18310e4d888d 330 }
Azure.IoT Build 37:18310e4d888d 331 }
Azure.IoT Build 37:18310e4d888d 332
Azure.IoT Build 37:18310e4d888d 333 if (iotHubClientInstance->TransportHandle == NULL)
Azure.IoT Build 37:18310e4d888d 334 {
Azure.IoT Build 37:18310e4d888d 335 /* Codes_SRS_IOTHUBCLIENT_01_032: [If the lock was allocated in IoTHubClient_Create, it shall be also freed..] */
Azure.IoT Build 37:18310e4d888d 336 Lock_Deinit(iotHubClientInstance->LockHandle);
Azure.IoT Build 37:18310e4d888d 337 }
Azure.IoT Build 37:18310e4d888d 338
AzureIoTClient 16:deba40344375 339 free(iotHubClientInstance);
AzureIoTClient 16:deba40344375 340 }
AzureIoTClient 16:deba40344375 341 }
AzureIoTClient 16:deba40344375 342
AzureIoTClient 16:deba40344375 343 IOTHUB_CLIENT_RESULT IoTHubClient_SendEventAsync(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK eventConfirmationCallback, void* userContextCallback)
AzureIoTClient 16:deba40344375 344 {
AzureIoTClient 16:deba40344375 345 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 346
AzureIoTClient 16:deba40344375 347 if (iotHubClientHandle == NULL)
AzureIoTClient 16:deba40344375 348 {
AzureIoTClient 16:deba40344375 349 /* Codes_SRS_IOTHUBCLIENT_01_011: [If iotHubClientHandle is NULL, IoTHubClient_SendEventAsync shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 16:deba40344375 350 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 16:deba40344375 351 LogError("NULL iothubClientHandle\r\n");
AzureIoTClient 16:deba40344375 352 }
AzureIoTClient 16:deba40344375 353 else
AzureIoTClient 16:deba40344375 354 {
AzureIoTClient 16:deba40344375 355 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 356
AzureIoTClient 16:deba40344375 357 /* Codes_SRS_IOTHUBCLIENT_01_025: [IoTHubClient_SendEventAsync shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 358 if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
AzureIoTClient 16:deba40344375 359 {
AzureIoTClient 16:deba40344375 360 /* Codes_SRS_IOTHUBCLIENT_01_026: [If acquiring the lock fails, IoTHubClient_SendEventAsync shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 361 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 16:deba40344375 362 LogError("Could not acquire lock\r\n");
AzureIoTClient 16:deba40344375 363 }
AzureIoTClient 16:deba40344375 364 else
AzureIoTClient 16:deba40344375 365 {
AzureIoTClient 16:deba40344375 366 /* Codes_SRS_IOTHUBCLIENT_01_009: [IoTHubClient_SendEventAsync shall start the worker thread if it was not previously started.] */
Azure.IoT Build 37:18310e4d888d 367 if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK)
AzureIoTClient 16:deba40344375 368 {
AzureIoTClient 16:deba40344375 369 /* Codes_SRS_IOTHUBCLIENT_01_010: [If starting the thread fails, IoTHubClient_SendEventAsync shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 370 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 16:deba40344375 371 LogError("Could not start worker thread\r\n");
AzureIoTClient 16:deba40344375 372 }
AzureIoTClient 16:deba40344375 373 else
AzureIoTClient 16:deba40344375 374 {
AzureIoTClient 16:deba40344375 375 /* 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.] */
AzureIoTClient 16:deba40344375 376 /* Codes_SRS_IOTHUBCLIENT_01_013: [When IoTHubClient_LL_SendEventAsync is called, IoTHubClient_SendEventAsync shall return the result of IoTHubClient_LL_SendEventAsync.] */
AzureIoTClient 16:deba40344375 377 result = IoTHubClient_LL_SendEventAsync(iotHubClientInstance->IoTHubClientLLHandle, eventMessageHandle, eventConfirmationCallback, userContextCallback);
AzureIoTClient 16:deba40344375 378 }
AzureIoTClient 16:deba40344375 379
AzureIoTClient 16:deba40344375 380 /* Codes_SRS_IOTHUBCLIENT_01_025: [IoTHubClient_SendEventAsync shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 381 (void)Unlock(iotHubClientInstance->LockHandle);
AzureIoTClient 16:deba40344375 382 }
AzureIoTClient 16:deba40344375 383 }
AzureIoTClient 16:deba40344375 384
AzureIoTClient 16:deba40344375 385 return result;
AzureIoTClient 16:deba40344375 386 }
AzureIoTClient 16:deba40344375 387
AzureIoTClient 16:deba40344375 388 IOTHUB_CLIENT_RESULT IoTHubClient_GetSendStatus(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus)
AzureIoTClient 16:deba40344375 389 {
AzureIoTClient 16:deba40344375 390 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 391
AzureIoTClient 16:deba40344375 392 if (iotHubClientHandle == NULL)
AzureIoTClient 16:deba40344375 393 {
AzureIoTClient 16:deba40344375 394 /* Codes_SRS_IOTHUBCLIENT_01_023: [If iotHubClientHandle is NULL, IoTHubClient_ GetSendStatus shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 16:deba40344375 395 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 16:deba40344375 396 LogError("NULL iothubClientHandle\r\n");
AzureIoTClient 16:deba40344375 397 }
AzureIoTClient 16:deba40344375 398 else
AzureIoTClient 16:deba40344375 399 {
AzureIoTClient 16:deba40344375 400 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 401
AzureIoTClient 16:deba40344375 402 /* Codes_SRS_IOTHUBCLIENT_01_033: [IoTHubClient_GetSendStatus shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 403 if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
AzureIoTClient 16:deba40344375 404 {
AzureIoTClient 16:deba40344375 405 /* Codes_SRS_IOTHUBCLIENT_01_034: [If acquiring the lock fails, IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 406 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 16:deba40344375 407 LogError("Could not acquire lock\r\n");
AzureIoTClient 16:deba40344375 408 }
AzureIoTClient 16:deba40344375 409 else
AzureIoTClient 16:deba40344375 410 {
AzureIoTClient 16:deba40344375 411 /* 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 412 /* Codes_SRS_IOTHUBCLIENT_01_024: [Otherwise, IoTHubClient_GetSendStatus shall return the result of IoTHubClient_LL_GetSendStatus.] */
AzureIoTClient 16:deba40344375 413 result = IoTHubClient_LL_GetSendStatus(iotHubClientInstance->IoTHubClientLLHandle, iotHubClientStatus);
AzureIoTClient 16:deba40344375 414
AzureIoTClient 16:deba40344375 415 /* Codes_SRS_IOTHUBCLIENT_01_033: [IoTHubClient_GetSendStatus shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 416 (void)Unlock(iotHubClientInstance->LockHandle);
AzureIoTClient 16:deba40344375 417 }
AzureIoTClient 16:deba40344375 418 }
AzureIoTClient 16:deba40344375 419
AzureIoTClient 16:deba40344375 420 return result;
AzureIoTClient 16:deba40344375 421 }
AzureIoTClient 16:deba40344375 422
AzureIoTClient 16:deba40344375 423 IOTHUB_CLIENT_RESULT IoTHubClient_SetMessageCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback)
AzureIoTClient 16:deba40344375 424 {
AzureIoTClient 16:deba40344375 425 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 426
AzureIoTClient 16:deba40344375 427 if (iotHubClientHandle == NULL)
AzureIoTClient 16:deba40344375 428 {
AzureIoTClient 16:deba40344375 429 /* Codes_SRS_IOTHUBCLIENT_01_016: [If iotHubClientHandle is NULL, IoTHubClient_SetMessageCallback shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 16:deba40344375 430 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 16:deba40344375 431 LogError("NULL iothubClientHandle\r\n");
AzureIoTClient 16:deba40344375 432 }
AzureIoTClient 16:deba40344375 433 else
AzureIoTClient 16:deba40344375 434 {
AzureIoTClient 16:deba40344375 435 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 436
AzureIoTClient 16:deba40344375 437 /* Codes_SRS_IOTHUBCLIENT_01_027: [IoTHubClient_SetMessageCallback shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 438 if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
AzureIoTClient 16:deba40344375 439 {
AzureIoTClient 16:deba40344375 440 /* Codes_SRS_IOTHUBCLIENT_01_028: [If acquiring the lock fails, IoTHubClient_SetMessageCallback shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 441 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 16:deba40344375 442 LogError("Could not acquire lock\r\n");
AzureIoTClient 16:deba40344375 443 }
AzureIoTClient 16:deba40344375 444 else
AzureIoTClient 16:deba40344375 445 {
AzureIoTClient 16:deba40344375 446 /* Codes_SRS_IOTHUBCLIENT_01_014: [IoTHubClient_SetMessageCallback shall start the worker thread if it was not previously started.] */
Azure.IoT Build 37:18310e4d888d 447 if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK)
AzureIoTClient 16:deba40344375 448 {
AzureIoTClient 16:deba40344375 449 /* Codes_SRS_IOTHUBCLIENT_01_015: [If starting the thread fails, IoTHubClient_SetMessageCallback shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 450 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 16:deba40344375 451 LogError("Could not start worker thread\r\n");
AzureIoTClient 16:deba40344375 452 }
AzureIoTClient 16:deba40344375 453 else
AzureIoTClient 16:deba40344375 454 {
AzureIoTClient 16:deba40344375 455 /* Codes_SRS_IOTHUBCLIENT_01_017: [IoTHubClient_SetMessageCallback shall call IoTHubClient_LL_SetMessageCallback, while passing the IoTHubClient_LL handle created by IoTHubClient_Create and the parameters messageCallback and userContextCallback.] */
AzureIoTClient 16:deba40344375 456 result = IoTHubClient_LL_SetMessageCallback(iotHubClientInstance->IoTHubClientLLHandle, messageCallback, userContextCallback);
AzureIoTClient 16:deba40344375 457 }
AzureIoTClient 16:deba40344375 458
AzureIoTClient 16:deba40344375 459 /* Codes_SRS_IOTHUBCLIENT_01_027: [IoTHubClient_SetMessageCallback shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 460 Unlock(iotHubClientInstance->LockHandle);
AzureIoTClient 16:deba40344375 461 }
AzureIoTClient 16:deba40344375 462 }
AzureIoTClient 16:deba40344375 463
AzureIoTClient 16:deba40344375 464 return result;
AzureIoTClient 16:deba40344375 465 }
AzureIoTClient 16:deba40344375 466
AzureIoTClient 16:deba40344375 467 IOTHUB_CLIENT_RESULT IoTHubClient_GetLastMessageReceiveTime(IOTHUB_CLIENT_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime)
AzureIoTClient 16:deba40344375 468 {
AzureIoTClient 16:deba40344375 469 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 470
AzureIoTClient 16:deba40344375 471 if (iotHubClientHandle == NULL)
AzureIoTClient 16:deba40344375 472 {
AzureIoTClient 16:deba40344375 473 /* Codes_SRS_IOTHUBCLIENT_01_020: [If iotHubClientHandle is NULL, IoTHubClient_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 16:deba40344375 474 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 16:deba40344375 475 LogError("NULL iothubClientHandle\r\n");
AzureIoTClient 16:deba40344375 476 }
AzureIoTClient 16:deba40344375 477 else
AzureIoTClient 16:deba40344375 478 {
AzureIoTClient 16:deba40344375 479 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 480
AzureIoTClient 16:deba40344375 481 /* Codes_SRS_IOTHUBCLIENT_01_035: [IoTHubClient_GetLastMessageReceiveTime shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 482 if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
AzureIoTClient 16:deba40344375 483 {
AzureIoTClient 16:deba40344375 484 /* Codes_SRS_IOTHUBCLIENT_01_036: [If acquiring the lock fails, IoTHubClient_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 485 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 16:deba40344375 486 LogError("Could not acquire lock\r\n");
AzureIoTClient 16:deba40344375 487 }
AzureIoTClient 16:deba40344375 488 else
AzureIoTClient 16:deba40344375 489 {
AzureIoTClient 16:deba40344375 490 /* 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 491 /* Codes_SRS_IOTHUBCLIENT_01_021: [Otherwise, IoTHubClient_GetLastMessageReceiveTime shall return the result of IoTHubClient_LL_GetLastMessageReceiveTime.] */
AzureIoTClient 16:deba40344375 492 result = IoTHubClient_LL_GetLastMessageReceiveTime(iotHubClientInstance->IoTHubClientLLHandle, lastMessageReceiveTime);
AzureIoTClient 16:deba40344375 493
AzureIoTClient 16:deba40344375 494 /* Codes_SRS_IOTHUBCLIENT_01_035: [IoTHubClient_GetLastMessageReceiveTime shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 495 Unlock(iotHubClientInstance->LockHandle);
AzureIoTClient 16:deba40344375 496 }
AzureIoTClient 16:deba40344375 497 }
AzureIoTClient 16:deba40344375 498
AzureIoTClient 16:deba40344375 499 return result;
AzureIoTClient 16:deba40344375 500 }
AzureIoTClient 16:deba40344375 501
AzureIoTClient 16:deba40344375 502 IOTHUB_CLIENT_RESULT IoTHubClient_SetOption(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const char* optionName, const void* value)
AzureIoTClient 16:deba40344375 503 {
AzureIoTClient 16:deba40344375 504 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 505 /*Codes_SRS_IOTHUBCLIENT_02_034: [If parameter iotHubClientHandle is NULL then IoTHubClient_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 16:deba40344375 506 if (
AzureIoTClient 16:deba40344375 507 (iotHubClientHandle == NULL) ||
AzureIoTClient 16:deba40344375 508 (optionName == NULL) ||
AzureIoTClient 16:deba40344375 509 (value == NULL)
AzureIoTClient 16:deba40344375 510 )
AzureIoTClient 16:deba40344375 511 {
AzureIoTClient 16:deba40344375 512 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 16:deba40344375 513 LogError("invalid arg (NULL)r\n");
AzureIoTClient 16:deba40344375 514 }
AzureIoTClient 16:deba40344375 515 else
AzureIoTClient 16:deba40344375 516 {
AzureIoTClient 16:deba40344375 517 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 518 /*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 16:deba40344375 519 result = IoTHubClient_LL_SetOption(iotHubClientInstance->IoTHubClientLLHandle, optionName, value);
AzureIoTClient 16:deba40344375 520
AzureIoTClient 16:deba40344375 521 if (result != IOTHUB_CLIENT_OK)
AzureIoTClient 16:deba40344375 522 {
AzureIoTClient 16:deba40344375 523 LogError("IoTHubClient_LL_SetOption failed\r\n");
AzureIoTClient 16:deba40344375 524 }
AzureIoTClient 16:deba40344375 525 }
AzureIoTClient 16:deba40344375 526 return result;
AzureIoTClient 16:deba40344375 527 }