Azure IoT common library

Dependents:   STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more

Committer:
AzureIoTClient
Date:
Fri Feb 24 14:01:41 2017 -0800
Revision:
21:b92006c5b9ff
Parent:
19:2e0811512ceb
Child:
32:3b68703b9316
1.1.8

Who changed what in which revision?

UserRevisionLine numberNew 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"
Azure.IoT Build 0:fa2de1b79154 9
AzureIoTClient 7:1af47e3a19b6 10 static const char* CONCRETE_OPTIONS = "concreteOptions";
AzureIoTClient 7:1af47e3a19b6 11
Azure.IoT Build 0:fa2de1b79154 12 typedef struct XIO_INSTANCE_TAG
Azure.IoT Build 0:fa2de1b79154 13 {
Azure.IoT Build 0:fa2de1b79154 14 const IO_INTERFACE_DESCRIPTION* io_interface_description;
AzureIoTClient 19:2e0811512ceb 15 CONCRETE_IO_HANDLE concrete_xio_handle;
Azure.IoT Build 0:fa2de1b79154 16 } XIO_INSTANCE;
Azure.IoT Build 0:fa2de1b79154 17
Azure.IoT Build 6:c55b013dfc2a 18 XIO_HANDLE xio_create(const IO_INTERFACE_DESCRIPTION* io_interface_description, const void* xio_create_parameters)
Azure.IoT Build 0:fa2de1b79154 19 {
Azure.IoT Build 0:fa2de1b79154 20 XIO_INSTANCE* xio_instance;
Azure.IoT Build 0:fa2de1b79154 21 /* Codes_SRS_XIO_01_003: [If the argument io_interface_description is NULL, xio_create shall return NULL.] */
Azure.IoT Build 0:fa2de1b79154 22 if ((io_interface_description == NULL) ||
Azure.IoT Build 0:fa2de1b79154 23 /* Codes_SRS_XIO_01_004: [If any io_interface_description member is NULL, xio_create shall return NULL.] */
AzureIoTClient 7:1af47e3a19b6 24 (io_interface_description->concrete_io_retrieveoptions == NULL) ||
Azure.IoT Build 0:fa2de1b79154 25 (io_interface_description->concrete_io_create == NULL) ||
Azure.IoT Build 0:fa2de1b79154 26 (io_interface_description->concrete_io_destroy == NULL) ||
Azure.IoT Build 0:fa2de1b79154 27 (io_interface_description->concrete_io_open == NULL) ||
Azure.IoT Build 0:fa2de1b79154 28 (io_interface_description->concrete_io_close == NULL) ||
Azure.IoT Build 0:fa2de1b79154 29 (io_interface_description->concrete_io_send == NULL) ||
Azure.IoT Build 0:fa2de1b79154 30 (io_interface_description->concrete_io_dowork == NULL) ||
Azure.IoT Build 0:fa2de1b79154 31 (io_interface_description->concrete_io_setoption == NULL))
Azure.IoT Build 0:fa2de1b79154 32 {
Azure.IoT Build 0:fa2de1b79154 33 xio_instance = NULL;
Azure.IoT Build 0:fa2de1b79154 34 }
Azure.IoT Build 0:fa2de1b79154 35 else
Azure.IoT Build 0:fa2de1b79154 36 {
Azure.IoT Build 0:fa2de1b79154 37 xio_instance = (XIO_INSTANCE*)malloc(sizeof(XIO_INSTANCE));
Azure.IoT Build 0:fa2de1b79154 38
Azure.IoT Build 0:fa2de1b79154 39 /* 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 40 if (xio_instance != NULL)
Azure.IoT Build 0:fa2de1b79154 41 {
Azure.IoT Build 0:fa2de1b79154 42 /* 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 43 xio_instance->io_interface_description = io_interface_description;
Azure.IoT Build 0:fa2de1b79154 44
Azure.IoT Build 6:c55b013dfc2a 45 /* 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 46 xio_instance->concrete_xio_handle = xio_instance->io_interface_description->concrete_io_create((void*)xio_create_parameters);
Azure.IoT Build 0:fa2de1b79154 47
Azure.IoT Build 0:fa2de1b79154 48 /* Codes_SRS_XIO_01_016: [If the underlying concrete_io_create call fails, xio_create shall return NULL.] */
Azure.IoT Build 0:fa2de1b79154 49 if (xio_instance->concrete_xio_handle == NULL)
Azure.IoT Build 0:fa2de1b79154 50 {
Azure.IoT Build 0:fa2de1b79154 51 free(xio_instance);
Azure.IoT Build 0:fa2de1b79154 52 xio_instance = NULL;
Azure.IoT Build 0:fa2de1b79154 53 }
Azure.IoT Build 0:fa2de1b79154 54 }
Azure.IoT Build 0:fa2de1b79154 55 }
Azure.IoT Build 0:fa2de1b79154 56 return (XIO_HANDLE)xio_instance;
Azure.IoT Build 0:fa2de1b79154 57 }
Azure.IoT Build 0:fa2de1b79154 58
Azure.IoT Build 0:fa2de1b79154 59 void xio_destroy(XIO_HANDLE xio)
Azure.IoT Build 0:fa2de1b79154 60 {
Azure.IoT Build 0:fa2de1b79154 61 /* Codes_SRS_XIO_01_007: [If the argument io is NULL, xio_destroy shall do nothing.] */
Azure.IoT Build 0:fa2de1b79154 62 if (xio != NULL)
Azure.IoT Build 0:fa2de1b79154 63 {
Azure.IoT Build 0:fa2de1b79154 64 XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio;
Azure.IoT Build 0:fa2de1b79154 65
Azure.IoT Build 0:fa2de1b79154 66 /* 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 67 xio_instance->io_interface_description->concrete_io_destroy(xio_instance->concrete_xio_handle);
Azure.IoT Build 0:fa2de1b79154 68
Azure.IoT Build 0:fa2de1b79154 69 /* Codes_SRS_XIO_01_005: [xio_destroy shall free all resources associated with the IO handle.] */
Azure.IoT Build 0:fa2de1b79154 70 free(xio_instance);
Azure.IoT Build 0:fa2de1b79154 71 }
Azure.IoT Build 0:fa2de1b79154 72 }
Azure.IoT Build 0:fa2de1b79154 73
Azure.IoT Build 0:fa2de1b79154 74 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 75 {
Azure.IoT Build 0:fa2de1b79154 76 int result;
Azure.IoT Build 0:fa2de1b79154 77
Azure.IoT Build 0:fa2de1b79154 78 if (xio == NULL)
Azure.IoT Build 0:fa2de1b79154 79 {
Azure.IoT Build 0:fa2de1b79154 80 /* Codes_SRS_XIO_01_021: [If handle is NULL, xio_open shall return a non-zero value.] */
AzureIoTClient 21:b92006c5b9ff 81 result = __FAILURE__;
Azure.IoT Build 0:fa2de1b79154 82 }
Azure.IoT Build 0:fa2de1b79154 83 else
Azure.IoT Build 0:fa2de1b79154 84 {
Azure.IoT Build 0:fa2de1b79154 85 XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio;
Azure.IoT Build 0:fa2de1b79154 86
Azure.IoT Build 0:fa2de1b79154 87 /* 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 88 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 89 {
Azure.IoT Build 0:fa2de1b79154 90 /* Codes_SRS_XIO_01_022: [If the underlying concrete_io_open fails, xio_open shall return a non-zero value.] */
AzureIoTClient 21:b92006c5b9ff 91 result = __FAILURE__;
Azure.IoT Build 0:fa2de1b79154 92 }
Azure.IoT Build 0:fa2de1b79154 93 else
Azure.IoT Build 0:fa2de1b79154 94 {
Azure.IoT Build 0:fa2de1b79154 95 /* Codes_SRS_XIO_01_020: [On success, xio_open shall return 0.] */
Azure.IoT Build 0:fa2de1b79154 96 result = 0;
Azure.IoT Build 0:fa2de1b79154 97 }
Azure.IoT Build 0:fa2de1b79154 98 }
Azure.IoT Build 0:fa2de1b79154 99
Azure.IoT Build 0:fa2de1b79154 100 return result;
Azure.IoT Build 0:fa2de1b79154 101 }
Azure.IoT Build 0:fa2de1b79154 102
Azure.IoT Build 0:fa2de1b79154 103 int xio_close(XIO_HANDLE xio, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context)
Azure.IoT Build 0:fa2de1b79154 104 {
Azure.IoT Build 0:fa2de1b79154 105 int result;
Azure.IoT Build 0:fa2de1b79154 106
Azure.IoT Build 0:fa2de1b79154 107 if (xio == NULL)
Azure.IoT Build 0:fa2de1b79154 108 {
Azure.IoT Build 0:fa2de1b79154 109 /* Codes_SRS_XIO_01_025: [If handle is NULL, xio_close shall return a non-zero value.] */
AzureIoTClient 21:b92006c5b9ff 110 result = __FAILURE__;
Azure.IoT Build 0:fa2de1b79154 111 }
Azure.IoT Build 0:fa2de1b79154 112 else
Azure.IoT Build 0:fa2de1b79154 113 {
Azure.IoT Build 0:fa2de1b79154 114 XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio;
Azure.IoT Build 0:fa2de1b79154 115
Azure.IoT Build 0:fa2de1b79154 116 /* Codes_SRS_XIO_01_023: [xio_close shall call the specific concrete_io_close function specified in xio_create.] */
Azure.IoT Build 0:fa2de1b79154 117 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 118 {
Azure.IoT Build 0:fa2de1b79154 119 /* Codes_SRS_XIO_01_026: [If the underlying concrete_io_close fails, xio_close shall return a non-zero value.] */
AzureIoTClient 21:b92006c5b9ff 120 result = __FAILURE__;
Azure.IoT Build 0:fa2de1b79154 121 }
Azure.IoT Build 0:fa2de1b79154 122 else
Azure.IoT Build 0:fa2de1b79154 123 {
Azure.IoT Build 0:fa2de1b79154 124 /* Codes_SRS_XIO_01_024: [On success, xio_close shall return 0.] */
Azure.IoT Build 0:fa2de1b79154 125 result = 0;
Azure.IoT Build 0:fa2de1b79154 126 }
Azure.IoT Build 0:fa2de1b79154 127 }
Azure.IoT Build 0:fa2de1b79154 128
Azure.IoT Build 0:fa2de1b79154 129 return result;
Azure.IoT Build 0:fa2de1b79154 130 }
Azure.IoT Build 0:fa2de1b79154 131
Azure.IoT Build 0:fa2de1b79154 132 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 133 {
Azure.IoT Build 0:fa2de1b79154 134 int result;
Azure.IoT Build 0:fa2de1b79154 135
Azure.IoT Build 0:fa2de1b79154 136 /* Codes_SRS_XIO_01_011: [No error check shall be performed on buffer and size.] */
Azure.IoT Build 0:fa2de1b79154 137 /* Codes_SRS_XIO_01_010: [If handle is NULL, xio_send shall return a non-zero value.] */
Azure.IoT Build 0:fa2de1b79154 138 if (xio == NULL)
Azure.IoT Build 0:fa2de1b79154 139 {
AzureIoTClient 21:b92006c5b9ff 140 result = __FAILURE__;
Azure.IoT Build 0:fa2de1b79154 141 }
Azure.IoT Build 0:fa2de1b79154 142 else
Azure.IoT Build 0:fa2de1b79154 143 {
Azure.IoT Build 0:fa2de1b79154 144 XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio;
Azure.IoT Build 0:fa2de1b79154 145
Azure.IoT Build 0:fa2de1b79154 146 /* 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 147 /* Codes_SRS_XIO_01_009: [On success, xio_send shall return 0.] */
Azure.IoT Build 0:fa2de1b79154 148 /* 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 149 /* 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 150 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 151 }
Azure.IoT Build 0:fa2de1b79154 152
Azure.IoT Build 0:fa2de1b79154 153 return result;
Azure.IoT Build 0:fa2de1b79154 154 }
Azure.IoT Build 0:fa2de1b79154 155
Azure.IoT Build 0:fa2de1b79154 156 void xio_dowork(XIO_HANDLE xio)
Azure.IoT Build 0:fa2de1b79154 157 {
Azure.IoT Build 0:fa2de1b79154 158 /* Codes_SRS_XIO_01_018: [When the handle argument is NULL, xio_dowork shall do nothing.] */
Azure.IoT Build 0:fa2de1b79154 159 if (xio != NULL)
Azure.IoT Build 0:fa2de1b79154 160 {
Azure.IoT Build 0:fa2de1b79154 161 XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio;
Azure.IoT Build 0:fa2de1b79154 162
Azure.IoT Build 0:fa2de1b79154 163 /* 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 164 xio_instance->io_interface_description->concrete_io_dowork(xio_instance->concrete_xio_handle);
Azure.IoT Build 0:fa2de1b79154 165 }
Azure.IoT Build 0:fa2de1b79154 166 }
Azure.IoT Build 0:fa2de1b79154 167
Azure.IoT Build 0:fa2de1b79154 168 int xio_setoption(XIO_HANDLE xio, const char* optionName, const void* value)
Azure.IoT Build 0:fa2de1b79154 169 {
Azure.IoT Build 0:fa2de1b79154 170 int result;
Azure.IoT Build 0:fa2de1b79154 171
AzureIoTClient 7:1af47e3a19b6 172 /* 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 173 if (xio == NULL || optionName == NULL)
Azure.IoT Build 0:fa2de1b79154 174 {
AzureIoTClient 21:b92006c5b9ff 175 result = __FAILURE__;
Azure.IoT Build 0:fa2de1b79154 176 }
Azure.IoT Build 0:fa2de1b79154 177 else
Azure.IoT Build 0:fa2de1b79154 178 {
Azure.IoT Build 0:fa2de1b79154 179 XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio;
Azure.IoT Build 0:fa2de1b79154 180
AzureIoTClient 7:1af47e3a19b6 181 if (strcmp(CONCRETE_OPTIONS, optionName) == 0)
AzureIoTClient 7:1af47e3a19b6 182 {
AzureIoTClient 7:1af47e3a19b6 183 /*then value is a pointer to OPTIONHANDLER_HANDLE*/
AzureIoTClient 7:1af47e3a19b6 184 if (OptionHandler_FeedOptions((OPTIONHANDLER_HANDLE)value, xio_instance->concrete_xio_handle) != OPTIONHANDLER_OK)
AzureIoTClient 7:1af47e3a19b6 185 {
AzureIoTClient 7:1af47e3a19b6 186 LogError("unable to OptionHandler_FeedOptions");
AzureIoTClient 21:b92006c5b9ff 187 result = __FAILURE__;
AzureIoTClient 7:1af47e3a19b6 188 }
AzureIoTClient 7:1af47e3a19b6 189 else
AzureIoTClient 7:1af47e3a19b6 190 {
AzureIoTClient 7:1af47e3a19b6 191 result = 0;
AzureIoTClient 7:1af47e3a19b6 192 }
AzureIoTClient 7:1af47e3a19b6 193 }
AzureIoTClient 7:1af47e3a19b6 194 else /*passthrough*/
AzureIoTClient 7:1af47e3a19b6 195 {
AzureIoTClient 7:1af47e3a19b6 196 /* 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 197 /* Codes_SRS_XIO_03_029: [xio_setoption shall return 0 upon success.] */
AzureIoTClient 7:1af47e3a19b6 198 /* Codes_SRS_XIO_03_031: [If the underlying concrete_xio_setoption fails, xio_setOption shall return a non-zero value.] */
AzureIoTClient 7:1af47e3a19b6 199 result = xio_instance->io_interface_description->concrete_io_setoption(xio_instance->concrete_xio_handle, optionName, value);
AzureIoTClient 7:1af47e3a19b6 200 }
Azure.IoT Build 0:fa2de1b79154 201 }
Azure.IoT Build 0:fa2de1b79154 202
Azure.IoT Build 0:fa2de1b79154 203 return result;
Azure.IoT Build 0:fa2de1b79154 204 }
AzureIoTClient 7:1af47e3a19b6 205
AzureIoTClient 7:1af47e3a19b6 206 static void* xio_CloneOption(const char* name, const void* value)
AzureIoTClient 7:1af47e3a19b6 207 {
AzureIoTClient 7:1af47e3a19b6 208 void *result;
AzureIoTClient 7:1af47e3a19b6 209 if (
AzureIoTClient 7:1af47e3a19b6 210 (name == NULL) ||
AzureIoTClient 7:1af47e3a19b6 211 (value == NULL)
AzureIoTClient 7:1af47e3a19b6 212 )
AzureIoTClient 7:1af47e3a19b6 213 {
AzureIoTClient 7:1af47e3a19b6 214 LogError("invalid argument detected: const char* name=%p, const void* value=%p", name, value);
AzureIoTClient 7:1af47e3a19b6 215 result = NULL;
AzureIoTClient 7:1af47e3a19b6 216 }
AzureIoTClient 7:1af47e3a19b6 217 else
AzureIoTClient 7:1af47e3a19b6 218 {
AzureIoTClient 7:1af47e3a19b6 219 if (strcmp(name, CONCRETE_OPTIONS) == 0)
AzureIoTClient 7:1af47e3a19b6 220 {
AzureIoTClient 7:1af47e3a19b6 221 result = (void*)value;
AzureIoTClient 7:1af47e3a19b6 222 }
AzureIoTClient 7:1af47e3a19b6 223 else
AzureIoTClient 7:1af47e3a19b6 224 {
AzureIoTClient 7:1af47e3a19b6 225 LogError("unknown option: %s", name);
AzureIoTClient 7:1af47e3a19b6 226 result = NULL;
AzureIoTClient 7:1af47e3a19b6 227 }
AzureIoTClient 7:1af47e3a19b6 228 }
AzureIoTClient 7:1af47e3a19b6 229 return result;
AzureIoTClient 7:1af47e3a19b6 230 }
AzureIoTClient 7:1af47e3a19b6 231
AzureIoTClient 7:1af47e3a19b6 232
AzureIoTClient 7:1af47e3a19b6 233 static void xio_DestroyOption(const char* name, const void* value)
AzureIoTClient 7:1af47e3a19b6 234 {
AzureIoTClient 7:1af47e3a19b6 235 if (
AzureIoTClient 7:1af47e3a19b6 236 (name == NULL) ||
AzureIoTClient 7:1af47e3a19b6 237 (value == NULL)
AzureIoTClient 7:1af47e3a19b6 238 )
AzureIoTClient 7:1af47e3a19b6 239 {
AzureIoTClient 7:1af47e3a19b6 240 LogError("invalid argument detected: const char* name=%p, const void* value=%p", name, value);
AzureIoTClient 7:1af47e3a19b6 241 }
AzureIoTClient 7:1af47e3a19b6 242 else
AzureIoTClient 7:1af47e3a19b6 243 {
AzureIoTClient 7:1af47e3a19b6 244 if (strcmp(name, CONCRETE_OPTIONS) == 0)
AzureIoTClient 7:1af47e3a19b6 245 {
AzureIoTClient 7:1af47e3a19b6 246 OptionHandler_Destroy((OPTIONHANDLER_HANDLE)value);
AzureIoTClient 7:1af47e3a19b6 247 }
AzureIoTClient 7:1af47e3a19b6 248 else
AzureIoTClient 7:1af47e3a19b6 249 {
AzureIoTClient 7:1af47e3a19b6 250 LogError("unknown option: %s", name);
AzureIoTClient 7:1af47e3a19b6 251 }
AzureIoTClient 7:1af47e3a19b6 252 }
AzureIoTClient 7:1af47e3a19b6 253 }
AzureIoTClient 7:1af47e3a19b6 254
AzureIoTClient 7:1af47e3a19b6 255 OPTIONHANDLER_HANDLE xio_retrieveoptions(XIO_HANDLE xio)
AzureIoTClient 7:1af47e3a19b6 256 {
AzureIoTClient 7:1af47e3a19b6 257 OPTIONHANDLER_HANDLE result;
AzureIoTClient 7:1af47e3a19b6 258
AzureIoTClient 7:1af47e3a19b6 259 if (xio == NULL)
AzureIoTClient 7:1af47e3a19b6 260 {
AzureIoTClient 7:1af47e3a19b6 261 LogError("invalid argument detected: XIO_HANDLE xio=%p", xio);
AzureIoTClient 7:1af47e3a19b6 262 result = NULL;
AzureIoTClient 7:1af47e3a19b6 263 }
AzureIoTClient 7:1af47e3a19b6 264 else
AzureIoTClient 7:1af47e3a19b6 265 {
AzureIoTClient 7:1af47e3a19b6 266 XIO_INSTANCE* xio_instance = (XIO_INSTANCE*)xio;
AzureIoTClient 7:1af47e3a19b6 267 /*xio_retrieveoptions shall return a OPTIONHANDLER_HANDLE that has 1 option called "underlyingOptions" which is of type OPTIONHANDLER_HANDLE*/
AzureIoTClient 7:1af47e3a19b6 268 result = OptionHandler_Create(xio_CloneOption, xio_DestroyOption, (pfSetOption)xio_setoption);
AzureIoTClient 7:1af47e3a19b6 269 if (result == NULL)
AzureIoTClient 7:1af47e3a19b6 270 {
AzureIoTClient 7:1af47e3a19b6 271 LogError("unable to OptionHandler_Create");
AzureIoTClient 7:1af47e3a19b6 272 /*return as is*/
AzureIoTClient 7:1af47e3a19b6 273 }
AzureIoTClient 7:1af47e3a19b6 274 else
AzureIoTClient 7:1af47e3a19b6 275 {
AzureIoTClient 7:1af47e3a19b6 276 OPTIONHANDLER_HANDLE concreteOptions = xio_instance->io_interface_description->concrete_io_retrieveoptions(xio_instance->concrete_xio_handle);
AzureIoTClient 7:1af47e3a19b6 277 if (concreteOptions == NULL)
AzureIoTClient 7:1af47e3a19b6 278 {
AzureIoTClient 7:1af47e3a19b6 279 LogError("unable to concrete_io_retrieveoptions");
AzureIoTClient 7:1af47e3a19b6 280 OptionHandler_Destroy(result);
AzureIoTClient 7:1af47e3a19b6 281 result = NULL;
AzureIoTClient 7:1af47e3a19b6 282 }
AzureIoTClient 7:1af47e3a19b6 283 else
AzureIoTClient 7:1af47e3a19b6 284 {
AzureIoTClient 7:1af47e3a19b6 285 if (OptionHandler_AddOption(result, CONCRETE_OPTIONS, concreteOptions) != OPTIONHANDLER_OK)
AzureIoTClient 7:1af47e3a19b6 286 {
AzureIoTClient 7:1af47e3a19b6 287 LogError("unable to OptionHandler_AddOption");
AzureIoTClient 7:1af47e3a19b6 288 OptionHandler_Destroy(concreteOptions);
AzureIoTClient 7:1af47e3a19b6 289 OptionHandler_Destroy(result);
AzureIoTClient 7:1af47e3a19b6 290 result = NULL;
AzureIoTClient 7:1af47e3a19b6 291 }
AzureIoTClient 7:1af47e3a19b6 292 else
AzureIoTClient 7:1af47e3a19b6 293 {
AzureIoTClient 7:1af47e3a19b6 294 /*all is fine*/
AzureIoTClient 7:1af47e3a19b6 295 }
AzureIoTClient 7:1af47e3a19b6 296 }
AzureIoTClient 7:1af47e3a19b6 297 }
AzureIoTClient 7:1af47e3a19b6 298 }
AzureIoTClient 7:1af47e3a19b6 299
AzureIoTClient 7:1af47e3a19b6 300 return result;
AzureIoTClient 7:1af47e3a19b6 301 }
AzureIoTClient 7:1af47e3a19b6 302