Microsoft Azure IoTHub client AMQP transport

Dependents:   sht15_remote_monitoring RobotArmDemo iothub_client_sample_amqp iothub_client_sample_amqp ... more

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

Committer:
AzureIoTClient
Date:
Fri Mar 10 11:46:55 2017 -0800
Revision:
30:20a85b733111
Parent:
26:ee14eed604f6
Child:
31:adadaef857c1
1.1.9

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 4:57e049bce51e 1 // Copyright (c) Microsoft. All rights reserved.
AzureIoTClient 4:57e049bce51e 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
AzureIoTClient 4:57e049bce51e 3
AzureIoTClient 25:63f7d371c030 4 #include "iothubtransportamqp.h"
AzureIoTClient 25:63f7d371c030 5 #include "iothubtransport_amqp_common.h"
Azure.IoT Build 12:841a4c36bd36 6 #include "azure_c_shared_utility/tlsio.h"
AzureIoTClient 25:63f7d371c030 7 #include "azure_c_shared_utility/platform.h"
AzureIoTClient 22:8b70cf813f25 8
Azure.IoT Build 7:07bc440836b3 9 #define RESULT_OK 0
Azure.IoT Build 7:07bc440836b3 10 #define DEFAULT_IOTHUB_AMQP_PORT 5671
AzureIoTClient 4:57e049bce51e 11
AzureIoTClient 25:63f7d371c030 12 static XIO_HANDLE getTLSIOTransport(const char* fqdn)
Azure.IoT Build 7:07bc440836b3 13 {
AzureIoTClient 20:8dec76e7ba34 14 XIO_HANDLE result;
AzureIoTClient 19:ea016664011a 15 TLSIO_CONFIG tls_io_config;
AzureIoTClient 19:ea016664011a 16 tls_io_config.hostname = fqdn;
AzureIoTClient 25:63f7d371c030 17 tls_io_config.port = DEFAULT_IOTHUB_AMQP_PORT;
AzureIoTClient 30:20a85b733111 18 tls_io_config.underlying_io_interface = NULL;
AzureIoTClient 30:20a85b733111 19 tls_io_config.underlying_io_parameters = NULL;
AzureIoTClient 30:20a85b733111 20
AzureIoTClient 26:ee14eed604f6 21 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_002: [getTLSIOTransport shall get `io_interface_description` using platform_get_default_tlsio())]
Azure.IoT Build 10:75c5e0d8537d 22 const IO_INTERFACE_DESCRIPTION* io_interface_description = platform_get_default_tlsio();
AzureIoTClient 4:57e049bce51e 23
AzureIoTClient 26:ee14eed604f6 24 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_003: [If `io_interface_description` is NULL getTLSIOTransport shall return NULL.]
AzureIoTClient 26:ee14eed604f6 25 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_004: [getTLSIOTransport shall return the XIO_HANDLE created using xio_create().]
AzureIoTClient 25:63f7d371c030 26 if ((result = xio_create(io_interface_description, &tls_io_config)) == NULL)
AzureIoTClient 19:ea016664011a 27 {
AzureIoTClient 25:63f7d371c030 28 LogError("Failed to get the TLS/IO transport (xio_create failed)");
AzureIoTClient 4:57e049bce51e 29 }
Azure.IoT Build 11:62d7b956e76e 30
Azure.IoT Build 7:07bc440836b3 31 return result;
AzureIoTClient 4:57e049bce51e 32 }
Azure.IoT Build 7:07bc440836b3 33
AzureIoTClient 25:63f7d371c030 34 // API functions
AzureIoTClient 25:63f7d371c030 35 static TRANSPORT_LL_HANDLE IoTHubTransportAMQP_Create(const IOTHUBTRANSPORT_CONFIG* config)
AzureIoTClient 4:57e049bce51e 36 {
AzureIoTClient 26:ee14eed604f6 37 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_001: [IoTHubTransportAMQP_Create shall create a TRANSPORT_LL_HANDLE by calling into the IoTHubTransport_AMQP_Common_Create function, passing `config` and getTLSIOTransport.]
AzureIoTClient 26:ee14eed604f6 38 return IoTHubTransport_AMQP_Common_Create(config, getTLSIOTransport);
AzureIoTClient 20:8dec76e7ba34 39 }
AzureIoTClient 20:8dec76e7ba34 40
AzureIoTClient 25:63f7d371c030 41 static IOTHUB_PROCESS_ITEM_RESULT IoTHubTransportAMQP_ProcessItem(TRANSPORT_LL_HANDLE handle, IOTHUB_IDENTITY_TYPE item_type, IOTHUB_IDENTITY_INFO* iothub_item)
Azure.IoT Build 7:07bc440836b3 42 {
AzureIoTClient 26:ee14eed604f6 43 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_014: [IoTHubTransportAMQP_ProcessItem shall invoke IoTHubTransport_AMQP_Common_ProcessItem() and return its result.]
AzureIoTClient 26:ee14eed604f6 44 return IoTHubTransport_AMQP_Common_ProcessItem(handle, item_type, iothub_item);
AzureIoTClient 4:57e049bce51e 45 }
AzureIoTClient 4:57e049bce51e 46
AzureIoTClient 25:63f7d371c030 47 static void IoTHubTransportAMQP_DoWork(TRANSPORT_LL_HANDLE handle, IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle)
AzureIoTClient 4:57e049bce51e 48 {
AzureIoTClient 26:ee14eed604f6 49 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_015: [IoTHubTransportAMQP_DoWork shall call into the IoTHubTransport_AMQP_Common_DoWork()]
AzureIoTClient 26:ee14eed604f6 50 IoTHubTransport_AMQP_Common_DoWork(handle, iotHubClientHandle);
Azure.IoT Build 7:07bc440836b3 51 }
Azure.IoT Build 7:07bc440836b3 52
AzureIoTClient 25:63f7d371c030 53 static int IoTHubTransportAMQP_Subscribe(IOTHUB_DEVICE_HANDLE handle)
Azure.IoT Build 7:07bc440836b3 54 {
AzureIoTClient 26:ee14eed604f6 55 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_012: [IoTHubTransportAMQP_Subscribe shall subscribe for D2C messages by calling into the IoTHubTransport_AMQP_Common_Subscribe().]
AzureIoTClient 26:ee14eed604f6 56 return IoTHubTransport_AMQP_Common_Subscribe(handle);
AzureIoTClient 4:57e049bce51e 57 }
AzureIoTClient 4:57e049bce51e 58
AzureIoTClient 25:63f7d371c030 59 static void IoTHubTransportAMQP_Unsubscribe(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 19:ea016664011a 60 {
AzureIoTClient 26:ee14eed604f6 61 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_013: [IoTHubTransportAMQP_Unsubscribe shall subscribe for D2C messages by calling into the IoTHubTransport_AMQP_Common_Unsubscribe().]
AzureIoTClient 26:ee14eed604f6 62 IoTHubTransport_AMQP_Common_Unsubscribe(handle);
AzureIoTClient 25:63f7d371c030 63 }
AzureIoTClient 25:63f7d371c030 64
AzureIoTClient 25:63f7d371c030 65 static int IoTHubTransportAMQP_Subscribe_DeviceTwin(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 25:63f7d371c030 66 {
AzureIoTClient 26:ee14eed604f6 67 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_008: [IoTHubTransportAMQP_Subscribe_DeviceTwin shall invoke IoTHubTransport_AMQP_Common_Subscribe_DeviceTwin() and return its result.]
AzureIoTClient 26:ee14eed604f6 68 return IoTHubTransport_AMQP_Common_Subscribe_DeviceTwin(handle);
AzureIoTClient 19:ea016664011a 69 }
AzureIoTClient 19:ea016664011a 70
AzureIoTClient 25:63f7d371c030 71 static void IoTHubTransportAMQP_Unsubscribe_DeviceTwin(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 4:57e049bce51e 72 {
AzureIoTClient 26:ee14eed604f6 73 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_009: [IoTHubTransportAMQP_Unsubscribe_DeviceTwin shall invoke IoTHubTransport_AMQP_Common_Unsubscribe_DeviceTwin()]
AzureIoTClient 26:ee14eed604f6 74 IoTHubTransport_AMQP_Common_Unsubscribe_DeviceTwin(handle);
AzureIoTClient 25:63f7d371c030 75 }
AzureIoTClient 4:57e049bce51e 76
AzureIoTClient 25:63f7d371c030 77 static int IoTHubTransportAMQP_Subscribe_DeviceMethod(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 25:63f7d371c030 78 {
AzureIoTClient 26:ee14eed604f6 79 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_010: [IoTHubTransportAMQP_Subscribe_DeviceMethod shall invoke IoTHubTransport_AMQP_Common_Subscribe_DeviceMethod() and return its result.]
AzureIoTClient 26:ee14eed604f6 80 return IoTHubTransport_AMQP_Common_Subscribe_DeviceMethod(handle);
AzureIoTClient 25:63f7d371c030 81 }
AzureIoTClient 4:57e049bce51e 82
AzureIoTClient 25:63f7d371c030 83 static void IoTHubTransportAMQP_Unsubscribe_DeviceMethod(IOTHUB_DEVICE_HANDLE handle)
AzureIoTClient 25:63f7d371c030 84 {
AzureIoTClient 26:ee14eed604f6 85 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_011: [IoTHubTransportAMQP_Unsubscribe_DeviceMethod shall invoke IoTHubTransport_AMQP_Common_Unsubscribe_DeviceMethod()]
AzureIoTClient 26:ee14eed604f6 86 IoTHubTransport_AMQP_Common_Unsubscribe_DeviceMethod(handle);
AzureIoTClient 26:ee14eed604f6 87 }
AzureIoTClient 26:ee14eed604f6 88
AzureIoTClient 26:ee14eed604f6 89 static int IoTHubTransportAMQP_DeviceMethod_Response(IOTHUB_DEVICE_HANDLE handle, METHOD_HANDLE methodId, const unsigned char* response, size_t response_size, int status_response)
AzureIoTClient 26:ee14eed604f6 90 {
AzureIoTClient 26:ee14eed604f6 91 return IoTHubTransport_AMQP_Common_DeviceMethod_Response(handle, methodId, response, response_size, status_response);
AzureIoTClient 25:63f7d371c030 92 }
AzureIoTClient 19:ea016664011a 93
AzureIoTClient 25:63f7d371c030 94 static IOTHUB_CLIENT_RESULT IoTHubTransportAMQP_GetSendStatus(IOTHUB_DEVICE_HANDLE handle, IOTHUB_CLIENT_STATUS *iotHubClientStatus)
AzureIoTClient 25:63f7d371c030 95 {
AzureIoTClient 26:ee14eed604f6 96 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_016: [IoTHubTransportAMQP_GetSendStatus shall get the send status by calling into the IoTHubTransport_AMQP_Common_GetSendStatus()]
AzureIoTClient 26:ee14eed604f6 97 return IoTHubTransport_AMQP_Common_GetSendStatus(handle, iotHubClientStatus);
AzureIoTClient 25:63f7d371c030 98 }
AzureIoTClient 19:ea016664011a 99
AzureIoTClient 25:63f7d371c030 100 static IOTHUB_CLIENT_RESULT IoTHubTransportAMQP_SetOption(TRANSPORT_LL_HANDLE handle, const char* option, const void* value)
AzureIoTClient 25:63f7d371c030 101 {
AzureIoTClient 26:ee14eed604f6 102 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_017: [IoTHubTransportAMQP_SetOption shall set the options by calling into the IoTHubTransport_AMQP_Common_SetOption()]
AzureIoTClient 26:ee14eed604f6 103 return IoTHubTransport_AMQP_Common_SetOption(handle, option, value);
AzureIoTClient 25:63f7d371c030 104 }
AzureIoTClient 19:ea016664011a 105
AzureIoTClient 25:63f7d371c030 106 static IOTHUB_DEVICE_HANDLE IoTHubTransportAMQP_Register(TRANSPORT_LL_HANDLE handle, const IOTHUB_DEVICE_CONFIG* device, IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, PDLIST_ENTRY waitingToSend)
AzureIoTClient 25:63f7d371c030 107 {
AzureIoTClient 26:ee14eed604f6 108 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_006: [IoTHubTransportAMQP_Register shall register the device by calling into the IoTHubTransport_AMQP_Common_Register().]
AzureIoTClient 26:ee14eed604f6 109 return IoTHubTransport_AMQP_Common_Register(handle, device, iotHubClientHandle, waitingToSend);
AzureIoTClient 25:63f7d371c030 110 }
Azure.IoT Build 7:07bc440836b3 111
AzureIoTClient 25:63f7d371c030 112 static void IoTHubTransportAMQP_Unregister(IOTHUB_DEVICE_HANDLE deviceHandle)
AzureIoTClient 25:63f7d371c030 113 {
AzureIoTClient 26:ee14eed604f6 114 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_007: [IoTHubTransportAMQP_Unregister shall unregister the device by calling into the IoTHubTransport_AMQP_Common_Unregister().]
AzureIoTClient 26:ee14eed604f6 115 IoTHubTransport_AMQP_Common_Unregister(deviceHandle);
AzureIoTClient 4:57e049bce51e 116 }
AzureIoTClient 4:57e049bce51e 117
Azure.IoT Build 11:62d7b956e76e 118 static void IoTHubTransportAMQP_Destroy(TRANSPORT_LL_HANDLE handle)
AzureIoTClient 4:57e049bce51e 119 {
AzureIoTClient 26:ee14eed604f6 120 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_005: [IoTHubTransportAMQP_Destroy shall destroy the TRANSPORT_LL_HANDLE by calling into the IoTHubTransport_AMQP_Common_Destroy().]
AzureIoTClient 26:ee14eed604f6 121 IoTHubTransport_AMQP_Common_Destroy(handle);
AzureIoTClient 4:57e049bce51e 122 }
AzureIoTClient 4:57e049bce51e 123
AzureIoTClient 25:63f7d371c030 124 static int IoTHubTransportAMQP_SetRetryPolicy(TRANSPORT_LL_HANDLE handle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds)
AzureIoTClient 4:57e049bce51e 125 {
AzureIoTClient 30:20a85b733111 126 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_020: [IoTHubTransportAMQP_SetRetryPolicy shall call into the IoTHubTransport_AMQP_Common_SetRetryPolicy().]
AzureIoTClient 26:ee14eed604f6 127 return IoTHubTransport_AMQP_Common_SetRetryPolicy(handle, retryPolicy, retryTimeoutLimitInSeconds);
Azure.IoT Build 10:75c5e0d8537d 128 }
Azure.IoT Build 10:75c5e0d8537d 129
AzureIoTClient 17:597443dc65a4 130 static STRING_HANDLE IoTHubTransportAMQP_GetHostname(TRANSPORT_LL_HANDLE handle)
AzureIoTClient 17:597443dc65a4 131 {
AzureIoTClient 26:ee14eed604f6 132 // Codes_SRS_IOTHUBTRANSPORTAMQP_09_018: [IoTHubTransportAMQP_GetHostname shall get the hostname by calling into the IoTHubTransport_AMQP_Common_GetHostname()]
AzureIoTClient 26:ee14eed604f6 133 return IoTHubTransport_AMQP_Common_GetHostname(handle);
AzureIoTClient 17:597443dc65a4 134 }
AzureIoTClient 17:597443dc65a4 135
AzureIoTClient 30:20a85b733111 136 static IOTHUB_CLIENT_RESULT IoTHubTransportAMQP_SendMessageDisposition(MESSAGE_CALLBACK_INFO* message_data, IOTHUBMESSAGE_DISPOSITION_RESULT disposition)
AzureIoTClient 30:20a85b733111 137 {
AzureIoTClient 30:20a85b733111 138 // Codes_SRS_IOTHUBTRANSPORTAMQP_10_001: [IoTHubTransportAMQP_SendMessageDisposition shall send the message disposition by calling into the IoTHubTransport_AMQP_Common_SendMessageDispostion().]
AzureIoTClient 30:20a85b733111 139 return IoTHubTransport_AMQP_Common_SendMessageDisposition(message_data, disposition);
AzureIoTClient 30:20a85b733111 140 }
AzureIoTClient 30:20a85b733111 141
AzureIoTClient 25:63f7d371c030 142 static TRANSPORT_PROVIDER thisTransportProvider =
AzureIoTClient 25:63f7d371c030 143 {
AzureIoTClient 30:20a85b733111 144 IoTHubTransportAMQP_SendMessageDisposition, /*pfIotHubTransport_Send_Message_Disposition IoTHubTransport_Send_Message_Disposition;*/
AzureIoTClient 25:63f7d371c030 145 IoTHubTransportAMQP_Subscribe_DeviceMethod, /*pfIoTHubTransport_Subscribe_DeviceMethod IoTHubTransport_Subscribe_DeviceMethod;*/
AzureIoTClient 25:63f7d371c030 146 IoTHubTransportAMQP_Unsubscribe_DeviceMethod, /*pfIoTHubTransport_Unsubscribe_DeviceMethod IoTHubTransport_Unsubscribe_DeviceMethod;*/
AzureIoTClient 26:ee14eed604f6 147 IoTHubTransportAMQP_DeviceMethod_Response,
AzureIoTClient 25:63f7d371c030 148 IoTHubTransportAMQP_Subscribe_DeviceTwin, /*pfIoTHubTransport_Subscribe_DeviceTwin IoTHubTransport_Subscribe_DeviceTwin;*/
AzureIoTClient 25:63f7d371c030 149 IoTHubTransportAMQP_Unsubscribe_DeviceTwin, /*pfIoTHubTransport_Unsubscribe_DeviceTwin IoTHubTransport_Unsubscribe_DeviceTwin;*/
AzureIoTClient 25:63f7d371c030 150 IoTHubTransportAMQP_ProcessItem, /*pfIoTHubTransport_ProcessItem IoTHubTransport_ProcessItem;*/
AzureIoTClient 25:63f7d371c030 151 IoTHubTransportAMQP_GetHostname, /*pfIoTHubTransport_GetHostname IoTHubTransport_GetHostname;*/
AzureIoTClient 25:63f7d371c030 152 IoTHubTransportAMQP_SetOption, /*pfIoTHubTransport_SetOption IoTHubTransport_SetOption;*/
AzureIoTClient 25:63f7d371c030 153 IoTHubTransportAMQP_Create, /*pfIoTHubTransport_Create IoTHubTransport_Create;*/
AzureIoTClient 25:63f7d371c030 154 IoTHubTransportAMQP_Destroy, /*pfIoTHubTransport_Destroy IoTHubTransport_Destroy;*/
AzureIoTClient 25:63f7d371c030 155 IoTHubTransportAMQP_Register, /*pfIotHubTransport_Register IoTHubTransport_Register;*/
AzureIoTClient 25:63f7d371c030 156 IoTHubTransportAMQP_Unregister, /*pfIotHubTransport_Unregister IoTHubTransport_Unegister;*/
AzureIoTClient 25:63f7d371c030 157 IoTHubTransportAMQP_Subscribe, /*pfIoTHubTransport_Subscribe IoTHubTransport_Subscribe;*/
AzureIoTClient 25:63f7d371c030 158 IoTHubTransportAMQP_Unsubscribe, /*pfIoTHubTransport_Unsubscribe IoTHubTransport_Unsubscribe;*/
AzureIoTClient 25:63f7d371c030 159 IoTHubTransportAMQP_DoWork, /*pfIoTHubTransport_DoWork IoTHubTransport_DoWork;*/
AzureIoTClient 25:63f7d371c030 160 IoTHubTransportAMQP_SetRetryPolicy, /*pfIoTHubTransport_DoWork IoTHubTransport_SetRetryPolicy;*/
AzureIoTClient 25:63f7d371c030 161 IoTHubTransportAMQP_GetSendStatus /*pfIoTHubTransport_GetSendStatus IoTHubTransport_GetSendStatus;*/
AzureIoTClient 4:57e049bce51e 162 };
AzureIoTClient 4:57e049bce51e 163
AzureIoTClient 25:63f7d371c030 164 /* Codes_SRS_IOTHUBTRANSPORTAMQP_09_019: [This function shall return a pointer to a structure of type TRANSPORT_PROVIDER having the following values for it's fields:
AzureIoTClient 30:20a85b733111 165 IoTHubTransport_SendMessageDisposition = IoTHubTransportAMQP_SendMessageDisposition
AzureIoTClient 25:63f7d371c030 166 IoTHubTransport_Subscribe_DeviceMethod = IoTHubTransportAMQP_Subscribe_DeviceMethod
AzureIoTClient 25:63f7d371c030 167 IoTHubTransport_Unsubscribe_DeviceMethod = IoTHubTransportAMQP_Unsubscribe_DeviceMethod
AzureIoTClient 25:63f7d371c030 168 IoTHubTransport_Subscribe_DeviceTwin = IoTHubTransportAMQP_Subscribe_DeviceTwin
AzureIoTClient 25:63f7d371c030 169 IoTHubTransport_Unsubscribe_DeviceTwin = IoTHubTransportAMQP_Unsubscribe_DeviceTwin
AzureIoTClient 25:63f7d371c030 170 IoTHubTransport_ProcessItem - IoTHubTransportAMQP_ProcessItem
AzureIoTClient 25:63f7d371c030 171 IoTHubTransport_GetHostname = IoTHubTransportAMQP_GetHostname
AzureIoTClient 25:63f7d371c030 172 IoTHubTransport_Create = IoTHubTransportAMQP_Create
AzureIoTClient 25:63f7d371c030 173 IoTHubTransport_Destroy = IoTHubTransportAMQP_Destroy
AzureIoTClient 25:63f7d371c030 174 IoTHubTransport_Subscribe = IoTHubTransportAMQP_Subscribe
AzureIoTClient 25:63f7d371c030 175 IoTHubTransport_Unsubscribe = IoTHubTransportAMQP_Unsubscribe
AzureIoTClient 25:63f7d371c030 176 IoTHubTransport_DoWork = IoTHubTransportAMQP_DoWork
AzureIoTClient 30:20a85b733111 177 IoTHubTransport_SetRetryPolicy = IoTHubTransportAMQP_SetRetryPolicy
AzureIoTClient 25:63f7d371c030 178 IoTHubTransport_SetOption = IoTHubTransportAMQP_SetOption]*/
AzureIoTClient 17:597443dc65a4 179 extern const TRANSPORT_PROVIDER* AMQP_Protocol(void)
AzureIoTClient 4:57e049bce51e 180 {
Azure.IoT Build 7:07bc440836b3 181 return &thisTransportProvider;
AzureIoTClient 4:57e049bce51e 182 }