source: azure_iot_hub_f767zi/trunk/azure_iot_sdk/iothub_client/inc/iothub_client_ll.h@ 457

Last change on this file since 457 was 457, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 24.6 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_client_ll.h
5* @brief APIs that allow a user (usually a device) to communicate
6* with an Azure IoTHub.
7*
8* @details IoTHubClient_LL is a module that 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 IoTHubClient_... 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 wire).
19* This is useful for constrained devices where spinning a separate thread is
20* often not desired.
21*/
22
23#ifndef IOTHUB_CLIENT_LL_H
24#define IOTHUB_CLIENT_LL_H
25
26#include <stddef.h>
27#include <stdint.h>
28#include <time.h>
29#include "umock_c/umock_c_prod.h"
30
31#include "iothub_client_core_common.h"
32
33#ifdef __cplusplus
34extern "C"
35{
36#endif
37
38typedef struct IOTHUB_CLIENT_CORE_LL_HANDLE_DATA_TAG* IOTHUB_CLIENT_LL_HANDLE;
39
40
41 /**
42 * @brief Creates a IoT Hub client for communication with an existing
43 * IoT Hub using the specified connection string parameter.
44 *
45 * @param connectionString Pointer to a character string
46 * @param protocol Function pointer for protocol implementation
47 *
48 * Sample connection string:
49 * <blockquote>
50 * <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>
51 * </blockquote>
52 *
53 * @return A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
54 * invoking other functions for IoT Hub client and @c NULL on failure.
55 */
56 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_HANDLE, IoTHubClient_LL_CreateFromConnectionString, const char*, connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol);
57
58 /**
59 * @brief Creates a IoT Hub client for communication with an existing IoT
60 * Hub using the specified parameters.
61 *
62 * @param config Pointer to an @c IOTHUB_CLIENT_CONFIG structure
63 *
64 * The API does not allow sharing of a connection across multiple
65 * devices. This is a blocking call.
66 *
67 * @return A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
68 * invoking other functions for IoT Hub client and @c NULL on failure.
69 */
70 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_HANDLE, IoTHubClient_LL_Create, const IOTHUB_CLIENT_CONFIG*, config);
71
72 /**
73 * @brief Creates a IoT Hub client for communication with an existing IoT
74 * Hub using an existing transport.
75 *
76 * @param config Pointer to an @c IOTHUB_CLIENT_DEVICE_CONFIG structure
77 *
78 * The API *allows* sharing of a connection across multiple
79 * devices. This is a blocking call.
80 *
81 * @return A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
82 * invoking other functions for IoT Hub client and @c NULL on failure.
83 */
84 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_HANDLE, IoTHubClient_LL_CreateWithTransport, const IOTHUB_CLIENT_DEVICE_CONFIG*, config);
85
86 /**
87 * @brief Creates a IoT Hub client for communication with an existing IoT
88 * Hub using the device auth module.
89 *
90 * @param iothub_uri Pointer to an ioThub hostname received in the registration process
91 * @param device_id Pointer to the device Id of the device
92 * @param device_auth_handle a device auth handle used to generate the connection string
93 * @param protocol Function pointer for protocol implementation
94 *
95 * @return A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
96 * invoking other functions for IoT Hub client and @c NULL on failure.
97 */
98 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_HANDLE, IoTHubClient_LL_CreateFromDeviceAuth, const char*, iothub_uri, const char*, device_id, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol);
99
100 /**
101 * @brief Disposes of resources allocated by the IoT Hub client. This is a
102 * blocking call.
103 *
104 * @param iotHubClientHandle The handle created by a call to the create function.
105 */
106 MOCKABLE_FUNCTION(, void, IoTHubClient_LL_Destroy, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle);
107
108 /**
109 * @brief Asynchronous call to send the message specified by @p eventMessageHandle.
110 *
111 * @param iotHubClientHandle The handle created by a call to the create function.
112 * @param eventMessageHandle The handle to an IoT Hub message.
113 * @param eventConfirmationCallback The callback specified by the device for receiving
114 * confirmation of the delivery of the IoT Hub message.
115 * This callback can be expected to invoke the
116 * ::IoTHubClient_LL_SendEventAsync function for the
117 * same message in an attempt to retry sending a failing
118 * message. The user can specify a @c NULL value here to
119 * indicate that no callback is required.
120 * @param userContextCallback User specified context that will be provided to the
121 * callback. This can be @c NULL.
122 *
123 * @b NOTE: The application behavior is undefined if the user calls
124 * the ::IoTHubClient_LL_Destroy function from within any callback.
125 * @remarks
126 * The IOTHUB_MESSAGE_HANDLE instance provided as argument is copied by the function,
127 * so this argument can be destroyed by the calling application right after IoTHubClient_LL_SendEventAsync returns.
128 * 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.
129 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
130 */
131 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SendEventAsync, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_MESSAGE_HANDLE, eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, eventConfirmationCallback, void*, userContextCallback);
132
133 /**
134 * @brief This function returns the current sending status for IoTHubClient.
135 *
136 * @param iotHubClientHandle The handle created by a call to the create function.
137 * @param iotHubClientStatus The sending state is populated at the address pointed
138 * at by this parameter. The value will be set to
139 * @c IOTHUBCLIENT_SENDSTATUS_IDLE if there is currently
140 * no item to be sent and @c IOTHUBCLIENT_SENDSTATUS_BUSY
141 * if there are.
142 *
143 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
144 */
145 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_GetSendStatus, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_STATUS*, iotHubClientStatus);
146
147 /**
148 * @brief Sets up the message callback to be invoked when IoT Hub issues a
149 * message to the device. This is a blocking call.
150 *
151 * @param iotHubClientHandle The handle created by a call to the create function.
152 * @param messageCallback The callback specified by the device for receiving
153 * messages from IoT Hub.
154 * @param userContextCallback User specified context that will be provided to the
155 * callback. This can be @c NULL.
156 *
157 * @b NOTE: The application behavior is undefined if the user calls
158 * the ::IoTHubClient_LL_Destroy function from within any callback.
159 *
160 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
161 */
162 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetMessageCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC, messageCallback, void*, userContextCallback);
163
164 /**
165 * @brief Sets up the connection status callback to be invoked representing the status of
166 * the connection to IOT Hub. This is a blocking call.
167 *
168 * @param iotHubClientHandle The handle created by a call to the create function.
169 * @param connectionStatusCallback The callback specified by the device for receiving
170 * updates about the status of the connection to IoT Hub.
171 * @param userContextCallback User specified context that will be provided to the
172 * callback. This can be @c NULL.
173 *
174 * @b NOTE: The application behavior is undefined if the user calls
175 * the ::IoTHubClient_LL_Destroy function from within any callback.
176 *
177 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
178 */
179 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetConnectionStatusCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK, connectionStatusCallback, void*, userContextCallback);
180
181 /**
182 * @brief Sets up the connection status callback to be invoked representing the status of
183 * the connection to IOT Hub. This is a blocking call.
184 *
185 * @param iotHubClientHandle The handle created by a call to the create function.
186 * @param retryPolicy The policy to use to reconnect to IoT Hub when a
187 * connection drops.
188 * @param retryTimeoutLimitInSeconds Maximum amount of time(seconds) to attempt reconnection when a
189 * connection drops to IOT Hub.
190 *
191 * @b NOTE: The application behavior is undefined if the user calls
192 * the ::IoTHubClient_LL_Destroy function from within any callback.
193 *
194 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
195 */
196 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetRetryPolicy, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY, retryPolicy, size_t, retryTimeoutLimitInSeconds);
197
198
199 /**
200 * @brief Sets up the connection status callback to be invoked representing the status of
201 * the connection to IOT Hub. This is a blocking call.
202 *
203 * @param iotHubClientHandle The handle created by a call to the create function.
204 * @param retryPolicy Out parameter containing the policy to use to reconnect to IoT Hub.
205 * @param retryTimeoutLimitInSeconds Out parameter containing maximum amount of time in seconds to attempt reconnection
206 to IOT Hub.
207 *
208 * @b NOTE: The application behavior is undefined if the user calls
209 * the ::IoTHubClient_LL_Destroy function from within any callback.
210 *
211 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
212 */
213 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_GetRetryPolicy, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY*, retryPolicy, size_t*, retryTimeoutLimitInSeconds);
214
215 /**
216 * @brief This function returns in the out parameter @p lastMessageReceiveTime
217 * what was the value of the @c time function when the last message was
218 * received at the client.
219 *
220 * @param iotHubClientHandle The handle created by a call to the create function.
221 * @param lastMessageReceiveTime Out parameter containing the value of @c time function
222 * when the last message was received.
223 *
224 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
225 */
226 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_GetLastMessageReceiveTime, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, time_t*, lastMessageReceiveTime);
227
228 /**
229 * @brief This function is meant to be called by the user when work
230 * (sending/receiving) can be done by the IoTHubClient.
231 *
232 * @param iotHubClientHandle The handle created by a call to the create function.
233 *
234 * All IoTHubClient interactions (in regards to network traffic
235 * and/or user level callbacks) are the effect of calling this
236 * function and they take place synchronously inside _DoWork.
237 */
238 MOCKABLE_FUNCTION(, void, IoTHubClient_LL_DoWork, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle);
239
240 /**
241 * @brief This API sets a runtime option identified by parameter @p optionName
242 * to a value pointed to by @p value. @p optionName and the data type
243 * @p value is pointing to are specific for every option.
244 *
245 * @param iotHubClientHandle The handle created by a call to the create function.
246 * @param optionName Name of the option.
247 * @param value The value.
248 *
249 * The options that can be set via this API are:
250 * - @b timeout - the maximum time in milliseconds a communication is
251 * allowed to use. @p value is a pointer to an @c unsigned @c int with
252 * the timeout value in milliseconds. This is only supported for the HTTP
253 * protocol as of now. When the HTTP protocol uses CURL, the meaning of
254 * the parameter is <em>total request time</em>. When the HTTP protocol uses
255 * winhttp, the meaning is the same as the @c dwSendTimeout and
256 * @c dwReceiveTimeout parameters of the
257 * <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384116(v=vs.85).aspx">
258 * WinHttpSetTimeouts</a> API.
259 * - @b CURLOPT_LOW_SPEED_LIMIT - only available for HTTP protocol and only
260 * when CURL is used. It has the same meaning as CURL's option with the same
261 * name. @p value is pointer to a long.
262 * - @b CURLOPT_LOW_SPEED_TIME - only available for HTTP protocol and only
263 * when CURL is used. It has the same meaning as CURL's option with the same
264 * name. @p value is pointer to a long.
265 * - @b CURLOPT_FORBID_REUSE - only available for HTTP protocol and only
266 * when CURL is used. It has the same meaning as CURL's option with the same
267 * name. @p value is pointer to a long.
268 * - @b CURLOPT_FRESH_CONNECT - only available for HTTP protocol and only
269 * when CURL is used. It has the same meaning as CURL's option with the same
270 * name. @p value is pointer to a long.
271 * - @b CURLOPT_VERBOSE - only available for HTTP protocol and only
272 * when CURL is used. It has the same meaning as CURL's option with the same
273 * name. @p value is pointer to a long.
274 * - @b keepalive - available for MQTT protocol. Integer value that sets the
275 * interval in seconds when pings are sent to the server.
276 * - @b logtrace - available for MQTT protocol. Boolean value that turns on and
277 * off the diagnostic logging.
278 * - @b sas_token_lifetime - available for MQTT & AMQP protocol. size_t value that that determines the
279 * sas token timeout length.
280 *
281 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
282 */
283 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetOption, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, optionName, const void*, value);
284
285 /**
286 * @brief This API specifies a call back to be used when the device receives a desired state update.
287 *
288 * @param iotHubClientHandle The handle created by a call to the create function.
289 * @param deviceTwinCallback The callback specified by the device client to be used for updating
290 * the desired state. The callback will be called in response to patch
291 * request send by the IoTHub services. The payload will be passed to the
292 * callback, along with two version numbers:
293 * - Desired:
294 * - LastSeenReported:
295 * @param userContextCallback User specified context that will be provided to the
296 * callback. This can be @c NULL.
297 *
298 * @b NOTE: The application behavior is undefined if the user calls
299 * the ::IoTHubClient_LL_Destroy function from within any callback.
300 *
301 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
302 */
303 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetDeviceTwinCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK, deviceTwinCallback, void*, userContextCallback);
304
305 /**
306 * @brief This API sneds a report of the device's properties and their current values.
307 *
308 * @param iotHubClientHandle The handle created by a call to the create function.
309 * @param reportedState The current device property values to be 'reported' to the IoTHub.
310 * @param reportedStateCallback The callback specified by the device client to be called with the
311 * result of the transaction.
312 * @param userContextCallback User specified context that will be provided to the
313 * callback. This can be @c NULL.
314 *
315 * @b NOTE: The application behavior is undefined if the user calls
316 * the ::IoTHubClient_LL_Destroy function from within any callback.
317 *
318 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
319 */
320 MOCKABLE_FUNCTION(, 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);
321
322 /**
323 * @brief This API sets callback for cloud to device method call.
324 *
325 * @param iotHubClientHandle The handle created by a call to the create function.
326 * @param deviceMethodCallback The callback which will be called by IoTHub.
327 * @param userContextCallback User specified context that will be provided to the
328 * callback. This can be @c NULL.
329 *
330 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
331 */
332 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetDeviceMethodCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC, deviceMethodCallback, void*, userContextCallback);
333
334 /**
335 * @brief This API sets callback for async cloud to device method call.
336 *
337 * @param iotHubClientHandle The handle created by a call to the create function.
338 * @param inboundDeviceMethodCallback The callback which will be called by IoTHub.
339 * @param userContextCallback User specified context that will be provided to the
340 * callback. This can be @c NULL.
341 *
342 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
343 */
344 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetDeviceMethodCallback_Ex, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK, inboundDeviceMethodCallback, void*, userContextCallback);
345
346 /**
347 * @brief This API responses to a asnyc method callback identified the methodId.
348 *
349 * @param iotHubClientHandle The handle created by a call to the create function.
350 * @param methodId The methodId of the Device Method callback.
351 * @param response The response data for the method callback.
352 * @param response_size The size of the response data buffer.
353 * @param status_response The status response of the method callback.
354 *
355 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
356 */
357 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_DeviceMethodResponse, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, METHOD_HANDLE, methodId, const unsigned char*, response, size_t, respSize, int, statusCode);
358
359#ifndef DONT_USE_UPLOADTOBLOB
360 /**
361 * @brief This API uploads to Azure Storage the content pointed to by @p source having the size @p size
362 * under the blob name devicename/@pdestinationFileName
363 *
364 * @param iotHubClientHandle The handle created by a call to the create function.
365 * @param destinationFileName name of the file.
366 * @param source pointer to the source for file content (can be NULL)
367 * @param size the size of the source in memory (if @p source is NULL then size needs to be 0).
368 *
369 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
370 */
371 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, destinationFileName, const unsigned char*, source, size_t, size);
372
373 /**
374 ** DEPRECATED: Use IoTHubClient_LL_UploadMultipleBlocksToBlobAsyncEx instead **
375 * @brief This API uploads to Azure Storage the content provided block by block by @p getDataCallback
376 * under the blob name devicename/@pdestinationFileName
377 *
378 * @param iotHubClientHandle The handle created by a call to the create function.
379 * @param destinationFileName name of the file.
380 * @param getDataCallback 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.
381 * @param context Any data provided by the user to serve as context on getDataCallback.
382 *
383 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
384 ** DEPRECATED: Use IoTHubClient_LL_UploadMultipleBlocksToBlobAsyncEx instead **
385 */
386 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadMultipleBlocksToBlob, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, destinationFileName, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK, getDataCallback, void*, context);
387
388 /**
389 * @brief This API uploads to Azure Storage the content provided block by block by @p getDataCallback
390 * under the blob name devicename/@pdestinationFileName
391 *
392 * @param iotHubClientHandle The handle created by a call to the create function.
393 * @param destinationFileName name of the file.
394 * @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.
395 * @param context Any data provided by the user to serve as context on getDataCallback.
396 *
397 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
398 */
399 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadMultipleBlocksToBlobEx, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, destinationFileName, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX, getDataCallbackEx, void*, context);
400
401#endif /*DONT_USE_UPLOADTOBLOB*/
402
403#ifdef __cplusplus
404}
405#endif
406
407#endif /* IOTHUB_CLIENT_LL_H */
Note: See TracBrowser for help on using the repository browser.