source: azure_iot_hub/trunk/azure_iothub/iothub_client/inc/iothub_client_ll.h@ 389

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

ビルドが通るよう更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 24.2 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 "azure_c_shared_utility/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 *
126 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
127 */
128 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);
129
130 /**
131 * @brief This function returns the current sending status for IoTHubClient.
132 *
133 * @param iotHubClientHandle The handle created by a call to the create function.
134 * @param iotHubClientStatus The sending state is populated at the address pointed
135 * at by this parameter. The value will be set to
136 * @c IOTHUBCLIENT_SENDSTATUS_IDLE if there is currently
137 * no item to be sent and @c IOTHUBCLIENT_SENDSTATUS_BUSY
138 * if there are.
139 *
140 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
141 */
142 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_GetSendStatus, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_STATUS*, iotHubClientStatus);
143
144 /**
145 * @brief Sets up the message callback to be invoked when IoT Hub issues a
146 * message to the device. This is a blocking call.
147 *
148 * @param iotHubClientHandle The handle created by a call to the create function.
149 * @param messageCallback The callback specified by the device for receiving
150 * messages from IoT Hub.
151 * @param userContextCallback User specified context that will be provided to the
152 * callback. This can be @c NULL.
153 *
154 * @b NOTE: The application behavior is undefined if the user calls
155 * the ::IoTHubClient_LL_Destroy function from within any callback.
156 *
157 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
158 */
159 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetMessageCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC, messageCallback, void*, userContextCallback);
160
161 /**
162 * @brief Sets up the connection status callback to be invoked representing the status of
163 * the connection to IOT Hub. This is a blocking call.
164 *
165 * @param iotHubClientHandle The handle created by a call to the create function.
166 * @param connectionStatusCallback The callback specified by the device for receiving
167 * updates about the status of the connection to IoT Hub.
168 * @param userContextCallback User specified context that will be provided to the
169 * callback. This can be @c NULL.
170 *
171 * @b NOTE: The application behavior is undefined if the user calls
172 * the ::IoTHubClient_LL_Destroy function from within any callback.
173 *
174 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
175 */
176 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetConnectionStatusCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK, connectionStatusCallback, void*, userContextCallback);
177
178 /**
179 * @brief Sets up the connection status callback to be invoked representing the status of
180 * the connection to IOT Hub. This is a blocking call.
181 *
182 * @param iotHubClientHandle The handle created by a call to the create function.
183 * @param retryPolicy The policy to use to reconnect to IoT Hub when a
184 * connection drops.
185 * @param retryTimeoutLimitInSeconds Maximum amount of time(seconds) to attempt reconnection when a
186 * connection drops to IOT Hub.
187 *
188 * @b NOTE: The application behavior is undefined if the user calls
189 * the ::IoTHubClient_LL_Destroy function from within any callback.
190 *
191 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
192 */
193 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetRetryPolicy, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY, retryPolicy, size_t, retryTimeoutLimitInSeconds);
194
195
196 /**
197 * @brief Sets up the connection status callback to be invoked representing the status of
198 * the connection to IOT Hub. This is a blocking call.
199 *
200 * @param iotHubClientHandle The handle created by a call to the create function.
201 * @param retryPolicy Out parameter containing the policy to use to reconnect to IoT Hub.
202 * @param retryTimeoutLimitInSeconds Out parameter containing maximum amount of time in seconds to attempt reconnection
203 to IOT Hub.
204 *
205 * @b NOTE: The application behavior is undefined if the user calls
206 * the ::IoTHubClient_LL_Destroy function from within any callback.
207 *
208 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
209 */
210 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_GetRetryPolicy, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY*, retryPolicy, size_t*, retryTimeoutLimitInSeconds);
211
212 /**
213 * @brief This function returns in the out parameter @p lastMessageReceiveTime
214 * what was the value of the @c time function when the last message was
215 * received at the client.
216 *
217 * @param iotHubClientHandle The handle created by a call to the create function.
218 * @param lastMessageReceiveTime Out parameter containing the value of @c time function
219 * when the last message was received.
220 *
221 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
222 */
223 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_GetLastMessageReceiveTime, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, time_t*, lastMessageReceiveTime);
224
225 /**
226 * @brief This function is meant to be called by the user when work
227 * (sending/receiving) can be done by the IoTHubClient.
228 *
229 * @param iotHubClientHandle The handle created by a call to the create function.
230 *
231 * All IoTHubClient interactions (in regards to network traffic
232 * and/or user level callbacks) are the effect of calling this
233 * function and they take place synchronously inside _DoWork.
234 */
235 MOCKABLE_FUNCTION(, void, IoTHubClient_LL_DoWork, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle);
236
237 /**
238 * @brief This API sets a runtime option identified by parameter @p optionName
239 * to a value pointed to by @p value. @p optionName and the data type
240 * @p value is pointing to are specific for every option.
241 *
242 * @param iotHubClientHandle The handle created by a call to the create function.
243 * @param optionName Name of the option.
244 * @param value The value.
245 *
246 * The options that can be set via this API are:
247 * - @b timeout - the maximum time in milliseconds a communication is
248 * allowed to use. @p value is a pointer to an @c unsigned @c int with
249 * the timeout value in milliseconds. This is only supported for the HTTP
250 * protocol as of now. When the HTTP protocol uses CURL, the meaning of
251 * the parameter is <em>total request time</em>. When the HTTP protocol uses
252 * winhttp, the meaning is the same as the @c dwSendTimeout and
253 * @c dwReceiveTimeout parameters of the
254 * <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384116(v=vs.85).aspx">
255 * WinHttpSetTimeouts</a> API.
256 * - @b CURLOPT_LOW_SPEED_LIMIT - only available for HTTP protocol and only
257 * when CURL is used. It has the same meaning as CURL's option with the same
258 * name. @p value is pointer to a long.
259 * - @b CURLOPT_LOW_SPEED_TIME - 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_FORBID_REUSE - 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_FRESH_CONNECT - 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_VERBOSE - 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 keepalive - available for MQTT protocol. Integer value that sets the
272 * interval in seconds when pings are sent to the server.
273 * - @b logtrace - available for MQTT protocol. Boolean value that turns on and
274 * off the diagnostic logging.
275 * - @b sas_token_lifetime - available for MQTT & AMQP protocol. size_t value that that determines the
276 * sas token timeout length.
277 *
278 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
279 */
280 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetOption, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, optionName, const void*, value);
281
282 /**
283 * @brief This API specifies a call back to be used when the device receives a desired state update.
284 *
285 * @param iotHubClientHandle The handle created by a call to the create function.
286 * @param deviceTwinCallback The callback specified by the device client to be used for updating
287 * the desired state. The callback will be called in response to patch
288 * request send by the IoTHub services. The payload will be passed to the
289 * callback, along with two version numbers:
290 * - Desired:
291 * - LastSeenReported:
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 ::IoTHubClient_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, IoTHubClient_LL_SetDeviceTwinCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK, deviceTwinCallback, void*, userContextCallback);
301
302 /**
303 * @brief This API sneds a report of the device's properties and their current values.
304 *
305 * @param iotHubClientHandle The handle created by a call to the create function.
306 * @param reportedState The current device property values to be 'reported' to the IoTHub.
307 * @param reportedStateCallback The callback specified by the device client to be called with the
308 * result of the transaction.
309 * @param userContextCallback User specified context that will be provided to the
310 * callback. This can be @c NULL.
311 *
312 * @b NOTE: The application behavior is undefined if the user calls
313 * the ::IoTHubClient_LL_Destroy function from within any callback.
314 *
315 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
316 */
317 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);
318
319 /**
320 * @brief This API sets callback for cloud to device method call.
321 *
322 * @param iotHubClientHandle The handle created by a call to the create function.
323 * @param deviceMethodCallback The callback which will be called by IoTHub.
324 * @param userContextCallback User specified context that will be provided to the
325 * callback. This can be @c NULL.
326 *
327 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
328 */
329 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetDeviceMethodCallback, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC, deviceMethodCallback, void*, userContextCallback);
330
331 /**
332 * @brief This API sets callback for async cloud to device method call.
333 *
334 * @param iotHubClientHandle The handle created by a call to the create function.
335 * @param inboundDeviceMethodCallback The callback which will be called by IoTHub.
336 * @param userContextCallback User specified context that will be provided to the
337 * callback. This can be @c NULL.
338 *
339 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
340 */
341 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetDeviceMethodCallback_Ex, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK, inboundDeviceMethodCallback, void*, userContextCallback);
342
343 /**
344 * @brief This API responses to a asnyc method callback identified the methodId.
345 *
346 * @param iotHubClientHandle The handle created by a call to the create function.
347 * @param methodId The methodId of the Device Method callback.
348 * @param response The response data for the method callback.
349 * @param response_size The size of the response data buffer.
350 * @param status_response The status response of the method callback.
351 *
352 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
353 */
354 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);
355
356#ifndef DONT_USE_UPLOADTOBLOB
357 /**
358 * @brief This API uploads to Azure Storage the content pointed to by @p source having the size @p size
359 * under the blob name devicename/@pdestinationFileName
360 *
361 * @param iotHubClientHandle The handle created by a call to the create function.
362 * @param destinationFileName name of the file.
363 * @param source pointer to the source for file content (can be NULL)
364 * @param size the size of the source in memory (if @p source is NULL then size needs to be 0).
365 *
366 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
367 */
368 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, destinationFileName, const unsigned char*, source, size_t, size);
369
370 /**
371 ** DEPRECATED: Use IoTHubClient_LL_UploadMultipleBlocksToBlobAsyncEx instead **
372 * @brief This API uploads to Azure Storage the content provided block by block by @p getDataCallback
373 * under the blob name devicename/@pdestinationFileName
374 *
375 * @param iotHubClientHandle The handle created by a call to the create function.
376 * @param destinationFileName name of the file.
377 * @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.
378 * @param context Any data provided by the user to serve as context on getDataCallback.
379 *
380 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
381 ** DEPRECATED: Use IoTHubClient_LL_UploadMultipleBlocksToBlobAsyncEx instead **
382 */
383 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);
384
385 /**
386 * @brief This API uploads to Azure Storage the content provided block by block by @p getDataCallback
387 * under the blob name devicename/@pdestinationFileName
388 *
389 * @param iotHubClientHandle The handle created by a call to the create function.
390 * @param destinationFileName name of the file.
391 * @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.
392 * @param context Any data provided by the user to serve as context on getDataCallback.
393 *
394 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
395 */
396 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);
397
398#endif /*DONT_USE_UPLOADTOBLOB*/
399
400#ifdef __cplusplus
401}
402#endif
403
404#endif /* IOTHUB_CLIENT_LL_H */
Note: See TracBrowser for help on using the repository browser.