Inheritance diagram for code::FileChangeNotifier:
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:
Recommended: Use EventHandler instead and set up your client(s)/server interaction appropriately.
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::FileInfo > | filemap |
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... |
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.
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.
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.
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.
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.
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.
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.
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 )
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.
lstnr | the action listener to be unsubscribed. |
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.