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:
Azure.IoT Build
Date:
Fri Mar 11 17:00:59 2016 -0800
Revision:
36:67300d5a4c1f
Parent:
34:578a1a3636cc
Child:
37:18310e4d888d
1.0.2

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
AzureIoTClient 16:deba40344375 8 #include "gballoc.h"
AzureIoTClient 16:deba40344375 9 #include "string.h"
AzureIoTClient 16:deba40344375 10 #include "string_tokenizer.h"
AzureIoTClient 16:deba40344375 11
AzureIoTClient 16:deba40344375 12 #include "iothub_client_ll.h"
AzureIoTClient 16:deba40344375 13 #include "iothub_client_private.h"
AzureIoTClient 16:deba40344375 14 #include "doublylinkedlist.h"
AzureIoTClient 33:b372b0efcd20 15 #include "iothub_client_version.h"
AzureIoTClient 16:deba40344375 16
AzureIoTClient 16:deba40344375 17 #include "iot_logging.h"
AzureIoTClient 16:deba40344375 18
Azure.IoT Build 36:67300d5a4c1f 19 #include "tickcounter.h"
Azure.IoT Build 36:67300d5a4c1f 20
AzureIoTClient 16:deba40344375 21 #define LOG_ERROR LogError("result = %s\r\n", ENUM_TO_STRING(IOTHUB_CLIENT_RESULT, result));
AzureIoTClient 16:deba40344375 22 #define INDEFINITE_TIME ((time_t)(-1))
AzureIoTClient 16:deba40344375 23
AzureIoTClient 16:deba40344375 24 DEFINE_ENUM_STRINGS(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_RESULT_VALUES);
AzureIoTClient 16:deba40344375 25
AzureIoTClient 16:deba40344375 26 typedef struct IOTHUB_CLIENT_LL_HANDLE_DATA_TAG
AzureIoTClient 16:deba40344375 27 {
AzureIoTClient 16:deba40344375 28 DLIST_ENTRY waitingToSend;
AzureIoTClient 16:deba40344375 29 TRANSPORT_HANDLE transportHandle;
Azure.IoT Build 36:67300d5a4c1f 30 bool isSharedTransport;
Azure.IoT Build 36:67300d5a4c1f 31 IOTHUB_DEVICE_HANDLE deviceHandle;
AzureIoTClient 16:deba40344375 32 TRANSPORT_PROVIDER_FIELDS;
AzureIoTClient 16:deba40344375 33 IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback;
AzureIoTClient 16:deba40344375 34 void* messageUserContextCallback;
AzureIoTClient 16:deba40344375 35 time_t lastMessageReceiveTime;
Azure.IoT Build 36:67300d5a4c1f 36 TICK_COUNTER_HANDLE tickCounter; /*shared tickcounter used to track message timeouts in waitingToSend list*/
Azure.IoT Build 36:67300d5a4c1f 37 uint64_t currentMessageTimeout;
AzureIoTClient 16:deba40344375 38 }IOTHUB_CLIENT_LL_HANDLE_DATA;
AzureIoTClient 16:deba40344375 39
AzureIoTClient 16:deba40344375 40 static const char HOSTNAME_TOKEN[] = "HostName";
AzureIoTClient 16:deba40344375 41 static const char DEVICEID_TOKEN[] = "DeviceId";
AzureIoTClient 16:deba40344375 42 static const char DEVICEKEY_TOKEN[] = "SharedAccessKey";
AzureIoTClient 16:deba40344375 43 static const char PROTOCOL_GATEWAY_HOST[] = "GatewayHostName";
AzureIoTClient 16:deba40344375 44
AzureIoTClient 16:deba40344375 45 IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol)
AzureIoTClient 16:deba40344375 46 {
AzureIoTClient 32:6e9d81a62085 47 IOTHUB_CLIENT_LL_HANDLE result = NULL;
AzureIoTClient 16:deba40344375 48
AzureIoTClient 16:deba40344375 49 /*Codes_SRS_IOTHUBCLIENT_LL_05_001: [IoTHubClient_LL_CreateFromConnectionString shall obtain the version string by a call to IoTHubClient_GetVersionString.]*/
AzureIoTClient 16:deba40344375 50 /*Codes_SRS_IOTHUBCLIENT_LL_05_002: [IoTHubClient_LL_CreateFromConnectionString shall print the version string to standard output.]*/
AzureIoTClient 16:deba40344375 51 LogInfo("IoT Hub SDK for C, version %s\r\n", IoTHubClient_GetVersionString());
AzureIoTClient 16:deba40344375 52
AzureIoTClient 16:deba40344375 53 /* SRS_IOTHUBCLIENT_LL_12_003: [IoTHubClient_LL_CreateFromConnectionString shall verify the input parameter and if it is NULL then return NULL] */
AzureIoTClient 16:deba40344375 54 if (connectionString == NULL)
AzureIoTClient 16:deba40344375 55 {
AzureIoTClient 16:deba40344375 56 LogError("Input parameter is NULL: connectionString\r\n");
AzureIoTClient 16:deba40344375 57 }
AzureIoTClient 16:deba40344375 58 else if (protocol == NULL)
AzureIoTClient 16:deba40344375 59 {
AzureIoTClient 16:deba40344375 60 LogError("Input parameter is NULL: protocol\r\n");
AzureIoTClient 16:deba40344375 61 }
AzureIoTClient 16:deba40344375 62 else
AzureIoTClient 16:deba40344375 63 {
AzureIoTClient 16:deba40344375 64 /* SRS_IOTHUBCLIENT_LL_12_004: [IoTHubClient_LL_CreateFromConnectionString shall allocate IOTHUB_CLIENT_CONFIG structure] */
AzureIoTClient 16:deba40344375 65 IOTHUB_CLIENT_CONFIG* config = malloc(sizeof(IOTHUB_CLIENT_CONFIG));
AzureIoTClient 16:deba40344375 66 if (config == NULL)
AzureIoTClient 16:deba40344375 67 {
AzureIoTClient 16:deba40344375 68 /* SRS_IOTHUBCLIENT_LL_12_012: [If the allocation failed IoTHubClient_LL_CreateFromConnectionString returns NULL] */
AzureIoTClient 16:deba40344375 69 LogError("Malloc failed\r\n");
AzureIoTClient 16:deba40344375 70 return NULL;
AzureIoTClient 16:deba40344375 71 }
AzureIoTClient 16:deba40344375 72 else
AzureIoTClient 16:deba40344375 73 {
AzureIoTClient 16:deba40344375 74 STRING_TOKENIZER_HANDLE tokenizer1 = NULL;
AzureIoTClient 16:deba40344375 75 STRING_HANDLE connString = NULL;
AzureIoTClient 16:deba40344375 76 STRING_HANDLE tokenString = NULL;
AzureIoTClient 16:deba40344375 77 STRING_HANDLE valueString = NULL;
AzureIoTClient 16:deba40344375 78 STRING_HANDLE hostNameString = NULL;
AzureIoTClient 16:deba40344375 79 STRING_HANDLE hostSuffixString = NULL;
AzureIoTClient 16:deba40344375 80 STRING_HANDLE deviceIdString = NULL;
AzureIoTClient 16:deba40344375 81 STRING_HANDLE deviceKeyString = NULL;
AzureIoTClient 16:deba40344375 82 STRING_HANDLE protocolGateway = NULL;
AzureIoTClient 16:deba40344375 83
AzureIoTClient 16:deba40344375 84 config->protocol = protocol;
AzureIoTClient 16:deba40344375 85
AzureIoTClient 16:deba40344375 86 config->iotHubName = NULL;
AzureIoTClient 16:deba40344375 87 config->iotHubSuffix = NULL;
AzureIoTClient 16:deba40344375 88 config->deviceId = NULL;
AzureIoTClient 16:deba40344375 89 config->deviceKey = NULL;
AzureIoTClient 31:741eacddf296 90 /* Codes_SRS_IOTHUBCLIENT_LL_04_002: [If it does not, it shall pass the protocolGatewayHostName NULL.] */
AzureIoTClient 31:741eacddf296 91 config->protocolGatewayHostName = NULL;
AzureIoTClient 16:deba40344375 92
AzureIoTClient 16:deba40344375 93 if ((connString = STRING_construct(connectionString)) == NULL)
AzureIoTClient 16:deba40344375 94 {
AzureIoTClient 16:deba40344375 95 LogError("Error constructing connectiong String\r\n");
AzureIoTClient 16:deba40344375 96 }
AzureIoTClient 16:deba40344375 97 else if ((tokenizer1 = STRING_TOKENIZER_create(connString)) == NULL)
AzureIoTClient 16:deba40344375 98 {
AzureIoTClient 16:deba40344375 99 LogError("Error creating Tokenizer\r\n");
AzureIoTClient 16:deba40344375 100 }
AzureIoTClient 16:deba40344375 101 else if ((tokenString = STRING_new()) == NULL)
AzureIoTClient 16:deba40344375 102 {
AzureIoTClient 16:deba40344375 103 LogError("Error creating Token String\r\n");
AzureIoTClient 16:deba40344375 104 }
AzureIoTClient 16:deba40344375 105 else if ((valueString = STRING_new()) == NULL)
AzureIoTClient 16:deba40344375 106 {
AzureIoTClient 16:deba40344375 107 LogError("Error creating Value String\r\n");
AzureIoTClient 16:deba40344375 108 }
AzureIoTClient 16:deba40344375 109 else if ((hostNameString = STRING_new()) == NULL)
AzureIoTClient 16:deba40344375 110 {
AzureIoTClient 16:deba40344375 111 LogError("Error creating HostName String\r\n");
AzureIoTClient 16:deba40344375 112 }
AzureIoTClient 16:deba40344375 113 else if ((hostSuffixString = STRING_new()) == NULL)
AzureIoTClient 16:deba40344375 114 {
AzureIoTClient 16:deba40344375 115 LogError("Error creating HostSuffix String\r\n");
AzureIoTClient 16:deba40344375 116 }
AzureIoTClient 16:deba40344375 117 /* SRS_IOTHUBCLIENT_LL_12_005: [IoTHubClient_LL_CreateFromConnectionString shall try to parse the connectionString input parameter for the following structure: "Key1=value1;key2=value2;key3=value3..."] */
AzureIoTClient 16:deba40344375 118 /* SRS_IOTHUBCLIENT_LL_12_006: [IoTHubClient_LL_CreateFromConnectionString shall verify the existence of the following Key/Value pairs in the connection string: HostName, DeviceId, SharedAccessKey.] */
AzureIoTClient 16:deba40344375 119 else
AzureIoTClient 16:deba40344375 120 {
AzureIoTClient 16:deba40344375 121 while ((STRING_TOKENIZER_get_next_token(tokenizer1, tokenString, "=") == 0))
AzureIoTClient 16:deba40344375 122 {
AzureIoTClient 16:deba40344375 123 if (STRING_TOKENIZER_get_next_token(tokenizer1, valueString, ";") != 0)
AzureIoTClient 16:deba40344375 124 {
AzureIoTClient 16:deba40344375 125 LogError("Tokenizer error\r\n");
AzureIoTClient 16:deba40344375 126 break;
AzureIoTClient 16:deba40344375 127 }
AzureIoTClient 16:deba40344375 128 else
AzureIoTClient 16:deba40344375 129 {
AzureIoTClient 16:deba40344375 130 if (tokenString != NULL)
AzureIoTClient 16:deba40344375 131 {
AzureIoTClient 16:deba40344375 132 /* SRS_IOTHUBCLIENT_LL_12_010: [IoTHubClient_LL_CreateFromConnectionString shall fill up the IOTHUB_CLIENT_CONFIG structure using the following mapping: iotHubName = Name, iotHubSuffix = Suffix, deviceId = DeviceId, deviceKey = SharedAccessKey] */
AzureIoTClient 16:deba40344375 133 const char* s_token = STRING_c_str(tokenString);
AzureIoTClient 31:741eacddf296 134 if (strcmp(s_token, HOSTNAME_TOKEN) == 0)
AzureIoTClient 16:deba40344375 135 {
AzureIoTClient 16:deba40344375 136 /* SRS_IOTHUBCLIENT_LL_12_009: [IoTHubClient_LL_CreateFromConnectionString shall split the value of HostName to Name and Suffix using the first "." as a separator] */
AzureIoTClient 16:deba40344375 137 STRING_TOKENIZER_HANDLE tokenizer2 = NULL;
AzureIoTClient 16:deba40344375 138 if ((tokenizer2 = STRING_TOKENIZER_create(valueString)) == NULL)
AzureIoTClient 16:deba40344375 139 {
AzureIoTClient 16:deba40344375 140 LogError("Error creating Tokenizer\r\n");
AzureIoTClient 16:deba40344375 141 break;
AzureIoTClient 16:deba40344375 142 }
AzureIoTClient 16:deba40344375 143 else
AzureIoTClient 16:deba40344375 144 {
AzureIoTClient 16:deba40344375 145 /* SRS_IOTHUBCLIENT_LL_12_015: [If the string split failed, IoTHubClient_LL_CreateFromConnectionString returns NULL ] */
AzureIoTClient 16:deba40344375 146 if (STRING_TOKENIZER_get_next_token(tokenizer2, hostNameString, ".") != 0)
AzureIoTClient 16:deba40344375 147 {
AzureIoTClient 16:deba40344375 148 LogError("Tokenizer error\r\n");
AzureIoTClient 16:deba40344375 149 STRING_TOKENIZER_destroy(tokenizer2);
AzureIoTClient 16:deba40344375 150 break;
AzureIoTClient 16:deba40344375 151 }
AzureIoTClient 16:deba40344375 152 else
AzureIoTClient 16:deba40344375 153 {
AzureIoTClient 16:deba40344375 154 config->iotHubName = STRING_c_str(hostNameString);
AzureIoTClient 16:deba40344375 155 if (STRING_TOKENIZER_get_next_token(tokenizer2, hostSuffixString, ";") != 0)
AzureIoTClient 16:deba40344375 156 {
AzureIoTClient 16:deba40344375 157 LogError("Tokenizer error\r\n");
AzureIoTClient 16:deba40344375 158 STRING_TOKENIZER_destroy(tokenizer2);
AzureIoTClient 16:deba40344375 159 break;
AzureIoTClient 16:deba40344375 160 }
AzureIoTClient 16:deba40344375 161 else
AzureIoTClient 16:deba40344375 162 {
AzureIoTClient 16:deba40344375 163 config->iotHubSuffix = STRING_c_str(hostSuffixString);
AzureIoTClient 16:deba40344375 164 }
AzureIoTClient 16:deba40344375 165 }
AzureIoTClient 16:deba40344375 166 STRING_TOKENIZER_destroy(tokenizer2);
AzureIoTClient 16:deba40344375 167 }
AzureIoTClient 16:deba40344375 168 }
AzureIoTClient 16:deba40344375 169 else if (strcmp(s_token, DEVICEID_TOKEN) == 0)
AzureIoTClient 16:deba40344375 170 {
AzureIoTClient 16:deba40344375 171 deviceIdString = STRING_clone(valueString);
AzureIoTClient 16:deba40344375 172 if (deviceIdString != NULL)
AzureIoTClient 16:deba40344375 173 {
AzureIoTClient 16:deba40344375 174 config->deviceId = STRING_c_str(deviceIdString);
AzureIoTClient 16:deba40344375 175 }
AzureIoTClient 16:deba40344375 176 }
AzureIoTClient 16:deba40344375 177 else if (strcmp(s_token, DEVICEKEY_TOKEN) == 0)
AzureIoTClient 16:deba40344375 178 {
AzureIoTClient 16:deba40344375 179 deviceKeyString = STRING_clone(valueString);
AzureIoTClient 16:deba40344375 180 if (deviceKeyString != NULL)
AzureIoTClient 16:deba40344375 181 {
AzureIoTClient 16:deba40344375 182 config->deviceKey = STRING_c_str(deviceKeyString);
AzureIoTClient 16:deba40344375 183 }
AzureIoTClient 16:deba40344375 184 }
AzureIoTClient 31:741eacddf296 185 /* Codes_SRS_IOTHUBCLIENT_LL_04_001: [IoTHubClient_LL_CreateFromConnectionString shall verify the existence of key/value pair GatewayHostName. If it does exist it shall pass the value to IoTHubClient_LL_Create API.] */
AzureIoTClient 16:deba40344375 186 else if (strcmp(s_token, PROTOCOL_GATEWAY_HOST) == 0)
AzureIoTClient 16:deba40344375 187 {
AzureIoTClient 16:deba40344375 188 protocolGateway = STRING_clone(valueString);
AzureIoTClient 16:deba40344375 189 if (protocolGateway != NULL)
AzureIoTClient 16:deba40344375 190 {
AzureIoTClient 16:deba40344375 191 config->protocolGatewayHostName = STRING_c_str(protocolGateway);
AzureIoTClient 16:deba40344375 192 }
AzureIoTClient 16:deba40344375 193 }
AzureIoTClient 16:deba40344375 194 }
AzureIoTClient 16:deba40344375 195 }
AzureIoTClient 16:deba40344375 196 }
AzureIoTClient 16:deba40344375 197 /* parsing is done - check the result */
AzureIoTClient 16:deba40344375 198 if (config->iotHubName == NULL)
AzureIoTClient 16:deba40344375 199 {
AzureIoTClient 16:deba40344375 200 LogError("iotHubName is not found\r\n");
AzureIoTClient 16:deba40344375 201 }
AzureIoTClient 16:deba40344375 202 else if (config->iotHubSuffix == NULL)
AzureIoTClient 16:deba40344375 203 {
AzureIoTClient 16:deba40344375 204 LogError("iotHubSuffix is not found\r\n");
AzureIoTClient 16:deba40344375 205 }
AzureIoTClient 16:deba40344375 206 else if (config->deviceId == NULL)
AzureIoTClient 16:deba40344375 207 {
AzureIoTClient 16:deba40344375 208 LogError("deviceId is not found\r\n");
AzureIoTClient 16:deba40344375 209 }
AzureIoTClient 16:deba40344375 210 else if (config->deviceKey == NULL)
AzureIoTClient 16:deba40344375 211 {
AzureIoTClient 16:deba40344375 212 LogError("deviceId is not found\r\n");
AzureIoTClient 16:deba40344375 213 }
AzureIoTClient 16:deba40344375 214 else
AzureIoTClient 16:deba40344375 215 {
AzureIoTClient 16:deba40344375 216 /* SRS_IOTHUBCLIENT_LL_12_011: [IoTHubClient_LL_CreateFromConnectionString shall call into the IoTHubClient_LL_Create API with the current structure and returns with the return value of it] */
AzureIoTClient 16:deba40344375 217 result = IoTHubClient_LL_Create(config);
AzureIoTClient 16:deba40344375 218 if (result == NULL)
AzureIoTClient 16:deba40344375 219 {
AzureIoTClient 16:deba40344375 220 LogError("IoTHubClient_LL_Create failed\r\n");
AzureIoTClient 16:deba40344375 221 }
AzureIoTClient 16:deba40344375 222 }
AzureIoTClient 16:deba40344375 223 }
AzureIoTClient 16:deba40344375 224 if (deviceKeyString != NULL)
AzureIoTClient 16:deba40344375 225 STRING_delete(deviceKeyString);
AzureIoTClient 16:deba40344375 226 if (deviceIdString != NULL)
AzureIoTClient 16:deba40344375 227 STRING_delete(deviceIdString);
AzureIoTClient 16:deba40344375 228 if (hostSuffixString != NULL)
AzureIoTClient 16:deba40344375 229 STRING_delete(hostSuffixString);
AzureIoTClient 16:deba40344375 230 if (hostNameString != NULL)
AzureIoTClient 16:deba40344375 231 STRING_delete(hostNameString);
AzureIoTClient 16:deba40344375 232 if (valueString != NULL)
AzureIoTClient 16:deba40344375 233 STRING_delete(valueString);
AzureIoTClient 16:deba40344375 234 if (tokenString != NULL)
AzureIoTClient 16:deba40344375 235 STRING_delete(tokenString);
AzureIoTClient 16:deba40344375 236 if (connString != NULL)
AzureIoTClient 16:deba40344375 237 STRING_delete(connString);
AzureIoTClient 16:deba40344375 238 if (protocolGateway != NULL)
AzureIoTClient 16:deba40344375 239 STRING_delete(protocolGateway);
AzureIoTClient 16:deba40344375 240
AzureIoTClient 16:deba40344375 241 if (tokenizer1 != NULL)
AzureIoTClient 16:deba40344375 242 STRING_TOKENIZER_destroy(tokenizer1);
AzureIoTClient 16:deba40344375 243
AzureIoTClient 16:deba40344375 244 free(config);
AzureIoTClient 16:deba40344375 245 }
AzureIoTClient 16:deba40344375 246 }
AzureIoTClient 16:deba40344375 247 return result;
AzureIoTClient 16:deba40344375 248 }
AzureIoTClient 16:deba40344375 249
Azure.IoT Build 36:67300d5a4c1f 250 static void setTransportProtocol(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, TRANSPORT_PROVIDER* protocol)
Azure.IoT Build 36:67300d5a4c1f 251 {
Azure.IoT Build 36:67300d5a4c1f 252 handleData->IoTHubTransport_SetOption = protocol->IoTHubTransport_SetOption;
Azure.IoT Build 36:67300d5a4c1f 253 handleData->IoTHubTransport_Create = protocol->IoTHubTransport_Create;
Azure.IoT Build 36:67300d5a4c1f 254 handleData->IoTHubTransport_Destroy = protocol->IoTHubTransport_Destroy;
Azure.IoT Build 36:67300d5a4c1f 255 handleData->IoTHubTransport_Register = protocol->IoTHubTransport_Register;
Azure.IoT Build 36:67300d5a4c1f 256 handleData->IoTHubTransport_Unregister = protocol->IoTHubTransport_Unregister;
Azure.IoT Build 36:67300d5a4c1f 257 handleData->IoTHubTransport_Subscribe = protocol->IoTHubTransport_Subscribe;
Azure.IoT Build 36:67300d5a4c1f 258 handleData->IoTHubTransport_Unsubscribe = protocol->IoTHubTransport_Unsubscribe;
Azure.IoT Build 36:67300d5a4c1f 259 handleData->IoTHubTransport_DoWork = protocol->IoTHubTransport_DoWork;
Azure.IoT Build 36:67300d5a4c1f 260 handleData->IoTHubTransport_GetSendStatus = protocol->IoTHubTransport_GetSendStatus;
Azure.IoT Build 36:67300d5a4c1f 261
Azure.IoT Build 36:67300d5a4c1f 262 }
AzureIoTClient 16:deba40344375 263
AzureIoTClient 16:deba40344375 264 IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_Create(const IOTHUB_CLIENT_CONFIG* config)
AzureIoTClient 16:deba40344375 265 {
AzureIoTClient 16:deba40344375 266 IOTHUB_CLIENT_LL_HANDLE result;
AzureIoTClient 16:deba40344375 267 /*Codes_SRS_IOTHUBCLIENT_LL_02_001: [IoTHubClient_LL_Create shall return NULL if config parameter is NULL or protocol field is NULL.]*/
AzureIoTClient 16:deba40344375 268 if (
AzureIoTClient 16:deba40344375 269 (config == NULL) ||
AzureIoTClient 16:deba40344375 270 (config->protocol == NULL)
AzureIoTClient 16:deba40344375 271 )
AzureIoTClient 16:deba40344375 272 {
AzureIoTClient 16:deba40344375 273 result = NULL;
AzureIoTClient 16:deba40344375 274 LogError("invalid configuration (NULL detected)\r\n");
AzureIoTClient 16:deba40344375 275 }
AzureIoTClient 16:deba40344375 276 else
AzureIoTClient 16:deba40344375 277 {
AzureIoTClient 16:deba40344375 278 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)malloc(sizeof(IOTHUB_CLIENT_LL_HANDLE_DATA));
AzureIoTClient 16:deba40344375 279 if (handleData == NULL)
AzureIoTClient 16:deba40344375 280 {
AzureIoTClient 16:deba40344375 281 LogError("malloc failed\r\n");
AzureIoTClient 16:deba40344375 282 result = NULL;
AzureIoTClient 16:deba40344375 283 }
AzureIoTClient 16:deba40344375 284 else
AzureIoTClient 16:deba40344375 285 {
Azure.IoT Build 36:67300d5a4c1f 286 if ((handleData->tickCounter = tickcounter_create()) == NULL)
Azure.IoT Build 36:67300d5a4c1f 287 {
Azure.IoT Build 36:67300d5a4c1f 288 LogError("unable to get a tickcounter");
Azure.IoT Build 36:67300d5a4c1f 289 free(handleData);
Azure.IoT Build 36:67300d5a4c1f 290 result = NULL;
Azure.IoT Build 36:67300d5a4c1f 291 }
Azure.IoT Build 36:67300d5a4c1f 292 else
Azure.IoT Build 36:67300d5a4c1f 293 {
AzureIoTClient 16:deba40344375 294 /*Codes_SRS_IOTHUBCLIENT_LL_02_004: [Otherwise IoTHubClient_LL_Create shall initialize a new DLIST (further called "waitingToSend") containing records with fields of the following types: IOTHUB_MESSAGE_HANDLE, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, void*.]*/
AzureIoTClient 16:deba40344375 295 IOTHUBTRANSPORT_CONFIG lowerLayerConfig;
AzureIoTClient 16:deba40344375 296 DList_InitializeListHead(&(handleData->waitingToSend));
Azure.IoT Build 36:67300d5a4c1f 297 setTransportProtocol(handleData, (TRANSPORT_PROVIDER*)config->protocol());
AzureIoTClient 16:deba40344375 298 handleData->messageCallback = NULL;
AzureIoTClient 16:deba40344375 299 handleData->messageUserContextCallback = NULL;
AzureIoTClient 16:deba40344375 300 handleData->lastMessageReceiveTime = INDEFINITE_TIME;
AzureIoTClient 16:deba40344375 301 /*Codes_SRS_IOTHUBCLIENT_LL_02_006: [IoTHubClient_LL_Create shall populate a structure of type IOTHUBTRANSPORT_CONFIG with the information from config parameter and the previous DLIST and shall pass that to the underlying layer _Create function.]*/
AzureIoTClient 16:deba40344375 302 lowerLayerConfig.upperConfig = config;
AzureIoTClient 16:deba40344375 303 lowerLayerConfig.waitingToSend = &(handleData->waitingToSend);
AzureIoTClient 16:deba40344375 304 /*Codes_SRS_IOTHUBCLIENT_LL_02_007: [If the underlaying layer _Create function fails them IoTHubClient_LL_Create shall fail and return NULL.] */
AzureIoTClient 16:deba40344375 305 if ((handleData->transportHandle = handleData->IoTHubTransport_Create(&lowerLayerConfig)) == NULL)
AzureIoTClient 16:deba40344375 306 {
AzureIoTClient 16:deba40344375 307 LogError("underlying transport failed\r\n");
Azure.IoT Build 36:67300d5a4c1f 308 tickcounter_destroy(handleData->tickCounter);
AzureIoTClient 16:deba40344375 309 free(handleData);
AzureIoTClient 16:deba40344375 310 result = NULL;
AzureIoTClient 16:deba40344375 311 }
AzureIoTClient 16:deba40344375 312 else
AzureIoTClient 16:deba40344375 313 {
Azure.IoT Build 36:67300d5a4c1f 314 /*Codes_SRS_IOTHUBCLIENT_LL_17_008: [IoTHubClient_LL_Create shall call the transport _Register function with the deviceId, DeviceKey and waitingToSend list.] */
Azure.IoT Build 36:67300d5a4c1f 315 if ((handleData->deviceHandle = handleData->IoTHubTransport_Register(handleData->transportHandle, config->deviceId, config->deviceKey, handleData, &(handleData->waitingToSend))) == NULL)
Azure.IoT Build 36:67300d5a4c1f 316 {
Azure.IoT Build 36:67300d5a4c1f 317 /*Codes_SRS_IOTHUBCLIENT_LL_17_009: [If the _Register function fails, this function shall fail and return NULL.]*/
Azure.IoT Build 36:67300d5a4c1f 318 LogError("Registering device in transport failed");
Azure.IoT Build 36:67300d5a4c1f 319 handleData->IoTHubTransport_Destroy(handleData->transportHandle);
Azure.IoT Build 36:67300d5a4c1f 320 tickcounter_destroy(handleData->tickCounter);
Azure.IoT Build 36:67300d5a4c1f 321 free(handleData);
Azure.IoT Build 36:67300d5a4c1f 322 result = NULL;
Azure.IoT Build 36:67300d5a4c1f 323 }
Azure.IoT Build 36:67300d5a4c1f 324 else
Azure.IoT Build 36:67300d5a4c1f 325 {
Azure.IoT Build 36:67300d5a4c1f 326 /*Codes_SRS_IOTHUBCLIENT_LL_02_008: [Otherwise, IoTHubClient_LL_Create shall succeed and return a non-NULL handle.] */
Azure.IoT Build 36:67300d5a4c1f 327 handleData->isSharedTransport = false;
Azure.IoT Build 36:67300d5a4c1f 328 /*Codes_SRS_IOTHUBCLIENT_LL_02_042: [ By default, messages shall not timeout. ]*/
Azure.IoT Build 36:67300d5a4c1f 329 handleData->currentMessageTimeout = 0;
Azure.IoT Build 36:67300d5a4c1f 330 result = handleData;
Azure.IoT Build 36:67300d5a4c1f 331 }
AzureIoTClient 16:deba40344375 332 }
AzureIoTClient 16:deba40344375 333 }
AzureIoTClient 16:deba40344375 334 }
Azure.IoT Build 36:67300d5a4c1f 335 }
AzureIoTClient 16:deba40344375 336
AzureIoTClient 16:deba40344375 337 return result;
AzureIoTClient 16:deba40344375 338 }
AzureIoTClient 16:deba40344375 339
Azure.IoT Build 36:67300d5a4c1f 340 IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateWithTransport(const IOTHUB_CLIENT_DEVICE_CONFIG * config)
Azure.IoT Build 36:67300d5a4c1f 341 {
Azure.IoT Build 36:67300d5a4c1f 342 IOTHUB_CLIENT_LL_HANDLE result;
Azure.IoT Build 36:67300d5a4c1f 343 /*Codes_SRS_IOTHUBCLIENT_LL_17_001: [IoTHubClient_LL_CreateWithTransport shall return NULL if config parameter is NULL, or protocol field is NULL or transportHandle is NULL.]*/
Azure.IoT Build 36:67300d5a4c1f 344 if (
Azure.IoT Build 36:67300d5a4c1f 345 (config == NULL) ||
Azure.IoT Build 36:67300d5a4c1f 346 (config->protocol == NULL) ||
Azure.IoT Build 36:67300d5a4c1f 347 (config->transportHandle == NULL)
Azure.IoT Build 36:67300d5a4c1f 348 )
Azure.IoT Build 36:67300d5a4c1f 349 {
Azure.IoT Build 36:67300d5a4c1f 350 result = NULL;
Azure.IoT Build 36:67300d5a4c1f 351 LogError("invalid configuration (NULL detected)\r\n");
Azure.IoT Build 36:67300d5a4c1f 352 }
Azure.IoT Build 36:67300d5a4c1f 353 else
Azure.IoT Build 36:67300d5a4c1f 354 {
Azure.IoT Build 36:67300d5a4c1f 355 /*Codes_SRS_IOTHUBCLIENT_LL_17_002: [IoTHubClient_LL_CreateWithTransport shall allocate data for the IOTHUB_CLIENT_LL_HANDLE.]*/
Azure.IoT Build 36:67300d5a4c1f 356 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)malloc(sizeof(IOTHUB_CLIENT_LL_HANDLE_DATA));
Azure.IoT Build 36:67300d5a4c1f 357 if (handleData == NULL)
Azure.IoT Build 36:67300d5a4c1f 358 {
Azure.IoT Build 36:67300d5a4c1f 359 /*Codes_SRS_IOTHUBCLIENT_LL_17_003: [If allocation fails, the function shall fail and return NULL.] */
Azure.IoT Build 36:67300d5a4c1f 360 LogError("malloc failed\r\n");
Azure.IoT Build 36:67300d5a4c1f 361 result = NULL;
Azure.IoT Build 36:67300d5a4c1f 362 }
Azure.IoT Build 36:67300d5a4c1f 363 else
Azure.IoT Build 36:67300d5a4c1f 364 {
Azure.IoT Build 36:67300d5a4c1f 365 if ((handleData->tickCounter = tickcounter_create()) == NULL)
Azure.IoT Build 36:67300d5a4c1f 366 {
Azure.IoT Build 36:67300d5a4c1f 367 LogError("unable to get a tickcounter");
Azure.IoT Build 36:67300d5a4c1f 368 free(handleData);
Azure.IoT Build 36:67300d5a4c1f 369 result = NULL;
Azure.IoT Build 36:67300d5a4c1f 370 }
Azure.IoT Build 36:67300d5a4c1f 371 else
Azure.IoT Build 36:67300d5a4c1f 372 {
Azure.IoT Build 36:67300d5a4c1f 373 /*Codes_SRS_IOTHUBCLIENT_LL_17_004: [IoTHubClient_LL_CreateWithTransport shall initialize a new DLIST (further called "waitingToSend") containing records with fields of the following types: IOTHUB_MESSAGE_HANDLE, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, void*.]*/
Azure.IoT Build 36:67300d5a4c1f 374 DList_InitializeListHead(&(handleData->waitingToSend));
Azure.IoT Build 36:67300d5a4c1f 375 setTransportProtocol(handleData, (TRANSPORT_PROVIDER*)config->protocol());
Azure.IoT Build 36:67300d5a4c1f 376 handleData->messageCallback = NULL;
Azure.IoT Build 36:67300d5a4c1f 377 handleData->messageUserContextCallback = NULL;
Azure.IoT Build 36:67300d5a4c1f 378 handleData->lastMessageReceiveTime = INDEFINITE_TIME;
Azure.IoT Build 36:67300d5a4c1f 379 handleData->transportHandle = config->transportHandle;
Azure.IoT Build 36:67300d5a4c1f 380 /*Codes_SRS_IOTHUBCLIENT_LL_17_006: [IoTHubClient_LL_CreateWithTransport shall call the transport _Register function with the deviceId, DeviceKey and waitingToSend list.]*/
Azure.IoT Build 36:67300d5a4c1f 381 if ((handleData->deviceHandle = handleData->IoTHubTransport_Register(config->transportHandle, config->deviceId, config->deviceKey, handleData, &(handleData->waitingToSend))) == NULL)
Azure.IoT Build 36:67300d5a4c1f 382 {
Azure.IoT Build 36:67300d5a4c1f 383 /*Codes_SRS_IOTHUBCLIENT_LL_17_007: [If the _Register function fails, this function shall fail and return NULL.]*/
Azure.IoT Build 36:67300d5a4c1f 384 LogError("Registering device in transport failed");
Azure.IoT Build 36:67300d5a4c1f 385 tickcounter_destroy(handleData->tickCounter);
Azure.IoT Build 36:67300d5a4c1f 386 free(handleData);
Azure.IoT Build 36:67300d5a4c1f 387 result = NULL;
Azure.IoT Build 36:67300d5a4c1f 388 }
Azure.IoT Build 36:67300d5a4c1f 389 else
Azure.IoT Build 36:67300d5a4c1f 390 {
Azure.IoT Build 36:67300d5a4c1f 391 /*Codes_SRS_IOTHUBCLIENT_LL_17_005: [IoTHubClient_LL_CreateWithTransport shall save the transport handle and mark this transport as shared.]*/
Azure.IoT Build 36:67300d5a4c1f 392 handleData->isSharedTransport = true;
Azure.IoT Build 36:67300d5a4c1f 393 /*Codes_SRS_IOTHUBCLIENT_LL_02_042: [ By default, messages shall not timeout. ]*/
Azure.IoT Build 36:67300d5a4c1f 394 handleData->currentMessageTimeout = 0;
Azure.IoT Build 36:67300d5a4c1f 395 result = handleData;
Azure.IoT Build 36:67300d5a4c1f 396 }
Azure.IoT Build 36:67300d5a4c1f 397 }
Azure.IoT Build 36:67300d5a4c1f 398 }
Azure.IoT Build 36:67300d5a4c1f 399 }
Azure.IoT Build 36:67300d5a4c1f 400
Azure.IoT Build 36:67300d5a4c1f 401 return result;
Azure.IoT Build 36:67300d5a4c1f 402 }
Azure.IoT Build 36:67300d5a4c1f 403
AzureIoTClient 16:deba40344375 404 void IoTHubClient_LL_Destroy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle)
AzureIoTClient 16:deba40344375 405 {
AzureIoTClient 16:deba40344375 406 /*Codes_SRS_IOTHUBCLIENT_LL_02_009: [IoTHubClient_LL_Destroy shall do nothing if parameter iotHubClientHandle is NULL.]*/
AzureIoTClient 16:deba40344375 407 if (iotHubClientHandle != NULL)
AzureIoTClient 16:deba40344375 408 {
AzureIoTClient 16:deba40344375 409 PDLIST_ENTRY unsend;
Azure.IoT Build 36:67300d5a4c1f 410 /*Codes_SRS_IOTHUBCLIENT_LL_17_010: [IoTHubClient_LL_Destroy shall call the underlaying layer's _Unregister function] */
AzureIoTClient 16:deba40344375 411 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
Azure.IoT Build 36:67300d5a4c1f 412 handleData->IoTHubTransport_Unregister(handleData->deviceHandle);
Azure.IoT Build 36:67300d5a4c1f 413 if (handleData->isSharedTransport == false)
Azure.IoT Build 36:67300d5a4c1f 414 {
Azure.IoT Build 36:67300d5a4c1f 415 /*Codes_SRS_IOTHUBCLIENT_LL_02_010: [If iotHubClientHandle was not created by IoTHubClient_LL_CreateWithTransport, IoTHubClient_LL_Destroy shall call the underlaying layer's _Destroy function.] */
Azure.IoT Build 36:67300d5a4c1f 416 handleData->IoTHubTransport_Destroy(handleData->transportHandle);
Azure.IoT Build 36:67300d5a4c1f 417 }
AzureIoTClient 16:deba40344375 418 /*if any, remove the items currently not send*/
AzureIoTClient 16:deba40344375 419 while ((unsend = DList_RemoveHeadList(&(handleData->waitingToSend))) != &(handleData->waitingToSend))
AzureIoTClient 16:deba40344375 420 {
AzureIoTClient 16:deba40344375 421 IOTHUB_MESSAGE_LIST* temp = containingRecord(unsend, IOTHUB_MESSAGE_LIST, entry);
AzureIoTClient 16:deba40344375 422 /*Codes_SRS_IOTHUBCLIENT_LL_02_033: [Otherwise, IoTHubClient_LL_Destroy shall complete all the event message callbacks that are in the waitingToSend list with the result IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY.] */
AzureIoTClient 16:deba40344375 423 if (temp->callback != NULL)
AzureIoTClient 16:deba40344375 424 {
AzureIoTClient 16:deba40344375 425 temp->callback(IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY, temp->context);
AzureIoTClient 16:deba40344375 426 }
AzureIoTClient 16:deba40344375 427 IoTHubMessage_Destroy(temp->messageHandle);
AzureIoTClient 16:deba40344375 428 free(temp);
AzureIoTClient 16:deba40344375 429 }
Azure.IoT Build 36:67300d5a4c1f 430 /*Codes_SRS_IOTHUBCLIENT_LL_17_011: [IoTHubClient_LL_Destroy shall free the resources allocated by IoTHubClient (if any).] */
Azure.IoT Build 36:67300d5a4c1f 431 tickcounter_destroy(handleData->tickCounter);
AzureIoTClient 16:deba40344375 432 free(handleData);
AzureIoTClient 16:deba40344375 433 }
AzureIoTClient 16:deba40344375 434 }
AzureIoTClient 16:deba40344375 435
Azure.IoT Build 36:67300d5a4c1f 436 /*Codes_SRS_IOTHUBCLIENT_LL_02_044: [ Messages already delivered to IoTHubClient_LL shall not have their timeouts modified by a new call to IoTHubClient_LL_SetOption. ]*/
Azure.IoT Build 36:67300d5a4c1f 437 /*returns 0 on success, any other value is error*/
Azure.IoT Build 36:67300d5a4c1f 438 static int attach_ms_timesOutAfter(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, IOTHUB_MESSAGE_LIST *newEntry)
Azure.IoT Build 36:67300d5a4c1f 439 {
Azure.IoT Build 36:67300d5a4c1f 440 int result;
Azure.IoT Build 36:67300d5a4c1f 441 /*Codes_SRS_IOTHUBCLIENT_LL_02_043: [ Calling IoTHubClient_LL_SetOption with value set to "0" shall disable the timeout mechanism for all new messages. ]*/
Azure.IoT Build 36:67300d5a4c1f 442 if (handleData->currentMessageTimeout == 0)
Azure.IoT Build 36:67300d5a4c1f 443 {
Azure.IoT Build 36:67300d5a4c1f 444 newEntry->ms_timesOutAfter = 0; /*do not timeout*/
Azure.IoT Build 36:67300d5a4c1f 445 result = 0;
Azure.IoT Build 36:67300d5a4c1f 446 }
Azure.IoT Build 36:67300d5a4c1f 447 else
Azure.IoT Build 36:67300d5a4c1f 448 {
Azure.IoT Build 36:67300d5a4c1f 449 /*Codes_SRS_IOTHUBCLIENT_LL_02_039: [ "messageTimeout" - once IoTHubClient_LL_SendEventAsync is called the message shall timeout after value miliseconds. Value is a pointer to a uint64. ]*/
Azure.IoT Build 36:67300d5a4c1f 450 if (tickcounter_get_current_ms(handleData->tickCounter, &newEntry->ms_timesOutAfter) != 0)
Azure.IoT Build 36:67300d5a4c1f 451 {
Azure.IoT Build 36:67300d5a4c1f 452 result = __LINE__;
Azure.IoT Build 36:67300d5a4c1f 453 LogError("unable to get the current relative tickcount");
Azure.IoT Build 36:67300d5a4c1f 454 }
Azure.IoT Build 36:67300d5a4c1f 455 else
Azure.IoT Build 36:67300d5a4c1f 456 {
Azure.IoT Build 36:67300d5a4c1f 457 newEntry->ms_timesOutAfter += handleData->currentMessageTimeout;
Azure.IoT Build 36:67300d5a4c1f 458 result = 0;
Azure.IoT Build 36:67300d5a4c1f 459 }
Azure.IoT Build 36:67300d5a4c1f 460 }
Azure.IoT Build 36:67300d5a4c1f 461 return result;
Azure.IoT Build 36:67300d5a4c1f 462 }
Azure.IoT Build 36:67300d5a4c1f 463
AzureIoTClient 16:deba40344375 464 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SendEventAsync(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK eventConfirmationCallback, void* userContextCallback)
AzureIoTClient 16:deba40344375 465 {
AzureIoTClient 16:deba40344375 466 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 467 /*Codes_SRS_IOTHUBCLIENT_LL_02_011: [IoTHubClient_LL_SendEventAsync shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle or eventMessageHandle is NULL.]*/
AzureIoTClient 16:deba40344375 468 if (
AzureIoTClient 16:deba40344375 469 (iotHubClientHandle == NULL) ||
AzureIoTClient 16:deba40344375 470 (eventMessageHandle == NULL) ||
AzureIoTClient 16:deba40344375 471 /*Codes_SRS_IOTHUBCLIENT_LL_02_012: [IoTHubClient_LL_SendEventAsync shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter eventConfirmationCallback is NULL and userContextCallback is not NULL.] */
AzureIoTClient 16:deba40344375 472 ((eventConfirmationCallback == NULL) && (userContextCallback != NULL))
AzureIoTClient 16:deba40344375 473 )
AzureIoTClient 16:deba40344375 474 {
AzureIoTClient 16:deba40344375 475 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 16:deba40344375 476 LOG_ERROR;
AzureIoTClient 16:deba40344375 477 }
AzureIoTClient 16:deba40344375 478 else
AzureIoTClient 16:deba40344375 479 {
AzureIoTClient 16:deba40344375 480 IOTHUB_MESSAGE_LIST *newEntry = (IOTHUB_MESSAGE_LIST*)malloc(sizeof(IOTHUB_MESSAGE_LIST));
AzureIoTClient 16:deba40344375 481 if (newEntry == NULL)
AzureIoTClient 16:deba40344375 482 {
AzureIoTClient 16:deba40344375 483 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 16:deba40344375 484 LOG_ERROR;
AzureIoTClient 16:deba40344375 485 }
AzureIoTClient 16:deba40344375 486 else
AzureIoTClient 16:deba40344375 487 {
Azure.IoT Build 36:67300d5a4c1f 488 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
Azure.IoT Build 36:67300d5a4c1f 489
Azure.IoT Build 36:67300d5a4c1f 490 if (attach_ms_timesOutAfter(handleData, newEntry) != 0)
Azure.IoT Build 36:67300d5a4c1f 491 {
Azure.IoT Build 36:67300d5a4c1f 492 result = IOTHUB_CLIENT_ERROR;
Azure.IoT Build 36:67300d5a4c1f 493 LOG_ERROR;
Azure.IoT Build 36:67300d5a4c1f 494 free(newEntry);
Azure.IoT Build 36:67300d5a4c1f 495 }
Azure.IoT Build 36:67300d5a4c1f 496 else
Azure.IoT Build 36:67300d5a4c1f 497 {
AzureIoTClient 16:deba40344375 498 /*Codes_SRS_IOTHUBCLIENT_LL_02_013: [IoTHubClient_SendEventAsync shall add the DLIST waitingToSend a new record cloning the information from eventMessageHandle, eventConfirmationCallback, userContextCallback.]*/
AzureIoTClient 16:deba40344375 499 if ((newEntry->messageHandle = IoTHubMessage_Clone(eventMessageHandle)) == NULL)
AzureIoTClient 16:deba40344375 500 {
AzureIoTClient 16:deba40344375 501 /*Codes_SRS_IOTHUBCLIENT_LL_02_014: [If cloning and/or adding the information fails for any reason, IoTHubClient_LL_SendEventAsync shall fail and return IOTHUB_CLIENT_ERROR.] */
AzureIoTClient 16:deba40344375 502 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 16:deba40344375 503 free(newEntry);
AzureIoTClient 16:deba40344375 504 LOG_ERROR;
AzureIoTClient 16:deba40344375 505 }
AzureIoTClient 16:deba40344375 506 else
AzureIoTClient 16:deba40344375 507 {
AzureIoTClient 16:deba40344375 508 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 509 /*Codes_SRS_IOTHUBCLIENT_LL_02_013: [IoTHubClient_SendEventAsync shall add the DLIST waitingToSend a new record cloning the information from eventMessageHandle, eventConfirmationCallback, userContextCallback.]*/
AzureIoTClient 16:deba40344375 510 newEntry->callback = eventConfirmationCallback;
AzureIoTClient 16:deba40344375 511 newEntry->context = userContextCallback;
AzureIoTClient 16:deba40344375 512 DList_InsertTailList(&(handleData->waitingToSend), &(newEntry->entry));
AzureIoTClient 16:deba40344375 513 /*Codes_SRS_IOTHUBCLIENT_LL_02_015: [Otherwise IoTHubClient_LL_SendEventAsync shall succeed and return IOTHUB_CLIENT_OK.] */
AzureIoTClient 16:deba40344375 514 result = IOTHUB_CLIENT_OK;
AzureIoTClient 16:deba40344375 515 }
AzureIoTClient 16:deba40344375 516 }
AzureIoTClient 16:deba40344375 517 }
Azure.IoT Build 36:67300d5a4c1f 518 }
AzureIoTClient 16:deba40344375 519 return result;
AzureIoTClient 16:deba40344375 520 }
AzureIoTClient 16:deba40344375 521
AzureIoTClient 16:deba40344375 522 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetMessageCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback)
AzureIoTClient 16:deba40344375 523 {
AzureIoTClient 16:deba40344375 524 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 525 /*Codes_SRS_IOTHUBCLIENT_LL_02_016: [IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.] */
AzureIoTClient 16:deba40344375 526 if (iotHubClientHandle == NULL)
AzureIoTClient 16:deba40344375 527 {
AzureIoTClient 16:deba40344375 528 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 16:deba40344375 529 LOG_ERROR;
AzureIoTClient 16:deba40344375 530 }
AzureIoTClient 16:deba40344375 531 else
AzureIoTClient 16:deba40344375 532 {
AzureIoTClient 16:deba40344375 533 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 534 if (messageCallback == NULL)
AzureIoTClient 16:deba40344375 535 {
AzureIoTClient 16:deba40344375 536 /*Codes_SRS_IOTHUBCLIENT_LL_02_019: [If parameter messageCallback is NULL then IoTHubClient_LL_SetMessageCallback shall call the underlying layer's _Unsubscribe function and return IOTHUB_CLIENT_OK.] */
Azure.IoT Build 36:67300d5a4c1f 537 handleData->IoTHubTransport_Unsubscribe(handleData->deviceHandle);
AzureIoTClient 16:deba40344375 538 handleData->messageCallback = NULL;
AzureIoTClient 16:deba40344375 539 handleData->messageUserContextCallback = NULL;
AzureIoTClient 16:deba40344375 540 result = IOTHUB_CLIENT_OK;
AzureIoTClient 16:deba40344375 541 }
AzureIoTClient 16:deba40344375 542 else
AzureIoTClient 16:deba40344375 543 {
AzureIoTClient 16:deba40344375 544 /*Codes_SRS_IOTHUBCLIENT_LL_02_017: [If parameter messageCallback is non-NULL then IoTHubClient_LL_SetMessageCallback shall call the underlying layer's _Subscribe function.]*/
Azure.IoT Build 36:67300d5a4c1f 545 if (handleData->IoTHubTransport_Subscribe(handleData->deviceHandle) == 0)
AzureIoTClient 16:deba40344375 546 {
AzureIoTClient 16:deba40344375 547 handleData->messageCallback = messageCallback;
AzureIoTClient 16:deba40344375 548 handleData->messageUserContextCallback = userContextCallback;
AzureIoTClient 16:deba40344375 549 result = IOTHUB_CLIENT_OK;
AzureIoTClient 16:deba40344375 550 }
AzureIoTClient 16:deba40344375 551 else
AzureIoTClient 16:deba40344375 552 {
AzureIoTClient 16:deba40344375 553 handleData->messageCallback = NULL;
AzureIoTClient 16:deba40344375 554 handleData->messageUserContextCallback = NULL;
AzureIoTClient 16:deba40344375 555 /*Codes_SRS_IOTHUBCLIENT_LL_02_018: [If the underlying layer's _Subscribe function fails, then IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_ERROR. Otherwise IoTHubClient_LL_SetMessageCallback shall succeed and return IOTHUB_CLIENT_OK.]*/
AzureIoTClient 16:deba40344375 556 result = IOTHUB_CLIENT_ERROR;
AzureIoTClient 16:deba40344375 557 }
AzureIoTClient 16:deba40344375 558 }
AzureIoTClient 16:deba40344375 559 }
AzureIoTClient 16:deba40344375 560
AzureIoTClient 16:deba40344375 561 return result;
AzureIoTClient 16:deba40344375 562 }
AzureIoTClient 16:deba40344375 563
Azure.IoT Build 36:67300d5a4c1f 564 static void DoTimeouts(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData)
Azure.IoT Build 36:67300d5a4c1f 565 {
Azure.IoT Build 36:67300d5a4c1f 566 uint64_t nowTick;
Azure.IoT Build 36:67300d5a4c1f 567 if (tickcounter_get_current_ms(handleData->tickCounter, &nowTick) != 0)
Azure.IoT Build 36:67300d5a4c1f 568 {
Azure.IoT Build 36:67300d5a4c1f 569 LogError("unable to get the current ms, timeouts will not be processed");
Azure.IoT Build 36:67300d5a4c1f 570 }
Azure.IoT Build 36:67300d5a4c1f 571 else
Azure.IoT Build 36:67300d5a4c1f 572 {
Azure.IoT Build 36:67300d5a4c1f 573 DLIST_ENTRY* currentItemInWaitingToSend = handleData->waitingToSend.Flink;
Azure.IoT Build 36:67300d5a4c1f 574 while (currentItemInWaitingToSend != &(handleData->waitingToSend)) /*while we are not at the end of the list*/
Azure.IoT Build 36:67300d5a4c1f 575 {
Azure.IoT Build 36:67300d5a4c1f 576 IOTHUB_MESSAGE_LIST* fullEntry = containingRecord(currentItemInWaitingToSend, IOTHUB_MESSAGE_LIST, entry);
Azure.IoT Build 36:67300d5a4c1f 577 /*Codes_SRS_IOTHUBCLIENT_LL_02_041: [ If more than value miliseconds have passed since the call to IoTHubClient_LL_SendEventAsync then the message callback shall be called with a status code of IOTHUB_CLIENT_CONFIRMATION_TIMEOUT. ]*/
Azure.IoT Build 36:67300d5a4c1f 578 if ((fullEntry->ms_timesOutAfter!=0) && (fullEntry->ms_timesOutAfter < nowTick))
Azure.IoT Build 36:67300d5a4c1f 579 {
Azure.IoT Build 36:67300d5a4c1f 580 PDLIST_ENTRY theNext = currentItemInWaitingToSend->Flink; /*need to save the next item, because the below operations are destructive*/
Azure.IoT Build 36:67300d5a4c1f 581 DList_RemoveEntryList(currentItemInWaitingToSend);
Azure.IoT Build 36:67300d5a4c1f 582 if (fullEntry->callback != NULL)
Azure.IoT Build 36:67300d5a4c1f 583 {
Azure.IoT Build 36:67300d5a4c1f 584 fullEntry->callback(IOTHUB_CLIENT_CONFIRMATION_MESSAGE_TIMEOUT, fullEntry->context);
Azure.IoT Build 36:67300d5a4c1f 585 }
Azure.IoT Build 36:67300d5a4c1f 586 IoTHubMessage_Destroy(fullEntry->messageHandle); /*because it has been cloned*/
Azure.IoT Build 36:67300d5a4c1f 587 free(fullEntry);
Azure.IoT Build 36:67300d5a4c1f 588 currentItemInWaitingToSend = theNext;
Azure.IoT Build 36:67300d5a4c1f 589 }
Azure.IoT Build 36:67300d5a4c1f 590 else
Azure.IoT Build 36:67300d5a4c1f 591 {
Azure.IoT Build 36:67300d5a4c1f 592 currentItemInWaitingToSend = currentItemInWaitingToSend->Flink;
Azure.IoT Build 36:67300d5a4c1f 593 }
Azure.IoT Build 36:67300d5a4c1f 594 }
Azure.IoT Build 36:67300d5a4c1f 595 }
Azure.IoT Build 36:67300d5a4c1f 596 }
Azure.IoT Build 36:67300d5a4c1f 597
AzureIoTClient 16:deba40344375 598 void IoTHubClient_LL_DoWork(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle)
AzureIoTClient 16:deba40344375 599 {
AzureIoTClient 16:deba40344375 600 /*Codes_SRS_IOTHUBCLIENT_LL_02_020: [If parameter iotHubClientHandle is NULL then IoTHubClient_LL_DoWork shall not perform any action.] */
AzureIoTClient 16:deba40344375 601 if (iotHubClientHandle != NULL)
AzureIoTClient 16:deba40344375 602 {
AzureIoTClient 16:deba40344375 603 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
Azure.IoT Build 36:67300d5a4c1f 604 DoTimeouts(handleData);
AzureIoTClient 16:deba40344375 605 handleData->IoTHubTransport_DoWork(handleData->transportHandle, iotHubClientHandle);
AzureIoTClient 16:deba40344375 606 }
AzureIoTClient 16:deba40344375 607 }
AzureIoTClient 16:deba40344375 608
AzureIoTClient 16:deba40344375 609 IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetSendStatus(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus)
AzureIoTClient 16:deba40344375 610 {
AzureIoTClient 16:deba40344375 611 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 612
AzureIoTClient 16:deba40344375 613 /* Codes_SRS_IOTHUBCLIENT_09_007: [IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL parameter] */
AzureIoTClient 16:deba40344375 614 if (iotHubClientHandle == NULL || iotHubClientStatus == NULL)
AzureIoTClient 16:deba40344375 615 {
AzureIoTClient 16:deba40344375 616 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 16:deba40344375 617 LOG_ERROR;
AzureIoTClient 16:deba40344375 618 }
AzureIoTClient 16:deba40344375 619 else
AzureIoTClient 16:deba40344375 620 {
AzureIoTClient 16:deba40344375 621 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 622
AzureIoTClient 16:deba40344375 623 /* Codes_SRS_IOTHUBCLIENT_09_008: [IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_OK and status IOTHUB_CLIENT_SEND_STATUS_IDLE if there is currently no items to be sent] */
AzureIoTClient 16:deba40344375 624 /* Codes_SRS_IOTHUBCLIENT_09_009: [IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_OK and status IOTHUB_CLIENT_SEND_STATUS_BUSY if there are currently items to be sent] */
Azure.IoT Build 36:67300d5a4c1f 625 result = handleData->IoTHubTransport_GetSendStatus(handleData->deviceHandle, iotHubClientStatus);
AzureIoTClient 16:deba40344375 626 }
AzureIoTClient 16:deba40344375 627
AzureIoTClient 16:deba40344375 628 return result;
AzureIoTClient 16:deba40344375 629 }
AzureIoTClient 16:deba40344375 630
AzureIoTClient 16:deba40344375 631 void IoTHubClient_LL_SendComplete(IOTHUB_CLIENT_LL_HANDLE handle, PDLIST_ENTRY completed, IOTHUB_BATCHSTATE_RESULT result)
AzureIoTClient 16:deba40344375 632 {
AzureIoTClient 16:deba40344375 633 /*Codes_SRS_IOTHUBCLIENT_LL_02_022: [If parameter completed is NULL, or parameter handle is NULL then IoTHubClient_LL_SendBatch shall return.]*/
AzureIoTClient 16:deba40344375 634 if (
AzureIoTClient 16:deba40344375 635 (handle == NULL) ||
AzureIoTClient 16:deba40344375 636 (completed == NULL)
AzureIoTClient 16:deba40344375 637 )
AzureIoTClient 16:deba40344375 638 {
AzureIoTClient 16:deba40344375 639 /*"shall return"*/
AzureIoTClient 16:deba40344375 640 LogError("invalid arg\r\n");
AzureIoTClient 16:deba40344375 641 }
AzureIoTClient 16:deba40344375 642 else
AzureIoTClient 16:deba40344375 643 {
AzureIoTClient 16:deba40344375 644 /*Codes_SRS_IOTHUBCLIENT_LL_02_027: [If parameter result is IOTHUB_BACTHSTATE_FAILED then IoTHubClient_LL_SendComplete shall call all the non-NULL callbacks with the result parameter set to IOTHUB_CLIENT_CONFIRMATION_ERROR and the context set to the context passed originally in the SendEventAsync call.] */
AzureIoTClient 16:deba40344375 645 /*Codes_SRS_IOTHUBCLIENT_LL_02_025: [If parameter result is IOTHUB_BATCHSTATE_SUCCESS then IoTHubClient_LL_SendComplete shall call all the non-NULL callbacks with the result parameter set to IOTHUB_CLIENT_CONFIRMATION_OK and the context set to the context passed originally in the SendEventAsync call.]*/
AzureIoTClient 16:deba40344375 646 IOTHUB_CLIENT_CONFIRMATION_RESULT resultToBeCalled = (result == IOTHUB_BATCHSTATE_SUCCESS) ? IOTHUB_CLIENT_CONFIRMATION_OK : IOTHUB_CLIENT_CONFIRMATION_ERROR;
AzureIoTClient 16:deba40344375 647 PDLIST_ENTRY oldest;
AzureIoTClient 16:deba40344375 648 while((oldest= DList_RemoveHeadList(completed))!=completed)
AzureIoTClient 16:deba40344375 649 {
AzureIoTClient 16:deba40344375 650 IOTHUB_MESSAGE_LIST* messageList = (IOTHUB_MESSAGE_LIST*)containingRecord(oldest, IOTHUB_MESSAGE_LIST, entry);
AzureIoTClient 16:deba40344375 651 if (messageList->callback != NULL)
AzureIoTClient 16:deba40344375 652 {
AzureIoTClient 16:deba40344375 653 messageList->callback(resultToBeCalled, messageList->context);
AzureIoTClient 16:deba40344375 654 }
AzureIoTClient 16:deba40344375 655 IoTHubMessage_Destroy(messageList->messageHandle);
AzureIoTClient 16:deba40344375 656 free(messageList);
AzureIoTClient 16:deba40344375 657 }
AzureIoTClient 16:deba40344375 658 }
AzureIoTClient 16:deba40344375 659 }
AzureIoTClient 16:deba40344375 660
AzureIoTClient 16:deba40344375 661 IOTHUBMESSAGE_DISPOSITION_RESULT IoTHubClient_LL_MessageCallback(IOTHUB_CLIENT_LL_HANDLE handle, IOTHUB_MESSAGE_HANDLE message)
AzureIoTClient 16:deba40344375 662 {
AzureIoTClient 16:deba40344375 663 int result;
AzureIoTClient 16:deba40344375 664 /*Codes_SRS_IOTHUBCLIENT_LL_02_029: [If parameter handle is NULL then IoTHubClient_LL_MessageCallback shall return IOTHUBMESSAGE_ABANDONED.] */
AzureIoTClient 16:deba40344375 665 if (handle == NULL)
AzureIoTClient 16:deba40344375 666 {
AzureIoTClient 16:deba40344375 667 LogError("invalid argument\r\n");
AzureIoTClient 16:deba40344375 668 result = IOTHUBMESSAGE_ABANDONED;
AzureIoTClient 16:deba40344375 669 }
AzureIoTClient 16:deba40344375 670 else
AzureIoTClient 16:deba40344375 671 {
AzureIoTClient 16:deba40344375 672 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle;
AzureIoTClient 16:deba40344375 673
AzureIoTClient 16:deba40344375 674 /* Codes_SRS_IOTHUBCLIENT_LL_09_004: [IoTHubClient_LL_GetLastMessageReceiveTime shall return lastMessageReceiveTime in localtime] */
AzureIoTClient 16:deba40344375 675 handleData->lastMessageReceiveTime = get_time(NULL);
AzureIoTClient 16:deba40344375 676
AzureIoTClient 16:deba40344375 677 /*Codes_SRS_IOTHUBCLIENT_LL_02_030: [IoTHubClient_LL_MessageCallback shall invoke the last callback function (the parameter messageCallback to IoTHubClient_LL_SetMessageCallback) passing the message and the passed userContextCallback.]*/
AzureIoTClient 16:deba40344375 678 if (handleData->messageCallback != NULL)
AzureIoTClient 16:deba40344375 679 {
AzureIoTClient 16:deba40344375 680 result = handleData->messageCallback(message, handleData->messageUserContextCallback);
AzureIoTClient 16:deba40344375 681 }
AzureIoTClient 16:deba40344375 682 else
AzureIoTClient 16:deba40344375 683 {
AzureIoTClient 16:deba40344375 684 /*Codes_SRS_IOTHUBCLIENT_LL_02_032: [If the last callback function was NULL, then IoTHubClient_LL_MessageCallback shall return IOTHUBMESSAGE_ABANDONED.] */
AzureIoTClient 16:deba40344375 685 LogError("user callback was NULL\r\n");
AzureIoTClient 16:deba40344375 686 result = IOTHUBMESSAGE_ABANDONED;
AzureIoTClient 16:deba40344375 687 }
AzureIoTClient 16:deba40344375 688 }
AzureIoTClient 16:deba40344375 689 /*Codes_SRS_IOTHUBCLIENT_LL_02_031: [Then IoTHubClient_LL_MessageCallback shall return what the user function returns.]*/
AzureIoTClient 16:deba40344375 690 return result;
AzureIoTClient 16:deba40344375 691 }
AzureIoTClient 16:deba40344375 692
AzureIoTClient 16:deba40344375 693 IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetLastMessageReceiveTime(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime)
AzureIoTClient 16:deba40344375 694 {
AzureIoTClient 16:deba40344375 695 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 696 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 697
AzureIoTClient 16:deba40344375 698 /* Codes_SRS_IOTHUBCLIENT_LL_09_001: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INVALID_ARG if any of the arguments is NULL] */
AzureIoTClient 16:deba40344375 699 if (handleData == NULL || lastMessageReceiveTime == NULL)
AzureIoTClient 16:deba40344375 700 {
AzureIoTClient 16:deba40344375 701 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 16:deba40344375 702 LOG_ERROR;
AzureIoTClient 16:deba40344375 703 }
AzureIoTClient 16:deba40344375 704 else
AzureIoTClient 16:deba40344375 705 {
AzureIoTClient 16:deba40344375 706 /* Codes_SRS_IOTHUBCLIENT_LL_09_002: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INDEFINITE_TIME - and not set 'lastMessageReceiveTime' - if it is unable to provide the time for the last commands] */
AzureIoTClient 16:deba40344375 707 if (handleData->lastMessageReceiveTime == INDEFINITE_TIME)
AzureIoTClient 16:deba40344375 708 {
AzureIoTClient 16:deba40344375 709 result = IOTHUB_CLIENT_INDEFINITE_TIME;
AzureIoTClient 16:deba40344375 710 LOG_ERROR;
AzureIoTClient 16:deba40344375 711 }
AzureIoTClient 16:deba40344375 712 else
AzureIoTClient 16:deba40344375 713 {
AzureIoTClient 16:deba40344375 714 /* Codes_SRS_IOTHUBCLIENT_LL_09_003: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_OK if it wrote in the lastMessageReceiveTime the time when the last command was received] */
AzureIoTClient 16:deba40344375 715 /* Codes_SRS_IOTHUBCLIENT_LL_09_004: [IoTHubClient_LL_GetLastMessageReceiveTime shall return lastMessageReceiveTime in localtime] */
AzureIoTClient 16:deba40344375 716 *lastMessageReceiveTime = handleData->lastMessageReceiveTime;
AzureIoTClient 16:deba40344375 717 result = IOTHUB_CLIENT_OK;
AzureIoTClient 16:deba40344375 718 }
AzureIoTClient 16:deba40344375 719 }
AzureIoTClient 16:deba40344375 720
AzureIoTClient 16:deba40344375 721 return result;
AzureIoTClient 16:deba40344375 722 }
AzureIoTClient 16:deba40344375 723
AzureIoTClient 16:deba40344375 724 IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetOption(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* optionName, const void* value)
AzureIoTClient 16:deba40344375 725 {
AzureIoTClient 16:deba40344375 726
AzureIoTClient 16:deba40344375 727 IOTHUB_CLIENT_RESULT result;
AzureIoTClient 16:deba40344375 728 /*Codes_SRS_IOTHUBCLIENT_LL_02_034: [If iotHubClientHandle is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.]*/
AzureIoTClient 16:deba40344375 729 /*Codes_SRS_IOTHUBCLIENT_LL_02_035: [If optionName is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 16:deba40344375 730 /*Codes_SRS_IOTHUBCLIENT_LL_02_036: [If value is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */
AzureIoTClient 16:deba40344375 731 if (
AzureIoTClient 16:deba40344375 732 (iotHubClientHandle == NULL) ||
AzureIoTClient 16:deba40344375 733 (optionName == NULL) ||
AzureIoTClient 16:deba40344375 734 (value == NULL)
AzureIoTClient 16:deba40344375 735 )
AzureIoTClient 16:deba40344375 736 {
AzureIoTClient 16:deba40344375 737 result = IOTHUB_CLIENT_INVALID_ARG;
AzureIoTClient 16:deba40344375 738 LogError("invalid argument (NULL)\r\n");
AzureIoTClient 16:deba40344375 739 }
AzureIoTClient 16:deba40344375 740 else
AzureIoTClient 16:deba40344375 741 {
AzureIoTClient 16:deba40344375 742 IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle;
AzureIoTClient 16:deba40344375 743
Azure.IoT Build 36:67300d5a4c1f 744 /*Codes_SRS_IOTHUBCLIENT_LL_02_039: [ "messageTimeout" - once IoTHubClient_LL_SendEventAsync is called the message shall timeout after value miliseconds. Value is a pointer to a uint64. ]*/
Azure.IoT Build 36:67300d5a4c1f 745 if (strcmp(optionName, "messageTimeout") == 0)
Azure.IoT Build 36:67300d5a4c1f 746 {
Azure.IoT Build 36:67300d5a4c1f 747 /*this is an option handled by IoTHubClient_LL*/
Azure.IoT Build 36:67300d5a4c1f 748 /*Codes_SRS_IOTHUBCLIENT_LL_02_043: [ Calling IoTHubClient_LL_SetOption with value set to "0" shall disable the timeout mechanism for all new messages. ]*/
Azure.IoT Build 36:67300d5a4c1f 749 handleData->currentMessageTimeout = *(const uint64_t*)value;
Azure.IoT Build 36:67300d5a4c1f 750 result = IOTHUB_CLIENT_OK;
Azure.IoT Build 36:67300d5a4c1f 751 }
Azure.IoT Build 36:67300d5a4c1f 752 else
Azure.IoT Build 36:67300d5a4c1f 753 {
AzureIoTClient 16:deba40344375 754 /*Codes_SRS_IOTHUBCLIENT_LL_02_038: [Otherwise, IoTHubClient_LL shall call the function _SetOption of the underlying transport and return what that function is returning.] */
AzureIoTClient 16:deba40344375 755 result = handleData->IoTHubTransport_SetOption(handleData->transportHandle, optionName, value);
AzureIoTClient 16:deba40344375 756
AzureIoTClient 16:deba40344375 757 if (result != IOTHUB_CLIENT_OK)
AzureIoTClient 16:deba40344375 758 {
AzureIoTClient 16:deba40344375 759 LogError("underlying transport failed, returned = %s\r\n", ENUM_TO_STRING(IOTHUB_CLIENT_RESULT, result));
AzureIoTClient 16:deba40344375 760 }
Azure.IoT Build 36:67300d5a4c1f 761 }
AzureIoTClient 16:deba40344375 762 }
AzureIoTClient 16:deba40344375 763 return result;
AzureIoTClient 16:deba40344375 764 }