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 | /* Shared structures and enums for iothub convenience layer and LL layer */
|
---|
5 |
|
---|
6 | #ifndef IOTHUB_CLIENT_CORE_COMMON_H
|
---|
7 | #define IOTHUB_CLIENT_CORE_COMMON_H
|
---|
8 |
|
---|
9 | #include "azure_c_shared_utility/macro_utils.h"
|
---|
10 | #include "azure_c_shared_utility/umock_c_prod.h"
|
---|
11 |
|
---|
12 | #include "iothub_transport_ll.h"
|
---|
13 | #include "iothub_message.h"
|
---|
14 |
|
---|
15 | #ifdef __cplusplus
|
---|
16 | extern "C"
|
---|
17 | {
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #define IOTHUB_CLIENT_FILE_UPLOAD_RESULT_VALUES \
|
---|
21 | FILE_UPLOAD_OK, \
|
---|
22 | FILE_UPLOAD_ERROR
|
---|
23 |
|
---|
24 | MU_DEFINE_ENUM(IOTHUB_CLIENT_FILE_UPLOAD_RESULT, IOTHUB_CLIENT_FILE_UPLOAD_RESULT_VALUES)
|
---|
25 | typedef void(*IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK)(IOTHUB_CLIENT_FILE_UPLOAD_RESULT result, void* userContextCallback);
|
---|
26 |
|
---|
27 | #define IOTHUB_CLIENT_RESULT_VALUES \
|
---|
28 | IOTHUB_CLIENT_OK, \
|
---|
29 | IOTHUB_CLIENT_INVALID_ARG, \
|
---|
30 | IOTHUB_CLIENT_ERROR, \
|
---|
31 | IOTHUB_CLIENT_INVALID_SIZE, \
|
---|
32 | IOTHUB_CLIENT_INDEFINITE_TIME
|
---|
33 |
|
---|
34 | /** @brief Enumeration specifying the status of calls to various APIs in this module.
|
---|
35 | */
|
---|
36 |
|
---|
37 | MU_DEFINE_ENUM(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_RESULT_VALUES);
|
---|
38 |
|
---|
39 | typedef void(*IOTHUB_METHOD_INVOKE_CALLBACK)(IOTHUB_CLIENT_RESULT result, int responseStatus, unsigned char* responsePayload, size_t responsePayloadSize, void* context);
|
---|
40 |
|
---|
41 | #define IOTHUB_CLIENT_RETRY_POLICY_VALUES \
|
---|
42 | IOTHUB_CLIENT_RETRY_NONE, \
|
---|
43 | IOTHUB_CLIENT_RETRY_IMMEDIATE, \
|
---|
44 | IOTHUB_CLIENT_RETRY_INTERVAL, \
|
---|
45 | IOTHUB_CLIENT_RETRY_LINEAR_BACKOFF, \
|
---|
46 | IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF, \
|
---|
47 | IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER, \
|
---|
48 | IOTHUB_CLIENT_RETRY_RANDOM
|
---|
49 |
|
---|
50 | /** @brief Enumeration passed in by the IoT Hub when the event confirmation
|
---|
51 | * callback is invoked to indicate status of the event processing in
|
---|
52 | * the hub.
|
---|
53 | */
|
---|
54 | MU_DEFINE_ENUM(IOTHUB_CLIENT_RETRY_POLICY, IOTHUB_CLIENT_RETRY_POLICY_VALUES);
|
---|
55 |
|
---|
56 | struct IOTHUBTRANSPORT_CONFIG_TAG;
|
---|
57 | typedef struct IOTHUBTRANSPORT_CONFIG_TAG IOTHUBTRANSPORT_CONFIG;
|
---|
58 |
|
---|
59 | #define IOTHUB_CLIENT_STATUS_VALUES \
|
---|
60 | IOTHUB_CLIENT_SEND_STATUS_IDLE, \
|
---|
61 | IOTHUB_CLIENT_SEND_STATUS_BUSY
|
---|
62 |
|
---|
63 | /** @brief Enumeration returned by the ::IoTHubClient_LL_GetSendStatus
|
---|
64 | * API to indicate the current sending status of the IoT Hub client.
|
---|
65 | */
|
---|
66 | MU_DEFINE_ENUM(IOTHUB_CLIENT_STATUS, IOTHUB_CLIENT_STATUS_VALUES);
|
---|
67 |
|
---|
68 | #define IOTHUB_IDENTITY_TYPE_VALUE \
|
---|
69 | IOTHUB_TYPE_TELEMETRY, \
|
---|
70 | IOTHUB_TYPE_DEVICE_TWIN, \
|
---|
71 | IOTHUB_TYPE_DEVICE_METHODS, \
|
---|
72 | IOTHUB_TYPE_EVENT_QUEUE
|
---|
73 | MU_DEFINE_ENUM(IOTHUB_IDENTITY_TYPE, IOTHUB_IDENTITY_TYPE_VALUE);
|
---|
74 |
|
---|
75 | #define IOTHUB_PROCESS_ITEM_RESULT_VALUE \
|
---|
76 | IOTHUB_PROCESS_OK, \
|
---|
77 | IOTHUB_PROCESS_ERROR, \
|
---|
78 | IOTHUB_PROCESS_NOT_CONNECTED, \
|
---|
79 | IOTHUB_PROCESS_CONTINUE
|
---|
80 | MU_DEFINE_ENUM(IOTHUB_PROCESS_ITEM_RESULT, IOTHUB_PROCESS_ITEM_RESULT_VALUE);
|
---|
81 |
|
---|
82 | #define IOTHUBMESSAGE_DISPOSITION_RESULT_VALUES \
|
---|
83 | IOTHUBMESSAGE_ACCEPTED, \
|
---|
84 | IOTHUBMESSAGE_REJECTED, \
|
---|
85 | IOTHUBMESSAGE_ABANDONED
|
---|
86 |
|
---|
87 | /** @brief Enumeration returned by the callback which is invoked whenever the
|
---|
88 | * IoT Hub sends a message to the device.
|
---|
89 | */
|
---|
90 | MU_DEFINE_ENUM(IOTHUBMESSAGE_DISPOSITION_RESULT, IOTHUBMESSAGE_DISPOSITION_RESULT_VALUES);
|
---|
91 |
|
---|
92 | #define IOTHUB_CLIENT_IOTHUB_METHOD_STATUS_VALUES \
|
---|
93 | IOTHUB_CLIENT_IOTHUB_METHOD_STATUS_SUCCESS, \
|
---|
94 | IOTHUB_CLIENT_IOTHUB_METHOD_STATUS_ERROR \
|
---|
95 |
|
---|
96 | /** @brief Enumeration returned by remotely executed functions
|
---|
97 | */
|
---|
98 | MU_DEFINE_ENUM(IOTHUB_CLIENT_IOTHUB_METHOD_STATUS, IOTHUB_CLIENT_IOTHUB_METHOD_STATUS_VALUES);
|
---|
99 |
|
---|
100 |
|
---|
101 | #define IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES \
|
---|
102 | IOTHUB_CLIENT_CONFIRMATION_OK, \
|
---|
103 | IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY, \
|
---|
104 | IOTHUB_CLIENT_CONFIRMATION_MESSAGE_TIMEOUT, \
|
---|
105 | IOTHUB_CLIENT_CONFIRMATION_ERROR \
|
---|
106 |
|
---|
107 | /** @brief Enumeration passed in by the IoT Hub when the event confirmation
|
---|
108 | * callback is invoked to indicate status of the event processing in
|
---|
109 | * the hub.
|
---|
110 | */
|
---|
111 | MU_DEFINE_ENUM(IOTHUB_CLIENT_CONFIRMATION_RESULT, IOTHUB_CLIENT_CONFIRMATION_RESULT_VALUES);
|
---|
112 |
|
---|
113 | #define IOTHUB_CLIENT_CONNECTION_STATUS_VALUES \
|
---|
114 | IOTHUB_CLIENT_CONNECTION_AUTHENTICATED, \
|
---|
115 | IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED \
|
---|
116 |
|
---|
117 |
|
---|
118 | /** @brief Enumeration passed in by the IoT Hub when the connection status
|
---|
119 | * callback is invoked to indicate status of the connection in
|
---|
120 | * the hub.
|
---|
121 | */
|
---|
122 | MU_DEFINE_ENUM(IOTHUB_CLIENT_CONNECTION_STATUS, IOTHUB_CLIENT_CONNECTION_STATUS_VALUES);
|
---|
123 |
|
---|
124 | #define IOTHUB_CLIENT_CONNECTION_STATUS_REASON_VALUES \
|
---|
125 | IOTHUB_CLIENT_CONNECTION_EXPIRED_SAS_TOKEN, \
|
---|
126 | IOTHUB_CLIENT_CONNECTION_DEVICE_DISABLED, \
|
---|
127 | IOTHUB_CLIENT_CONNECTION_BAD_CREDENTIAL, \
|
---|
128 | IOTHUB_CLIENT_CONNECTION_RETRY_EXPIRED, \
|
---|
129 | IOTHUB_CLIENT_CONNECTION_NO_NETWORK, \
|
---|
130 | IOTHUB_CLIENT_CONNECTION_COMMUNICATION_ERROR, \
|
---|
131 | IOTHUB_CLIENT_CONNECTION_OK \
|
---|
132 |
|
---|
133 | /** @brief Enumeration passed in by the IoT Hub when the connection status
|
---|
134 | * callback is invoked to indicate status of the connection in
|
---|
135 | * the hub.
|
---|
136 | */
|
---|
137 | MU_DEFINE_ENUM(IOTHUB_CLIENT_CONNECTION_STATUS_REASON, IOTHUB_CLIENT_CONNECTION_STATUS_REASON_VALUES);
|
---|
138 |
|
---|
139 | #define TRANSPORT_TYPE_VALUES \
|
---|
140 | TRANSPORT_LL, /*LL comes from "LowLevel" */ \
|
---|
141 | TRANSPORT_THREADED
|
---|
142 |
|
---|
143 | MU_DEFINE_ENUM(TRANSPORT_TYPE, TRANSPORT_TYPE_VALUES);
|
---|
144 |
|
---|
145 | #define DEVICE_TWIN_UPDATE_STATE_VALUES \
|
---|
146 | DEVICE_TWIN_UPDATE_COMPLETE, \
|
---|
147 | DEVICE_TWIN_UPDATE_PARTIAL
|
---|
148 |
|
---|
149 | MU_DEFINE_ENUM(DEVICE_TWIN_UPDATE_STATE, DEVICE_TWIN_UPDATE_STATE_VALUES);
|
---|
150 |
|
---|
151 | typedef void(*IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK)(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback);
|
---|
152 | typedef void(*IOTHUB_CLIENT_CONNECTION_STATUS_CALLBACK)(IOTHUB_CLIENT_CONNECTION_STATUS result, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason, void* userContextCallback);
|
---|
153 | typedef IOTHUBMESSAGE_DISPOSITION_RESULT (*IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC)(IOTHUB_MESSAGE_HANDLE message, void* userContextCallback);
|
---|
154 |
|
---|
155 | typedef void(*IOTHUB_CLIENT_DEVICE_TWIN_CALLBACK)(DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char* payLoad, size_t size, void* userContextCallback);
|
---|
156 | typedef void(*IOTHUB_CLIENT_REPORTED_STATE_CALLBACK)(int status_code, void* userContextCallback);
|
---|
157 | typedef int(*IOTHUB_CLIENT_DEVICE_METHOD_CALLBACK_ASYNC)(const char* method_name, const unsigned char* payload, size_t size, unsigned char** response, size_t* response_size, void* userContextCallback);
|
---|
158 | typedef int(*IOTHUB_CLIENT_INBOUND_DEVICE_METHOD_CALLBACK)(const char* method_name, const unsigned char* payload, size_t size, METHOD_HANDLE method_id, void* userContextCallback);
|
---|
159 |
|
---|
160 |
|
---|
161 | #define IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_RESULT_VALUES \
|
---|
162 | IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_OK, \
|
---|
163 | IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_ABORT
|
---|
164 |
|
---|
165 | MU_DEFINE_ENUM(IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_RESULT, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_RESULT_VALUES);
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * @brief Callback invoked by IoTHubClient_UploadMultipleBlocksToBlobAsync requesting the chunks of data to be uploaded.
|
---|
169 | * @param result The result of the upload of the previous block of data provided by the user (IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX only)
|
---|
170 | * @param data Next block of data to be uploaded, to be provided by the user when this callback is invoked.
|
---|
171 | * @param size Size of the data parameter.
|
---|
172 | * @param context User context provided on the call to IoTHubClient_UploadMultipleBlocksToBlobAsync.
|
---|
173 | * @remarks If the user wants to abort the upload, the callback should return IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_ABORT
|
---|
174 | * It should return IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_OK otherwise.
|
---|
175 | * If a NULL is provided for parameter "data" and/or zero is provided for "size", the user indicates to the client that the complete file has been uploaded.
|
---|
176 | * In such case this callback will be invoked only once more to indicate the status of the final block upload.
|
---|
177 | * If result is not FILE_UPLOAD_OK, the upload is cancelled and this callback stops being invoked.
|
---|
178 | * When this callback is called for the last time, no data or size is expected, so data and size are NULL
|
---|
179 | */
|
---|
180 | typedef void(*IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK)(IOTHUB_CLIENT_FILE_UPLOAD_RESULT result, unsigned char const ** data, size_t* size, void* context);
|
---|
181 | typedef IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_RESULT(*IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX)(IOTHUB_CLIENT_FILE_UPLOAD_RESULT result, unsigned char const ** data, size_t* size, void* context);
|
---|
182 |
|
---|
183 | /** @brief This struct captures IoTHub client configuration. */
|
---|
184 | typedef struct IOTHUB_CLIENT_CONFIG_TAG
|
---|
185 | {
|
---|
186 | /** @brief A function pointer that is passed into the @c IoTHubClientCreate.
|
---|
187 | * A function definition for AMQP is defined in the include @c iothubtransportamqp.h.
|
---|
188 | * A function definition for HTTP is defined in the include @c iothubtransporthttp.h
|
---|
189 | * A function definition for MQTT is defined in the include @c iothubtransportmqtt.h */
|
---|
190 | IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol;
|
---|
191 |
|
---|
192 | /** @brief A string that identifies the device. */
|
---|
193 | const char* deviceId;
|
---|
194 |
|
---|
195 | /** @brief The device key used to authenticate the device.
|
---|
196 | If neither deviceSasToken nor deviceKey is present then the authentication is assumed x509.*/
|
---|
197 | const char* deviceKey;
|
---|
198 |
|
---|
199 | /** @brief The device SAS Token used to authenticate the device in place of device key.
|
---|
200 | If neither deviceSasToken nor deviceKey is present then the authentication is assumed x509.*/
|
---|
201 | const char* deviceSasToken;
|
---|
202 |
|
---|
203 | /** @brief The IoT Hub name to which the device is connecting. */
|
---|
204 | const char* iotHubName;
|
---|
205 |
|
---|
206 | /** @brief IoT Hub suffix goes here, e.g., private.azure-devices-int.net. */
|
---|
207 | const char* iotHubSuffix;
|
---|
208 |
|
---|
209 | const char* protocolGatewayHostName;
|
---|
210 | } IOTHUB_CLIENT_CONFIG;
|
---|
211 |
|
---|
212 | /** @brief This struct captures IoTHub client device configuration. */
|
---|
213 | typedef struct IOTHUB_CLIENT_DEVICE_CONFIG_TAG
|
---|
214 | {
|
---|
215 | /** @brief A function pointer that is passed into the @c IoTHubClientCreate.
|
---|
216 | * A function definition for AMQP is defined in the include @c iothubtransportamqp.h.
|
---|
217 | * A function definition for HTTP is defined in the include @c iothubtransporthttp.h
|
---|
218 | * A function definition for MQTT is defined in the include @c iothubtransportmqtt.h */
|
---|
219 | IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol;
|
---|
220 |
|
---|
221 | /** @brief a transport handle implementing the protocol */
|
---|
222 | void * transportHandle;
|
---|
223 |
|
---|
224 | /** @brief A string that identifies the device. */
|
---|
225 | const char* deviceId;
|
---|
226 |
|
---|
227 | /** @brief The device key used to authenticate the device.
|
---|
228 | x509 authentication is is not supported for multiplexed connections*/
|
---|
229 | const char* deviceKey;
|
---|
230 |
|
---|
231 | /** @brief The device SAS Token used to authenticate the device in place of device key.
|
---|
232 | x509 authentication is is not supported for multiplexed connections.*/
|
---|
233 | const char* deviceSasToken;
|
---|
234 | } IOTHUB_CLIENT_DEVICE_CONFIG;
|
---|
235 |
|
---|
236 | #ifdef __cplusplus
|
---|
237 | }
|
---|
238 | #endif
|
---|
239 |
|
---|
240 | #endif /* IOTHUB_CLIENT_CORE_COMMON_H */
|
---|