• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef foopulsertpollhfoo
2 #define foopulsertpollhfoo
3 
4 /***
5   This file is part of PulseAudio.
6 
7   Copyright 2004-2006 Lennart Poettering
8 
9   PulseAudio is free software; you can redistribute it and/or modify
10   it under the terms of the GNU Lesser General Public License as
11   published by the Free Software Foundation; either version 2.1 of the
12   License, or (at your option) any later version.
13 
14   PulseAudio 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   Lesser General Public License for more details.
18 
19   You should have received a copy of the GNU Lesser General Public
20   License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
21 ***/
22 
23 #include <sys/types.h>
24 #include <limits.h>
25 
26 #include <pulse/sample.h>
27 #include <pulsecore/asyncmsgq.h>
28 #include <pulsecore/fdsem.h>
29 #include <pulsecore/macro.h>
30 
31 /* An implementation of a "real-time" poll loop. Basically, this is
32  * yet another wrapper around poll(). However it has certain
33  * advantages over pa_mainloop and suchlike:
34  *
35  * 1) High resolution timers are used
36  *
37  * 2) It allows raw access to the pollfd data to users
38  *
39  * 3) It allows arbitrary functions to be run before entering the
40  * actual poll() and after it.
41  *
42  * Only a single interval timer is supported. */
43 
44 typedef struct pa_rtpoll pa_rtpoll;
45 typedef struct pa_rtpoll_item pa_rtpoll_item;
46 
47 typedef enum pa_rtpoll_priority {
48     PA_RTPOLL_EARLY  = -100,          /* For very important stuff, like handling control messages */
49     PA_RTPOLL_NORMAL = 0,             /* For normal stuff */
50     PA_RTPOLL_LATE   = +100,          /* For housekeeping */
51     PA_RTPOLL_NEVER  = INT_MAX,       /* For stuff that doesn't register any callbacks, but only fds to listen on */
52 } pa_rtpoll_priority_t;
53 
54 pa_rtpoll *pa_rtpoll_new(void);
55 void pa_rtpoll_free(pa_rtpoll *p);
56 
57 /* Sleep on the rtpoll until the time event, or any of the fd events
58  * is triggered. Returns negative on error, positive if the loop
59  * should continue to run, 0 when the loop should be terminated
60  * cleanly. */
61 int pa_rtpoll_run(pa_rtpoll *f);
62 
63 void pa_rtpoll_set_timer_absolute(pa_rtpoll *p, pa_usec_t usec);
64 void pa_rtpoll_set_timer_relative(pa_rtpoll *p, pa_usec_t usec);
65 void pa_rtpoll_set_timer_disabled(pa_rtpoll *p);
66 
67 /* Return true when the elapsed timer was the reason for
68  * the last pa_rtpoll_run() invocation to finish */
69 bool pa_rtpoll_timer_elapsed(pa_rtpoll *p);
70 
71 /* A new fd wakeup item for pa_rtpoll */
72 pa_rtpoll_item *pa_rtpoll_item_new(pa_rtpoll *p, pa_rtpoll_priority_t prio, unsigned n_fds);
73 void pa_rtpoll_item_free(pa_rtpoll_item *i);
74 
75 /* Please note that this pointer might change on every call and when
76  * pa_rtpoll_run() is called. Hence: call this immediately before
77  * using the pointer and don't save the result anywhere */
78 struct pollfd *pa_rtpoll_item_get_pollfd(pa_rtpoll_item *i, unsigned *n_fds);
79 
80 /* Set the callback that shall be called when there's time to do some work: If the
81  * callback returns a value > 0, the poll is skipped and the next
82  * iteration of the loop will start immediately. */
83 void pa_rtpoll_item_set_work_callback(pa_rtpoll_item *i, int (*work_cb)(pa_rtpoll_item *i), void *userdata);
84 
85 /* Set the callback that shall be called immediately before entering
86  * the sleeping poll: If the callback returns a value > 0, the poll is
87  * skipped and the next iteration of the loop will start immediately. */
88 void pa_rtpoll_item_set_before_callback(pa_rtpoll_item *i, int (*before_cb)(pa_rtpoll_item *i), void *userdata);
89 
90 /* Set the callback that shall be called immediately after having
91  * entered the sleeping poll */
92 void pa_rtpoll_item_set_after_callback(pa_rtpoll_item *i, void (*after_cb)(pa_rtpoll_item *i), void *userdata);
93 
94 void* pa_rtpoll_item_get_work_userdata(pa_rtpoll_item *i);
95 
96 pa_rtpoll_item *pa_rtpoll_item_new_fdsem(pa_rtpoll *p, pa_rtpoll_priority_t prio, pa_fdsem *s);
97 pa_rtpoll_item *pa_rtpoll_item_new_asyncmsgq_read(pa_rtpoll *p, pa_rtpoll_priority_t prio, pa_asyncmsgq *q);
98 pa_rtpoll_item *pa_rtpoll_item_new_asyncmsgq_write(pa_rtpoll *p, pa_rtpoll_priority_t prio, pa_asyncmsgq *q);
99 
100 #endif
101