Azure IoT common library

Dependents:   STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more

Committer:
AzureIoTClient
Date:
Sat Jan 28 09:35:22 2017 -0800
Revision:
19:2e0811512ceb
Parent:
7:1af47e3a19b6
Child:
21:b92006c5b9ff
1.1.6

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