From 98d65a3c503d3e20795405401f9b650817ab5ad9 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Wed, 15 Oct 2014 20:05:50 +0200 Subject: [PATCH] Add event handlers for the image and video directory watcher events --- src/MediaServer/MediaServer.cpp | 30 ++++++++++++++++++------------ src/MediaServer/MediaServer.h | 13 ++++++++----- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/MediaServer/MediaServer.cpp b/src/MediaServer/MediaServer.cpp index 10298ba..a7ce6d3 100644 --- a/src/MediaServer/MediaServer.cpp +++ b/src/MediaServer/MediaServer.cpp @@ -31,32 +31,38 @@ namespace piMapper { return videoWatcher.getFilePaths(); } - void MediaServer::onImageAdded(string& path) { + void MediaServer::handleImageAdded(string& path) { cout << "onImageAdded: " << path << endl; + cout << "numImages: " << getNumImages() << endl; + ofNotifyEvent(onImageAdded, path, this); } - void MediaServer::onImageRemoved(string& path) { + void MediaServer::handleImageRemoved(string& path) { cout << "onImageRemoved: " << path << endl; + cout << "numImages: " << getNumImages() << endl; + ofNotifyEvent(onImageRemoved, path, this); } - void MediaServer::onVideoAdded(string& path) { + void MediaServer::handleVideoAdded(string& path) { cout << "onVideoAdded: " << path << endl; + ofNotifyEvent(onVideoAdded, path, this); } - void MediaServer::onVideoRemoved(string& path) { + void MediaServer::handleVideoRemoved(string& path) { cout << "onVideoRemoved: " << path << endl; + ofNotifyEvent(onVideoRemoved, path, this); } 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); + ofAddListener(imageWatcher.onItemAdded, this, &MediaServer::handleImageAdded); + ofAddListener(imageWatcher.onItemRemoved, this, &MediaServer::handleImageRemoved); + ofAddListener(videoWatcher.onItemAdded, this, &MediaServer::handleVideoAdded); + ofAddListener(videoWatcher.onItemRemoved, this, &MediaServer::handleVideoRemoved); } 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); + ofRemoveListener(imageWatcher.onItemAdded, this, &MediaServer::handleImageAdded); + ofRemoveListener(imageWatcher.onItemRemoved, this, &MediaServer::handleImageRemoved); + ofRemoveListener(videoWatcher.onItemAdded, this, &MediaServer::handleVideoAdded); + ofRemoveListener(videoWatcher.onItemRemoved, this, &MediaServer::handleVideoRemoved); } } // namespace piMapper diff --git a/src/MediaServer/MediaServer.h b/src/MediaServer/MediaServer.h index cbb39a8..3c4b7a3 100644 --- a/src/MediaServer/MediaServer.h +++ b/src/MediaServer/MediaServer.h @@ -28,7 +28,10 @@ class MediaServer { std::vector& getImagePaths(); // Custom events - //ofEvent on + ofEvent onImageAdded; + ofEvent onImageRemoved; + ofEvent onVideoAdded; + ofEvent onVideoRemoved; private: // Directory Watchers @@ -36,8 +39,8 @@ class MediaServer { ofx::piMapper::DirectoryWatcher imageWatcher; // imageWatcher event listeners - void onImageAdded(string& path); - void onImageRemoved(string& path); + void handleImageAdded(string& path); + void handleImageRemoved(string& path); // TODO rest of listeners /* void onImageModified(); @@ -46,8 +49,8 @@ class MediaServer { */ // videoWatcher event listeners - void onVideoAdded(string& path); - void onVideoRemoved(string& path); + void handleVideoAdded(string& path); + void handleVideoRemoved(string& path); // TODO rest of listeners /* void onVideoModified();