Microsoft Azure IoTHub client libraries

Dependents:   sht15_remote_monitoring RobotArmDemo iothub_client_sample_amqp f767zi_mqtt ... more

This library implements the Microsoft Azure IoTHub client library. The code is replicated from https://github.com/Azure/azure-iot-sdks

Committer:
AzureIoTClient
Date:
Thu Oct 22 18:32:36 2015 -0700
Revision:
16:deba40344375
Child:
18:1e9adb15c645
v1.0.0-preview.4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 16:deba40344375 1 // Copyright (c) Microsoft. All rights reserved.
AzureIoTClient 16:deba40344375 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
AzureIoTClient 16:deba40344375 3
AzureIoTClient 16:deba40344375 4 /** @file iothub_message.h
AzureIoTClient 16:deba40344375 5 * @brief The @c IoTHub_Message component encapsulates one message that
AzureIoTClient 16:deba40344375 6 * can be transferred by an IoT hub client.
AzureIoTClient 16:deba40344375 7 */
AzureIoTClient 16:deba40344375 8
AzureIoTClient 16:deba40344375 9 #ifndef IOTHUB_MESSAGE_H
AzureIoTClient 16:deba40344375 10 #define IOTHUB_MESSAGE_H
AzureIoTClient 16:deba40344375 11
AzureIoTClient 16:deba40344375 12 #include "macro_utils.h"
AzureIoTClient 16:deba40344375 13 #include "map.h"
AzureIoTClient 16:deba40344375 14
AzureIoTClient 16:deba40344375 15 #ifdef __cplusplus
AzureIoTClient 16:deba40344375 16 #include <cstddef>
AzureIoTClient 16:deba40344375 17 extern "C"
AzureIoTClient 16:deba40344375 18 {
AzureIoTClient 16:deba40344375 19 #else
AzureIoTClient 16:deba40344375 20 #include <stddef.h>
AzureIoTClient 16:deba40344375 21 #endif
AzureIoTClient 16:deba40344375 22
AzureIoTClient 16:deba40344375 23 #define IOTHUB_MESSAGE_RESULT_VALUES \
AzureIoTClient 16:deba40344375 24 IOTHUB_MESSAGE_OK, \
AzureIoTClient 16:deba40344375 25 IOTHUB_MESSAGE_INVALID_ARG, \
AzureIoTClient 16:deba40344375 26 IOTHUB_MESSAGE_INVALID_TYPE, \
AzureIoTClient 16:deba40344375 27 IOTHUB_MESSAGE_ERROR \
AzureIoTClient 16:deba40344375 28
AzureIoTClient 16:deba40344375 29 /** @brief Enumeration specifying the status of calls to various
AzureIoTClient 16:deba40344375 30 * APIs in this module.
AzureIoTClient 16:deba40344375 31 */
AzureIoTClient 16:deba40344375 32 DEFINE_ENUM(IOTHUB_MESSAGE_RESULT, IOTHUB_MESSAGE_RESULT_VALUES);
AzureIoTClient 16:deba40344375 33
AzureIoTClient 16:deba40344375 34 #define IOTHUBMESSAGE_CONTENT_TYPE_VALUES \
AzureIoTClient 16:deba40344375 35 IOTHUBMESSAGE_BYTEARRAY, \
AzureIoTClient 16:deba40344375 36 IOTHUBMESSAGE_STRING, \
AzureIoTClient 16:deba40344375 37 IOTHUBMESSAGE_UNKNOWN \
AzureIoTClient 16:deba40344375 38
AzureIoTClient 16:deba40344375 39 /** @brief Enumeration specifying the content type of the a given
AzureIoTClient 16:deba40344375 40 * message.
AzureIoTClient 16:deba40344375 41 */
AzureIoTClient 16:deba40344375 42 DEFINE_ENUM(IOTHUBMESSAGE_CONTENT_TYPE, IOTHUBMESSAGE_CONTENT_TYPE_VALUES);
AzureIoTClient 16:deba40344375 43
AzureIoTClient 16:deba40344375 44 typedef void* IOTHUB_MESSAGE_HANDLE;
AzureIoTClient 16:deba40344375 45
AzureIoTClient 16:deba40344375 46 /**
AzureIoTClient 16:deba40344375 47 * @brief Creates a new IoT hub message from a byte array. The type of the
AzureIoTClient 16:deba40344375 48 * message will be set to @c IOTHUBMESSAGE_BYTEARRAY.
AzureIoTClient 16:deba40344375 49 *
AzureIoTClient 16:deba40344375 50 * @param byteArray The byte array from which the message is to be created.
AzureIoTClient 16:deba40344375 51 * @param size The size of the byte array.
AzureIoTClient 16:deba40344375 52 *
AzureIoTClient 16:deba40344375 53 * @return A valid @c IOTHUB_MESSAGE_HANDLE if the message was successfully
AzureIoTClient 16:deba40344375 54 * created or @c NULL in case an error occurs.
AzureIoTClient 16:deba40344375 55 */
AzureIoTClient 16:deba40344375 56 extern IOTHUB_MESSAGE_HANDLE IoTHubMessage_CreateFromByteArray(const unsigned char* byteArray, size_t size);
AzureIoTClient 16:deba40344375 57
AzureIoTClient 16:deba40344375 58 /**
AzureIoTClient 16:deba40344375 59 * @brief Creates a new IoT hub message from a null terminated string. The
AzureIoTClient 16:deba40344375 60 * type of the message will be set to @c IOTHUBMESSAGE_STRING.
AzureIoTClient 16:deba40344375 61 *
AzureIoTClient 16:deba40344375 62 * @param source The null terminated string from which the message is to be
AzureIoTClient 16:deba40344375 63 * created.
AzureIoTClient 16:deba40344375 64 *
AzureIoTClient 16:deba40344375 65 * @return A valid @c IOTHUB_MESSAGE_HANDLE if the message was successfully
AzureIoTClient 16:deba40344375 66 * created or @c NULL in case an error occurs.
AzureIoTClient 16:deba40344375 67 */
AzureIoTClient 16:deba40344375 68 extern IOTHUB_MESSAGE_HANDLE IoTHubMessage_CreateFromString(const char* source);
AzureIoTClient 16:deba40344375 69
AzureIoTClient 16:deba40344375 70 /**
AzureIoTClient 16:deba40344375 71 * @brief Creates a new IoT hub message with the content identical to that
AzureIoTClient 16:deba40344375 72 * of the @p iotHubMessageHandle parameter.
AzureIoTClient 16:deba40344375 73 *
AzureIoTClient 16:deba40344375 74 * @param iotHubMessageHandle Handle to the message that is to be cloned.
AzureIoTClient 16:deba40344375 75 *
AzureIoTClient 16:deba40344375 76 * @return A valid @c IOTHUB_MESSAGE_HANDLE if the message was successfully
AzureIoTClient 16:deba40344375 77 * cloned or @c NULL in case an error occurs.
AzureIoTClient 16:deba40344375 78 */
AzureIoTClient 16:deba40344375 79 extern IOTHUB_MESSAGE_HANDLE IoTHubMessage_Clone(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle);
AzureIoTClient 16:deba40344375 80
AzureIoTClient 16:deba40344375 81 /**
AzureIoTClient 16:deba40344375 82 * @brief Fetches a pointer and size for the data associated with the IoT
AzureIoTClient 16:deba40344375 83 * hub message handle. If the content type of the message is not
AzureIoTClient 16:deba40344375 84 * @c IOTHUBMESSAGE_BYTEARRAY then the function returns
AzureIoTClient 16:deba40344375 85 * @c IOTHUB_MESSAGE_INVALID_ARG.
AzureIoTClient 16:deba40344375 86 *
AzureIoTClient 16:deba40344375 87 * @param iotHubMessageHandle Handle to the message.
AzureIoTClient 16:deba40344375 88 * @param buffer Pointer to the memory location where the
AzureIoTClient 16:deba40344375 89 * pointer to the buffer will be written.
AzureIoTClient 16:deba40344375 90 * @param size The size of the buffer will be written to
AzureIoTClient 16:deba40344375 91 * this address.
AzureIoTClient 16:deba40344375 92 *
AzureIoTClient 16:deba40344375 93 * @return Returns IOTHUB_MESSAGE_OK if the byte array was fetched successfully
AzureIoTClient 16:deba40344375 94 * or an error code otherwise.
AzureIoTClient 16:deba40344375 95 */
AzureIoTClient 16:deba40344375 96 extern IOTHUB_MESSAGE_RESULT IoTHubMessage_GetByteArray(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const unsigned char** buffer, size_t* size);
AzureIoTClient 16:deba40344375 97
AzureIoTClient 16:deba40344375 98 /**
AzureIoTClient 16:deba40344375 99 * @brief Returns the null terminated string stored in the message.
AzureIoTClient 16:deba40344375 100 * If the content type of the message is not @c IOTHUBMESSAGE_STRING
AzureIoTClient 16:deba40344375 101 * then the function returns @c NULL.
AzureIoTClient 16:deba40344375 102 *
AzureIoTClient 16:deba40344375 103 * @param iotHubMessageHandle Handle to the message.
AzureIoTClient 16:deba40344375 104 *
AzureIoTClient 16:deba40344375 105 * @return @c NULL if an error occurs or a pointer to the stored null
AzureIoTClient 16:deba40344375 106 * terminated string otherwise.
AzureIoTClient 16:deba40344375 107 */
AzureIoTClient 16:deba40344375 108 extern const char* IoTHubMessage_GetString(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle);
AzureIoTClient 16:deba40344375 109
AzureIoTClient 16:deba40344375 110 /**
AzureIoTClient 16:deba40344375 111 * @brief Returns the content type of the message given by parameter
AzureIoTClient 16:deba40344375 112 * @c iotHubMessageHandle.
AzureIoTClient 16:deba40344375 113 *
AzureIoTClient 16:deba40344375 114 * @param iotHubMessageHandle Handle to the message.
AzureIoTClient 16:deba40344375 115 *
AzureIoTClient 16:deba40344375 116 * @return An @c IOTHUBMESSAGE_CONTENT_TYPE value.
AzureIoTClient 16:deba40344375 117 */
AzureIoTClient 16:deba40344375 118 extern IOTHUBMESSAGE_CONTENT_TYPE IoTHubMessage_GetContentType(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle);
AzureIoTClient 16:deba40344375 119
AzureIoTClient 16:deba40344375 120 /**
AzureIoTClient 16:deba40344375 121 * @brief Gets a handle to the message's properties map.
AzureIoTClient 16:deba40344375 122 *
AzureIoTClient 16:deba40344375 123 * @param iotHubMessageHandle Handle to the message.
AzureIoTClient 16:deba40344375 124 *
AzureIoTClient 16:deba40344375 125 * @return A @c MAP_HANDLE pointing to the properties map for this message.
AzureIoTClient 16:deba40344375 126 */
AzureIoTClient 16:deba40344375 127 extern MAP_HANDLE IoTHubMessage_Properties(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle);
AzureIoTClient 16:deba40344375 128
AzureIoTClient 16:deba40344375 129 /**
AzureIoTClient 16:deba40344375 130 * @brief Frees all resources associated with the given message handle.
AzureIoTClient 16:deba40344375 131 *
AzureIoTClient 16:deba40344375 132 * @param iotHubMessageHandle Handle to the message.
AzureIoTClient 16:deba40344375 133 */
AzureIoTClient 16:deba40344375 134 extern void IoTHubMessage_Destroy(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle);
AzureIoTClient 16:deba40344375 135
AzureIoTClient 16:deba40344375 136 #ifdef __cplusplus
AzureIoTClient 16:deba40344375 137 }
AzureIoTClient 16:deba40344375 138 #endif
AzureIoTClient 16:deba40344375 139
AzureIoTClient 16:deba40344375 140 #endif /* IOTHUB_MESSAGE_H */