• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef foowatchhfoo
2 #define foowatchhfoo
3 
4 /***
5   This file is part of avahi.
6 
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.
11 
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.
16 
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
20   USA.
21 ***/
22 
23 /** \file watch.h Simplistic main loop abstraction */
24 
25 #include <sys/poll.h>
26 #include <sys/time.h>
27 
28 #include <avahi-common/cdecl.h>
29 
30 AVAHI_C_DECL_BEGIN
31 
32 /** An I/O watch object */
33 typedef struct AvahiWatch AvahiWatch;
34 
35 /** A timeout watch object */
36 typedef struct AvahiTimeout AvahiTimeout;
37 
38 /** An event polling abstraction object */
39 typedef struct AvahiPoll AvahiPoll;
40 
41 /** Type of watch events */
42 typedef enum {
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 */
47 } AvahiWatchEvent;
48 
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);
51 
52 /** Called when the timeout is reached */
53 typedef void (*AvahiTimeoutCallback)(AvahiTimeout *t, void *userdata);
54 
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 .*/
60 struct AvahiPoll {
61 
62     /** Some abstract user data usable by the provider of the API */
63     void* userdata;
64 
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);
69 
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);
72 
73     /** Return the events that happened. It is safe to call this function from an AvahiWatchCallback  */
74     AvahiWatchEvent (*watch_get_events)(AvahiWatch *w);
75 
76     /** Free a watch. It is safe to call this function from an AvahiWatchCallback */
77     void (*watch_free)(AvahiWatch *w);
78 
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);
85 
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);
89 
90     /** Free a timeout. It is safe to call this function from an AvahiTimeoutCallback */
91     void (*timeout_free)(AvahiTimeout *t);
92 };
93 
94 AVAHI_C_DECL_END
95 
96 #endif
97 
98