Refactoring The Task Class.

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

  1. Event_add –  File added to watched folder hierarchy
  2. Event_change –  File changed
  3. Event_unlink –  File deleted from watched folder hierarchy
  4. Event_addir – Directory added to watched folder hierarchy
  5. Event_unlinkdir – Directory deleted from watched folder hierarchy
  6. 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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s