1 #ifndef foothreadedwatchhfoo
2 #define foothreadedwatchhfoo
7 This file is part of avahi.
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.
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.
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
25 /** \file thread-watch.h Threaded poll() based main loop implementation */
28 #include <avahi-common/cdecl.h>
29 #include <avahi-common/watch.h>
33 /** A main loop object that runs an AvahiSimplePoll in its own thread. \since 0.6.4 */
34 typedef struct AvahiThreadedPoll AvahiThreadedPoll;
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);
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);
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);
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);
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);
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
68 void avahi_threaded_poll_quit(AvahiThreadedPoll *p);
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);
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);