source: azure_iot_hub_f767zi/trunk/azure_iot_sdk/iothub_client/inc/iothub_message.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: 16.3 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_macro_utils/macro_utils.h"
13#include "azure_c_shared_utility/map.h"
14#include "umock_c/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_WITHOUT_INVALID(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_WITHOUT_INVALID(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. No new memory is allocated,
112* the caller is not responsible for freeing the memory. The memory
113* is valid until IoTHubMessage_Destroy is called on the message.
114*
115* @param iotHubMessageHandle Handle to the message.
116*
117* @return @c NULL if an error occurs or a pointer to the stored null
118* terminated string otherwise.
119*/
120MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetString, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
121
122/**
123* @brief Returns the content type of the message given by parameter
124* @c iotHubMessageHandle.
125*
126* @param iotHubMessageHandle Handle to the message.
127*
128* @remarks This function retrieves the standardized type of the payload, which indicates if @c iotHubMessageHandle was created using a String or a Byte Array.
129*
130* @return An @c IOTHUBMESSAGE_CONTENT_TYPE value.
131*/
132MOCKABLE_FUNCTION(, IOTHUBMESSAGE_CONTENT_TYPE, IoTHubMessage_GetContentType, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
133
134/**
135* @brief Sets the content-type of the message payload, as per supported values on RFC 2046.
136*
137* @param iotHubMessageHandle Handle to the message.
138*
139* @param contentType String defining the type of the payload (e.g., text/plain).
140*
141* @return An @c IOTHUB_MESSAGE_RESULT value.
142*/
143MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetContentTypeSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, contentType);
144
145/**
146* @brief Returns the content-type of the message payload, if defined. No new memory is allocated,
147* the caller is not responsible for freeing the memory. The memory
148* is valid until IoTHubMessage_Destroy is called on the message.
149*
150* @param iotHubMessageHandle Handle to the message.
151*
152* @return A string with the content-type value if defined (or NULL otherwise).
153*/
154MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetContentTypeSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
155
156/**
157* @brief Sets the content-encoding of the message payload, as per supported values on RFC 2616.
158*
159* @param iotHubMessageHandle Handle to the message.
160*
161* @param contentEncoding String defining the encoding of the payload (e.g., utf-8).
162*
163* @return An @c IOTHUB_MESSAGE_RESULT value.
164*/
165MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetContentEncodingSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, contentEncoding);
166
167/**
168* @brief Returns the content-encoding of the message payload, if defined. No new memory is allocated,
169* the caller is not responsible for freeing the memory. The memory
170* is valid until IoTHubMessage_Destroy is called on the message.
171*
172* @param iotHubMessageHandle Handle to the message.
173*
174* @return A string with the content-encoding value if defined (or NULL otherwise).
175*/
176MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetContentEncodingSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
177
178/**
179** DEPRECATED: Use IoTHubMessage_SetProperty and IoTHubMessage_GetProperty instead. **
180* @brief Gets a handle to the message's properties map.
181* Note that when sending messages via the HTTP transport, the key names in the map must not contain spaces.
182*
183* @param iotHubMessageHandle Handle to the message.
184*
185* @return A @c MAP_HANDLE pointing to the properties map for this message.
186*/
187MOCKABLE_FUNCTION(, MAP_HANDLE, IoTHubMessage_Properties, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
188
189/**
190* @brief Sets a property on a Iothub Message.
191*
192* @param iotHubMessageHandle Handle to the message.
193*
194* @param key name of the property to set. Note that when sending messages via the HTTP transport, this value must not contain spaces.
195*
196* @param value of the property to set.
197*
198* @return An @c IOTHUB_MESSAGE_RESULT value indicating the result of setting the property.
199*/
200MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, key, const char*, value);
201
202/**
203* @brief Gets a IotHub Message's properties item. No new memory is allocated,
204* the caller is not responsible for freeing the memory. The memory
205* is valid until IoTHubMessage_Destroy is called on the message.
206*
207* @param iotHubMessageHandle Handle to the message.
208*
209* @param key name of the property to retrieve.
210*
211* @return A string with the property's value, or NULL if it does not exist in the properties list.
212*/
213MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, key);
214
215/**
216* @brief Gets the MessageId from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
217* the caller is not responsible for freeing the memory. The memory
218* is valid until IoTHubMessage_Destroy is called on the message.
219*
220* @param iotHubMessageHandle Handle to the message.
221*
222* @return A const char* pointing to the Message Id.
223*/
224MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetMessageId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
225
226/**
227* @brief Sets the MessageId for the IOTHUB_MESSAGE_HANDLE.
228*
229* @param iotHubMessageHandle Handle to the message.
230* @param messageId Pointer to the memory location of the messageId
231*
232* @return Returns IOTHUB_MESSAGE_OK if the messageId was set successfully
233* or an error code otherwise.
234*/
235MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetMessageId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, messageId);
236
237/**
238* @brief Gets the CorrelationId from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
239* the caller is not responsible for freeing the memory. The memory
240* is valid until IoTHubMessage_Destroy is called on the message.
241*
242* @param iotHubMessageHandle Handle to the message.
243*
244* @return A const char* pointing to the Correlation Id.
245*/
246MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetCorrelationId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
247
248/**
249* @brief Sets the CorrelationId for the IOTHUB_MESSAGE_HANDLE.
250*
251* @param iotHubMessageHandle Handle to the message.
252* @param correlationId Pointer to the memory location of the messageId
253*
254* @return Returns IOTHUB_MESSAGE_OK if the messageId was set successfully
255* or an error code otherwise.
256*/
257MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetCorrelationId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, correlationId);
258
259/**
260* @brief Gets the DiagnosticData from the IOTHUB_MESSAGE_HANDLE. CAUTION: SDK user should not call it directly, it is for internal use only.
261*
262* @param iotHubMessageHandle Handle to the message.
263*
264* @return A const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* pointing to the diagnostic property data.
265*/
266MOCKABLE_FUNCTION(, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*, IoTHubMessage_GetDiagnosticPropertyData, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
267
268/**
269* @brief Sets the DiagnosticData for the IOTHUB_MESSAGE_HANDLE. CAUTION: SDK user should not call it directly, it is for internal use only.
270*
271* @param iotHubMessageHandle Handle to the message.
272* @param diagnosticData Pointer to the memory location of the diagnosticData
273*
274* @return Returns IOTHUB_MESSAGE_OK if the DiagnosticData was set successfully
275* or an error code otherwise.
276*/
277MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetDiagnosticPropertyData, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*, diagnosticData);
278
279/**
280* @brief Gets the output name from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
281* the caller is not responsible for freeing the memory. The memory
282* is valid until IoTHubMessage_Destroy is called on the message.
283*
284* @param iotHubMessageHandle Handle to the message.
285*
286* @return A const char* pointing to the Output Id.
287*/
288MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetOutputName, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
289
290
291/**
292* @brief Sets output for named queues. CAUTION: SDK user should not call it directly, it is for internal use only.
293*
294* @param iotHubMessageHandle Handle to the message.
295* @param outputName Pointer to the queue to output message to
296*
297* @return Returns IOTHUB_MESSAGE_OK if the DiagnosticData was set successfully
298* or an error code otherwise.
299*/
300MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetOutputName, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, outputName);
301
302
303/**
304* @brief Gets the input name from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
305* the caller is not responsible for freeing the memory. The memory
306* is valid until IoTHubMessage_Destroy is called on the message.
307*
308* @param iotHubMessageHandle Handle to the message.
309*
310* @return A const char* pointing to the Input Id.
311*/
312MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetInputName, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
313
314/**
315* @brief Sets input for named queues. CAUTION: SDK user should not call it directly, it is for internal use only.
316*
317* @param iotHubMessageHandle Handle to the message.
318* @param inputName Pointer to the queue to input message to
319*
320* @return Returns IOTHUB_MESSAGE_OK if the DiagnosticData was set successfully
321* or an error code otherwise.
322*/
323MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetInputName, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, inputName);
324
325/**
326* @brief Gets the module name from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
327* the caller is not responsible for freeing the memory. The memory
328* is valid until IoTHubMessage_Destroy is called on the message.
329*
330* @param iotHubMessageHandle Handle to the message.
331*
332* @return A const char* pointing to the connection module Id.
333*/
334MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetConnectionModuleId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
335
336/**
337* @brief Sets connection module ID. CAUTION: SDK user should not call it directly, it is for internal use only.
338*
339* @param iotHubMessageHandle Handle to the message.
340* @param connectionModuleId Pointer to the module ID of connector
341*
342* @return Returns IOTHUB_MESSAGE_OK if the DiagnosticData was set successfully
343* or an error code otherwise.
344*/
345MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetConnectionModuleId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, connectionModuleId);
346
347
348/**
349* @brief Gets the connection device ID from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
350* the caller is not responsible for freeing the memory. The memory
351* is valid until IoTHubMessage_Destroy is called on the message.
352*
353* @param iotHubMessageHandle Handle to the message.
354*
355* @return A const char* pointing to the connection device Id.
356*/
357MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetConnectionDeviceId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
358
359/**
360* @brief Sets connection device Id. CAUTION: SDK user should not call it directly, it is for internal use only.
361*
362* @param iotHubMessageHandle Handle to the message.
363* @param connectionDeviceId Pointer to the device ID of connector
364*
365* @return Returns IOTHUB_MESSAGE_OK if the DiagnosticData was set successfully
366* or an error code otherwise.
367*/
368MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetConnectionDeviceId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, connectionDeviceId);
369
370
371/**
372* @brief Marks a IoTHub message as a security message. CAUTION: Security messages are special messages not easily accessable by the user.
373*
374* @param iotHubMessageHandle Handle to the message.
375*
376* @return Returns IOTHUB_MESSAGE_OK if the Security Message was set successfully
377* or an error code otherwise.
378*/
379MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetAsSecurityMessage, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
380
381/**
382* @brief returns if this message is a IoTHub security message or not
383*
384* @param iotHubMessageHandle Handle to the message.
385*
386* @return Returns true if the Message is a security message false otherwise.
387*/
388MOCKABLE_FUNCTION(, bool, IoTHubMessage_IsSecurityMessage, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
389
390/**
391* @brief Frees all resources associated with the given message handle.
392*
393* @param iotHubMessageHandle Handle to the message.
394*/
395MOCKABLE_FUNCTION(, void, IoTHubMessage_Destroy, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
396
397#ifdef __cplusplus
398}
399#endif
400
401#endif /* IOTHUB_MESSAGE_H */
Note: See TracBrowser for help on using the repository browser.