5 This file is part of avahi.
7 avahi is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
12 avahi is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15 Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with avahi; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 /** \file watch.h Simplistic main loop abstraction */
28 #include <avahi-common/cdecl.h>
32 /** An I/O watch object */
33 typedef struct AvahiWatch AvahiWatch;
35 /** A timeout watch object */
36 typedef struct AvahiTimeout AvahiTimeout;
38 /** An event polling abstraction object */
39 typedef struct AvahiPoll AvahiPoll;
41 /** Type of watch events */
43 AVAHI_WATCH_IN = POLLIN, /**< Input event */
44 AVAHI_WATCH_OUT = POLLOUT, /**< Output event */
45 AVAHI_WATCH_ERR = POLLERR, /**< Error event */
46 AVAHI_WATCH_HUP = POLLHUP /**< Hangup event */
49 /** Called whenever an I/O event happens on an I/O watch */
50 typedef void (*AvahiWatchCallback)(AvahiWatch *w, int fd, AvahiWatchEvent event, void *userdata);
52 /** Called when the timeout is reached */
53 typedef void (*AvahiTimeoutCallback)(AvahiTimeout *t, void *userdata);
55 /** Defines an abstracted event polling API. This may be used to
56 connect Avahi to other main loops. This is loosely based on Unix
57 poll(2). A consumer will call watch_new() for all file descriptors it
58 wants to listen for events on. In addition he can call timeout_new()
59 to define time based events .*/
62 /** Some abstract user data usable by the provider of the API */
65 /** Create a new watch for the specified file descriptor and for
66 * the specified events. The API will call the callback function
67 * whenever any of the events happens. */
68 AvahiWatch* (*watch_new)(const AvahiPoll *api, int fd, AvahiWatchEvent event, AvahiWatchCallback callback, void *userdata);
70 /** Update the events to wait for. It is safe to call this function from an AvahiWatchCallback */
71 void (*watch_update)(AvahiWatch *w, AvahiWatchEvent event);
73 /** Return the events that happened. It is safe to call this function from an AvahiWatchCallback */
74 AvahiWatchEvent (*watch_get_events)(AvahiWatch *w);
76 /** Free a watch. It is safe to call this function from an AvahiWatchCallback */
77 void (*watch_free)(AvahiWatch *w);
79 /** Set a wakeup time for the polling loop. The API will call the
80 callback function when the absolute time *tv is reached. If tv is
81 NULL, the timeout is disabled. After the timeout expired the
82 callback function will be called and the timeout is disabled. You
83 can reenable it by calling timeout_update() */
84 AvahiTimeout* (*timeout_new)(const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata);
86 /** Update the absolute expiration time for a timeout, If tv is
87 * NULL, the timeout is disabled. It is safe to call this function from an AvahiTimeoutCallback */
88 void (*timeout_update)(AvahiTimeout *, const struct timeval *tv);
90 /** Free a timeout. It is safe to call this function from an AvahiTimeoutCallback */
91 void (*timeout_free)(AvahiTimeout *t);