fawkes::FileAlterationMonitor Class Reference

Monitors files for changes. More...

#include <utils/system/fam.h>

List of all members.

Public Member Functions

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


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:
regex regular expression to add

Definition at line 233 of file fam.cpp.

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

Referenced by fawkes::LuaContext::LuaContext().

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

Add a listener.

Parameters:
listener listener to add

Definition at line 251 of file fam.cpp.

Referenced by fawkes::LuaContext::LuaContext().

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:
timeout timeout 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 273 of file fam.cpp.

References fawkes::LibLogger::log_error(), fawkes::LibLogger::log_warn(), and watch_dir().

Referenced by fawkes::LuaContext::process_fam_events().

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

Remove a listener.

Parameters:
listener listener to remove

Definition at line 261 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:
dirpath path to directory to add

Definition at line 153 of file fam.cpp.

References fawkes::LibLogger::log_debug().

Referenced by fawkes::LuaContext::add_cpackage_dir(), fawkes::LuaContext::add_package_dir(), and process_events().

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

Watch a file.

This adds the given fileto this FAM.

Parameters:
filepath path to file to add

Definition at line 203 of file fam.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Feb 22 13:31:41 2011 for Fawkes API by  doxygen 1.4.7