I have finally gotten to factoring all of the file event handing code from the task class with the creation of the CFileApprise class. This is similar to the old Task class except it can generate a number of events beyond just file added. It now supports the following
- Event_add – File added to watched folder hierarchy
- Event_change – File changed
- Event_unlink – File deleted from watched folder hierarchy
- Event_addir – Directory added to watched folder hierarchy
- Event_unlinkdir – Directory deleted from watched folder hierarchy
- Event_error – Exception error
with each event having the following entries in its structure
- event id
- full path and name of file that created event
The main class constructor still has a central watch folder from which any addition / removal of a directory results automatically in a new watch being created or removed. There is now a secondary constructor which only takes an options parameter which allows watches to be manually added and removed for files /directories. At present any directories added still have the recursive behavior for the handling of watches but this constructor is intended for full manual and it is intended to remove this.
The Task class (renamed CFileTask) has thinned dramatically and when created it uses a CFileApprise object on a separate thread and loops waiting for Event_add events and then calling the task action function for it. It should be noted that the class still has the same interfaces and functionality as before but the file event handling as mentioned above has moved to CFileApprise.
Now that all of the inotify code is contained within CFileApprise this make porting the FPE and CFileTask to other platforms a lot easier and is the intention in the near future. Not having access to a Macintosh these days then a Windows version will probably be looked at first.
The current state of the above classes and their source can be found at my GitHub here