WIP. RemoteServer, DbUpdate settings implemented

This commit is contained in:
emeric
2014-08-21 15:45:32 +02:00
parent e8b2412cd6
commit e7707d9faa
7 changed files with 62 additions and 15 deletions
+21
View File
@@ -24,3 +24,24 @@ ConfigReader::getUserInterfaceConfig(Service::UserInterfaceService::Config& conf
config.dbPath = _config.lookup("main.db"); 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<unsigned int>(_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");
}
+4 -1
View File
@@ -5,6 +5,8 @@
#include <libconfig.h++> #include <libconfig.h++>
#include "service/UserInterfaceService.hpp" #include "service/UserInterfaceService.hpp"
#include "service/RemoteServerService.hpp"
#include "service/DatabaseUpdateService.hpp"
class ConfigReader class ConfigReader
{ {
@@ -13,7 +15,8 @@ class ConfigReader
ConfigReader(boost::filesystem::path p); ConfigReader(boost::filesystem::path p);
void getUserInterfaceConfig(Service::UserInterfaceService::Config& config); void getUserInterfaceConfig(Service::UserInterfaceService::Config& config);
void getRemoteServerConfig(Service::RemoteServerService::Config& config);
void getDatabaseUpdateConfig(Service::DatabaseUpdateService::Config& config);
private: private:
+18 -8
View File
@@ -14,12 +14,15 @@ int main(int argc, char* argv[])
int res = EXIT_FAILURE; int res = EXIT_FAILURE;
assert(argc > 0);
assert(argv[0] != NULL);
try try
{ {
// TODO generate a nice command line help with args // TODO generate a nice command line help with args
// Open configuration file // Open configuration file
boost::filesystem::path configFile("/etc/lms.conf"); boost::filesystem::path configFile("/etc/lms.conf"); // TODO
if (argc > 1) if (argc > 1)
configFile = boost::filesystem::path(argv[1]); configFile = boost::filesystem::path(argv[1]);
@@ -32,14 +35,16 @@ int main(int argc, char* argv[])
ConfigReader configReader(configFile); ConfigReader configReader(configFile);
Service::DatabaseUpdateService::Config dbUpdateConfig;
configReader.getDatabaseUpdateConfig(dbUpdateConfig);
Service::UserInterfaceService::Config uiConfig; Service::UserInterfaceService::Config uiConfig;
configReader.getUserInterfaceConfig(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 Service::ServiceManager& serviceManager = Service::ServiceManager::instance();
const boost::filesystem::path dbPath("test.db");
Remote::Server::Server::endpoint_type remoteListenEndpoint( boost::asio::ip::address::from_string("0.0.0.0"), 5080);
// lib init // lib init
Av::AvInit(); Av::AvInit();
@@ -48,9 +53,14 @@ int main(int argc, char* argv[])
std::cout << "Starting services..." << std::endl; std::cout << "Starting services..." << std::endl;
serviceManager.startService( std::make_shared<Service::DatabaseUpdateService>( dbPath) ); if (dbUpdateConfig.enable)
serviceManager.startService( std::make_shared<Service::RemoteServerService>( remoteListenEndpoint, dbPath) ); serviceManager.startService( std::make_shared<Service::DatabaseUpdateService>( dbUpdateConfig ) );
serviceManager.startService( std::make_shared<Service::UserInterfaceService>(boost::filesystem::path(argv[0]), uiConfig));
if (remoteConfig.enable)
serviceManager.startService( std::make_shared<Service::RemoteServerService>( remoteConfig ));
if (uiConfig.enable)
serviceManager.startService( std::make_shared<Service::UserInterfaceService>(boost::filesystem::path(argv[0]), uiConfig));
std::cout << "Running..." << std::endl; std::cout << "Running..." << std::endl;
+2 -2
View File
@@ -4,9 +4,9 @@
namespace Service { namespace Service {
DatabaseUpdateService::DatabaseUpdateService(const boost::filesystem::path& p) DatabaseUpdateService::DatabaseUpdateService(const Config& config)
: _metadataParser(), : _metadataParser(),
_databaseUpdater( p, _metadataParser) _databaseUpdater( config.dbPath, _metadataParser)
{ {
} }
+6 -1
View File
@@ -17,7 +17,12 @@ class DatabaseUpdateService : public Service
typedef std::shared_ptr<DatabaseUpdateService> pointer; typedef std::shared_ptr<DatabaseUpdateService> pointer;
DatabaseUpdateService(const boost::filesystem::path& p); struct Config {
bool enable;
boost::filesystem::path dbPath;
};
DatabaseUpdateService(const Config& config);
// Service interface // Service interface
void start(void); void start(void);
+2 -2
View File
@@ -3,8 +3,8 @@
namespace Service { namespace Service {
RemoteServerService::RemoteServerService(const Remote::Server::Server::endpoint_type& endpoint, boost::filesystem::path dbPath) RemoteServerService::RemoteServerService(const Config& config)
: _server(endpoint, dbPath) : _server(boost::asio::ip::tcp::endpoint(config.address, config.port), config.dbPath)
{ {
} }
+9 -1
View File
@@ -2,6 +2,7 @@
#define REMOTE_SERVER_SERVICE_HPP #define REMOTE_SERVER_SERVICE_HPP
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/asio/ip/address.hpp>
#include "Service.hpp" #include "Service.hpp"
@@ -13,7 +14,14 @@ class RemoteServerService : public Service
{ {
public: 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 start(void);
void stop(void); void stop(void);