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]
|
[Users]
|
||||||
- Do the feature
|
- Do the feature
|
||||||
- Admin account to add/remove users, add path to watch for Audio/Video files
|
- Admin account to add/remove users, add path to watch for Audio/Video files
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
#include "Database.hpp"
|
#include "Database.hpp"
|
||||||
#include "Checksum.hpp"
|
#include "Checksum.hpp"
|
||||||
@@ -240,6 +241,8 @@ Database::refreshAudioDirectory( const boost::filesystem::path& p)
|
|||||||
|
|
||||||
BOOST_FOREACH(const boost::filesystem::path& file, files) {
|
BOOST_FOREACH(const boost::filesystem::path& file, files) {
|
||||||
|
|
||||||
|
boost::this_thread::interruption_point();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (boost::filesystem::is_directory(file)) {
|
if (boost::filesystem::is_directory(file)) {
|
||||||
refreshAudioDirectory( file );
|
refreshAudioDirectory( file );
|
||||||
|
|||||||
@@ -6,27 +6,26 @@ DatabaseRefreshService::DatabaseRefreshService(boost::asio::io_service& ioServic
|
|||||||
: _metadataParser(),
|
: _metadataParser(),
|
||||||
_database( p, _metadataParser)
|
_database( p, _metadataParser)
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO read from the database itself!
|
// TODO read from the database itself!
|
||||||
// Move this code in the database class
|
// Move this code in the database class
|
||||||
_database.watchDirectory( WatchedDirectory("/storage/common/Media/Son/Metal", WatchedDirectory::Audio) );
|
_database.watchDirectory( WatchedDirectory("/storage/common/Media/Son/Metal", WatchedDirectory::Audio) );
|
||||||
_database.watchDirectory( WatchedDirectory("/storage/common/Media/Video", WatchedDirectory::Video) );
|
_database.watchDirectory( WatchedDirectory("/storage/common/Media/Video", WatchedDirectory::Video) );
|
||||||
|
|
||||||
// TODO launch thread
|
|
||||||
boost::thread refreshThread(boost::bind(&Database::refresh, &_database));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DatabaseRefreshService::start(void)
|
DatabaseRefreshService::start(void)
|
||||||
{
|
{
|
||||||
std::cout << "DatabaseRefreshService::start, not implemented" << std::endl;
|
// _thread = boost::thread(boost::bind(&Database::refresh, &_database));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DatabaseRefreshService::stop(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
|
void
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef DB_REFRESH_SERVICE_HPP
|
#ifndef DB_REFRESH_SERVICE_HPP
|
||||||
#define DB_REFRESH_SERVICE_HPP
|
#define DB_REFRESH_SERVICE_HPP
|
||||||
|
|
||||||
|
#include <boost/thread.hpp>
|
||||||
#include <boost/asio/io_service.hpp>
|
#include <boost/asio/io_service.hpp>
|
||||||
|
|
||||||
#include "metadata/AvFormat.hpp"
|
#include "metadata/AvFormat.hpp"
|
||||||
@@ -20,6 +21,8 @@ class DatabaseRefreshService : public Service
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
boost::thread _thread;
|
||||||
|
|
||||||
MetaData::AvFormat _metadataParser;
|
MetaData::AvFormat _metadataParser;
|
||||||
Database _database;
|
Database _database;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ ServiceManager::ServiceManager()
|
|||||||
_signalSet.add(SIGHUP);
|
_signalSet.add(SIGHUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServiceManager::~ServiceManager()
|
||||||
|
{
|
||||||
|
stopServices();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServiceManager::run()
|
ServiceManager::run()
|
||||||
{
|
{
|
||||||
@@ -25,8 +30,15 @@ ServiceManager::run()
|
|||||||
asyncWaitSignals();
|
asyncWaitSignals();
|
||||||
|
|
||||||
std::cout << "ServiceManager::run Waiting for events..." << std::endl;
|
std::cout << "ServiceManager::run Waiting for events..." << std::endl;
|
||||||
|
try {
|
||||||
// Wait for events
|
// Wait for events
|
||||||
_ioService.run();
|
_ioService.run();
|
||||||
|
}
|
||||||
|
catch( std::exception& e )
|
||||||
|
{
|
||||||
|
std::cerr << "Caugh exception in service : " << e.what() << std::endl;
|
||||||
|
stopServices();
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "ServiceManager::run complete!" << std::endl;
|
std::cout << "ServiceManager::run complete!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,13 @@ class ServiceManager
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
ServiceManager();
|
ServiceManager();
|
||||||
|
~ServiceManager();
|
||||||
|
|
||||||
void stopService(Service::pointer service);
|
void stopService(Service::pointer service);
|
||||||
void startService(Service::pointer service);
|
void startService(Service::pointer service);
|
||||||
|
|
||||||
|
void stopAllServices();
|
||||||
|
|
||||||
// Return in case of failure/stop by user
|
// Return in case of failure/stop by user
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user