]> git.meshlink.io Git - catta/blob - avahi-common/simple-watch.h
20e8f798dc04f1e40158f76deadb091f0c142e30
[catta] / avahi-common / simple-watch.h
1 #ifndef foosimplewatchhfoo
2 #define foosimplewatchhfoo
3
4 /* $Id$ */
5
6 /***
7   This file is part of avahi.
8
9   avahi is free software; you can redistribute it and/or modify it
10   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   avahi is distributed in the hope that it will be useful, but WITHOUT
15   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
17   Public License for more details.
18
19   You should have received a copy of the GNU Lesser General Public
20   License along with avahi; if not, write to the Free Software
21   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22   USA.
23 ***/
24
25 /** \file simple-watch.h Simple poll() based main loop implementation */
26
27 #include <sys/poll.h>
28 #include <avahi-common/cdecl.h>
29 #include <avahi-common/watch.h>
30
31 AVAHI_C_DECL_BEGIN
32
33 /** A main loop object. Main loops of this type aren't very flexible
34  * since they only support a single wakeup type. Nevertheless it
35  * should suffice for small test and example applications.  */
36 typedef struct AvahiSimplePoll AvahiSimplePoll;
37
38 /** Create a new main loop object */
39 AvahiSimplePoll *avahi_simple_poll_new(void);
40
41 /** Free a main loop object */
42 void avahi_simple_poll_free(AvahiSimplePoll *s);
43
44 /** Return the abstracted poll API object for this main loop
45  * object. The is will return the same pointer each time it is
46  * called. */
47 const AvahiPoll* avahi_simple_poll_get(AvahiSimplePoll *s);
48
49 /** Run a single main loop iteration of this main loop. If sleep_time
50 is < 0 this will block until any of the registered events happens,
51 then it will execute the attached callback function. If sleep_time is
52 0 the routine just checks if any event is pending. If yes the attached
53 callback function is called, otherwise the function returns
54 immediately. If sleep_time > 0 the function will block for at most the
55 specified time in msecs. Returns -1 on error, 0 on success and 1 if a
56 quit request has been scheduled. Usually this function should be called
57 in a loop until it returns a non-zero value*/
58 int avahi_simple_poll_iterate(AvahiSimplePoll *s, int sleep_time);
59
60 /** Request that the main loop quits. If this is called the next
61  call to avahi_simple_poll_iterate() will return 1 */
62 void avahi_simple_poll_quit(AvahiSimplePoll *s);
63
64 /** Prototype for a poll() type function */
65 typedef int (*AvahiPollFunc)(struct pollfd *ufds, unsigned int nfds, int timeout, void *userdata);
66
67 /** Replace the internally used poll() function. By default the system's poll() will be used */
68 void avahi_simple_poll_set_func(AvahiSimplePoll *s, AvahiPollFunc func, void *userdata);
69
70 /** The first stage of avahi_simple_poll_iterate(), use this function only if you know what you do */
71 int avahi_simple_poll_prepare(AvahiSimplePoll *s, int timeout);
72
73 /** The second stage of avahi_simple_poll_iterate(), use this function only if you know what you do */
74 int avahi_simple_poll_run(AvahiSimplePoll *s);
75
76 /** The third and final stage of avahi_simple_poll_iterate(), use this function only if you know what you do */
77 int avahi_simple_poll_dispatch(AvahiSimplePoll *s);
78
79 /** Call avahi_simple_poll_iterate() in a loop and return if it returns non-zero */
80 int avahi_simple_poll_loop(AvahiSimplePoll *s);
81
82 /** Wakeup the main loop. (for threaded environments) */
83 void avahi_simple_poll_wakeup(AvahiSimplePoll *s);
84
85 AVAHI_C_DECL_END
86
87 #endif