demo project

Dependencies:   AX-12A Dynamixel mbed iothub_client EthernetInterface NTPClient ConfigFile SDFileSystem iothub_amqp_transport mbed-rtos proton-c-mbed wolfSSL

Committer:
henryrawas
Date:
Thu Feb 04 20:10:33 2016 +0000
Revision:
33:8b9dcbf6d8ec
Parent:
21:051751f9ca9e
update libs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
henryrawas 21:051751f9ca9e 1 // Copyright (c) Microsoft. All rights reserved.
henryrawas 21:051751f9ca9e 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
henryrawas 21:051751f9ca9e 3
henryrawas 21:051751f9ca9e 4 // iothub_mod_client.h : modified version of iothub_client.h
henryrawas 21:051751f9ca9e 5
henryrawas 21:051751f9ca9e 6 /** @file iothub_client.h
henryrawas 21:051751f9ca9e 7 * @brief Extends the IoTHubCLient_LL module with additional features.
henryrawas 21:051751f9ca9e 8 *
henryrawas 21:051751f9ca9e 9 * @details IoTHubClient is a module that extends the IoTHubCLient_LL
henryrawas 21:051751f9ca9e 10 * module with 2 features:
henryrawas 21:051751f9ca9e 11 * - scheduling the work for the IoTHubCLient from a
henryrawas 21:051751f9ca9e 12 * thread, so that the user does not need to create their
henryrawas 21:051751f9ca9e 13 * own thread
henryrawas 21:051751f9ca9e 14 * - thread-safe APIs
henryrawas 21:051751f9ca9e 15 */
henryrawas 21:051751f9ca9e 16
henryrawas 21:051751f9ca9e 17 #ifndef IOTHUB_MOD_CLIENT_H
henryrawas 21:051751f9ca9e 18
henryrawas 21:051751f9ca9e 19 #include "iothub_client_ll.h"
henryrawas 21:051751f9ca9e 20
henryrawas 21:051751f9ca9e 21 #ifdef __cplusplus
henryrawas 21:051751f9ca9e 22 extern "C"
henryrawas 21:051751f9ca9e 23 {
henryrawas 21:051751f9ca9e 24 #endif
henryrawas 21:051751f9ca9e 25
henryrawas 21:051751f9ca9e 26 typedef void* IOTHUB_CLIENT_HANDLE;
henryrawas 21:051751f9ca9e 27
henryrawas 21:051751f9ca9e 28 typedef void (*IOTHUB_CLIENT_SEND_CALLBACK)(IOTHUB_CLIENT_HANDLE iotHubClientHandle, void* userContextCallback);
henryrawas 21:051751f9ca9e 29
henryrawas 21:051751f9ca9e 30 /**
henryrawas 21:051751f9ca9e 31 * @brief Creates a IoT Hub client for communication with an existing
henryrawas 21:051751f9ca9e 32 * IoT Hub using the specified connection string parameter.
henryrawas 21:051751f9ca9e 33 *
henryrawas 21:051751f9ca9e 34 * @param connectionString Pointer to a character string
henryrawas 21:051751f9ca9e 35 * @param protocol Function pointer for protocol implementation
henryrawas 21:051751f9ca9e 36 *
henryrawas 21:051751f9ca9e 37 * Sample connection string:
henryrawas 21:051751f9ca9e 38 * <blockquote>
henryrawas 21:051751f9ca9e 39 * <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>
henryrawas 21:051751f9ca9e 40 * </blockquote>
henryrawas 21:051751f9ca9e 41 *
henryrawas 21:051751f9ca9e 42 * @return A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
henryrawas 21:051751f9ca9e 43 * invoking other functions for IoT Hub client and @c NULL on failure.
henryrawas 21:051751f9ca9e 44 */
henryrawas 21:051751f9ca9e 45 extern IOTHUB_CLIENT_HANDLE IoTHubClient_Mod_CreateFromConnectionString(const char* connectionString, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol);
henryrawas 21:051751f9ca9e 46
henryrawas 21:051751f9ca9e 47 /**
henryrawas 21:051751f9ca9e 48 * @brief Creates a IoT Hub client for communication with an existing IoT
henryrawas 21:051751f9ca9e 49 * Hub using the specified parameters.
henryrawas 21:051751f9ca9e 50 *
henryrawas 21:051751f9ca9e 51 * @param config Pointer to an @c IOTHUB_CLIENT_CONFIG structure
henryrawas 21:051751f9ca9e 52 *
henryrawas 21:051751f9ca9e 53 * The API does not allow sharing of a connection across multiple
henryrawas 21:051751f9ca9e 54 * devices. This is a blocking call.
henryrawas 21:051751f9ca9e 55 *
henryrawas 21:051751f9ca9e 56 * @return A non-NULL @c IOTHUB_CLIENT_HANDLE value that is used when
henryrawas 21:051751f9ca9e 57 * invoking other functions for IoT Hub client and @c NULL on failure.
henryrawas 21:051751f9ca9e 58 */
henryrawas 21:051751f9ca9e 59 extern IOTHUB_CLIENT_HANDLE IoTHubClient_Mod_Create(const IOTHUB_CLIENT_CONFIG* config);
henryrawas 21:051751f9ca9e 60
henryrawas 21:051751f9ca9e 61 /**
henryrawas 21:051751f9ca9e 62 * @brief Disposes of resources allocated by the IoT Hub client. This is a
henryrawas 21:051751f9ca9e 63 * blocking call.
henryrawas 21:051751f9ca9e 64 *
henryrawas 21:051751f9ca9e 65 * @param iotHubClientHandle The handle created by a call to the create function.
henryrawas 21:051751f9ca9e 66 */
henryrawas 21:051751f9ca9e 67 extern void IoTHubClient_Mod_Destroy(IOTHUB_CLIENT_HANDLE iotHubClientHandle);
henryrawas 21:051751f9ca9e 68
henryrawas 21:051751f9ca9e 69 /**
henryrawas 21:051751f9ca9e 70 * @brief Asynchronous call to send the message specified by @p eventMessageHandle.
henryrawas 21:051751f9ca9e 71 *
henryrawas 21:051751f9ca9e 72 * @param iotHubClientHandle The handle created by a call to the create function.
henryrawas 21:051751f9ca9e 73 * @param eventMessageHandle The handle to an IoT Hub message.
henryrawas 21:051751f9ca9e 74 * @param eventConfirmationCallback The callback specified by the device for receiving
henryrawas 21:051751f9ca9e 75 * confirmation of the delivery of the IoT Hub message.
henryrawas 21:051751f9ca9e 76 * This callback can be expected to invoke the
henryrawas 21:051751f9ca9e 77 * ::IoTHubClient_SendEventAsync function for the
henryrawas 21:051751f9ca9e 78 * same message in an attempt to retry sending a failing
henryrawas 21:051751f9ca9e 79 * message. The user can specify a @c NULL value here to
henryrawas 21:051751f9ca9e 80 * indicate that no callback is required.
henryrawas 21:051751f9ca9e 81 * @param userContextCallback User specified context that will be provided to the
henryrawas 21:051751f9ca9e 82 * callback. This can be @c NULL.
henryrawas 21:051751f9ca9e 83 *
henryrawas 21:051751f9ca9e 84 * @b NOTE: The application behavior is undefined if the user calls
henryrawas 21:051751f9ca9e 85 * the ::IoTHubClient_Destroy function from within any callback.
henryrawas 21:051751f9ca9e 86 *
henryrawas 21:051751f9ca9e 87 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
henryrawas 21:051751f9ca9e 88 */
henryrawas 21:051751f9ca9e 89 extern IOTHUB_CLIENT_RESULT IoTHubClient_Mod_SendEventAsync(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_MESSAGE_HANDLE eventMessageHandle, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK eventConfirmationCallback, void* userContextCallback);
henryrawas 21:051751f9ca9e 90
henryrawas 21:051751f9ca9e 91 /**
henryrawas 21:051751f9ca9e 92 * @brief This function returns the current sending status for IoTHubClient.
henryrawas 21:051751f9ca9e 93 *
henryrawas 21:051751f9ca9e 94 * @param iotHubClientHandle The handle created by a call to the create function.
henryrawas 21:051751f9ca9e 95 * @param iotHubClientStatus The sending state is populated at the address pointed
henryrawas 21:051751f9ca9e 96 * at by this parameter. The value will be set to
henryrawas 21:051751f9ca9e 97 * @c IOTHUBCLIENT_SENDSTATUS_IDLE if there is currently
henryrawas 21:051751f9ca9e 98 * no item to be sent and @c IOTHUBCLIENT_SENDSTATUS_BUSY
henryrawas 21:051751f9ca9e 99 * if there are.
henryrawas 21:051751f9ca9e 100 *
henryrawas 21:051751f9ca9e 101 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
henryrawas 21:051751f9ca9e 102 */
henryrawas 21:051751f9ca9e 103 extern IOTHUB_CLIENT_RESULT IoTHubClient_Mod_GetSendStatus(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_STATUS *iotHubClientStatus);
henryrawas 21:051751f9ca9e 104
henryrawas 21:051751f9ca9e 105 /**
henryrawas 21:051751f9ca9e 106 * @brief Sets up the message callback to be invoked when IoT Hub issues a
henryrawas 21:051751f9ca9e 107 * message to the device. This is a blocking call.
henryrawas 21:051751f9ca9e 108 *
henryrawas 21:051751f9ca9e 109 * @param iotHubClientHandle The handle created by a call to the create function.
henryrawas 21:051751f9ca9e 110 * @param messageCallback The callback specified by the device for receiving
henryrawas 21:051751f9ca9e 111 * messages from IoT Hub.
henryrawas 21:051751f9ca9e 112 * @param userContextCallback User specified context that will be provided to the
henryrawas 21:051751f9ca9e 113 * callback. This can be @c NULL.
henryrawas 21:051751f9ca9e 114 *
henryrawas 21:051751f9ca9e 115 * @b NOTE: The application behavior is undefined if the user calls
henryrawas 21:051751f9ca9e 116 * the ::IoTHubClient_Destroy function from within any callback.
henryrawas 21:051751f9ca9e 117 *
henryrawas 21:051751f9ca9e 118 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
henryrawas 21:051751f9ca9e 119 */
henryrawas 21:051751f9ca9e 120 extern IOTHUB_CLIENT_RESULT IoTHubClient_Mod_SetMessageCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC messageCallback, void* userContextCallback);
henryrawas 21:051751f9ca9e 121
henryrawas 21:051751f9ca9e 122 /**
henryrawas 21:051751f9ca9e 123 * @brief Sets up the callback to be invoked from IoT Hub worker thread.
henryrawas 21:051751f9ca9e 124 * Can call SendAsync from here without blocking on lock.
henryrawas 21:051751f9ca9e 125 *
henryrawas 21:051751f9ca9e 126 * @param iotHubClientHandle The handle created by a call to the create function.
henryrawas 21:051751f9ca9e 127 * @param sendCallback The callback specified by the device for sending
henryrawas 21:051751f9ca9e 128 * messages to IoT Hub.
henryrawas 21:051751f9ca9e 129 * @param userContextCallback User specified context that will be provided to the
henryrawas 21:051751f9ca9e 130 * callback. This can be @c NULL.
henryrawas 21:051751f9ca9e 131 *
henryrawas 21:051751f9ca9e 132 * @b NOTE: The application behavior is undefined if the user calls
henryrawas 21:051751f9ca9e 133 * the ::IoTHubClient_Destroy function from within any callback.
henryrawas 21:051751f9ca9e 134 *
henryrawas 21:051751f9ca9e 135 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
henryrawas 21:051751f9ca9e 136 */
henryrawas 21:051751f9ca9e 137 extern IOTHUB_CLIENT_RESULT IoTHubClient_Mod_SetSendCallback(IOTHUB_CLIENT_HANDLE iotHubClientHandle, IOTHUB_CLIENT_SEND_CALLBACK messageCallback, void* userContextCallback);
henryrawas 21:051751f9ca9e 138
henryrawas 21:051751f9ca9e 139 /**
henryrawas 21:051751f9ca9e 140 * @brief This function returns in the out parameter @p lastMessageReceiveTime
henryrawas 21:051751f9ca9e 141 * what was the value of the @c time function when the last message was
henryrawas 21:051751f9ca9e 142 * received at the client.
henryrawas 21:051751f9ca9e 143 *
henryrawas 21:051751f9ca9e 144 * @param iotHubClientHandle The handle created by a call to the create function.
henryrawas 21:051751f9ca9e 145 * @param lastMessageReceiveTime Out parameter containing the value of @c time function
henryrawas 21:051751f9ca9e 146 * when the last message was received.
henryrawas 21:051751f9ca9e 147 *
henryrawas 21:051751f9ca9e 148 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
henryrawas 21:051751f9ca9e 149 */
henryrawas 21:051751f9ca9e 150 extern IOTHUB_CLIENT_RESULT IoTHubClient_Mod_GetLastMessageReceiveTime(IOTHUB_CLIENT_HANDLE iotHubClientHandle, time_t* lastMessageReceiveTime);
henryrawas 21:051751f9ca9e 151
henryrawas 21:051751f9ca9e 152 /**
henryrawas 21:051751f9ca9e 153 * @brief This API sets a runtime option identified by parameter @p optionName
henryrawas 21:051751f9ca9e 154 * to a value pointed to by @p value. @p optionName and the data type
henryrawas 21:051751f9ca9e 155 * @p value is pointing to are specific for every option.
henryrawas 21:051751f9ca9e 156 *
henryrawas 21:051751f9ca9e 157 * @param iotHubClientHandle The handle created by a call to the create function.
henryrawas 21:051751f9ca9e 158 * @param optionName Name of the option.
henryrawas 21:051751f9ca9e 159 * @param value The value.
henryrawas 21:051751f9ca9e 160 *
henryrawas 21:051751f9ca9e 161 * The options that can be set via this API are:
henryrawas 21:051751f9ca9e 162 * - @b timeout - the maximum time in milliseconds a communication is
henryrawas 21:051751f9ca9e 163 * allowed to use. @p value is a pointer to an @c unsigned @c int with
henryrawas 21:051751f9ca9e 164 * the timeout value in milliseconds. This is only supported for the HTTP
henryrawas 21:051751f9ca9e 165 * protocol as of now. When the HTTP protocol uses CURL, the meaning of
henryrawas 21:051751f9ca9e 166 * the parameter is <em>total request time</em>. When the HTTP protocol uses
henryrawas 21:051751f9ca9e 167 * winhttp, the meaning is the same as the @c dwSendTimeout and
henryrawas 21:051751f9ca9e 168 * @c dwReceiveTimeout parameters of the
henryrawas 21:051751f9ca9e 169 * <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384116(v=vs.85).aspx">
henryrawas 21:051751f9ca9e 170 * WinHttpSetTimeouts</a> API.
henryrawas 21:051751f9ca9e 171 * - @b CURLOPT_LOW_SPEED_LIMIT - only available for HTTP protocol and only
henryrawas 21:051751f9ca9e 172 * when CURL is used. It has the same meaning as CURL's option with the same
henryrawas 21:051751f9ca9e 173 * name. @p value is pointer to a long.
henryrawas 21:051751f9ca9e 174 * - @b CURLOPT_LOW_SPEED_TIME - only available for HTTP protocol and only
henryrawas 21:051751f9ca9e 175 * when CURL is used. It has the same meaning as CURL's option with the same
henryrawas 21:051751f9ca9e 176 * name. @p value is pointer to a long.
henryrawas 21:051751f9ca9e 177 * - @b CURLOPT_FORBID_REUSE - only available for HTTP protocol and only
henryrawas 21:051751f9ca9e 178 * when CURL is used. It has the same meaning as CURL's option with the same
henryrawas 21:051751f9ca9e 179 * name. @p value is pointer to a long.
henryrawas 21:051751f9ca9e 180 * - @b CURLOPT_FRESH_CONNECT - only available for HTTP protocol and only
henryrawas 21:051751f9ca9e 181 * when CURL is used. It has the same meaning as CURL's option with the same
henryrawas 21:051751f9ca9e 182 * name. @p value is pointer to a long.
henryrawas 21:051751f9ca9e 183 * - @b CURLOPT_VERBOSE - only available for HTTP protocol and only
henryrawas 21:051751f9ca9e 184 * when CURL is used. It has the same meaning as CURL's option with the same
henryrawas 21:051751f9ca9e 185 * name. @p value is pointer to a long.
henryrawas 21:051751f9ca9e 186 *
henryrawas 21:051751f9ca9e 187 * @return IOTHUB_CLIENT_OK upon success or an error code upon failure.
henryrawas 21:051751f9ca9e 188 */
henryrawas 21:051751f9ca9e 189 extern IOTHUB_CLIENT_RESULT IoTHubClient_Mod_SetOption(IOTHUB_CLIENT_HANDLE iotHubClientHandle, const char* optionName, const void* value);
henryrawas 21:051751f9ca9e 190
henryrawas 21:051751f9ca9e 191 #ifdef __cplusplus
henryrawas 21:051751f9ca9e 192 }
henryrawas 21:051751f9ca9e 193 #endif
henryrawas 21:051751f9ca9e 194
henryrawas 21:051751f9ca9e 195 #endif /* IOTHUB_CLIENT_H */