Fawkes API  Fawkes Development Version
fawkes::FileAlterationMonitor Class Reference

Monitors files for changes. More...

#include <>>

Public Member Functions

 FileAlterationMonitor ()
 Constructor. More...
 
 ~FileAlterationMonitor ()
 Destructor. More...
 
void watch_dir (const char *dirpath)
 Watch a directory. More...
 
void watch_file (const char *filepath)
 Watch a file. More...
 
void add_filter (const char *regex)
 Add a filter. More...
 
void process_events (int timeout=0)
 Process events. More...
 
void interrupt ()
 Interrupt a running process_events(). More...
 
void add_listener (FamListener *listener)
 Add a listener. More...
 
void remove_listener (FamListener *listener)
 Remove a listener. More...
 

Detailed Description

Monitors files for changes.

This is a wrapper around inotify. It will watch directories and files for modifications. If a modifiacation, removal or addition of a file is detected one or more listeners are called. The files which trigger the event can be constrained with regular expressions.

Author
Tim Niemueller

Definition at line 71 of file fam.h.

Constructor & Destructor Documentation

fawkes::FileAlterationMonitor::FileAlterationMonitor ( )

Constructor.

Opens the inotify context.

Definition at line 108 of file fam.cpp.

fawkes::FileAlterationMonitor::~FileAlterationMonitor ( )

Destructor.

Definition at line 128 of file fam.cpp.

Member Function Documentation

void fawkes::FileAlterationMonitor::add_filter ( const char *  regex)

Add a filter.

Filters are applied to path names that triggered an event. All pathnames are checked against this regex and if any does not match the event is not posted to listeners. An example regular expression is

^[^.].*\\.lua$

This regular expression matches to all files that does not start with a dot and have an .lua ending.

Parameters
regexregular expression to add

Definition at line 231 of file fam.cpp.

References fawkes::LockList< Type >::push_back_locked().

void fawkes::FileAlterationMonitor::add_listener ( FamListener listener)

Add a listener.

Parameters
listenerlistener to add

Definition at line 249 of file fam.cpp.

void fawkes::FileAlterationMonitor::interrupt ( )

Interrupt a running process_events().

This method will interrupt e.g. a running inifinetly blocking call of process_events().

Definition at line 386 of file fam.cpp.

void fawkes::FileAlterationMonitor::process_events ( int  timeout = 0)

Process events.

Call this when you want file events to be processed.

Parameters
timeouttimeout in milliseconds to wait for an event, 0 to just check and no wait, -1 to wait forever until an event is received

Definition at line 271 of file fam.cpp.

References watch_dir().

void fawkes::FileAlterationMonitor::remove_listener ( FamListener listener)

Remove a listener.

Parameters
listenerlistener to remove

Definition at line 259 of file fam.cpp.

void fawkes::FileAlterationMonitor::watch_dir ( const char *  dirpath)

Watch a directory.

This adds the given directory recursively to this FAM.

Parameters
dirpathpath to directory to add

Definition at line 153 of file fam.cpp.

Referenced by process_events().

void fawkes::FileAlterationMonitor::watch_file ( const char *  filepath)

Watch a file.

This adds the given fileto this FAM.

Parameters
filepathpath to file to add

Definition at line 202 of file fam.cpp.


The documentation for this class was generated from the following files: