DirectoryWatcher Class Reference
A class that watches for changes in a given directory.
More...
#include <DirectoryWatcher.h++>
List of all members.
Public Member Functions |
| virtual | ~DirectoryWatcher () throw () |
| | Destructor.
|
| void | init () throw (SystemException) |
| | Initialize the watcher.
|
| virtual void | start () throw () |
| | Start executing the thread.
|
| virtual void | stop () throw () |
| | Stop execution of the thread.
|
| bool | join () throw () |
| | Wait for the thread to terminate.
|
| bool | isRunning () const throw () |
| | Test if the thread is currently running.
|
| bool | isDetached () const throw () |
| | Test if the thread is detached.
|
| void | setPriority (Priority priority) throw () |
| | Set the thread priority.
|
| Priority | getPriority () const throw () |
| | Get the thread priority.
|
| void | setName (const String &name) throw () |
| | Set the name of this thread.
|
| String | getName () const throw () |
| | Get the name of this thread.
|
Static Public Member Functions |
| static void | sleep (timespan_ms_t msec) throw () |
| | Suspend the calling thread for the given time interval.
|
| static Thread * | currentThread () |
| | Obtain a pointer to the Thread object for the calling thread.
|
| static ThreadID | currentThreadID () throw () |
| | Get the calling thread's thread ID.
|
Protected Member Functions |
| | DirectoryWatcher (const String &directory) |
| | Construct a new DirectoryWatcher that will watch the specified directory.
|
| void | run () |
| | Main function.
|
| virtual void | fileCreated (const String &path)=0 |
| | Called when a file is created in the watched directory.
|
| virtual void | fileDeleted (const String &path)=0 |
| | Called when a file is deleted in the watched directory.
|
| virtual void | fileModified (const String &path)=0 |
| | Called when a file is modified in the watched directory.
|
| virtual void | fileRenamed (const String &oldPath, const String &newPath)=0 |
| | Called when a file is renamed in the watched directory.
|
| virtual void | cleanup () |
| | Cleanup function.
|
| bool | trySleep (timespan_ms_t msec) throw () |
| | Suspend the thread for the given time interval, returning early if the thread was cancelled via a call to stop().
|
| bool | testCancel () throw () |
| | Test for asynchronous cancellation requests.
|
| void | yield () throw () |
| | Yield the CPU to (potentially) another thread.
|
Static Protected Member Functions |
| static void | exit () throw () |
| | Exit (terminate) the calling thread.
|
Detailed Description
A class that watches for changes in a given directory.
When a file within the watched directory is created, deleted, modified, or renamed, the corresponding handler method is called. This is an abstract class which must be subclassed to implement the handler methods. A watcher must run in its own thread.
NOTE: This class is currently not implemented on Mac OS X.
- Author:
- Mark Lindner
Constructor & Destructor Documentation
Construct a new DirectoryWatcher that will watch the specified directory.
- Parameters:
-
| directory | The directory to watch. |
Member Function Documentation
| void cleanup |
( |
|
) |
[protected, virtual, inherited] |
Cleanup function.
This function will be executed by the thread just prior to termination. The default implementation is a no-op.
Reimplemented in PulseTimer, and SocketMuxer.
| Thread * currentThread |
( |
|
) |
[static, inherited] |
Obtain a pointer to the Thread object for the calling thread.
If the calling thread is the main thread, or some other thread that was not created via commonc++, a NULL pointer is returned. Never delete the object returned by this method.
Get the calling thread's thread ID.
| void exit |
( |
|
) |
throw () [static, protected, inherited] |
Exit (terminate) the calling thread.
| virtual void fileCreated |
( |
const String & |
path |
) |
[protected, pure virtual] |
Called when a file is created in the watched directory.
- Parameters:
-
| path | The path (relative to the watched directory) of the new file. |
| virtual void fileDeleted |
( |
const String & |
path |
) |
[protected, pure virtual] |
Called when a file is deleted in the watched directory.
- Parameters:
-
| path | The path (relative to the watched directory) of the deleted file. |
| virtual void fileModified |
( |
const String & |
path |
) |
[protected, pure virtual] |
Called when a file is modified in the watched directory.
- Parameters:
-
| path | The path (relative to the watched directory) of the modified file. |
| virtual void fileRenamed |
( |
const String & |
oldPath, |
|
|
const String & |
newPath | |
|
) |
| | [protected, pure virtual] |
Called when a file is renamed in the watched directory.
- Parameters:
-
| oldPath | The old path (relative to the watched directory) of the renamed file. |
| newPath | The new path (relative to the watched directory) of the renamed file. |
| String getName |
( |
|
) |
const throw () [inline, inherited] |
Get the name of this thread.
| Priority getPriority |
( |
|
) |
const throw () [inherited] |
Initialize the watcher.
- Exceptions:
-
| bool isDetached |
( |
|
) |
const throw () [inline, inherited] |
Test if the thread is detached.
| bool isRunning |
( |
|
) |
const throw () [inherited] |
Test if the thread is currently running.
| bool join |
( |
|
) |
throw () [inherited] |
Wait for the thread to terminate.
- Returns:
- true if the join was successful, false otherwise. Note that threads which were created in a detached state are not joinable.
| void run |
( |
|
) |
[protected, virtual] |
Main function.
Thread execution begins in this function. The default implementation does nothing.
Reimplemented from Thread.
| void setName |
( |
const String & |
name |
) |
throw () [inline, inherited] |
Set the name of this thread.
| void setPriority |
( |
Priority |
priority |
) |
throw () [inherited] |
Suspend the calling thread for the given time interval.
- Parameters:
-
| msec | The number of milliseconds to sleep. |
| void start |
( |
|
) |
throw () [virtual, inherited] |
Start executing the thread.
If a Runnable object was supplied in the constructor, its run() method is invoked; otherwise the thread object's run() method is called. If the thread is already running, the call has no effect.
| void stop |
( |
|
) |
throw () [virtual, inherited] |
Stop execution of the thread.
The thread is not forcibly killed; instead, an asynchronous cancellation request is posted to the thread. If the thread is not running, the call has no effect.
| bool testCancel |
( |
|
) |
throw () [protected, inherited] |
Test for asynchronous cancellation requests.
- Returns:
- true If a cancellation request has been posted to the calling thread.
| bool trySleep |
( |
timespan_ms_t |
msec |
) |
throw () [protected, inherited] |
Suspend the thread for the given time interval, returning early if the thread was cancelled via a call to stop().
- Parameters:
-
| msec | The number of milliseconds to sleep. |
- Returns:
- true if the full interval elapsed, false if the thread was cancelled during the sleep.
| void yield |
( |
|
) |
throw () [protected, inherited] |
Yield the CPU to (potentially) another thread.
The documentation for this class was generated from the following files: