Path: blob/master/thirdparty/linuxbsd_headers/pulse/mainloop.h
9905 views
#ifndef foomainloophfoo1#define foomainloophfoo23/***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 as published11by the Free Software Foundation; either version 2.1 of the License,12or (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 GNU17General Public License for more details.1819You should have received a copy of the GNU Lesser General Public License20along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.21***/2223#include <pulse/mainloop-api.h>24#include <pulse/cdecl.h>2526PA_C_DECL_BEGIN2728struct pollfd;2930/** \page mainloop Main Loop31*32* \section overv_sec Overview33*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 very36* little else.37*38* The main loop is created using pa_mainloop_new() and destroyed using39* pa_mainloop_free(). To get access to the main loop abstraction,40* pa_mainloop_get_api() is used.41*42* \section iter_sec Iteration43*44* The main loop is designed around the concept of iterations. Each iteration45* consists of three steps that repeat during the application's entire46* lifetime:47*48* -# Prepare - Build a list of file descriptors49* that need to be monitored and calculate the next timeout.50* -# Poll - Execute the actual poll() system call.51* -# Dispatch - Dispatch any events that have fired.52*53* When using the main loop, the application can either execute each54* iteration, one at a time, using pa_mainloop_iterate(), or let the library55* iterate automatically using pa_mainloop_run().56*57* \section thread_sec Threads58*59* The main loop functions are designed to be thread safe, but the objects60* are not. What this means is that multiple main loops can be used, but only61* one object per thread.62*63*/6465/** \file66*67* A minimal main loop implementation based on the C library's poll()68* function. Using the routines defined herein you may create a simple69* main loop supporting the generic main loop abstraction layer as70* defined in \ref mainloop-api.h. This implementation is thread safe71* as long as you access the main loop object from a single thread only.72*73* See also \subpage mainloop74*/7576/** An opaque main loop object */77typedef struct pa_mainloop pa_mainloop;7879/** Allocate a new main loop object */80pa_mainloop *pa_mainloop_new(void);8182/** Free a main loop object */83void pa_mainloop_free(pa_mainloop* m);8485/** Prepare for a single iteration of the main loop. Returns a negative value86on error or exit request. timeout specifies a maximum timeout for the subsequent87poll, or -1 for blocking behaviour. .*/88int pa_mainloop_prepare(pa_mainloop *m, int timeout);8990/** Execute the previously prepared poll. Returns a negative value on error.*/91int pa_mainloop_poll(pa_mainloop *m);9293/** Dispatch timeout, io and deferred events from the previously executed poll. Returns94a negative value on error. On success returns the number of source dispatched. */95int pa_mainloop_dispatch(pa_mainloop *m);9697/** Return the return value as specified with the main loop's quit() routine. */98int pa_mainloop_get_retval(pa_mainloop *m);99100/** Run a single iteration of the main loop. This is a convenience function101for pa_mainloop_prepare(), pa_mainloop_poll() and pa_mainloop_dispatch().102Returns a negative value on error or exit request. If block is nonzero,103block for events if none are queued. Optionally return the return value as104specified with the main loop's quit() routine in the integer variable retval points105to. On success returns the number of sources dispatched in this iteration. */106int pa_mainloop_iterate(pa_mainloop *m, int block, int *retval);107108/** Run unlimited iterations of the main loop object until the main loop's quit() routine is called. */109int pa_mainloop_run(pa_mainloop *m, int *retval);110111/** Return the abstract main loop abstraction layer vtable for this112main loop. No need to free the API as it is owned by the loop113and is destroyed when the loop is freed. */114pa_mainloop_api* pa_mainloop_get_api(pa_mainloop*m);115116/** Shutdown the main loop with the specified return value */117void pa_mainloop_quit(pa_mainloop *m, int retval);118119/** Interrupt a running poll (for threaded systems) */120void pa_mainloop_wakeup(pa_mainloop *m);121122/** Generic prototype of a poll() like function */123typedef int (*pa_poll_func)(struct pollfd *ufds, unsigned long nfds, int timeout, void*userdata);124125/** Change the poll() implementation */126void pa_mainloop_set_poll_func(pa_mainloop *m, pa_poll_func poll_func, void *userdata);127128PA_C_DECL_END129130#endif131132133