source: azure_iot_hub/trunk/azure_iothub/iothub_client/inc/iothub_message.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: 13.8 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_message.h
5* @brief The @c IoTHub_Message component encapsulates one message that
6* can be transferred by an IoT hub client.
7*/
8
9#ifndef IOTHUB_MESSAGE_H
10#define IOTHUB_MESSAGE_H
11
12#include "azure_c_shared_utility/macro_utils.h"
13#include "azure_c_shared_utility/map.h"
14#include "azure_c_shared_utility/umock_c_prod.h"
15
16#ifdef __cplusplus
17#include <cstddef>
18extern "C"
19{
20#else
21#include <stddef.h>
22#endif
23
24#define IOTHUB_MESSAGE_RESULT_VALUES \
25 IOTHUB_MESSAGE_OK, \
26 IOTHUB_MESSAGE_INVALID_ARG, \
27 IOTHUB_MESSAGE_INVALID_TYPE, \
28 IOTHUB_MESSAGE_ERROR \
29
30/** @brief Enumeration specifying the status of calls to various
31* APIs in this module.
32*/
33MU_DEFINE_ENUM(IOTHUB_MESSAGE_RESULT, IOTHUB_MESSAGE_RESULT_VALUES);
34
35#define IOTHUBMESSAGE_CONTENT_TYPE_VALUES \
36IOTHUBMESSAGE_BYTEARRAY, \
37IOTHUBMESSAGE_STRING, \
38IOTHUBMESSAGE_UNKNOWN \
39
40/** @brief Enumeration specifying the content type of the a given
41* message.
42*/
43MU_DEFINE_ENUM(IOTHUBMESSAGE_CONTENT_TYPE, IOTHUBMESSAGE_CONTENT_TYPE_VALUES);
44
45typedef struct IOTHUB_MESSAGE_HANDLE_DATA_TAG* IOTHUB_MESSAGE_HANDLE;
46
47/** @brief diagnostic related data*/
48typedef struct IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_TAG
49{
50 char* diagnosticId;
51 char* diagnosticCreationTimeUtc;
52}IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA, *IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE;
53
54static const char DIAG_CREATION_TIME_UTC_PROPERTY_NAME[] = "diag_creation_time_utc";
55
56/**
57* @brief Creates a new IoT hub message from a byte array. The type of the
58* message will be set to @c IOTHUBMESSAGE_BYTEARRAY.
59*
60* @param byteArray The byte array from which the message is to be created.
61* @param size The size of the byte array.
62*
63* @return A valid @c IOTHUB_MESSAGE_HANDLE if the message was successfully
64* created or @c NULL in case an error occurs.
65*/
66MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_HANDLE, IoTHubMessage_CreateFromByteArray, const unsigned char*, byteArray, size_t, size);
67
68/**
69* @brief Creates a new IoT hub message from a null terminated string. The
70* type of the message will be set to @c IOTHUBMESSAGE_STRING.
71*
72* @param source The null terminated string from which the message is to be
73* created.
74*
75* @return A valid @c IOTHUB_MESSAGE_HANDLE if the message was successfully
76* created or @c NULL in case an error occurs.
77*/
78MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_HANDLE, IoTHubMessage_CreateFromString, const char*, source);
79
80/**
81* @brief Creates a new IoT hub message with the content identical to that
82* of the @p iotHubMessageHandle parameter.
83*
84* @param iotHubMessageHandle Handle to the message that is to be cloned.
85*
86* @return A valid @c IOTHUB_MESSAGE_HANDLE if the message was successfully
87* cloned or @c NULL in case an error occurs.
88*/
89MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_HANDLE, IoTHubMessage_Clone, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
90
91/**
92* @brief Fetches a pointer and size for the data associated with the IoT
93* hub message handle. If the content type of the message is not
94* @c IOTHUBMESSAGE_BYTEARRAY then the function returns
95* @c IOTHUB_MESSAGE_INVALID_ARG.
96*
97* @param iotHubMessageHandle Handle to the message.
98* @param buffer Pointer to the memory location where the
99* pointer to the buffer will be written.
100* @param size The size of the buffer will be written to
101* this address.
102*
103* @return Returns IOTHUB_MESSAGE_OK if the byte array was fetched successfully
104* or an error code otherwise.
105*/
106MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_GetByteArray, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const unsigned char**, buffer, size_t*, size);
107
108/**
109* @brief Returns the null terminated string stored in the message.
110* If the content type of the message is not @c IOTHUBMESSAGE_STRING
111* then the function returns @c NULL.
112*
113* @param iotHubMessageHandle Handle to the message.
114*
115* @return @c NULL if an error occurs or a pointer to the stored null
116* terminated string otherwise.
117*/
118MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetString, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
119
120/**
121* @brief Returns the content type of the message given by parameter
122* @c iotHubMessageHandle.
123*
124* @param iotHubMessageHandle Handle to the message.
125*
126* @remarks This function retrieves the standardized type of the payload, which indicates if @c iotHubMessageHandle was created using a String or a Byte Array.
127*
128* @return An @c IOTHUBMESSAGE_CONTENT_TYPE value.
129*/
130MOCKABLE_FUNCTION(, IOTHUBMESSAGE_CONTENT_TYPE, IoTHubMessage_GetContentType, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
131
132/**
133* @brief Sets the content-type of the message payload, as per supported values on RFC 2046.
134*
135* @param iotHubMessageHandle Handle to the message.
136*
137* @param contentType String defining the type of the payload (e.g., text/plain).
138*
139* @return An @c IOTHUB_MESSAGE_RESULT value.
140*/
141MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetContentTypeSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, contentType);
142
143/**
144* @brief Returns the content-type of the message payload, if defined.
145*
146* @param iotHubMessageHandle Handle to the message.
147*
148* @return A string with the content-type value if defined (or NULL otherwise).
149*/
150MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetContentTypeSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
151
152/**
153* @brief Sets the content-encoding of the message payload, as per supported values on RFC 2616.
154*
155* @param iotHubMessageHandle Handle to the message.
156*
157* @param contentEncoding String defining the encoding of the payload (e.g., utf-8).
158*
159* @return An @c IOTHUB_MESSAGE_RESULT value.
160*/
161MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetContentEncodingSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, contentEncoding);
162
163/**
164* @brief Returns the content-encoding of the message payload, if defined.
165*
166* @param iotHubMessageHandle Handle to the message.
167*
168* @return A string with the content-encoding value if defined (or NULL otherwise).
169*/
170MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetContentEncodingSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
171
172/**
173** DEPRECATED: Use IoTHubMessage_SetProperty and IoTHubMessage_GetProperty instead. **
174* @brief Gets a handle to the message's properties map.
175* Note that when sending messages via the HTTP transport, the key names in the map must not contain spaces.
176*
177* @param iotHubMessageHandle Handle to the message.
178*
179* @return A @c MAP_HANDLE pointing to the properties map for this message.
180*/
181MOCKABLE_FUNCTION(, MAP_HANDLE, IoTHubMessage_Properties, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
182
183/**
184* @brief Sets a property on a Iothub Message.
185*
186* @param iotHubMessageHandle Handle to the message.
187*
188* @param key name of the property to set. Note that when sending messages via the HTTP transport, this value must not contain spaces.
189*
190* @param value of the property to set.
191*
192* @return An @c IOTHUB_MESSAGE_RESULT value indicating the result of setting the property.
193*/
194MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, key, const char*, value);
195
196/**
197* @brief Gets a IotHub Message's properties item.
198*
199* @param iotHubMessageHandle Handle to the message.
200*
201* @param key name of the property to retrieve.
202*
203* @return A string with the property's value, or NULL if it does not exist in the properties list.
204*/
205MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, key);
206
207/**
208* @brief Gets the MessageId from the IOTHUB_MESSAGE_HANDLE.
209*
210* @param iotHubMessageHandle Handle to the message.
211*
212* @return A const char* pointing to the Message Id.
213*/
214MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetMessageId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
215
216/**
217* @brief Sets the MessageId for the IOTHUB_MESSAGE_HANDLE.
218*
219* @param iotHubMessageHandle Handle to the message.
220* @param messageId Pointer to the memory location of the messageId
221*
222* @return Returns IOTHUB_MESSAGE_OK if the messageId was set successfully
223* or an error code otherwise.
224*/
225MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetMessageId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, messageId);
226
227/**
228* @brief Gets the CorrelationId from the IOTHUB_MESSAGE_HANDLE.
229*
230* @param iotHubMessageHandle Handle to the message.
231*
232* @return A const char* pointing to the Correlation Id.
233*/
234MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetCorrelationId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
235
236/**
237* @brief Sets the CorrelationId for the IOTHUB_MESSAGE_HANDLE.
238*
239* @param iotHubMessageHandle Handle to the message.
240* @param correlationId Pointer to the memory location of the messageId
241*
242* @return Returns IOTHUB_MESSAGE_OK if the messageId was set successfully
243* or an error code otherwise.
244*/
245MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetCorrelationId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, correlationId);
246
247/**
248* @brief Gets the DiagnosticData from the IOTHUB_MESSAGE_HANDLE. CAUTION: SDK user should not call it directly, it is for internal use only.
249*
250* @param iotHubMessageHandle Handle to the message.
251*
252* @return A const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* pointing to the diagnostic property data.
253*/
254MOCKABLE_FUNCTION(, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*, IoTHubMessage_GetDiagnosticPropertyData, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
255
256/**
257* @brief Sets the DiagnosticData for the IOTHUB_MESSAGE_HANDLE. CAUTION: SDK user should not call it directly, it is for internal use only.
258*
259* @param iotHubMessageHandle Handle to the message.
260* @param diagnosticData Pointer to the memory location of the diagnosticData
261*
262* @return Returns IOTHUB_MESSAGE_OK if the DiagnosticData was set successfully
263* or an error code otherwise.
264*/
265MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetDiagnosticPropertyData, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*, diagnosticData);
266
267/**
268* @brief Gets the output name from the IOTHUB_MESSAGE_HANDLE.
269*
270* @param iotHubMessageHandle Handle to the message.
271*
272* @return A const char* pointing to the Output Id.
273*/
274MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetOutputName, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
275
276
277/**
278* @brief Sets output for named queues. CAUTION: SDK user should not call it directly, it is for internal use only.
279*
280* @param iotHubMessageHandle Handle to the message.
281* @param outputName Pointer to the queue to output message to
282*
283* @return Returns IOTHUB_MESSAGE_OK if the DiagnosticData was set successfully
284* or an error code otherwise.
285*/
286MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetOutputName, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, outputName);
287
288
289/**
290* @brief Gets the input name from the IOTHUB_MESSAGE_HANDLE.
291*
292* @param iotHubMessageHandle Handle to the message.
293*
294* @return A const char* pointing to the Input Id.
295*/
296MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetInputName, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
297
298/**
299* @brief Sets input for named queues. CAUTION: SDK user should not call it directly, it is for internal use only.
300*
301* @param iotHubMessageHandle Handle to the message.
302* @param inputName Pointer to the queue to input message to
303*
304* @return Returns IOTHUB_MESSAGE_OK if the DiagnosticData was set successfully
305* or an error code otherwise.
306*/
307MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetInputName, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, inputName);
308
309/**
310* @brief Gets the module name from the IOTHUB_MESSAGE_HANDLE.
311*
312* @param iotHubMessageHandle Handle to the message.
313*
314* @return A const char* pointing to the connection module Id.
315*/
316MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetConnectionModuleId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
317
318/**
319* @brief Sets connection module ID. CAUTION: SDK user should not call it directly, it is for internal use only.
320*
321* @param iotHubMessageHandle Handle to the message.
322* @param connectionModuleId Pointer to the module ID of connector
323*
324* @return Returns IOTHUB_MESSAGE_OK if the DiagnosticData was set successfully
325* or an error code otherwise.
326*/
327MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetConnectionModuleId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, connectionModuleId);
328
329
330/**
331* @brief Gets the connection device ID from the IOTHUB_MESSAGE_HANDLE.
332*
333* @param iotHubMessageHandle Handle to the message.
334*
335* @return A const char* pointing to the connection device Id.
336*/
337MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetConnectionDeviceId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
338
339/**
340* @brief Sets connection device Id. CAUTION: SDK user should not call it directly, it is for internal use only.
341*
342* @param iotHubMessageHandle Handle to the message.
343* @param connectionDeviceId Pointer to the device ID of connector
344*
345* @return Returns IOTHUB_MESSAGE_OK if the DiagnosticData was set successfully
346* or an error code otherwise.
347*/
348MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetConnectionDeviceId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, connectionDeviceId);
349
350
351/**
352* @brief Frees all resources associated with the given message handle.
353*
354* @param iotHubMessageHandle Handle to the message.
355*/
356MOCKABLE_FUNCTION(, void, IoTHubMessage_Destroy, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
357
358#ifdef __cplusplus
359}
360#endif
361
362#endif /* IOTHUB_MESSAGE_H */
Note: See TracBrowser for help on using the repository browser.