diff --git a/TODO b/TODO index 1240118f..30e53f6b 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,7 @@ +[ServiceManager] +- Rework the whole start/stop/try/cach/thread/interrupts things + [Users] - Do the feature - Admin account to add/remove users, add path to watch for Audio/Video files diff --git a/database/Database.cpp b/database/Database.cpp index 785fdb3a..f3db0ee5 100644 --- a/database/Database.cpp +++ b/database/Database.cpp @@ -1,6 +1,7 @@ #include #include +#include #include "Database.hpp" #include "Checksum.hpp" @@ -240,6 +241,8 @@ Database::refreshAudioDirectory( const boost::filesystem::path& p) BOOST_FOREACH(const boost::filesystem::path& file, files) { + boost::this_thread::interruption_point(); + try { if (boost::filesystem::is_directory(file)) { refreshAudioDirectory( file ); diff --git a/main/DatabaseRefreshService.cpp b/main/DatabaseRefreshService.cpp index 4403197b..b5a5fe97 100644 --- a/main/DatabaseRefreshService.cpp +++ b/main/DatabaseRefreshService.cpp @@ -6,27 +6,26 @@ DatabaseRefreshService::DatabaseRefreshService(boost::asio::io_service& ioServic : _metadataParser(), _database( p, _metadataParser) { - // TODO read from the database itself! // Move this code in the database class _database.watchDirectory( WatchedDirectory("/storage/common/Media/Son/Metal", WatchedDirectory::Audio) ); _database.watchDirectory( WatchedDirectory("/storage/common/Media/Video", WatchedDirectory::Video) ); - // TODO launch thread - boost::thread refreshThread(boost::bind(&Database::refresh, &_database)); } void DatabaseRefreshService::start(void) { - std::cout << "DatabaseRefreshService::start, not implemented" << std::endl; - +// _thread = boost::thread(boost::bind(&Database::refresh, &_database)); } void DatabaseRefreshService::stop(void) { - std::cout << "DatabaseRefreshService::stop, not implemented" << std::endl; + std::cout << "DatabaseRefreshService::stop, processing..." << std::endl; + _thread.interrupt(); + _thread.join(); + std::cout << "DatabaseRefreshService::stop, process done" << std::endl; } void diff --git a/main/DatabaseRefreshService.hpp b/main/DatabaseRefreshService.hpp index 8ad8295f..b35f5cd9 100644 --- a/main/DatabaseRefreshService.hpp +++ b/main/DatabaseRefreshService.hpp @@ -1,6 +1,7 @@ #ifndef DB_REFRESH_SERVICE_HPP #define DB_REFRESH_SERVICE_HPP +#include #include #include "metadata/AvFormat.hpp" @@ -20,6 +21,8 @@ class DatabaseRefreshService : public Service private: + boost::thread _thread; + MetaData::AvFormat _metadataParser; Database _database; }; diff --git a/main/ServiceManager.cpp b/main/ServiceManager.cpp index 2f41a9c6..e7edebe9 100644 --- a/main/ServiceManager.cpp +++ b/main/ServiceManager.cpp @@ -18,6 +18,11 @@ ServiceManager::ServiceManager() _signalSet.add(SIGHUP); } +ServiceManager::~ServiceManager() +{ + stopServices(); +} + void ServiceManager::run() { @@ -25,8 +30,15 @@ ServiceManager::run() asyncWaitSignals(); std::cout << "ServiceManager::run Waiting for events..." << std::endl; - // Wait for events - _ioService.run(); + try { + // Wait for events + _ioService.run(); + } + catch( std::exception& e ) + { + std::cerr << "Caugh exception in service : " << e.what() << std::endl; + stopServices(); + } std::cout << "ServiceManager::run complete!" << std::endl; } diff --git a/main/ServiceManager.hpp b/main/ServiceManager.hpp index 4edd9ae0..b84609ce 100644 --- a/main/ServiceManager.hpp +++ b/main/ServiceManager.hpp @@ -12,10 +12,13 @@ class ServiceManager public: ServiceManager(); + ~ServiceManager(); void stopService(Service::pointer service); void startService(Service::pointer service); + void stopAllServices(); + // Return in case of failure/stop by user void run();