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 <sys/time.h> 29 30#include <avahi-common/cdecl.h> 31 32AVAHI_C_DECL_BEGIN 33 34/** An I/O watch object */ 35typedef struct AvahiWatch AvahiWatch; 36 37/** A timeout watch object */ 38typedef struct AvahiTimeout AvahiTimeout; 39 40/** An event polling abstraction object */ 41typedef struct AvahiPoll AvahiPoll; 42 43/** Type of watch events */ 44typedef enum { 45 AVAHI_WATCH_IN = POLLIN, /**< Input event */ 46 AVAHI_WATCH_OUT = POLLOUT, /**< Output event */ 47 AVAHI_WATCH_ERR = POLLERR, /**< Error event */ 48 AVAHI_WATCH_HUP = POLLHUP /**< Hangup event */ 49} AvahiWatchEvent; 50 51/** Called whenever an I/O event happens on an I/O watch */ 52typedef void (*AvahiWatchCallback)(AvahiWatch *w, int fd, AvahiWatchEvent event, void *userdata); 53 54/** Called when the timeout is reached */ 55typedef void (*AvahiTimeoutCallback)(AvahiTimeout *t, void *userdata); 56 57/** Defines an abstracted event polling API. This may be used to 58 connect Avahi to other main loops. This is loosely based on Unix 59 poll(2). A consumer will call watch_new() for all file descriptors it 60 wants to listen for events on. In addition he can call timeout_new() 61 to define time based events .*/ 62struct AvahiPoll { 63 64 /** Some abstract user data usable by the provider of the API */ 65 void* userdata; 66 67 /** Create a new watch for the specified file descriptor and for 68 * the specified events. The API will call the callback function 69 * whenever any of the events happens. */ 70 AvahiWatch* (*watch_new)(const AvahiPoll *api, int fd, AvahiWatchEvent event, AvahiWatchCallback callback, void *userdata); 71 72 /** Update the events to wait for. It is safe to call this function from an AvahiWatchCallback */ 73 void (*watch_update)(AvahiWatch *w, AvahiWatchEvent event); 74 75 /** Return the events that happened. It is safe to call this function from an AvahiWatchCallback */ 76 AvahiWatchEvent (*watch_get_events)(AvahiWatch *w); 77 78 /** Free a watch. It is safe to call this function from an AvahiWatchCallback */ 79 void (*watch_free)(AvahiWatch *w); 80 81 /** Set a wakeup time for the polling loop. The API will call the 82 callback function when the absolute time *tv is reached. If tv is 83 NULL, the timeout is disabled. After the timeout expired the 84 callback function will be called and the timeout is disabled. You 85 can reenable it by calling timeout_update() */ 86 AvahiTimeout* (*timeout_new)(const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata); 87 88 /** Update the absolute expiration time for a timeout, If tv is 89 * NULL, the timeout is disabled. It is safe to call this function from an AvahiTimeoutCallback */ 90 void (*timeout_update)(AvahiTimeout *, const struct timeval *tv); 91 92 /** Free a timeout. It is safe to call this function from an AvahiTimeoutCallback */ 93 void (*timeout_free)(AvahiTimeout *t); 94}; 95 96AVAHI_C_DECL_END 97 98#endif 99 100