]> code.delx.au - pulseaudio/blob - src/polyp/mainloop.h
fe2b4c5b4863c1c233c63dfc11e76ffbb003202b
[pulseaudio] / src / polyp / mainloop.h
1 #ifndef foomainloophfoo
2 #define foomainloophfoo
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 Lesser 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 Lesser 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 <polyp/mainloop-api.h>
26 #include <polyp/cdecl.h>
27
28 PA_C_DECL_BEGIN
29
30 /** \page mainloop Main Loop
31 *
32 * \section overv_sec Overview
33 *
34 * The built-in main loop implementation is based on the poll() system call.
35 * It supports the functions defined in the main loop abstraction and very
36 * little else.
37 *
38 * The main loop is created using pa_mainloop_new() and destroyed using
39 * pa_mainloop_free(). To get access to the main loop abstraction,
40 * pa_mainloop_get_api() is used.
41 *
42 * \section iter_sec Iteration
43 *
44 * The main loop is designed around the concept of iterations. Each iteration
45 * consists of three steps that repeat during the application's entire
46 * lifetime:
47 *
48 * -# Prepare - Build a list of file descriptors
49 * that need to be monitored and calculate the next timeout.
50 * -# Poll - Execute the actuall poll() system call.
51 * -# Dispatch - Dispatch any events that have fired.
52 *
53 * When using the main loop, the application can either execute each
54 * iteration, one at a time, using pa_mainloop_iterate(), or let the library
55 * iterate automatically using pa_mainloop_run().
56 *
57 * \section thread_sec Threads
58 *
59 * The main loop functions are designed to be thread safe, but the objects
60 * are not. What this means is that multiple main loops can be used, but only
61 * one object per thread.
62 *
63 */
64
65 /** \file
66 *
67 * A minimal main loop implementation based on the C library's poll()
68 * function. Using the routines defined herein you may create a simple
69 * main loop supporting the generic main loop abstraction layer as
70 * defined in \ref mainloop-api.h. This implementation is thread safe
71 * as long as you access the main loop object from a single thread only.*/
72
73 /** An opaque main loop object */
74 typedef struct pa_mainloop pa_mainloop;
75
76 /** Allocate a new main loop object */
77 pa_mainloop *pa_mainloop_new(void);
78
79 /** Free a main loop object */
80 void pa_mainloop_free(pa_mainloop* m);
81
82 /** Prepare for a single iteration of the main loop. Returns a negative value
83 on error or exit request. timeout specifies a maximum timeout for the subsequent
84 poll, or -1 for blocking behaviour. .*/
85 int pa_mainloop_prepare(pa_mainloop *m, int timeout);
86
87 /** Execute the previously prepared poll. Returns a negative value on error.*/
88 int pa_mainloop_poll(pa_mainloop *m);
89
90 /** Dispatch timeout, io and deferred events from the previously executed poll. Returns
91 a negative value on error. On success returns the number of source dispatched. */
92 int pa_mainloop_dispatch(pa_mainloop *m);
93
94 /** Return the return value as specified with the main loop's quit() routine. */
95 int pa_mainloop_get_retval(pa_mainloop *m);
96
97 /** Run a single iteration of the main loop. This is a convenience function
98 for pa_mainloop_prepare(), pa_mainloop_poll() and pa_mainloop_dispatch().
99 Returns a negative value on error or exit request. If block is nonzero,
100 block for events if none are queued. Optionally return the return value as
101 specified with the main loop's quit() routine in the integer variable retval points
102 to. On success returns the number of sources dispatched in this iteration. */
103 int pa_mainloop_iterate(pa_mainloop *m, int block, int *retval);
104
105 /** Run unlimited iterations of the main loop object until the main loop's quit() routine is called. */
106 int pa_mainloop_run(pa_mainloop *m, int *retval);
107
108 /** Return the abstract main loop abstraction layer vtable for this main loop. */
109 pa_mainloop_api* pa_mainloop_get_api(pa_mainloop*m);
110
111 /** Shutdown the main loop */
112 void pa_mainloop_quit(pa_mainloop *m, int r);
113
114 /** Interrupt a running poll (for threaded systems) */
115 void pa_mainloop_wakeup(pa_mainloop *m);
116
117 PA_C_DECL_END
118
119 #endif