Microsoft Azure IoTHub client libraries
Dependents: sht15_remote_monitoring RobotArmDemo iothub_client_sample_amqp f767zi_mqtt ... more
This library implements the Microsoft Azure IoTHub client library. The code is replicated from https://github.com/Azure/azure-iot-sdks
iothub_client_ll.c@53:1e5a1ca1f274, 2016-11-16 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Wed Nov 16 21:37:53 2016 -0800
- Revision:
- 53:1e5a1ca1f274
- Parent:
- 52:1cc3c6d07cad
- Child:
- 54:6dcad9019a64
1.0.10
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AzureIoTClient | 16:deba40344375 | 1 | // Copyright (c) Microsoft. All rights reserved. |
AzureIoTClient | 16:deba40344375 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
AzureIoTClient | 16:deba40344375 | 3 | |
AzureIoTClient | 16:deba40344375 | 4 | #include <stdlib.h> |
AzureIoTClient | 16:deba40344375 | 5 | #ifdef _CRTDBG_MAP_ALLOC |
AzureIoTClient | 16:deba40344375 | 6 | #include <crtdbg.h> |
AzureIoTClient | 16:deba40344375 | 7 | #endif |
Azure.IoT Build | 38:a05929a75111 | 8 | #include <string.h> |
Azure.IoT Build | 38:a05929a75111 | 9 | #include "azure_c_shared_utility/gballoc.h" |
Azure.IoT Build | 38:a05929a75111 | 10 | #include "azure_c_shared_utility/string_tokenizer.h" |
Azure.IoT Build | 38:a05929a75111 | 11 | #include "azure_c_shared_utility/doublylinkedlist.h" |
Azure.IoT Build | 45:54c11b1b1407 | 12 | #include "azure_c_shared_utility/xlogging.h" |
Azure.IoT Build | 38:a05929a75111 | 13 | #include "azure_c_shared_utility/tickcounter.h" |
AzureIoTClient | 53:1e5a1ca1f274 | 14 | #include "azure_c_shared_utility/constbuffer.h" |
AzureIoTClient | 16:deba40344375 | 15 | |
AzureIoTClient | 16:deba40344375 | 16 | #include "iothub_client_ll.h" |
AzureIoTClient | 16:deba40344375 | 17 | #include "iothub_client_private.h" |
AzureIoTClient | 33:b372b0efcd20 | 18 | #include "iothub_client_version.h" |
Azure.IoT Build | 38:a05929a75111 | 19 | #include "iothub_transport_ll.h" |
AzureIoTClient | 53:1e5a1ca1f274 | 20 | #include <stdint.h> |
AzureIoTClient | 43:038d8511e817 | 21 | |
AzureIoTClient | 44:33dd78697616 | 22 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 23 | #include "iothub_client_ll_uploadtoblob.h" |
AzureIoTClient | 43:038d8511e817 | 24 | #endif |
Azure.IoT Build | 36:67300d5a4c1f | 25 | |
Azure.IoT Build | 45:54c11b1b1407 | 26 | #define LOG_ERROR_RESULT LogError("result = %s", ENUM_TO_STRING(IOTHUB_CLIENT_RESULT, result)); |
AzureIoTClient | 16:deba40344375 | 27 | #define INDEFINITE_TIME ((time_t)(-1)) |
AzureIoTClient | 16:deba40344375 | 28 | |
AzureIoTClient | 16:deba40344375 | 29 | DEFINE_ENUM_STRINGS(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_RESULT_VALUES); |
Azure.IoT Build | 45:54c11b1b1407 | 30 | DEFINE_ENUM_STRINGS(IOTHUB_CLIENT_CONFIRMATION_RESULT, IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES); |
AzureIoTClient | 16:deba40344375 | 31 | |
AzureIoTClient | 16:deba40344375 | 32 | typedef struct IOTHUB_CLIENT_LL_HANDLE_DATA_TAG |
AzureIoTClient | 16:deba40344375 | 33 | { |
AzureIoTClient | 42:448eecc3676e | 34 | DLIST_ENTRY waitingToSend; |
AzureIoTClient | 53:1e5a1ca1f274 | 35 | DLIST_ENTRY iot_msg_queue; |
AzureIoTClient | 53:1e5a1ca1f274 | 36 | DLIST_ENTRY iot_ack_queue; |
AzureIoTClient | 42:448eecc3676e | 37 | TRANSPORT_LL_HANDLE transportHandle; |
AzureIoTClient | 42:448eecc3676e | 38 | bool isSharedTransport; |
AzureIoTClient | 42:448eecc3676e | 39 | IOTHUB_DEVICE_HANDLE deviceHandle; |
AzureIoTClient | 42:448eecc3676e | 40 | TRANSPORT_PROVIDER_FIELDS; |
AzureIoTClient | 42:448eecc3676e | 41 | IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback; |
AzureIoTClient | 42:448eecc3676e | 42 | void* messageUserContextCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 43 | IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK conStatusCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 44 | void* conStatusUserContextCallback; |
AzureIoTClient | 42:448eecc3676e | 45 | time_t lastMessageReceiveTime; |
AzureIoTClient | 42:448eecc3676e | 46 | TICK_COUNTER_HANDLE tickCounter; /*shared tickcounter used to track message timeouts in waitingToSend list*/ |
AzureIoTClient | 42:448eecc3676e | 47 | uint64_t currentMessageTimeout; |
AzureIoTClient | 53:1e5a1ca1f274 | 48 | uint64_t current_device_twin_timeout; |
AzureIoTClient | 53:1e5a1ca1f274 | 49 | IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK deviceTwinCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 50 | void* deviceTwinContextCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 51 | IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC deviceMethodCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 52 | void* deviceMethodUserContextCallback; |
AzureIoTClient | 52:1cc3c6d07cad | 53 | IOTHUB_CLIENT_RETRY_POLICY retryPolicy; |
AzureIoTClient | 53:1e5a1ca1f274 | 54 | size_t retryTimeoutLimitInSeconds; |
AzureIoTClient | 44:33dd78697616 | 55 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 56 | IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE uploadToBlobHandle; |
AzureIoTClient | 43:038d8511e817 | 57 | #endif |
AzureIoTClient | 53:1e5a1ca1f274 | 58 | uint32_t data_msg_id; |
AzureIoTClient | 53:1e5a1ca1f274 | 59 | bool complete_twin_update_encountered; |
AzureIoTClient | 16:deba40344375 | 60 | }IOTHUB_CLIENT_LL_HANDLE_DATA; |
AzureIoTClient | 16:deba40344375 | 61 | |
AzureIoTClient | 16:deba40344375 | 62 | static const char HOSTNAME_TOKEN[] = "HostName"; |
AzureIoTClient | 16:deba40344375 | 63 | static const char DEVICEID_TOKEN[] = "DeviceId"; |
Azure.IoT Build | 45:54c11b1b1407 | 64 | static const char X509_TOKEN[] = "x509"; |
Azure.IoT Build | 45:54c11b1b1407 | 65 | static const char X509_TOKEN_ONLY_ACCEPTABLE_VALUE[] = "true"; |
AzureIoTClient | 16:deba40344375 | 66 | static const char DEVICEKEY_TOKEN[] = "SharedAccessKey"; |
AzureIoTClient | 40:1a94db9139ea | 67 | static const char DEVICESAS_TOKEN[] = "SharedAccessSignature"; |
AzureIoTClient | 16:deba40344375 | 68 | static const char PROTOCOL_GATEWAY_HOST[] = "GatewayHostName"; |
AzureIoTClient | 16:deba40344375 | 69 | |
AzureIoTClient | 53:1e5a1ca1f274 | 70 | static void device_twin_data_destroy(IOTHUB_DEVICE_TWIN* client_item) |
AzureIoTClient | 53:1e5a1ca1f274 | 71 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 72 | CONSTBUFFER_Destroy(client_item->report_data_handle); |
AzureIoTClient | 53:1e5a1ca1f274 | 73 | free(client_item); |
AzureIoTClient | 53:1e5a1ca1f274 | 74 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 75 | |
AzureIoTClient | 53:1e5a1ca1f274 | 76 | static uint32_t get_next_item_id(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData) |
AzureIoTClient | 53:1e5a1ca1f274 | 77 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 78 | if (handleData->data_msg_id+1 >= UINT32_MAX) |
AzureIoTClient | 53:1e5a1ca1f274 | 79 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 80 | handleData->data_msg_id = 1; |
AzureIoTClient | 53:1e5a1ca1f274 | 81 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 82 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 83 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 84 | handleData->data_msg_id++; |
AzureIoTClient | 53:1e5a1ca1f274 | 85 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 86 | return handleData->data_msg_id; |
AzureIoTClient | 53:1e5a1ca1f274 | 87 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 88 | |
AzureIoTClient | 53:1e5a1ca1f274 | 89 | static IOTHUB_DEVICE_TWIN* dev_twin_data_create(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, uint32_t id, const unsigned char* reportedState, size_t size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reportedStateCallback, void* userContextCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 90 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 91 | IOTHUB_DEVICE_TWIN* result = (IOTHUB_DEVICE_TWIN*)malloc(sizeof(IOTHUB_DEVICE_TWIN) ); |
AzureIoTClient | 53:1e5a1ca1f274 | 92 | if (result != NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 93 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 94 | result->report_data_handle = CONSTBUFFER_Create(reportedState, size); |
AzureIoTClient | 53:1e5a1ca1f274 | 95 | if (result->report_data_handle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 96 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 97 | LogError("Failure allocating reported state data"); |
AzureIoTClient | 53:1e5a1ca1f274 | 98 | free(result); |
AzureIoTClient | 53:1e5a1ca1f274 | 99 | result = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 100 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 101 | else if (tickcounter_get_current_ms(handleData->tickCounter, &result->ms_timesOutAfter) != 0) |
AzureIoTClient | 53:1e5a1ca1f274 | 102 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 103 | LogError("Failure getting tickcount info"); |
AzureIoTClient | 53:1e5a1ca1f274 | 104 | CONSTBUFFER_Destroy(result->report_data_handle); |
AzureIoTClient | 53:1e5a1ca1f274 | 105 | free(result); |
AzureIoTClient | 53:1e5a1ca1f274 | 106 | result = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 107 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 108 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 109 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 110 | result->item_id = id; |
AzureIoTClient | 53:1e5a1ca1f274 | 111 | result->ms_timesOutAfter = 0; |
AzureIoTClient | 53:1e5a1ca1f274 | 112 | result->context = userContextCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 113 | result->reported_state_callback = reportedStateCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 114 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 115 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 116 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 117 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 118 | LogError("Failure allocating device twin information"); |
AzureIoTClient | 53:1e5a1ca1f274 | 119 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 120 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 121 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 122 | |
AzureIoTClient | 16:deba40344375 | 123 | IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol) |
AzureIoTClient | 16:deba40344375 | 124 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 125 | IOTHUB_CLIENT_LL_HANDLE result; |
AzureIoTClient | 16:deba40344375 | 126 | |
AzureIoTClient | 42:448eecc3676e | 127 | /*Codes_SRS_IOTHUBCLIENT_LL_05_001: [IoTHubClient_LL_CreateFromConnectionString shall obtain the version string by a call to IoTHubClient_GetVersionString.]*/ |
AzureIoTClient | 42:448eecc3676e | 128 | /*Codes_SRS_IOTHUBCLIENT_LL_05_002: [IoTHubClient_LL_CreateFromConnectionString shall print the version string to standard output.]*/ |
AzureIoTClient | 42:448eecc3676e | 129 | LogInfo("IoT Hub SDK for C, version %s", IoTHubClient_GetVersionString()); |
AzureIoTClient | 16:deba40344375 | 130 | |
AzureIoTClient | 42:448eecc3676e | 131 | /* Codes_SRS_IOTHUBCLIENT_LL_12_003: [IoTHubClient_LL_CreateFromConnectionString shall verify the input parameter and if it is NULL then return NULL] */ |
AzureIoTClient | 42:448eecc3676e | 132 | if (connectionString == NULL) |
AzureIoTClient | 42:448eecc3676e | 133 | { |
AzureIoTClient | 42:448eecc3676e | 134 | LogError("Input parameter is NULL: connectionString"); |
AzureIoTClient | 53:1e5a1ca1f274 | 135 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 136 | } |
AzureIoTClient | 42:448eecc3676e | 137 | else if (protocol == NULL) |
AzureIoTClient | 42:448eecc3676e | 138 | { |
AzureIoTClient | 42:448eecc3676e | 139 | LogError("Input parameter is NULL: protocol"); |
AzureIoTClient | 53:1e5a1ca1f274 | 140 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 141 | } |
AzureIoTClient | 42:448eecc3676e | 142 | else |
AzureIoTClient | 42:448eecc3676e | 143 | { |
AzureIoTClient | 42:448eecc3676e | 144 | /* Codes_SRS_IOTHUBCLIENT_LL_12_004: [IoTHubClient_LL_CreateFromConnectionString shall allocate IOTHUB_CLIENT_CONFIG structure] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 145 | IOTHUB_CLIENT_CONFIG* config = (IOTHUB_CLIENT_CONFIG*) malloc(sizeof(IOTHUB_CLIENT_CONFIG)); |
AzureIoTClient | 42:448eecc3676e | 146 | if (config == NULL) |
AzureIoTClient | 42:448eecc3676e | 147 | { |
AzureIoTClient | 42:448eecc3676e | 148 | /* Codes_SRS_IOTHUBCLIENT_LL_12_012: [If the allocation failed IoTHubClient_LL_CreateFromConnectionString returns NULL] */ |
AzureIoTClient | 42:448eecc3676e | 149 | LogError("Malloc failed"); |
AzureIoTClient | 53:1e5a1ca1f274 | 150 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 151 | } |
AzureIoTClient | 42:448eecc3676e | 152 | else |
AzureIoTClient | 42:448eecc3676e | 153 | { |
AzureIoTClient | 42:448eecc3676e | 154 | STRING_TOKENIZER_HANDLE tokenizer1 = NULL; |
AzureIoTClient | 42:448eecc3676e | 155 | STRING_HANDLE connString = NULL; |
AzureIoTClient | 42:448eecc3676e | 156 | STRING_HANDLE tokenString = NULL; |
AzureIoTClient | 42:448eecc3676e | 157 | STRING_HANDLE valueString = NULL; |
AzureIoTClient | 42:448eecc3676e | 158 | STRING_HANDLE hostNameString = NULL; |
AzureIoTClient | 42:448eecc3676e | 159 | STRING_HANDLE hostSuffixString = NULL; |
AzureIoTClient | 42:448eecc3676e | 160 | STRING_HANDLE deviceIdString = NULL; |
AzureIoTClient | 42:448eecc3676e | 161 | STRING_HANDLE deviceKeyString = NULL; |
AzureIoTClient | 42:448eecc3676e | 162 | STRING_HANDLE deviceSasTokenString = NULL; |
AzureIoTClient | 42:448eecc3676e | 163 | STRING_HANDLE protocolGateway = NULL; |
AzureIoTClient | 16:deba40344375 | 164 | |
AzureIoTClient | 42:448eecc3676e | 165 | config->protocol = protocol; |
AzureIoTClient | 16:deba40344375 | 166 | |
AzureIoTClient | 42:448eecc3676e | 167 | config->iotHubName = NULL; |
AzureIoTClient | 42:448eecc3676e | 168 | config->iotHubSuffix = NULL; |
AzureIoTClient | 42:448eecc3676e | 169 | config->deviceId = NULL; |
AzureIoTClient | 42:448eecc3676e | 170 | config->deviceKey = NULL; |
AzureIoTClient | 42:448eecc3676e | 171 | config->deviceSasToken = NULL; |
AzureIoTClient | 40:1a94db9139ea | 172 | |
AzureIoTClient | 42:448eecc3676e | 173 | /* Codes_SRS_IOTHUBCLIENT_LL_04_002: [If it does not, it shall pass the protocolGatewayHostName NULL.] */ |
AzureIoTClient | 42:448eecc3676e | 174 | config->protocolGatewayHostName = NULL; |
AzureIoTClient | 16:deba40344375 | 175 | |
AzureIoTClient | 42:448eecc3676e | 176 | if ((connString = STRING_construct(connectionString)) == NULL) |
AzureIoTClient | 42:448eecc3676e | 177 | { |
AzureIoTClient | 42:448eecc3676e | 178 | LogError("Error constructing connectiong String"); |
AzureIoTClient | 53:1e5a1ca1f274 | 179 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 180 | } |
AzureIoTClient | 42:448eecc3676e | 181 | else if ((tokenizer1 = STRING_TOKENIZER_create(connString)) == NULL) |
AzureIoTClient | 42:448eecc3676e | 182 | { |
AzureIoTClient | 42:448eecc3676e | 183 | LogError("Error creating Tokenizer"); |
AzureIoTClient | 53:1e5a1ca1f274 | 184 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 185 | } |
AzureIoTClient | 42:448eecc3676e | 186 | else if ((tokenString = STRING_new()) == NULL) |
AzureIoTClient | 42:448eecc3676e | 187 | { |
AzureIoTClient | 42:448eecc3676e | 188 | LogError("Error creating Token String"); |
AzureIoTClient | 53:1e5a1ca1f274 | 189 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 190 | } |
AzureIoTClient | 42:448eecc3676e | 191 | else if ((valueString = STRING_new()) == NULL) |
AzureIoTClient | 42:448eecc3676e | 192 | { |
AzureIoTClient | 42:448eecc3676e | 193 | LogError("Error creating Value String"); |
AzureIoTClient | 53:1e5a1ca1f274 | 194 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 195 | } |
AzureIoTClient | 42:448eecc3676e | 196 | else if ((hostNameString = STRING_new()) == NULL) |
AzureIoTClient | 42:448eecc3676e | 197 | { |
AzureIoTClient | 42:448eecc3676e | 198 | LogError("Error creating HostName String"); |
AzureIoTClient | 53:1e5a1ca1f274 | 199 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 200 | } |
AzureIoTClient | 42:448eecc3676e | 201 | else if ((hostSuffixString = STRING_new()) == NULL) |
AzureIoTClient | 42:448eecc3676e | 202 | { |
AzureIoTClient | 42:448eecc3676e | 203 | LogError("Error creating HostSuffix String"); |
AzureIoTClient | 53:1e5a1ca1f274 | 204 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 205 | } |
AzureIoTClient | 42:448eecc3676e | 206 | /* Codes_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..."] */ |
Azure.IoT Build | 45:54c11b1b1407 | 207 | /* Codes_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, SharedAccessSignature or x509] */ |
AzureIoTClient | 42:448eecc3676e | 208 | else |
AzureIoTClient | 42:448eecc3676e | 209 | { |
Azure.IoT Build | 45:54c11b1b1407 | 210 | int isx509found = 0; |
AzureIoTClient | 42:448eecc3676e | 211 | while ((STRING_TOKENIZER_get_next_token(tokenizer1, tokenString, "=") == 0)) |
AzureIoTClient | 42:448eecc3676e | 212 | { |
AzureIoTClient | 42:448eecc3676e | 213 | if (STRING_TOKENIZER_get_next_token(tokenizer1, valueString, ";") != 0) |
AzureIoTClient | 42:448eecc3676e | 214 | { |
AzureIoTClient | 42:448eecc3676e | 215 | LogError("Tokenizer error"); |
AzureIoTClient | 42:448eecc3676e | 216 | break; |
AzureIoTClient | 42:448eecc3676e | 217 | } |
AzureIoTClient | 42:448eecc3676e | 218 | else |
AzureIoTClient | 42:448eecc3676e | 219 | { |
AzureIoTClient | 42:448eecc3676e | 220 | if (tokenString != NULL) |
AzureIoTClient | 42:448eecc3676e | 221 | { |
AzureIoTClient | 42:448eecc3676e | 222 | /* Codes_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 or deviceSasToken = SharedAccessSignature] */ |
AzureIoTClient | 42:448eecc3676e | 223 | const char* s_token = STRING_c_str(tokenString); |
AzureIoTClient | 42:448eecc3676e | 224 | if (strcmp(s_token, HOSTNAME_TOKEN) == 0) |
AzureIoTClient | 42:448eecc3676e | 225 | { |
AzureIoTClient | 42:448eecc3676e | 226 | /* Codes_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 | 42:448eecc3676e | 227 | STRING_TOKENIZER_HANDLE tokenizer2 = NULL; |
AzureIoTClient | 42:448eecc3676e | 228 | if ((tokenizer2 = STRING_TOKENIZER_create(valueString)) == NULL) |
AzureIoTClient | 42:448eecc3676e | 229 | { |
AzureIoTClient | 42:448eecc3676e | 230 | LogError("Error creating Tokenizer"); |
AzureIoTClient | 42:448eecc3676e | 231 | break; |
AzureIoTClient | 42:448eecc3676e | 232 | } |
AzureIoTClient | 42:448eecc3676e | 233 | else |
AzureIoTClient | 42:448eecc3676e | 234 | { |
AzureIoTClient | 42:448eecc3676e | 235 | /* Codes_SRS_IOTHUBCLIENT_LL_12_015: [If the string split failed, IoTHubClient_LL_CreateFromConnectionString returns NULL ] */ |
AzureIoTClient | 42:448eecc3676e | 236 | if (STRING_TOKENIZER_get_next_token(tokenizer2, hostNameString, ".") != 0) |
AzureIoTClient | 42:448eecc3676e | 237 | { |
AzureIoTClient | 42:448eecc3676e | 238 | LogError("Tokenizer error"); |
AzureIoTClient | 42:448eecc3676e | 239 | STRING_TOKENIZER_destroy(tokenizer2); |
AzureIoTClient | 42:448eecc3676e | 240 | break; |
AzureIoTClient | 42:448eecc3676e | 241 | } |
AzureIoTClient | 42:448eecc3676e | 242 | else |
AzureIoTClient | 42:448eecc3676e | 243 | { |
AzureIoTClient | 42:448eecc3676e | 244 | config->iotHubName = STRING_c_str(hostNameString); |
AzureIoTClient | 42:448eecc3676e | 245 | if (STRING_TOKENIZER_get_next_token(tokenizer2, hostSuffixString, ";") != 0) |
AzureIoTClient | 42:448eecc3676e | 246 | { |
AzureIoTClient | 42:448eecc3676e | 247 | LogError("Tokenizer error"); |
AzureIoTClient | 42:448eecc3676e | 248 | STRING_TOKENIZER_destroy(tokenizer2); |
AzureIoTClient | 42:448eecc3676e | 249 | break; |
AzureIoTClient | 42:448eecc3676e | 250 | } |
AzureIoTClient | 42:448eecc3676e | 251 | else |
AzureIoTClient | 42:448eecc3676e | 252 | { |
AzureIoTClient | 42:448eecc3676e | 253 | config->iotHubSuffix = STRING_c_str(hostSuffixString); |
AzureIoTClient | 42:448eecc3676e | 254 | } |
AzureIoTClient | 42:448eecc3676e | 255 | } |
AzureIoTClient | 42:448eecc3676e | 256 | STRING_TOKENIZER_destroy(tokenizer2); |
AzureIoTClient | 42:448eecc3676e | 257 | } |
AzureIoTClient | 42:448eecc3676e | 258 | } |
AzureIoTClient | 42:448eecc3676e | 259 | else if (strcmp(s_token, DEVICEID_TOKEN) == 0) |
AzureIoTClient | 42:448eecc3676e | 260 | { |
AzureIoTClient | 42:448eecc3676e | 261 | deviceIdString = STRING_clone(valueString); |
AzureIoTClient | 42:448eecc3676e | 262 | if (deviceIdString != NULL) |
AzureIoTClient | 42:448eecc3676e | 263 | { |
AzureIoTClient | 42:448eecc3676e | 264 | config->deviceId = STRING_c_str(deviceIdString); |
AzureIoTClient | 42:448eecc3676e | 265 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 266 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 267 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 268 | LogError("Failure cloning device id string"); |
AzureIoTClient | 53:1e5a1ca1f274 | 269 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 270 | } |
AzureIoTClient | 42:448eecc3676e | 271 | } |
AzureIoTClient | 42:448eecc3676e | 272 | else if (strcmp(s_token, DEVICEKEY_TOKEN) == 0) |
AzureIoTClient | 42:448eecc3676e | 273 | { |
AzureIoTClient | 42:448eecc3676e | 274 | deviceKeyString = STRING_clone(valueString); |
AzureIoTClient | 42:448eecc3676e | 275 | if (deviceKeyString != NULL) |
AzureIoTClient | 42:448eecc3676e | 276 | { |
AzureIoTClient | 42:448eecc3676e | 277 | config->deviceKey = STRING_c_str(deviceKeyString); |
AzureIoTClient | 42:448eecc3676e | 278 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 279 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 280 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 281 | LogError("Failure cloning device key string"); |
AzureIoTClient | 53:1e5a1ca1f274 | 282 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 283 | } |
AzureIoTClient | 42:448eecc3676e | 284 | } |
AzureIoTClient | 42:448eecc3676e | 285 | else if (strcmp(s_token, DEVICESAS_TOKEN) == 0) |
AzureIoTClient | 42:448eecc3676e | 286 | { |
AzureIoTClient | 42:448eecc3676e | 287 | deviceSasTokenString = STRING_clone(valueString); |
AzureIoTClient | 42:448eecc3676e | 288 | if (deviceSasTokenString != NULL) |
AzureIoTClient | 42:448eecc3676e | 289 | { |
AzureIoTClient | 42:448eecc3676e | 290 | config->deviceSasToken = STRING_c_str(deviceSasTokenString); |
AzureIoTClient | 42:448eecc3676e | 291 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 292 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 293 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 294 | LogError("Failure cloning device sasToken string"); |
AzureIoTClient | 53:1e5a1ca1f274 | 295 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 296 | } |
AzureIoTClient | 42:448eecc3676e | 297 | } |
Azure.IoT Build | 45:54c11b1b1407 | 298 | else if (strcmp(s_token, X509_TOKEN) == 0) |
Azure.IoT Build | 45:54c11b1b1407 | 299 | { |
Azure.IoT Build | 45:54c11b1b1407 | 300 | if (strcmp(STRING_c_str(valueString), X509_TOKEN_ONLY_ACCEPTABLE_VALUE) != 0) |
Azure.IoT Build | 45:54c11b1b1407 | 301 | { |
Azure.IoT Build | 45:54c11b1b1407 | 302 | LogError("x509 option has wrong value, the only acceptable one is \"true\""); |
AzureIoTClient | 53:1e5a1ca1f274 | 303 | break; |
Azure.IoT Build | 45:54c11b1b1407 | 304 | } |
Azure.IoT Build | 45:54c11b1b1407 | 305 | else |
Azure.IoT Build | 45:54c11b1b1407 | 306 | { |
Azure.IoT Build | 45:54c11b1b1407 | 307 | isx509found = 1; |
Azure.IoT Build | 45:54c11b1b1407 | 308 | } |
Azure.IoT Build | 45:54c11b1b1407 | 309 | } |
AzureIoTClient | 42:448eecc3676e | 310 | /* 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 | 42:448eecc3676e | 311 | else if (strcmp(s_token, PROTOCOL_GATEWAY_HOST) == 0) |
AzureIoTClient | 42:448eecc3676e | 312 | { |
AzureIoTClient | 42:448eecc3676e | 313 | protocolGateway = STRING_clone(valueString); |
AzureIoTClient | 42:448eecc3676e | 314 | if (protocolGateway != NULL) |
AzureIoTClient | 42:448eecc3676e | 315 | { |
AzureIoTClient | 42:448eecc3676e | 316 | config->protocolGatewayHostName = STRING_c_str(protocolGateway); |
AzureIoTClient | 42:448eecc3676e | 317 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 318 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 319 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 320 | LogError("Failure cloning protocol Gateway Name"); |
AzureIoTClient | 53:1e5a1ca1f274 | 321 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 322 | } |
AzureIoTClient | 42:448eecc3676e | 323 | } |
AzureIoTClient | 42:448eecc3676e | 324 | } |
AzureIoTClient | 42:448eecc3676e | 325 | } |
AzureIoTClient | 42:448eecc3676e | 326 | } |
AzureIoTClient | 42:448eecc3676e | 327 | /* parsing is done - check the result */ |
AzureIoTClient | 42:448eecc3676e | 328 | if (config->iotHubName == NULL) |
AzureIoTClient | 42:448eecc3676e | 329 | { |
AzureIoTClient | 42:448eecc3676e | 330 | LogError("iotHubName is not found"); |
AzureIoTClient | 53:1e5a1ca1f274 | 331 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 332 | } |
AzureIoTClient | 42:448eecc3676e | 333 | else if (config->iotHubSuffix == NULL) |
AzureIoTClient | 42:448eecc3676e | 334 | { |
AzureIoTClient | 42:448eecc3676e | 335 | LogError("iotHubSuffix is not found"); |
AzureIoTClient | 53:1e5a1ca1f274 | 336 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 337 | } |
AzureIoTClient | 42:448eecc3676e | 338 | else if (config->deviceId == NULL) |
AzureIoTClient | 42:448eecc3676e | 339 | { |
AzureIoTClient | 42:448eecc3676e | 340 | LogError("deviceId is not found"); |
AzureIoTClient | 53:1e5a1ca1f274 | 341 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 342 | } |
Azure.IoT Build | 45:54c11b1b1407 | 343 | else if (!( |
Azure.IoT Build | 45:54c11b1b1407 | 344 | ((!isx509found) && (config->deviceSasToken == NULL) ^ (config->deviceKey == NULL)) || |
Azure.IoT Build | 45:54c11b1b1407 | 345 | ((isx509found) && (config->deviceSasToken == NULL) && (config->deviceKey == NULL)) |
Azure.IoT Build | 45:54c11b1b1407 | 346 | )) |
AzureIoTClient | 42:448eecc3676e | 347 | { |
Azure.IoT Build | 45:54c11b1b1407 | 348 | LogError("invalid combination of x509, deviceSasToken and deviceKey"); |
AzureIoTClient | 53:1e5a1ca1f274 | 349 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 350 | } |
AzureIoTClient | 42:448eecc3676e | 351 | else |
AzureIoTClient | 42:448eecc3676e | 352 | { |
AzureIoTClient | 42:448eecc3676e | 353 | /* Codes_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 | 42:448eecc3676e | 354 | |
AzureIoTClient | 42:448eecc3676e | 355 | result = IoTHubClient_LL_Create(config); |
AzureIoTClient | 42:448eecc3676e | 356 | if (result == NULL) |
AzureIoTClient | 42:448eecc3676e | 357 | { |
AzureIoTClient | 42:448eecc3676e | 358 | LogError("IoTHubClient_LL_Create failed"); |
AzureIoTClient | 42:448eecc3676e | 359 | } |
AzureIoTClient | 42:448eecc3676e | 360 | else |
AzureIoTClient | 42:448eecc3676e | 361 | { |
AzureIoTClient | 42:448eecc3676e | 362 | /*return as is*/ |
AzureIoTClient | 42:448eecc3676e | 363 | } |
AzureIoTClient | 42:448eecc3676e | 364 | } |
AzureIoTClient | 42:448eecc3676e | 365 | } |
AzureIoTClient | 42:448eecc3676e | 366 | if (deviceSasTokenString != NULL) |
AzureIoTClient | 42:448eecc3676e | 367 | STRING_delete(deviceSasTokenString); |
AzureIoTClient | 42:448eecc3676e | 368 | if (deviceKeyString != NULL) |
AzureIoTClient | 42:448eecc3676e | 369 | STRING_delete(deviceKeyString); |
AzureIoTClient | 42:448eecc3676e | 370 | if (deviceIdString != NULL) |
AzureIoTClient | 42:448eecc3676e | 371 | STRING_delete(deviceIdString); |
AzureIoTClient | 42:448eecc3676e | 372 | if (hostSuffixString != NULL) |
AzureIoTClient | 42:448eecc3676e | 373 | STRING_delete(hostSuffixString); |
AzureIoTClient | 42:448eecc3676e | 374 | if (hostNameString != NULL) |
AzureIoTClient | 42:448eecc3676e | 375 | STRING_delete(hostNameString); |
AzureIoTClient | 42:448eecc3676e | 376 | if (valueString != NULL) |
AzureIoTClient | 42:448eecc3676e | 377 | STRING_delete(valueString); |
AzureIoTClient | 42:448eecc3676e | 378 | if (tokenString != NULL) |
AzureIoTClient | 42:448eecc3676e | 379 | STRING_delete(tokenString); |
AzureIoTClient | 42:448eecc3676e | 380 | if (connString != NULL) |
AzureIoTClient | 42:448eecc3676e | 381 | STRING_delete(connString); |
AzureIoTClient | 42:448eecc3676e | 382 | if (protocolGateway != NULL) |
AzureIoTClient | 42:448eecc3676e | 383 | STRING_delete(protocolGateway); |
AzureIoTClient | 16:deba40344375 | 384 | |
AzureIoTClient | 42:448eecc3676e | 385 | if (tokenizer1 != NULL) |
AzureIoTClient | 42:448eecc3676e | 386 | STRING_TOKENIZER_destroy(tokenizer1); |
AzureIoTClient | 16:deba40344375 | 387 | |
AzureIoTClient | 42:448eecc3676e | 388 | free(config); |
AzureIoTClient | 42:448eecc3676e | 389 | } |
AzureIoTClient | 42:448eecc3676e | 390 | } |
AzureIoTClient | 42:448eecc3676e | 391 | return result; |
AzureIoTClient | 16:deba40344375 | 392 | } |
AzureIoTClient | 16:deba40344375 | 393 | |
Azure.IoT Build | 36:67300d5a4c1f | 394 | static void setTransportProtocol(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, TRANSPORT_PROVIDER* protocol) |
Azure.IoT Build | 36:67300d5a4c1f | 395 | { |
AzureIoTClient | 43:038d8511e817 | 396 | handleData->IoTHubTransport_GetHostname = protocol->IoTHubTransport_GetHostname; |
AzureIoTClient | 42:448eecc3676e | 397 | handleData->IoTHubTransport_SetOption = protocol->IoTHubTransport_SetOption; |
AzureIoTClient | 42:448eecc3676e | 398 | handleData->IoTHubTransport_Create = protocol->IoTHubTransport_Create; |
AzureIoTClient | 42:448eecc3676e | 399 | handleData->IoTHubTransport_Destroy = protocol->IoTHubTransport_Destroy; |
AzureIoTClient | 42:448eecc3676e | 400 | handleData->IoTHubTransport_Register = protocol->IoTHubTransport_Register; |
AzureIoTClient | 42:448eecc3676e | 401 | handleData->IoTHubTransport_Unregister = protocol->IoTHubTransport_Unregister; |
AzureIoTClient | 42:448eecc3676e | 402 | handleData->IoTHubTransport_Subscribe = protocol->IoTHubTransport_Subscribe; |
AzureIoTClient | 42:448eecc3676e | 403 | handleData->IoTHubTransport_Unsubscribe = protocol->IoTHubTransport_Unsubscribe; |
AzureIoTClient | 42:448eecc3676e | 404 | handleData->IoTHubTransport_DoWork = protocol->IoTHubTransport_DoWork; |
AzureIoTClient | 53:1e5a1ca1f274 | 405 | handleData->IoTHubTransport_SetRetryPolicy = protocol->IoTHubTransport_SetRetryPolicy; |
AzureIoTClient | 42:448eecc3676e | 406 | handleData->IoTHubTransport_GetSendStatus = protocol->IoTHubTransport_GetSendStatus; |
AzureIoTClient | 53:1e5a1ca1f274 | 407 | handleData->IoTHubTransport_ProcessItem = protocol->IoTHubTransport_ProcessItem; |
AzureIoTClient | 53:1e5a1ca1f274 | 408 | handleData->IoTHubTransport_Subscribe_DeviceTwin = protocol->IoTHubTransport_Subscribe_DeviceTwin; |
AzureIoTClient | 53:1e5a1ca1f274 | 409 | handleData->IoTHubTransport_Unsubscribe_DeviceTwin = protocol->IoTHubTransport_Unsubscribe_DeviceTwin; |
AzureIoTClient | 53:1e5a1ca1f274 | 410 | handleData->IoTHubTransport_Subscribe_DeviceMethod = protocol->IoTHubTransport_Subscribe_DeviceMethod; |
AzureIoTClient | 53:1e5a1ca1f274 | 411 | handleData->IoTHubTransport_Unsubscribe_DeviceMethod = protocol->IoTHubTransport_Unsubscribe_DeviceMethod; |
Azure.IoT Build | 36:67300d5a4c1f | 412 | } |
AzureIoTClient | 16:deba40344375 | 413 | |
AzureIoTClient | 16:deba40344375 | 414 | IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_Create(const IOTHUB_CLIENT_CONFIG* config) |
AzureIoTClient | 16:deba40344375 | 415 | { |
AzureIoTClient | 42:448eecc3676e | 416 | IOTHUB_CLIENT_LL_HANDLE result; |
AzureIoTClient | 42:448eecc3676e | 417 | /*Codes_SRS_IOTHUBCLIENT_LL_02_001: [IoTHubClient_LL_Create shall return NULL if config parameter is NULL or protocol field is NULL.]*/ |
AzureIoTClient | 42:448eecc3676e | 418 | if( |
AzureIoTClient | 42:448eecc3676e | 419 | (config == NULL) || |
AzureIoTClient | 42:448eecc3676e | 420 | (config->protocol == NULL) |
AzureIoTClient | 42:448eecc3676e | 421 | ) |
AzureIoTClient | 42:448eecc3676e | 422 | { |
AzureIoTClient | 42:448eecc3676e | 423 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 424 | LogError("invalid configuration (NULL detected)"); |
AzureIoTClient | 42:448eecc3676e | 425 | } |
AzureIoTClient | 42:448eecc3676e | 426 | else |
AzureIoTClient | 42:448eecc3676e | 427 | { |
AzureIoTClient | 42:448eecc3676e | 428 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)malloc(sizeof(IOTHUB_CLIENT_LL_HANDLE_DATA)); |
AzureIoTClient | 42:448eecc3676e | 429 | if (handleData == NULL) |
AzureIoTClient | 42:448eecc3676e | 430 | { |
AzureIoTClient | 42:448eecc3676e | 431 | LogError("malloc failed"); |
AzureIoTClient | 42:448eecc3676e | 432 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 433 | } |
AzureIoTClient | 42:448eecc3676e | 434 | else |
AzureIoTClient | 42:448eecc3676e | 435 | { |
AzureIoTClient | 44:33dd78697616 | 436 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 437 | /*Codes_SRS_IOTHUBCLIENT_LL_02_094: [ IoTHubClient_LL_Create shall create a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE from IOTHUB_CLIENT_CONFIG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 438 | /*Codes_SRS_IOTHUBCLIENT_LL_02_092: [ IoTHubClient_LL_CreateFromConnectionString shall create a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE from IOTHUB_CLIENT_CONFIG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 439 | handleData->uploadToBlobHandle = IoTHubClient_LL_UploadToBlob_Create(config); |
AzureIoTClient | 42:448eecc3676e | 440 | if (handleData->uploadToBlobHandle == NULL) |
AzureIoTClient | 42:448eecc3676e | 441 | { |
AzureIoTClient | 42:448eecc3676e | 442 | /*Codes_SRS_IOTHUBCLIENT_LL_02_093: [ If creating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateFromConnectionString shall fail and return NULL. ]*/ |
AzureIoTClient | 42:448eecc3676e | 443 | /*Codes_SRS_IOTHUBCLIENT_LL_02_095: [ If creating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_Create shall fail and return NULL. ]*/ |
AzureIoTClient | 42:448eecc3676e | 444 | LogError("unable to IoTHubClient_LL_UploadToBlob_Create"); |
AzureIoTClient | 42:448eecc3676e | 445 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 446 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 447 | } |
AzureIoTClient | 42:448eecc3676e | 448 | else |
AzureIoTClient | 43:038d8511e817 | 449 | #endif |
AzureIoTClient | 42:448eecc3676e | 450 | { |
AzureIoTClient | 42:448eecc3676e | 451 | /*Codes_SRS_IOTHUBCLIENT_LL_02_045: [ Otherwise IoTHubClient_LL_Create shall create a new TICK_COUNTER_HANDLE ]*/ |
AzureIoTClient | 42:448eecc3676e | 452 | if ((handleData->tickCounter = tickcounter_create()) == NULL) |
AzureIoTClient | 42:448eecc3676e | 453 | { |
AzureIoTClient | 44:33dd78697616 | 454 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 455 | /*Codes_SRS_IOTHUBCLIENT_LL_02_046: [ If creating the TICK_COUNTER_HANDLE fails then IoTHubClient_LL_Create shall fail and return NULL. ]*/ |
AzureIoTClient | 42:448eecc3676e | 456 | IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle); |
AzureIoTClient | 43:038d8511e817 | 457 | #endif |
AzureIoTClient | 42:448eecc3676e | 458 | LogError("unable to get a tickcounter"); |
AzureIoTClient | 42:448eecc3676e | 459 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 460 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 461 | } |
AzureIoTClient | 42:448eecc3676e | 462 | else |
AzureIoTClient | 42:448eecc3676e | 463 | { |
AzureIoTClient | 42:448eecc3676e | 464 | /*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 | 42:448eecc3676e | 465 | IOTHUBTRANSPORT_CONFIG lowerLayerConfig; |
AzureIoTClient | 42:448eecc3676e | 466 | DList_InitializeListHead(&(handleData->waitingToSend)); |
AzureIoTClient | 53:1e5a1ca1f274 | 467 | DList_InitializeListHead(&(handleData->iot_msg_queue)); |
AzureIoTClient | 53:1e5a1ca1f274 | 468 | DList_InitializeListHead(&(handleData->iot_ack_queue)); |
AzureIoTClient | 42:448eecc3676e | 469 | setTransportProtocol(handleData, (TRANSPORT_PROVIDER*)config->protocol()); |
AzureIoTClient | 42:448eecc3676e | 470 | handleData->messageCallback = NULL; |
AzureIoTClient | 42:448eecc3676e | 471 | handleData->messageUserContextCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 472 | handleData->deviceTwinCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 473 | handleData->deviceTwinContextCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 474 | handleData->deviceMethodCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 475 | handleData->deviceMethodUserContextCallback = NULL; |
AzureIoTClient | 42:448eecc3676e | 476 | handleData->lastMessageReceiveTime = INDEFINITE_TIME; |
AzureIoTClient | 53:1e5a1ca1f274 | 477 | handleData->data_msg_id = 1; |
AzureIoTClient | 53:1e5a1ca1f274 | 478 | handleData->complete_twin_update_encountered = false; |
AzureIoTClient | 53:1e5a1ca1f274 | 479 | handleData->conStatusCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 480 | handleData->conStatusUserContextCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 481 | handleData->lastMessageReceiveTime = INDEFINITE_TIME; |
AzureIoTClient | 53:1e5a1ca1f274 | 482 | |
AzureIoTClient | 42:448eecc3676e | 483 | /*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 | 42:448eecc3676e | 484 | lowerLayerConfig.upperConfig = config; |
AzureIoTClient | 42:448eecc3676e | 485 | lowerLayerConfig.waitingToSend = &(handleData->waitingToSend); |
AzureIoTClient | 42:448eecc3676e | 486 | /*Codes_SRS_IOTHUBCLIENT_LL_02_007: [If the underlaying layer _Create function fails them IoTHubClient_LL_Create shall fail and return NULL.] */ |
AzureIoTClient | 42:448eecc3676e | 487 | if ((handleData->transportHandle = handleData->IoTHubTransport_Create(&lowerLayerConfig)) == NULL) |
AzureIoTClient | 42:448eecc3676e | 488 | { |
AzureIoTClient | 42:448eecc3676e | 489 | LogError("underlying transport failed"); |
AzureIoTClient | 44:33dd78697616 | 490 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 491 | IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle); |
AzureIoTClient | 43:038d8511e817 | 492 | #endif |
AzureIoTClient | 42:448eecc3676e | 493 | tickcounter_destroy(handleData->tickCounter); |
AzureIoTClient | 42:448eecc3676e | 494 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 495 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 496 | } |
AzureIoTClient | 42:448eecc3676e | 497 | else |
AzureIoTClient | 42:448eecc3676e | 498 | { |
AzureIoTClient | 42:448eecc3676e | 499 | IOTHUB_DEVICE_CONFIG deviceConfig; |
AzureIoTClient | 40:1a94db9139ea | 500 | |
AzureIoTClient | 42:448eecc3676e | 501 | deviceConfig.deviceId = config->deviceId; |
AzureIoTClient | 42:448eecc3676e | 502 | deviceConfig.deviceKey = config->deviceKey; |
AzureIoTClient | 42:448eecc3676e | 503 | deviceConfig.deviceSasToken = config->deviceSasToken; |
AzureIoTClient | 40:1a94db9139ea | 504 | |
AzureIoTClient | 42:448eecc3676e | 505 | /*Codes_SRS_IOTHUBCLIENT_LL_17_008: [IoTHubClient_LL_Create shall call the transport _Register function with a populated structure of type IOTHUB_DEVICE_CONFIG and waitingToSend list.] */ |
AzureIoTClient | 42:448eecc3676e | 506 | if ((handleData->deviceHandle = handleData->IoTHubTransport_Register(handleData->transportHandle, &deviceConfig, handleData, &(handleData->waitingToSend))) == NULL) |
AzureIoTClient | 42:448eecc3676e | 507 | { |
AzureIoTClient | 42:448eecc3676e | 508 | /*Codes_SRS_IOTHUBCLIENT_LL_17_009: [If the _Register function fails, this function shall fail and return NULL.]*/ |
AzureIoTClient | 42:448eecc3676e | 509 | LogError("Registering device in transport failed"); |
AzureIoTClient | 42:448eecc3676e | 510 | handleData->IoTHubTransport_Destroy(handleData->transportHandle); |
AzureIoTClient | 44:33dd78697616 | 511 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 512 | IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle); |
AzureIoTClient | 43:038d8511e817 | 513 | #endif |
AzureIoTClient | 42:448eecc3676e | 514 | tickcounter_destroy(handleData->tickCounter); |
AzureIoTClient | 42:448eecc3676e | 515 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 516 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 517 | } |
AzureIoTClient | 42:448eecc3676e | 518 | else |
AzureIoTClient | 42:448eecc3676e | 519 | { |
AzureIoTClient | 42:448eecc3676e | 520 | /*Codes_SRS_IOTHUBCLIENT_LL_02_008: [Otherwise, IoTHubClient_LL_Create shall succeed and return a non-NULL handle.] */ |
AzureIoTClient | 42:448eecc3676e | 521 | handleData->isSharedTransport = false; |
AzureIoTClient | 42:448eecc3676e | 522 | /*Codes_SRS_IOTHUBCLIENT_LL_02_042: [ By default, messages shall not timeout. ]*/ |
AzureIoTClient | 42:448eecc3676e | 523 | handleData->currentMessageTimeout = 0; |
AzureIoTClient | 53:1e5a1ca1f274 | 524 | handleData->current_device_twin_timeout = 0; |
AzureIoTClient | 42:448eecc3676e | 525 | result = handleData; |
AzureIoTClient | 53:1e5a1ca1f274 | 526 | /*Codes_SRS_IOTHUBCLIENT_LL_25_124: [ `IoTHubClient_LL_Create` shall set the default retry policy as Exponential backoff with jitter and if succeed and return a `non-NULL` handle. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 527 | if (IoTHubClient_LL_SetRetryPolicy(handleData, IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER, 0) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 528 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 529 | LogError("Setting default retry policy in transport failed"); |
AzureIoTClient | 53:1e5a1ca1f274 | 530 | IoTHubClient_LL_Destroy(handleData); |
AzureIoTClient | 53:1e5a1ca1f274 | 531 | result = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 532 | } |
AzureIoTClient | 42:448eecc3676e | 533 | } |
AzureIoTClient | 42:448eecc3676e | 534 | } |
AzureIoTClient | 42:448eecc3676e | 535 | } |
AzureIoTClient | 42:448eecc3676e | 536 | } |
AzureIoTClient | 42:448eecc3676e | 537 | } |
AzureIoTClient | 42:448eecc3676e | 538 | } |
AzureIoTClient | 16:deba40344375 | 539 | |
AzureIoTClient | 42:448eecc3676e | 540 | return result; |
AzureIoTClient | 16:deba40344375 | 541 | } |
AzureIoTClient | 16:deba40344375 | 542 | |
Azure.IoT Build | 36:67300d5a4c1f | 543 | IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateWithTransport(const IOTHUB_CLIENT_DEVICE_CONFIG * config) |
Azure.IoT Build | 36:67300d5a4c1f | 544 | { |
AzureIoTClient | 42:448eecc3676e | 545 | IOTHUB_CLIENT_LL_HANDLE result; |
AzureIoTClient | 42:448eecc3676e | 546 | /*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.]*/ |
AzureIoTClient | 42:448eecc3676e | 547 | if ( |
AzureIoTClient | 42:448eecc3676e | 548 | (config == NULL) || |
AzureIoTClient | 42:448eecc3676e | 549 | (config->protocol == NULL) || |
Azure.IoT Build | 45:54c11b1b1407 | 550 | (config->transportHandle == NULL) || |
Azure.IoT Build | 45:54c11b1b1407 | 551 | /*Codes_SRS_IOTHUBCLIENT_LL_02_098: [ IoTHubClient_LL_CreateWithTransport shall fail and return NULL if both config->deviceKey AND config->deviceSasToken are NULL. ]*/ |
Azure.IoT Build | 45:54c11b1b1407 | 552 | ((config->deviceKey == NULL) && (config->deviceSasToken == NULL)) |
AzureIoTClient | 42:448eecc3676e | 553 | ) |
AzureIoTClient | 42:448eecc3676e | 554 | { |
AzureIoTClient | 42:448eecc3676e | 555 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 556 | LogError("invalid configuration (NULL detected)"); |
AzureIoTClient | 42:448eecc3676e | 557 | } |
AzureIoTClient | 42:448eecc3676e | 558 | else |
AzureIoTClient | 42:448eecc3676e | 559 | { |
AzureIoTClient | 42:448eecc3676e | 560 | /*Codes_SRS_IOTHUBCLIENT_LL_17_002: [IoTHubClient_LL_CreateWithTransport shall allocate data for the IOTHUB_CLIENT_LL_HANDLE.]*/ |
AzureIoTClient | 42:448eecc3676e | 561 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)malloc(sizeof(IOTHUB_CLIENT_LL_HANDLE_DATA)); |
AzureIoTClient | 42:448eecc3676e | 562 | if (handleData == NULL) |
AzureIoTClient | 42:448eecc3676e | 563 | { |
AzureIoTClient | 42:448eecc3676e | 564 | /*Codes_SRS_IOTHUBCLIENT_LL_17_003: [If allocation fails, the function shall fail and return NULL.] */ |
AzureIoTClient | 42:448eecc3676e | 565 | LogError("malloc failed"); |
AzureIoTClient | 42:448eecc3676e | 566 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 567 | } |
AzureIoTClient | 42:448eecc3676e | 568 | else |
AzureIoTClient | 42:448eecc3676e | 569 | { |
AzureIoTClient | 43:038d8511e817 | 570 | handleData->transportHandle = config->transportHandle; |
AzureIoTClient | 43:038d8511e817 | 571 | setTransportProtocol(handleData, (TRANSPORT_PROVIDER*)config->protocol()); |
AzureIoTClient | 43:038d8511e817 | 572 | |
AzureIoTClient | 44:33dd78697616 | 573 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 43:038d8511e817 | 574 | const char* hostname = STRING_c_str(handleData->IoTHubTransport_GetHostname(handleData->transportHandle)); |
AzureIoTClient | 43:038d8511e817 | 575 | /*Codes_SRS_IOTHUBCLIENT_LL_02_096: [ IoTHubClient_LL_CreateWithTransport shall create the data structures needed to instantiate a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE. ]*/ |
AzureIoTClient | 43:038d8511e817 | 576 | /*the first '.' says where the iothubname finishes*/ |
AzureIoTClient | 43:038d8511e817 | 577 | const char* whereIsDot = strchr(hostname, '.'); |
AzureIoTClient | 43:038d8511e817 | 578 | if (whereIsDot == NULL) |
AzureIoTClient | 42:448eecc3676e | 579 | { |
AzureIoTClient | 43:038d8511e817 | 580 | /*Codes_SRS_IOTHUBCLIENT_LL_02_097: [ If creating the data structures fails or instantiating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateWithTransport shall fail and return NULL. ]*/ |
AzureIoTClient | 43:038d8511e817 | 581 | LogError("unable to determine the IoTHub name"); |
AzureIoTClient | 42:448eecc3676e | 582 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 583 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 584 | } |
AzureIoTClient | 42:448eecc3676e | 585 | else |
AzureIoTClient | 42:448eecc3676e | 586 | { |
AzureIoTClient | 43:038d8511e817 | 587 | /*Codes_SRS_IOTHUBCLIENT_LL_02_096: [ IoTHubClient_LL_CreateWithTransport shall create the data structures needed to instantiate a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 588 | char* IoTHubName = (char*) malloc(whereIsDot - hostname + 1); |
AzureIoTClient | 43:038d8511e817 | 589 | if (IoTHubName == NULL) |
AzureIoTClient | 42:448eecc3676e | 590 | { |
AzureIoTClient | 43:038d8511e817 | 591 | /*Codes_SRS_IOTHUBCLIENT_LL_02_097: [ If creating the data structures fails or instantiating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateWithTransport shall fail and return NULL. ]*/ |
AzureIoTClient | 43:038d8511e817 | 592 | LogError("unable to malloc"); |
AzureIoTClient | 42:448eecc3676e | 593 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 594 | result = NULL; |
AzureIoTClient | 42:448eecc3676e | 595 | } |
AzureIoTClient | 42:448eecc3676e | 596 | else |
AzureIoTClient | 42:448eecc3676e | 597 | { |
AzureIoTClient | 43:038d8511e817 | 598 | const char* IotHubSuffix = whereIsDot + 1; |
AzureIoTClient | 43:038d8511e817 | 599 | memcpy(IoTHubName, hostname, whereIsDot - hostname); |
AzureIoTClient | 43:038d8511e817 | 600 | IoTHubName[whereIsDot - hostname ] = '\0'; |
AzureIoTClient | 43:038d8511e817 | 601 | |
AzureIoTClient | 43:038d8511e817 | 602 | IOTHUB_CLIENT_CONFIG temp; |
AzureIoTClient | 43:038d8511e817 | 603 | temp.deviceId = config->deviceId; |
AzureIoTClient | 43:038d8511e817 | 604 | temp.deviceKey = config->deviceKey; |
AzureIoTClient | 43:038d8511e817 | 605 | temp.deviceSasToken = config->deviceSasToken; |
AzureIoTClient | 43:038d8511e817 | 606 | temp.iotHubName = IoTHubName; |
AzureIoTClient | 43:038d8511e817 | 607 | temp.iotHubSuffix = IotHubSuffix; |
AzureIoTClient | 43:038d8511e817 | 608 | temp.protocol = NULL; /*irrelevant to IoTHubClient_LL_UploadToBlob*/ |
AzureIoTClient | 43:038d8511e817 | 609 | temp.protocolGatewayHostName = NULL; /*irrelevant to IoTHubClient_LL_UploadToBlob*/ |
AzureIoTClient | 43:038d8511e817 | 610 | |
AzureIoTClient | 43:038d8511e817 | 611 | /*Codes_SRS_IOTHUBCLIENT_LL_02_097: [ If creating the data structures fails or instantiating the IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE fails then IoTHubClient_LL_CreateWithTransport shall fail and return NULL. ]*/ |
AzureIoTClient | 43:038d8511e817 | 612 | handleData->uploadToBlobHandle = IoTHubClient_LL_UploadToBlob_Create(&temp); |
AzureIoTClient | 43:038d8511e817 | 613 | if (handleData->uploadToBlobHandle == NULL) |
AzureIoTClient | 43:038d8511e817 | 614 | { |
AzureIoTClient | 43:038d8511e817 | 615 | /*Codes_SRS_IOTHUBCLIENT_LL_02_096: [ IoTHubClient_LL_CreateWithTransport shall create the data structures needed to instantiate a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE. ]*/ |
AzureIoTClient | 43:038d8511e817 | 616 | LogError("unable to IoTHubClient_LL_UploadToBlob_Create"); |
AzureIoTClient | 43:038d8511e817 | 617 | free(handleData); |
AzureIoTClient | 43:038d8511e817 | 618 | result = NULL; |
AzureIoTClient | 43:038d8511e817 | 619 | } |
AzureIoTClient | 43:038d8511e817 | 620 | else |
AzureIoTClient | 43:038d8511e817 | 621 | #endif |
AzureIoTClient | 43:038d8511e817 | 622 | { |
AzureIoTClient | 43:038d8511e817 | 623 | /*Codes_SRS_IOTHUBCLIENT_LL_02_047: [ IoTHubClient_LL_CreateWithTransport shall create a TICK_COUNTER_HANDLE. ]*/ |
AzureIoTClient | 43:038d8511e817 | 624 | if ((handleData->tickCounter = tickcounter_create()) == NULL) |
AzureIoTClient | 43:038d8511e817 | 625 | { |
AzureIoTClient | 43:038d8511e817 | 626 | /*Codes_SRS_IOTHUBCLIENT_LL_02_048: [ If creating the handle fails, then IoTHubClient_LL_CreateWithTransport shall fail and return NULL ]*/ |
AzureIoTClient | 43:038d8511e817 | 627 | LogError("unable to get a tickcounter"); |
AzureIoTClient | 44:33dd78697616 | 628 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 43:038d8511e817 | 629 | IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle); |
AzureIoTClient | 43:038d8511e817 | 630 | #endif |
AzureIoTClient | 43:038d8511e817 | 631 | free(handleData); |
AzureIoTClient | 43:038d8511e817 | 632 | result = NULL; |
AzureIoTClient | 43:038d8511e817 | 633 | } |
AzureIoTClient | 43:038d8511e817 | 634 | else |
AzureIoTClient | 43:038d8511e817 | 635 | { |
AzureIoTClient | 43:038d8511e817 | 636 | /*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*.]*/ |
AzureIoTClient | 43:038d8511e817 | 637 | DList_InitializeListHead(&(handleData->waitingToSend)); |
AzureIoTClient | 53:1e5a1ca1f274 | 638 | DList_InitializeListHead(&(handleData->iot_msg_queue)); |
AzureIoTClient | 53:1e5a1ca1f274 | 639 | DList_InitializeListHead(&(handleData->iot_ack_queue)); |
AzureIoTClient | 43:038d8511e817 | 640 | handleData->messageCallback = NULL; |
AzureIoTClient | 43:038d8511e817 | 641 | handleData->messageUserContextCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 642 | handleData->deviceTwinCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 643 | handleData->deviceTwinContextCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 644 | handleData->deviceMethodCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 645 | handleData->deviceMethodUserContextCallback = NULL; |
AzureIoTClient | 43:038d8511e817 | 646 | handleData->lastMessageReceiveTime = INDEFINITE_TIME; |
AzureIoTClient | 53:1e5a1ca1f274 | 647 | handleData->data_msg_id = 1; |
AzureIoTClient | 53:1e5a1ca1f274 | 648 | handleData->complete_twin_update_encountered = false; |
AzureIoTClient | 43:038d8511e817 | 649 | |
AzureIoTClient | 43:038d8511e817 | 650 | IOTHUB_DEVICE_CONFIG deviceConfig; |
AzureIoTClient | 43:038d8511e817 | 651 | |
AzureIoTClient | 43:038d8511e817 | 652 | deviceConfig.deviceId = config->deviceId; |
AzureIoTClient | 43:038d8511e817 | 653 | deviceConfig.deviceKey = config->deviceKey; |
AzureIoTClient | 43:038d8511e817 | 654 | deviceConfig.deviceSasToken = config->deviceSasToken; |
AzureIoTClient | 43:038d8511e817 | 655 | |
AzureIoTClient | 43:038d8511e817 | 656 | /*Codes_SRS_IOTHUBCLIENT_LL_17_006: [IoTHubClient_LL_CreateWithTransport shall call the transport _Register function with the IOTHUB_DEVICE_CONFIG populated structure and waitingToSend list.]*/ |
AzureIoTClient | 43:038d8511e817 | 657 | if ((handleData->deviceHandle = handleData->IoTHubTransport_Register(config->transportHandle, &deviceConfig, handleData, &(handleData->waitingToSend))) == NULL) |
AzureIoTClient | 43:038d8511e817 | 658 | { |
AzureIoTClient | 43:038d8511e817 | 659 | /*Codes_SRS_IOTHUBCLIENT_LL_17_007: [If the _Register function fails, this function shall fail and return NULL.]*/ |
AzureIoTClient | 43:038d8511e817 | 660 | LogError("Registering device in transport failed"); |
AzureIoTClient | 44:33dd78697616 | 661 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 43:038d8511e817 | 662 | IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle); |
AzureIoTClient | 43:038d8511e817 | 663 | #endif |
AzureIoTClient | 43:038d8511e817 | 664 | tickcounter_destroy(handleData->tickCounter); |
AzureIoTClient | 43:038d8511e817 | 665 | free(handleData); |
AzureIoTClient | 43:038d8511e817 | 666 | result = NULL; |
AzureIoTClient | 43:038d8511e817 | 667 | } |
AzureIoTClient | 43:038d8511e817 | 668 | else |
AzureIoTClient | 43:038d8511e817 | 669 | { |
AzureIoTClient | 43:038d8511e817 | 670 | /*Codes_SRS_IOTHUBCLIENT_LL_17_005: [IoTHubClient_LL_CreateWithTransport shall save the transport handle and mark this transport as shared.]*/ |
AzureIoTClient | 43:038d8511e817 | 671 | handleData->isSharedTransport = true; |
AzureIoTClient | 43:038d8511e817 | 672 | /*Codes_SRS_IOTHUBCLIENT_LL_02_042: [ By default, messages shall not timeout. ]*/ |
AzureIoTClient | 43:038d8511e817 | 673 | handleData->currentMessageTimeout = 0; |
AzureIoTClient | 53:1e5a1ca1f274 | 674 | handleData->current_device_twin_timeout = 0; |
AzureIoTClient | 43:038d8511e817 | 675 | result = handleData; |
AzureIoTClient | 53:1e5a1ca1f274 | 676 | /*Codes_SRS_IOTHUBCLIENT_LL_25_125: [ `IoTHubClient_LL_CreateWithTransport` shall set the default retry policy as Exponential backoff with jitter and if succeed and return a `non-NULL` handle. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 677 | if (IoTHubClient_LL_SetRetryPolicy(handleData, IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER, 0) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 678 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 679 | LogError("Setting default retry policy in transport failed"); |
AzureIoTClient | 53:1e5a1ca1f274 | 680 | IoTHubClient_LL_Destroy(handleData); |
AzureIoTClient | 53:1e5a1ca1f274 | 681 | result = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 682 | } |
AzureIoTClient | 43:038d8511e817 | 683 | } |
AzureIoTClient | 43:038d8511e817 | 684 | } |
AzureIoTClient | 43:038d8511e817 | 685 | } |
AzureIoTClient | 44:33dd78697616 | 686 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 43:038d8511e817 | 687 | free(IoTHubName); |
AzureIoTClient | 42:448eecc3676e | 688 | } |
AzureIoTClient | 42:448eecc3676e | 689 | } |
AzureIoTClient | 43:038d8511e817 | 690 | #endif |
AzureIoTClient | 42:448eecc3676e | 691 | } |
AzureIoTClient | 42:448eecc3676e | 692 | } |
Azure.IoT Build | 36:67300d5a4c1f | 693 | |
AzureIoTClient | 42:448eecc3676e | 694 | return result; |
Azure.IoT Build | 36:67300d5a4c1f | 695 | } |
Azure.IoT Build | 36:67300d5a4c1f | 696 | |
AzureIoTClient | 16:deba40344375 | 697 | void IoTHubClient_LL_Destroy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle) |
AzureIoTClient | 16:deba40344375 | 698 | { |
AzureIoTClient | 42:448eecc3676e | 699 | /*Codes_SRS_IOTHUBCLIENT_LL_02_009: [IoTHubClient_LL_Destroy shall do nothing if parameter iotHubClientHandle is NULL.]*/ |
AzureIoTClient | 42:448eecc3676e | 700 | if (iotHubClientHandle != NULL) |
AzureIoTClient | 42:448eecc3676e | 701 | { |
AzureIoTClient | 42:448eecc3676e | 702 | PDLIST_ENTRY unsend; |
AzureIoTClient | 42:448eecc3676e | 703 | /*Codes_SRS_IOTHUBCLIENT_LL_17_010: [IoTHubClient_LL_Destroy shall call the underlaying layer's _Unregister function] */ |
AzureIoTClient | 42:448eecc3676e | 704 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 42:448eecc3676e | 705 | handleData->IoTHubTransport_Unregister(handleData->deviceHandle); |
AzureIoTClient | 42:448eecc3676e | 706 | if (handleData->isSharedTransport == false) |
AzureIoTClient | 42:448eecc3676e | 707 | { |
AzureIoTClient | 42:448eecc3676e | 708 | /*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.] */ |
AzureIoTClient | 42:448eecc3676e | 709 | handleData->IoTHubTransport_Destroy(handleData->transportHandle); |
AzureIoTClient | 42:448eecc3676e | 710 | } |
AzureIoTClient | 42:448eecc3676e | 711 | /*if any, remove the items currently not send*/ |
AzureIoTClient | 42:448eecc3676e | 712 | while ((unsend = DList_RemoveHeadList(&(handleData->waitingToSend))) != &(handleData->waitingToSend)) |
AzureIoTClient | 42:448eecc3676e | 713 | { |
AzureIoTClient | 42:448eecc3676e | 714 | IOTHUB_MESSAGE_LIST* temp = containingRecord(unsend, IOTHUB_MESSAGE_LIST, entry); |
AzureIoTClient | 42:448eecc3676e | 715 | /*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 | 42:448eecc3676e | 716 | if (temp->callback != NULL) |
AzureIoTClient | 42:448eecc3676e | 717 | { |
AzureIoTClient | 42:448eecc3676e | 718 | temp->callback(IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY, temp->context); |
AzureIoTClient | 42:448eecc3676e | 719 | } |
AzureIoTClient | 42:448eecc3676e | 720 | IoTHubMessage_Destroy(temp->messageHandle); |
AzureIoTClient | 42:448eecc3676e | 721 | free(temp); |
AzureIoTClient | 42:448eecc3676e | 722 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 723 | |
AzureIoTClient | 53:1e5a1ca1f274 | 724 | /* Codes_SRS_IOTHUBCLIENT_LL_07_007: [ IoTHubClient_LL_Destroy shall iterate the device twin queues and destroy any remaining items. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 725 | while ((unsend = DList_RemoveHeadList(&(handleData->iot_msg_queue))) != &(handleData->iot_msg_queue)) |
AzureIoTClient | 53:1e5a1ca1f274 | 726 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 727 | IOTHUB_DEVICE_TWIN* temp = containingRecord(unsend, IOTHUB_DEVICE_TWIN, entry); |
AzureIoTClient | 53:1e5a1ca1f274 | 728 | device_twin_data_destroy(temp); |
AzureIoTClient | 53:1e5a1ca1f274 | 729 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 730 | while ((unsend = DList_RemoveHeadList(&(handleData->iot_ack_queue))) != &(handleData->iot_ack_queue)) |
AzureIoTClient | 53:1e5a1ca1f274 | 731 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 732 | IOTHUB_DEVICE_TWIN* temp = containingRecord(unsend, IOTHUB_DEVICE_TWIN, entry); |
AzureIoTClient | 53:1e5a1ca1f274 | 733 | device_twin_data_destroy(temp); |
AzureIoTClient | 53:1e5a1ca1f274 | 734 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 735 | |
AzureIoTClient | 42:448eecc3676e | 736 | /*Codes_SRS_IOTHUBCLIENT_LL_17_011: [IoTHubClient_LL_Destroy shall free the resources allocated by IoTHubClient (if any).] */ |
AzureIoTClient | 42:448eecc3676e | 737 | tickcounter_destroy(handleData->tickCounter); |
AzureIoTClient | 44:33dd78697616 | 738 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 739 | IoTHubClient_LL_UploadToBlob_Destroy(handleData->uploadToBlobHandle); |
AzureIoTClient | 43:038d8511e817 | 740 | #endif |
AzureIoTClient | 42:448eecc3676e | 741 | free(handleData); |
AzureIoTClient | 42:448eecc3676e | 742 | } |
AzureIoTClient | 16:deba40344375 | 743 | } |
AzureIoTClient | 16:deba40344375 | 744 | |
Azure.IoT Build | 36:67300d5a4c1f | 745 | /*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 | 746 | /*returns 0 on success, any other value is error*/ |
Azure.IoT Build | 36:67300d5a4c1f | 747 | static int attach_ms_timesOutAfter(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData, IOTHUB_MESSAGE_LIST *newEntry) |
Azure.IoT Build | 36:67300d5a4c1f | 748 | { |
AzureIoTClient | 42:448eecc3676e | 749 | int result; |
AzureIoTClient | 42:448eecc3676e | 750 | /*Codes_SRS_IOTHUBCLIENT_LL_02_043: [ Calling IoTHubClient_LL_SetOption with value set to "0" shall disable the timeout mechanism for all new messages. ]*/ |
AzureIoTClient | 42:448eecc3676e | 751 | if (handleData->currentMessageTimeout == 0) |
AzureIoTClient | 42:448eecc3676e | 752 | { |
AzureIoTClient | 42:448eecc3676e | 753 | newEntry->ms_timesOutAfter = 0; /*do not timeout*/ |
AzureIoTClient | 42:448eecc3676e | 754 | result = 0; |
AzureIoTClient | 42:448eecc3676e | 755 | } |
AzureIoTClient | 42:448eecc3676e | 756 | else |
AzureIoTClient | 42:448eecc3676e | 757 | { |
AzureIoTClient | 42:448eecc3676e | 758 | /*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. ]*/ |
AzureIoTClient | 42:448eecc3676e | 759 | if (tickcounter_get_current_ms(handleData->tickCounter, &newEntry->ms_timesOutAfter) != 0) |
AzureIoTClient | 42:448eecc3676e | 760 | { |
AzureIoTClient | 42:448eecc3676e | 761 | result = __LINE__; |
AzureIoTClient | 42:448eecc3676e | 762 | LogError("unable to get the current relative tickcount"); |
AzureIoTClient | 42:448eecc3676e | 763 | } |
AzureIoTClient | 42:448eecc3676e | 764 | else |
AzureIoTClient | 42:448eecc3676e | 765 | { |
AzureIoTClient | 42:448eecc3676e | 766 | newEntry->ms_timesOutAfter += handleData->currentMessageTimeout; |
AzureIoTClient | 42:448eecc3676e | 767 | result = 0; |
AzureIoTClient | 42:448eecc3676e | 768 | } |
AzureIoTClient | 42:448eecc3676e | 769 | } |
AzureIoTClient | 42:448eecc3676e | 770 | return result; |
Azure.IoT Build | 36:67300d5a4c1f | 771 | } |
Azure.IoT Build | 36:67300d5a4c1f | 772 | |
AzureIoTClient | 16:deba40344375 | 773 | 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 | 774 | { |
AzureIoTClient | 42:448eecc3676e | 775 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 42:448eecc3676e | 776 | /*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 | 42:448eecc3676e | 777 | if ( |
AzureIoTClient | 42:448eecc3676e | 778 | (iotHubClientHandle == NULL) || |
AzureIoTClient | 42:448eecc3676e | 779 | (eventMessageHandle == NULL) || |
AzureIoTClient | 42:448eecc3676e | 780 | /*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 | 42:448eecc3676e | 781 | ((eventConfirmationCallback == NULL) && (userContextCallback != NULL)) |
AzureIoTClient | 42:448eecc3676e | 782 | ) |
AzureIoTClient | 42:448eecc3676e | 783 | { |
AzureIoTClient | 42:448eecc3676e | 784 | result = IOTHUB_CLIENT_INVALID_ARG; |
Azure.IoT Build | 45:54c11b1b1407 | 785 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 786 | } |
AzureIoTClient | 42:448eecc3676e | 787 | else |
AzureIoTClient | 42:448eecc3676e | 788 | { |
AzureIoTClient | 42:448eecc3676e | 789 | IOTHUB_MESSAGE_LIST *newEntry = (IOTHUB_MESSAGE_LIST*)malloc(sizeof(IOTHUB_MESSAGE_LIST)); |
AzureIoTClient | 42:448eecc3676e | 790 | if (newEntry == NULL) |
AzureIoTClient | 42:448eecc3676e | 791 | { |
AzureIoTClient | 42:448eecc3676e | 792 | result = IOTHUB_CLIENT_ERROR; |
Azure.IoT Build | 45:54c11b1b1407 | 793 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 794 | } |
AzureIoTClient | 42:448eecc3676e | 795 | else |
AzureIoTClient | 42:448eecc3676e | 796 | { |
AzureIoTClient | 42:448eecc3676e | 797 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 40:1a94db9139ea | 798 | |
AzureIoTClient | 42:448eecc3676e | 799 | if (attach_ms_timesOutAfter(handleData, newEntry) != 0) |
AzureIoTClient | 42:448eecc3676e | 800 | { |
AzureIoTClient | 42:448eecc3676e | 801 | result = IOTHUB_CLIENT_ERROR; |
Azure.IoT Build | 45:54c11b1b1407 | 802 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 803 | free(newEntry); |
AzureIoTClient | 42:448eecc3676e | 804 | } |
AzureIoTClient | 42:448eecc3676e | 805 | else |
AzureIoTClient | 42:448eecc3676e | 806 | { |
AzureIoTClient | 42:448eecc3676e | 807 | /*Codes_SRS_IOTHUBCLIENT_LL_02_013: [IoTHubClient_SendEventAsync shall add the DLIST waitingToSend a new record cloning the information from eventMessageHandle, eventConfirmationCallback, userContextCallback.]*/ |
AzureIoTClient | 42:448eecc3676e | 808 | if ((newEntry->messageHandle = IoTHubMessage_Clone(eventMessageHandle)) == NULL) |
AzureIoTClient | 42:448eecc3676e | 809 | { |
AzureIoTClient | 42:448eecc3676e | 810 | /*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 | 42:448eecc3676e | 811 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 812 | free(newEntry); |
Azure.IoT Build | 45:54c11b1b1407 | 813 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 814 | } |
AzureIoTClient | 42:448eecc3676e | 815 | else |
AzureIoTClient | 42:448eecc3676e | 816 | { |
AzureIoTClient | 42:448eecc3676e | 817 | /*Codes_SRS_IOTHUBCLIENT_LL_02_013: [IoTHubClient_SendEventAsync shall add the DLIST waitingToSend a new record cloning the information from eventMessageHandle, eventConfirmationCallback, userContextCallback.]*/ |
AzureIoTClient | 42:448eecc3676e | 818 | newEntry->callback = eventConfirmationCallback; |
AzureIoTClient | 42:448eecc3676e | 819 | newEntry->context = userContextCallback; |
AzureIoTClient | 46:6a69294b6119 | 820 | DList_InsertTailList(&(iotHubClientHandle->waitingToSend), &(newEntry->entry)); |
AzureIoTClient | 42:448eecc3676e | 821 | /*Codes_SRS_IOTHUBCLIENT_LL_02_015: [Otherwise IoTHubClient_LL_SendEventAsync shall succeed and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 42:448eecc3676e | 822 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 42:448eecc3676e | 823 | } |
AzureIoTClient | 42:448eecc3676e | 824 | } |
AzureIoTClient | 42:448eecc3676e | 825 | } |
AzureIoTClient | 42:448eecc3676e | 826 | } |
AzureIoTClient | 42:448eecc3676e | 827 | return result; |
AzureIoTClient | 16:deba40344375 | 828 | } |
AzureIoTClient | 16:deba40344375 | 829 | |
AzureIoTClient | 16:deba40344375 | 830 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetMessageCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback) |
AzureIoTClient | 16:deba40344375 | 831 | { |
AzureIoTClient | 42:448eecc3676e | 832 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 42:448eecc3676e | 833 | /*Codes_SRS_IOTHUBCLIENT_LL_02_016: [IoTHubClient_LL_SetMessageCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.] */ |
AzureIoTClient | 42:448eecc3676e | 834 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 42:448eecc3676e | 835 | { |
AzureIoTClient | 42:448eecc3676e | 836 | result = IOTHUB_CLIENT_INVALID_ARG; |
Azure.IoT Build | 45:54c11b1b1407 | 837 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 838 | } |
AzureIoTClient | 42:448eecc3676e | 839 | else |
AzureIoTClient | 42:448eecc3676e | 840 | { |
AzureIoTClient | 42:448eecc3676e | 841 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 42:448eecc3676e | 842 | if (messageCallback == NULL) |
AzureIoTClient | 42:448eecc3676e | 843 | { |
AzureIoTClient | 42:448eecc3676e | 844 | /*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.] */ |
AzureIoTClient | 42:448eecc3676e | 845 | handleData->IoTHubTransport_Unsubscribe(handleData->deviceHandle); |
AzureIoTClient | 42:448eecc3676e | 846 | handleData->messageCallback = NULL; |
AzureIoTClient | 42:448eecc3676e | 847 | handleData->messageUserContextCallback = NULL; |
AzureIoTClient | 42:448eecc3676e | 848 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 42:448eecc3676e | 849 | } |
AzureIoTClient | 42:448eecc3676e | 850 | else |
AzureIoTClient | 42:448eecc3676e | 851 | { |
AzureIoTClient | 42:448eecc3676e | 852 | /*Codes_SRS_IOTHUBCLIENT_LL_02_017: [If parameter messageCallback is non-NULL then IoTHubClient_LL_SetMessageCallback shall call the underlying layer's _Subscribe function.]*/ |
AzureIoTClient | 42:448eecc3676e | 853 | if (handleData->IoTHubTransport_Subscribe(handleData->deviceHandle) == 0) |
AzureIoTClient | 42:448eecc3676e | 854 | { |
AzureIoTClient | 42:448eecc3676e | 855 | handleData->messageCallback = messageCallback; |
AzureIoTClient | 42:448eecc3676e | 856 | handleData->messageUserContextCallback = userContextCallback; |
AzureIoTClient | 42:448eecc3676e | 857 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 42:448eecc3676e | 858 | } |
AzureIoTClient | 42:448eecc3676e | 859 | else |
AzureIoTClient | 42:448eecc3676e | 860 | { |
AzureIoTClient | 42:448eecc3676e | 861 | handleData->messageCallback = NULL; |
AzureIoTClient | 42:448eecc3676e | 862 | handleData->messageUserContextCallback = NULL; |
AzureIoTClient | 42:448eecc3676e | 863 | /*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 | 42:448eecc3676e | 864 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 42:448eecc3676e | 865 | } |
AzureIoTClient | 42:448eecc3676e | 866 | } |
AzureIoTClient | 42:448eecc3676e | 867 | } |
AzureIoTClient | 40:1a94db9139ea | 868 | |
AzureIoTClient | 42:448eecc3676e | 869 | return result; |
AzureIoTClient | 16:deba40344375 | 870 | } |
AzureIoTClient | 16:deba40344375 | 871 | |
Azure.IoT Build | 36:67300d5a4c1f | 872 | static void DoTimeouts(IOTHUB_CLIENT_LL_HANDLE_DATA* handleData) |
Azure.IoT Build | 36:67300d5a4c1f | 873 | { |
AzureIoTClient | 42:448eecc3676e | 874 | uint64_t nowTick; |
AzureIoTClient | 42:448eecc3676e | 875 | if (tickcounter_get_current_ms(handleData->tickCounter, &nowTick) != 0) |
AzureIoTClient | 42:448eecc3676e | 876 | { |
AzureIoTClient | 42:448eecc3676e | 877 | LogError("unable to get the current ms, timeouts will not be processed"); |
AzureIoTClient | 42:448eecc3676e | 878 | } |
AzureIoTClient | 42:448eecc3676e | 879 | else |
AzureIoTClient | 42:448eecc3676e | 880 | { |
AzureIoTClient | 42:448eecc3676e | 881 | DLIST_ENTRY* currentItemInWaitingToSend = handleData->waitingToSend.Flink; |
AzureIoTClient | 42:448eecc3676e | 882 | while (currentItemInWaitingToSend != &(handleData->waitingToSend)) /*while we are not at the end of the list*/ |
AzureIoTClient | 42:448eecc3676e | 883 | { |
AzureIoTClient | 42:448eecc3676e | 884 | IOTHUB_MESSAGE_LIST* fullEntry = containingRecord(currentItemInWaitingToSend, IOTHUB_MESSAGE_LIST, entry); |
AzureIoTClient | 42:448eecc3676e | 885 | /*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. ]*/ |
AzureIoTClient | 42:448eecc3676e | 886 | if ((fullEntry->ms_timesOutAfter != 0) && (fullEntry->ms_timesOutAfter < nowTick)) |
AzureIoTClient | 42:448eecc3676e | 887 | { |
AzureIoTClient | 42:448eecc3676e | 888 | PDLIST_ENTRY theNext = currentItemInWaitingToSend->Flink; /*need to save the next item, because the below operations are destructive*/ |
AzureIoTClient | 42:448eecc3676e | 889 | DList_RemoveEntryList(currentItemInWaitingToSend); |
AzureIoTClient | 42:448eecc3676e | 890 | if (fullEntry->callback != NULL) |
AzureIoTClient | 42:448eecc3676e | 891 | { |
AzureIoTClient | 42:448eecc3676e | 892 | fullEntry->callback(IOTHUB_CLIENT_CONFIRMATION_MESSAGE_TIMEOUT, fullEntry->context); |
AzureIoTClient | 42:448eecc3676e | 893 | } |
AzureIoTClient | 42:448eecc3676e | 894 | IoTHubMessage_Destroy(fullEntry->messageHandle); /*because it has been cloned*/ |
AzureIoTClient | 42:448eecc3676e | 895 | free(fullEntry); |
AzureIoTClient | 42:448eecc3676e | 896 | currentItemInWaitingToSend = theNext; |
AzureIoTClient | 42:448eecc3676e | 897 | } |
AzureIoTClient | 42:448eecc3676e | 898 | else |
AzureIoTClient | 42:448eecc3676e | 899 | { |
AzureIoTClient | 42:448eecc3676e | 900 | currentItemInWaitingToSend = currentItemInWaitingToSend->Flink; |
AzureIoTClient | 42:448eecc3676e | 901 | } |
AzureIoTClient | 42:448eecc3676e | 902 | } |
AzureIoTClient | 42:448eecc3676e | 903 | } |
Azure.IoT Build | 36:67300d5a4c1f | 904 | } |
Azure.IoT Build | 36:67300d5a4c1f | 905 | |
AzureIoTClient | 16:deba40344375 | 906 | void IoTHubClient_LL_DoWork(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle) |
AzureIoTClient | 16:deba40344375 | 907 | { |
AzureIoTClient | 42:448eecc3676e | 908 | /*Codes_SRS_IOTHUBCLIENT_LL_02_020: [If parameter iotHubClientHandle is NULL then IoTHubClient_LL_DoWork shall not perform any action.] */ |
AzureIoTClient | 42:448eecc3676e | 909 | if (iotHubClientHandle != NULL) |
AzureIoTClient | 42:448eecc3676e | 910 | { |
AzureIoTClient | 42:448eecc3676e | 911 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 42:448eecc3676e | 912 | DoTimeouts(handleData); |
AzureIoTClient | 42:448eecc3676e | 913 | |
AzureIoTClient | 53:1e5a1ca1f274 | 914 | /*Codes_SRS_IOTHUBCLIENT_LL_07_008: [ IoTHubClient_LL_DoWork shall iterate the message queue and execute the underlying transports IoTHubTransport_ProcessItem function for each item. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 915 | DLIST_ENTRY* client_item = handleData->iot_msg_queue.Flink; |
AzureIoTClient | 53:1e5a1ca1f274 | 916 | while (client_item != &(handleData->iot_msg_queue)) /*while we are not at the end of the list*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 917 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 918 | PDLIST_ENTRY next_item = client_item->Flink; |
AzureIoTClient | 53:1e5a1ca1f274 | 919 | |
AzureIoTClient | 53:1e5a1ca1f274 | 920 | IOTHUB_DEVICE_TWIN* queue_data = containingRecord(client_item, IOTHUB_DEVICE_TWIN, entry); |
AzureIoTClient | 53:1e5a1ca1f274 | 921 | IOTHUB_IDENTITY_INFO identity_info; |
AzureIoTClient | 53:1e5a1ca1f274 | 922 | identity_info.device_twin = queue_data; |
AzureIoTClient | 53:1e5a1ca1f274 | 923 | IOTHUB_PROCESS_ITEM_RESULT process_results = handleData->IoTHubTransport_ProcessItem(handleData->transportHandle, IOTHUB_TYPE_DEVICE_TWIN, &identity_info); |
AzureIoTClient | 53:1e5a1ca1f274 | 924 | if (process_results == IOTHUB_PROCESS_CONTINUE || process_results == IOTHUB_PROCESS_NOT_CONNECTED) |
AzureIoTClient | 53:1e5a1ca1f274 | 925 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 926 | /*Codes_SRS_IOTHUBCLIENT_LL_07_010: [ If 'IoTHubTransport_ProcessItem' returns IOTHUB_PROCESS_CONTINUE or IOTHUB_PROCESS_NOT_CONNECTED IoTHubClient_LL_DoWork shall continue on to call the underlaying layer's _DoWork function. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 927 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 928 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 929 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 930 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 931 | DList_RemoveEntryList(client_item); |
AzureIoTClient | 53:1e5a1ca1f274 | 932 | if (process_results == IOTHUB_PROCESS_OK) |
AzureIoTClient | 53:1e5a1ca1f274 | 933 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 934 | /*Codes_SRS_IOTHUBCLIENT_LL_07_011: [ If 'IoTHubTransport_ProcessItem' returns IOTHUB_PROCESS_OK IoTHubClient_LL_DoWork shall add the IOTHUB_DEVICE_TWIN to the ack queue. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 935 | DList_InsertTailList(&(iotHubClientHandle->iot_ack_queue), &(queue_data->entry)); |
AzureIoTClient | 53:1e5a1ca1f274 | 936 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 937 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 938 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 939 | /*Codes_SRS_IOTHUBCLIENT_LL_07_012: [ If 'IoTHubTransport_ProcessItem' returns any other value IoTHubClient_LL_DoWork shall destroy the IOTHUB_DEVICE_TWIN item. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 940 | LogError("Failure queue processing item"); |
AzureIoTClient | 53:1e5a1ca1f274 | 941 | device_twin_data_destroy(queue_data); |
AzureIoTClient | 53:1e5a1ca1f274 | 942 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 943 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 944 | // Move along to the next item |
AzureIoTClient | 53:1e5a1ca1f274 | 945 | client_item = next_item; |
AzureIoTClient | 53:1e5a1ca1f274 | 946 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 947 | |
AzureIoTClient | 42:448eecc3676e | 948 | /*Codes_SRS_IOTHUBCLIENT_LL_02_021: [Otherwise, IoTHubClient_LL_DoWork shall invoke the underlaying layer's _DoWork function.]*/ |
AzureIoTClient | 42:448eecc3676e | 949 | handleData->IoTHubTransport_DoWork(handleData->transportHandle, iotHubClientHandle); |
AzureIoTClient | 42:448eecc3676e | 950 | } |
AzureIoTClient | 16:deba40344375 | 951 | } |
AzureIoTClient | 16:deba40344375 | 952 | |
AzureIoTClient | 16:deba40344375 | 953 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetSendStatus(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus) |
AzureIoTClient | 16:deba40344375 | 954 | { |
AzureIoTClient | 42:448eecc3676e | 955 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 16:deba40344375 | 956 | |
AzureIoTClient | 42:448eecc3676e | 957 | /* Codes_SRS_IOTHUBCLIENT_09_007: [IoTHubClient_GetSendStatus shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL parameter] */ |
AzureIoTClient | 42:448eecc3676e | 958 | if (iotHubClientHandle == NULL || iotHubClientStatus == NULL) |
AzureIoTClient | 42:448eecc3676e | 959 | { |
AzureIoTClient | 42:448eecc3676e | 960 | result = IOTHUB_CLIENT_INVALID_ARG; |
Azure.IoT Build | 45:54c11b1b1407 | 961 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 962 | } |
AzureIoTClient | 42:448eecc3676e | 963 | else |
AzureIoTClient | 42:448eecc3676e | 964 | { |
AzureIoTClient | 42:448eecc3676e | 965 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 16:deba40344375 | 966 | |
AzureIoTClient | 42:448eecc3676e | 967 | /* 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 | 42:448eecc3676e | 968 | /* 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] */ |
AzureIoTClient | 42:448eecc3676e | 969 | result = handleData->IoTHubTransport_GetSendStatus(handleData->deviceHandle, iotHubClientStatus); |
AzureIoTClient | 42:448eecc3676e | 970 | } |
AzureIoTClient | 16:deba40344375 | 971 | |
AzureIoTClient | 42:448eecc3676e | 972 | return result; |
AzureIoTClient | 16:deba40344375 | 973 | } |
AzureIoTClient | 16:deba40344375 | 974 | |
Azure.IoT Build | 45:54c11b1b1407 | 975 | void IoTHubClient_LL_SendComplete(IOTHUB_CLIENT_LL_HANDLE handle, PDLIST_ENTRY completed, IOTHUB_CLIENT_CONFIRMATION_RESULT result) |
AzureIoTClient | 16:deba40344375 | 976 | { |
AzureIoTClient | 42:448eecc3676e | 977 | /*Codes_SRS_IOTHUBCLIENT_LL_02_022: [If parameter completed is NULL, or parameter handle is NULL then IoTHubClient_LL_SendBatch shall return.]*/ |
AzureIoTClient | 42:448eecc3676e | 978 | if ( |
AzureIoTClient | 42:448eecc3676e | 979 | (handle == NULL) || |
AzureIoTClient | 42:448eecc3676e | 980 | (completed == NULL) |
AzureIoTClient | 42:448eecc3676e | 981 | ) |
AzureIoTClient | 42:448eecc3676e | 982 | { |
AzureIoTClient | 42:448eecc3676e | 983 | /*"shall return"*/ |
AzureIoTClient | 42:448eecc3676e | 984 | LogError("invalid arg"); |
AzureIoTClient | 42:448eecc3676e | 985 | } |
AzureIoTClient | 42:448eecc3676e | 986 | else |
AzureIoTClient | 42:448eecc3676e | 987 | { |
Azure.IoT Build | 45:54c11b1b1407 | 988 | /*Codes_SRS_IOTHUBCLIENT_LL_02_027: [If parameter result is IOTHUB_CLIENT_CONFIRMATION_ERROR 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.] */ |
Azure.IoT Build | 45:54c11b1b1407 | 989 | /*Codes_SRS_IOTHUBCLIENT_LL_02_025: [If parameter result is IOTHUB_CLIENT_CONFIRMATION_OK 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 | 42:448eecc3676e | 990 | PDLIST_ENTRY oldest; |
AzureIoTClient | 42:448eecc3676e | 991 | while ((oldest = DList_RemoveHeadList(completed)) != completed) |
AzureIoTClient | 42:448eecc3676e | 992 | { |
AzureIoTClient | 42:448eecc3676e | 993 | IOTHUB_MESSAGE_LIST* messageList = (IOTHUB_MESSAGE_LIST*)containingRecord(oldest, IOTHUB_MESSAGE_LIST, entry); |
AzureIoTClient | 42:448eecc3676e | 994 | /*Codes_SRS_IOTHUBCLIENT_LL_02_026: [If any callback is NULL then there shall not be a callback call.]*/ |
AzureIoTClient | 42:448eecc3676e | 995 | if (messageList->callback != NULL) |
AzureIoTClient | 42:448eecc3676e | 996 | { |
Azure.IoT Build | 45:54c11b1b1407 | 997 | messageList->callback(result, messageList->context); |
AzureIoTClient | 42:448eecc3676e | 998 | } |
AzureIoTClient | 42:448eecc3676e | 999 | IoTHubMessage_Destroy(messageList->messageHandle); |
AzureIoTClient | 42:448eecc3676e | 1000 | free(messageList); |
AzureIoTClient | 42:448eecc3676e | 1001 | } |
AzureIoTClient | 42:448eecc3676e | 1002 | } |
AzureIoTClient | 16:deba40344375 | 1003 | } |
AzureIoTClient | 16:deba40344375 | 1004 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1005 | int IoTHubClient_LL_DeviceMethodComplete(IOTHUB_CLIENT_LL_HANDLE handle, const char* method_name, const unsigned char* payLoad, size_t size, BUFFER_HANDLE response) |
AzureIoTClient | 53:1e5a1ca1f274 | 1006 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1007 | int result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1008 | if (handle == NULL || response == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1009 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1010 | /* Codes_SRS_IOTHUBCLIENT_LL_07_017: [ If handle or response is NULL then IoTHubClient_LL_DeviceMethodComplete shall return 500. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1011 | LogError("Invalid argument handle=%p", handle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1012 | result = 500; |
AzureIoTClient | 53:1e5a1ca1f274 | 1013 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1014 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1015 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1016 | /* Codes_SRS_IOTHUBCLIENT_LL_07_018: [ If deviceMethodCallback is not NULL IoTHubClient_LL_DeviceMethodComplete shall execute deviceMethodCallback and return the status. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1017 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1018 | if (handleData->deviceMethodCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 1019 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1020 | unsigned char* payload_resp = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 1021 | size_t resp_size = 0; |
AzureIoTClient | 53:1e5a1ca1f274 | 1022 | result = handleData->deviceMethodCallback(method_name, payLoad, size, &payload_resp, &resp_size, handleData->deviceMethodUserContextCallback); |
AzureIoTClient | 53:1e5a1ca1f274 | 1023 | /* Codes_SRS_IOTHUBCLIENT_LL_07_020: [ deviceMethodCallback shall buil the BUFFER_HANDLE with the response payload from the IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC callback. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1024 | if (payload_resp != NULL && resp_size > 0) |
AzureIoTClient | 53:1e5a1ca1f274 | 1025 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1026 | if (BUFFER_build(response, payload_resp, resp_size) != 0) |
AzureIoTClient | 53:1e5a1ca1f274 | 1027 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1028 | result = 500; |
AzureIoTClient | 53:1e5a1ca1f274 | 1029 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1030 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1031 | if (payload_resp != NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1032 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1033 | free(payload_resp); |
AzureIoTClient | 53:1e5a1ca1f274 | 1034 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1035 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1036 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1037 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1038 | /* Codes_SRS_IOTHUBCLIENT_LL_07_019: [ If deviceMethodCallback is NULL IoTHubClient_LL_DeviceMethodComplete shall return 404. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1039 | result = 404; |
AzureIoTClient | 53:1e5a1ca1f274 | 1040 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1041 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1042 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1043 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1044 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1045 | void IoTHubClient_LL_RetrievePropertyComplete(IOTHUB_CLIENT_LL_HANDLE handle, DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char* payLoad, size_t size) |
AzureIoTClient | 53:1e5a1ca1f274 | 1046 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1047 | if (handle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1048 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1049 | /* Codes_SRS_IOTHUBCLIENT_LL_07_013: [ If handle is NULL then IoTHubClient_LL_RetrievePropertyComplete shall do nothing.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1050 | LogError("Invalid argument handle=%p", handle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1051 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1052 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1053 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1054 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1055 | /* Codes_SRS_IOTHUBCLIENT_LL_07_014: [ If deviceTwinCallback is NULL then IoTHubClient_LL_RetrievePropertyComplete shall do nothing.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1056 | if (handleData->deviceTwinCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 1057 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1058 | /* Codes_SRS_IOTHUBCLIENT_LL_07_015: [ If the the update_state parameter is DEVICE_TWIN_UPDATE_PARTIAL and a DEVICE_TWIN_UPDATE_COMPLETE has not been previously recieved then IoTHubClient_LL_RetrievePropertyComplete shall do nothing.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1059 | if (update_state == DEVICE_TWIN_UPDATE_COMPLETE) |
AzureIoTClient | 53:1e5a1ca1f274 | 1060 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1061 | handleData->complete_twin_update_encountered = true; |
AzureIoTClient | 53:1e5a1ca1f274 | 1062 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1063 | if (handleData->complete_twin_update_encountered) |
AzureIoTClient | 53:1e5a1ca1f274 | 1064 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1065 | /* Codes_SRS_IOTHUBCLIENT_LL_07_016: [ If deviceTwinCallback is set and DEVICE_TWIN_UPDATE_COMPLETE has been encountered then IoTHubClient_LL_RetrievePropertyComplete shall call deviceTwinCallback.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1066 | handleData->deviceTwinCallback(update_state, payLoad, size, handleData->deviceTwinContextCallback); |
AzureIoTClient | 53:1e5a1ca1f274 | 1067 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1068 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1069 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1070 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1071 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1072 | void IoTHubClient_LL_ReportedStateComplete(IOTHUB_CLIENT_LL_HANDLE handle, uint32_t item_id, int status_code) |
AzureIoTClient | 53:1e5a1ca1f274 | 1073 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1074 | /* Codes_SRS_IOTHUBCLIENT_LL_07_002: [ if handle or queue_handle are NULL then IoTHubClient_LL_ReportedStateComplete shall do nothing. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1075 | if (handle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1076 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1077 | /*"shall return"*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1078 | LogError("Invalid argument handle=%p", handle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1079 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1080 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1081 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1082 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1083 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1084 | /* Codes_SRS_IOTHUBCLIENT_LL_07_003: [ IoTHubClient_LL_ReportedStateComplete shall enumerate through the IOTHUB_DEVICE_TWIN structures in queue_handle. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1085 | DLIST_ENTRY* client_item = handleData->iot_ack_queue.Flink; |
AzureIoTClient | 53:1e5a1ca1f274 | 1086 | while (client_item != &(handleData->iot_ack_queue)) /*while we are not at the end of the list*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1087 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1088 | PDLIST_ENTRY next_item = client_item->Flink; |
AzureIoTClient | 53:1e5a1ca1f274 | 1089 | IOTHUB_DEVICE_TWIN* queue_data = containingRecord(client_item, IOTHUB_DEVICE_TWIN, entry); |
AzureIoTClient | 53:1e5a1ca1f274 | 1090 | if (queue_data->item_id == item_id) |
AzureIoTClient | 53:1e5a1ca1f274 | 1091 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1092 | if (queue_data->reported_state_callback != NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1093 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1094 | queue_data->reported_state_callback(status_code, queue_data->context); |
AzureIoTClient | 53:1e5a1ca1f274 | 1095 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1096 | /*Codes_SRS_IOTHUBCLIENT_LL_07_009: [ IoTHubClient_LL_ReportedStateComplete shall remove the IOTHUB_DEVICE_TWIN item from the ack queue.]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1097 | DList_RemoveEntryList(client_item); |
AzureIoTClient | 53:1e5a1ca1f274 | 1098 | device_twin_data_destroy(queue_data); |
AzureIoTClient | 53:1e5a1ca1f274 | 1099 | break; |
AzureIoTClient | 53:1e5a1ca1f274 | 1100 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1101 | client_item = next_item; |
AzureIoTClient | 53:1e5a1ca1f274 | 1102 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1103 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1104 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1105 | |
AzureIoTClient | 16:deba40344375 | 1106 | IOTHUBMESSAGE_DISPOSITION_RESULT IoTHubClient_LL_MessageCallback(IOTHUB_CLIENT_LL_HANDLE handle, IOTHUB_MESSAGE_HANDLE message) |
AzureIoTClient | 16:deba40344375 | 1107 | { |
AzureIoTClient | 42:448eecc3676e | 1108 | int result; |
AzureIoTClient | 42:448eecc3676e | 1109 | /*Codes_SRS_IOTHUBCLIENT_LL_02_029: [If parameter handle is NULL then IoTHubClient_LL_MessageCallback shall return IOTHUBMESSAGE_ABANDONED.] */ |
AzureIoTClient | 42:448eecc3676e | 1110 | if (handle == NULL) |
AzureIoTClient | 42:448eecc3676e | 1111 | { |
AzureIoTClient | 42:448eecc3676e | 1112 | LogError("invalid argument"); |
AzureIoTClient | 42:448eecc3676e | 1113 | result = IOTHUBMESSAGE_ABANDONED; |
AzureIoTClient | 42:448eecc3676e | 1114 | } |
AzureIoTClient | 42:448eecc3676e | 1115 | else |
AzureIoTClient | 42:448eecc3676e | 1116 | { |
AzureIoTClient | 42:448eecc3676e | 1117 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle; |
AzureIoTClient | 16:deba40344375 | 1118 | |
AzureIoTClient | 42:448eecc3676e | 1119 | /* Codes_SRS_IOTHUBCLIENT_LL_09_004: [IoTHubClient_LL_GetLastMessageReceiveTime shall return lastMessageReceiveTime in localtime] */ |
AzureIoTClient | 42:448eecc3676e | 1120 | handleData->lastMessageReceiveTime = get_time(NULL); |
AzureIoTClient | 16:deba40344375 | 1121 | |
AzureIoTClient | 42:448eecc3676e | 1122 | /*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 | 42:448eecc3676e | 1123 | if (handleData->messageCallback != NULL) |
AzureIoTClient | 42:448eecc3676e | 1124 | { |
AzureIoTClient | 42:448eecc3676e | 1125 | result = handleData->messageCallback(message, handleData->messageUserContextCallback); |
AzureIoTClient | 42:448eecc3676e | 1126 | } |
AzureIoTClient | 42:448eecc3676e | 1127 | else |
AzureIoTClient | 42:448eecc3676e | 1128 | { |
AzureIoTClient | 42:448eecc3676e | 1129 | /*Codes_SRS_IOTHUBCLIENT_LL_02_032: [If the last callback function was NULL, then IoTHubClient_LL_MessageCallback shall return IOTHUBMESSAGE_ABANDONED.] */ |
AzureIoTClient | 42:448eecc3676e | 1130 | LogError("user callback was NULL"); |
AzureIoTClient | 42:448eecc3676e | 1131 | result = IOTHUBMESSAGE_ABANDONED; |
AzureIoTClient | 42:448eecc3676e | 1132 | } |
AzureIoTClient | 42:448eecc3676e | 1133 | } |
AzureIoTClient | 42:448eecc3676e | 1134 | /*Codes_SRS_IOTHUBCLIENT_LL_02_031: [Then IoTHubClient_LL_MessageCallback shall return what the user function returns.]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1135 | return (IOTHUBMESSAGE_DISPOSITION_RESULT) result; |
AzureIoTClient | 16:deba40344375 | 1136 | } |
AzureIoTClient | 16:deba40344375 | 1137 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1138 | void IotHubClient_LL_ConnectionStatusCallBack(IOTHUB_CLIENT_LL_HANDLE handle, IOTHUB_CLIENT_CONNECTION_STATUS status, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason) |
AzureIoTClient | 52:1cc3c6d07cad | 1139 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1140 | /*Codes_SRS_IOTHUBCLIENT_LL_25_113: [If parameter connectionStatus is NULL or parameter handle is NULL then IotHubClient_LL_ConnectionStatusCallBack shall return.]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1141 | if (handle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1142 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1143 | /*"shall return"*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1144 | LogError("invalid arg"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1145 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1146 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1147 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1148 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)handle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1149 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1150 | /*Codes_SRS_IOTHUBCLIENT_LL_25_114: [IotHubClient_LL_ConnectionStatusCallBack shall call non-callback set by the user from IoTHubClient_LL_SetConnectionStatusCallback passing the status, reason and the passed userContextCallback.]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1151 | if (handleData->conStatusCallback != NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1152 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1153 | handleData->conStatusCallback(status, reason, handleData->conStatusUserContextCallback); |
AzureIoTClient | 53:1e5a1ca1f274 | 1154 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1155 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1156 | |
AzureIoTClient | 52:1cc3c6d07cad | 1157 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1158 | |
AzureIoTClient | 52:1cc3c6d07cad | 1159 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetConnectionStatusCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK connectionStatusCallback, void * userContextCallback) |
AzureIoTClient | 52:1cc3c6d07cad | 1160 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1161 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1162 | /*Codes_SRS_IOTHUBCLIENT_LL_25_111: [IoTHubClient_LL_SetConnectionStatusCallback shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL parameter iotHubClientHandle**]** */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1163 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1164 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1165 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1166 | LOG_ERROR_RESULT; |
AzureIoTClient | 53:1e5a1ca1f274 | 1167 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1168 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1169 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1170 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1171 | /*Codes_SRS_IOTHUBCLIENT_LL_25_112: [IoTHubClient_LL_SetConnectionStatusCallback shall return IOTHUB_CLIENT_OK and save the callback and userContext as a member of the handle.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1172 | handleData->conStatusCallback = connectionStatusCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 1173 | handleData->conStatusUserContextCallback = userContextCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 1174 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1175 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1176 | |
AzureIoTClient | 52:1cc3c6d07cad | 1177 | return result; |
AzureIoTClient | 52:1cc3c6d07cad | 1178 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1179 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1180 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds) |
AzureIoTClient | 52:1cc3c6d07cad | 1181 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1182 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1183 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 52:1cc3c6d07cad | 1184 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1185 | /* Codes_SRS_IOTHUBCLIENT_LL_25_116: [**IoTHubClient_LL_SetRetryPolicy shall return IOTHUB_CLIENT_INVALID_ARG if called with NULL iotHubClientHandle]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1186 | if (handleData == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1187 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1188 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1189 | LOG_ERROR_RESULT; |
AzureIoTClient | 53:1e5a1ca1f274 | 1190 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1191 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1192 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1193 | if (handleData->transportHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1194 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1195 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1196 | LOG_ERROR_RESULT; |
AzureIoTClient | 53:1e5a1ca1f274 | 1197 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1198 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1199 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1200 | if (handleData->IoTHubTransport_SetRetryPolicy(handleData->transportHandle, retryPolicy, retryTimeoutLimitInSeconds) != 0) |
AzureIoTClient | 53:1e5a1ca1f274 | 1201 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1202 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1203 | LOG_ERROR_RESULT; |
AzureIoTClient | 53:1e5a1ca1f274 | 1204 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1205 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1206 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1207 | /*Codes_SRS_IOTHUBCLIENT_LL_25_118: [**IoTHubClient_LL_SetRetryPolicy shall save connection retry policies specified by the user to retryPolicy in struct IOTHUB_CLIENT_LL_HANDLE_DATA]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1208 | /*Codes_SRS_IOTHUBCLIENT_LL_25_119: [**IoTHubClient_LL_SetRetryPolicy shall save retryTimeoutLimitInSeconds in seconds to retryTimeout in struct IOTHUB_CLIENT_LL_HANDLE_DATA]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1209 | handleData->retryPolicy = retryPolicy; |
AzureIoTClient | 53:1e5a1ca1f274 | 1210 | handleData->retryTimeoutLimitInSeconds = retryTimeoutLimitInSeconds; |
AzureIoTClient | 53:1e5a1ca1f274 | 1211 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1212 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1213 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1214 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1215 | return result; |
AzureIoTClient | 52:1cc3c6d07cad | 1216 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1217 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1218 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY* retryPolicy, size_t* retryTimeoutLimitInSeconds) |
AzureIoTClient | 52:1cc3c6d07cad | 1219 | { |
AzureIoTClient | 52:1cc3c6d07cad | 1220 | IOTHUB_CLIENT_RESULT result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1221 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1222 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1223 | /* Codes_SRS_IOTHUBCLIENT_LL_09_001: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INVALID_ARG if any of the arguments is NULL] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1224 | if (handleData == NULL || retryPolicy == NULL || retryTimeoutLimitInSeconds == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1225 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1226 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1227 | LOG_ERROR_RESULT; |
AzureIoTClient | 53:1e5a1ca1f274 | 1228 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1229 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1230 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1231 | *retryPolicy = handleData->retryPolicy; |
AzureIoTClient | 53:1e5a1ca1f274 | 1232 | *retryTimeoutLimitInSeconds = handleData->retryTimeoutLimitInSeconds; |
AzureIoTClient | 53:1e5a1ca1f274 | 1233 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1234 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1235 | |
AzureIoTClient | 52:1cc3c6d07cad | 1236 | return result; |
AzureIoTClient | 52:1cc3c6d07cad | 1237 | } |
AzureIoTClient | 52:1cc3c6d07cad | 1238 | |
AzureIoTClient | 16:deba40344375 | 1239 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetLastMessageReceiveTime(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime) |
AzureIoTClient | 16:deba40344375 | 1240 | { |
AzureIoTClient | 42:448eecc3676e | 1241 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 42:448eecc3676e | 1242 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 16:deba40344375 | 1243 | |
AzureIoTClient | 42:448eecc3676e | 1244 | /* Codes_SRS_IOTHUBCLIENT_LL_09_001: [IoTHubClient_LL_GetLastMessageReceiveTime shall return IOTHUB_CLIENT_INVALID_ARG if any of the arguments is NULL] */ |
AzureIoTClient | 42:448eecc3676e | 1245 | if (handleData == NULL || lastMessageReceiveTime == NULL) |
AzureIoTClient | 42:448eecc3676e | 1246 | { |
AzureIoTClient | 42:448eecc3676e | 1247 | result = IOTHUB_CLIENT_INVALID_ARG; |
Azure.IoT Build | 45:54c11b1b1407 | 1248 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 1249 | } |
AzureIoTClient | 42:448eecc3676e | 1250 | else |
AzureIoTClient | 42:448eecc3676e | 1251 | { |
AzureIoTClient | 42:448eecc3676e | 1252 | /* 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 | 42:448eecc3676e | 1253 | if (handleData->lastMessageReceiveTime == INDEFINITE_TIME) |
AzureIoTClient | 42:448eecc3676e | 1254 | { |
AzureIoTClient | 42:448eecc3676e | 1255 | result = IOTHUB_CLIENT_INDEFINITE_TIME; |
Azure.IoT Build | 45:54c11b1b1407 | 1256 | LOG_ERROR_RESULT; |
AzureIoTClient | 42:448eecc3676e | 1257 | } |
AzureIoTClient | 42:448eecc3676e | 1258 | else |
AzureIoTClient | 42:448eecc3676e | 1259 | { |
AzureIoTClient | 42:448eecc3676e | 1260 | /* 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 | 42:448eecc3676e | 1261 | /* Codes_SRS_IOTHUBCLIENT_LL_09_004: [IoTHubClient_LL_GetLastMessageReceiveTime shall return lastMessageReceiveTime in localtime] */ |
AzureIoTClient | 42:448eecc3676e | 1262 | *lastMessageReceiveTime = handleData->lastMessageReceiveTime; |
AzureIoTClient | 42:448eecc3676e | 1263 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 42:448eecc3676e | 1264 | } |
AzureIoTClient | 42:448eecc3676e | 1265 | } |
AzureIoTClient | 16:deba40344375 | 1266 | |
AzureIoTClient | 42:448eecc3676e | 1267 | return result; |
AzureIoTClient | 16:deba40344375 | 1268 | } |
AzureIoTClient | 16:deba40344375 | 1269 | |
AzureIoTClient | 16:deba40344375 | 1270 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetOption(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* optionName, const void* value) |
AzureIoTClient | 16:deba40344375 | 1271 | { |
AzureIoTClient | 40:1a94db9139ea | 1272 | |
AzureIoTClient | 42:448eecc3676e | 1273 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 42:448eecc3676e | 1274 | /*Codes_SRS_IOTHUBCLIENT_LL_02_034: [If iotHubClientHandle is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.]*/ |
AzureIoTClient | 42:448eecc3676e | 1275 | /*Codes_SRS_IOTHUBCLIENT_LL_02_035: [If optionName is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */ |
AzureIoTClient | 42:448eecc3676e | 1276 | /*Codes_SRS_IOTHUBCLIENT_LL_02_036: [If value is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */ |
AzureIoTClient | 42:448eecc3676e | 1277 | if ( |
AzureIoTClient | 42:448eecc3676e | 1278 | (iotHubClientHandle == NULL) || |
AzureIoTClient | 42:448eecc3676e | 1279 | (optionName == NULL) || |
AzureIoTClient | 42:448eecc3676e | 1280 | (value == NULL) |
AzureIoTClient | 42:448eecc3676e | 1281 | ) |
AzureIoTClient | 42:448eecc3676e | 1282 | { |
AzureIoTClient | 42:448eecc3676e | 1283 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 42:448eecc3676e | 1284 | LogError("invalid argument (NULL)"); |
AzureIoTClient | 42:448eecc3676e | 1285 | } |
AzureIoTClient | 42:448eecc3676e | 1286 | else |
AzureIoTClient | 42:448eecc3676e | 1287 | { |
AzureIoTClient | 42:448eecc3676e | 1288 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 42:448eecc3676e | 1289 | |
AzureIoTClient | 42:448eecc3676e | 1290 | /*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. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1291 | if (strcmp(optionName, "messageTimeout") == 0) |
AzureIoTClient | 42:448eecc3676e | 1292 | { |
AzureIoTClient | 42:448eecc3676e | 1293 | /*this is an option handled by IoTHubClient_LL*/ |
AzureIoTClient | 42:448eecc3676e | 1294 | /*Codes_SRS_IOTHUBCLIENT_LL_02_043: [ Calling IoTHubClient_LL_SetOption with value set to "0" shall disable the timeout mechanism for all new messages. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1295 | handleData->currentMessageTimeout = *(const uint64_t*)value; |
AzureIoTClient | 42:448eecc3676e | 1296 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 42:448eecc3676e | 1297 | } |
AzureIoTClient | 42:448eecc3676e | 1298 | else |
AzureIoTClient | 42:448eecc3676e | 1299 | { |
AzureIoTClient | 46:6a69294b6119 | 1300 | |
AzureIoTClient | 46:6a69294b6119 | 1301 | /*Codes_SRS_IOTHUBCLIENT_LL_02_099: [ IoTHubClient_LL_SetOption shall return according to the table below ]*/ |
AzureIoTClient | 46:6a69294b6119 | 1302 | IOTHUB_CLIENT_RESULT uploadToBlob_result; |
AzureIoTClient | 46:6a69294b6119 | 1303 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 46:6a69294b6119 | 1304 | uploadToBlob_result = IoTHubClient_LL_UploadToBlob_SetOption(handleData->uploadToBlobHandle, optionName, value); |
AzureIoTClient | 46:6a69294b6119 | 1305 | if(uploadToBlob_result == IOTHUB_CLIENT_ERROR) |
AzureIoTClient | 46:6a69294b6119 | 1306 | { |
AzureIoTClient | 46:6a69294b6119 | 1307 | LogError("unable to IoTHubClient_LL_UploadToBlob_SetOption"); |
AzureIoTClient | 46:6a69294b6119 | 1308 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 46:6a69294b6119 | 1309 | } |
AzureIoTClient | 46:6a69294b6119 | 1310 | #else |
AzureIoTClient | 46:6a69294b6119 | 1311 | uploadToBlob_result = IOTHUB_CLIENT_INVALID_ARG; /*harmless value (IOTHUB_CLIENT_INVALID_ARG)in the case when uploadtoblob is not compiled in, otherwise whatever IoTHubClient_LL_UploadToBlob_SetOption returned*/ |
AzureIoTClient | 46:6a69294b6119 | 1312 | #endif /*DONT_USE_UPLOADTOBLOB*/ |
AzureIoTClient | 16:deba40344375 | 1313 | |
AzureIoTClient | 46:6a69294b6119 | 1314 | |
AzureIoTClient | 46:6a69294b6119 | 1315 | result = |
AzureIoTClient | 46:6a69294b6119 | 1316 | /*based on uploadToBlob_result value this is what happens:*/ |
AzureIoTClient | 46:6a69294b6119 | 1317 | /*IOTHUB_CLIENT_INVALID_ARG always returns what IoTHubTransport_SetOption returns*/ |
AzureIoTClient | 46:6a69294b6119 | 1318 | /*IOTHUB_CLIENT_ERROR always returns IOTHUB_CLIENT_ERROR */ |
AzureIoTClient | 46:6a69294b6119 | 1319 | /*IOTHUB_CLIENT_OK returns OK |
AzureIoTClient | 46:6a69294b6119 | 1320 | IOTHUB_CLIENT_OK if IoTHubTransport_SetOption returns OK or INVALID_ARG |
AzureIoTClient | 46:6a69294b6119 | 1321 | IOTHUB_CLIENT_ERROR if IoTHubTransport_SetOption returns ERROR*/ |
AzureIoTClient | 46:6a69294b6119 | 1322 | |
AzureIoTClient | 46:6a69294b6119 | 1323 | (uploadToBlob_result == IOTHUB_CLIENT_INVALID_ARG) ? handleData->IoTHubTransport_SetOption(handleData->transportHandle, optionName, value) : |
AzureIoTClient | 46:6a69294b6119 | 1324 | (uploadToBlob_result == IOTHUB_CLIENT_ERROR) ? IOTHUB_CLIENT_ERROR : |
AzureIoTClient | 46:6a69294b6119 | 1325 | (handleData->IoTHubTransport_SetOption(handleData->transportHandle, optionName, value) == IOTHUB_CLIENT_ERROR) ? IOTHUB_CLIENT_ERROR : IOTHUB_CLIENT_OK; |
AzureIoTClient | 46:6a69294b6119 | 1326 | |
AzureIoTClient | 47:aaa262b5f898 | 1327 | if (result != IOTHUB_CLIENT_OK) |
AzureIoTClient | 47:aaa262b5f898 | 1328 | { |
AzureIoTClient | 47:aaa262b5f898 | 1329 | LogError("underlying transport failed, returned = %s", ENUM_TO_STRING(IOTHUB_CLIENT_RESULT, result)); |
AzureIoTClient | 42:448eecc3676e | 1330 | } |
AzureIoTClient | 47:aaa262b5f898 | 1331 | } |
AzureIoTClient | 42:448eecc3676e | 1332 | } |
AzureIoTClient | 42:448eecc3676e | 1333 | return result; |
AzureIoTClient | 42:448eecc3676e | 1334 | } |
AzureIoTClient | 16:deba40344375 | 1335 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1336 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetDeviceTwinCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK deviceTwinCallback, void* userContextCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 1337 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1338 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1339 | /* Codes_SRS_IOTHUBCLIENT_LL_10_001: [ IoTHubClient_LL_SetDeviceTwinCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1340 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1341 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1342 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1343 | LogError("Invalid argument specified iothubClientHandle=%p", iotHubClientHandle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1344 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1345 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1346 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1347 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1348 | if (deviceTwinCallback == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1349 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1350 | /* Codes_SRS_IOTHUBCLIENT_LL_10_006: [ If deviceTwinCallback is NULL, then IoTHubClient_LL_SetDeviceTwinCallback shall call the underlying layer's _Unsubscribe function and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1351 | handleData->IoTHubTransport_Unsubscribe_DeviceTwin(handleData->transportHandle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1352 | handleData->deviceTwinCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 1353 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1354 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1355 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1356 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1357 | /* Codes_SRS_IOTHUBCLIENT_LL_10_002: [ If deviceTwinCallback is not NULL, then IoTHubClient_LL_SetDeviceTwinCallback shall call the underlying layer's _Subscribe function.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1358 | if (handleData->IoTHubTransport_Subscribe_DeviceTwin(handleData->transportHandle) == 0) |
AzureIoTClient | 53:1e5a1ca1f274 | 1359 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1360 | handleData->deviceTwinCallback = deviceTwinCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 1361 | handleData->deviceTwinContextCallback = userContextCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 1362 | /* Codes_SRS_IOTHUBCLIENT_LL_10_005: [ Otherwise IoTHubClient_LL_SetDeviceTwinCallback shall succeed and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1363 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1364 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1365 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1366 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1367 | /* Codes_SRS_IOTHUBCLIENT_LL_10_003: [ If the underlying layer's _Subscribe function fails, then IoTHubClient_LL_SetDeviceTwinCallback shall fail and return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1368 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1369 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1370 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1371 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1372 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1373 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1374 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1375 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SendReportedState(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const unsigned char* reportedState, size_t size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reportedStateCallback, void* userContextCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 1376 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1377 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1378 | /* Codes_SRS_IOTHUBCLIENT_LL_10_012: [ IoTHubClient_LL_SendReportedState shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1379 | /* Codes_SRS_IOTHUBCLIENT_LL_10_013: [ IoTHubClient_LL_SendReportedState shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter reportedState is NULL] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1380 | /* Codes_SRS_IOTHUBCLIENT_LL_07_005: [ IoTHubClient_LL_SendReportedState shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter size is equal to 0. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1381 | if (iotHubClientHandle == NULL || (reportedState == NULL || size == 0) ) |
AzureIoTClient | 53:1e5a1ca1f274 | 1382 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1383 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1384 | LogError("Invalid argument specified iothubClientHandle=%p, reportedState=%p, size=%zu", iotHubClientHandle, reportedState, size); |
AzureIoTClient | 53:1e5a1ca1f274 | 1385 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1386 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1387 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1388 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1389 | /* Codes_SRS_IOTHUBCLIENT_LL_10_014: [IoTHubClient_LL_SendReportedState shall construct and queue the reported a Device_Twin structure for transmition by the underlying transport.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1390 | IOTHUB_DEVICE_TWIN* client_data = dev_twin_data_create(handleData, get_next_item_id(handleData), reportedState, size, reportedStateCallback, userContextCallback); |
AzureIoTClient | 53:1e5a1ca1f274 | 1391 | if (client_data == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1392 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1393 | /* Codes_SRS_IOTHUBCLIENT_LL_10_015: [If any error is encountered IoTHubClient_LL_SendReportedState shall return IOTHUB_CLIENT_ERROR.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1394 | LogError("Failure constructing device twin data"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1395 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1396 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1397 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1398 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1399 | if (handleData->IoTHubTransport_Subscribe_DeviceTwin(handleData->transportHandle) != 0) |
AzureIoTClient | 53:1e5a1ca1f274 | 1400 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1401 | LogError("Failure adding device twin data to queue"); |
AzureIoTClient | 53:1e5a1ca1f274 | 1402 | device_twin_data_destroy(client_data); |
AzureIoTClient | 53:1e5a1ca1f274 | 1403 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1404 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1405 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1406 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1407 | /* Codes_SRS_IOTHUBCLIENT_LL_07_001: [ IoTHubClient_LL_SendReportedState shall queue the constructed reportedState data to be consumed by the targeted transport. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1408 | DList_InsertTailList(&(iotHubClientHandle->iot_msg_queue), &(client_data->entry)); |
AzureIoTClient | 53:1e5a1ca1f274 | 1409 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1410 | /* Codes_SRS_IOTHUBCLIENT_LL_10_016: [ Otherwise IoTHubClient_LL_SendReportedState shall succeed and return IOTHUB_CLIENT_OK.] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1411 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1412 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1413 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1414 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1415 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1416 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1417 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1418 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetDeviceMethodCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC deviceMethodCallback, void* userContextCallback) |
AzureIoTClient | 53:1e5a1ca1f274 | 1419 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1420 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1421 | |
AzureIoTClient | 53:1e5a1ca1f274 | 1422 | /*Codes_SRS_IOTHUBCLIENT_LL_12_017: [ IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_INVALID_ARG if parameter iotHubClientHandle is NULL. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1423 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1424 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1425 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 53:1e5a1ca1f274 | 1426 | LOG_ERROR_RESULT; |
AzureIoTClient | 53:1e5a1ca1f274 | 1427 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1428 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1429 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1430 | IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; |
AzureIoTClient | 53:1e5a1ca1f274 | 1431 | if (deviceMethodCallback == NULL) |
AzureIoTClient | 53:1e5a1ca1f274 | 1432 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1433 | /*Codes_SRS_IOTHUBCLIENT_LL_12_018: [If deviceMethodCallback is NULL, then IoTHubClient_LL_SetDeviceMethodCallback shall call the underlying layer's IoTHubTransport_Unsubscribe_DeviceMethod function and return IOTHUB_CLIENT_OK. ] */ |
AzureIoTClient | 53:1e5a1ca1f274 | 1434 | /*Codes_SRS_IOTHUBCLIENT_LL_12_022: [ Otherwise IoTHubClient_LL_SetDeviceMethodCallback shall succeed and return IOTHUB_CLIENT_OK. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1435 | handleData->IoTHubTransport_Unsubscribe_DeviceMethod(handleData->transportHandle); |
AzureIoTClient | 53:1e5a1ca1f274 | 1436 | handleData->deviceMethodCallback = NULL; |
AzureIoTClient | 53:1e5a1ca1f274 | 1437 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1438 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1439 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1440 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1441 | /*Codes_SRS_IOTHUBCLIENT_LL_12_019: [ If deviceMethodCallback is not NULL, then IoTHubClient_LL_SetDeviceMethodCallback shall call the underlying layer's IoTHubTransport_Subscribe_DeviceMethod function. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1442 | if (handleData->IoTHubTransport_Subscribe_DeviceMethod(handleData->deviceHandle) == 0) |
AzureIoTClient | 53:1e5a1ca1f274 | 1443 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1444 | /*Codes_SRS_IOTHUBCLIENT_LL_12_022: [ Otherwise IoTHubClient_LL_SetDeviceMethodCallback shall succeed and return IOTHUB_CLIENT_OK. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1445 | handleData->deviceMethodCallback = deviceMethodCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 1446 | handleData->deviceMethodUserContextCallback = userContextCallback; |
AzureIoTClient | 53:1e5a1ca1f274 | 1447 | result = IOTHUB_CLIENT_OK; |
AzureIoTClient | 53:1e5a1ca1f274 | 1448 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1449 | else |
AzureIoTClient | 53:1e5a1ca1f274 | 1450 | { |
AzureIoTClient | 53:1e5a1ca1f274 | 1451 | /*Codes_SRS_IOTHUBCLIENT_LL_12_020: [ If the underlying layer's IoTHubTransport_Subscribe_DeviceMethod function fails, then IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1452 | /*Codes_SRS_IOTHUBCLIENT_LL_12_021: [ If adding the information fails for any reason, IoTHubClient_LL_SetDeviceMethodCallback shall fail and return IOTHUB_CLIENT_ERROR. ]*/ |
AzureIoTClient | 53:1e5a1ca1f274 | 1453 | result = IOTHUB_CLIENT_ERROR; |
AzureIoTClient | 53:1e5a1ca1f274 | 1454 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1455 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1456 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1457 | return result; |
AzureIoTClient | 53:1e5a1ca1f274 | 1458 | } |
AzureIoTClient | 53:1e5a1ca1f274 | 1459 | |
AzureIoTClient | 44:33dd78697616 | 1460 | #ifndef DONT_USE_UPLOADTOBLOB |
AzureIoTClient | 42:448eecc3676e | 1461 | IOTHUB_CLIENT_RESULT IoTHubClient_LL_UploadToBlob(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* destinationFileName, const unsigned char* source, size_t size) |
AzureIoTClient | 42:448eecc3676e | 1462 | { |
AzureIoTClient | 42:448eecc3676e | 1463 | IOTHUB_CLIENT_RESULT result; |
AzureIoTClient | 42:448eecc3676e | 1464 | /*Codes_SRS_IOTHUBCLIENT_LL_02_061: [ If iotHubClientHandle is NULL then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1465 | /*Codes_SRS_IOTHUBCLIENT_LL_02_062: [ If destinationFileName is NULL then IoTHubClient_LL_UploadToBlob shall fail and return IOTHUB_CLIENT_INVALID_ARG. ]*/ |
AzureIoTClient | 42:448eecc3676e | 1466 | if ( |
AzureIoTClient | 42:448eecc3676e | 1467 | (iotHubClientHandle == NULL) || |
AzureIoTClient | 42:448eecc3676e | 1468 | (destinationFileName == NULL) || |
AzureIoTClient | 42:448eecc3676e | 1469 | ((source == NULL) && (size >0)) |
AzureIoTClient | 42:448eecc3676e | 1470 | ) |
AzureIoTClient | 42:448eecc3676e | 1471 | { |
AzureIoTClient | 42:448eecc3676e | 1472 | LogError("invalid parameters IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle=%p, const char* destinationFileName=%s, const unsigned char* source=%p, size_t size=%zu", iotHubClientHandle, destinationFileName, source, size); |
AzureIoTClient | 42:448eecc3676e | 1473 | result = IOTHUB_CLIENT_INVALID_ARG; |
AzureIoTClient | 42:448eecc3676e | 1474 | } |
AzureIoTClient | 42:448eecc3676e | 1475 | else |
AzureIoTClient | 42:448eecc3676e | 1476 | { |
AzureIoTClient | 42:448eecc3676e | 1477 | result = IoTHubClient_LL_UploadToBlob_Impl(iotHubClientHandle->uploadToBlobHandle, destinationFileName, source, size); |
AzureIoTClient | 42:448eecc3676e | 1478 | } |
AzureIoTClient | 42:448eecc3676e | 1479 | return result; |
AzureIoTClient | 16:deba40344375 | 1480 | } |
AzureIoTClient | 43:038d8511e817 | 1481 | #endif |