pnotify.h File Reference

#include <dirent.h>
#include <stdarg.h>
#include <stdint.h>
#include <limits.h>
#include <sys/time.h>

Go to the source code of this file.

Classes

union  pn_resource_id
struct  pnotify_watch

Defines

#define NOTE_TRUNCATE   0

Enumerations

enum  pn_watch_type {
  WATCH_VNODE = 0, WATCH_FD, WATCH_TIMER, WATCH_SIGNAL,
  WATCH_FUNCTION
}
enum  pn_event_bitmask {
  PN_DEFAULT = 0, PN_ATTRIB = 0x1 << 0, PN_CREATE = 0x1 << 1, PN_DELETE = 0x1 << 2,
  PN_MODIFY = 0x1 << 3, PN_READ = 0x1 << 4, PN_WRITE = 0x1 << 5, PN_CLOSE = 0x1 << 6,
  PN_TIMEOUT = 0x1 << 7, PN_SIGNAL = 0x1 << 8, PN_ONESHOT = 0x1 << 30, PN_ERROR = 0x1 << 31
}

Functions

pnotify_ctxpnotify_init ()
int pnotify_add_watch (struct pnotify_watch *watch)
int pnotify_rm_watch (int wd)
int pnotify_get_event (struct pnotify_event *, struct pnotify_ctx *)
int pnotify_dispatch ()
int pnotify_print_event (struct pnotify_event *)
void pnotify_dump (struct pnotify_ctx *)
void pnotify_free (struct pnotify_ctx *ctx)
int pnotify_trap_signal (int signum, void(*cb)(), void *arg)
int pnotify_watch_vnode (const char *path, int mask, void(*cb)(), void *arg)
int pnotify_watch_fd (int fd, int mask, void(*cb)(), void *arg)
int pnotify_set_timer (int interval, int mask, void(*cb)(), void *arg)


Detailed Description

Public header for the pnotify library.

Definition in file pnotify.h.


Enumeration Type Documentation

enum pn_event_bitmask

The bitmask of events to monitor

Enumerator:
PN_DEFAULT  Use the default settings when creating a watch
PN_ATTRIB  The attributes of a file have been modified
PN_CREATE  A file was created in a watched directory
PN_DELETE  A file was deleted from a watched directory
PN_MODIFY  The contents of a file have changed
PN_READ  Data is ready to be read from a file descriptor
PN_WRITE  Data is ready to be written to a file descriptor
PN_CLOSE  A socket or pipe descriptor was closed by the remote end
PN_TIMEOUT  A timer expired
PN_SIGNAL  A signal was received
PN_ONESHOT  Delete the watch after a matching event occurs
PN_ERROR  An error condition in the underlying kernel event queue

Definition at line 97 of file pnotify.h.

enum pn_watch_type

The type of resource to be watched

Enumerator:
WATCH_VNODE  A vnode in the filesystem
WATCH_FD  An open file descriptor
WATCH_TIMER  A user-defined timer
WATCH_SIGNAL  Signals from the operating system
WATCH_FUNCTION  User-defined asynchronous function call

Definition at line 46 of file pnotify.h.


Function Documentation

int pnotify_add_watch ( struct pnotify_watch watch  ) 

Add a watch.

Parameters:
watch a watch structure
Returns:
a unique watch descriptor if successful, or -1 if an error occurred.

Definition at line 164 of file pnotify.c.

References pnotify_vtable::add_watch, pnotify_watch::arg, pnotify_watch::cb, pnotify_watch::ctx, CTX_GET, pnotify_watch::ident, pnotify_watch::mask, pn_resource_id::path, pn_resource_id::signum, sys, pnotify_watch::type, WATCH_FD, WATCH_SIGNAL, WATCH_TIMER, and WATCH_VNODE.

Referenced by pnotify_set_timer(), pnotify_trap_signal(), pnotify_watch_fd(), and pnotify_watch_vnode().

int pnotify_dispatch (  ) 

Wait for events and dispatch callbacks.

Returns:
-1 if an error occurs, otherwise the function does not return

Definition at line 481 of file pnotify.c.

References pn_watch::arg, pn_watch::cb, pnotify_event::mask, pnotify_get_event(), pn_watch::type, pnotify_event::watch, WATCH_TIMER, and WATCH_VNODE.

void pnotify_dump ( struct pnotify_ctx  ) 

Print the context to standard output.

Definition at line 337 of file pnotify.c.

References pnotify_print_event().

