source: azure_iot_hub_f767zi/trunk/azure_iot_sdk/iothub_client/inc/iothub_device_client_ll.h

Last change on this file was 464, checked in by coas-nagasima, 3 years ago

WolfSSLとAzure IoT SDKを更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 22.9 KB
Line 
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4/** @file iothub_device_client_ll.h
5* @brief APIs that allow a user (usually a device) to communicate
6* with an Azure IoTHub.
7*
8* @details IoTHubDeviceClient_LL allows a user (usually a
9* device) to communicate with an Azure IoTHub. It can send events
10* and receive messages. At any given moment in time there can only
11* be at most 1 message callback function.
12*
13* This API surface contains a set of APIs that allows the user to
14* interact with the lower layer portion of the IoTHubClient. These APIs
15* contain @c _LL_ in their name, but retain the same functionality like the
16* @c IoTHubDeviceClient_... APIs, with one difference. If the @c _LL_ APIs are
17* used then the user is responsible for scheduling when the actual work done
18* by the IoTHubClient happens (when the data is sent/received on/from the network).
19* This is useful for constrained devices where spinning a separate thread is
20* often not desired.
21*/
22
23#ifndef IOTHUB_DEVICE_CLIENT_LL_H
24#define IOTHUB_DEVICE_CLIENT_LL_H
25
26#include <stddef.h>
27#include <stdint.h>
28
29#include "azure_macro_utils/macro_utils.h"
30#include "umock_c/umock_c_prod.h"
31
32#include "iothub_transport_ll.h"
33#include "iothub_client_core_ll.h"
34
35#ifdef __cplusplus
36extern "C"
37{
38#endif
39
40typedef struct IOTHUB_CLIENT_CORE_LL_HANDLE_DATA_TAG* IOTHUB_DEVICE_CLIENT_LL_HANDLE;
41
42
43 /**
44 * @brief Creates a IoT Hub client for communication with an existing
45 * IoT Hub using the specified connection string parameter.
46 *
47 * @param connectionString Pointer to a character string
48 * @param protocol Function pointer for protocol implementation
49 *
50 * Sample connection string:
51 * <blockquote>
52 * <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>
53 * </blockquote>
54 *
55 * @return A non-NULL @c IOTHUB_DEVICE_CLIENT_LL_HANDLE value that is used when
56 * invoking other functions for IoT Hub client and @c NULL on failure.
57 */
58 MOCKABLE_FUNCTION(, IOTHUB_DEVICE_CLIENT_LL_HANDLE, IoTHubDeviceClient_LL_CreateFromConnectionString, const char*, connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol);
59
60 /**
61 * @brief Creates a IoT Hub client for communication with an existing IoT
62 * Hub using the specified parameters.
63 *
64 * @param config Pointer to an @c IOTHUB_CLIENT_CONFIG structure
65 *
66 * The API does not allow sharing of a connection across multiple
67 * devices. This is a blocking call.
68 *
69 * @return A non-NULL @c IOTHUB_DEVICE_CLIENT_LL_HANDLE value that is used when
70 * invoking other functions for IoT Hub client and @c NULL on failure.
71 */
72 MOCKABLE_FUNCTION(, IOTHUB_DEVICE_CLIENT_LL_HANDLE, IoTHubDeviceClient_LL_Create, const IOTHUB_CLIENT_CONFIG*, config);
73
74 /**
75 * @brief Creates a IoT Hub client for communication with an existing IoT
76 * Hub using an existing transport.
77 *
78 * @param config Pointer to an @c IOTHUB_CLIENT_DEVICE_CONFIG structure
79 *
80 * The API *allows* sharing of a connection across multiple
81 * devices. This is a blocking call.
82 *
83 * @return A non-NULL @c IOTHUB_DEVICE_CLIENT_LL_HANDLE value that is used when
84 * invoking other functions for IoT Hub client and @c NULL on failure.
85 */
86 MOCKABLE_FUNCTION(, IOTHUB_DEVICE_CLIENT_LL_HANDLE, IoTHubDeviceClient_LL_CreateWithTransport, const IOTHUB_CLIENT_DEVICE_CONFIG*, config);
87
88 /**
89 * @brief Creates a IoT Hub client for communication with an existing IoT
90 * Hub using the device auth.
91 *
92 * @param iothub_uri Pointer to an ioThub hostname received in the registration process
93 * @param device_id Pointer to the device Id of the device
94 * @param device_auth_handle A device auth handle used to generate the connection string
95 * @param protocol Function pointer for protocol implementation
96 *
97 * @return A non-NULL @c IOTHUB_DEVICE_CLIENT_LL_HANDLE value that is used when
98 * invoking other functions for IoT Hub client and @c NULL on failure.
99 */
100 MOCKABLE_FUNCTION(, IOTHUB_DEVICE_CLIENT_LL_HANDLE, IoTHubDeviceClient_LL_CreateFromDeviceAuth, const char*, iothub_uri, const char*, device_id, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol);
101
102 /**
103 * @brief Disposes of resources allocated by the IoT Hub client. This is a
104 * blocking call.
105 *
106 * @param iotHubClientHandle The handle created by a call to the create function.
107 */
108 MOCKABLE_FUNCTION(, void, IoTHubDeviceClient_LL_Destroy, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle);
109
110 /**
111 * @brief Asynchronous call to send the message specified by @p eventMessageHandle.
112 *
113 * @param iotHubClientHandle The handle created by a call to the create function.
114 * @param eventMessageHandle The handle to an IoT Hub message.
115 * @param eventConfirmationCallback The callback specified by the device for receiving
116 * confirmation of the delivery of the IoT Hub message.
117 * This callback can be expected to invoke the
118 * IoTHubDeviceClient_LL_SendEventAsync function for the
119 * same message in an attempt to retry sending a failing
120 * message. The user can specify a @c NULL value here to
121 * indicate that no callback is required.
122 * @param userContextCallback User specified context that will be provided to the
123 * callback. This can be @c NULL.
124 *
125 * @b NOTE: The application behavior is undefined if the user calls
126 * the IoTHubDeviceClient_LL_Destroy function from within any callback.
127 * @remarks
128 * The IOTHUB_MESSAGE_HANDLE instance provided as argument is copied by the function,
129 * so this argument can be destroyed by the calling application right after IoTHubDeviceClient_LL_SendEventAsync returns.
130 * The copy of @c eventMessageHandle is later destroyed by the iothub client when the message is effectively sent, if a failure sending it occurs, or if the client is destroyed.
131 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
132 */
133 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_SendEventAsync, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_MESSAGE_HANDLE, eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, eventConfirmationCallback, void*, userContextCallback);
134
135 /**
136 * @brief This function returns the current sending status for IoTHubClient.
137 *
138 * @param iotHubClientHandle The handle created by a call to the create function.
139 * @param iotHubClientStatus The sending state is populated at the address pointed
140 * at by this parameter. The value will be set to
141 * @c IOTHUB_CLIENT_SEND_STATUS_IDLE if there is currently
142 * no item to be sent and @c IOTHUB_CLIENT_SEND_STATUS_BUSY
143 * if there are.
144 *
145 * @remark Does not return information related to uploads initiated by IoTHubDeviceClient_LL_UploadToBlob or IoTHubDeviceClient_LL_UploadMultipleBlocksToBlob.
146 *
147 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
148 */
149 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_GetSendStatus, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_STATUS*, iotHubClientStatus);
150
151 /**
152 * @brief Sets up the message callback to be invoked when IoT Hub issues a
153 * message to the device. This is a blocking call.
154 *
155 * @param iotHubClientHandle The handle created by a call to the create function.
156 * @param messageCallback The callback specified by the device for receiving
157 * messages from IoT Hub.
158 * @param userContextCallback User specified context that will be provided to the
159 * callback. This can be @c NULL.
160 *
161 * @b NOTE: The application behavior is undefined if the user calls
162 * the IoTHubDeviceClient_LL_Destroy function from within any callback.
163 *
164 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
165 */
166 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_SetMessageCallback, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC, messageCallback, void*, userContextCallback);
167
168 /**
169 * @brief Sets up the connection status callback to be invoked representing the status of
170 * the connection to IOT Hub. This is a blocking call.
171 *
172 * @param iotHubClientHandle The handle created by a call to the create function.
173 * @param connectionStatusCallback The callback specified by the device for receiving
174 * updates about the status of the connection to IoT Hub.
175 * @param userContextCallback User specified context that will be provided to the
176 * callback. This can be @c NULL.
177 *
178 * @b NOTE: The application behavior is undefined if the user calls
179 * the IoTHubDeviceClient_LL_Destroy function from within any callback.
180 *
181 * @remark Callback specified will not receive connection status change notifications for upload connections created with IoTHubDeviceClient_LL_UploadToBlob or IoTHubDeviceClient_LL_UploadMultipleBlocksToBlob.
182 *
183 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
184 */
185 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_SetConnectionStatusCallback, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK, connectionStatusCallback, void*, userContextCallback);
186
187 /**
188 * @brief Sets up the connection status callback to be invoked representing the status of
189 * the connection to IOT Hub. This is a blocking call.
190 *
191 * @param iotHubClientHandle The handle created by a call to the create function.
192 * @param retryPolicy The policy to use to reconnect to IoT Hub when a
193 * connection drops.
194 * @param retryTimeoutLimitInSeconds Maximum amount of time(seconds) to attempt reconnection when a
195 * connection drops to IOT Hub.
196 *
197 * @b NOTE: The application behavior is undefined if the user calls
198 * the IoTHubDeviceClient_LL_Destroy function from within any callback.
199 *
200 * @remark Uploads initiated by IoTHubDeviceClient_LL_UploadToBlob or IoTHubDeviceClient_LL_UploadMultipleBlocksToBlob do not have automatic retries and do not honor the retryPolicy settings.
201 *
202 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
203 */
204 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_SetRetryPolicy, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY, retryPolicy, size_t, retryTimeoutLimitInSeconds);
205
206
207 /**
208 * @brief Sets up the connection status callback to be invoked representing the status of
209 * the connection to IOT Hub. This is a blocking call.
210 *
211 * @param iotHubClientHandle The handle created by a call to the create function.
212 * @param retryPolicy Out parameter containing the policy to use to reconnect to IoT Hub.
213 * @param retryTimeoutLimitInSeconds Out parameter containing maximum amount of time in seconds to attempt reconnection
214 to IOT Hub.
215 *
216 * @b NOTE: The application behavior is undefined if the user calls
217 * the IoTHubDeviceClient_LL_Destroy function from within any callback.
218 *
219 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
220 */
221 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_GetRetryPolicy, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY*, retryPolicy, size_t*, retryTimeoutLimitInSeconds);
222
223 /**
224 * @brief This function returns in the out parameter @p lastMessageReceiveTime
225 * what was the value of the @c time function when the last message was
226 * received at the client.
227 *
228 * @param iotHubClientHandle The handle created by a call to the create function.
229 * @param lastMessageReceiveTime Out parameter containing the value of @c time function
230 * when the last message was received.
231 *
232 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
233 */
234 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_GetLastMessageReceiveTime, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, time_t*, lastMessageReceiveTime);
235
236 /**
237 * @brief This function MUST be called by the user so work (sending/receiving data on the network,
238 * computing and enforcing timeout controls, managing the connection to the IoT Hub) can
239 * be done by the IoTHubClient.
240 * The recommended call frequency is at least once every 100 milliseconds.
241 *
242 * @param iotHubClientHandle The handle created by a call to the create function.
243 *
244 * All IoTHubClient interactions (in regards to network traffic
245 * and/or user level callbacks) are the effect of calling this
246 * function and they take place synchronously inside _DoWork.
247 */
248 MOCKABLE_FUNCTION(, void, IoTHubDeviceClient_LL_DoWork, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle);
249
250 /**
251 * @brief This API sets a runtime option identified by parameter @p optionName
252 * to a value pointed to by @p value. @p optionName and the data type
253 * @p value is pointing to are specific for every option.
254 *
255 * @param iotHubClientHandle The handle created by a call to the create function.
256 * @param optionName Name of the option.
257 * @param value The value.
258 *
259 * @remarks Documentation for configuration options is available at https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/Iothub_sdk_options.md.
260 *
261 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
262 */
263 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_SetOption, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, optionName, const void*, value);
264
265 /**
266 * @brief This API specifies a callback to be used when the device receives a desired state update.
267 *
268 * @param iotHubClientHandle The handle created by a call to the create function.
269 * @param deviceTwinCallback The callback specified by the device client to be used for updating
270 * the desired state. The callback will be called in response to patch
271 * request send by the IoTHub services. The payload will be passed to the
272 * callback, along with two version numbers:
273 * - Desired:
274 * - LastSeenReported:
275 * @param userContextCallback User specified context that will be provided to the
276 * callback. This can be @c NULL.
277 *
278 * @b NOTE: The application behavior is undefined if the user calls
279 * the IoTHubDeviceClient_LL_Destroy function from within any callback.
280 *
281 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
282 */
283 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_SetDeviceTwinCallback, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK, deviceTwinCallback, void*, userContextCallback);
284
285 /**
286 * @brief This API sends a report of the device's properties and their current values.
287 *
288 * @param iotHubClientHandle The handle created by a call to the create function.
289 * @param reportedState The current device property values to be 'reported' to the IoTHub.
290 * @param reportedStateCallback The callback specified by the device client to be called with the
291 * result of the transaction.
292 * @param userContextCallback User specified context that will be provided to the
293 * callback. This can be @c NULL.
294 *
295 * @b NOTE: The application behavior is undefined if the user calls
296 * the IoTHubDeviceClient_LL_Destroy function from within any callback.
297 *
298 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
299 */
300 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_SendReportedState, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, const unsigned char*, reportedState, size_t, size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK, reportedStateCallback, void*, userContextCallback);
301
302 /**
303 * @brief This API enabled the device to request the full device twin (with all the desired and reported properties) on demand.
304 *
305 * @param iotHubClientHandle The handle created by a call to the create function.
306 * @param deviceTwinCallback The callback specified by the device client to receive the Twin document.
307 * @param userContextCallback User specified context that will be provided to the
308 * callback. This can be @c NULL.
309 *
310 * @b NOTE: The application behavior is undefined if the user calls
311 * the IoTHubClient_LL_Destroy function from within any callback.
312 *
313 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
314 */
315 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_GetTwinAsync, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK, deviceTwinCallback, void*, userContextCallback);
316
317 /**
318 * @brief This API sets the callback for async cloud to device method calls.
319 *
320 * @param iotHubClientHandle The handle created by a call to the create function.
321 * @param inboundDeviceMethodCallback The callback which will be called by IoTHub.
322 * @param userContextCallback User specified context that will be provided to the
323 * callback. This can be @c NULL.
324 *
325 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
326 */
327 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_SetDeviceMethodCallback, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC, deviceMethodCallback, void*, userContextCallback);
328
329 /**
330 * @brief This API responds to an asnyc method callback identified the methodId.
331 *
332 * @param iotHubClientHandle The handle created by a call to the create function.
333 * @param methodId The methodId of the Device Method callback.
334 * @param response The response data for the method callback.
335 * @param response_size The size of the response data buffer.
336 * @param status_response The status response of the method callback.
337 *
338 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
339 */
340 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_DeviceMethodResponse, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, METHOD_HANDLE, methodId, const unsigned char*, response, size_t, respSize, int, statusCode);
341
342#ifndef DONT_USE_UPLOADTOBLOB
343 /**
344 * @brief This API uploads to Azure Storage the content pointed to by @p source having the size @p size
345 * under the blob name devicename/@pdestinationFileName
346 *
347 * @param iotHubClientHandle The handle created by a call to the create function.
348 * @param destinationFileName name of the file.
349 * @param source pointer to the source for file content (can be NULL)
350 * @param size the size of the source in memory (if @p source is NULL then size needs to be 0).
351 *
352 * @warning Other _LL_ functions such as IoTHubDeviceClient_LL_SendEventAsync queue work to be performed later and do not block. IoTHubDeviceClient_LL_UploadToBlob
353 * will block however until the upload is completed or fails, which may take a while.
354 *
355 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
356 */
357 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_UploadToBlob, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, destinationFileName, const unsigned char*, source, size_t, size);
358
359 /**
360 * @brief This API uploads to Azure Storage the content provided block by block by @p getDataCallback
361 * under the blob name devicename/@pdestinationFileName
362 *
363 * @param iotHubClientHandle The handle created by a call to the create function.
364 * @param destinationFileName name of the file.
365 * @param getDataCallbackEx A callback to be invoked to acquire the file chunks to be uploaded, as well as to indicate the status of the upload of the previous block.
366 * @param context Any data provided by the user to serve as context on getDataCallback.
367 *
368 * @warning Other _LL_ functions such as IoTHubDeviceClient_LL_SendEventAsync queue work to be performed later and do not block. IoTHubDeviceClient_LL_UploadMultipleBlocksToBlob
369 * will block however until the upload is completed or fails, which may take a while.
370 *
371 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
372 */
373 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubDeviceClient_LL_UploadMultipleBlocksToBlob, IOTHUB_DEVICE_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, destinationFileName, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX, getDataCallbackEx, void*, context);
374
375#endif /*DONT_USE_UPLOADTOBLOB*/
376
377#ifdef __cplusplus
378}
379#endif
380
381#endif /* IOTHUB_DEVICE_CLIENT_LL_H */
Note: See TracBrowser for help on using the repository browser.