source: azure_iot_hub_f767zi/trunk/azure_iot_sdk/iothub_client/inc/iothub_client.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: 25.0 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.h
5* @brief Extends the IoTHubCLient_LL module with additional features.
6*
7* @note DEPRECATED. New users use iothub_device_client.h for IoTHubClient APIs.
8* @details IoTHubClient is a module that extends the IoTHubCLient_LL
9* module with 2 features:
10* - scheduling the work for the IoTHubCLient from a
11* thread, so that the user does not need to create their
12* own thread
13* - thread-safe APIs
14*/
15
16#ifndef IOTHUB_CLIENT_H
17#define IOTHUB_CLIENT_H
18
19#include <stddef.h>
20#include <stdint.h>
21
22#include "umock_c/umock_c_prod.h"
23#include "iothub_transport_ll.h"
24#include "iothub_client_core_ll.h"
25#include "iothub_client_core.h"
26#include "iothub_client_ll.h"
27
28#ifndef IOTHUB_CLIENT_INSTANCE_TYPE
29typedef IOTHUB_CLIENT_CORE_HANDLE IOTHUB_CLIENT_HANDLE;
30#define IOTHUB_CLIENT_INSTANCE_TYPE
31#endif // IOTHUB_CLIENT_INSTANCE
32
33
34#ifdef __cplusplus
35extern "C"
36{
37#endif
38
39 /**
40 * @brief Creates a IoT Hub client for communication with an existing
41 * IoT Hub using the specified connection string parameter.
42 *
43 * @param connectionString Pointer to a character string
44 * @param protocol Function pointer for protocol implementation
45 *
46 * Sample connection string:
47 * <blockquote>
48 * <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>
49 * <pre>HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];DeviceId=[Device ID goes here];SharedAccessSignature=SharedAccessSignature sr=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net]/devices/[Device ID goes here]&sig=[SAS Token goes here]&se=[Expiry Time goes here];</pre>
50 * </blockquote>
51 *
52 * @return A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
53 * invoking other functions for IoT Hub client and @c NULL on failure.
54 */
55 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_HANDLE, IoTHubClient_CreateFromConnectionString, const char*, connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol);
56
57 /**
58 * @brief Creates a IoT Hub client for communication with an existing IoT
59 * Hub using the specified parameters.
60 *
61 * @param config Pointer to an @c IOTHUB_CLIENT_CONFIG structure
62 *
63 * The API does not allow sharing of a connection across multiple
64 * devices. This is a blocking call.
65 *
66 * @return A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
67 * invoking other functions for IoT Hub client and @c NULL on failure.
68 */
69 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_HANDLE, IoTHubClient_Create, const IOTHUB_CLIENT_CONFIG*, config);
70
71 /**
72 * @brief Creates a IoT Hub client for communication with an existing IoT
73 * Hub using the specified parameters.
74 *
75 * @param transportHandle TRANSPORT_HANDLE which represents a connection.
76 * @param config Pointer to an @c IOTHUB_CLIENT_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_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_HANDLE, IoTHubClient_CreateWithTransport, TRANSPORT_HANDLE, transportHandle, const IOTHUB_CLIENT_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 protocol Function pointer for protocol implementation
93 *
94 * @return A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when
95 * invoking other functions for IoT Hub client and @c NULL on failure.
96 */
97 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_HANDLE, IoTHubClient_CreateFromDeviceAuth, const char*, iothub_uri, const char*, device_id, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol);
98
99 /**
100 * @brief Disposes of resources allocated by the IoT Hub client. This is a
101 * blocking call.
102 *
103 * @param iotHubClientHandle The handle created by a call to the create function.
104 */
105 MOCKABLE_FUNCTION(, void, IoTHubClient_Destroy, IOTHUB_CLIENT_HANDLE, iotHubClientHandle);
106
107 /**
108 * @brief Asynchronous call to send the message specified by @p eventMessageHandle.
109 *
110 * @param iotHubClientHandle The handle created by a call to the create function.
111 * @param eventMessageHandle The handle to an IoT Hub message.
112 * @param eventConfirmationCallback The callback specified by the device for receiving
113 * confirmation of the delivery of the IoT Hub message.
114 * This callback can be expected to invoke the
115 * ::IoTHubClient_SendEventAsync function for the
116 * same message in an attempt to retry sending a failing
117 * message. The user can specify a @c NULL value here to
118 * indicate that no callback is required.
119 * @param userContextCallback User specified context that will be provided to the
120 * callback. This can be @c NULL.
121 *
122 * @b NOTE: The application behavior is undefined if the user calls
123 * the ::IoTHubClient_Destroy function from within any callback.
124 * @remarks
125 * The IOTHUB_MESSAGE_HANDLE instance provided as argument is copied by the function,
126 * so this argument can be destroyed by the calling application right after IoTHubClient_SendEventAsync returns.
127 * 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.
128 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
129 */
130 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SendEventAsync, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_MESSAGE_HANDLE, eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, eventConfirmationCallback, void*, userContextCallback);
131
132 /**
133 * @brief This function returns the current sending status for IoTHubClient.
134 *
135 * @param iotHubClientHandle The handle created by a call to the create function.
136 * @param iotHubClientStatus The sending state is populated at the address pointed
137 * at by this parameter. The value will be set to
138 * @c IOTHUBCLIENT_SENDSTATUS_IDLE if there is currently
139 * no item to be sent and @c IOTHUBCLIENT_SENDSTATUS_BUSY
140 * if there are.
141 *
142 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
143 */
144 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_GetSendStatus, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_STATUS*, iotHubClientStatus);
145
146 /**
147 * @brief Sets up the message callback to be invoked when IoT Hub issues a
148 * message to the device. This is a blocking call.
149 *
150 * @param iotHubClientHandle The handle created by a call to the create function.
151 * @param messageCallback The callback specified by the device for receiving
152 * messages from IoT Hub.
153 * @param userContextCallback User specified context that will be provided to the
154 * callback. This can be @c NULL.
155 *
156 * @b NOTE: The application behavior is undefined if the user calls
157 * the ::IoTHubClient_Destroy function from within any callback.
158 *
159 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
160 */
161 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetMessageCallback, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC, messageCallback, void*, userContextCallback);
162
163 /**
164 * @brief Sets up the connection status callback to be invoked representing the status of
165 * the connection to IOT Hub. This is a blocking call.
166 *
167 * @param iotHubClientHandle The handle created by a call to the create function.
168 * @param connectionStatusCallback The callback specified by the device for receiving
169 * updates about the status of the connection to IoT Hub.
170 * @param userContextCallback User specified context that will be provided to the
171 * callback. This can be @c NULL.
172 *
173 * @b NOTE: The application behavior is undefined if the user calls
174 * the ::IoTHubClient_LL_Destroy function from within any callback.
175 *
176 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
177 */
178 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetConnectionStatusCallback, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK, connectionStatusCallback, void*, userContextCallback);
179
180 /**
181 * @brief Sets up the connection status callback to be invoked representing the status of
182 * the connection to IOT Hub. This is a blocking call.
183 *
184 * @param iotHubClientHandle The handle created by a call to the create function.
185 * @param retryPolicy The policy to use to reconnect to IoT Hub when a
186 * connection drops.
187 * @param retryTimeoutLimitInSeconds Maximum amount of time(seconds) to attempt reconnection when a
188 * connection drops to IOT Hub.
189 *
190 * @b NOTE: The application behavior is undefined if the user calls
191 * the ::IoTHubClient_LL_Destroy function from within any callback.
192 *
193 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
194 */
195 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetRetryPolicy, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY, retryPolicy, size_t, retryTimeoutLimitInSeconds);
196
197 /**
198 * @brief Sets up the connection status callback to be invoked representing the status of
199 * the connection to IOT Hub. This is a blocking call.
200 *
201 * @param iotHubClientHandle The handle created by a call to the create function.
202 * @param retryPolicy Out parameter containing the policy to use to reconnect to IoT Hub.
203 * @param retryTimeoutLimitInSeconds Out parameter containing maximum amount of time in seconds to attempt reconnection
204 to IOT Hub.
205 *
206 * @b NOTE: The application behavior is undefined if the user calls
207 * the ::IoTHubClient_LL_Destroy function from within any callback.
208 *
209 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
210 */
211 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_GetRetryPolicy, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_RETRY_POLICY*, retryPolicy, size_t*, retryTimeoutLimitInSeconds);
212
213 /**
214 * @brief This function returns in the out parameter @p lastMessageReceiveTime
215 * what was the value of the @c time function when the last message was
216 * received at the client.
217 *
218 * @param iotHubClientHandle The handle created by a call to the create function.
219 * @param lastMessageReceiveTime Out parameter containing the value of @c time function
220 * when the last message was received.
221 *
222 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
223 */
224 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_GetLastMessageReceiveTime, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, time_t*, lastMessageReceiveTime);
225
226 /**
227 * @brief This API sets a runtime option identified by parameter @p optionName
228 * to a value pointed to by @p value. @p optionName and the data type
229 * @p value is pointing to are specific for every option.
230 *
231 * @param iotHubClientHandle The handle created by a call to the create function.
232 * @param optionName Name of the option.
233 * @param value The value.
234 *
235 * The options that can be set via this API are:
236 * - @b timeout - the maximum time in milliseconds a communication is
237 * allowed to use. @p value is a pointer to an @c unsigned @c int with
238 * the timeout value in milliseconds. This is only supported for the HTTP
239 * protocol as of now. When the HTTP protocol uses CURL, the meaning of
240 * the parameter is <em>total request time</em>. When the HTTP protocol uses
241 * winhttp, the meaning is the same as the @c dwSendTimeout and
242 * @c dwReceiveTimeout parameters of the
243 * <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384116(v=vs.85).aspx">
244 * WinHttpSetTimeouts</a> API.
245 * - @b CURLOPT_LOW_SPEED_LIMIT - only available for HTTP protocol and only
246 * when CURL is used. It has the same meaning as CURL's option with the same
247 * name. @p value is pointer to a long.
248 * - @b CURLOPT_LOW_SPEED_TIME - only available for HTTP protocol and only
249 * when CURL is used. It has the same meaning as CURL's option with the same
250 * name. @p value is pointer to a long.
251 * - @b CURLOPT_FORBID_REUSE - only available for HTTP protocol and only
252 * when CURL is used. It has the same meaning as CURL's option with the same
253 * name. @p value is pointer to a long.
254 * - @b CURLOPT_FRESH_CONNECT - only available for HTTP protocol and only
255 * when CURL is used. It has the same meaning as CURL's option with the same
256 * name. @p value is pointer to a long.
257 * - @b CURLOPT_VERBOSE - only available for HTTP protocol and only
258 * when CURL is used. It has the same meaning as CURL's option with the same
259 * name. @p value is pointer to a long.
260 * - @b messageTimeout - the maximum time in milliseconds until a message
261 * is timeouted. The time starts at IoTHubClient_SendEventAsync. By default,
262 * messages do not expire. @p is a pointer to a uint64_t
263 * - @b svc2cl_keep_alive_timeout_secs - the AMQP service side keep alive interval in seconds.
264 * After the connection established the client requests the server to set the
265 * keep alive interval for given time.
266 * If it is not set then the default 240 sec applies.
267 * If it is set to zero the server will not send keep alive messages to the client.
268 * - @b cl2svc_keep_alive_send_ratio - the AMQP client side keep alive interval in seconds.
269 * After the connection established the server requests the client to set the
270 * keep alive interval for given time.
271 * If it is not set then the default ratio of 1/2 is applied.
272 * The ratio has to be greater than 0.0 and equal to or less than 0.9
273
274 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
275 */
276 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetOption, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, const char*, optionName, const void*, value);
277
278 /**
279 * @brief This API specifies a call back to be used when the device receives a state update.
280 *
281 * @param iotHubClientHandle The handle created by a call to the create function.
282 * @param deviceTwinCallback The callback specified by the device client to be used for updating
283 * the desired state. The callback will be called in response to a
284 * request send by the IoTHub services. The payload will be passed to the
285 * callback, along with two version numbers:
286 * - Desired:
287 * - LastSeenReported:
288 * @param userContextCallback User specified context that will be provided to the
289 * callback. This can be @c NULL.
290 *
291 * @b NOTE: The application behavior is undefined if the user calls
292 * the ::IoTHubClient_Destroy function from within any callback.
293 *
294 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
295 */
296 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetDeviceTwinCallback, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK, deviceTwinCallback, void*, userContextCallback);
297
298 /**
299 * @brief This API sends a report of the device's properties and their current values.
300 *
301 * @param iotHubClientHandle The handle created by a call to the create function.
302 * @param reportedState The current device property values to be 'reported' to the IoTHub.
303 * @param reportedStateCallback The callback specified by the device client to be called with the
304 * result of the transaction.
305 * @param userContextCallback User specified context that will be provided to the
306 * callback. This can be @c NULL.
307 *
308 * @b NOTE: The application behavior is undefined if the user calls
309 * the ::IoTHubClient_Destroy function from within any callback.
310 *
311 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
312 */
313 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SendReportedState, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, const unsigned char*, reportedState, size_t, size, IOTHUB_CLIENT_REPORTED_STATE_CALLBACK, reportedStateCallback, void*, userContextCallback);
314
315 /**
316 * @brief This API sets callback for cloud to device method call.
317 *
318 * @param iotHubClientHandle The handle created by a call to the create function.
319 * @param deviceMethodCallback The callback which will be called by IoTHub.
320 * @param userContextCallback User specified context that will be provided to the
321 * callback. This can be @c NULL.
322 *
323 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
324 */
325 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetDeviceMethodCallback, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC, deviceMethodCallback, void*, userContextCallback);
326
327 /**
328 * @brief This API sets callback for async cloud to device method call.
329 *
330 * @param iotHubClientHandle The handle created by a call to the create function.
331 * @param inboundDeviceMethodCallback The callback which will be called by IoTHub.
332 * @param userContextCallback User specified context that will be provided to the
333 * callback. This can be @c NULL.
334 *
335 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
336 */
337 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_SetDeviceMethodCallback_Ex, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK, inboundDeviceMethodCallback, void*, userContextCallback);
338
339 /**
340 * @brief This API responses to a asnyc method callback identified the methodId.
341 *
342 * @param iotHubClientHandle The handle created by a call to the create function.
343 * @param methodId The methodId of the Device Method callback.
344 * @param response The response data for the method callback.
345 * @param response_size The size of the response data buffer.
346 * @param status_response The status response of the method callback.
347 *
348 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
349 */
350 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_DeviceMethodResponse, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, METHOD_HANDLE, methodId, const unsigned char*, response, size_t, response_size, int, statusCode);
351
352#ifndef DONT_USE_UPLOADTOBLOB
353 /**
354 * @brief IoTHubClient_UploadToBlobAsync uploads data from memory to a file in Azure Blob Storage.
355 *
356 * @param iotHubClientHandle The handle created by a call to the IoTHubClient_Create function.
357 * @param destinationFileName The name of the file to be created in Azure Blob Storage.
358 * @param source The source of data.
359 * @param size The size of data.
360 * @param iotHubClientFileUploadCallback A callback to be invoked when the file upload operation has finished.
361 * @param context A user-provided context to be passed to the file upload callback.
362 *
363 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
364 */
365 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_UploadToBlobAsync, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, const char*, destinationFileName, const unsigned char*, source, size_t, size, IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK, iotHubClientFileUploadCallback, void*, context);
366
367 /**
368 ** DEPRECATED: Use IoTHubClient_UploadMultipleBlocksToBlobAsyncEx instead **
369 * @brief Uploads a file to a Blob storage in chunks, fed through the callback function provided by the user.
370 * @remarks This function allows users to upload large files in chunks, not requiring the whole file content to be passed in memory.
371 * @param iotHubClientHandle The handle created by a call to the IoTHubClient_Create function.
372 * @param destinationFileName The name of the file to be created in Azure Blob Storage.
373 * @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.
374 * @param context Any data provided by the user to serve as context on getDataCallback.
375 * @returns An IOTHUB_CLIENT_RESULT value indicating the success or failure of the API call.
376 ** DEPRECATED: Use IoTHubClient_UploadMultipleBlocksToBlobAsyncEx instead **
377 */
378 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_UploadMultipleBlocksToBlobAsync, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, const char*, destinationFileName, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK, getDataCallback, void*, context);
379
380 /**
381 * @brief Uploads a file to a Blob storage in chunks, fed through the callback function provided by the user.
382 * @remarks This function allows users to upload large files in chunks, not requiring the whole file content to be passed in memory.
383 * @param iotHubClientHandle The handle created by a call to the IoTHubClient_Create function.
384 * @param destinationFileName The name of the file to be created in Azure Blob Storage.
385 * @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.
386 * @param context Any data provided by the user to serve as context on getDataCallback.
387 * @returns An IOTHUB_CLIENT_RESULT value indicating the success or failure of the API call.*/
388 MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_UploadMultipleBlocksToBlobAsyncEx, IOTHUB_CLIENT_HANDLE, iotHubClientHandle, const char*, destinationFileName, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX, getDataCallbackEx, void*, context);
389
390#endif /* DONT_USE_UPLOADTOBLOB */
391
392#ifdef __cplusplus
393}
394#endif
395
396#endif /* IOTHUB_CLIENT_H */
Note: See TracBrowser for help on using the repository browser.