WIP, some workaround around the service manager, to be cleaned seriously later
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#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 );
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef DB_REFRESH_SERVICE_HPP
|
||||
#define DB_REFRESH_SERVICE_HPP
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
|
||||
#include "metadata/AvFormat.hpp"
|
||||
@@ -20,6 +21,8 @@ class DatabaseRefreshService : public Service
|
||||
|
||||
private:
|
||||
|
||||
boost::thread _thread;
|
||||
|
||||
MetaData::AvFormat _metadataParser;
|
||||
Database _database;
|
||||
};
|
||||
|
||||
+14
-2
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user