diff --git a/src/MediaServer/DirectoryWatcher.cpp b/src/MediaServer/DirectoryWatcher.cpp index 14f697d..104abcf 100644 --- a/src/MediaServer/DirectoryWatcher.cpp +++ b/src/MediaServer/DirectoryWatcher.cpp @@ -67,11 +67,17 @@ void DirectoryWatcher::threadedFunction() { while (isThreadRunning()) { int newSize = _directory.listDir(); - if (newSize != dirSize) { + if (newSize > dirSize) { ofLogVerbose("DirectoryWatcher") << "Directory changed"; - ofNotifyEvent(directoryFileCountChangedEvent, this); + dirSize = newSize; + ofNotifyEvent(directoryFileAddedEvent, this); + } else if (newSize < dirSize) { + dirSize = newSize; + ofNotifyEvent(directoryFileRemovedEvent, this); } + + sleep(watchInterval); } } diff --git a/src/MediaServer/DirectoryWatcher.h b/src/MediaServer/DirectoryWatcher.h index bcd3879..8ef7ede 100644 --- a/src/MediaServer/DirectoryWatcher.h +++ b/src/MediaServer/DirectoryWatcher.h @@ -10,7 +10,7 @@ class DirectoryWatcher : public ofThread { public: DirectoryWatcher(string path, int watcherMediaType); virtual ~DirectoryWatcher(); - vector & getFilePaths(); + vector &getFilePaths(); int getMediaType(); void beginWatch(int intervalInMillis = 5000); @@ -18,12 +18,16 @@ class DirectoryWatcher : public ofThread { void threadedFunction(); /** - * Triggered when the file count of a directory increases - * or decreases. - * + * Notifies when files are added to this directory. * Sender is a pointer to this DirectoryWatcher */ - ofEvent directoryFileCountChangedEvent; + ofEvent directoryFileAddedEvent; + /** + * Notifies when files are removed from this directory. + * Sender is a pointer to this DirectoryWatcher + */ + ofEvent directoryFileRemovedEvent; + private: ofDirectory _directory; vector _filePaths;