pnotify.h

Go to the documentation of this file.
00001 /*              $Id: $          */
00002 
00003 /*
00004  * Copyright (c) 2007 Mark Heily <devel@heily.com>
00005  *
00006  * Permission to use, copy, modify, and distribute this software for any
00007  * purpose with or without fee is hereby granted, provided that the above
00008  * copyright notice and this permission notice appear in all copies.
00009  *
00010  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00011  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00012  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00013  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00014  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00016  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00017  */
00018 
00019 #ifndef _PNOTIFY_H
00020 #define _PNOTIFY_H
00021 
00028 #include <dirent.h>
00029 #include <stdarg.h>
00030 #include <stdint.h>
00031 #include <limits.h>
00032 #include <sys/time.h>
00033 #include <stdarg.h>
00034 
00035 /* kqueue(4) in MacOS/X does not support NOTE_TRUNCATE */
00036 #ifndef NOTE_TRUNCATE
00037 # define NOTE_TRUNCATE 0
00038 #endif
00039 
00040 /* Opaque structures */
00041 struct pnotify_event;
00042 struct pnotify_ctx;
00043 
00044 
00046 enum pn_watch_type {
00048         WATCH_VNODE = 0,
00049 
00051         WATCH_FD,
00052 
00054         WATCH_TIMER,
00055 
00057         WATCH_SIGNAL,
00058         
00060         WATCH_FUNCTION
00061 };
00062 
00063 
00065 union pn_resource_id {
00070         int fd;
00071 
00077         int signum;
00078 
00084         int interval;
00085 
00092         char *path;
00093 };
00094 
00095 
00097 enum pn_event_bitmask {
00098 
00100         PN_DEFAULT              = 0,
00101 
00103         PN_ATTRIB               = 0x1 << 0,
00104 
00106         PN_CREATE               = 0x1 << 1,
00107 
00109         PN_DELETE               = 0x1 << 2,
00110 
00112         PN_MODIFY               = 0x1 << 3,
00113 
00115         PN_READ                 = 0x1 << 4,
00116 
00118         PN_WRITE                = 0x1 << 5,
00119 
00121         PN_CLOSE                = 0x1 << 6,
00122 
00124         PN_TIMEOUT              = 0x1 << 7,  
00125 
00127         PN_SIGNAL               = 0x1 << 8,  
00128 
00130         PN_ONESHOT              = 0x1 << 30,
00131 
00133         PN_ERROR                = 0x1 << 31,
00134 
00135 };
00136 
00137 
00143 struct pnotify_watch {
00144 
00146         enum pn_watch_type type;
00147 
00149         enum pn_event_bitmask mask;
00150 
00152         union pn_resource_id ident;
00153 
00161         void (*cb)();
00162         void *arg;
00163 
00165         struct pnotify_ctx *ctx;
00166 };
00167 
00168 
00177 struct pnotify_ctx * pnotify_init();
00178 
00185 int pnotify_add_watch(struct pnotify_watch *watch);
00186 
00193 int pnotify_rm_watch(int wd);
00194 
00195 
00203 int pnotify_get_event(struct pnotify_event *, struct pnotify_ctx *);
00204 
00210 int pnotify_dispatch();
00211 
00216 int pnotify_print_event(struct pnotify_event *);
00217 
00218 
00222 void pnotify_dump(struct pnotify_ctx *);
00223 
00232 void pnotify_free(struct pnotify_ctx *ctx);
00233 
00242 int pnotify_trap_signal(int signum, void (*cb)(), void *arg);
00243 
00250 int pnotify_watch_vnode(const char *path, int mask, void (*cb)(), void *arg);
00251 
00253 int pnotify_watch_fd(int fd, int mask, void (*cb)(), void *arg); 
00254 
00264 int pnotify_set_timer(int interval, int mask, void (*cb)(), void *arg);
00265 
00266 #if TODO
00267         // experimental
00268         
00270 #define PNOTIFY_ARG_MAX 12
00271 
00272 struct pnotify_func {
00273 
00275         void (*symbol)();
00276 
00278         size_t argc;
00279 
00281         void *argv[PNOTIFY_ARG_MAX + 1];
00282 
00284         void (*cb)();
00286         void *cbarg;    
00287 
00288         /* -- filled in by the function when it returns -- */
00289 
00291         union {
00292                 int rv_int;
00293                 void *rv_ptr;
00294         } retval;
00295 
00297         int ret_errno;
00298 };
00299 
00300 #define pnotify_set_function(pf, sym, 
00301 
00305 int pnotify_call_function(struct );
00306 #endif
00307 
00308 #endif /* _PNOTIFY_H */

Generated on Wed Aug 22 23:15:42 2007 for pnotify by  doxygen 1.5.1