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:
Mon May 09 14:37:02 2016 -0700
Revision:
40:1a94db9139ea
Parent:
39:2719651a5bee
Child:
42:448eecc3676e
1.0.6

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 39:2719651a5bee 106 LogError("Input parameter is NULL: connectionString");
AzureIoTClient 16:deba40344375 107 }
AzureIoTClient 16:deba40344375 108 else if (protocol == NULL)
AzureIoTClient 16:deba40344375 109 {
AzureIoTClient 39:2719651a5bee 110 LogError("Input parameter is NULL: protocol");
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 39:2719651a5bee 120 LogError("Malloc failed");
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;
AzureIoTClient 39:2719651a5bee 131 LogError("Lock_Init failed");
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;
AzureIoTClient 39:2719651a5bee 143 LogError("IoTHubClient_LL_CreateFromConnectionString failed");
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 IOTHUB_CLIENT_HANDLE IoTHubClient_Create(const IOTHUB_CLIENT_CONFIG* config)
AzureIoTClient 16:deba40344375 158 {
AzureIoTClient 16:deba40344375 159 /* Codes_SRS_IOTHUBCLIENT_01_001: [IoTHubClient_Create shall allocate a new IoTHubClient instance and return a non-NULL handle to it.] */
AzureIoTClient 16:deba40344375 160 IOTHUB_CLIENT_INSTANCE* result = (IOTHUB_CLIENT_INSTANCE*)malloc(sizeof(IOTHUB_CLIENT_INSTANCE));
AzureIoTClient 16:deba40344375 161
AzureIoTClient 16:deba40344375 162 /* Codes_SRS_IOTHUBCLIENT_01_004: [If allocating memory for the new IoTHubClient instance fails, then IoTHubClient_Create shall return NULL.] */
AzureIoTClient 16:deba40344375 163 if (result != NULL)
AzureIoTClient 16:deba40344375 164 {
AzureIoTClient 16:deba40344375 165 /* Codes_SRS_IOTHUBCLIENT_01_029: [IoTHubClient_Create shall create a lock object to be used later for serializing IoTHubClient calls.] */
AzureIoTClient 16:deba40344375 166 result->LockHandle = Lock_Init();
AzureIoTClient 16:deba40344375 167 if (result->LockHandle == NULL)
AzureIoTClient 16:deba40344375 168 {
AzureIoTClient 16:deba40344375 169 /* Codes_SRS_IOTHUBCLIENT_01_030: [If creating the lock fails, then IoTHubClient_Create shall return NULL.] */
AzureIoTClient 16:deba40344375 170 /* Codes_SRS_IOTHUBCLIENT_01_031: [If IoTHubClient_Create fails, all resources allocated by it shall be freed.] */
AzureIoTClient 16:deba40344375 171 free(result);
AzureIoTClient 16:deba40344375 172 result = NULL;
AzureIoTClient 16:deba40344375 173 }
AzureIoTClient 16:deba40344375 174 else
AzureIoTClient 16:deba40344375 175 {
AzureIoTClient 16:deba40344375 176 /* 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 177 result->IoTHubClientLLHandle = IoTHubClient_LL_Create(config);
AzureIoTClient 16:deba40344375 178 if (result->IoTHubClientLLHandle == NULL)
AzureIoTClient 16:deba40344375 179 {
AzureIoTClient 16:deba40344375 180 /* Codes_SRS_IOTHUBCLIENT_01_003: [If IoTHubClient_LL_Create fails, then IoTHubClient_Create shall return NULL.] */
AzureIoTClient 16:deba40344375 181 /* Codes_SRS_IOTHUBCLIENT_01_031: [If IoTHubClient_Create fails, all resources allocated by it shall be freed.] */
AzureIoTClient 16:deba40344375 182 Lock_Deinit(result->LockHandle);
AzureIoTClient 16:deba40344375 183 free(result);
AzureIoTClient 16:deba40344375 184 result = NULL;
AzureIoTClient 16:deba40344375 185 }
Azure.IoT Build 37:18310e4d888d 186 else
Azure.IoT Build 37:18310e4d888d 187 {
Azure.IoT Build 37:18310e4d888d 188 result->TransportHandle = NULL;
Azure.IoT Build 37:18310e4d888d 189 result->ThreadHandle = NULL;
Azure.IoT Build 37:18310e4d888d 190 }
AzureIoTClient 16:deba40344375 191 }
AzureIoTClient 16:deba40344375 192 }
AzureIoTClient 16:deba40344375 193
AzureIoTClient 16:deba40344375 194 return result;
AzureIoTClient 16:deba40344375 195 }
AzureIoTClient 16:deba40344375 196
Azure.IoT Build 37:18310e4d888d 197 IOTHUB_CLIENT_HANDLE IoTHubClient_CreateWithTransport(TRANSPORT_HANDLE transportHandle, const IOTHUB_CLIENT_CONFIG* config)
Azure.IoT Build 37:18310e4d888d 198 {
Azure.IoT Build 37:18310e4d888d 199 IOTHUB_CLIENT_INSTANCE* result;
Azure.IoT Build 37:18310e4d888d 200 /*Codes_SRS_IOTHUBCLIENT_17_013: [ IoTHubClient_CreateWithTransport shall return NULL if transportHandle is NULL. ]*/
Azure.IoT Build 37:18310e4d888d 201 /*Codes_SRS_IOTHUBCLIENT_17_014: [ IoTHubClient_CreateWithTransport shall return NULL if config is NULL. ]*/
Azure.IoT Build 37:18310e4d888d 202 if (transportHandle == NULL || config == NULL)
Azure.IoT Build 37:18310e4d888d 203 {
Azure.IoT Build 37:18310e4d888d 204 result = NULL;
Azure.IoT Build 37:18310e4d888d 205 }
Azure.IoT Build 37:18310e4d888d 206 else
Azure.IoT Build 37:18310e4d888d 207 {
Azure.IoT Build 37:18310e4d888d 208 /*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 209 result = (IOTHUB_CLIENT_INSTANCE*)malloc(sizeof(IOTHUB_CLIENT_INSTANCE));
Azure.IoT Build 37:18310e4d888d 210 /*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 211 if (result != NULL)
Azure.IoT Build 37:18310e4d888d 212 {
Azure.IoT Build 37:18310e4d888d 213 result->ThreadHandle = NULL;
Azure.IoT Build 37:18310e4d888d 214 result->TransportHandle = transportHandle;
Azure.IoT Build 37:18310e4d888d 215 /*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 216 LOCK_HANDLE transportLock = IoTHubTransport_GetLock(transportHandle);
Azure.IoT Build 37:18310e4d888d 217 result->LockHandle = transportLock;
Azure.IoT Build 37:18310e4d888d 218 if (result->LockHandle == NULL)
Azure.IoT Build 37:18310e4d888d 219 {
Azure.IoT Build 37:18310e4d888d 220 /*Codes_SRS_IOTHUBCLIENT_17_006: [ If IoTHubTransport_GetLock fails, then IoTHubClient_CreateWithTransport shall return NULL. ]*/
Azure.IoT Build 37:18310e4d888d 221 free(result);
Azure.IoT Build 37:18310e4d888d 222 result = NULL;
Azure.IoT Build 37:18310e4d888d 223 }
Azure.IoT Build 37:18310e4d888d 224 else
Azure.IoT Build 37:18310e4d888d 225 {
Azure.IoT Build 37:18310e4d888d 226 IOTHUB_CLIENT_DEVICE_CONFIG deviceConfig;
Azure.IoT Build 37:18310e4d888d 227 deviceConfig.deviceId = config->deviceId;
Azure.IoT Build 37:18310e4d888d 228 deviceConfig.deviceKey = config->deviceKey;
Azure.IoT Build 37:18310e4d888d 229 deviceConfig.protocol = config->protocol;
AzureIoTClient 40:1a94db9139ea 230 deviceConfig.deviceSasToken = config->deviceSasToken;
AzureIoTClient 40:1a94db9139ea 231 deviceConfig.protocol = config->protocol;
Azure.IoT Build 37:18310e4d888d 232
Azure.IoT Build 37:18310e4d888d 233 /*Codes_SRS_IOTHUBCLIENT_17_003: [ IoTHubClient_CreateWithTransport shall call IoTHubTransport_GetLLTransport on transportHandle to get lower layer transport. ]*/
Azure.IoT Build 37:18310e4d888d 234 deviceConfig.transportHandle = IoTHubTransport_GetLLTransport(transportHandle);
Azure.IoT Build 37:18310e4d888d 235
Azure.IoT Build 37:18310e4d888d 236 if (deviceConfig.transportHandle == NULL)
Azure.IoT Build 37:18310e4d888d 237 {
Azure.IoT Build 37:18310e4d888d 238 /*Codes_SRS_IOTHUBCLIENT_17_004: [ If IoTHubTransport_GetLLTransport fails, then IoTHubClient_CreateWithTransport shall return NULL. ]*/
Azure.IoT Build 37:18310e4d888d 239 free(result);
Azure.IoT Build 37:18310e4d888d 240 result = NULL;
Azure.IoT Build 37:18310e4d888d 241 }
Azure.IoT Build 37:18310e4d888d 242 else
Azure.IoT Build 37:18310e4d888d 243 {
Azure.IoT Build 37:18310e4d888d 244 if (Lock(transportLock) != LOCK_OK)
Azure.IoT Build 37:18310e4d888d 245 {
Azure.IoT Build 37:18310e4d888d 246 free(result);
Azure.IoT Build 37:18310e4d888d 247 result = NULL;
Azure.IoT Build 37:18310e4d888d 248 }
Azure.IoT Build 37:18310e4d888d 249 else
Azure.IoT Build 37:18310e4d888d 250 {
Azure.IoT Build 37:18310e4d888d 251 /*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 252 result->IoTHubClientLLHandle = IoTHubClient_LL_CreateWithTransport(&deviceConfig);
Azure.IoT Build 37:18310e4d888d 253 if (result->IoTHubClientLLHandle == NULL)
Azure.IoT Build 37:18310e4d888d 254 {
Azure.IoT Build 37:18310e4d888d 255 /*Codes_SRS_IOTHUBCLIENT_17_008: [ If IoTHubClient_LL_CreateWithTransport fails, then IoTHubClient_Create shall return NULL. ]*/
Azure.IoT Build 37:18310e4d888d 256 /*Codes_SRS_IOTHUBCLIENT_17_009: [ If IoTHubClient_LL_CreateWithTransport fails, all resources allocated by it shall be freed. ]*/
Azure.IoT Build 37:18310e4d888d 257 free(result);
Azure.IoT Build 37:18310e4d888d 258 result = NULL;
Azure.IoT Build 37:18310e4d888d 259 }
Azure.IoT Build 37:18310e4d888d 260
Azure.IoT Build 37:18310e4d888d 261 if (Unlock(transportLock) != LOCK_OK)
Azure.IoT Build 37:18310e4d888d 262 {
Azure.IoT Build 37:18310e4d888d 263 LogError("unable to Unlock");
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
Azure.IoT Build 37:18310e4d888d 272 return result;
Azure.IoT Build 37:18310e4d888d 273 }
Azure.IoT Build 37:18310e4d888d 274
AzureIoTClient 16:deba40344375 275 /* Codes_SRS_IOTHUBCLIENT_01_005: [IoTHubClient_Destroy shall free all resources associated with the iotHubClientHandle instance.] */
AzureIoTClient 18:1e9adb15c645 276 void IoTHubClient_Destroy(IOTHUB_CLIENT_HANDLE iotHubClientHandle)
AzureIoTClient 16:deba40344375 277 {
AzureIoTClient 16:deba40344375 278 /* Codes_SRS_IOTHUBCLIENT_01_008: [IoTHubClient_Destroy shall do nothing if parameter iotHubClientHandle is NULL.] */
AzureIoTClient 16:deba40344375 279 if (iotHubClientHandle != NULL)
AzureIoTClient 16:deba40344375 280 {
Azure.IoT Build 37:18310e4d888d 281 bool okToJoin;
Azure.IoT Build 37:18310e4d888d 282
AzureIoTClient 16:deba40344375 283 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 284
Azure.IoT Build 37:18310e4d888d 285 /*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 286 if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
Azure.IoT Build 37:18310e4d888d 287 {
Azure.IoT Build 37:18310e4d888d 288 LogError("unable to Lock - - will still proceed to try to end the thread without locking");
Azure.IoT Build 37:18310e4d888d 289 }
Azure.IoT Build 37:18310e4d888d 290
AzureIoTClient 16:deba40344375 291 if (iotHubClientInstance->ThreadHandle != NULL)
AzureIoTClient 16:deba40344375 292 {
Azure.IoT Build 37:18310e4d888d 293 iotHubClientInstance->StopThread = 1;
Azure.IoT Build 37:18310e4d888d 294 okToJoin = true;
AzureIoTClient 16:deba40344375 295 }
Azure.IoT Build 37:18310e4d888d 296 else
Azure.IoT Build 37:18310e4d888d 297 {
Azure.IoT Build 37:18310e4d888d 298 okToJoin = false;
Azure.IoT Build 37:18310e4d888d 299 }
Azure.IoT Build 37:18310e4d888d 300
Azure.IoT Build 37:18310e4d888d 301 if (iotHubClientInstance->TransportHandle != NULL)
Azure.IoT Build 37:18310e4d888d 302 {
Azure.IoT Build 37:18310e4d888d 303 /*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 304 okToJoin = IoTHubTransport_SignalEndWorkerThread(iotHubClientInstance->TransportHandle, iotHubClientHandle);
Azure.IoT Build 37:18310e4d888d 305 }
AzureIoTClient 16:deba40344375 306
AzureIoTClient 16:deba40344375 307 /* Codes_SRS_IOTHUBCLIENT_01_006: [That includes destroying the IoTHubClient_LL instance by calling IoTHubClient_LL_Destroy.] */
AzureIoTClient 16:deba40344375 308 IoTHubClient_LL_Destroy(iotHubClientInstance->IoTHubClientLLHandle);
AzureIoTClient 16:deba40344375 309
Azure.IoT Build 37:18310e4d888d 310 /*Codes_SRS_IOTHUBCLIENT_02_045: [ IoTHubClient_Destroy shall unlock the serializing lock. ]*/
Azure.IoT Build 37:18310e4d888d 311 if (Unlock(iotHubClientInstance->LockHandle) != LOCK_OK)
Azure.IoT Build 37:18310e4d888d 312 {
Azure.IoT Build 37:18310e4d888d 313 LogError("unable to Unlock");
Azure.IoT Build 37:18310e4d888d 314 }
Azure.IoT Build 37:18310e4d888d 315
Azure.IoT Build 37:18310e4d888d 316 if (okToJoin == true)
Azure.IoT Build 37:18310e4d888d 317 {
Azure.IoT Build 37:18310e4d888d 318 if (iotHubClientInstance->ThreadHandle != NULL)
Azure.IoT Build 37:18310e4d888d 319 {
Azure.IoT Build 37:18310e4d888d 320 int res;
Azure.IoT Build 37:18310e4d888d 321 /*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 322 if (ThreadAPI_Join(iotHubClientInstance->ThreadHandle, &res) != THREADAPI_OK)
Azure.IoT Build 37:18310e4d888d 323 {
AzureIoTClient 39:2719651a5bee 324 LogError("ThreadAPI_Join failed");
Azure.IoT Build 37:18310e4d888d 325 }
Azure.IoT Build 37:18310e4d888d 326 }
Azure.IoT Build 37:18310e4d888d 327 if (iotHubClientInstance->TransportHandle != NULL)
Azure.IoT Build 37:18310e4d888d 328 {
Azure.IoT Build 37:18310e4d888d 329 /*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 330 IoTHubTransport_JoinWorkerThread(iotHubClientInstance->TransportHandle, iotHubClientHandle);
Azure.IoT Build 37:18310e4d888d 331 }
Azure.IoT Build 37:18310e4d888d 332 }
Azure.IoT Build 37:18310e4d888d 333
Azure.IoT Build 37:18310e4d888d 334 if (iotHubClientInstance->TransportHandle == NULL)
Azure.IoT Build 37:18310e4d888d 335 {
Azure.IoT Build 37:18310e4d888d 336 /* Codes_SRS_IOTHUBCLIENT_01_032: [If the lock was allocated in IoTHubClient_Create, it shall be also freed..] */
Azure.IoT Build 37:18310e4d888d 337 Lock_Deinit(iotHubClientInstance->LockHandle);
Azure.IoT Build 37:18310e4d888d 338 }
Azure.IoT Build 37:18310e4d888d 339
AzureIoTClient 16:deba40344375 340 free(iotHubClientInstance);
AzureIoTClient 16:deba40344375 341 }
AzureIoTClient 16:deba40344375 342 }
AzureIoTClient 16:deba40344375 343
AzureIoTClient 16:deba40344375 344 IOTHUB_CLIENT_RESULT IoTHubClient_SendEventAsync(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK eventConfirmationCallback, void* userContextCallback)
AzureIoTClient 16:deba40344375 345 {
AzureIoTClient 16:deba40344375 346 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 347
AzureIoTClient 16:deba40344375 348 if (iotHubClientHandle == NULL)
AzureIoTClient 16:deba40344375 349 {
AzureIoTClient 16:deba40344375 350 /* Codes_SRS_IOTHUBCLIENT_01_011: [If iotHubClientHandle is NULL, IoTHubClient_SendEventAsync shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 16:deba40344375 351 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 39:2719651a5bee 352 LogError("NULL iothubClientHandle");
AzureIoTClient 16:deba40344375 353 }
AzureIoTClient 16:deba40344375 354 else
AzureIoTClient 16:deba40344375 355 {
AzureIoTClient 16:deba40344375 356 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 357
AzureIoTClient 16:deba40344375 358 /* Codes_SRS_IOTHUBCLIENT_01_025: [IoTHubClient_SendEventAsync shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 359 if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
AzureIoTClient 16:deba40344375 360 {
AzureIoTClient 16:deba40344375 361 /* Codes_SRS_IOTHUBCLIENT_01_026: [If acquiring the lock fails, IoTHubClient_SendEventAsync shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 362 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 39:2719651a5bee 363 LogError("Could not acquire lock");
AzureIoTClient 16:deba40344375 364 }
AzureIoTClient 16:deba40344375 365 else
AzureIoTClient 16:deba40344375 366 {
AzureIoTClient 16:deba40344375 367 /* Codes_SRS_IOTHUBCLIENT_01_009: [IoTHubClient_SendEventAsync shall start the worker thread if it was not previously started.] */
Azure.IoT Build 37:18310e4d888d 368 if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK)
AzureIoTClient 16:deba40344375 369 {
AzureIoTClient 16:deba40344375 370 /* Codes_SRS_IOTHUBCLIENT_01_010: [If starting the thread fails, IoTHubClient_SendEventAsync shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 371 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 39:2719651a5bee 372 LogError("Could not start worker thread");
AzureIoTClient 16:deba40344375 373 }
AzureIoTClient 16:deba40344375 374 else
AzureIoTClient 16:deba40344375 375 {
AzureIoTClient 16:deba40344375 376 /* 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 377 /* Codes_SRS_IOTHUBCLIENT_01_013: [When IoTHubClient_LL_SendEventAsync is called, IoTHubClient_SendEventAsync shall return the result of IoTHubClient_LL_SendEventAsync.] */
AzureIoTClient 16:deba40344375 378 result = IoTHubClient_LL_SendEventAsync(iotHubClientInstance->IoTHubClientLLHandle, eventMessageHandle, eventConfirmationCallback, userContextCallback);
AzureIoTClient 16:deba40344375 379 }
AzureIoTClient 16:deba40344375 380
AzureIoTClient 16:deba40344375 381 /* Codes_SRS_IOTHUBCLIENT_01_025: [IoTHubClient_SendEventAsync shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 382 (void)Unlock(iotHubClientInstance->LockHandle);
AzureIoTClient 16:deba40344375 383 }
AzureIoTClient 16:deba40344375 384 }
AzureIoTClient 16:deba40344375 385
AzureIoTClient 16:deba40344375 386 return result;
AzureIoTClient 16:deba40344375 387 }
AzureIoTClient 16:deba40344375 388
AzureIoTClient 16:deba40344375 389 IOTHUB_CLIENT_RESULT IoTHubClient_GetSendStatus(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus)
AzureIoTClient 16:deba40344375 390 {
AzureIoTClient 16:deba40344375 391 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 392
AzureIoTClient 16:deba40344375 393 if (iotHubClientHandle == NULL)
AzureIoTClient 16:deba40344375 394 {
AzureIoTClient 16:deba40344375 395 /* Codes_SRS_IOTHUBCLIENT_01_023: [If iotHubClientHandle is NULL, IoTHubClient_ GetSendStatus shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 16:deba40344375 396 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 39:2719651a5bee 397 LogError("NULL iothubClientHandle");
AzureIoTClient 16:deba40344375 398 }
AzureIoTClient 16:deba40344375 399 else
AzureIoTClient 16:deba40344375 400 {
AzureIoTClient 16:deba40344375 401 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 402
AzureIoTClient 16:deba40344375 403 /* Codes_SRS_IOTHUBCLIENT_01_033: [IoTHubClient_GetSendStatus shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 404 if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
AzureIoTClient 16:deba40344375 405 {
AzureIoTClient 16:deba40344375 406 /* Codes_SRS_IOTHUBCLIENT_01_034: [If acquiring the lock fails, IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 407 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 39:2719651a5bee 408 LogError("Could not acquire lock");
AzureIoTClient 16:deba40344375 409 }
AzureIoTClient 16:deba40344375 410 else
AzureIoTClient 16:deba40344375 411 {
AzureIoTClient 16:deba40344375 412 /* 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 413 /* Codes_SRS_IOTHUBCLIENT_01_024: [Otherwise, IoTHubClient_GetSendStatus shall return the result of IoTHubClient_LL_GetSendStatus.] */
AzureIoTClient 16:deba40344375 414 result = IoTHubClient_LL_GetSendStatus(iotHubClientInstance->IoTHubClientLLHandle, iotHubClientStatus);
AzureIoTClient 16:deba40344375 415
AzureIoTClient 16:deba40344375 416 /* Codes_SRS_IOTHUBCLIENT_01_033: [IoTHubClient_GetSendStatus shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 417 (void)Unlock(iotHubClientInstance->LockHandle);
AzureIoTClient 16:deba40344375 418 }
AzureIoTClient 16:deba40344375 419 }
AzureIoTClient 16:deba40344375 420
AzureIoTClient 16:deba40344375 421 return result;
AzureIoTClient 16:deba40344375 422 }
AzureIoTClient 16:deba40344375 423
AzureIoTClient 16:deba40344375 424 IOTHUB_CLIENT_RESULT IoTHubClient_SetMessageCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback)
AzureIoTClient 16:deba40344375 425 {
AzureIoTClient 16:deba40344375 426 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 427
AzureIoTClient 16:deba40344375 428 if (iotHubClientHandle == NULL)
AzureIoTClient 16:deba40344375 429 {
AzureIoTClient 16:deba40344375 430 /* Codes_SRS_IOTHUBCLIENT_01_016: [If iotHubClientHandle is NULL, IoTHubClient_SetMessageCallback shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 16:deba40344375 431 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 39:2719651a5bee 432 LogError("NULL iothubClientHandle");
AzureIoTClient 16:deba40344375 433 }
AzureIoTClient 16:deba40344375 434 else
AzureIoTClient 16:deba40344375 435 {
AzureIoTClient 16:deba40344375 436 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 437
AzureIoTClient 16:deba40344375 438 /* Codes_SRS_IOTHUBCLIENT_01_027: [IoTHubClient_SetMessageCallback shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 439 if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
AzureIoTClient 16:deba40344375 440 {
AzureIoTClient 16:deba40344375 441 /* Codes_SRS_IOTHUBCLIENT_01_028: [If acquiring the lock fails, IoTHubClient_SetMessageCallback shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 442 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 39:2719651a5bee 443 LogError("Could not acquire lock");
AzureIoTClient 16:deba40344375 444 }
AzureIoTClient 16:deba40344375 445 else
AzureIoTClient 16:deba40344375 446 {
AzureIoTClient 16:deba40344375 447 /* Codes_SRS_IOTHUBCLIENT_01_014: [IoTHubClient_SetMessageCallback shall start the worker thread if it was not previously started.] */
Azure.IoT Build 37:18310e4d888d 448 if ((result = StartWorkerThreadIfNeeded(iotHubClientInstance)) != IOTHUB_CLIENT_OK)
AzureIoTClient 16:deba40344375 449 {
AzureIoTClient 16:deba40344375 450 /* Codes_SRS_IOTHUBCLIENT_01_015: [If starting the thread fails, IoTHubClient_SetMessageCallback shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 451 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 39:2719651a5bee 452 LogError("Could not start worker thread");
AzureIoTClient 16:deba40344375 453 }
AzureIoTClient 16:deba40344375 454 else
AzureIoTClient 16:deba40344375 455 {
AzureIoTClient 16:deba40344375 456 /* 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 457 result = IoTHubClient_LL_SetMessageCallback(iotHubClientInstance->IoTHubClientLLHandle, messageCallback, userContextCallback);
AzureIoTClient 16:deba40344375 458 }
AzureIoTClient 16:deba40344375 459
AzureIoTClient 16:deba40344375 460 /* Codes_SRS_IOTHUBCLIENT_01_027: [IoTHubClient_SetMessageCallback shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 461 Unlock(iotHubClientInstance->LockHandle);
AzureIoTClient 16:deba40344375 462 }
AzureIoTClient 16:deba40344375 463 }
AzureIoTClient 16:deba40344375 464
AzureIoTClient 16:deba40344375 465 return result;
AzureIoTClient 16:deba40344375 466 }
AzureIoTClient 16:deba40344375 467
AzureIoTClient 16:deba40344375 468 IOTHUB_CLIENT_RESULT IoTHubClient_GetLastMessageReceiveTime(IOTHUB_CLIENT_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime)
AzureIoTClient 16:deba40344375 469 {
AzureIoTClient 16:deba40344375 470 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 471
AzureIoTClient 16:deba40344375 472 if (iotHubClientHandle == NULL)
AzureIoTClient 16:deba40344375 473 {
AzureIoTClient 16:deba40344375 474 /* Codes_SRS_IOTHUBCLIENT_01_020: [If iotHubClientHandle is NULL, IoTHubClient_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 16:deba40344375 475 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 39:2719651a5bee 476 LogError("NULL iothubClientHandle");
AzureIoTClient 16:deba40344375 477 }
AzureIoTClient 16:deba40344375 478 else
AzureIoTClient 16:deba40344375 479 {
AzureIoTClient 16:deba40344375 480 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 481
AzureIoTClient 16:deba40344375 482 /* Codes_SRS_IOTHUBCLIENT_01_035: [IoTHubClient_GetLastMessageReceiveTime shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 483 if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
AzureIoTClient 16:deba40344375 484 {
AzureIoTClient 16:deba40344375 485 /* Codes_SRS_IOTHUBCLIENT_01_036: [If acquiring the lock fails, IoTHubClient_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 486 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 39:2719651a5bee 487 LogError("Could not acquire lock");
AzureIoTClient 16:deba40344375 488 }
AzureIoTClient 16:deba40344375 489 else
AzureIoTClient 16:deba40344375 490 {
AzureIoTClient 16:deba40344375 491 /* 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 492 /* Codes_SRS_IOTHUBCLIENT_01_021: [Otherwise, IoTHubClient_GetLastMessageReceiveTime shall return the result of IoTHubClient_LL_GetLastMessageReceiveTime.] */
AzureIoTClient 16:deba40344375 493 result = IoTHubClient_LL_GetLastMessageReceiveTime(iotHubClientInstance->IoTHubClientLLHandle, lastMessageReceiveTime);
AzureIoTClient 16:deba40344375 494
AzureIoTClient 16:deba40344375 495 /* Codes_SRS_IOTHUBCLIENT_01_035: [IoTHubClient_GetLastMessageReceiveTime shall be made thread-safe by using the lock created in IoTHubClient_Create.] */
AzureIoTClient 16:deba40344375 496 Unlock(iotHubClientInstance->LockHandle);
AzureIoTClient 16:deba40344375 497 }
AzureIoTClient 16:deba40344375 498 }
AzureIoTClient 16:deba40344375 499
AzureIoTClient 16:deba40344375 500 return result;
AzureIoTClient 16:deba40344375 501 }
AzureIoTClient 16:deba40344375 502
AzureIoTClient 16:deba40344375 503 IOTHUB_CLIENT_RESULT IoTHubClient_SetOption(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const char* optionName, const void* value)
AzureIoTClient 16:deba40344375 504 {
AzureIoTClient 16:deba40344375 505 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 506 /*Codes_SRS_IOTHUBCLIENT_02_034: [If parameter iotHubClientHandle is NULL then IoTHubClient_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 16:deba40344375 507 if (
AzureIoTClient 16:deba40344375 508 (iotHubClientHandle == NULL) ||
AzureIoTClient 16:deba40344375 509 (optionName == NULL) ||
AzureIoTClient 16:deba40344375 510 (value == NULL)
AzureIoTClient 16:deba40344375 511 )
AzureIoTClient 16:deba40344375 512 {
AzureIoTClient 16:deba40344375 513 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 16:deba40344375 514 LogError("invalid arg (NULL)r\n");
AzureIoTClient 16:deba40344375 515 }
AzureIoTClient 16:deba40344375 516 else
AzureIoTClient 16:deba40344375 517 {
AzureIoTClient 16:deba40344375 518 IOTHUB_CLIENT_INSTANCE* iotHubClientInstance = (IOTHUB_CLIENT_INSTANCE*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 519
AzureIoTClient 40:1a94db9139ea 520 /* Codes_SRS_IOTHUBCLIENT_01_041: [ IoTHubClient_SetOption shall be made thread-safe by using the lock created in IoTHubClient_Create. ]*/
AzureIoTClient 40:1a94db9139ea 521 if (Lock(iotHubClientInstance->LockHandle) != LOCK_OK)
AzureIoTClient 40:1a94db9139ea 522 {
AzureIoTClient 40:1a94db9139ea 523 /* Codes_SRS_IOTHUBCLIENT_01_042: [ If acquiring the lock fails, IoTHubClient_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_ERROR. ]*/
AzureIoTClient 40:1a94db9139ea 524 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 40:1a94db9139ea 525 LogError("Could not acquire lock");
AzureIoTClient 40:1a94db9139ea 526 }
AzureIoTClient 40:1a94db9139ea 527 else
AzureIoTClient 16:deba40344375 528 {
AzureIoTClient 40:1a94db9139ea 529 /*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 530 result = IoTHubClient_LL_SetOption(iotHubClientInstance->IoTHubClientLLHandle, optionName, value);
AzureIoTClient 40:1a94db9139ea 531 if (result != IOTHUB_CLIENT_OK)
AzureIoTClient 40:1a94db9139ea 532 {
AzureIoTClient 40:1a94db9139ea 533 LogError("IoTHubClient_LL_SetOption failed");
AzureIoTClient 40:1a94db9139ea 534 }
AzureIoTClient 40:1a94db9139ea 535
AzureIoTClient 40:1a94db9139ea 536 Unlock(iotHubClientInstance->LockHandle);
AzureIoTClient 16:deba40344375 537 }
AzureIoTClient 16:deba40344375 538 }
AzureIoTClient 16:deba40344375 539 return result;
AzureIoTClient 16:deba40344375 540 }