Browse Source

Add event handlers to video and image wathcher add and remove events

master
Krisjanis Rijnieks 11 years ago
parent
commit
32e3e15ded
  1. 61
      src/MediaServer/MediaServer.cpp
  2. 31
      src/MediaServer/MediaServer.h

61
src/MediaServer/MediaServer.cpp

@ -11,20 +11,53 @@
namespace ofx {
namespace piMapper {
MediaServer::MediaServer()
: videoWatcher(ofToDataPath(DEFAULT_VIDEOS_DIR, true), true),
imageWatcher(ofToDataPath(DEFAULT_IMAGES_DIR, true), false) {}
MediaServer::MediaServer():
videoWatcher(ofToDataPath(DEFAULT_VIDEOS_DIR, true), true),
imageWatcher(ofToDataPath(DEFAULT_IMAGES_DIR, true), false) {
addWatcherListeners();
}
MediaServer::~MediaServer() {};
MediaServer::~MediaServer() {
removeWatcherListeners();
};
int MediaServer::getNumImages() { return imageWatcher.getFilePaths().size(); }
int MediaServer::getNumVideos() { return videoWatcher.getFilePaths().size(); }
int MediaServer::getNumImages() { return imageWatcher.getFilePaths().size(); }
int MediaServer::getNumVideos() { return videoWatcher.getFilePaths().size(); }
std::vector<std::string>& MediaServer::getImagePaths() {
return imageWatcher.getFilePaths();
}
std::vector<std::string>& MediaServer::getVideoPaths() {
return videoWatcher.getFilePaths();
}
}
}
std::vector<std::string>& MediaServer::getImagePaths() {
return imageWatcher.getFilePaths();
}
std::vector<std::string>& MediaServer::getVideoPaths() {
return videoWatcher.getFilePaths();
}
void MediaServer::onImageAdded(string& path) {
cout << "onImageAdded: " << path << endl;
}
void MediaServer::onImageRemoved(string& path) {
cout << "onImageRemoved: " << path << endl;
}
void MediaServer::onVideoAdded(string& path) {
cout << "onVideoAdded: " << path << endl;
}
void MediaServer::onVideoRemoved(string& path) {
cout << "onVideoRemoved: " << path << endl;
}
void MediaServer::addWatcherListeners() {
ofAddListener(imageWatcher.onItemAdded, this, &MediaServer::onImageAdded);
ofAddListener(imageWatcher.onItemRemoved, this, &MediaServer::onImageRemoved);
ofAddListener(videoWatcher.onItemAdded, this, &MediaServer::onVideoAdded);
ofAddListener(videoWatcher.onItemRemoved, this, &MediaServer::onVideoRemoved);
}
void MediaServer::removeWatcherListeners() {
ofRemoveListener(imageWatcher.onItemAdded, this, &MediaServer::onImageAdded);
ofRemoveListener(imageWatcher.onItemRemoved, this, &MediaServer::onImageRemoved);
ofRemoveListener(videoWatcher.onItemAdded, this, &MediaServer::onVideoAdded);
ofRemoveListener(videoWatcher.onItemRemoved, this, &MediaServer::onVideoRemoved);
}
} // namespace piMapper
} // namespace ofx

31
src/MediaServer/MediaServer.h

@ -34,6 +34,33 @@ class MediaServer {
// Directory Watchers
ofx::piMapper::DirectoryWatcher videoWatcher;
ofx::piMapper::DirectoryWatcher imageWatcher;
// imageWatcher event listeners
void onImageAdded(string& path);
void onImageRemoved(string& path);
// TODO rest of listeners
/*
void onImageModified();
void onImageMovedFrom();
void onImageMovedTo();
*/
// videoWatcher event listeners
void onVideoAdded(string& path);
void onVideoRemoved(string& path);
// TODO rest of listeners
/*
void onVideoModified();
void onVideoMovedFrom();
void onVideoMovedTo();
*/
// Add/remove event listeners.
// Add event listeners to image and video watcher events.
void addWatcherListeners();
// Remove event listeners to image and video watcher events
void removeWatcherListeners();
};
}
}
} // namespace piMapper
} // namespace ofx

Loading…
Cancel
Save