WIP. Using WIOService to handle Services
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "DatabaseUpdateService.hpp"
|
||||
|
||||
DatabaseUpdateService::DatabaseUpdateService(boost::asio::io_service& ioService, const boost::filesystem::path& p)
|
||||
DatabaseUpdateService::DatabaseUpdateService(const boost::filesystem::path& p)
|
||||
: _metadataParser(),
|
||||
_databaseUpdater( p, _metadataParser)
|
||||
{
|
||||
@@ -11,18 +11,14 @@ DatabaseUpdateService::DatabaseUpdateService(boost::asio::io_service& ioService,
|
||||
void
|
||||
DatabaseUpdateService::start(void)
|
||||
{
|
||||
// TODO
|
||||
// Read database parameters and program a timer for the next scan
|
||||
// _thread = boost::thread(boost::bind(&DatabaseUpdater::Updater::process, &_databaseUpdater));
|
||||
_databaseUpdater.start();
|
||||
}
|
||||
|
||||
void
|
||||
DatabaseUpdateService::stop(void)
|
||||
{
|
||||
std::cout << "DatabaseUpdateService::stop, processing..." << std::endl;
|
||||
// no effect if thread does not exist
|
||||
_thread.interrupt();
|
||||
_thread.join();
|
||||
_databaseUpdater.stop();
|
||||
std::cout << "DatabaseUpdateService::stop, process done" << std::endl;
|
||||
}
|
||||
|
||||
@@ -34,11 +30,3 @@ DatabaseUpdateService::restart(void)
|
||||
start();
|
||||
}
|
||||
|
||||
bool
|
||||
DatabaseUpdateService::isScanning(void) const
|
||||
{
|
||||
// scanning is active only if a thread is running the updater
|
||||
return _thread.get_id() != boost::thread::id();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,20 +15,15 @@ class DatabaseUpdateService : public Service
|
||||
|
||||
typedef std::shared_ptr<DatabaseUpdateService> pointer;
|
||||
|
||||
DatabaseUpdateService(boost::asio::io_service& ioService, const boost::filesystem::path& p);
|
||||
DatabaseUpdateService(const boost::filesystem::path& p);
|
||||
|
||||
// Service interface
|
||||
void start(void);
|
||||
void stop(void);
|
||||
void restart(void);
|
||||
|
||||
// Specific interface
|
||||
bool isScanning(void) const; //return if the service is currently scanning the db
|
||||
|
||||
private:
|
||||
|
||||
boost::thread _thread;
|
||||
|
||||
MetaData::AvFormat _metadataParser;
|
||||
DatabaseUpdater::Updater _databaseUpdater; // Todo use handler
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
#include "RemoteServerService.hpp"
|
||||
|
||||
RemoteServerService::RemoteServerService(boost::asio::io_service& ioService, const Remote::Server::Server::endpoint_type& endpoint, boost::filesystem::path dbPath)
|
||||
: _server(ioService, endpoint, dbPath)
|
||||
RemoteServerService::RemoteServerService(const Remote::Server::Server::endpoint_type& endpoint, boost::filesystem::path dbPath)
|
||||
: _server(endpoint, dbPath)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ void
|
||||
RemoteServerService::start(void)
|
||||
{
|
||||
std::cout << "RemoteServerService::start, starting..." << std::endl;
|
||||
_server.run();
|
||||
_server.start();
|
||||
std::cout << "RemoteServerService::start, started!" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +20,7 @@ RemoteServerService::stop(void)
|
||||
{
|
||||
std::cout << "RemoteServerService::stop, stopping..." << std::endl;
|
||||
_server.stop();
|
||||
std::cout << "RemoteServerService::stop, stopped!" << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@ class RemoteServerService : public Service
|
||||
{
|
||||
public:
|
||||
|
||||
RemoteServerService(boost::asio::io_service& ioService, const Remote::Server::Server::endpoint_type& endpoint, boost::filesystem::path dbPath);
|
||||
RemoteServerService(const Remote::Server::Server::endpoint_type& endpoint, boost::filesystem::path dbPath);
|
||||
|
||||
void start(void);
|
||||
void stop(void);
|
||||
|
||||
@@ -27,7 +27,6 @@ ServiceManager::ServiceManager()
|
||||
|
||||
ServiceManager::~ServiceManager()
|
||||
{
|
||||
stopServices();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -44,9 +43,11 @@ ServiceManager::run()
|
||||
catch( std::exception& e )
|
||||
{
|
||||
std::cerr << "Caugh exception in service : " << e.what() << std::endl;
|
||||
stopServices();
|
||||
}
|
||||
|
||||
// Stopping services
|
||||
stopServices();
|
||||
|
||||
std::cout << "ServiceManager::run complete!" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,6 @@ class ServiceManager
|
||||
// Return in case of failure/stop by user
|
||||
void run();
|
||||
|
||||
boost::asio::io_service& getIoService() {return _ioService;}
|
||||
const boost::asio::io_service& getIoService() const {return _ioService;}
|
||||
|
||||
template <class T> typename T::pointer getService();
|
||||
|
||||
boost::mutex& mutex() { return _mutex;}
|
||||
|
||||
Reference in New Issue
Block a user