]> git.meshlink.io Git - catta/blob - avahi-common/watch.h
* doxygen documentation updates
[catta] / avahi-common / watch.h
1 #ifndef foowatchhfoo
2 #define foowatchhfoo
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 watch.h Simplistic main loop abstraction */
26
27 #include <sys/poll.h>
28 #include <avahi-common/cdecl.h>
29
30 #include "timeval.h"
31
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 AVAHI_C_DECL_BEGIN
34 #endif
35
36 /** An I/O watch object */
37 typedef struct AvahiWatch AvahiWatch;
38
39 /** An event polling abstraction object */
40 typedef struct AvahiPoll AvahiPoll;
41
42 /** Type of watch events */
43 typedef enum {
44     AVAHI_WATCH_IN = POLLIN,      /** Input event */
45     AVAHI_WATCH_OUT = POLLOUT,    /** Output event */
46     AVAHI_WATCH_ERR = POLLERR,    /** Error event */
47     AVAHI_WATCH_HUP = POLLHUP     /** Hangup event */
48 } AvahiWatchEvent;
49
50 /** Called whenever an I/O event happens  on an I/O watch */
51 typedef void (*AvahiWatchCallback)(AvahiWatch *w, int fd, AvahiWatchEvent event, void *userdata);
52
53 /** Called when the wakeup time is reached */
54 typedef void (*AvahiWakeupCallback)(AvahiPoll *api, void *userdata);
55
56 /** Defines an abstracted event polling API. This may be used to
57  connect Avahi to other main loops. This is losely based on Unix
58  poll(2). A consumer will call watch_new() for all file descriptors it
59  wants to listen for events on. In addition he can call set_wakeup()
60  to define a single wakeup time.*/
61 struct AvahiPoll {
62
63     /** Some abstract user data usable by the implementor of the API */
64     void* userdata; 
65
66     /** Create a new watch for the specified file descriptor and for
67      * the specified events. The API will call the callback function
68      * whenever any of the events happens. */
69     AvahiWatch* (*watch_new)(const AvahiPoll *api, int fd, AvahiWatchEvent event, AvahiWatchCallback callback, void *userdata);
70
71     /** Update the events to wait for. */
72     void (*watch_update)(AvahiWatch *w, AvahiWatchEvent event);
73
74     /** Free a watch */
75     void (*watch_free)(AvahiWatch *w);
76
77     /** Set a wakeup time for the polling loop. The API will call the
78     callback function when the absolute time *tv is reached. If *tv is
79     NULL, the callback will be called in the next main loop
80     iteration. If callback is NULL the wakeup time is disabled. */
81     void (*set_wakeup)(const AvahiPoll *api, const struct timeval *tv, AvahiWakeupCallback callback, void *userdata);
82 };
83
84 #ifndef DOXYGEN_SHOULD_SKIP_THIS
85 AVAHI_C_DECL_END
86 #endif
87
88 #endif
89