Browse Source

Merge branch 'DirectoryWatcher'

master
c-mendoza 8 years ago
parent
commit
ae75eb62b5
  1. 6
      .gitignore
  2. 11
      example/bin/data/ofxpimapper.xml
  3. 45
      src/MediaServer/DirectoryWatcher.cpp
  4. 18
      src/MediaServer/DirectoryWatcher.h
  5. 19
      src/MediaServer/MediaServer.cpp

6
.gitignore

@ -113,3 +113,9 @@ example/\.idea/
example/cmake-build-release/
example/example\.xcodeproj/xcshareddata/xcschemes/
.idea/
cmake-build-debug/
CMakeLists\.txt

11
example/bin/data/ofxpimapper.xml

@ -73,6 +73,17 @@
<source>
<source-type>fbo</source-type>
<source-name>Slide Show Source</source-name>
<magSlideShow>
<Width>1920</Width>
<Height>1080</Height>
<SlideDuration>1</SlideDuration> <!-- Optional default duration for each slide-->
<Loop>
<Type>PING-PONG</Type> <!-- NONE | NORMAL | PING-PONG -->
</Loop>
<Transition></Transition>
<!-- NoResize | Native | Fit | FitProportionally | FillProportionally -->
<ResizeOption>FitProportionally</ResizeOption>
</magSlideShow>
</source>
<properties>
<perspectiveWarping>1</perspectiveWarping>

45
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 <string> & 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

18
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<string> & 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<void> directoryFileCountChangedEvent;
private:
ofDirectory _directory;
vector<string> _filePaths;
std::string directoryPath;
int _mediaType;
int dirSize;
long watchInterval; // in millis.
};
} // namespace piMapper

19
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(){

Loading…
Cancel
Save