| 1 |
// Copyright (c) Microsoft. All rights reserved. |
| 2 |
// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 |
|
| 4 |
#ifndef XIO_H |
| 5 |
#define XIO_H |
| 6 |
|
| 7 |
#ifdef __cplusplus |
| 8 |
#include <cstddef> |
| 9 |
#else |
| 10 |
#include <stddef.h> |
| 11 |
#endif /* __cplusplus */ |
| 12 |
|
| 13 |
#include "azure_c_shared_utility/optionhandler.h" |
| 14 |
|
| 15 |
#include "umock_c/umock_c_prod.h" |
| 16 |
#include "azure_macro_utils/macro_utils.h" |
| 17 |
|
| 18 |
#ifdef __cplusplus |
| 19 |
extern "C" { |
| 20 |
#endif /* __cplusplus */ |
| 21 |
|
| 22 |
typedef struct XIO_INSTANCE_TAG* XIO_HANDLE; |
| 23 |
typedef void* CONCRETE_IO_HANDLE; |
| 24 |
|
| 25 |
#define IO_SEND_RESULT_VALUES \ |
| 26 |
IO_SEND_OK, \ |
| 27 |
IO_SEND_ERROR, \ |
| 28 |
IO_SEND_CANCELLED |
| 29 |
|
| 30 |
MU_DEFINE_ENUM(IO_SEND_RESULT, IO_SEND_RESULT_VALUES); |
| 31 |
|
| 32 |
#define IO_OPEN_RESULT_VALUES \ |
| 33 |
IO_OPEN_OK, \ |
| 34 |
IO_OPEN_ERROR, \ |
| 35 |
IO_OPEN_CANCELLED |
| 36 |
|
| 37 |
MU_DEFINE_ENUM(IO_OPEN_RESULT, IO_OPEN_RESULT_VALUES); |
| 38 |
|
| 39 |
typedef void(*ON_BYTES_RECEIVED)(void* context, const unsigned char* buffer, size_t size); |
| 40 |
typedef void(*ON_SEND_COMPLETE)(void* context, IO_SEND_RESULT send_result); |
| 41 |
typedef void(*ON_IO_OPEN_COMPLETE)(void* context, IO_OPEN_RESULT open_result); |
| 42 |
typedef void(*ON_IO_CLOSE_COMPLETE)(void* context); |
| 43 |
typedef void(*ON_IO_ERROR)(void* context); |
| 44 |
|
| 45 |
typedef OPTIONHANDLER_HANDLE (*IO_RETRIEVEOPTIONS)(CONCRETE_IO_HANDLE concrete_io); |
| 46 |
typedef CONCRETE_IO_HANDLE(*IO_CREATE)(void* io_create_parameters); |
| 47 |
typedef void(*IO_DESTROY)(CONCRETE_IO_HANDLE concrete_io); |
| 48 |
typedef int(*IO_OPEN)(CONCRETE_IO_HANDLE concrete_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); |
| 49 |
typedef int(*IO_CLOSE)(CONCRETE_IO_HANDLE concrete_io, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context); |
| 50 |
typedef int(*IO_SEND)(CONCRETE_IO_HANDLE concrete_io, const void* buffer, size_t size, ON_SEND_COMPLETE on_send_complete, void* callback_context); |
| 51 |
typedef void(*IO_DOWORK)(CONCRETE_IO_HANDLE concrete_io); |
| 52 |
typedef int(*IO_SETOPTION)(CONCRETE_IO_HANDLE concrete_io, const char* optionName, const void* value); |
| 53 |
|
| 54 |
|
| 55 |
typedef struct IO_INTERFACE_DESCRIPTION_TAG |
| 56 |
{ |
| 57 |
IO_RETRIEVEOPTIONS concrete_io_retrieveoptions; |
| 58 |
IO_CREATE concrete_io_create; |
| 59 |
IO_DESTROY concrete_io_destroy; |
| 60 |
IO_OPEN concrete_io_open; |
| 61 |
IO_CLOSE concrete_io_close; |
| 62 |
IO_SEND concrete_io_send; |
| 63 |
IO_DOWORK concrete_io_dowork; |
| 64 |
IO_SETOPTION concrete_io_setoption; |
| 65 |
} IO_INTERFACE_DESCRIPTION; |
| 66 |
|
| 67 |
MOCKABLE_FUNCTION(, XIO_HANDLE, xio_create, const IO_INTERFACE_DESCRIPTION*, io_interface_description, const void*, io_create_parameters); |
| 68 |
MOCKABLE_FUNCTION(, void, xio_destroy, XIO_HANDLE, xio); |
| 69 |
MOCKABLE_FUNCTION(, 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); |
| 70 |
MOCKABLE_FUNCTION(, int, xio_close, XIO_HANDLE, xio, ON_IO_CLOSE_COMPLETE, on_io_close_complete, void*, callback_context); |
| 71 |
MOCKABLE_FUNCTION(, int, xio_send, XIO_HANDLE, xio, const void*, buffer, size_t, size, ON_SEND_COMPLETE, on_send_complete, void*, callback_context); |
| 72 |
MOCKABLE_FUNCTION(, void, xio_dowork, XIO_HANDLE, xio); |
| 73 |
MOCKABLE_FUNCTION(, int, xio_setoption, XIO_HANDLE, xio, const char*, optionName, const void*, value); |
| 74 |
MOCKABLE_FUNCTION(, OPTIONHANDLER_HANDLE, xio_retrieveoptions, XIO_HANDLE, xio); |
| 75 |
|
| 76 |
#ifdef __cplusplus |
| 77 |
} |
| 78 |
#endif /* __cplusplus */ |
| 79 |
|
| 80 |
#endif /* XIO_H */ |