code::FileChangeNotifier Class Reference

Inheritance diagram for code::FileChangeNotifier:

code::ActionSource List of all members.

Detailed Description

This ActionSource will check a given directory every time the function check() is invoked.

Then, if it determines that a file has been modified or added to that directory since the last check(), all its listeners are notified.

Note that the notification here is hit-and-miss and it is likely that you will get a file or two that is currently being modified ... You could also run into race problems. For sure-fire notification, use EventHandler. Use FileChangeNotifier when:

  1. you can not modify the writing program
  2. the writing program doesn't update files often or you are interested mostly in NewFile events.
  3. when there is not much network traffic

Recommended: Use EventHandler instead and set up your client(s)/server interaction appropriately.

See also:
EventHandler
Author:
: Lakshman
Version:
:
Id
code_FileChangeNotifier.h,v 1.9 2009/06/02 20:17:39 lakshman Exp


Public Member Functions

 FileChangeNotifier (const std::string &dir_name, TimeInterval latency_time=TimeInterval::Seconds(5))
 Specify the directory to check and the minimum time that the file should be unmodified before we assume that the file-writer is done.
void check ()
 Will check the directory once more and notify its listeners of any new files in the directory.
void process_filename (const std::string &filename)
 Tells the FileChangeNotifier to process the given filename and notify its clients if the access time is later than what is known.
void disregard_file (const std::string &filename)
 Tells the FileChangeNotifier to avoid the passed in file within the already-known directory.
void disregard (const std::string &complete_path)
 Tells the FileChangeNotifier to avoid the passed in file.
void copyListenersFrom (const ActionSource &other)
 copy all the listeners from the other source (replacing our own)
size_t getNumListeners () const
 returns the number of listeners linked to this source.
std::string getDir ()
 Returns a source-specific disk directory.
void addActionListener (SmartPtr< ActionListener > lstnr)
 Subscribe lstnr such that it receives all events from this ActionSource.
void addActionListener (const std::string &event_type, SmartPtr< ActionListener > lstnr)
 Subscribe lstnr such that it receives only this event type from this ActionSource.
void removeActionListener (SmartPtr< ActionListener > lstner)
 Unsubscribe lstnr such that it no longer receives events from this ActionSource.
void removeActionListener (const std::string &eventType, SmartPtr< ActionListener > lstner)
 Unsubscribe the listener so that it does not respond to the the event type noted.
void fireActionPerformed (const ActionEvent &e)
 Convenience function for subclasses to notify ActionListeners of events.
void fireActionPerformed (const ActionEvent *e)
 Convenience function for subclasses to notify ActionListeners of events.
void fireActionPerformed (const std::string &type)
 Convenience function for subclasses to notify ActionListeners of events.

Static Public Attributes

static const std::string Modified
 Notification events can be for a modified file.
static const std::string NewFile
 Notification events can be for a new file.

Protected Attributes

std::string dir_name
 The directory being checked.
TimeInterval latency_time
 The latency-time : the time for which the file should be unmodified before we consider it.
std::map< std::string, FileChangeNotifier::FileInfofilemap
 The map that stores information about known files.
std::set< std::string > avoidthese
 Set of filenames that for some reason or the other, we avoid.

Classes

struct  FileInfo
 Information about file that is stored in map. More...
class  NotifierEvent
 NotifierEvent is the event that gets passed to clients of FileChangeNotifier. More...


Constructor & Destructor Documentation

code::FileChangeNotifier::FileChangeNotifier ( const std::string &  dir_name,
TimeInterval  latency_time = TimeInterval::Seconds(5) 
)

Specify the directory to check and the minimum time that the file should be unmodified before we assume that the file-writer is done.

Default for the latency time is 5 seconds. In heavy network traffic, you probably want to increase this.

If you can get the program writing the files to post messages into a linear buffer (see EventHandler), this sort of hit-and-miss nature can be avoided.


Member Function Documentation

void code::ActionSource::addActionListener ( const std::string &  event_type,
SmartPtr< ActionListener lstnr 
) [inline, inherited]

Subscribe lstnr such that it receives only this event type from this ActionSource.

Parameters:
evt_type the event type we are subscribing to
lstnr the action listener to be subscribed.

void code::ActionSource::addActionListener ( SmartPtr< ActionListener lstnr  )  [inline, inherited]

Subscribe lstnr such that it receives all events from this ActionSource.

Parameters:
l the action listener to be subscribed.

void code::FileChangeNotifier::check (  ) 

Will check the directory once more and notify its listeners of any new files in the directory.

void code::ActionSource::copyListenersFrom ( const ActionSource other  )  [inline, inherited]

copy all the listeners from the other source (replacing our own)

void code::FileChangeNotifier::disregard ( const std::string &  complete_path  ) 

Tells the FileChangeNotifier to avoid the passed in file.

The file should be of the form dir_name/filename. If you don't know the directory name, use the public function disregard_file

void code::FileChangeNotifier::disregard_file ( const std::string &  filename  )  [inline]

Tells the FileChangeNotifier to avoid the passed in file within the already-known directory.

void code::ActionSource::fireActionPerformed ( const std::string &  type  )  [inline, inherited]

Convenience function for subclasses to notify ActionListeners of events.

Parameters:
type the type of the ActionEvent to be passed along to the action listeners.

void code::ActionSource::fireActionPerformed ( const ActionEvent e  )  [inline, inherited]

Convenience function for subclasses to notify ActionListeners of events.

Parameters:
actionEvent the event to be passed along to the action listeners.

void code::ActionSource::fireActionPerformed ( const ActionEvent e  )  [inline, inherited]

Convenience function for subclasses to notify ActionListeners of events.

Parameters:
actionEvent the event to be passed along to the action listeners.

std::string code::ActionSource::getDir (  )  [inline, inherited]

Returns a source-specific disk directory.

Default implementation does nothing --- this should be overridden.

Returns:
a source-specific type identifier to indicate what action occurred.

size_t code::ActionSource::getNumListeners (  )  const [inline, inherited]

returns the number of listeners linked to this source.

void code::FileChangeNotifier::process_filename ( const std::string &  filename  ) 

Tells the FileChangeNotifier to process the given filename and notify its clients if the access time is later than what is known.

The filename doesn't include path.

void code::ActionSource::removeActionListener ( const std::string &  eventType,
SmartPtr< ActionListener lstner 
) [inline, inherited]

Unsubscribe the listener so that it does not respond to the the event type noted.

This works only if the listener was added via addActionListener( type, SmartPtr )

Parameters:
type The event type
lstnr The listener to remove

void code::ActionSource::removeActionListener ( SmartPtr< ActionListener lstner  )  [inline, inherited]

Unsubscribe lstnr such that it no longer receives events from this ActionSource.

Parameters:
lstnr the action listener to be unsubscribed.


Member Data Documentation

std::set< std::string > code::FileChangeNotifier::avoidthese [protected]

Set of filenames that for some reason or the other, we avoid.

std::string code::FileChangeNotifier::dir_name [protected]

The directory being checked.

std::map< std::string, FileChangeNotifier::FileInfo > code::FileChangeNotifier::filemap [protected]

The map that stores information about known files.

TimeInterval code::FileChangeNotifier::latency_time [protected]

The latency-time : the time for which the file should be unmodified before we consider it.

const std::string code::FileChangeNotifier::Modified [static]

Notification events can be for a modified file.

const std::string code::FileChangeNotifier::NewFile [static]

Notification events can be for a new file.


Generated on Fri May 4 13:40:13 2012 for WDSS-IIw2 by  doxygen 1.4.7