WIP. Reorganizing things to get settings work. First attempt on Database settings
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include "DatabaseUpdateService.hpp"
|
||||
|
||||
DatabaseUpdateService::DatabaseUpdateService(boost::asio::io_service& ioService, const boost::filesystem::path& p)
|
||||
: _metadataParser(),
|
||||
_databaseUpdater( p, _metadataParser)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
DatabaseUpdateService::start(void)
|
||||
{
|
||||
_thread = boost::thread(boost::bind(&DatabaseUpdater::Updater::process, &_databaseUpdater));
|
||||
}
|
||||
|
||||
void
|
||||
DatabaseUpdateService::stop(void)
|
||||
{
|
||||
std::cout << "DatabaseUpdateService::stop, processing..." << std::endl;
|
||||
_thread.interrupt();
|
||||
_thread.join();
|
||||
std::cout << "DatabaseUpdateService::stop, process done" << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
DatabaseUpdateService::restart(void)
|
||||
{
|
||||
std::cout << "DatabaseUpdateService::restart, not implemented" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef DB_UPDATE_SERVICE_HPP
|
||||
#define DB_UPDATE_SERVICE_HPP
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
|
||||
#include "metadata/AvFormat.hpp"
|
||||
#include "database-updater/DatabaseUpdater.hpp"
|
||||
|
||||
#include "Service.hpp"
|
||||
|
||||
class DatabaseUpdateService : public Service
|
||||
{
|
||||
public:
|
||||
|
||||
DatabaseUpdateService(boost::asio::io_service& ioService, const boost::filesystem::path& p);
|
||||
|
||||
void start(void);
|
||||
void stop(void);
|
||||
void restart(void);
|
||||
|
||||
private:
|
||||
|
||||
boost::thread _thread;
|
||||
|
||||
MetaData::AvFormat _metadataParser;
|
||||
DatabaseUpdater::Updater _databaseUpdater; // Todo use handler
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
|
||||
#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)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RemoteServerService::start(void)
|
||||
{
|
||||
std::cout << "RemoteServerService::start, starting..." << std::endl;
|
||||
_server.run();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RemoteServerService::stop(void)
|
||||
{
|
||||
std::cout << "RemoteServerService::stop, stopping..." << std::endl;
|
||||
_server.stop();
|
||||
}
|
||||
|
||||
void
|
||||
RemoteServerService::restart(void)
|
||||
{
|
||||
std::cout << "RemoteServerService::restart, not implemented!" << std::endl;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef REMOTE_SERVER_SERVICE_HPP
|
||||
#define REMOTE_SERVER_SERVICE_HPP
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "Service.hpp"
|
||||
|
||||
#include "remote/server/Server.hpp"
|
||||
|
||||
class RemoteServerService : public Service
|
||||
{
|
||||
public:
|
||||
|
||||
RemoteServerService(boost::asio::io_service& ioService, const Remote::Server::Server::endpoint_type& endpoint, boost::filesystem::path dbPath);
|
||||
|
||||
void start(void);
|
||||
void stop(void);
|
||||
void restart(void);
|
||||
|
||||
private:
|
||||
|
||||
Remote::Server::Server _server;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef SERVICE_HPP
|
||||
#define SERVICE_HPP
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
// Interface class wrapper for running services
|
||||
class Service
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::shared_ptr<Service> pointer;
|
||||
|
||||
Service(const Service&) = delete;
|
||||
Service& operator=(const Service&) = delete;
|
||||
|
||||
Service() {}
|
||||
virtual ~Service() {}
|
||||
|
||||
virtual void start(void) = 0;
|
||||
virtual void stop(void) = 0;
|
||||
virtual void restart(void) = 0;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
|
||||
//#include <csignal>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "ServiceManager.hpp"
|
||||
|
||||
ServiceManager::ServiceManager()
|
||||
: _signalSet(_ioService)
|
||||
{
|
||||
_signalSet.add(SIGINT);
|
||||
_signalSet.add(SIGTERM);
|
||||
#if defined(SIGQUIT)
|
||||
_signalSet.add(SIGQUIT);
|
||||
#endif // defined(SIGQUIT)
|
||||
|
||||
_signalSet.add(SIGHUP);
|
||||
}
|
||||
|
||||
ServiceManager::~ServiceManager()
|
||||
{
|
||||
stopServices();
|
||||
}
|
||||
|
||||
void
|
||||
ServiceManager::run()
|
||||
{
|
||||
|
||||
asyncWaitSignals();
|
||||
|
||||
std::cout << "ServiceManager::run Waiting for events..." << std::endl;
|
||||
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;
|
||||
}
|
||||
|
||||
void
|
||||
ServiceManager::asyncWaitSignals(void)
|
||||
{
|
||||
_signalSet.async_wait(boost::bind(&ServiceManager::handleSignal,
|
||||
this,
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::signal_number));
|
||||
}
|
||||
|
||||
void
|
||||
ServiceManager::startService(Service::pointer service)
|
||||
{
|
||||
std::cout << "ServiceManager::startService" << std::endl;
|
||||
_services.insert(service);
|
||||
service->start();
|
||||
std::cout << "ServiceManager::startService done" << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
ServiceManager::stopService(Service::pointer service)
|
||||
{
|
||||
_services.erase(service);
|
||||
service->stop();
|
||||
}
|
||||
|
||||
void
|
||||
ServiceManager::stopServices(void)
|
||||
{
|
||||
BOOST_FOREACH(Service::pointer service, _services)
|
||||
service->stop();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ServiceManager::restartServices(void)
|
||||
{
|
||||
BOOST_FOREACH(Service::pointer service, _services)
|
||||
service->restart();
|
||||
}
|
||||
|
||||
void
|
||||
ServiceManager::handleSignal(boost::system::error_code /*ec*/, int signo)
|
||||
{
|
||||
std::cout << "Received signal " << signo << std::endl;
|
||||
|
||||
switch (signo)
|
||||
{
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
case SIGQUIT:
|
||||
std::cout << "Stopping services..." << std::endl;
|
||||
stopServices();
|
||||
|
||||
// Do not listen for signals, this will make the ioservice.run return
|
||||
break;
|
||||
case SIGHUP:
|
||||
std::cout << "Restarting services..." << std::endl;
|
||||
|
||||
restartServices();
|
||||
asyncWaitSignals();
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
#ifndef SERVICE_CONTROLER_HPP
|
||||
#define SERVICE_CONTROLER_HPP
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <set>
|
||||
|
||||
#include "Service.hpp"
|
||||
|
||||
// Start/Stop/Reload Services
|
||||
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();
|
||||
|
||||
boost::asio::io_service& getIoService() {return _ioService;}
|
||||
const boost::asio::io_service& getIoService() const {return _ioService;}
|
||||
|
||||
private:
|
||||
|
||||
void restartServices(void);
|
||||
void stopServices(void);
|
||||
|
||||
void asyncWaitSignals(void);
|
||||
|
||||
void handleSignal(boost::system::error_code error, int signo);
|
||||
|
||||
boost::asio::io_service _ioService;
|
||||
|
||||
// Listen for interesting signals
|
||||
boost::asio::signal_set _signalSet;
|
||||
|
||||
std::set<Service::pointer> _services;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "UserInterfaceService.hpp"
|
||||
#include "ui/LmsApplication.hpp"
|
||||
|
||||
UserInterfaceService::UserInterfaceService( int argc, char* argv[], boost::filesystem::path dbPath)
|
||||
: _server(argv[0], "")
|
||||
{
|
||||
// TODO configure server using another way (config file?)
|
||||
_server.setServerConfiguration (argc, argv, WTHTTP_CONFIGURATION);
|
||||
|
||||
// bind entry point
|
||||
_server.addEntryPoint(Wt::Application, boost::bind(UserInterface::LmsApplication::create, _1, dbPath));
|
||||
}
|
||||
|
||||
void
|
||||
UserInterfaceService::start(void)
|
||||
{
|
||||
_server.start();
|
||||
std::cout << "UserInterfaceService::start -> Service started..." << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
UserInterfaceService::stop(void)
|
||||
{
|
||||
std::cout << "UserInterfaceService::stop -> stopping..." << std::endl;
|
||||
_server.stop();
|
||||
std::cout << "UserInterfaceService::stop -> stopped!" << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
UserInterfaceService::restart(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#ifndef WEB_SERVER_SERVICE_HPP
|
||||
#define WEB_SERVER_SERVICE_HPP
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <Wt/WServer>
|
||||
|
||||
#include "Service.hpp"
|
||||
|
||||
class UserInterfaceService : public Service
|
||||
{
|
||||
public:
|
||||
UserInterfaceService( int argc, char* argv[], boost::filesystem::path dbPath);
|
||||
|
||||
void start(void);
|
||||
void stop(void);
|
||||
void restart(void);
|
||||
|
||||
private:
|
||||
|
||||
Wt::WServer _server;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+6
-6
@@ -7,10 +7,10 @@
|
||||
#include "av/Common.hpp"
|
||||
#include "database/DatabaseHandler.hpp"
|
||||
|
||||
#include "ServiceManager.hpp"
|
||||
#include "DatabaseUpdateService.hpp"
|
||||
#include "UserInterfaceService.hpp"
|
||||
#include "RemoteServerService.hpp"
|
||||
#include "service/ServiceManager.hpp"
|
||||
#include "service/DatabaseUpdateService.hpp"
|
||||
#include "service/UserInterfaceService.hpp"
|
||||
#include "service/RemoteServerService.hpp"
|
||||
|
||||
#include "ui/LmsApplication.hpp"
|
||||
|
||||
@@ -21,7 +21,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
try
|
||||
{
|
||||
ServiceManager serviceManager;
|
||||
ServiceManager& serviceManager = ServiceManager::instance();
|
||||
|
||||
// TODO Retreive the database path in some config file
|
||||
const boost::filesystem::path dbPath("test.db");
|
||||
@@ -34,7 +34,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
std::cout << "Starting services..." << std::endl;
|
||||
|
||||
// serviceManager.startService( std::make_shared<DatabaseUpdateService>( serviceManager.getIoService(), dbPath) );
|
||||
serviceManager.startService( std::make_shared<DatabaseUpdateService>( serviceManager.getIoService(), dbPath) );
|
||||
serviceManager.startService( std::make_shared<RemoteServerService>( serviceManager.getIoService(), remoteListenEndpoint, dbPath) );
|
||||
serviceManager.startService( std::make_shared<UserInterfaceService>(argc, argv, dbPath) );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user