A small memory footprint AMQP implimentation

Dependents:   iothub_client_sample_amqp remote_monitoring simplesample_amqp

Committer:
Azure.IoT Build
Date:
Fri Jul 01 10:42:48 2016 -0700
Revision:
5:ae49385aff34
Parent:
1:eab586236bfe
Child:
6:641a9672db08
1.0.10

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Azure.IoT Build 0:6ae2f7bca550 1 // Copyright (c) Microsoft. All rights reserved.
Azure.IoT Build 0:6ae2f7bca550 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
Azure.IoT Build 0:6ae2f7bca550 3
Azure.IoT Build 0:6ae2f7bca550 4 #include "azure_uamqp_c/header_detect_io.h"
Azure.IoT Build 0:6ae2f7bca550 5 #include "azure_uamqp_c/amqpalloc.h"
Azure.IoT Build 0:6ae2f7bca550 6
Azure.IoT Build 0:6ae2f7bca550 7 typedef enum IO_STATE_TAG
Azure.IoT Build 0:6ae2f7bca550 8 {
Azure.IoT Build 0:6ae2f7bca550 9 IO_STATE_NOT_OPEN,
Azure.IoT Build 0:6ae2f7bca550 10 IO_STATE_OPENING_UNDERLYING_IO,
Azure.IoT Build 0:6ae2f7bca550 11 IO_STATE_WAIT_FOR_HEADER,
Azure.IoT Build 0:6ae2f7bca550 12 IO_STATE_OPEN,
Azure.IoT Build 0:6ae2f7bca550 13 IO_STATE_CLOSING,
Azure.IoT Build 0:6ae2f7bca550 14 IO_STATE_ERROR
Azure.IoT Build 0:6ae2f7bca550 15 } IO_STATE;
Azure.IoT Build 0:6ae2f7bca550 16
Azure.IoT Build 0:6ae2f7bca550 17 typedef struct HEADER_DETECT_IO_INSTANCE_TAG
Azure.IoT Build 0:6ae2f7bca550 18 {
Azure.IoT Build 0:6ae2f7bca550 19 XIO_HANDLE underlying_io;
Azure.IoT Build 0:6ae2f7bca550 20 size_t header_pos;
Azure.IoT Build 0:6ae2f7bca550 21 IO_STATE io_state;
Azure.IoT Build 0:6ae2f7bca550 22 ON_IO_OPEN_COMPLETE on_io_open_complete;
Azure.IoT Build 0:6ae2f7bca550 23 ON_IO_CLOSE_COMPLETE on_io_close_complete;
Azure.IoT Build 0:6ae2f7bca550 24 ON_IO_ERROR on_io_error;
Azure.IoT Build 0:6ae2f7bca550 25 ON_BYTES_RECEIVED on_bytes_received;
Azure.IoT Build 0:6ae2f7bca550 26 void* on_io_open_complete_context;
Azure.IoT Build 0:6ae2f7bca550 27 void* on_io_close_complete_context;
Azure.IoT Build 0:6ae2f7bca550 28 void* on_io_error_context;
Azure.IoT Build 0:6ae2f7bca550 29 void* on_bytes_received_context;
Azure.IoT Build 0:6ae2f7bca550 30 } HEADER_DETECT_IO_INSTANCE;
Azure.IoT Build 0:6ae2f7bca550 31
Azure.IoT Build 0:6ae2f7bca550 32 static const unsigned char amqp_header[] = { 'A', 'M', 'Q', 'P', 0, 1, 0, 0 };
Azure.IoT Build 0:6ae2f7bca550 33
Azure.IoT Build 0:6ae2f7bca550 34 static void indicate_error(HEADER_DETECT_IO_INSTANCE* header_detect_io_instance)
Azure.IoT Build 0:6ae2f7bca550 35 {
Azure.IoT Build 0:6ae2f7bca550 36 if (header_detect_io_instance->on_io_error != NULL)
Azure.IoT Build 0:6ae2f7bca550 37 {
Azure.IoT Build 0:6ae2f7bca550 38 header_detect_io_instance->on_io_error(header_detect_io_instance->on_io_error_context);
Azure.IoT Build 0:6ae2f7bca550 39 }
Azure.IoT Build 0:6ae2f7bca550 40 }
Azure.IoT Build 0:6ae2f7bca550 41
Azure.IoT Build 0:6ae2f7bca550 42 static void indicate_open_complete(HEADER_DETECT_IO_INSTANCE* header_detect_io_instance, IO_OPEN_RESULT open_result)
Azure.IoT Build 0:6ae2f7bca550 43 {
Azure.IoT Build 0:6ae2f7bca550 44 if (header_detect_io_instance->on_io_open_complete != NULL)
Azure.IoT Build 0:6ae2f7bca550 45 {
Azure.IoT Build 0:6ae2f7bca550 46 header_detect_io_instance->on_io_open_complete(header_detect_io_instance->on_io_open_complete_context, open_result);
Azure.IoT Build 0:6ae2f7bca550 47 }
Azure.IoT Build 0:6ae2f7bca550 48 }
Azure.IoT Build 0:6ae2f7bca550 49
Azure.IoT Build 0:6ae2f7bca550 50 static void indicate_close_complete(HEADER_DETECT_IO_INSTANCE* header_detect_io_instance)
Azure.IoT Build 0:6ae2f7bca550 51 {
Azure.IoT Build 0:6ae2f7bca550 52 if (header_detect_io_instance->on_io_close_complete != NULL)
Azure.IoT Build 0:6ae2f7bca550 53 {
Azure.IoT Build 0:6ae2f7bca550 54 header_detect_io_instance->on_io_close_complete(header_detect_io_instance->on_io_close_complete_context);
Azure.IoT Build 0:6ae2f7bca550 55 }
Azure.IoT Build 0:6ae2f7bca550 56 }
Azure.IoT Build 0:6ae2f7bca550 57
Azure.IoT Build 0:6ae2f7bca550 58 static void on_underlying_io_error(void* context);
Azure.IoT Build 0:6ae2f7bca550 59 static void on_send_complete_close(void* context, IO_SEND_RESULT send_result)
Azure.IoT Build 0:6ae2f7bca550 60 {
Azure.IoT Build 0:6ae2f7bca550 61 on_underlying_io_error(context);
Azure.IoT Build 0:6ae2f7bca550 62 }
Azure.IoT Build 0:6ae2f7bca550 63
Azure.IoT Build 0:6ae2f7bca550 64 static void on_underlying_io_bytes_received(void* context, const unsigned char* buffer, size_t size)
Azure.IoT Build 0:6ae2f7bca550 65 {
Azure.IoT Build 0:6ae2f7bca550 66 HEADER_DETECT_IO_INSTANCE* header_detect_io_instance = (HEADER_DETECT_IO_INSTANCE*)context;
Azure.IoT Build 0:6ae2f7bca550 67
Azure.IoT Build 0:6ae2f7bca550 68 while (size > 0)
Azure.IoT Build 0:6ae2f7bca550 69 {
Azure.IoT Build 0:6ae2f7bca550 70 switch (header_detect_io_instance->io_state)
Azure.IoT Build 0:6ae2f7bca550 71 {
Azure.IoT Build 0:6ae2f7bca550 72 default:
Azure.IoT Build 0:6ae2f7bca550 73 break;
Azure.IoT Build 0:6ae2f7bca550 74
Azure.IoT Build 0:6ae2f7bca550 75 case IO_STATE_WAIT_FOR_HEADER:
Azure.IoT Build 0:6ae2f7bca550 76 if (amqp_header[header_detect_io_instance->header_pos] != buffer[0])
Azure.IoT Build 0:6ae2f7bca550 77 {
Azure.IoT Build 0:6ae2f7bca550 78 /* Send expected header, then close as per spec. We do not care if we fail */
Azure.IoT Build 0:6ae2f7bca550 79 (void)xio_send(header_detect_io_instance->underlying_io, amqp_header, sizeof(amqp_header), on_send_complete_close, context);
Azure.IoT Build 0:6ae2f7bca550 80
Azure.IoT Build 0:6ae2f7bca550 81 header_detect_io_instance->io_state = IO_STATE_NOT_OPEN;
Azure.IoT Build 0:6ae2f7bca550 82 indicate_open_complete(header_detect_io_instance, IO_OPEN_ERROR);
Azure.IoT Build 0:6ae2f7bca550 83 size = 0;
Azure.IoT Build 0:6ae2f7bca550 84 }
Azure.IoT Build 0:6ae2f7bca550 85 else
Azure.IoT Build 0:6ae2f7bca550 86 {
Azure.IoT Build 0:6ae2f7bca550 87 header_detect_io_instance->header_pos++;
Azure.IoT Build 0:6ae2f7bca550 88 size--;
Azure.IoT Build 0:6ae2f7bca550 89 buffer++;
Azure.IoT Build 0:6ae2f7bca550 90 if (header_detect_io_instance->header_pos == sizeof(amqp_header))
Azure.IoT Build 0:6ae2f7bca550 91 {
Azure.IoT Build 0:6ae2f7bca550 92 if (xio_send(header_detect_io_instance->underlying_io, amqp_header, sizeof(amqp_header), NULL, NULL) != 0)
Azure.IoT Build 0:6ae2f7bca550 93 {
Azure.IoT Build 0:6ae2f7bca550 94 header_detect_io_instance->io_state = IO_STATE_NOT_OPEN;
Azure.IoT Build 0:6ae2f7bca550 95 indicate_open_complete(header_detect_io_instance, IO_OPEN_ERROR);
Azure.IoT Build 0:6ae2f7bca550 96 }
Azure.IoT Build 0:6ae2f7bca550 97 else
Azure.IoT Build 0:6ae2f7bca550 98 {
Azure.IoT Build 0:6ae2f7bca550 99 header_detect_io_instance->io_state = IO_STATE_OPEN;
Azure.IoT Build 0:6ae2f7bca550 100 indicate_open_complete(header_detect_io_instance, IO_OPEN_OK);
Azure.IoT Build 0:6ae2f7bca550 101 }
Azure.IoT Build 0:6ae2f7bca550 102 }
Azure.IoT Build 0:6ae2f7bca550 103 }
Azure.IoT Build 0:6ae2f7bca550 104 break;
Azure.IoT Build 0:6ae2f7bca550 105
Azure.IoT Build 0:6ae2f7bca550 106 case IO_STATE_OPEN:
Azure.IoT Build 0:6ae2f7bca550 107 header_detect_io_instance->on_bytes_received(header_detect_io_instance->on_bytes_received_context, buffer, size);
Azure.IoT Build 0:6ae2f7bca550 108 size = 0;
Azure.IoT Build 0:6ae2f7bca550 109 break;
Azure.IoT Build 0:6ae2f7bca550 110 }
Azure.IoT Build 0:6ae2f7bca550 111 }
Azure.IoT Build 0:6ae2f7bca550 112 }
Azure.IoT Build 0:6ae2f7bca550 113
Azure.IoT Build 0:6ae2f7bca550 114 static void on_underlying_io_close_complete(void* context)
Azure.IoT Build 0:6ae2f7bca550 115 {
Azure.IoT Build 0:6ae2f7bca550 116 HEADER_DETECT_IO_INSTANCE* header_detect_io_instance = (HEADER_DETECT_IO_INSTANCE*)context;
Azure.IoT Build 0:6ae2f7bca550 117
Azure.IoT Build 0:6ae2f7bca550 118 switch (header_detect_io_instance->io_state)
Azure.IoT Build 0:6ae2f7bca550 119 {
Azure.IoT Build 0:6ae2f7bca550 120 default:
Azure.IoT Build 0:6ae2f7bca550 121 break;
Azure.IoT Build 0:6ae2f7bca550 122
Azure.IoT Build 0:6ae2f7bca550 123 case IO_STATE_CLOSING:
Azure.IoT Build 0:6ae2f7bca550 124 header_detect_io_instance->io_state = IO_STATE_NOT_OPEN;
Azure.IoT Build 0:6ae2f7bca550 125 indicate_close_complete(header_detect_io_instance);
Azure.IoT Build 0:6ae2f7bca550 126 break;
Azure.IoT Build 0:6ae2f7bca550 127
Azure.IoT Build 0:6ae2f7bca550 128 case IO_STATE_WAIT_FOR_HEADER:
Azure.IoT Build 0:6ae2f7bca550 129 case IO_STATE_OPENING_UNDERLYING_IO:
Azure.IoT Build 0:6ae2f7bca550 130 header_detect_io_instance->io_state = IO_STATE_NOT_OPEN;
Azure.IoT Build 0:6ae2f7bca550 131 indicate_open_complete(header_detect_io_instance, IO_OPEN_ERROR);
Azure.IoT Build 0:6ae2f7bca550 132 break;
Azure.IoT Build 0:6ae2f7bca550 133 }
Azure.IoT Build 0:6ae2f7bca550 134 }
Azure.IoT Build 0:6ae2f7bca550 135
Azure.IoT Build 0:6ae2f7bca550 136 static void on_underlying_io_open_complete(void* context, IO_OPEN_RESULT open_result)
Azure.IoT Build 0:6ae2f7bca550 137 {
Azure.IoT Build 0:6ae2f7bca550 138 HEADER_DETECT_IO_INSTANCE* header_detect_io_instance = (HEADER_DETECT_IO_INSTANCE*)context;
Azure.IoT Build 0:6ae2f7bca550 139
Azure.IoT Build 0:6ae2f7bca550 140 switch (header_detect_io_instance->io_state)
Azure.IoT Build 0:6ae2f7bca550 141 {
Azure.IoT Build 0:6ae2f7bca550 142 default:
Azure.IoT Build 0:6ae2f7bca550 143 break;
Azure.IoT Build 0:6ae2f7bca550 144
Azure.IoT Build 0:6ae2f7bca550 145 case IO_STATE_OPENING_UNDERLYING_IO:
Azure.IoT Build 0:6ae2f7bca550 146 if (open_result == IO_OPEN_OK)
Azure.IoT Build 0:6ae2f7bca550 147 {
Azure.IoT Build 0:6ae2f7bca550 148 header_detect_io_instance->io_state = IO_STATE_WAIT_FOR_HEADER;
Azure.IoT Build 0:6ae2f7bca550 149 }
Azure.IoT Build 0:6ae2f7bca550 150 else
Azure.IoT Build 0:6ae2f7bca550 151 {
Azure.IoT Build 0:6ae2f7bca550 152 if (xio_close(header_detect_io_instance->underlying_io, on_underlying_io_close_complete, header_detect_io_instance) != 0)
Azure.IoT Build 0:6ae2f7bca550 153 {
Azure.IoT Build 0:6ae2f7bca550 154 header_detect_io_instance->io_state = IO_STATE_NOT_OPEN;
Azure.IoT Build 0:6ae2f7bca550 155 indicate_open_complete(header_detect_io_instance, IO_OPEN_ERROR);
Azure.IoT Build 0:6ae2f7bca550 156 }
Azure.IoT Build 0:6ae2f7bca550 157 }
Azure.IoT Build 0:6ae2f7bca550 158
Azure.IoT Build 0:6ae2f7bca550 159 break;
Azure.IoT Build 0:6ae2f7bca550 160 }
Azure.IoT Build 0:6ae2f7bca550 161 }
Azure.IoT Build 0:6ae2f7bca550 162
Azure.IoT Build 0:6ae2f7bca550 163 static void on_underlying_io_error(void* context)
Azure.IoT Build 0:6ae2f7bca550 164 {
Azure.IoT Build 0:6ae2f7bca550 165 HEADER_DETECT_IO_INSTANCE* header_detect_io_instance = (HEADER_DETECT_IO_INSTANCE*)context;
Azure.IoT Build 0:6ae2f7bca550 166
Azure.IoT Build 0:6ae2f7bca550 167 switch (header_detect_io_instance->io_state)
Azure.IoT Build 0:6ae2f7bca550 168 {
Azure.IoT Build 0:6ae2f7bca550 169 default:
Azure.IoT Build 0:6ae2f7bca550 170 break;
Azure.IoT Build 0:6ae2f7bca550 171
Azure.IoT Build 0:6ae2f7bca550 172 case IO_STATE_WAIT_FOR_HEADER:
Azure.IoT Build 0:6ae2f7bca550 173 case IO_STATE_OPENING_UNDERLYING_IO:
Azure.IoT Build 0:6ae2f7bca550 174 header_detect_io_instance->io_state = IO_STATE_NOT_OPEN;
Azure.IoT Build 0:6ae2f7bca550 175 indicate_open_complete(header_detect_io_instance, IO_OPEN_ERROR);
Azure.IoT Build 0:6ae2f7bca550 176 break;
Azure.IoT Build 0:6ae2f7bca550 177
Azure.IoT Build 0:6ae2f7bca550 178 case IO_STATE_OPEN:
Azure.IoT Build 0:6ae2f7bca550 179 header_detect_io_instance->io_state = IO_STATE_ERROR;
Azure.IoT Build 0:6ae2f7bca550 180 indicate_error(header_detect_io_instance);
Azure.IoT Build 0:6ae2f7bca550 181 break;
Azure.IoT Build 0:6ae2f7bca550 182 }
Azure.IoT Build 0:6ae2f7bca550 183 }
Azure.IoT Build 0:6ae2f7bca550 184
Azure.IoT Build 5:ae49385aff34 185 CONCRETE_IO_HANDLE headerdetectio_create(void* io_create_parameters)
Azure.IoT Build 0:6ae2f7bca550 186 {
Azure.IoT Build 0:6ae2f7bca550 187 HEADER_DETECT_IO_INSTANCE* result;
Azure.IoT Build 0:6ae2f7bca550 188
Azure.IoT Build 0:6ae2f7bca550 189 if (io_create_parameters == NULL)
Azure.IoT Build 0:6ae2f7bca550 190 {
Azure.IoT Build 0:6ae2f7bca550 191 result = NULL;
Azure.IoT Build 0:6ae2f7bca550 192 }
Azure.IoT Build 0:6ae2f7bca550 193 else
Azure.IoT Build 0:6ae2f7bca550 194 {
Azure.IoT Build 0:6ae2f7bca550 195 HEADERDETECTIO_CONFIG* header_detect_io_config = (HEADERDETECTIO_CONFIG*)io_create_parameters;
Azure.IoT Build 0:6ae2f7bca550 196 result = (HEADER_DETECT_IO_INSTANCE*)amqpalloc_malloc(sizeof(HEADER_DETECT_IO_INSTANCE));
Azure.IoT Build 0:6ae2f7bca550 197 if (result != NULL)
Azure.IoT Build 0:6ae2f7bca550 198 {
Azure.IoT Build 0:6ae2f7bca550 199 result->underlying_io = header_detect_io_config->underlying_io;
Azure.IoT Build 0:6ae2f7bca550 200 result->on_io_open_complete = NULL;
Azure.IoT Build 0:6ae2f7bca550 201 result->on_io_close_complete = NULL;
Azure.IoT Build 0:6ae2f7bca550 202 result->on_io_error = NULL;
Azure.IoT Build 0:6ae2f7bca550 203 result->on_bytes_received = NULL;
Azure.IoT Build 0:6ae2f7bca550 204 result->on_io_open_complete_context = NULL;
Azure.IoT Build 0:6ae2f7bca550 205 result->on_io_close_complete_context = NULL;
Azure.IoT Build 0:6ae2f7bca550 206 result->on_io_error_context = NULL;
Azure.IoT Build 0:6ae2f7bca550 207 result->on_bytes_received_context = NULL;
Azure.IoT Build 0:6ae2f7bca550 208
Azure.IoT Build 0:6ae2f7bca550 209 result->io_state = IO_STATE_NOT_OPEN;
Azure.IoT Build 0:6ae2f7bca550 210 }
Azure.IoT Build 0:6ae2f7bca550 211 }
Azure.IoT Build 0:6ae2f7bca550 212
Azure.IoT Build 0:6ae2f7bca550 213 return result;
Azure.IoT Build 0:6ae2f7bca550 214 }
Azure.IoT Build 0:6ae2f7bca550 215
Azure.IoT Build 0:6ae2f7bca550 216 void headerdetectio_destroy(CONCRETE_IO_HANDLE header_detect_io)
Azure.IoT Build 0:6ae2f7bca550 217 {
Azure.IoT Build 0:6ae2f7bca550 218 if (header_detect_io != NULL)
Azure.IoT Build 0:6ae2f7bca550 219 {
Azure.IoT Build 0:6ae2f7bca550 220 HEADER_DETECT_IO_INSTANCE* header_detect_io_instance = (HEADER_DETECT_IO_INSTANCE*)header_detect_io;
Azure.IoT Build 0:6ae2f7bca550 221 (void)headerdetectio_close(header_detect_io, NULL, NULL);
Azure.IoT Build 0:6ae2f7bca550 222 xio_destroy(header_detect_io_instance->underlying_io);
Azure.IoT Build 0:6ae2f7bca550 223 amqpalloc_free(header_detect_io);
Azure.IoT Build 0:6ae2f7bca550 224 }
Azure.IoT Build 0:6ae2f7bca550 225 }
Azure.IoT Build 0:6ae2f7bca550 226
Azure.IoT Build 0:6ae2f7bca550 227 int headerdetectio_open(CONCRETE_IO_HANDLE header_detect_io, 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:6ae2f7bca550 228 {
Azure.IoT Build 0:6ae2f7bca550 229 int result;
Azure.IoT Build 0:6ae2f7bca550 230
Azure.IoT Build 0:6ae2f7bca550 231 if (header_detect_io == NULL)
Azure.IoT Build 0:6ae2f7bca550 232 {
Azure.IoT Build 0:6ae2f7bca550 233 result = __LINE__;
Azure.IoT Build 0:6ae2f7bca550 234 }
Azure.IoT Build 0:6ae2f7bca550 235 else
Azure.IoT Build 0:6ae2f7bca550 236 {
Azure.IoT Build 0:6ae2f7bca550 237 HEADER_DETECT_IO_INSTANCE* header_detect_io_instance = (HEADER_DETECT_IO_INSTANCE*)header_detect_io;
Azure.IoT Build 0:6ae2f7bca550 238
Azure.IoT Build 0:6ae2f7bca550 239 if (header_detect_io_instance->io_state != IO_STATE_NOT_OPEN &&
Azure.IoT Build 0:6ae2f7bca550 240 header_detect_io_instance->io_state != IO_STATE_OPEN)
Azure.IoT Build 0:6ae2f7bca550 241 {
Azure.IoT Build 0:6ae2f7bca550 242 result = __LINE__;
Azure.IoT Build 0:6ae2f7bca550 243 }
Azure.IoT Build 0:6ae2f7bca550 244 else
Azure.IoT Build 0:6ae2f7bca550 245 {
Azure.IoT Build 0:6ae2f7bca550 246 header_detect_io_instance->on_bytes_received = on_bytes_received;
Azure.IoT Build 0:6ae2f7bca550 247 header_detect_io_instance->on_io_open_complete = on_io_open_complete;
Azure.IoT Build 0:6ae2f7bca550 248 header_detect_io_instance->on_io_error = on_io_error;
Azure.IoT Build 0:6ae2f7bca550 249 header_detect_io_instance->on_bytes_received_context = on_bytes_received_context;
Azure.IoT Build 0:6ae2f7bca550 250 header_detect_io_instance->on_io_open_complete_context = on_io_open_complete_context;
Azure.IoT Build 0:6ae2f7bca550 251 header_detect_io_instance->on_io_error_context = on_io_error_context;
Azure.IoT Build 0:6ae2f7bca550 252
Azure.IoT Build 0:6ae2f7bca550 253 if (header_detect_io_instance->io_state == IO_STATE_OPEN)
Azure.IoT Build 0:6ae2f7bca550 254 {
Azure.IoT Build 0:6ae2f7bca550 255 indicate_open_complete(header_detect_io_instance, IO_OPEN_OK);
Azure.IoT Build 0:6ae2f7bca550 256 result = 0;
Azure.IoT Build 0:6ae2f7bca550 257 }
Azure.IoT Build 0:6ae2f7bca550 258 else
Azure.IoT Build 0:6ae2f7bca550 259 {
Azure.IoT Build 0:6ae2f7bca550 260 header_detect_io_instance->header_pos = 0;
Azure.IoT Build 0:6ae2f7bca550 261 header_detect_io_instance->io_state = IO_STATE_OPENING_UNDERLYING_IO;
Azure.IoT Build 0:6ae2f7bca550 262
Azure.IoT Build 0:6ae2f7bca550 263 if (xio_open(header_detect_io_instance->underlying_io, on_underlying_io_open_complete, header_detect_io_instance, on_underlying_io_bytes_received, header_detect_io_instance, on_underlying_io_error, header_detect_io_instance) != 0)
Azure.IoT Build 0:6ae2f7bca550 264 {
Azure.IoT Build 0:6ae2f7bca550 265 result = __LINE__;
Azure.IoT Build 0:6ae2f7bca550 266 }
Azure.IoT Build 0:6ae2f7bca550 267 else
Azure.IoT Build 0:6ae2f7bca550 268 {
Azure.IoT Build 0:6ae2f7bca550 269 result = 0;
Azure.IoT Build 0:6ae2f7bca550 270 }
Azure.IoT Build 0:6ae2f7bca550 271 }
Azure.IoT Build 0:6ae2f7bca550 272 }
Azure.IoT Build 0:6ae2f7bca550 273 }
Azure.IoT Build 0:6ae2f7bca550 274
Azure.IoT Build 0:6ae2f7bca550 275 return result;
Azure.IoT Build 0:6ae2f7bca550 276 }
Azure.IoT Build 0:6ae2f7bca550 277
Azure.IoT Build 0:6ae2f7bca550 278 int headerdetectio_close(CONCRETE_IO_HANDLE header_detect_io, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context)
Azure.IoT Build 0:6ae2f7bca550 279 {
Azure.IoT Build 0:6ae2f7bca550 280 int result;
Azure.IoT Build 0:6ae2f7bca550 281
Azure.IoT Build 0:6ae2f7bca550 282 if (header_detect_io == NULL)
Azure.IoT Build 0:6ae2f7bca550 283 {
Azure.IoT Build 0:6ae2f7bca550 284 result = __LINE__;
Azure.IoT Build 0:6ae2f7bca550 285 }
Azure.IoT Build 0:6ae2f7bca550 286 else
Azure.IoT Build 0:6ae2f7bca550 287 {
Azure.IoT Build 0:6ae2f7bca550 288 HEADER_DETECT_IO_INSTANCE* header_detect_io_instance = (HEADER_DETECT_IO_INSTANCE*)header_detect_io;
Azure.IoT Build 0:6ae2f7bca550 289
Azure.IoT Build 0:6ae2f7bca550 290 if ((header_detect_io_instance->io_state == IO_STATE_NOT_OPEN) ||
Azure.IoT Build 0:6ae2f7bca550 291 (header_detect_io_instance->io_state == IO_STATE_CLOSING))
Azure.IoT Build 0:6ae2f7bca550 292 {
Azure.IoT Build 0:6ae2f7bca550 293 result = __LINE__;
Azure.IoT Build 0:6ae2f7bca550 294 }
Azure.IoT Build 0:6ae2f7bca550 295 else
Azure.IoT Build 0:6ae2f7bca550 296 {
Azure.IoT Build 0:6ae2f7bca550 297 header_detect_io_instance->io_state = IO_STATE_CLOSING;
Azure.IoT Build 0:6ae2f7bca550 298 header_detect_io_instance->on_io_close_complete = on_io_close_complete;
Azure.IoT Build 0:6ae2f7bca550 299 header_detect_io_instance->on_io_close_complete_context = callback_context;
Azure.IoT Build 0:6ae2f7bca550 300
Azure.IoT Build 0:6ae2f7bca550 301 if (xio_close(header_detect_io_instance->underlying_io, on_underlying_io_close_complete, header_detect_io_instance) != 0)
Azure.IoT Build 0:6ae2f7bca550 302 {
Azure.IoT Build 0:6ae2f7bca550 303 result = __LINE__;
Azure.IoT Build 0:6ae2f7bca550 304 }
Azure.IoT Build 0:6ae2f7bca550 305 else
Azure.IoT Build 0:6ae2f7bca550 306 {
Azure.IoT Build 0:6ae2f7bca550 307 result = 0;
Azure.IoT Build 0:6ae2f7bca550 308 }
Azure.IoT Build 0:6ae2f7bca550 309 }
Azure.IoT Build 0:6ae2f7bca550 310 }
Azure.IoT Build 0:6ae2f7bca550 311
Azure.IoT Build 0:6ae2f7bca550 312 return result;
Azure.IoT Build 0:6ae2f7bca550 313 }
Azure.IoT Build 0:6ae2f7bca550 314
Azure.IoT Build 0:6ae2f7bca550 315 int headerdetectio_send(CONCRETE_IO_HANDLE header_detect_io, const void* buffer, size_t size, ON_SEND_COMPLETE on_send_complete, void* callback_context)
Azure.IoT Build 0:6ae2f7bca550 316 {
Azure.IoT Build 0:6ae2f7bca550 317 int result;
Azure.IoT Build 0:6ae2f7bca550 318
Azure.IoT Build 0:6ae2f7bca550 319 if (header_detect_io == NULL)
Azure.IoT Build 0:6ae2f7bca550 320 {
Azure.IoT Build 0:6ae2f7bca550 321 result = __LINE__;
Azure.IoT Build 0:6ae2f7bca550 322 }
Azure.IoT Build 0:6ae2f7bca550 323 else
Azure.IoT Build 0:6ae2f7bca550 324 {
Azure.IoT Build 0:6ae2f7bca550 325 HEADER_DETECT_IO_INSTANCE* header_detect_io_instance = (HEADER_DETECT_IO_INSTANCE*)header_detect_io;
Azure.IoT Build 0:6ae2f7bca550 326
Azure.IoT Build 0:6ae2f7bca550 327 if (header_detect_io_instance->io_state != IO_STATE_OPEN)
Azure.IoT Build 0:6ae2f7bca550 328 {
Azure.IoT Build 0:6ae2f7bca550 329 result = __LINE__;
Azure.IoT Build 0:6ae2f7bca550 330 }
Azure.IoT Build 0:6ae2f7bca550 331 else
Azure.IoT Build 0:6ae2f7bca550 332 {
Azure.IoT Build 0:6ae2f7bca550 333 if (xio_send(header_detect_io_instance->underlying_io, buffer, size, on_send_complete, callback_context) != 0)
Azure.IoT Build 0:6ae2f7bca550 334 {
Azure.IoT Build 0:6ae2f7bca550 335 result = __LINE__;
Azure.IoT Build 0:6ae2f7bca550 336 }
Azure.IoT Build 0:6ae2f7bca550 337 else
Azure.IoT Build 0:6ae2f7bca550 338 {
Azure.IoT Build 0:6ae2f7bca550 339 result = 0;
Azure.IoT Build 0:6ae2f7bca550 340 }
Azure.IoT Build 0:6ae2f7bca550 341 }
Azure.IoT Build 0:6ae2f7bca550 342 }
Azure.IoT Build 0:6ae2f7bca550 343
Azure.IoT Build 0:6ae2f7bca550 344 return result;
Azure.IoT Build 0:6ae2f7bca550 345 }
Azure.IoT Build 0:6ae2f7bca550 346
Azure.IoT Build 0:6ae2f7bca550 347 void headerdetectio_dowork(CONCRETE_IO_HANDLE header_detect_io)
Azure.IoT Build 0:6ae2f7bca550 348 {
Azure.IoT Build 0:6ae2f7bca550 349 if (header_detect_io != NULL)
Azure.IoT Build 0:6ae2f7bca550 350 {
Azure.IoT Build 0:6ae2f7bca550 351 HEADER_DETECT_IO_INSTANCE* header_detect_io_instance = (HEADER_DETECT_IO_INSTANCE*)header_detect_io;
Azure.IoT Build 0:6ae2f7bca550 352
Azure.IoT Build 0:6ae2f7bca550 353 if ((header_detect_io_instance->io_state != IO_STATE_NOT_OPEN) &&
Azure.IoT Build 0:6ae2f7bca550 354 (header_detect_io_instance->io_state != IO_STATE_ERROR))
Azure.IoT Build 0:6ae2f7bca550 355 {
Azure.IoT Build 0:6ae2f7bca550 356 xio_dowork(header_detect_io_instance->underlying_io);
Azure.IoT Build 0:6ae2f7bca550 357 }
Azure.IoT Build 0:6ae2f7bca550 358 }
Azure.IoT Build 0:6ae2f7bca550 359 }
Azure.IoT Build 0:6ae2f7bca550 360
AzureIoTClient 1:eab586236bfe 361 int headerdetectio_setoption(CONCRETE_IO_HANDLE header_detect_io, const char* optionName, const void* value)
Azure.IoT Build 0:6ae2f7bca550 362 {
AzureIoTClient 1:eab586236bfe 363 int result;
AzureIoTClient 1:eab586236bfe 364
AzureIoTClient 1:eab586236bfe 365 if (header_detect_io == NULL)
AzureIoTClient 1:eab586236bfe 366 {
AzureIoTClient 1:eab586236bfe 367 result = __LINE__;
AzureIoTClient 1:eab586236bfe 368 }
AzureIoTClient 1:eab586236bfe 369 else
AzureIoTClient 1:eab586236bfe 370 {
AzureIoTClient 1:eab586236bfe 371 HEADER_DETECT_IO_INSTANCE* header_detect_io_instance = (HEADER_DETECT_IO_INSTANCE*)header_detect_io;
AzureIoTClient 1:eab586236bfe 372
AzureIoTClient 1:eab586236bfe 373 if (header_detect_io_instance->underlying_io == NULL)
AzureIoTClient 1:eab586236bfe 374 {
AzureIoTClient 1:eab586236bfe 375 result = __LINE__;
AzureIoTClient 1:eab586236bfe 376 }
AzureIoTClient 1:eab586236bfe 377 else
AzureIoTClient 1:eab586236bfe 378 {
AzureIoTClient 1:eab586236bfe 379 result = xio_setoption(header_detect_io_instance->underlying_io, optionName, value);
AzureIoTClient 1:eab586236bfe 380 }
AzureIoTClient 1:eab586236bfe 381 }
AzureIoTClient 1:eab586236bfe 382
AzureIoTClient 1:eab586236bfe 383 return result;
Azure.IoT Build 0:6ae2f7bca550 384 }
Azure.IoT Build 0:6ae2f7bca550 385
Azure.IoT Build 0:6ae2f7bca550 386 static const IO_INTERFACE_DESCRIPTION header_detect_io_interface_description =
Azure.IoT Build 0:6ae2f7bca550 387 {
Azure.IoT Build 0:6ae2f7bca550 388 headerdetectio_create,
Azure.IoT Build 0:6ae2f7bca550 389 headerdetectio_destroy,
Azure.IoT Build 0:6ae2f7bca550 390 headerdetectio_open,
Azure.IoT Build 0:6ae2f7bca550 391 headerdetectio_close,
Azure.IoT Build 0:6ae2f7bca550 392 headerdetectio_send,
Azure.IoT Build 0:6ae2f7bca550 393 headerdetectio_dowork,
Azure.IoT Build 0:6ae2f7bca550 394 headerdetectio_setoption
Azure.IoT Build 0:6ae2f7bca550 395 };
Azure.IoT Build 0:6ae2f7bca550 396
Azure.IoT Build 0:6ae2f7bca550 397 const IO_INTERFACE_DESCRIPTION* headerdetectio_get_interface_description(void)
Azure.IoT Build 0:6ae2f7bca550 398 {
Azure.IoT Build 0:6ae2f7bca550 399 return &header_detect_io_interface_description;
Azure.IoT Build 0:6ae2f7bca550 400 }