summaryrefslogtreecommitdiffstats
path: root/common/elapi/elapi_async.h
blob: 21331766b3e168ac7569d2e0800a567fab8219ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
    ELAPI

    Header file for the ELAPI async processing interface.

    Copyright (C) Dmitri Pal <dpal@redhat.com> 2009

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ELAPI_ASYNC_H
#define ELAPI_ASYNC_H

#include <sys/time.h>

#define ELAPI_FD_READ       0x00000001 /* request to read */
#define ELAPI_FD_WRITE      0x00000002 /* request to write */

/* Structure that holds ELAPI file descriptor's watch data */
struct elapi_fd_data;

/* Structure that holds ELAPI timer data */
struct elapi_tm_data;

/* Functions to set and get data from file descriptor data. */
/* Functions return EINVAL if passed in argument is invalid. */
int elapi_set_fd_priv(struct elapi_fd_data *fd_data,
                      void *priv_data_to_set);
int elapi_get_fd_priv(struct elapi_fd_data *fd_data,
                      void **priv_data_to_get);
/* Cleanup function */
void elapi_destroy_fd_data(struct elapi_fd_data *fd_data);

/* Functions to set and get custom data from timer data. */
/* Functions return EINVAL if passed in argument is invalid. */
int elapi_set_tm_priv(struct elapi_tm_data *tm_data,
                      void *priv_data_to_set);
int elapi_get_tm_priv(struct elapi_tm_data *tm_data,
                      void **priv_data_to_get);
/* Cleanup function */
void elapi_destroy_tm_data(struct elapi_tm_data *tm_data);

/* Public interfaces ELAPI exposes to handle fd or timer
 * events (do not confuse with log events).
 */
int elapi_process_fd(struct elapi_fd_data *fd_data);
int elapi_process_tm(struct elapi_tm_data *tm_data);

/* Signature of the function to add
 * file descriptor into the event loop.
 * Provided by caller of the ELAPI interface.
 */
typedef int (*elapi_add_fd)(int fd,
                            unsigned flags,
                            struct elapi_fd_data *fd_data,
                            void *ext_fd_data);

/* Signature of the function to remove
 * file descriptor from the event loop.
 * Provided by caller of the ELAPI interface.
 */
typedef int (*elapi_rem_fd)(int fd,
                            struct elapi_fd_data *fd_data,
                            void *ext_fd_data);

/* Signature of the function to set
 * file descriptor for read/write operation.
 * Provided by caller of the ELAPI interface.
 */
typedef int (*elapi_set_fd)(int fd,
                            unsigned flags,
                            struct elapi_fd_data *fd_data,
                            void *ext_fd_data);


/* Signature of the function to add timer.
 * Provided by caller of the ELAPI interface.
 */
typedef int (*elapi_add_tm)(struct timeval tv,
                            struct elapi_tm_data *tm_data,
                            void *ext_tm_data);

/* Signature of the function to add timer.
 * Provided by caller of the ELAPI interface.
 * Caller must be aware that the timeval strcuture
 * is allocated on stack.
 */
typedef int (*elapi_rem_tm)(struct elapi_tm_data *tm_data,
                            void *ext_tm_data);




#endif