1 /*****
2 *
3 * Copyright (C) 2001-2015 CS-SI. All Rights Reserved.
4 * Author: Yoann Vandoorselaere <yoann.v@prelude-ids.com>
5 *
6 * This file is part of the Prelude library.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 *****/
23
24 #ifndef _LIBPRELUDE_PRELUDE_ASYNC_H
25 #define _LIBPRELUDE_PRELUDE_ASYNC_H
26
27
28 #include "prelude-linked-object.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34
35 /**
36 * prelude_async_flags_t
37 * @PRELUDE_ASYNC_FLAGS_TIMER: Enable asynchronous timer.
38 *
39 * This provides asynchronous timer. When enabled, the heartbeat
40 * function (and user specified callback, if any) will be called
41 * automatically, from an asynchronous thread.
42 *
43 * If you use this flags, you won't need to call prelude_wake_up_timer()
44 * anymore.
45 */
46 typedef enum {
47 PRELUDE_ASYNC_FLAGS_TIMER = 0x01
48 } prelude_async_flags_t;
49
50 typedef void (*prelude_async_callback_t)(void *object, void *data);
51
52
53
54 #define PRELUDE_ASYNC_OBJECT \
55 PRELUDE_LINKED_OBJECT; \
56 void *_async_data; \
57 prelude_async_callback_t _async_func
58
59
60 typedef struct {
61 PRELUDE_ASYNC_OBJECT;
62 } prelude_async_object_t;
63
64
65
prelude_async_set_data(prelude_async_object_t * obj,void * data)66 static inline void prelude_async_set_data(prelude_async_object_t *obj, void *data)
67 {
68 obj->_async_data = data;
69 }
70
71
prelude_async_set_callback(prelude_async_object_t * obj,prelude_async_callback_t func)72 static inline void prelude_async_set_callback(prelude_async_object_t *obj, prelude_async_callback_t func)
73 {
74 obj->_async_func = func;
75 }
76
77 int prelude_async_init(void);
78
79 prelude_async_flags_t prelude_async_get_flags(void);
80
81 void prelude_async_set_flags(prelude_async_flags_t flags);
82
83 void prelude_async_add(prelude_async_object_t *obj);
84
85 void prelude_async_del(prelude_async_object_t *obj);
86
87 void prelude_async_exit(void);
88
89
90 void _prelude_async_fork_prepare(void);
91 void _prelude_async_fork_parent(void);
92 void _prelude_async_fork_child(void);
93
94
95 #ifdef __cplusplus
96 }
97 #endif
98
99 #endif /* _LIBPRELUDE_PRELUDE_ASYNC_H */
100
101