| 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 ASYNC_OPERATION_H |
| 5 |
#define ASYNC_OPERATION_H |
| 6 |
|
| 7 |
#ifdef __cplusplus |
| 8 |
extern "C" { |
| 9 |
#include <cstdint> |
| 10 |
#include <cstddef> |
| 11 |
#else |
| 12 |
#include <stdint.h> |
| 13 |
#include <stddef.h> |
| 14 |
#endif /* __cplusplus */ |
| 15 |
|
| 16 |
#include "umock_c/umock_c_prod.h" |
| 17 |
|
| 18 |
typedef struct ASYNC_OPERATION_INSTANCE_TAG* ASYNC_OPERATION_HANDLE; |
| 19 |
|
| 20 |
typedef void(*ASYNC_OPERATION_CANCEL_HANDLER_FUNC)(ASYNC_OPERATION_HANDLE async_operation); |
| 21 |
|
| 22 |
#define DEFINE_ASYNC_OPERATION_CONTEXT(type) \ |
| 23 |
typedef struct MU_C3(ASYNC_OPERATION_CONTEXT_STRUCT_, type, _TAG) \ |
| 24 |
{ \ |
| 25 |
ASYNC_OPERATION_CANCEL_HANDLER_FUNC async_operation_cancel_handler; \ |
| 26 |
type context; \ |
| 27 |
} MU_C2(ASYNC_OPERATION_CONTEXT_STRUCT_, type); |
| 28 |
|
| 29 |
#define GET_ASYNC_OPERATION_CONTEXT(type, async_operation) \ |
| 30 |
(type*)((unsigned char*)async_operation + offsetof(MU_C2(ASYNC_OPERATION_CONTEXT_STRUCT_, type), context)) |
| 31 |
|
| 32 |
#define CREATE_ASYNC_OPERATION(type, async_operation_cancel_handler) \ |
| 33 |
async_operation_create(async_operation_cancel_handler, sizeof(MU_C2(ASYNC_OPERATION_CONTEXT_STRUCT_, type))) |
| 34 |
|
| 35 |
MOCKABLE_FUNCTION(, ASYNC_OPERATION_HANDLE, async_operation_create, ASYNC_OPERATION_CANCEL_HANDLER_FUNC, async_operation_cancel_handler, size_t, context_size); |
| 36 |
MOCKABLE_FUNCTION(, void, async_operation_destroy, ASYNC_OPERATION_HANDLE, async_operation); |
| 37 |
MOCKABLE_FUNCTION(, int, async_operation_cancel, ASYNC_OPERATION_HANDLE, async_operation); |
| 38 |
|
| 39 |
#ifdef __cplusplus |
| 40 |
} |
| 41 |
#endif /* __cplusplus */ |
| 42 |
|
| 43 |
#endif /* ASYNC_OPERATION_H */ |