From e7707d9faaf17c10149601cfbfff6ba335fc5729 Mon Sep 17 00:00:00 2001 From: emeric Date: Thu, 21 Aug 2014 15:45:32 +0200 Subject: [PATCH] WIP. RemoteServer, DbUpdate settings implemented --- config/ConfigReader.cpp | 21 +++++++++++++++++++++ config/ConfigReader.hpp | 5 ++++- main/main.cpp | 26 ++++++++++++++++++-------- service/DatabaseUpdateService.cpp | 4 ++-- service/DatabaseUpdateService.hpp | 7 ++++++- service/RemoteServerService.cpp | 4 ++-- service/RemoteServerService.hpp | 10 +++++++++- 7 files changed, 62 insertions(+), 15 deletions(-) diff --git a/config/ConfigReader.cpp b/config/ConfigReader.cpp index 3cb092fa..a01d01ae 100644 --- a/config/ConfigReader.cpp +++ b/config/ConfigReader.cpp @@ -24,3 +24,24 @@ ConfigReader::getUserInterfaceConfig(Service::UserInterfaceService::Config& conf config.dbPath = _config.lookup("main.db"); } +void +ConfigReader::getRemoteServerConfig(Service::RemoteServerService::Config& config) +{ + config.enable = _config.lookup("remote.enable"); + if (!config.enable) + return; + + config.port = static_cast(_config.lookup("remote.listen-endpoint.port")); + config.address = boost::asio::ip::address::from_string((const char*)_config.lookup("remote.listen-endpoint.addr")); + + config.dbPath = _config.lookup("main.db"); +} + +void +ConfigReader::getDatabaseUpdateConfig(Service::DatabaseUpdateService::Config& config) +{ + config.enable = true; + + config.dbPath = _config.lookup("main.db"); +} + diff --git a/config/ConfigReader.hpp b/config/ConfigReader.hpp index 9b424dfd..689bc3dc 100644 --- a/config/ConfigReader.hpp +++ b/config/ConfigReader.hpp @@ -5,6 +5,8 @@ #include #include "service/UserInterfaceService.hpp" +#include "service/RemoteServerService.hpp" +#include "service/DatabaseUpdateService.hpp" class ConfigReader { @@ -13,7 +15,8 @@ class ConfigReader ConfigReader(boost::filesystem::path p); void getUserInterfaceConfig(Service::UserInterfaceService::Config& config); - + void getRemoteServerConfig(Service::RemoteServerService::Config& config); + void getDatabaseUpdateConfig(Service::DatabaseUpdateService::Config& config); private: diff --git a/main/main.cpp b/main/main.cpp index 233aeea6..540ebb75 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -14,12 +14,15 @@ int main(int argc, char* argv[]) int res = EXIT_FAILURE; + assert(argc > 0); + assert(argv[0] != NULL); + try { // TODO generate a nice command line help with args // Open configuration file - boost::filesystem::path configFile("/etc/lms.conf"); + boost::filesystem::path configFile("/etc/lms.conf"); // TODO if (argc > 1) configFile = boost::filesystem::path(argv[1]); @@ -32,14 +35,16 @@ int main(int argc, char* argv[]) ConfigReader configReader(configFile); + Service::DatabaseUpdateService::Config dbUpdateConfig; + configReader.getDatabaseUpdateConfig(dbUpdateConfig); + Service::UserInterfaceService::Config uiConfig; configReader.getUserInterfaceConfig(uiConfig); - Service::ServiceManager& serviceManager = Service::ServiceManager::instance(); + Service::RemoteServerService::Config remoteConfig; + configReader.getRemoteServerConfig(remoteConfig); - // TODO Retreive the database path in some config file - const boost::filesystem::path dbPath("test.db"); - Remote::Server::Server::endpoint_type remoteListenEndpoint( boost::asio::ip::address::from_string("0.0.0.0"), 5080); + Service::ServiceManager& serviceManager = Service::ServiceManager::instance(); // lib init Av::AvInit(); @@ -48,9 +53,14 @@ int main(int argc, char* argv[]) std::cout << "Starting services..." << std::endl; - serviceManager.startService( std::make_shared( dbPath) ); - serviceManager.startService( std::make_shared( remoteListenEndpoint, dbPath) ); - serviceManager.startService( std::make_shared(boost::filesystem::path(argv[0]), uiConfig)); + if (dbUpdateConfig.enable) + serviceManager.startService( std::make_shared( dbUpdateConfig ) ); + + if (remoteConfig.enable) + serviceManager.startService( std::make_shared( remoteConfig )); + + if (uiConfig.enable) + serviceManager.startService( std::make_shared(boost::filesystem::path(argv[0]), uiConfig)); std::cout << "Running..." << std::endl; diff --git a/service/DatabaseUpdateService.cpp b/service/DatabaseUpdateService.cpp index d13765ce..ad4260ed 100644 --- a/service/DatabaseUpdateService.cpp +++ b/service/DatabaseUpdateService.cpp @@ -4,9 +4,9 @@ namespace Service { -DatabaseUpdateService::DatabaseUpdateService(const boost::filesystem::path& p) +DatabaseUpdateService::DatabaseUpdateService(const Config& config) : _metadataParser(), - _databaseUpdater( p, _metadataParser) + _databaseUpdater( config.dbPath, _metadataParser) { } diff --git a/service/DatabaseUpdateService.hpp b/service/DatabaseUpdateService.hpp index c42d7533..1490ae57 100644 --- a/service/DatabaseUpdateService.hpp +++ b/service/DatabaseUpdateService.hpp @@ -17,7 +17,12 @@ class DatabaseUpdateService : public Service typedef std::shared_ptr pointer; - DatabaseUpdateService(const boost::filesystem::path& p); + struct Config { + bool enable; + boost::filesystem::path dbPath; + }; + + DatabaseUpdateService(const Config& config); // Service interface void start(void); diff --git a/service/RemoteServerService.cpp b/service/RemoteServerService.cpp index df597dba..313cddd7 100644 --- a/service/RemoteServerService.cpp +++ b/service/RemoteServerService.cpp @@ -3,8 +3,8 @@ namespace Service { -RemoteServerService::RemoteServerService(const Remote::Server::Server::endpoint_type& endpoint, boost::filesystem::path dbPath) -: _server(endpoint, dbPath) +RemoteServerService::RemoteServerService(const Config& config) +: _server(boost::asio::ip::tcp::endpoint(config.address, config.port), config.dbPath) { } diff --git a/service/RemoteServerService.hpp b/service/RemoteServerService.hpp index f13346f5..3ab0697f 100644 --- a/service/RemoteServerService.hpp +++ b/service/RemoteServerService.hpp @@ -2,6 +2,7 @@ #define REMOTE_SERVER_SERVICE_HPP #include +#include #include "Service.hpp" @@ -13,7 +14,14 @@ class RemoteServerService : public Service { public: - RemoteServerService(const Remote::Server::Server::endpoint_type& endpoint, boost::filesystem::path dbPath); + struct Config { + bool enable; + boost::asio::ip::address address; + unsigned short port; + boost::filesystem::path dbPath; + }; + + RemoteServerService(const Config& config); void start(void); void stop(void);