Browse Source

added DrectoryWatchers for video and image

master
Felix Dubrownik 11 years ago
parent
commit
05ee627759
  1. 22
      src/MediaServer.cpp
  2. 23
      src/MediaServer/DirectoryWatcher.cpp
  3. 42
      src/MediaServer/DirectoryWatcher.h
  4. 23
      src/MediaServer/MediaServer.cpp
  5. 35
      src/MediaServer/MediaServer.h

22
src/MediaServer.cpp

@ -1,22 +0,0 @@
//
// MediaServer.cpp
// example
//
// Created by felix on 13.09.14.
//
//
#include "MediaServer.h"
namespace ofx {
namespace piMapper {
MediaServer::MediaServer() {
videoWatcher.registerAllEvents(this);
videoWatcher.addPath(ofToDataPath(DEFAULT_VIDEOS_DIR, true), true,
&videoFileFilter);
imageWatcher.registerAllEvents(this);
imageWatcher.addPath(ofToDataPath(DEFAULT_IMAGES_DIR, true), true,
&imageFileFilter);
}
}
}

23
src/MediaServer/DirectoryWatcher.cpp

@ -0,0 +1,23 @@
//
// DirectoryWatcher.cpp
// example
//
// Created by felix on 23.09.14.
//
//
#include "DirectoryWatcher.h"
namespace ofx {
namespace piMapper {
DirectoryWatcher::DirectoryWatcher(std::string path, bool video) {
if (video) {
filter = CustomVideoPathFilter();
} else {
filter = CustomImagePathFilter();
}
dirWatcher.registerAllEvents(this);
dirWatcher.addPath(path, true, &filter);
}
}
}

42
src/MediaServer.h → src/MediaServer/DirectoryWatcher.h

@ -1,8 +1,8 @@
//
// MediaServer.h
// DirectoryWatcher.h
// example
//
// Created by felix on 13.09.14.
// Created by felix on 23.09.14.
//
//
@ -11,39 +11,46 @@
#include "ofMain.h"
#include "ofxIO.h"
#define DEFAULT_IMAGES_DIR "sources/images/"
#define DEFAULT_VIDEOS_DIR "sources/videos/"
namespace ofx {
namespace piMapper {
class CustomVideoPathFilter : public ofx::IO::AbstractPathFilter {
class CustomPathFilter : public ofx::IO::AbstractPathFilter {
public:
CustomPathFilter() {};
virtual ~CustomPathFilter() {};
virtual bool accept(const Poco::Path& path) const;
};
class CustomVideoPathFilter : public CustomPathFilter {
public:
CustomVideoPathFilter() {};
virtual ~CustomVideoPathFilter() {};
// TODO: Find useful filters e.g. *.mp4, etc
bool const accept(Poco::Path& path) const {
bool accept(const Poco::Path& path) const {
return !Poco::File(path).isHidden() &&
ofIsStringInString(path.toString(), "mp4");
}
};
class CustomImagePathFilter : public ofx::IO::AbstractPathFilter {
class CustomImagePathFilter : public CustomPathFilter {
public:
CustomImagePathFilter() {};
virtual ~CustomImagePathFilter() {};
// TODO: Find useful filters e.g. *.png,*.jpeg, etc.
bool const accept(Poco::Path& path) const {
bool accept(const Poco::Path& path) const {
return !Poco::File(path).isHidden() &&
ofIsStringInString(path.toString(), "png");
}
};
class MediaServer {
class DirectoryWatcher {
public:
MediaServer();
DirectoryWatcher(std::string path, bool video);
// TODO make useful stuff with onDirectoryWatcher*
void onDirectoryWatcherItemAdded(
const ofx::IO::DirectoryWatcherManager::DirectoryEvent& evt) {
ofSendMessage("Added: " + evt.item.path());
filePaths.push_back(evt.item.path());
}
void onDirectoryWatcherItemRemoved(
@ -73,14 +80,11 @@ class MediaServer {
<< "Error: " << exc.displayText();
}
private:
// Video
ofx::IO::DirectoryWatcherManager videoWatcher;
ofx::IO::HiddenFileFilter videoFileFilter;
std::vector<std::string> filePaths;
// Images
ofx::IO::DirectoryWatcherManager imageWatcher;
ofx::IO::HiddenFileFilter imageFileFilter;
private:
ofx::IO::DirectoryWatcherManager dirWatcher;
CustomPathFilter filter;
};
}
}
}

23
src/MediaServer/MediaServer.cpp

@ -0,0 +1,23 @@
//
// MediaServer.cpp
// example
//
// Created by felix on 13.09.14.
//
//
#include "MediaServer.h"
namespace ofx {
namespace piMapper {
MediaServer::MediaServer()
: videoWatcher(ofToDataPath(DEFAULT_VIDEOS_DIR, true), true),
imageWatcher(ofToDataPath(DEFAULT_IMAGES_DIR, true), false) {}
MediaServer::~MediaServer() {};
int MediaServer::getNumImages() { return imageWatcher.filePaths.size(); }
int MediaServer::getNumVideos() { return videoWatcher.filePaths.size(); }
}
}

35
src/MediaServer/MediaServer.h

@ -0,0 +1,35 @@
//
// MediaServer.h
// example
//
// Created by felix on 13.09.14.
//
//
#pragma once
#include "ofMain.h"
#include "DirectoryWatcher.h"
#define DEFAULT_IMAGES_DIR "sources/images/"
#define DEFAULT_VIDEOS_DIR "sources/videos/"
namespace ofx {
namespace piMapper {
class MediaServer {
public:
MediaServer();
virtual ~MediaServer();
int getNumVideos();
int getNumImages();
private:
// Video
ofx::piMapper::DirectoryWatcher videoWatcher;
// Images
ofx::piMapper::DirectoryWatcher imageWatcher;
};
}
}
Loading…
Cancel
Save