Path: blob/master/thirdparty/linuxbsd_headers/pulse/mainloop-api.h
9905 views
#ifndef foomainloopapihfoo1#define foomainloopapihfoo23/***4This file is part of PulseAudio.56Copyright 2004-2006 Lennart Poettering7Copyright 2006 Pierre Ossman <[email protected]> for Cendio AB89PulseAudio is free software; you can redistribute it and/or modify10it under the terms of the GNU Lesser General Public License as11published by the Free Software Foundation; either version 2.1 of the12License, or (at your option) any later version.1314PulseAudio is distributed in the hope that it will be useful, but15WITHOUT ANY WARRANTY; without even the implied warranty of16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU17Lesser General Public License for more details.1819You should have received a copy of the GNU Lesser General Public20License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.21***/2223#include <sys/time.h>2425#include <pulse/cdecl.h>26#include <pulse/version.h>2728/** \file29*30* Main loop abstraction layer. Both the PulseAudio core and the31* PulseAudio client library use a main loop abstraction layer. Due to32* this it is possible to embed PulseAudio into other33* applications easily. Two main loop implementations are34* currently available:35* \li A minimal implementation based on the C library's poll() function (See \ref mainloop.h)36* \li A wrapper around the GLIB main loop. Use this to embed PulseAudio into your GLIB/GTK+/GNOME programs (See \ref glib-mainloop.h)37*38* The structure pa_mainloop_api is used as vtable for the main loop abstraction.39*40* This mainloop abstraction layer has no direct support for UNIX signals. Generic, mainloop implementation agnostic support is available through \ref mainloop-signal.h.41* */4243PA_C_DECL_BEGIN4445/** An abstract mainloop API vtable */46typedef struct pa_mainloop_api pa_mainloop_api;4748/** A bitmask for IO events */49typedef enum pa_io_event_flags {50PA_IO_EVENT_NULL = 0, /**< No event */51PA_IO_EVENT_INPUT = 1, /**< Input event */52PA_IO_EVENT_OUTPUT = 2, /**< Output event */53PA_IO_EVENT_HANGUP = 4, /**< Hangup event */54PA_IO_EVENT_ERROR = 8 /**< Error event */55} pa_io_event_flags_t;5657/** An opaque IO event source object */58typedef struct pa_io_event pa_io_event;59/** An IO event callback prototype \since 0.9.3 */60typedef void (*pa_io_event_cb_t)(pa_mainloop_api*ea, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata);61/** A IO event destroy callback prototype \since 0.9.3 */62typedef void (*pa_io_event_destroy_cb_t)(pa_mainloop_api*a, pa_io_event *e, void *userdata);6364/** An opaque timer event source object */65typedef struct pa_time_event pa_time_event;66/** A time event callback prototype \since 0.9.3 */67typedef void (*pa_time_event_cb_t)(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata);68/** A time event destroy callback prototype \since 0.9.3 */69typedef void (*pa_time_event_destroy_cb_t)(pa_mainloop_api*a, pa_time_event *e, void *userdata);7071/** An opaque deferred event source object. Events of this type are triggered once in every main loop iteration */72typedef struct pa_defer_event pa_defer_event;73/** A defer event callback prototype \since 0.9.3 */74typedef void (*pa_defer_event_cb_t)(pa_mainloop_api*a, pa_defer_event* e, void *userdata);75/** A defer event destroy callback prototype \since 0.9.3 */76typedef void (*pa_defer_event_destroy_cb_t)(pa_mainloop_api*a, pa_defer_event *e, void *userdata);7778/** An abstract mainloop API vtable */79struct pa_mainloop_api {80/** A pointer to some private, arbitrary data of the main loop implementation */81void *userdata;8283/** Create a new IO event source object */84pa_io_event* (*io_new)(pa_mainloop_api*a, int fd, pa_io_event_flags_t events, pa_io_event_cb_t cb, void *userdata);85/** Enable or disable IO events on this object */86void (*io_enable)(pa_io_event* e, pa_io_event_flags_t events);87/** Free a IO event source object */88void (*io_free)(pa_io_event* e);89/** Set a function that is called when the IO event source is destroyed. Use this to free the userdata argument if required */90void (*io_set_destroy)(pa_io_event *e, pa_io_event_destroy_cb_t cb);9192/** Create a new timer event source object for the specified Unix time */93pa_time_event* (*time_new)(pa_mainloop_api*a, const struct timeval *tv, pa_time_event_cb_t cb, void *userdata);94/** Restart a running or expired timer event source with a new Unix time */95void (*time_restart)(pa_time_event* e, const struct timeval *tv);96/** Free a deferred timer event source object */97void (*time_free)(pa_time_event* e);98/** Set a function that is called when the timer event source is destroyed. Use this to free the userdata argument if required */99void (*time_set_destroy)(pa_time_event *e, pa_time_event_destroy_cb_t cb);100101/** Create a new deferred event source object */102pa_defer_event* (*defer_new)(pa_mainloop_api*a, pa_defer_event_cb_t cb, void *userdata);103/** Enable or disable a deferred event source temporarily */104void (*defer_enable)(pa_defer_event* e, int b);105/** Free a deferred event source object */106void (*defer_free)(pa_defer_event* e);107/** Set a function that is called when the deferred event source is destroyed. Use this to free the userdata argument if required */108void (*defer_set_destroy)(pa_defer_event *e, pa_defer_event_destroy_cb_t cb);109110/** Exit the main loop and return the specified retval*/111void (*quit)(pa_mainloop_api*a, int retval);112};113114/** Run the specified callback function once from the main loop using an115* anonymous defer event. If the mainloop runs in a different thread, you need116* to follow the mainloop implementation's rules regarding how to safely create117* defer events. In particular, if you're using \ref pa_threaded_mainloop, you118* must lock the mainloop before calling this function. */119void pa_mainloop_api_once(pa_mainloop_api*m, void (*callback)(pa_mainloop_api*m, void *userdata), void *userdata);120121PA_C_DECL_END122123#endif124125126