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 Jul 29 16:01:07 2016 -0700
Revision:
7:1af47e3a19b6
Parent:
6:c55b013dfc2a
Child:
19:2e0811512ceb
1.0.10

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