H::FileEventWatcher Class Reference

Class to efficiently watch for changes in files. More...

#include <FileEventWatcher.hpp>

Inheritance diagram for H::FileEventWatcher:

Inheritance graph
[legend]
Collaboration diagram for H::FileEventWatcher:

Collaboration graph
[legend]
List of all members.

Public Member Functions

boost::shared_ptr< FileWatcheeaddFileToWatch (std::string FileName, FileWatchType WatchType, std::string DefaultDeviceName="Unknown")
 Add a file to watch for events.
boost::shared_ptr< FileWatcheeaddUnixSocketToWatch (std::string FileName, std::string DeviceName)
 Add a unix socket to the watch group.
boost::shared_ptr< FileWatcheegetWatcheeByFileDescriptor (int fd)
 Get a Watchee by file descriptor.
boost::shared_ptr< FileWatcheegetWatcheeByPath (std::string Path)
 Get a Watchee by file name.
boost::shared_ptr< FileWatcheegetWatcheeByWatchDescriptor (int wd)
 Get a Watchee by watch descriptor.
virtual void onFileEventCreate (boost::shared_ptr< FileWatchee > pWatchee, std::string FullPath, std::string FileName)
 Event triggered when a new file is created.
virtual void onFileEventDelete (boost::shared_ptr< FileWatchee > pWatchee, std::string FullPath, std::string FileName)
 Event triggered when a file is deleted.
virtual void onFileEventDisconnect (boost::shared_ptr< FileWatchee > pWatchee)
 Event triggered when a device is disconnected.
virtual void onFileEventRead (boost::shared_ptr< FileWatchee > pWatchee, DynamicBuffer< char > const &ReadBuffer)
 Event triggered when data is waiting on a device.
virtual void onFileEventRegister (boost::shared_ptr< FileWatchee > pWatchee)
 Event triggered when a new device is registered.
virtual void onFileEventWatchBegin ()
 Event called when the class will begin watching for events (and blocking).
virtual void onFileEventWatchEnd ()
 Event called when the class has ended watching for events (and done blocking).
void removeWatchee (boost::shared_ptr< FileWatchee > pWatchee)
 Remove a Watchee from the list.
void shutdown ()
 Disable event watching.
void watchForFileEvents ()
 Watch for events on already specified files.
 FileEventWatcher ()
 Default Constructor.
virtual ~FileEventWatcher ()
 Destructor.

Detailed Description

Class to efficiently watch for changes in files.

This class uses the poll() mechanism to efficiently watch for file changes rather than using select() which does not scale well.

FileEventWatcher is essentially a wrapper for poll() which makes it easy to integrate into any program

Also use the linux kernel's inotify event to get information about directory changes (add / remove files, etc). Unfortunately inotify doesn't work with event node updates so poll is still required


Member Function Documentation

boost::shared_ptr< FileWatchee > FileEventWatcher::addFileToWatch ( std::string  FileName,
FileWatchType  WatchType,
std::string  DefaultDeviceName = "Unknown" 
)

Add a file to watch for events.

Parameters:
FileName Absolute path of the file to watch
WatchType Type of watch to perform on the file
DefaultDeviceName Default device name if the device does not support having a name

boost::shared_ptr< FileWatchee > FileEventWatcher::addUnixSocketToWatch ( std::string  FileName,
std::string  DeviceName 
)

Add a unix socket to the watch group.

Parameters:
FileName Absolute path of the file to watch
DeviceName Device name

boost::shared_ptr< FileWatchee > FileEventWatcher::getWatcheeByFileDescriptor ( int  fd  ) 

Get a Watchee by file descriptor.

Parameters:
fd File Desriptor of the desired watchee
Returns:
The watchee (shared_ptr to FileWatchee)

boost::shared_ptr< FileWatchee > FileEventWatcher::getWatcheeByPath ( std::string  FileName  ) 

Get a Watchee by file name.

Parameters:
FileName File name of watchee to get
Returns:
The watchee (shared_ptr to FileWatchee)

boost::shared_ptr< FileWatchee > FileEventWatcher::getWatcheeByWatchDescriptor ( int  wd  ) 

Get a Watchee by watch descriptor.

Parameters:
wd Watch Desriptor of the desired watchee
Returns:
The watchee (shared_ptr to FileWatchee)

void FileEventWatcher::onFileEventCreate ( boost::shared_ptr< FileWatchee pWatchee,
std::string  FullPath,
std::string  FileName 
) [virtual]

Event triggered when a new file is created.

Parameters:
pWatchee The Watchee that triggered the event
FullPath The full (absolute) path of the new file
FileName The file name (relative ) of the new file

void FileEventWatcher::onFileEventDelete ( boost::shared_ptr< FileWatchee pWatchee,
std::string  FullPath,
std::string  FileName 
) [virtual]

Event triggered when a file is deleted.

Parameters:
pWatchee The Watchee that triggered the event
FullPath The full (absolute) path of the new file
FileName The file name (relative ) of the new file

void FileEventWatcher::onFileEventDisconnect ( boost::shared_ptr< FileWatchee pWatchee  )  [virtual]

Event triggered when a device is disconnected.

Parameters:
pWatchee The Watchee that triggered the event

void FileEventWatcher::onFileEventRead ( boost::shared_ptr< FileWatchee pWatchee,
DynamicBuffer< char > const &  ReadBuffer 
) [virtual]

Event triggered when data is waiting on a device.

Parameters:
pWatchee The Watchee that triggered the event
ReadBuffer The data that was waiting on the device

void FileEventWatcher::onFileEventRegister ( boost::shared_ptr< FileWatchee pWatchee  )  [virtual]

Event triggered when a new device is registered.

Parameters:
pWatchee The Watchee that triggered the event

void FileEventWatcher::removeWatchee ( boost::shared_ptr< FileWatchee pWatchee  ) 

Remove a Watchee from the list.

Parameters:
pWatchee The watchee to remove

void FileEventWatcher::shutdown (  ) 

Disable event watching.

This does not interrupt a current call to poll, so watchForFileEvents will only exit after this function is called, and then the next event is received

void FileEventWatcher::watchForFileEvents (  ) 

Watch for events on already specified files.

Note: Blocking


The documentation for this class was generated from the following files:
Generated on Wed Jun 27 12:44:05 2007 for gizmod by  doxygen 1.4.7