Azure IoT common library
Dependents: STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more
xio.c@49:6bb8b9a66642, 2018-10-04 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Thu Oct 04 09:17:16 2018 -0700
- Revision:
- 49:6bb8b9a66642
- Parent:
- 48:81866008bba4
1.2.10
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Azure.IoT Build | 0:fa2de1b79154 | 1 | // Copyright (c) Microsoft. All rights reserved. |
Azure.IoT Build | 0:fa2de1b79154 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
Azure.IoT Build | 0:fa2de1b79154 | 3 | |
Azure.IoT Build | 0:fa2de1b79154 | 4 | #include <stdlib.h> |
Azure.IoT Build | 0:fa2de1b79154 | 5 | #include <stddef.h> |
Azure.IoT Build | 0:fa2de1b79154 | 6 | #include "azure_c_shared_utility/gballoc.h" |
AzureIoTClient | 21:b92006c5b9ff | 7 | #include "azure_c_shared_utility/optimize_size.h" |
Azure.IoT Build | 0:fa2de1b79154 | 8 | #include "azure_c_shared_utility/xio.h" |
AzureIoTClient | 32:3b68703b9316 | 9 | #include "azure_c_shared_utility/xlogging.h" |
Azure.IoT Build | 0:fa2de1b79154 | 10 | |
AzureIoTClient | 7:1af47e3a19b6 | 11 | static const char* CONCRETE_OPTIONS = "concreteOptions"; |
AzureIoTClient | 7:1af47e3a19b6 | 12 | |
Azure.IoT Build | 0:fa2de1b79154 | 13 | typedef struct XIO_INSTANCE_TAG |
Azure.IoT Build | 0:fa2de1b79154 | 14 | { |
Azure.IoT Build | 0:fa2de1b79154 | 15 | const IO_INTERFACE_DESCRIPTION* io_interface_description; |
AzureIoTClient | 19:2e0811512ceb | 16 | CONCRETE_IO_HANDLE concrete_xio_handle; |
Azure.IoT Build | 0:fa2de1b79154 | 17 | } XIO_INSTANCE; |
Azure.IoT Build | 0:fa2de1b79154 | 18 | |
Azure.IoT Build | 6:c55b013dfc2a | 19 | XIO_HANDLE xio_create(const IO_INTERFACE_DESCRIPTION* io_interface_description, const void* xio_create_parameters) |
Azure.IoT Build | 0:fa2de1b79154 | 20 | { |
Azure.IoT Build | 0:fa2de1b79154 | 21 | XIO_INSTANCE* xio_instance; |
Azure.IoT Build | 0:fa2de1b79154 | 22 | /* Codes_SRS_XIO_01_003: [If the argument io_interface_description is NULL, xio_create shall return NULL.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 23 | if ((io_interface_description == NULL) || |
Azure.IoT Build | 0:fa2de1b79154 | 24 | /* Codes_SRS_XIO_01_004: [If any io_interface_description member is NULL, xio_create shall return NULL.] */ |
AzureIoTClient | 7:1af47e3a19b6 | 25 | (io_interface_description->concrete_io_retrieveoptions == NULL) || |
Azure.IoT Build | 0:fa2de1b79154 | 26 | (io_interface_description->concrete_io_create == NULL) || |
Azure.IoT Build | 0:fa2de1b79154 | 27 | (io_interface_description->concrete_io_destroy == NULL) || |
Azure.IoT Build | 0:fa2de1b79154 | 28 | (io_interface_description->concrete_io_open == NULL) || |
Azure.IoT Build | 0:fa2de1b79154 | 29 | (io_interface_description->concrete_io_close == NULL) || |
Azure.IoT Build | 0:fa2de1b79154 | 30 | (io_interface_description->concrete_io_send == NULL) || |
Azure.IoT Build | 0:fa2de1b79154 | 31 | (io_interface_description->concrete_io_dowork == NULL) || |
Azure.IoT Build | 0:fa2de1b79154 | 32 | (io_interface_description->concrete_io_setoption == NULL)) |
Azure.IoT Build | 0:fa2de1b79154 | 33 | { |
Azure.IoT Build | 0:fa2de1b79154 | 34 | xio_instance = NULL; |
Azure.IoT Build | 0:fa2de1b79154 | 35 | } |
Azure.IoT Build | 0:fa2de1b79154 | 36 | else |
Azure.IoT Build | 0:fa2de1b79154 | 37 | { |
Azure.IoT Build | 0:fa2de1b79154 | 38 | xio_instance = (XIO_INSTANCE*)malloc(sizeof(XIO_INSTANCE)); |
Azure.IoT Build | 0:fa2de1b79154 | 39 | |
Azure.IoT Build | 0:fa2de1b79154 | 40 | /* Codes_SRS_XIO_01_017: [If allocating the memory needed for the IO interface fails then xio_create shall return NULL.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 41 | if (xio_instance != NULL) |
Azure.IoT Build | 0:fa2de1b79154 | 42 | { |
Azure.IoT Build | 0:fa2de1b79154 | 43 | /* Codes_SRS_XIO_01_001: [xio_create shall return on success a non-NULL handle to a new IO interface.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 44 | xio_instance->io_interface_description = io_interface_description; |
Azure.IoT Build | 0:fa2de1b79154 | 45 | |
Azure.IoT Build | 6:c55b013dfc2a | 46 | /* Codes_SRS_XIO_01_002: [In order to instantiate the concrete IO implementation the function concrete_io_create from the io_interface_description shall be called, passing the xio_create_parameters argument.] */ |
Azure.IoT Build | 6:c55b013dfc2a | 47 | xio_instance->concrete_xio_handle = xio_instance->io_interface_description->concrete_io_create((void*)xio_create_parameters); |
Azure.IoT Build | 0:fa2de1b79154 | 48 | |
Azure.IoT Build | 0:fa2de1b79154 | 49 | /* Codes_SRS_XIO_01_016: [If the underlying concrete_io_create call fails, xio_create shall return NULL.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 50 | if (xio_instance->concrete_xio_handle == NULL) |
Azure.IoT Build | 0:fa2de1b79154 | 51 | { |
Azure.IoT Build | 0:fa2de1b79154 | 52 | free(xio_instance); |
Azure.IoT Build | 0:fa2de1b79154 | 53 | xio_instance = NULL; |
Azure.IoT Build | 0:fa2de1b79154 | 54 | } |
Azure.IoT Build | 0:fa2de1b79154 | 55 | } |
Azure.IoT Build | 0:fa2de1b79154 | 56 | } |
Azure.IoT Build | 0:fa2de1b79154 | 57 | return (XIO_HANDLE)xio_instance; |
Azure.IoT Build | 0:fa2de1b79154 | 58 | } |
Azure.IoT Build | 0:fa2de1b79154 | 59 | |
Azure.IoT Build | 0:fa2de1b79154 | 60 | void xio_destroy(XIO_HANDLE xio) |
Azure.IoT Build | 0:fa2de1b79154 | 61 | { |
Azure.IoT Build | 0:fa2de1b79154 | 62 | /* Codes_SRS_XIO_01_007: [If the argument io is NULL, xio_destroy shall do nothing.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 63 | if (xio != NULL) |
Azure.IoT Build | 0:fa2de1b79154 | 64 | { |
Azure.IoT Build | 0:fa2de1b79154 | 65 | XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio; |
Azure.IoT Build | 0:fa2de1b79154 | 66 | |
Azure.IoT Build | 0:fa2de1b79154 | 67 | /* Codes_SRS_XIO_01_006: [xio_destroy shall also call the concrete_io_destroy function that is member of the io_interface_description argument passed to xio_create, while passing as argument to concrete_io_destroy the result of the underlying concrete_io_create handle that was called as part of the xio_create call.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 68 | xio_instance->io_interface_description->concrete_io_destroy(xio_instance->concrete_xio_handle); |
Azure.IoT Build | 0:fa2de1b79154 | 69 | |
Azure.IoT Build | 0:fa2de1b79154 | 70 | /* Codes_SRS_XIO_01_005: [xio_destroy shall free all resources associated with the IO handle.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 71 | free(xio_instance); |
Azure.IoT Build | 0:fa2de1b79154 | 72 | } |
Azure.IoT Build | 0:fa2de1b79154 | 73 | } |
Azure.IoT Build | 0:fa2de1b79154 | 74 | |
Azure.IoT Build | 0:fa2de1b79154 | 75 | int xio_open(XIO_HANDLE xio, ON_IO_OPEN_COMPLETE on_io_open_complete, void* on_io_open_complete_context, ON_BYTES_RECEIVED on_bytes_received, void* on_bytes_received_context, ON_IO_ERROR on_io_error, void* on_io_error_context) |
Azure.IoT Build | 0:fa2de1b79154 | 76 | { |
Azure.IoT Build | 0:fa2de1b79154 | 77 | int result; |
Azure.IoT Build | 0:fa2de1b79154 | 78 | |
Azure.IoT Build | 0:fa2de1b79154 | 79 | if (xio == NULL) |
Azure.IoT Build | 0:fa2de1b79154 | 80 | { |
Azure.IoT Build | 0:fa2de1b79154 | 81 | /* Codes_SRS_XIO_01_021: [If handle is NULL, xio_open shall return a non-zero value.] */ |
AzureIoTClient | 21:b92006c5b9ff | 82 | result = __FAILURE__; |
Azure.IoT Build | 0:fa2de1b79154 | 83 | } |
Azure.IoT Build | 0:fa2de1b79154 | 84 | else |
Azure.IoT Build | 0:fa2de1b79154 | 85 | { |
Azure.IoT Build | 0:fa2de1b79154 | 86 | XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio; |
Azure.IoT Build | 0:fa2de1b79154 | 87 | |
Azure.IoT Build | 0:fa2de1b79154 | 88 | /* Codes_SRS_XIO_01_019: [xio_open shall call the specific concrete_xio_open function specified in xio_create, passing callback function and context arguments for three events: open completed, bytes received, and IO error.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 89 | if (xio_instance->io_interface_description->concrete_io_open(xio_instance->concrete_xio_handle, on_io_open_complete, on_io_open_complete_context, on_bytes_received, on_bytes_received_context, on_io_error, on_io_error_context) != 0) |
Azure.IoT Build | 0:fa2de1b79154 | 90 | { |
Azure.IoT Build | 0:fa2de1b79154 | 91 | /* Codes_SRS_XIO_01_022: [If the underlying concrete_io_open fails, xio_open shall return a non-zero value.] */ |
AzureIoTClient | 21:b92006c5b9ff | 92 | result = __FAILURE__; |
Azure.IoT Build | 0:fa2de1b79154 | 93 | } |
Azure.IoT Build | 0:fa2de1b79154 | 94 | else |
Azure.IoT Build | 0:fa2de1b79154 | 95 | { |
Azure.IoT Build | 0:fa2de1b79154 | 96 | /* Codes_SRS_XIO_01_020: [On success, xio_open shall return 0.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 97 | result = 0; |
Azure.IoT Build | 0:fa2de1b79154 | 98 | } |
Azure.IoT Build | 0:fa2de1b79154 | 99 | } |
Azure.IoT Build | 0:fa2de1b79154 | 100 | |
Azure.IoT Build | 0:fa2de1b79154 | 101 | return result; |
Azure.IoT Build | 0:fa2de1b79154 | 102 | } |
Azure.IoT Build | 0:fa2de1b79154 | 103 | |
Azure.IoT Build | 0:fa2de1b79154 | 104 | int xio_close(XIO_HANDLE xio, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context) |
Azure.IoT Build | 0:fa2de1b79154 | 105 | { |
Azure.IoT Build | 0:fa2de1b79154 | 106 | int result; |
Azure.IoT Build | 0:fa2de1b79154 | 107 | |
Azure.IoT Build | 0:fa2de1b79154 | 108 | if (xio == NULL) |
Azure.IoT Build | 0:fa2de1b79154 | 109 | { |
Azure.IoT Build | 0:fa2de1b79154 | 110 | /* Codes_SRS_XIO_01_025: [If handle is NULL, xio_close shall return a non-zero value.] */ |
AzureIoTClient | 21:b92006c5b9ff | 111 | result = __FAILURE__; |
Azure.IoT Build | 0:fa2de1b79154 | 112 | } |
Azure.IoT Build | 0:fa2de1b79154 | 113 | else |
Azure.IoT Build | 0:fa2de1b79154 | 114 | { |
Azure.IoT Build | 0:fa2de1b79154 | 115 | XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio; |
Azure.IoT Build | 0:fa2de1b79154 | 116 | |
Azure.IoT Build | 0:fa2de1b79154 | 117 | /* Codes_SRS_XIO_01_023: [xio_close shall call the specific concrete_io_close function specified in xio_create.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 118 | if (xio_instance->io_interface_description->concrete_io_close(xio_instance->concrete_xio_handle, on_io_close_complete, callback_context) != 0) |
Azure.IoT Build | 0:fa2de1b79154 | 119 | { |
Azure.IoT Build | 0:fa2de1b79154 | 120 | /* Codes_SRS_XIO_01_026: [If the underlying concrete_io_close fails, xio_close shall return a non-zero value.] */ |
AzureIoTClient | 21:b92006c5b9ff | 121 | result = __FAILURE__; |
Azure.IoT Build | 0:fa2de1b79154 | 122 | } |
Azure.IoT Build | 0:fa2de1b79154 | 123 | else |
Azure.IoT Build | 0:fa2de1b79154 | 124 | { |
Azure.IoT Build | 0:fa2de1b79154 | 125 | /* Codes_SRS_XIO_01_024: [On success, xio_close shall return 0.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 126 | result = 0; |
Azure.IoT Build | 0:fa2de1b79154 | 127 | } |
Azure.IoT Build | 0:fa2de1b79154 | 128 | } |
Azure.IoT Build | 0:fa2de1b79154 | 129 | |
Azure.IoT Build | 0:fa2de1b79154 | 130 | return result; |
Azure.IoT Build | 0:fa2de1b79154 | 131 | } |
Azure.IoT Build | 0:fa2de1b79154 | 132 | |
Azure.IoT Build | 0:fa2de1b79154 | 133 | int xio_send(XIO_HANDLE xio, const void* buffer, size_t size, ON_SEND_COMPLETE on_send_complete, void* callback_context) |
Azure.IoT Build | 0:fa2de1b79154 | 134 | { |
Azure.IoT Build | 0:fa2de1b79154 | 135 | int result; |
Azure.IoT Build | 0:fa2de1b79154 | 136 | |
Azure.IoT Build | 0:fa2de1b79154 | 137 | /* Codes_SRS_XIO_01_011: [No error check shall be performed on buffer and size.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 138 | /* Codes_SRS_XIO_01_010: [If handle is NULL, xio_send shall return a non-zero value.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 139 | if (xio == NULL) |
Azure.IoT Build | 0:fa2de1b79154 | 140 | { |
AzureIoTClient | 21:b92006c5b9ff | 141 | result = __FAILURE__; |
Azure.IoT Build | 0:fa2de1b79154 | 142 | } |
Azure.IoT Build | 0:fa2de1b79154 | 143 | else |
Azure.IoT Build | 0:fa2de1b79154 | 144 | { |
Azure.IoT Build | 0:fa2de1b79154 | 145 | XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio; |
Azure.IoT Build | 0:fa2de1b79154 | 146 | |
Azure.IoT Build | 0:fa2de1b79154 | 147 | /* Codes_SRS_XIO_01_008: [xio_send shall pass the sequence of bytes pointed to by buffer to the concrete IO implementation specified in xio_create, by calling the concrete_io_send function while passing down the buffer and size arguments to it.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 148 | /* Codes_SRS_XIO_01_009: [On success, xio_send shall return 0.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 149 | /* Codes_SRS_XIO_01_015: [If the underlying concrete_io_send fails, xio_send shall return a non-zero value.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 150 | /* Codes_SRS_XIO_01_027: [xio_send shall pass to the concrete_io_send function the on_send_complete and callback_context arguments.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 151 | result = xio_instance->io_interface_description->concrete_io_send(xio_instance->concrete_xio_handle, buffer, size, on_send_complete, callback_context); |
Azure.IoT Build | 0:fa2de1b79154 | 152 | } |
Azure.IoT Build | 0:fa2de1b79154 | 153 | |
Azure.IoT Build | 0:fa2de1b79154 | 154 | return result; |
Azure.IoT Build | 0:fa2de1b79154 | 155 | } |
Azure.IoT Build | 0:fa2de1b79154 | 156 | |
Azure.IoT Build | 0:fa2de1b79154 | 157 | void xio_dowork(XIO_HANDLE xio) |
Azure.IoT Build | 0:fa2de1b79154 | 158 | { |
Azure.IoT Build | 0:fa2de1b79154 | 159 | /* Codes_SRS_XIO_01_018: [When the handle argument is NULL, xio_dowork shall do nothing.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 160 | if (xio != NULL) |
Azure.IoT Build | 0:fa2de1b79154 | 161 | { |
Azure.IoT Build | 0:fa2de1b79154 | 162 | XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio; |
Azure.IoT Build | 0:fa2de1b79154 | 163 | |
Azure.IoT Build | 0:fa2de1b79154 | 164 | /* Codes_SRS_XIO_01_012: [xio_dowork shall call the concrete XIO implementation specified in xio_create, by calling the concrete_io_dowork function.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 165 | xio_instance->io_interface_description->concrete_io_dowork(xio_instance->concrete_xio_handle); |
Azure.IoT Build | 0:fa2de1b79154 | 166 | } |
Azure.IoT Build | 0:fa2de1b79154 | 167 | } |
Azure.IoT Build | 0:fa2de1b79154 | 168 | |
Azure.IoT Build | 0:fa2de1b79154 | 169 | int xio_setoption(XIO_HANDLE xio, const char* optionName, const void* value) |
Azure.IoT Build | 0:fa2de1b79154 | 170 | { |
Azure.IoT Build | 0:fa2de1b79154 | 171 | int result; |
Azure.IoT Build | 0:fa2de1b79154 | 172 | |
AzureIoTClient | 7:1af47e3a19b6 | 173 | /* Codes_SRS_XIO_03_030: [If the xio argument or the optionName argument is NULL, xio_setoption shall return a non-zero value.] */ |
Azure.IoT Build | 0:fa2de1b79154 | 174 | if (xio == NULL || optionName == NULL) |
Azure.IoT Build | 0:fa2de1b79154 | 175 | { |
AzureIoTClient | 21:b92006c5b9ff | 176 | result = __FAILURE__; |
Azure.IoT Build | 0:fa2de1b79154 | 177 | } |
Azure.IoT Build | 0:fa2de1b79154 | 178 | else |
Azure.IoT Build | 0:fa2de1b79154 | 179 | { |
Azure.IoT Build | 0:fa2de1b79154 | 180 | XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio; |
Azure.IoT Build | 0:fa2de1b79154 | 181 | |
AzureIoTClient | 7:1af47e3a19b6 | 182 | if (strcmp(CONCRETE_OPTIONS, optionName) == 0) |
AzureIoTClient | 7:1af47e3a19b6 | 183 | { |
AzureIoTClient | 7:1af47e3a19b6 | 184 | /*then value is a pointer to OPTIONHANDLER_HANDLE*/ |
AzureIoTClient | 7:1af47e3a19b6 | 185 | if (OptionHandler_FeedOptions((OPTIONHANDLER_HANDLE)value, xio_instance->concrete_xio_handle) != OPTIONHANDLER_OK) |
AzureIoTClient | 7:1af47e3a19b6 | 186 | { |
AzureIoTClient | 7:1af47e3a19b6 | 187 | LogError("unable to OptionHandler_FeedOptions"); |
AzureIoTClient | 21:b92006c5b9ff | 188 | result = __FAILURE__; |
AzureIoTClient | 7:1af47e3a19b6 | 189 | } |
AzureIoTClient | 7:1af47e3a19b6 | 190 | else |
AzureIoTClient | 7:1af47e3a19b6 | 191 | { |
AzureIoTClient | 7:1af47e3a19b6 | 192 | result = 0; |
AzureIoTClient | 7:1af47e3a19b6 | 193 | } |
AzureIoTClient | 7:1af47e3a19b6 | 194 | } |
AzureIoTClient | 48:81866008bba4 | 195 | else /*passthrough*/ |
AzureIoTClient | 7:1af47e3a19b6 | 196 | { |
AzureIoTClient | 7:1af47e3a19b6 | 197 | /* Codes_SRS_XIO_003_028: [xio_setoption shall pass the optionName and value to the concrete IO implementation specified in xio_create by invoking the concrete_xio_setoption function.] */ |
AzureIoTClient | 7:1af47e3a19b6 | 198 | /* Codes_SRS_XIO_03_029: [xio_setoption shall return 0 upon success.] */ |
AzureIoTClient | 7:1af47e3a19b6 | 199 | /* Codes_SRS_XIO_03_031: [If the underlying concrete_xio_setoption fails, xio_setOption shall return a non-zero value.] */ |
AzureIoTClient | 7:1af47e3a19b6 | 200 | result = xio_instance->io_interface_description->concrete_io_setoption(xio_instance->concrete_xio_handle, optionName, value); |
AzureIoTClient | 7:1af47e3a19b6 | 201 | } |
Azure.IoT Build | 0:fa2de1b79154 | 202 | } |
Azure.IoT Build | 0:fa2de1b79154 | 203 | |
Azure.IoT Build | 0:fa2de1b79154 | 204 | return result; |
Azure.IoT Build | 0:fa2de1b79154 | 205 | } |
AzureIoTClient | 7:1af47e3a19b6 | 206 | |
AzureIoTClient | 7:1af47e3a19b6 | 207 | static void* xio_CloneOption(const char* name, const void* value) |
AzureIoTClient | 7:1af47e3a19b6 | 208 | { |
AzureIoTClient | 7:1af47e3a19b6 | 209 | void *result; |
AzureIoTClient | 7:1af47e3a19b6 | 210 | if ( |
AzureIoTClient | 7:1af47e3a19b6 | 211 | (name == NULL) || |
AzureIoTClient | 7:1af47e3a19b6 | 212 | (value == NULL) |
AzureIoTClient | 7:1af47e3a19b6 | 213 | ) |
AzureIoTClient | 7:1af47e3a19b6 | 214 | { |
AzureIoTClient | 7:1af47e3a19b6 | 215 | LogError("invalid argument detected: const char* name=%p, const void* value=%p", name, value); |
AzureIoTClient | 7:1af47e3a19b6 | 216 | result = NULL; |
AzureIoTClient | 7:1af47e3a19b6 | 217 | } |
AzureIoTClient | 7:1af47e3a19b6 | 218 | else |
AzureIoTClient | 7:1af47e3a19b6 | 219 | { |
AzureIoTClient | 7:1af47e3a19b6 | 220 | if (strcmp(name, CONCRETE_OPTIONS) == 0) |
AzureIoTClient | 7:1af47e3a19b6 | 221 | { |
AzureIoTClient | 7:1af47e3a19b6 | 222 | result = (void*)value; |
AzureIoTClient | 7:1af47e3a19b6 | 223 | } |
AzureIoTClient | 7:1af47e3a19b6 | 224 | else |
AzureIoTClient | 7:1af47e3a19b6 | 225 | { |
AzureIoTClient | 7:1af47e3a19b6 | 226 | LogError("unknown option: %s", name); |
AzureIoTClient | 7:1af47e3a19b6 | 227 | result = NULL; |
AzureIoTClient | 7:1af47e3a19b6 | 228 | } |
AzureIoTClient | 7:1af47e3a19b6 | 229 | } |
AzureIoTClient | 7:1af47e3a19b6 | 230 | return result; |
AzureIoTClient | 7:1af47e3a19b6 | 231 | } |
AzureIoTClient | 7:1af47e3a19b6 | 232 | |
AzureIoTClient | 7:1af47e3a19b6 | 233 | |
AzureIoTClient | 7:1af47e3a19b6 | 234 | static void xio_DestroyOption(const char* name, const void* value) |
AzureIoTClient | 7:1af47e3a19b6 | 235 | { |
AzureIoTClient | 7:1af47e3a19b6 | 236 | if ( |
AzureIoTClient | 7:1af47e3a19b6 | 237 | (name == NULL) || |
AzureIoTClient | 7:1af47e3a19b6 | 238 | (value == NULL) |
AzureIoTClient | 7:1af47e3a19b6 | 239 | ) |
AzureIoTClient | 7:1af47e3a19b6 | 240 | { |
AzureIoTClient | 7:1af47e3a19b6 | 241 | LogError("invalid argument detected: const char* name=%p, const void* value=%p", name, value); |
AzureIoTClient | 7:1af47e3a19b6 | 242 | } |
AzureIoTClient | 7:1af47e3a19b6 | 243 | else |
AzureIoTClient | 7:1af47e3a19b6 | 244 | { |
AzureIoTClient | 7:1af47e3a19b6 | 245 | if (strcmp(name, CONCRETE_OPTIONS) == 0) |
AzureIoTClient | 7:1af47e3a19b6 | 246 | { |
AzureIoTClient | 7:1af47e3a19b6 | 247 | OptionHandler_Destroy((OPTIONHANDLER_HANDLE)value); |
AzureIoTClient | 7:1af47e3a19b6 | 248 | } |
AzureIoTClient | 7:1af47e3a19b6 | 249 | else |
AzureIoTClient | 7:1af47e3a19b6 | 250 | { |
AzureIoTClient | 7:1af47e3a19b6 | 251 | LogError("unknown option: %s", name); |
AzureIoTClient | 7:1af47e3a19b6 | 252 | } |
AzureIoTClient | 7:1af47e3a19b6 | 253 | } |
AzureIoTClient | 7:1af47e3a19b6 | 254 | } |
AzureIoTClient | 7:1af47e3a19b6 | 255 | |
AzureIoTClient | 7:1af47e3a19b6 | 256 | OPTIONHANDLER_HANDLE xio_retrieveoptions(XIO_HANDLE xio) |
AzureIoTClient | 7:1af47e3a19b6 | 257 | { |
AzureIoTClient | 7:1af47e3a19b6 | 258 | OPTIONHANDLER_HANDLE result; |
AzureIoTClient | 7:1af47e3a19b6 | 259 | |
AzureIoTClient | 7:1af47e3a19b6 | 260 | if (xio == NULL) |
AzureIoTClient | 7:1af47e3a19b6 | 261 | { |
AzureIoTClient | 7:1af47e3a19b6 | 262 | LogError("invalid argument detected: XIO_HANDLE xio=%p", xio); |
AzureIoTClient | 7:1af47e3a19b6 | 263 | result = NULL; |
AzureIoTClient | 7:1af47e3a19b6 | 264 | } |
AzureIoTClient | 7:1af47e3a19b6 | 265 | else |
AzureIoTClient | 7:1af47e3a19b6 | 266 | { |
AzureIoTClient | 7:1af47e3a19b6 | 267 | XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio; |
AzureIoTClient | 7:1af47e3a19b6 | 268 | /*xio_retrieveoptions shall return a OPTIONHANDLER_HANDLE that has 1 option called "underlyingOptions" which is of type OPTIONHANDLER_HANDLE*/ |
AzureIoTClient | 7:1af47e3a19b6 | 269 | result = OptionHandler_Create(xio_CloneOption, xio_DestroyOption, (pfSetOption)xio_setoption); |
AzureIoTClient | 7:1af47e3a19b6 | 270 | if (result == NULL) |
AzureIoTClient | 7:1af47e3a19b6 | 271 | { |
AzureIoTClient | 7:1af47e3a19b6 | 272 | LogError("unable to OptionHandler_Create"); |
AzureIoTClient | 7:1af47e3a19b6 | 273 | /*return as is*/ |
AzureIoTClient | 7:1af47e3a19b6 | 274 | } |
AzureIoTClient | 7:1af47e3a19b6 | 275 | else |
AzureIoTClient | 7:1af47e3a19b6 | 276 | { |
AzureIoTClient | 7:1af47e3a19b6 | 277 | OPTIONHANDLER_HANDLE concreteOptions = xio_instance->io_interface_description->concrete_io_retrieveoptions(xio_instance->concrete_xio_handle); |
AzureIoTClient | 7:1af47e3a19b6 | 278 | if (concreteOptions == NULL) |
AzureIoTClient | 7:1af47e3a19b6 | 279 | { |
AzureIoTClient | 7:1af47e3a19b6 | 280 | LogError("unable to concrete_io_retrieveoptions"); |
AzureIoTClient | 7:1af47e3a19b6 | 281 | OptionHandler_Destroy(result); |
AzureIoTClient | 7:1af47e3a19b6 | 282 | result = NULL; |
AzureIoTClient | 7:1af47e3a19b6 | 283 | } |
AzureIoTClient | 7:1af47e3a19b6 | 284 | else |
AzureIoTClient | 7:1af47e3a19b6 | 285 | { |
AzureIoTClient | 7:1af47e3a19b6 | 286 | if (OptionHandler_AddOption(result, CONCRETE_OPTIONS, concreteOptions) != OPTIONHANDLER_OK) |
AzureIoTClient | 7:1af47e3a19b6 | 287 | { |
AzureIoTClient | 7:1af47e3a19b6 | 288 | LogError("unable to OptionHandler_AddOption"); |
AzureIoTClient | 7:1af47e3a19b6 | 289 | OptionHandler_Destroy(concreteOptions); |
AzureIoTClient | 7:1af47e3a19b6 | 290 | OptionHandler_Destroy(result); |
AzureIoTClient | 7:1af47e3a19b6 | 291 | result = NULL; |
AzureIoTClient | 7:1af47e3a19b6 | 292 | } |
AzureIoTClient | 7:1af47e3a19b6 | 293 | else |
AzureIoTClient | 7:1af47e3a19b6 | 294 | { |
AzureIoTClient | 7:1af47e3a19b6 | 295 | /*all is fine*/ |
AzureIoTClient | 7:1af47e3a19b6 | 296 | } |
AzureIoTClient | 7:1af47e3a19b6 | 297 | } |
AzureIoTClient | 7:1af47e3a19b6 | 298 | } |
AzureIoTClient | 7:1af47e3a19b6 | 299 | } |
AzureIoTClient | 7:1af47e3a19b6 | 300 | |
AzureIoTClient | 7:1af47e3a19b6 | 301 | return result; |
AzureIoTClient | 7:1af47e3a19b6 | 302 | } |
AzureIoTClient | 7:1af47e3a19b6 | 303 |