Browse Source

DirectoryWatcher: file added and file removed events

master
c-mendoza 8 years ago
parent
commit
e231300b84
  1. 10
      src/MediaServer/DirectoryWatcher.cpp
  2. 12
      src/MediaServer/DirectoryWatcher.h

10
src/MediaServer/DirectoryWatcher.cpp

@ -67,11 +67,17 @@ void DirectoryWatcher::threadedFunction() {
while (isThreadRunning()) { while (isThreadRunning()) {
int newSize = _directory.listDir(); int newSize = _directory.listDir();
if (newSize != dirSize) { if (newSize > dirSize) {
ofLogVerbose("DirectoryWatcher") << "Directory changed"; ofLogVerbose("DirectoryWatcher") << "Directory changed";
ofNotifyEvent(directoryFileCountChangedEvent, this); dirSize = newSize;
ofNotifyEvent(directoryFileAddedEvent, this);
} else if (newSize < dirSize) {
dirSize = newSize;
ofNotifyEvent(directoryFileRemovedEvent, this);
} }
sleep(watchInterval); sleep(watchInterval);
} }
} }

12
src/MediaServer/DirectoryWatcher.h

@ -18,12 +18,16 @@ class DirectoryWatcher : public ofThread {
void threadedFunction(); void threadedFunction();
/** /**
* Triggered when the file count of a directory increases * Notifies when files are added to this directory.
* or decreases.
*
* Sender is a pointer to this DirectoryWatcher * Sender is a pointer to this DirectoryWatcher
*/ */
ofEvent<void> directoryFileCountChangedEvent; ofEvent<void> directoryFileAddedEvent;
/**
* Notifies when files are removed from this directory.
* Sender is a pointer to this DirectoryWatcher
*/
ofEvent<void> directoryFileRemovedEvent;
private: private:
ofDirectory _directory; ofDirectory _directory;
vector<string> _filePaths; vector<string> _filePaths;

Loading…
Cancel
Save