Browse Source

Add media type struct and make use of it in the media server

master
Krisjanis Rijnieks 11 years ago
parent
commit
fbc15943ad
  1. 17
      src/MediaServer/DirectoryWatcher.cpp
  2. 18
      src/MediaServer/DirectoryWatcher.h
  3. 6
      src/MediaServer/MediaServer.cpp
  4. 1
      src/MediaServer/MediaServer.h

17
src/MediaServer/DirectoryWatcher.cpp

@ -10,18 +10,21 @@
namespace ofx {
namespace piMapper {
DirectoryWatcher::DirectoryWatcher(std::string path, bool video) {
if (video) {
DirectoryWatcher::DirectoryWatcher(std::string path, int watcherMediaType) {
mediaType = watcherMediaType;
// Decide what filter we need depending on media type
if (mediaType == MediaType::MEDIA_TYPE_VIDEO) {
filter = new VideoPathFilter();
} else {
} else if (mediaType == MediaType::MEDIA_TYPE_IMAGE) {
filter = new ImagePathFilter();
} else {
ofLogFatalError("DirectoryWatcher::DirectoryWatcher", "Unkonwn media type");
std::exit(EXIT_FAILURE);
}
dirWatcher.registerAllEvents(this);
// For some reason the filters are not working,
// we leave just the path here and do the filter logic in the listeners
dirWatcher.addPath(path);
// Initial directory listing. Fill the file paths vector.
IO::DirectoryUtils::list(path, filePaths, true, filter);
}
@ -35,5 +38,9 @@ namespace ofx {
return filePaths;
}
int DirectoryWatcher::getMediaType() {
return mediaType;
}
} // namespace piMapper
} // namespace ofx

18
src/MediaServer/DirectoryWatcher.h

@ -10,6 +10,7 @@
#include "ofMain.h"
#include "ofxIO.h"
#include "MediaType.h"
namespace ofx {
namespace piMapper {
@ -26,7 +27,6 @@ class VideoPathFilter : public BasePathFilter {
VideoPathFilter() {};
virtual ~VideoPathFilter() {};
// TODO: Find useful filters e.g. *.mp4, etc
bool accept(const Poco::Path& path) const {
return !Poco::File(path).isHidden() &&
(ofIsStringInString(path.toString(), ".mp4") ||
@ -39,7 +39,6 @@ class ImagePathFilter : public BasePathFilter {
ImagePathFilter() {};
virtual ~ImagePathFilter() {};
// TODO: Find useful filters e.g. *.png,*.jpeg, etc.
bool accept(const Poco::Path& path) const {
return !Poco::File(path).isHidden() &&
(ofIsStringInString(path.toString(), ".png") ||
@ -50,7 +49,7 @@ class ImagePathFilter : public BasePathFilter {
class DirectoryWatcher {
public:
DirectoryWatcher(std::string path, bool video);
DirectoryWatcher(std::string path, int watcherMediaType);
~DirectoryWatcher();
// TODO make useful stuff with onDirectoryWatcher*
@ -58,11 +57,9 @@ class DirectoryWatcher {
const ofx::IO::DirectoryWatcherManager::DirectoryEvent& evt) {
string path = evt.item.path();
Poco::Path pocoPath = Poco::Path(path);
if (!filter->accept(pocoPath)) {
return;
}
filePaths.push_back(path);
ofNotifyEvent(onItemAdded, path, this);
}
@ -71,11 +68,9 @@ class DirectoryWatcher {
const ofx::IO::DirectoryWatcherManager::DirectoryEvent& evt) {
string path = evt.item.path();
Poco::Path pocoPath = Poco::Path(path);
if (!filter->accept(pocoPath)) {
return;
}
// Remove path from vector
for (int i = 0; i < filePaths.size(); i++) {
if (path == filePaths[i]) {
@ -83,7 +78,6 @@ class DirectoryWatcher {
break;
}
}
ofNotifyEvent(onItemRemoved, path, this);
}
@ -91,11 +85,9 @@ class DirectoryWatcher {
const ofx::IO::DirectoryWatcherManager::DirectoryEvent& evt) {
string path = evt.item.path();
Poco::Path pocoPath = Poco::Path(path);
if (!filter->accept(pocoPath)) {
return;
}
ofNotifyEvent(onItemModified, path, this);
}
@ -103,11 +95,9 @@ class DirectoryWatcher {
const ofx::IO::DirectoryWatcherManager::DirectoryEvent& evt) {
string path = evt.item.path();
Poco::Path pocoPath = Poco::Path(path);
if (!filter->accept(pocoPath)) {
return;
}
ofLogNotice("ofApp::onDirectoryWatcherItemMovedFrom")
<< "Moved From: " << path;
ofNotifyEvent(onItemMovedFrom, path, this);
@ -117,11 +107,9 @@ class DirectoryWatcher {
const ofx::IO::DirectoryWatcherManager::DirectoryEvent& evt) {
string path = evt.item.path();
Poco::Path pocoPath = Poco::Path(path);
if (!filter->accept(pocoPath)) {
return;
}
ofLogNotice("ofApp::onDirectoryWatcherItemMovedTo")
<< "Moved To: " << path;
ofNotifyEvent(onItemMovedTo, path, this);
@ -134,6 +122,7 @@ class DirectoryWatcher {
// Getters
std::vector<std::string>& getFilePaths();
int getMediaType();
// Custom events
ofEvent<string> onItemAdded;
@ -146,6 +135,7 @@ class DirectoryWatcher {
ofx::IO::DirectoryWatcherManager dirWatcher;
BasePathFilter* filter;
std::vector<std::string> filePaths;
int mediaType;
};
}
}

6
src/MediaServer/MediaServer.cpp

@ -12,9 +12,9 @@ namespace ofx {
namespace piMapper {
MediaServer::MediaServer():
videoWatcher(ofToDataPath(DEFAULT_VIDEOS_DIR, true), true),
imageWatcher(ofToDataPath(DEFAULT_IMAGES_DIR, true), false) {
addWatcherListeners();
videoWatcher(ofToDataPath(DEFAULT_VIDEOS_DIR, true), MediaType::MEDIA_TYPE_VIDEO),
imageWatcher(ofToDataPath(DEFAULT_IMAGES_DIR, true), MediaType::MEDIA_TYPE_IMAGE) {
addWatcherListeners();
}
MediaServer::~MediaServer() {

1
src/MediaServer/MediaServer.h

@ -10,6 +10,7 @@
#include "ofMain.h"
#include "DirectoryWatcher.h"
#include "MediaType.h"
#define DEFAULT_IMAGES_DIR "sources/images/"
#define DEFAULT_VIDEOS_DIR "sources/videos/"

Loading…
Cancel
Save