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