]> git.meshlink.io Git - catta/blob - avahi-common/thread-watch.h
98da2930b1296a3100598340daa58d886ebe02c0
[catta] / avahi-common / thread-watch.h
1 #ifndef foothreadedwatchhfoo
2 #define foothreadedwatchhfoo
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 thread-watch.h Threaded 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 that runs an AvahiSimplePoll in its own thread. \since 0.6.4 */
34 typedef struct AvahiThreadedPoll AvahiThreadedPoll;
35
36 /** Create a new event loop object. This will allocate the internal
37  * AvahiSimplePoll, but will not start the helper thread. \since 0.6.4 */
38 AvahiThreadedPoll *avahi_threaded_poll_new(void);
39
40 /** Free an event loop object. This will stop the associated event loop
41  * thread (if it is running). \since 0.6.4 */
42 void avahi_threaded_poll_free(AvahiThreadedPoll *p);
43
44 /** Return the abstracted poll API object for this event loop
45  * object. The will return the same pointer each time it is
46  * called. \since 0.6.4 */
47 const AvahiPoll* avahi_threaded_poll_get(AvahiThreadedPoll *p);
48
49 /** Start the event loop helper thread. After the thread has started
50  * you must make sure to access the event loop object
51  * (AvahiThreadedPoll, AvahiPoll and all its associated objects)
52  * synchronized, i.e. with proper locking. You may want to use
53  * avahi_threaded_poll_lock()/avahi_threaded_poll_unlock() for this,
54  * which will lock the the entire event loop. Please note that event
55  * loop callback functions are called from the event loop helper thread
56  * with that lock held, i.e. avahi_threaded_poll_lock() calls are not
57  * required from event callbacks. \since 0.6.4 */
58 int avahi_threaded_poll_start(AvahiThreadedPoll *p);
59
60 /** Request that the event loop quits and the associated thread
61  stops. Call this from outside the helper thread if you want to shut
62  it down. \since 0.6.4 */
63 int avahi_threaded_poll_stop(AvahiThreadedPoll *p);
64
65 /** Request that the event loop quits and the associated thread
66  stops. Call this from inside the helper thread if you want to shut it
67  down. \since 0.6.4  */
68 void avahi_threaded_poll_quit(AvahiThreadedPoll *p);
69
70 /** Lock the main loop object. Use this if you want to access the event
71  * loop objects (such as creating a new event source) from anything
72  * else but the event loop helper thread, i.e. from anything else but event
73  * loop callbacks \since 0.6.4  */
74 void avahi_threaded_poll_lock(AvahiThreadedPoll *p);
75
76 /** Unlock the event loop object, use this as counterpart to
77  * avahi_threaded_poll_lock() \since 0.6.4 */
78 void avahi_threaded_poll_unlock(AvahiThreadedPoll *p);
79
80 AVAHI_C_DECL_END
81
82 #endif