This class is used to get notifications about changes to the filesystem, more specifically, to a specific directory. Changes to a directory are reported via events.
A thread will be created that watches the specified directory for changes. Events are reported in the context of this thread.
Note that changes to files in subdirectories of the watched directory are not reported. Separate DirectoryWatcher objects must be created for these directories if they should be watched.
Changes to file attributes are not reported.
On Windows, this class is implemented using FindFirstChangeNotification()/FindNextChangeNotification(). On Linux, this class is implemented using inotify. On FreeBSD and Darwin (Mac OS X, iOS), this class uses kevent/kqueue. On all other platforms, the watched directory is periodically scanned for changes. This can negatively affect performance if done too often. Therefore, the interval in which scans are done can be specified in the constructor. Note that periodic scanning will also be done on FreeBSD and Darwin if events for changes to files (DW_ITEM_MODIFIED) are enabled.
DW_ITEM_MOVED_FROM and DW_ITEM_MOVED_TO events will only be reported on Linux. On other platforms, a file rename or move operation will be reported via a DW_ITEM_REMOVED and a DW_ITEM_ADDED event. The order of these two events is not defined.
An event mask can be specified to enable only certain events.
Direct Base Classes: Runnable
All Base Classes: Runnable
Inherited Functions: run
Default scan interval for platforms that don't provide a native notification mechanism.
DW_FILTER_ENABLE_ALL = 31
Enables all event types.
Disables all event types.
DW_ITEM_ADDED = 1
A new item has been created and added to the directory.
DW_ITEM_REMOVED = 2
An item has been removed from the directory.
DW_ITEM_MODIFIED = 4
An item has been modified.
An item has been renamed or moved. This event delivers the old name.
DW_ITEM_MOVED_TO = 16
An item has been renamed or moved. This event delivers the new name.
const std::string & path,
int eventMask = DW_FILTER_ENABLE_ALL,
int scanInterval = DW_DEFAULT_SCAN_INTERVAL
Creates a DirectoryWatcher for the directory given in path. To enable only specific events, an eventMask can be specified by OR-ing the desired event IDs (e.g., DW_ITEM_ADDED | DW_ITEM_MODIFIED). On platforms where no native filesystem notifications are available, scanInterval specifies the interval in seconds between scans of the directory.
Creates a DirectoryWatcher for the specified directory To enable only specific events, an eventMask can be specified by OR-ing the desired event IDs (e.g., DW_ITEM_ADDED | DW_ITEM_MODIFIED). On platforms where no native filesystem notifications are available, scanInterval specifies the interval in seconds between scans of the directory.
Destroys the DirectoryWatcher.
const File & directory() const;
Returns the directory being watched.
int eventMask() const;
Returns the value of the eventMask passed to the constructor.
bool eventsSuspended() const;
Returns true if and only if events are suspended.
Resumes events, after they have been suspended with a call to suspendEvents().
int scanInterval() const;
Returns the scan interval in seconds.
bool supportsMoveEvents() const;
Suspends sending of events. Can be called multiple times, but every call to suspendEvent() must be matched by a call to resumeEvents().
See also: Poco::Runnable::run()
Fired when a file or directory has been created or added to the directory.
Fired when a file or directory has been modified.
Fired when a file or directory has been renamed. This event delivers the old name.
Fired when a file or directory has been moved. This event delivers the new name.
Fired when a file or directory has been removed from the directory.
Fired when an error occurs while scanning for changes.