]> code.delx.au - pulseaudio/blob - src/pulse/mainloop-api.h
doc: Use \since doxygen command correctly in mainloop-api.h
[pulseaudio] / src / pulse / mainloop-api.h
1 #ifndef foomainloopapihfoo
2 #define foomainloopapihfoo
3
4 /***
5 This file is part of PulseAudio.
6
7 Copyright 2004-2006 Lennart Poettering
8 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9
10 PulseAudio is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as
12 published by the Free Software Foundation; either version 2.1 of the
13 License, or (at your option) any later version.
14
15 PulseAudio is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with PulseAudio; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 USA.
24 ***/
25
26 #include <sys/time.h>
27
28 #include <pulse/cdecl.h>
29 #include <pulse/version.h>
30
31 /** \file
32 *
33 * Main loop abstraction layer. Both the PulseAudio core and the
34 * PulseAudio client library use a main loop abstraction layer. Due to
35 * this it is possible to embed PulseAudio into other
36 * applications easily. Two main loop implementations are
37 * currently available:
38 * \li A minimal implementation based on the C library's poll() function (See \ref mainloop.h)
39 * \li A wrapper around the GLIB main loop. Use this to embed PulseAudio into your GLIB/GTK+/GNOME programs (See \ref glib-mainloop.h)
40 *
41 * The structure pa_mainloop_api is used as vtable for the main loop abstraction.
42 *
43 * This mainloop abstraction layer has no direct support for UNIX signals. Generic, mainloop implementation agnostic support is available through \ref mainloop-signal.h.
44 * */
45
46 PA_C_DECL_BEGIN
47
48 /** An abstract mainloop API vtable */
49 typedef struct pa_mainloop_api pa_mainloop_api;
50
51 /** A bitmask for IO events */
52 typedef enum pa_io_event_flags {
53 PA_IO_EVENT_NULL = 0, /**< No event */
54 PA_IO_EVENT_INPUT = 1, /**< Input event */
55 PA_IO_EVENT_OUTPUT = 2, /**< Output event */
56 PA_IO_EVENT_HANGUP = 4, /**< Hangup event */
57 PA_IO_EVENT_ERROR = 8 /**< Error event */
58 } pa_io_event_flags_t;
59
60 /** An opaque IO event source object */
61 typedef struct pa_io_event pa_io_event;
62 /** An IO event callback prototype \since 0.9.3 */
63 typedef void (*pa_io_event_cb_t)(pa_mainloop_api*ea, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata);
64 /** A IO event destroy callback prototype \since 0.9.3 */
65 typedef void (*pa_io_event_destroy_cb_t)(pa_mainloop_api*a, pa_io_event *e, void *userdata);
66
67 /** An opaque timer event source object */
68 typedef struct pa_time_event pa_time_event;
69 /** A time event callback prototype \since 0.9.3 */
70 typedef void (*pa_time_event_cb_t)(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata);
71 /** A time event destroy callback prototype \since 0.9.3 */
72 typedef void (*pa_time_event_destroy_cb_t)(pa_mainloop_api*a, pa_time_event *e, void *userdata);
73
74 /** An opaque deferred event source object. Events of this type are triggered once in every main loop iteration */
75 typedef struct pa_defer_event pa_defer_event;
76 /** A defer event callback prototype \since 0.9.3 */
77 typedef void (*pa_defer_event_cb_t)(pa_mainloop_api*a, pa_defer_event* e, void *userdata);
78 /** A defer event destroy callback prototype \since 0.9.3 */
79 typedef void (*pa_defer_event_destroy_cb_t)(pa_mainloop_api*a, pa_defer_event *e, void *userdata);
80
81 /** An abstract mainloop API vtable */
82 struct pa_mainloop_api {
83 /** A pointer to some private, arbitrary data of the main loop implementation */
84 void *userdata;
85
86 /** Create a new IO event source object */
87 pa_io_event* (*io_new)(pa_mainloop_api*a, int fd, pa_io_event_flags_t events, pa_io_event_cb_t cb, void *userdata);
88 /** Enable or disable IO events on this object */
89 void (*io_enable)(pa_io_event* e, pa_io_event_flags_t events);
90 /** Free a IO event source object */
91 void (*io_free)(pa_io_event* e);
92 /** Set a function that is called when the IO event source is destroyed. Use this to free the userdata argument if required */
93 void (*io_set_destroy)(pa_io_event *e, pa_io_event_destroy_cb_t cb);
94
95 /** Create a new timer event source object for the specified Unix time */
96 pa_time_event* (*time_new)(pa_mainloop_api*a, const struct timeval *tv, pa_time_event_cb_t cb, void *userdata);
97 /** Restart a running or expired timer event source with a new Unix time */
98 void (*time_restart)(pa_time_event* e, const struct timeval *tv);
99 /** Free a deferred timer event source object */
100 void (*time_free)(pa_time_event* e);
101 /** Set a function that is called when the timer event source is destroyed. Use this to free the userdata argument if required */
102 void (*time_set_destroy)(pa_time_event *e, pa_time_event_destroy_cb_t cb);
103
104 /** Create a new deferred event source object */
105 pa_defer_event* (*defer_new)(pa_mainloop_api*a, pa_defer_event_cb_t cb, void *userdata);
106 /** Enable or disable a deferred event source temporarily */
107 void (*defer_enable)(pa_defer_event* e, int b);
108 /** Free a deferred event source object */
109 void (*defer_free)(pa_defer_event* e);
110 /** Set a function that is called when the deferred event source is destroyed. Use this to free the userdata argument if required */
111 void (*defer_set_destroy)(pa_defer_event *e, pa_defer_event_destroy_cb_t cb);
112
113 /** Exit the main loop and return the specified retval*/
114 void (*quit)(pa_mainloop_api*a, int retval);
115 };
116
117 /** Run the specified callback function once from the main loop using an anonymous defer event. Note that this performs
118 * multiple mainloop operations non-atomically. If, for example, you are using a \ref pa_threaded_mainloop, you will need to
119 * take the mainloop lock before this call. */
120 void pa_mainloop_api_once(pa_mainloop_api*m, void (*callback)(pa_mainloop_api*m, void *userdata), void *userdata);
121
122 PA_C_DECL_END
123
124 #endif