Microsoft Azure IoTHub client libraries

Dependents:   sht15_remote_monitoring RobotArmDemo iothub_client_sample_amqp f767zi_mqtt ... more

This library implements the Microsoft Azure IoTHub client library. The code is replicated from https://github.com/Azure/azure-iot-sdks

Committer:
AzureIoTClient
Date:
Thu Oct 20 17:07:32 2016 -0700
Revision:
52:1cc3c6d07cad
Parent:
48:cc5d91f2b06d
Child:
53:1e5a1ca1f274
1.0.10

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 16:deba40344375 1 // Copyright (c) Microsoft. All rights reserved.
AzureIoTClient 16:deba40344375 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
AzureIoTClient 16:deba40344375 3
AzureIoTClient 16:deba40344375 4 /** @file iothub_client_ll.h
AzureIoTClient 16:deba40344375 5 * @brief APIs that allow a user (usually a device) to communicate
AzureIoTClient 16:deba40344375 6 * with an Azure IoTHub.
AzureIoTClient 16:deba40344375 7 *
AzureIoTClient 16:deba40344375 8 * @details IoTHubClient_LL is a module that allows a user (usually a
AzureIoTClient 16:deba40344375 9 * device) to communicate with an Azure IoTHub. It can send events
AzureIoTClient 16:deba40344375 10 * and receive messages. At any given moment in time there can only
AzureIoTClient 16:deba40344375 11 * be at most 1 message callback function.
AzureIoTClient 40:1a94db9139ea 12 *
AzureIoTClient 16:deba40344375 13 * This API surface contains a set of APIs that allows the user to
AzureIoTClient 16:deba40344375 14 * interact with the lower layer portion of the IoTHubClient. These APIs
AzureIoTClient 16:deba40344375 15 * contain @c _LL_ in their name, but retain the same functionality like the
AzureIoTClient 16:deba40344375 16 * @c IoTHubClient_... APIs, with one difference. If the @c _LL_ APIs are
AzureIoTClient 16:deba40344375 17 * used then the user is responsible for scheduling when the actual work done
AzureIoTClient 16:deba40344375 18 * by the IoTHubClient happens (when the data is sent/received on/from the wire).
AzureIoTClient 16:deba40344375 19 * This is useful for constrained devices where spinning a separate thread is
AzureIoTClient 16:deba40344375 20 * often not desired.
AzureIoTClient 16:deba40344375 21 */
AzureIoTClient 16:deba40344375 22
AzureIoTClient 16:deba40344375 23 #ifndef IOTHUB_CLIENT_LL_H
AzureIoTClient 16:deba40344375 24 #define IOTHUB_CLIENT_LL_H
AzureIoTClient 16:deba40344375 25
Azure.IoT Build 38:a05929a75111 26 #include "azure_c_shared_utility/macro_utils.h"
AzureIoTClient 16:deba40344375 27
AzureIoTClient 16:deba40344375 28 #define IOTHUB_CLIENT_RESULT_VALUES \
AzureIoTClient 16:deba40344375 29 IOTHUB_CLIENT_OK, \
AzureIoTClient 16:deba40344375 30 IOTHUB_CLIENT_INVALID_ARG, \
AzureIoTClient 16:deba40344375 31 IOTHUB_CLIENT_ERROR, \
AzureIoTClient 16:deba40344375 32 IOTHUB_CLIENT_INVALID_SIZE, \
AzureIoTClient 16:deba40344375 33 IOTHUB_CLIENT_INDEFINITE_TIME \
AzureIoTClient 16:deba40344375 34
AzureIoTClient 43:038d8511e817 35 /** @brief Enumeration specifying the status of calls to various APIs in this module.
AzureIoTClient 43:038d8511e817 36 */
AzureIoTClient 43:038d8511e817 37
AzureIoTClient 43:038d8511e817 38 DEFINE_ENUM(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_RESULT_VALUES);
AzureIoTClient 43:038d8511e817 39
AzureIoTClient 48:cc5d91f2b06d 40 struct IOTHUBTRANSPORT_CONFIG_TAG;
AzureIoTClient 43:038d8511e817 41 typedef struct IOTHUBTRANSPORT_CONFIG_TAG IOTHUBTRANSPORT_CONFIG;
AzureIoTClient 43:038d8511e817 42
AzureIoTClient 43:038d8511e817 43 typedef struct IOTHUB_CLIENT_LL_HANDLE_DATA_TAG* IOTHUB_CLIENT_LL_HANDLE;
AzureIoTClient 43:038d8511e817 44
AzureIoTClient 43:038d8511e817 45 #define IOTHUB_CLIENT_STATUS_VALUES \
AzureIoTClient 43:038d8511e817 46 IOTHUB_CLIENT_SEND_STATUS_IDLE, \
AzureIoTClient 43:038d8511e817 47 IOTHUB_CLIENT_SEND_STATUS_BUSY \
AzureIoTClient 43:038d8511e817 48
AzureIoTClient 43:038d8511e817 49 /** @brief Enumeration returned by the ::IoTHubClient_LL_GetSendStatus
AzureIoTClient 43:038d8511e817 50 * API to indicate the current sending status of the IoT Hub client.
AzureIoTClient 43:038d8511e817 51 */
AzureIoTClient 43:038d8511e817 52 DEFINE_ENUM(IOTHUB_CLIENT_STATUS, IOTHUB_CLIENT_STATUS_VALUES);
AzureIoTClient 43:038d8511e817 53
AzureIoTClient 43:038d8511e817 54 #include "azure_c_shared_utility/agenttime.h"
AzureIoTClient 43:038d8511e817 55 #include "azure_c_shared_utility/xio.h"
AzureIoTClient 43:038d8511e817 56 #include "azure_c_shared_utility/doublylinkedlist.h"
AzureIoTClient 43:038d8511e817 57 #include "iothub_message.h"
AzureIoTClient 43:038d8511e817 58 #include "iothub_transport_ll.h"
AzureIoTClient 43:038d8511e817 59
AzureIoTClient 43:038d8511e817 60 #ifdef __cplusplus
AzureIoTClient 43:038d8511e817 61 extern "C"
AzureIoTClient 43:038d8511e817 62 {
AzureIoTClient 43:038d8511e817 63 #endif
AzureIoTClient 16:deba40344375 64
AzureIoTClient 16:deba40344375 65 #define IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES \
AzureIoTClient 16:deba40344375 66 IOTHUB_CLIENT_CONFIRMATION_OK, \
AzureIoTClient 16:deba40344375 67 IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY, \
Azure.IoT Build 36:67300d5a4c1f 68 IOTHUB_CLIENT_CONFIRMATION_MESSAGE_TIMEOUT, \
AzureIoTClient 16:deba40344375 69 IOTHUB_CLIENT_CONFIRMATION_ERROR \
AzureIoTClient 16:deba40344375 70
AzureIoTClient 40:1a94db9139ea 71 /** @brief Enumeration passed in by the IoT Hub when the event confirmation
AzureIoTClient 40:1a94db9139ea 72 * callback is invoked to indicate status of the event processing in
AzureIoTClient 40:1a94db9139ea 73 * the hub.
AzureIoTClient 40:1a94db9139ea 74 */
AzureIoTClient 40:1a94db9139ea 75 DEFINE_ENUM(IOTHUB_CLIENT_CONFIRMATION_RESULT, IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES);
AzureIoTClient 16:deba40344375 76
AzureIoTClient 52:1cc3c6d07cad 77 #define IOTHUB_CLIENT_CONNECTION_STATUS_VALUES \
AzureIoTClient 52:1cc3c6d07cad 78 IOTHUB_CLIENT_CONNECTION_INPROGRESS, \
AzureIoTClient 52:1cc3c6d07cad 79 IOTHUB_CLIENT_CONNECTION_SUCCESS, \
AzureIoTClient 52:1cc3c6d07cad 80 IOTHUB_CLIENT_CONNECTION_DISCONNECTED, \
AzureIoTClient 52:1cc3c6d07cad 81 IOTHUB_CLIENT_CONNECTION_RETRY, \
AzureIoTClient 52:1cc3c6d07cad 82 IOTHUB_CLIENT_CONNECTION_RETRY_TIMEOUT, \
AzureIoTClient 52:1cc3c6d07cad 83 IOTHUB_CLIENT_CONNECTION_RECOVERABLE_ERROR, \
AzureIoTClient 52:1cc3c6d07cad 84 IOTHUB_CLIENT_CONNECTION_UNRECOVERABLE_ERROR \
AzureIoTClient 52:1cc3c6d07cad 85
AzureIoTClient 52:1cc3c6d07cad 86 /** @brief Enumeration passed in by the IoT Hub when the connection status
AzureIoTClient 52:1cc3c6d07cad 87 * callback is invoked to indicate status of the connection in
AzureIoTClient 52:1cc3c6d07cad 88 * the hub.
AzureIoTClient 52:1cc3c6d07cad 89 */
AzureIoTClient 52:1cc3c6d07cad 90 DEFINE_ENUM(IOTHUB_CLIENT_CONNECTION_STATUS, IOTHUB_CLIENT_CONNECTION_STATUS_VALUES);
AzureIoTClient 52:1cc3c6d07cad 91
AzureIoTClient 52:1cc3c6d07cad 92 #define IOTHUB_CLIENT_CONNECTION_STATUS_REASON_VALUES \
AzureIoTClient 52:1cc3c6d07cad 93 IOTHUB_CLIENT_CONNECTION_UNRECOVERABLE_SERVER_AUTHENTICATION_ERROR, \
AzureIoTClient 52:1cc3c6d07cad 94 IOTHUB_CLIENT_CONNECTION_UNRECOVERABLE_SERVER_QUOTA_EXCEEDED, \
AzureIoTClient 52:1cc3c6d07cad 95 IOTHUB_CLIENT_CONNECTION_USER_REQUEST, \
AzureIoTClient 52:1cc3c6d07cad 96 IOTHUB_CLIENT_CONNECTION_OK \
AzureIoTClient 52:1cc3c6d07cad 97
AzureIoTClient 52:1cc3c6d07cad 98 /** @brief Enumeration passed in by the IoT Hub when the connection status
AzureIoTClient 52:1cc3c6d07cad 99 * callback is invoked to indicate status of the connection in
AzureIoTClient 52:1cc3c6d07cad 100 * the hub.
AzureIoTClient 52:1cc3c6d07cad 101 */
AzureIoTClient 52:1cc3c6d07cad 102 DEFINE_ENUM(IOTHUB_CLIENT_CONNECTION_STATUS_REASON, IOTHUB_CLIENT_CONNECTION_STATUS_REASON_VALUES);
AzureIoTClient 52:1cc3c6d07cad 103
AzureIoTClient 16:deba40344375 104 #define TRANSPORT_TYPE_VALUES \
AzureIoTClient 16:deba40344375 105 TRANSPORT_LL, /*LL comes from "LowLevel" */ \
AzureIoTClient 16:deba40344375 106 TRANSPORT_THREADED
AzureIoTClient 16:deba40344375 107
AzureIoTClient 40:1a94db9139ea 108 DEFINE_ENUM(TRANSPORT_TYPE, TRANSPORT_TYPE_VALUES);
AzureIoTClient 16:deba40344375 109
AzureIoTClient 16:deba40344375 110 #define IOTHUBMESSAGE_DISPOSITION_RESULT_VALUES \
AzureIoTClient 16:deba40344375 111 IOTHUBMESSAGE_ACCEPTED, \
AzureIoTClient 16:deba40344375 112 IOTHUBMESSAGE_REJECTED, \
AzureIoTClient 16:deba40344375 113 IOTHUBMESSAGE_ABANDONED
AzureIoTClient 16:deba40344375 114
AzureIoTClient 40:1a94db9139ea 115 /** @brief Enumeration returned by the callback which is invoked whenever the
AzureIoTClient 40:1a94db9139ea 116 * IoT Hub sends a message to the device.
AzureIoTClient 40:1a94db9139ea 117 */
AzureIoTClient 40:1a94db9139ea 118 DEFINE_ENUM(IOTHUBMESSAGE_DISPOSITION_RESULT, IOTHUBMESSAGE_DISPOSITION_RESULT_VALUES);
AzureIoTClient 16:deba40344375 119
AzureIoTClient 52:1cc3c6d07cad 120 #define IOTHUB_CLIENT_RETRY_POLICY_VALUES \
AzureIoTClient 52:1cc3c6d07cad 121 IOTHUB_CLIENT_RETRY_NONE, \
AzureIoTClient 52:1cc3c6d07cad 122 IOTHUB_CLIENT_RETRY_IMMEDIATE, \
AzureIoTClient 52:1cc3c6d07cad 123 IOTHUB_CLIENT_RETRY_INTERVAL, \
AzureIoTClient 52:1cc3c6d07cad 124 IOTHUB_CLIENT_RETRY_LINEAR_BACKOFF, \
AzureIoTClient 52:1cc3c6d07cad 125 IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF, \
AzureIoTClient 52:1cc3c6d07cad 126 IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER, \
AzureIoTClient 52:1cc3c6d07cad 127 IOTHUB_CLIENT_RETRY_RANDOM
AzureIoTClient 52:1cc3c6d07cad 128
AzureIoTClient 52:1cc3c6d07cad 129 /** @brief Enumeration passed in by the IoT Hub when the event confirmation
AzureIoTClient 52:1cc3c6d07cad 130 * callback is invoked to indicate status of the event processing in
AzureIoTClient 52:1cc3c6d07cad 131 * the hub.
AzureIoTClient 52:1cc3c6d07cad 132 */
AzureIoTClient 52:1cc3c6d07cad 133 DEFINE_ENUM(IOTHUB_CLIENT_RETRY_POLICY, IOTHUB_CLIENT_RETRY_POLICY_VALUES);
AzureIoTClient 52:1cc3c6d07cad 134
AzureIoTClient 43:038d8511e817 135
AzureIoTClient 40:1a94db9139ea 136 typedef void(*IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK)(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback);
AzureIoTClient 52:1cc3c6d07cad 137 typedef void(*IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK)(IOTHUB_CLIENT_CONNECTION_STATUS result, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason, void* userContextCallback);
AzureIoTClient 40:1a94db9139ea 138 typedef IOTHUBMESSAGE_DISPOSITION_RESULT (*IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC)(IOTHUB_MESSAGE_HANDLE message, void* userContextCallback);
AzureIoTClient 43:038d8511e817 139 typedef const TRANSPORT_PROVIDER*(*IOTHUB_CLIENT_TRANSPORT_PROVIDER)(void);
AzureIoTClient 16:deba40344375 140
AzureIoTClient 40:1a94db9139ea 141 /** @brief This struct captures IoTHub client configuration. */
AzureIoTClient 40:1a94db9139ea 142 typedef struct IOTHUB_CLIENT_CONFIG_TAG
AzureIoTClient 40:1a94db9139ea 143 {
AzureIoTClient 40:1a94db9139ea 144 /** @brief A function pointer that is passed into the @c IoTHubClientCreate.
AzureIoTClient 40:1a94db9139ea 145 * A function definition for AMQP is defined in the include @c iothubtransportamqp.h.
AzureIoTClient 40:1a94db9139ea 146 * A function definition for HTTP is defined in the include @c iothubtransporthttp.h
AzureIoTClient 40:1a94db9139ea 147 * A function definition for MQTT is defined in the include @c iothubtransportmqtt.h */
AzureIoTClient 40:1a94db9139ea 148 IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol;
AzureIoTClient 16:deba40344375 149
AzureIoTClient 40:1a94db9139ea 150 /** @brief A string that identifies the device. */
AzureIoTClient 40:1a94db9139ea 151 const char* deviceId;
AzureIoTClient 40:1a94db9139ea 152
Azure.IoT Build 45:54c11b1b1407 153 /** @brief The device key used to authenticate the device.
Azure.IoT Build 45:54c11b1b1407 154 If neither deviceSasToken nor deviceKey is present then the authentication is assumed x509.*/
AzureIoTClient 40:1a94db9139ea 155 const char* deviceKey;
AzureIoTClient 40:1a94db9139ea 156
Azure.IoT Build 45:54c11b1b1407 157 /** @brief The device SAS Token used to authenticate the device in place of device key.
Azure.IoT Build 45:54c11b1b1407 158 If neither deviceSasToken nor deviceKey is present then the authentication is assumed x509.*/
AzureIoTClient 40:1a94db9139ea 159 const char* deviceSasToken;
AzureIoTClient 40:1a94db9139ea 160
AzureIoTClient 40:1a94db9139ea 161 /** @brief The IoT Hub name to which the device is connecting. */
AzureIoTClient 40:1a94db9139ea 162 const char* iotHubName;
AzureIoTClient 16:deba40344375 163
AzureIoTClient 40:1a94db9139ea 164 /** @brief IoT Hub suffix goes here, e.g., private.azure-devices-int.net. */
AzureIoTClient 40:1a94db9139ea 165 const char* iotHubSuffix;
AzureIoTClient 16:deba40344375 166
AzureIoTClient 40:1a94db9139ea 167 const char* protocolGatewayHostName;
AzureIoTClient 40:1a94db9139ea 168 } IOTHUB_CLIENT_CONFIG;
AzureIoTClient 16:deba40344375 169
AzureIoTClient 40:1a94db9139ea 170 /** @brief This struct captures IoTHub client device configuration. */
AzureIoTClient 40:1a94db9139ea 171 typedef struct IOTHUB_CLIENT_DEVICE_CONFIG_TAG
AzureIoTClient 40:1a94db9139ea 172 {
AzureIoTClient 40:1a94db9139ea 173 /** @brief A function pointer that is passed into the @c IoTHubClientCreate.
AzureIoTClient 40:1a94db9139ea 174 * A function definition for AMQP is defined in the include @c iothubtransportamqp.h.
AzureIoTClient 40:1a94db9139ea 175 * A function definition for HTTP is defined in the include @c iothubtransporthttp.h
AzureIoTClient 40:1a94db9139ea 176 * A function definition for MQTT is defined in the include @c iothubtransportmqtt.h */
AzureIoTClient 40:1a94db9139ea 177 IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol;
Azure.IoT Build 36:67300d5a4c1f 178
AzureIoTClient 40:1a94db9139ea 179 /** @brief a transport handle implementing the protocol */
AzureIoTClient 40:1a94db9139ea 180 void * transportHandle;
Azure.IoT Build 36:67300d5a4c1f 181
AzureIoTClient 40:1a94db9139ea 182 /** @brief A string that identifies the device. */
AzureIoTClient 40:1a94db9139ea 183 const char* deviceId;
Azure.IoT Build 36:67300d5a4c1f 184
Azure.IoT Build 45:54c11b1b1407 185 /** @brief The device key used to authenticate the device.
Azure.IoT Build 45:54c11b1b1407 186 x509 authentication is is not supported for multiplexed connections*/
AzureIoTClient 40:1a94db9139ea 187 const char* deviceKey;
Azure.IoT Build 36:67300d5a4c1f 188
Azure.IoT Build 45:54c11b1b1407 189 /** @brief The device SAS Token used to authenticate the device in place of device key.
Azure.IoT Build 45:54c11b1b1407 190 x509 authentication is is not supported for multiplexed connections.*/
AzureIoTClient 40:1a94db9139ea 191 const char* deviceSasToken;
AzureIoTClient 40:1a94db9139ea 192 } IOTHUB_CLIENT_DEVICE_CONFIG;
Azure.IoT Build 36:67300d5a4c1f 193
AzureIoTClient 40:1a94db9139ea 194 /** @brief This struct captures IoTHub transport configuration. */
AzureIoTClient 48:cc5d91f2b06d 195 struct IOTHUBTRANSPORT_CONFIG_TAG
AzureIoTClient 40:1a94db9139ea 196 {
AzureIoTClient 40:1a94db9139ea 197 const IOTHUB_CLIENT_CONFIG* upperConfig;
AzureIoTClient 40:1a94db9139ea 198 PDLIST_ENTRY waitingToSend;
AzureIoTClient 48:cc5d91f2b06d 199 };
Azure.IoT Build 37:18310e4d888d 200
Azure.IoT Build 37:18310e4d888d 201
AzureIoTClient 40:1a94db9139ea 202 /**
AzureIoTClient 40:1a94db9139ea 203 * @brief Creates a IoT Hub client for communication with an existing
AzureIoTClient 40:1a94db9139ea 204 * IoT Hub using the specified connection string parameter.
AzureIoTClient 40:1a94db9139ea 205 *
AzureIoTClient 40:1a94db9139ea 206 * @param connectionString Pointer to a character string
AzureIoTClient 40:1a94db9139ea 207 * @param protocol Function pointer for protocol implementation
AzureIoTClient 40:1a94db9139ea 208 *
AzureIoTClient 40:1a94db9139ea 209 * Sample connection string:
AzureIoTClient 40:1a94db9139ea 210 * <blockquote>
AzureIoTClient 40:1a94db9139ea 211 * <pre>HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];DeviceId=[Device ID goes here];SharedAccessKey=[Device key goes here];</pre>
AzureIoTClient 40:1a94db9139ea 212 * </blockquote>
AzureIoTClient 40:1a94db9139ea 213 *
AzureIoTClient 40:1a94db9139ea 214 * @return A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
AzureIoTClient 40:1a94db9139ea 215 * invoking other functions for IoT Hub client and @c NULL on failure.
AzureIoTClient 40:1a94db9139ea 216 */
AzureIoTClient 40:1a94db9139ea 217 extern IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol);
AzureIoTClient 16:deba40344375 218
AzureIoTClient 40:1a94db9139ea 219 /**
AzureIoTClient 40:1a94db9139ea 220 * @brief Creates a IoT Hub client for communication with an existing IoT
AzureIoTClient 40:1a94db9139ea 221 * Hub using the specified parameters.
AzureIoTClient 40:1a94db9139ea 222 *
AzureIoTClient 40:1a94db9139ea 223 * @param config Pointer to an @c IOTHUB_CLIENT_CONFIG structure
AzureIoTClient 40:1a94db9139ea 224 *
AzureIoTClient 40:1a94db9139ea 225 * The API does not allow sharing of a connection across multiple
AzureIoTClient 40:1a94db9139ea 226 * devices. This is a blocking call.
AzureIoTClient 40:1a94db9139ea 227 *
AzureIoTClient 40:1a94db9139ea 228 * @return A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
AzureIoTClient 40:1a94db9139ea 229 * invoking other functions for IoT Hub client and @c NULL on failure.
AzureIoTClient 40:1a94db9139ea 230 */
AzureIoTClient 40:1a94db9139ea 231 extern IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_Create(const IOTHUB_CLIENT_CONFIG* config);
AzureIoTClient 16:deba40344375 232
AzureIoTClient 40:1a94db9139ea 233 /**
AzureIoTClient 40:1a94db9139ea 234 * @brief Creates a IoT Hub client for communication with an existing IoT
AzureIoTClient 40:1a94db9139ea 235 * Hub using an existing transport.
AzureIoTClient 40:1a94db9139ea 236 *
AzureIoTClient 40:1a94db9139ea 237 * @param config Pointer to an @c IOTHUB_CLIENT_DEVICE_CONFIG structure
AzureIoTClient 40:1a94db9139ea 238 *
AzureIoTClient 40:1a94db9139ea 239 * The API *allows* sharing of a connection across multiple
AzureIoTClient 40:1a94db9139ea 240 * devices. This is a blocking call.
AzureIoTClient 40:1a94db9139ea 241 *
AzureIoTClient 40:1a94db9139ea 242 * @return A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
AzureIoTClient 40:1a94db9139ea 243 * invoking other functions for IoT Hub client and @c NULL on failure.
AzureIoTClient 40:1a94db9139ea 244 */
AzureIoTClient 40:1a94db9139ea 245 extern IOTHUB_CLIENT_LL_HANDLE IoTHubClient_LL_CreateWithTransport(const IOTHUB_CLIENT_DEVICE_CONFIG * config);
Azure.IoT Build 36:67300d5a4c1f 246
AzureIoTClient 40:1a94db9139ea 247 /**
AzureIoTClient 40:1a94db9139ea 248 * @brief Disposes of resources allocated by the IoT Hub client. This is a
AzureIoTClient 40:1a94db9139ea 249 * blocking call.
AzureIoTClient 40:1a94db9139ea 250 *
AzureIoTClient 40:1a94db9139ea 251 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 40:1a94db9139ea 252 */
AzureIoTClient 40:1a94db9139ea 253 extern void IoTHubClient_LL_Destroy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle);
AzureIoTClient 16:deba40344375 254
AzureIoTClient 40:1a94db9139ea 255 /**
AzureIoTClient 40:1a94db9139ea 256 * @brief Asynchronous call to send the message specified by @p eventMessageHandle.
AzureIoTClient 40:1a94db9139ea 257 *
AzureIoTClient 40:1a94db9139ea 258 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 40:1a94db9139ea 259 * @param eventMessageHandle The handle to an IoT Hub message.
AzureIoTClient 40:1a94db9139ea 260 * @param eventConfirmationCallback The callback specified by the device for receiving
AzureIoTClient 40:1a94db9139ea 261 * confirmation of the delivery of the IoT Hub message.
AzureIoTClient 40:1a94db9139ea 262 * This callback can be expected to invoke the
AzureIoTClient 40:1a94db9139ea 263 * ::IoTHubClient_LL_SendEventAsync function for the
AzureIoTClient 40:1a94db9139ea 264 * same message in an attempt to retry sending a failing
AzureIoTClient 40:1a94db9139ea 265 * message. The user can specify a @c NULL value here to
AzureIoTClient 40:1a94db9139ea 266 * indicate that no callback is required.
AzureIoTClient 40:1a94db9139ea 267 * @param userContextCallback User specified context that will be provided to the
AzureIoTClient 40:1a94db9139ea 268 * callback. This can be @c NULL.
AzureIoTClient 40:1a94db9139ea 269 *
AzureIoTClient 40:1a94db9139ea 270 * @b NOTE: The application behavior is undefined if the user calls
AzureIoTClient 40:1a94db9139ea 271 * the ::IoTHubClient_LL_Destroy function from within any callback.
AzureIoTClient 40:1a94db9139ea 272 *
AzureIoTClient 40:1a94db9139ea 273 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 40:1a94db9139ea 274 */
AzureIoTClient 40:1a94db9139ea 275 extern 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 276
AzureIoTClient 40:1a94db9139ea 277 /**
AzureIoTClient 40:1a94db9139ea 278 * @brief This function returns the current sending status for IoTHubClient.
AzureIoTClient 40:1a94db9139ea 279 *
AzureIoTClient 40:1a94db9139ea 280 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 40:1a94db9139ea 281 * @param iotHubClientStatus The sending state is populated at the address pointed
AzureIoTClient 40:1a94db9139ea 282 * at by this parameter. The value will be set to
AzureIoTClient 40:1a94db9139ea 283 * @c IOTHUBCLIENT_SENDSTATUS_IDLE if there is currently
AzureIoTClient 40:1a94db9139ea 284 * no item to be sent and @c IOTHUBCLIENT_SENDSTATUS_BUSY
AzureIoTClient 40:1a94db9139ea 285 * if there are.
AzureIoTClient 40:1a94db9139ea 286 *
AzureIoTClient 40:1a94db9139ea 287 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 40:1a94db9139ea 288 */
AzureIoTClient 40:1a94db9139ea 289 extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetSendStatus(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus);
AzureIoTClient 16:deba40344375 290
AzureIoTClient 40:1a94db9139ea 291 /**
AzureIoTClient 40:1a94db9139ea 292 * @brief Sets up the message callback to be invoked when IoT Hub issues a
AzureIoTClient 40:1a94db9139ea 293 * message to the device. This is a blocking call.
AzureIoTClient 40:1a94db9139ea 294 *
AzureIoTClient 40:1a94db9139ea 295 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 40:1a94db9139ea 296 * @param messageCallback The callback specified by the device for receiving
AzureIoTClient 40:1a94db9139ea 297 * messages from IoT Hub.
AzureIoTClient 40:1a94db9139ea 298 * @param userContextCallback User specified context that will be provided to the
AzureIoTClient 40:1a94db9139ea 299 * callback. This can be @c NULL.
AzureIoTClient 40:1a94db9139ea 300 *
AzureIoTClient 40:1a94db9139ea 301 * @b NOTE: The application behavior is undefined if the user calls
AzureIoTClient 40:1a94db9139ea 302 * the ::IoTHubClient_LL_Destroy function from within any callback.
AzureIoTClient 40:1a94db9139ea 303 *
AzureIoTClient 40:1a94db9139ea 304 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 40:1a94db9139ea 305 */
AzureIoTClient 40:1a94db9139ea 306 extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetMessageCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback);
AzureIoTClient 16:deba40344375 307
AzureIoTClient 52:1cc3c6d07cad 308 /**
AzureIoTClient 52:1cc3c6d07cad 309 * @brief Sets up the connection status callback to be invoked representing the status of
AzureIoTClient 52:1cc3c6d07cad 310 * the connection to IOT Hub. This is a blocking call.
AzureIoTClient 52:1cc3c6d07cad 311 *
AzureIoTClient 52:1cc3c6d07cad 312 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 52:1cc3c6d07cad 313 * @param connectionStatusCallback The callback specified by the device for receiving
AzureIoTClient 52:1cc3c6d07cad 314 * updates about the status of the connection to IoT Hub.
AzureIoTClient 52:1cc3c6d07cad 315 * @param userContextCallback User specified context that will be provided to the
AzureIoTClient 52:1cc3c6d07cad 316 * callback. This can be @c NULL.
AzureIoTClient 52:1cc3c6d07cad 317 *
AzureIoTClient 52:1cc3c6d07cad 318 * @b NOTE: The application behavior is undefined if the user calls
AzureIoTClient 52:1cc3c6d07cad 319 * the ::IoTHubClient_LL_Destroy function from within any callback.
AzureIoTClient 52:1cc3c6d07cad 320 *
AzureIoTClient 52:1cc3c6d07cad 321 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 52:1cc3c6d07cad 322 */
AzureIoTClient 52:1cc3c6d07cad 323 extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetConnectionStatusCallback(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK connectionStatusCallback, void* userContextCallback);
AzureIoTClient 52:1cc3c6d07cad 324
AzureIoTClient 52:1cc3c6d07cad 325 /**
AzureIoTClient 52:1cc3c6d07cad 326 * @brief Sets up the connection status callback to be invoked representing the status of
AzureIoTClient 52:1cc3c6d07cad 327 * the connection to IOT Hub. This is a blocking call.
AzureIoTClient 52:1cc3c6d07cad 328 *
AzureIoTClient 52:1cc3c6d07cad 329 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 52:1cc3c6d07cad 330 * @param retryPolicy The policy to use to reconnect to IoT Hub when a
AzureIoTClient 52:1cc3c6d07cad 331 * connection drops.
AzureIoTClient 52:1cc3c6d07cad 332 * @param retryTimeoutLimitinSeconds Maximum amount of time(seconds) to attempt reconnection when a
AzureIoTClient 52:1cc3c6d07cad 333 * connection drops to IOT Hub.
AzureIoTClient 52:1cc3c6d07cad 334 *
AzureIoTClient 52:1cc3c6d07cad 335 * @b NOTE: The application behavior is undefined if the user calls
AzureIoTClient 52:1cc3c6d07cad 336 * the ::IoTHubClient_LL_Destroy function from within any callback.
AzureIoTClient 52:1cc3c6d07cad 337 *
AzureIoTClient 52:1cc3c6d07cad 338 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 52:1cc3c6d07cad 339 */
AzureIoTClient 52:1cc3c6d07cad 340 extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitinSeconds);
AzureIoTClient 52:1cc3c6d07cad 341
AzureIoTClient 52:1cc3c6d07cad 342
AzureIoTClient 52:1cc3c6d07cad 343 /**
AzureIoTClient 52:1cc3c6d07cad 344 * @brief Sets up the connection status callback to be invoked representing the status of
AzureIoTClient 52:1cc3c6d07cad 345 * the connection to IOT Hub. This is a blocking call.
AzureIoTClient 52:1cc3c6d07cad 346 *
AzureIoTClient 52:1cc3c6d07cad 347 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 52:1cc3c6d07cad 348 * @param retryPolicy Out parameter containing the policy to use to reconnect to IoT Hub.
AzureIoTClient 52:1cc3c6d07cad 349 * @param retryTimeoutLimitinSeconds Out parameter containing maximum amount of time in seconds to attempt reconnection
AzureIoTClient 52:1cc3c6d07cad 350 to IOT Hub.
AzureIoTClient 52:1cc3c6d07cad 351 *
AzureIoTClient 52:1cc3c6d07cad 352 * @b NOTE: The application behavior is undefined if the user calls
AzureIoTClient 52:1cc3c6d07cad 353 * the ::IoTHubClient_LL_Destroy function from within any callback.
AzureIoTClient 52:1cc3c6d07cad 354 *
AzureIoTClient 52:1cc3c6d07cad 355 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 52:1cc3c6d07cad 356 */
AzureIoTClient 52:1cc3c6d07cad 357 extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetRetryPolicy(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY* retryPolicy, size_t* retryTimeoutLimitinSeconds);
AzureIoTClient 52:1cc3c6d07cad 358
AzureIoTClient 40:1a94db9139ea 359 /**
AzureIoTClient 40:1a94db9139ea 360 * @brief This function returns in the out parameter @p lastMessageReceiveTime
AzureIoTClient 40:1a94db9139ea 361 * what was the value of the @c time function when the last message was
AzureIoTClient 40:1a94db9139ea 362 * received at the client.
AzureIoTClient 40:1a94db9139ea 363 *
AzureIoTClient 40:1a94db9139ea 364 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 40:1a94db9139ea 365 * @param lastMessageReceiveTime Out parameter containing the value of @c time function
AzureIoTClient 40:1a94db9139ea 366 * when the last message was received.
AzureIoTClient 40:1a94db9139ea 367 *
AzureIoTClient 40:1a94db9139ea 368 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 40:1a94db9139ea 369 */
AzureIoTClient 40:1a94db9139ea 370 extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_GetLastMessageReceiveTime(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime);
AzureIoTClient 16:deba40344375 371
AzureIoTClient 40:1a94db9139ea 372 /**
AzureIoTClient 40:1a94db9139ea 373 * @brief This function is meant to be called by the user when work
AzureIoTClient 40:1a94db9139ea 374 * (sending/receiving) can be done by the IoTHubClient.
AzureIoTClient 40:1a94db9139ea 375 *
AzureIoTClient 40:1a94db9139ea 376 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 40:1a94db9139ea 377 *
AzureIoTClient 40:1a94db9139ea 378 * All IoTHubClient interactions (in regards to network traffic
AzureIoTClient 40:1a94db9139ea 379 * and/or user level callbacks) are the effect of calling this
AzureIoTClient 40:1a94db9139ea 380 * function and they take place synchronously inside _DoWork.
AzureIoTClient 40:1a94db9139ea 381 */
AzureIoTClient 40:1a94db9139ea 382 extern void IoTHubClient_LL_DoWork(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle);
AzureIoTClient 16:deba40344375 383
AzureIoTClient 40:1a94db9139ea 384 /**
AzureIoTClient 40:1a94db9139ea 385 * @brief This API sets a runtime option identified by parameter @p optionName
AzureIoTClient 40:1a94db9139ea 386 * to a value pointed to by @p value. @p optionName and the data type
AzureIoTClient 40:1a94db9139ea 387 * @p value is pointing to are specific for every option.
AzureIoTClient 40:1a94db9139ea 388 *
AzureIoTClient 40:1a94db9139ea 389 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 40:1a94db9139ea 390 * @param optionName Name of the option.
AzureIoTClient 40:1a94db9139ea 391 * @param value The value.
AzureIoTClient 40:1a94db9139ea 392 *
AzureIoTClient 40:1a94db9139ea 393 * The options that can be set via this API are:
AzureIoTClient 40:1a94db9139ea 394 * - @b timeout - the maximum time in milliseconds a communication is
AzureIoTClient 40:1a94db9139ea 395 * allowed to use. @p value is a pointer to an @c unsigned @c int with
AzureIoTClient 40:1a94db9139ea 396 * the timeout value in milliseconds. This is only supported for the HTTP
AzureIoTClient 40:1a94db9139ea 397 * protocol as of now. When the HTTP protocol uses CURL, the meaning of
AzureIoTClient 40:1a94db9139ea 398 * the parameter is <em>total request time</em>. When the HTTP protocol uses
AzureIoTClient 40:1a94db9139ea 399 * winhttp, the meaning is the same as the @c dwSendTimeout and
AzureIoTClient 40:1a94db9139ea 400 * @c dwReceiveTimeout parameters of the
AzureIoTClient 40:1a94db9139ea 401 * <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384116(v=vs.85).aspx">
AzureIoTClient 40:1a94db9139ea 402 * WinHttpSetTimeouts</a> API.
AzureIoTClient 40:1a94db9139ea 403 * - @b CURLOPT_LOW_SPEED_LIMIT - only available for HTTP protocol and only
AzureIoTClient 40:1a94db9139ea 404 * when CURL is used. It has the same meaning as CURL's option with the same
AzureIoTClient 40:1a94db9139ea 405 * name. @p value is pointer to a long.
AzureIoTClient 40:1a94db9139ea 406 * - @b CURLOPT_LOW_SPEED_TIME - only available for HTTP protocol and only
AzureIoTClient 40:1a94db9139ea 407 * when CURL is used. It has the same meaning as CURL's option with the same
AzureIoTClient 40:1a94db9139ea 408 * name. @p value is pointer to a long.
AzureIoTClient 40:1a94db9139ea 409 * - @b CURLOPT_FORBID_REUSE - only available for HTTP protocol and only
AzureIoTClient 40:1a94db9139ea 410 * when CURL is used. It has the same meaning as CURL's option with the same
AzureIoTClient 40:1a94db9139ea 411 * name. @p value is pointer to a long.
AzureIoTClient 40:1a94db9139ea 412 * - @b CURLOPT_FRESH_CONNECT - only available for HTTP protocol and only
AzureIoTClient 40:1a94db9139ea 413 * when CURL is used. It has the same meaning as CURL's option with the same
AzureIoTClient 40:1a94db9139ea 414 * name. @p value is pointer to a long.
AzureIoTClient 40:1a94db9139ea 415 * - @b CURLOPT_VERBOSE - only available for HTTP protocol and only
AzureIoTClient 40:1a94db9139ea 416 * when CURL is used. It has the same meaning as CURL's option with the same
AzureIoTClient 40:1a94db9139ea 417 * name. @p value is pointer to a long.
AzureIoTClient 40:1a94db9139ea 418 * - @b keepalive - available for MQTT protocol. Integer value that sets the
AzureIoTClient 40:1a94db9139ea 419 * interval in seconds when pings are sent to the server.
AzureIoTClient 40:1a94db9139ea 420 * - @b logtrace - available for MQTT protocol. Boolean value that turns on and
AzureIoTClient 40:1a94db9139ea 421 * off the diagnostic logging.
AzureIoTClient 40:1a94db9139ea 422 *
AzureIoTClient 40:1a94db9139ea 423 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 40:1a94db9139ea 424 */
AzureIoTClient 40:1a94db9139ea 425 extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetOption(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* optionName, const void* value);
AzureIoTClient 16:deba40344375 426
AzureIoTClient 44:33dd78697616 427 #ifndef DONT_USE_UPLOADTOBLOB
AzureIoTClient 43:038d8511e817 428 /**
AzureIoTClient 43:038d8511e817 429 * @brief This API uploads to Azure Storage the content pointed to by @p source having the size @p size
AzureIoTClient 43:038d8511e817 430 * under the blob name devicename/@pdestinationFileName
AzureIoTClient 43:038d8511e817 431 *
AzureIoTClient 43:038d8511e817 432 * @param iotHubClientHandle The handle created by a call to the create function.
AzureIoTClient 43:038d8511e817 433 * @param destinationFileName name of the file.
AzureIoTClient 43:038d8511e817 434 * @param source pointer to the source for file content (can be NULL)
AzureIoTClient 43:038d8511e817 435 * @param size the size of the source in memory (if @p source is NULL then size needs to be 0).
AzureIoTClient 43:038d8511e817 436 *
AzureIoTClient 43:038d8511e817 437 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
AzureIoTClient 43:038d8511e817 438 */
AzureIoTClient 42:448eecc3676e 439 extern IOTHUB_CLIENT_RESULT IoTHubClient_LL_UploadToBlob(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* destinationFileName, const unsigned char* source, size_t size);
AzureIoTClient 42:448eecc3676e 440
AzureIoTClient 44:33dd78697616 441 #endif /*DONT_USE_UPLOADTOBLOB*/
AzureIoTClient 43:038d8511e817 442
AzureIoTClient 16:deba40344375 443 #ifdef __cplusplus
AzureIoTClient 16:deba40344375 444 }
AzureIoTClient 16:deba40344375 445 #endif
AzureIoTClient 16:deba40344375 446
AzureIoTClient 16:deba40344375 447 #endif /* IOTHUB_CLIENT_LL_H */