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