Hey i got code for this running on linux and windows, but i for mac i need some folk to test what i worked out from Apple reference of FSevent API.
i’ve coded it blindly (it was better than trying to start xcode on my G4 !!) so i don’t know if it will even compile straight away.
For now the class is only 2 files with all the platform specific code inside (to ease testing), but probably we should make an own specific platform file after we work out all the lacking code for the mac.
On linux it uses inotify (tha powa!!) and a thread that poll a file descriptor with a specific timeout. Fast and slick to write and test.
On windows i used ReadDirectoryChangeW that is the only way to know which file is changed, as FindFirstChangeNotification works only for folders and you don’t know exactly what changed inside them. Actually this limitation forces you to monitor the whole parent directory when you want to be notified of a single file change, and check if any of the changes you have in that directory is actually one of the files you want to be notified.
Anyway It uses asynchronous IO with OVERLAPPED read / write (it took me some gray hairs before getting it to work!), so we achieve a similar approach to the linux file descriptor based implementation.
The mac code is a starting point only, it create a stream and teach it to monitor a set of files, then a callback will be triggered. From what i read in the docs, there is no way to add files to the stream unless you stop and start a new stream, but probably this has to be tested and tweaked.
This class is pretty simple but powerful to use. An example:
class MyClass : public FileChangeListener
watcher = new FileChangeWatcher();
watcher->addFile (File ("/home/kraken/Desktop/"));
void fileChangedCallback(const File& file)
std::cout << "File " << file.getFullPathName().toUTF8() << " has changed !" << std::endl;