void pnotify_free ( struct pnotify_ctx ctx  ) 

Free all resources associated with an event queue.

All internal data structures will be freed.

Parameters:
ctx a context returned by pnotify_init() or NULL for the current context
Returns:
0 if successful, or non-zero if an error occurred.

Definition at line 355 of file pnotify.c.

References pnotify_vtable::cleanup, pnotify_ctx::event_count, pnotify_ctx::mutex, pnotify_rm_watch(), sys, pnotify_event::watch, and pn_watch::wd.

int pnotify_get_event ( struct pnotify_event ,
struct pnotify_ctx  
)

Wait for an event to occur.

Parameters:
evt an event structure that will store the result
ctx a context returned by pnotify_init() or NULL for the current context
Returns:
0 if successful, or non-zero if an error occurred.

Definition at line 286 of file pnotify.c.

References CTX_GET, and pnotify_ctx::event_count.

Referenced by pnotify_dispatch().

struct pnotify_ctx* pnotify_init (  ) 

Initialize a pnotify event queue.

Before adding watches, the queue must be initialized via a call to pnotify_init().

Returns:
pointer to a new pnotify context, or NULL if an error occurred.

Definition at line 122 of file pnotify.c.

References pnotify_init_once().

int pnotify_print_event ( struct pnotify_event  ) 

Print debugging information about an event to standard output.

Parameters:
evt an event to be printed

Definition at line 321 of file pnotify.c.

References pnotify_event::mask, pnotify_event::name, PN_ATTRIB, PN_CREATE, PN_DELETE, PN_ERROR, PN_MODIFY, pnotify_event::watch, and pn_watch::wd.

Referenced by pnotify_dump().

int pnotify_rm_watch ( int  wd  ) 

Remove a watch.

Parameters:
wd watch descriptor
Returns:
0 if successful, or non-zero if an error occurred.

Definition at line 247 of file pnotify.c.

References pn_watch::parent_wd, pn_rm_timer(), pnotify_vtable::rm_watch, sys, WATCH_TIMER, and pn_watch::wd.

Referenced by pnotify_free().

int pnotify_set_timer ( int  interval,
int  mask,
void(*)()  cb,
void *  arg 
)

Set a timer to fire after specific number of seconds

If the mask is set to PN_ONESHOT, the timer will be automatically deleted after one occurrance. If the mask is PN_DEFAULT, the timer will repeat forever.

Parameters:
interval the number of seconds between timer events
mask either PN_DEFAULT or PN_ONESHOT

Definition at line 429 of file pnotify.c.

References pnotify_watch::arg, pnotify_watch::cb, pnotify_watch::ident, pn_resource_id::interval, pnotify_watch::mask, pn_add_timer(), pnotify_add_watch(), pnotify_watch::type, and WATCH_TIMER.

int pnotify_trap_signal ( int  signum,
void(*)()  cb,
void *  arg 
)

Trap a specific signal and generate an event when it is received.

When a signal is trapped, it is no longer delivered to the program and is converted into an event instead.

Parameters:
signum the signal to be trapped
Returns:
a watch descriptor, or -1 if an error occurred

Definition at line 455 of file pnotify.c.

References pnotify_watch::arg, pnotify_watch::cb, CTX_GET, pnotify_watch::ident, pnotify_watch::mask, PN_SIGNAL, pn_trap_signal(), pnotify_add_watch(), pn_resource_id::signum, pnotify_watch::type, and WATCH_SIGNAL.

int pnotify_watch_fd ( int  fd,
int  mask,
void(*)()  cb,
void *  arg 
)

Watch for changes to a file descriptor

Definition at line 415 of file pnotify.c.

References pnotify_watch::arg, pnotify_watch::cb, pn_resource_id::fd, pnotify_watch::ident, pnotify_watch::mask, pnotify_add_watch(), pnotify_watch::type, and WATCH_FD.

int pnotify_watch_vnode ( const char *  path,
int  mask,
void(*)()  cb,
void *  arg 
)

Watch for changes to a vnode

Parameters:
path the path to a file or directory to be monitored
mask a bitmask of events to monitor
Returns:
a watch descriptor, or -1 if an error occurred

Definition at line 400 of file pnotify.c.

References pnotify_watch::arg, pnotify_watch::cb, pnotify_watch::ident, pnotify_watch::mask, pn_resource_id::path, pnotify_add_watch(), pnotify_watch::type, and WATCH_VNODE.


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