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
iothubtransportamqp.c@25:63f7d371c030, 2016-11-16 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Wed Nov 16 21:37:20 2016 -0800
- Revision:
- 25:63f7d371c030
- Parent:
- 24:834cf977abcf
- Child:
- 26:ee14eed604f6
1.0.10
Who changed what in which revision?
User | Revision | Line number | New 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 | 25:63f7d371c030 | 18 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_002: [getTLSIOTransport shall get `io_interface_description` using platform_get_default_tlsio())] |
Azure.IoT Build | 10:75c5e0d8537d | 19 | const IO_INTERFACE_DESCRIPTION* io_interface_description = platform_get_default_tlsio(); |
AzureIoTClient | 4:57e049bce51e | 20 | |
AzureIoTClient | 25:63f7d371c030 | 21 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_003: [If `io_interface_description` is NULL getTLSIOTransport shall return NULL.] |
AzureIoTClient | 25:63f7d371c030 | 22 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_004: [getTLSIOTransport shall return the XIO_HANDLE created using xio_create().] |
AzureIoTClient | 25:63f7d371c030 | 23 | if ((result = xio_create(io_interface_description, &tls_io_config)) == NULL) |
AzureIoTClient | 19:ea016664011a | 24 | { |
AzureIoTClient | 25:63f7d371c030 | 25 | LogError("Failed to get the TLS/IO transport (xio_create failed)"); |
AzureIoTClient | 4:57e049bce51e | 26 | } |
Azure.IoT Build | 11:62d7b956e76e | 27 | |
Azure.IoT Build | 7:07bc440836b3 | 28 | return result; |
AzureIoTClient | 4:57e049bce51e | 29 | } |
Azure.IoT Build | 7:07bc440836b3 | 30 | |
AzureIoTClient | 25:63f7d371c030 | 31 | // API functions |
AzureIoTClient | 25:63f7d371c030 | 32 | static TRANSPORT_LL_HANDLE IoTHubTransportAMQP_Create(const IOTHUBTRANSPORT_CONFIG* config) |
AzureIoTClient | 4:57e049bce51e | 33 | { |
AzureIoTClient | 25:63f7d371c030 | 34 | // 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 | 25:63f7d371c030 | 35 | return IoTHubTransport_AMQP_Common_Create(config, getTLSIOTransport); |
AzureIoTClient | 20:8dec76e7ba34 | 36 | } |
AzureIoTClient | 20:8dec76e7ba34 | 37 | |
AzureIoTClient | 25:63f7d371c030 | 38 | 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 | 39 | { |
AzureIoTClient | 25:63f7d371c030 | 40 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_014: [IoTHubTransportAMQP_ProcessItem shall invoke IoTHubTransport_AMQP_Common_ProcessItem() and return its result.] |
AzureIoTClient | 25:63f7d371c030 | 41 | return IoTHubTransport_AMQP_Common_ProcessItem(handle, item_type, iothub_item); |
AzureIoTClient | 4:57e049bce51e | 42 | } |
AzureIoTClient | 4:57e049bce51e | 43 | |
AzureIoTClient | 25:63f7d371c030 | 44 | static void IoTHubTransportAMQP_DoWork(TRANSPORT_LL_HANDLE handle, IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle) |
AzureIoTClient | 4:57e049bce51e | 45 | { |
AzureIoTClient | 25:63f7d371c030 | 46 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_015: [IoTHubTransportAMQP_DoWork shall call into the IoTHubTransport_AMQP_Common_DoWork()] |
AzureIoTClient | 25:63f7d371c030 | 47 | IoTHubTransport_AMQP_Common_DoWork(handle, iotHubClientHandle); |
Azure.IoT Build | 7:07bc440836b3 | 48 | } |
Azure.IoT Build | 7:07bc440836b3 | 49 | |
AzureIoTClient | 25:63f7d371c030 | 50 | static int IoTHubTransportAMQP_Subscribe(IOTHUB_DEVICE_HANDLE handle) |
Azure.IoT Build | 7:07bc440836b3 | 51 | { |
AzureIoTClient | 25:63f7d371c030 | 52 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_012: [IoTHubTransportAMQP_Subscribe shall subscribe for D2C messages by calling into the IoTHubTransport_AMQP_Common_Subscribe().] |
AzureIoTClient | 25:63f7d371c030 | 53 | return IoTHubTransport_AMQP_Common_Subscribe(handle); |
AzureIoTClient | 4:57e049bce51e | 54 | } |
AzureIoTClient | 4:57e049bce51e | 55 | |
AzureIoTClient | 25:63f7d371c030 | 56 | static void IoTHubTransportAMQP_Unsubscribe(IOTHUB_DEVICE_HANDLE handle) |
AzureIoTClient | 19:ea016664011a | 57 | { |
AzureIoTClient | 25:63f7d371c030 | 58 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_013: [IoTHubTransportAMQP_Unsubscribe shall subscribe for D2C messages by calling into the IoTHubTransport_AMQP_Common_Unsubscribe().] |
AzureIoTClient | 25:63f7d371c030 | 59 | IoTHubTransport_AMQP_Common_Unsubscribe(handle); |
AzureIoTClient | 25:63f7d371c030 | 60 | } |
AzureIoTClient | 25:63f7d371c030 | 61 | |
AzureIoTClient | 25:63f7d371c030 | 62 | static int IoTHubTransportAMQP_Subscribe_DeviceTwin(IOTHUB_DEVICE_HANDLE handle) |
AzureIoTClient | 25:63f7d371c030 | 63 | { |
AzureIoTClient | 25:63f7d371c030 | 64 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_008: [IoTHubTransportAMQP_Subscribe_DeviceTwin shall invoke IoTHubTransport_AMQP_Common_Subscribe_DeviceTwin() and return its result.] |
AzureIoTClient | 25:63f7d371c030 | 65 | return IoTHubTransport_AMQP_Common_Subscribe_DeviceTwin(handle); |
AzureIoTClient | 19:ea016664011a | 66 | } |
AzureIoTClient | 19:ea016664011a | 67 | |
AzureIoTClient | 25:63f7d371c030 | 68 | static void IoTHubTransportAMQP_Unsubscribe_DeviceTwin(IOTHUB_DEVICE_HANDLE handle) |
AzureIoTClient | 4:57e049bce51e | 69 | { |
AzureIoTClient | 25:63f7d371c030 | 70 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_009: [IoTHubTransportAMQP_Unsubscribe_DeviceTwin shall invoke IoTHubTransport_AMQP_Common_Unsubscribe_DeviceTwin()] |
AzureIoTClient | 25:63f7d371c030 | 71 | IoTHubTransport_AMQP_Common_Unsubscribe_DeviceTwin(handle); |
AzureIoTClient | 25:63f7d371c030 | 72 | } |
AzureIoTClient | 4:57e049bce51e | 73 | |
AzureIoTClient | 25:63f7d371c030 | 74 | static int IoTHubTransportAMQP_Subscribe_DeviceMethod(IOTHUB_DEVICE_HANDLE handle) |
AzureIoTClient | 25:63f7d371c030 | 75 | { |
AzureIoTClient | 25:63f7d371c030 | 76 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_010: [IoTHubTransportAMQP_Subscribe_DeviceMethod shall invoke IoTHubTransport_AMQP_Common_Subscribe_DeviceMethod() and return its result.] |
AzureIoTClient | 25:63f7d371c030 | 77 | return IoTHubTransport_AMQP_Common_Subscribe_DeviceMethod(handle); |
AzureIoTClient | 25:63f7d371c030 | 78 | } |
AzureIoTClient | 4:57e049bce51e | 79 | |
AzureIoTClient | 25:63f7d371c030 | 80 | static void IoTHubTransportAMQP_Unsubscribe_DeviceMethod(IOTHUB_DEVICE_HANDLE handle) |
AzureIoTClient | 25:63f7d371c030 | 81 | { |
AzureIoTClient | 25:63f7d371c030 | 82 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_011: [IoTHubTransportAMQP_Unsubscribe_DeviceMethod shall invoke IoTHubTransport_AMQP_Common_Unsubscribe_DeviceMethod()] |
AzureIoTClient | 25:63f7d371c030 | 83 | IoTHubTransport_AMQP_Common_Unsubscribe_DeviceMethod(handle); |
AzureIoTClient | 25:63f7d371c030 | 84 | } |
AzureIoTClient | 19:ea016664011a | 85 | |
AzureIoTClient | 25:63f7d371c030 | 86 | static IOTHUB_CLIENT_RESULT IoTHubTransportAMQP_GetSendStatus(IOTHUB_DEVICE_HANDLE handle, IOTHUB_CLIENT_STATUS *iotHubClientStatus) |
AzureIoTClient | 25:63f7d371c030 | 87 | { |
AzureIoTClient | 25:63f7d371c030 | 88 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_016: [IoTHubTransportAMQP_GetSendStatus shall get the send status by calling into the IoTHubTransport_AMQP_Common_GetSendStatus()] |
AzureIoTClient | 25:63f7d371c030 | 89 | return IoTHubTransport_AMQP_Common_GetSendStatus(handle, iotHubClientStatus); |
AzureIoTClient | 25:63f7d371c030 | 90 | } |
AzureIoTClient | 19:ea016664011a | 91 | |
AzureIoTClient | 25:63f7d371c030 | 92 | static IOTHUB_CLIENT_RESULT IoTHubTransportAMQP_SetOption(TRANSPORT_LL_HANDLE handle, const char* option, const void* value) |
AzureIoTClient | 25:63f7d371c030 | 93 | { |
AzureIoTClient | 25:63f7d371c030 | 94 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_017: [IoTHubTransportAMQP_SetOption shall set the options by calling into the IoTHubTransport_AMQP_Common_SetOption()] |
AzureIoTClient | 25:63f7d371c030 | 95 | return IoTHubTransport_AMQP_Common_SetOption(handle, option, value); |
AzureIoTClient | 25:63f7d371c030 | 96 | } |
AzureIoTClient | 19:ea016664011a | 97 | |
AzureIoTClient | 25:63f7d371c030 | 98 | 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 | 99 | { |
AzureIoTClient | 25:63f7d371c030 | 100 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_006: [IoTHubTransportAMQP_Register shall register the device by calling into the IoTHubTransport_AMQP_Common_Register().] |
AzureIoTClient | 25:63f7d371c030 | 101 | return IoTHubTransport_AMQP_Common_Register(handle, device, iotHubClientHandle, waitingToSend); |
AzureIoTClient | 25:63f7d371c030 | 102 | } |
Azure.IoT Build | 7:07bc440836b3 | 103 | |
AzureIoTClient | 25:63f7d371c030 | 104 | static void IoTHubTransportAMQP_Unregister(IOTHUB_DEVICE_HANDLE deviceHandle) |
AzureIoTClient | 25:63f7d371c030 | 105 | { |
AzureIoTClient | 25:63f7d371c030 | 106 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_007: [IoTHubTransportAMQP_Unregister shall unregister the device by calling into the IoTHubTransport_AMQP_Common_Unregister().] |
AzureIoTClient | 25:63f7d371c030 | 107 | IoTHubTransport_AMQP_Common_Unregister(deviceHandle); |
AzureIoTClient | 4:57e049bce51e | 108 | } |
AzureIoTClient | 4:57e049bce51e | 109 | |
Azure.IoT Build | 11:62d7b956e76e | 110 | static void IoTHubTransportAMQP_Destroy(TRANSPORT_LL_HANDLE handle) |
AzureIoTClient | 4:57e049bce51e | 111 | { |
AzureIoTClient | 25:63f7d371c030 | 112 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_005: [IoTHubTransportAMQP_Destroy shall destroy the TRANSPORT_LL_HANDLE by calling into the IoTHubTransport_AMQP_Common_Destroy().] |
AzureIoTClient | 25:63f7d371c030 | 113 | IoTHubTransport_AMQP_Common_Destroy(handle); |
AzureIoTClient | 4:57e049bce51e | 114 | } |
AzureIoTClient | 4:57e049bce51e | 115 | |
AzureIoTClient | 25:63f7d371c030 | 116 | static int IoTHubTransportAMQP_SetRetryPolicy(TRANSPORT_LL_HANDLE handle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds) |
AzureIoTClient | 4:57e049bce51e | 117 | { |
AzureIoTClient | 25:63f7d371c030 | 118 | return IoTHubTransport_AMQP_Common_SetRetryPolicy(handle, retryPolicy, retryTimeoutLimitInSeconds); |
Azure.IoT Build | 10:75c5e0d8537d | 119 | } |
Azure.IoT Build | 10:75c5e0d8537d | 120 | |
AzureIoTClient | 17:597443dc65a4 | 121 | static STRING_HANDLE IoTHubTransportAMQP_GetHostname(TRANSPORT_LL_HANDLE handle) |
AzureIoTClient | 17:597443dc65a4 | 122 | { |
AzureIoTClient | 25:63f7d371c030 | 123 | // Codes_SRS_IOTHUBTRANSPORTAMQP_09_018: [IoTHubTransportAMQP_GetHostname shall get the hostname by calling into the IoTHubTransport_AMQP_Common_GetHostname()] |
AzureIoTClient | 25:63f7d371c030 | 124 | return IoTHubTransport_AMQP_Common_GetHostname(handle); |
AzureIoTClient | 17:597443dc65a4 | 125 | } |
AzureIoTClient | 17:597443dc65a4 | 126 | |
AzureIoTClient | 25:63f7d371c030 | 127 | static TRANSPORT_PROVIDER thisTransportProvider = |
AzureIoTClient | 25:63f7d371c030 | 128 | { |
AzureIoTClient | 25:63f7d371c030 | 129 | IoTHubTransportAMQP_Subscribe_DeviceMethod, /*pfIoTHubTransport_Subscribe_DeviceMethod IoTHubTransport_Subscribe_DeviceMethod;*/ |
AzureIoTClient | 25:63f7d371c030 | 130 | IoTHubTransportAMQP_Unsubscribe_DeviceMethod, /*pfIoTHubTransport_Unsubscribe_DeviceMethod IoTHubTransport_Unsubscribe_DeviceMethod;*/ |
AzureIoTClient | 25:63f7d371c030 | 131 | IoTHubTransportAMQP_Subscribe_DeviceTwin, /*pfIoTHubTransport_Subscribe_DeviceTwin IoTHubTransport_Subscribe_DeviceTwin;*/ |
AzureIoTClient | 25:63f7d371c030 | 132 | IoTHubTransportAMQP_Unsubscribe_DeviceTwin, /*pfIoTHubTransport_Unsubscribe_DeviceTwin IoTHubTransport_Unsubscribe_DeviceTwin;*/ |
AzureIoTClient | 25:63f7d371c030 | 133 | IoTHubTransportAMQP_ProcessItem, /*pfIoTHubTransport_ProcessItem IoTHubTransport_ProcessItem;*/ |
AzureIoTClient | 25:63f7d371c030 | 134 | IoTHubTransportAMQP_GetHostname, /*pfIoTHubTransport_GetHostname IoTHubTransport_GetHostname;*/ |
AzureIoTClient | 25:63f7d371c030 | 135 | IoTHubTransportAMQP_SetOption, /*pfIoTHubTransport_SetOption IoTHubTransport_SetOption;*/ |
AzureIoTClient | 25:63f7d371c030 | 136 | IoTHubTransportAMQP_Create, /*pfIoTHubTransport_Create IoTHubTransport_Create;*/ |
AzureIoTClient | 25:63f7d371c030 | 137 | IoTHubTransportAMQP_Destroy, /*pfIoTHubTransport_Destroy IoTHubTransport_Destroy;*/ |
AzureIoTClient | 25:63f7d371c030 | 138 | IoTHubTransportAMQP_Register, /*pfIotHubTransport_Register IoTHubTransport_Register;*/ |
AzureIoTClient | 25:63f7d371c030 | 139 | IoTHubTransportAMQP_Unregister, /*pfIotHubTransport_Unregister IoTHubTransport_Unegister;*/ |
AzureIoTClient | 25:63f7d371c030 | 140 | IoTHubTransportAMQP_Subscribe, /*pfIoTHubTransport_Subscribe IoTHubTransport_Subscribe;*/ |
AzureIoTClient | 25:63f7d371c030 | 141 | IoTHubTransportAMQP_Unsubscribe, /*pfIoTHubTransport_Unsubscribe IoTHubTransport_Unsubscribe;*/ |
AzureIoTClient | 25:63f7d371c030 | 142 | IoTHubTransportAMQP_DoWork, /*pfIoTHubTransport_DoWork IoTHubTransport_DoWork;*/ |
AzureIoTClient | 25:63f7d371c030 | 143 | IoTHubTransportAMQP_SetRetryPolicy, /*pfIoTHubTransport_DoWork IoTHubTransport_SetRetryPolicy;*/ |
AzureIoTClient | 25:63f7d371c030 | 144 | IoTHubTransportAMQP_GetSendStatus /*pfIoTHubTransport_GetSendStatus IoTHubTransport_GetSendStatus;*/ |
AzureIoTClient | 4:57e049bce51e | 145 | }; |
AzureIoTClient | 4:57e049bce51e | 146 | |
AzureIoTClient | 25:63f7d371c030 | 147 | /* 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 | 25:63f7d371c030 | 148 | IoTHubTransport_Subscribe_DeviceMethod = IoTHubTransportAMQP_Subscribe_DeviceMethod |
AzureIoTClient | 25:63f7d371c030 | 149 | IoTHubTransport_Unsubscribe_DeviceMethod = IoTHubTransportAMQP_Unsubscribe_DeviceMethod |
AzureIoTClient | 25:63f7d371c030 | 150 | IoTHubTransport_Subscribe_DeviceTwin = IoTHubTransportAMQP_Subscribe_DeviceTwin |
AzureIoTClient | 25:63f7d371c030 | 151 | IoTHubTransport_Unsubscribe_DeviceTwin = IoTHubTransportAMQP_Unsubscribe_DeviceTwin |
AzureIoTClient | 25:63f7d371c030 | 152 | IoTHubTransport_ProcessItem - IoTHubTransportAMQP_ProcessItem |
AzureIoTClient | 25:63f7d371c030 | 153 | IoTHubTransport_GetHostname = IoTHubTransportAMQP_GetHostname |
AzureIoTClient | 25:63f7d371c030 | 154 | IoTHubTransport_Create = IoTHubTransportAMQP_Create |
AzureIoTClient | 25:63f7d371c030 | 155 | IoTHubTransport_Destroy = IoTHubTransportAMQP_Destroy |
AzureIoTClient | 25:63f7d371c030 | 156 | IoTHubTransport_Subscribe = IoTHubTransportAMQP_Subscribe |
AzureIoTClient | 25:63f7d371c030 | 157 | IoTHubTransport_Unsubscribe = IoTHubTransportAMQP_Unsubscribe |
AzureIoTClient | 25:63f7d371c030 | 158 | IoTHubTransport_DoWork = IoTHubTransportAMQP_DoWork |
AzureIoTClient | 25:63f7d371c030 | 159 | IoTHubTransport_SetOption = IoTHubTransportAMQP_SetOption]*/ |
AzureIoTClient | 17:597443dc65a4 | 160 | extern const TRANSPORT_PROVIDER* AMQP_Protocol(void) |
AzureIoTClient | 4:57e049bce51e | 161 | { |
Azure.IoT Build | 7:07bc440836b3 | 162 | return &thisTransportProvider; |
AzureIoTClient | 4:57e049bce51e | 163 | } |