diff --git a/.gitignore b/.gitignore
index 3b590fa..8cd07bf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -113,3 +113,9 @@ example/\.idea/
example/cmake-build-release/
example/example\.xcodeproj/xcshareddata/xcschemes/
+
+.idea/
+
+cmake-build-debug/
+
+CMakeLists\.txt
diff --git a/example/bin/data/ofxpimapper.xml b/example/bin/data/ofxpimapper.xml
index 553ca20..46b5816 100644
--- a/example/bin/data/ofxpimapper.xml
+++ b/example/bin/data/ofxpimapper.xml
@@ -73,6 +73,17 @@
fbo
Slide Show Source
+
+ 1920
+ 1080
+ 1
+
+ PING-PONG
+
+
+
+ FitProportionally
+
1
diff --git a/src/MediaServer/DirectoryWatcher.cpp b/src/MediaServer/DirectoryWatcher.cpp
index 3c86543..14f697d 100644
--- a/src/MediaServer/DirectoryWatcher.cpp
+++ b/src/MediaServer/DirectoryWatcher.cpp
@@ -4,8 +4,9 @@ namespace ofx {
namespace piMapper {
DirectoryWatcher::DirectoryWatcher(string path, int watcherMediaType){
+ directoryPath = path;
_mediaType = watcherMediaType;
-
+
if(_mediaType == SourceType::SOURCE_TYPE_VIDEO){
_directory.allowExt("mp4");
_directory.allowExt("h264");
@@ -21,20 +22,27 @@ DirectoryWatcher::DirectoryWatcher(string path, int watcherMediaType){
ofLogFatalError("DirectoryWatcher::DirectoryWatcher", "Unkonwn media type");
exit(EXIT_FAILURE);
}
-
- _directory.listDir(path);
+
+ _directory.listDir(directoryPath);
_directory.sort();
-
+
for(int i = 0; i < _directory.size(); ++i){
- _filePaths.push_back(path + _directory.getName(i));
-
- ofFile file(path + _directory.getName(i));
+ _filePaths.push_back(directoryPath + _directory.getName(i));
+
+ ofFile file(directoryPath + _directory.getName(i));
if(_mediaType == SourceType::SOURCE_TYPE_VIDEO){
file.copyTo("sources/videos/" + _directory.getName(i));
}else if(_mediaType == SourceType::SOURCE_TYPE_IMAGE){
file.copyTo("sources/images/" + _directory.getName(i));
}
}
+
+ dirSize = _directory.size();
+}
+
+DirectoryWatcher::~DirectoryWatcher() {
+ endWatch();
+// waitForThread(false);
}
vector & DirectoryWatcher::getFilePaths(){
@@ -45,5 +53,28 @@ int DirectoryWatcher::getMediaType(){
return _mediaType;
}
+void DirectoryWatcher::beginWatch(int intervalInMillis) {
+ watchInterval = intervalInMillis;
+ startThread();
+}
+
+void DirectoryWatcher::endWatch() {
+ stopThread();
+}
+
+void DirectoryWatcher::threadedFunction() {
+
+ while (isThreadRunning()) {
+
+ int newSize = _directory.listDir();
+ if (newSize != dirSize) {
+ ofLogVerbose("DirectoryWatcher") << "Directory changed";
+ ofNotifyEvent(directoryFileCountChangedEvent, this);
+ }
+
+ sleep(watchInterval);
+ }
+}
+
} // namespace piMapper
} // namespace ofx
diff --git a/src/MediaServer/DirectoryWatcher.h b/src/MediaServer/DirectoryWatcher.h
index 717bbde..bcd3879 100644
--- a/src/MediaServer/DirectoryWatcher.h
+++ b/src/MediaServer/DirectoryWatcher.h
@@ -6,16 +6,32 @@
namespace ofx {
namespace piMapper {
-class DirectoryWatcher {
+class DirectoryWatcher : public ofThread {
public:
DirectoryWatcher(string path, int watcherMediaType);
+ virtual ~DirectoryWatcher();
vector & getFilePaths();
int getMediaType();
+ void beginWatch(int intervalInMillis = 5000);
+ void endWatch();
+ void threadedFunction();
+
+ /**
+ * Triggered when the file count of a directory increases
+ * or decreases.
+ *
+ * Sender is a pointer to this DirectoryWatcher
+ */
+ ofEvent directoryFileCountChangedEvent;
private:
ofDirectory _directory;
vector _filePaths;
+ std::string directoryPath;
int _mediaType;
+
+ int dirSize;
+ long watchInterval; // in millis.
};
} // namespace piMapper
diff --git a/src/MediaServer/MediaServer.cpp b/src/MediaServer/MediaServer.cpp
index 78d1af8..41b1747 100644
--- a/src/MediaServer/MediaServer.cpp
+++ b/src/MediaServer/MediaServer.cpp
@@ -19,14 +19,17 @@ MediaServer::MediaServer():
{
// By initialising all above we also copy files from external media
// to the ofxPiMapper storage.
-
- imageWatcher = DirectoryWatcher(
- ofToDataPath(DEFAULT_IMAGES_DIR, true),
- SourceType::SOURCE_TYPE_IMAGE);
-
- videoWatcher = DirectoryWatcher(
- ofToDataPath(DEFAULT_VIDEOS_DIR, true),
- SourceType::SOURCE_TYPE_VIDEO);
+ imageWatcher.beginWatch();
+
+
+// imageWatcher = DirectoryWatcher(
+// ofToDataPath(DEFAULT_IMAGES_DIR, true),
+// SourceType::SOURCE_TYPE_IMAGE);
+// imageWatcher.beginWatch();
+//
+// videoWatcher = DirectoryWatcher(
+// ofToDataPath(DEFAULT_VIDEOS_DIR, true),
+// SourceType::SOURCE_TYPE_VIDEO);
}
void MediaServer::setup(){