Qore fsevent Module  ..
Qore::FsEvents::AbstractFsWatcher Class Referenceabstract

Implementation of filesystem event watcher. More...

Public Member Methods

int addPath (string path, bool recursive=False)
 Add new path for monitoring. More...
 
 constructor ()
 Create an empty file system watcher. No directories are monitored.
 
 copy ()
 Copy method - instance of this class cannot be copied. More...
 
 destructor ()
 stops the watcher thread and destroyes the object
 
*list< string > directories ()
 Return all monitored directories. More...
 
abstract event (hash< FsEventInfo > event)
 Filesystem event handler/callback. More...
 
 removePath (int id)
 Remove a directory tree from monitoring by its id. More...
 
 removePath (string path)
 Remove a directory tree from monitoring by its name. More...
 

Detailed Description

Implementation of filesystem event watcher.

Restrictions:
Qore::PO_NO_FILESYSTEM

This is an abstract class. Developers have to inherit AbstractFsWatcher with method event() implemented.

Basic Example

%requires fsevent
class MyWatcher inherits FsEvents::AbstractFsWatcher {
event(hash<FsEventInfo> event) {
printf("FS event: %d, %s, %s, %d, %s\n", event.id, event.dir,
event.name, event.action, event.old_name);
}
}
MyWatcher w();
w.addPath('/var/log/');
while (True) {
sleep(1);
}

Member Function Documentation

◆ addPath()

int Qore::FsEvents::AbstractFsWatcher::addPath ( string  path,
bool  recursive = False 
)

Add new path for monitoring.

Parameters
patha string with path to be monitored
recursiveFalse = only the top level directory is monitored; True = all sub-directories are monitored too
Returns
an integer id of the monitored tree

The returning id can be used in AbstractFsWatcher::removePath()

◆ copy()

Qore::FsEvents::AbstractFsWatcher::copy ( )

Copy method - instance of this class cannot be copied.

Exceptions
FSWATCHER-COPY-ERROR- Copying of AbstractFsWatcher objects is not supported

◆ directories()

*list<string> Qore::FsEvents::AbstractFsWatcher::directories ( )

Return all monitored directories.

Returns
list of all registered (top-level) directories in this watcher instance or nothing if there is no directory registered

◆ event()

abstract Qore::FsEvents::AbstractFsWatcher::event ( hash< FsEventInfo event)
pure virtual

Filesystem event handler/callback.

Parameters
eventthe filesystem event hash

◆ removePath() [1/2]

Qore::FsEvents::AbstractFsWatcher::removePath ( int  id)

Remove a directory tree from monitoring by its id.

Parameters
idan integer value. Obtained by AbstractFsWatcher::addPath

This method uses a map lookup: O(ln(n))

◆ removePath() [2/2]

Qore::FsEvents::AbstractFsWatcher::removePath ( string  path)

Remove a directory tree from monitoring by its name.

Parameters
patha named path to remove

This method uses a linear search: O(n)


The documentation for this class was generated from the following file: