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