[Config] Reworked the services' configuration

This commit is contained in:
emeric
2015-08-03 19:12:22 +02:00
parent 3ada201eb8
commit ecb6f5502d
14 changed files with 129 additions and 222 deletions
+18 -4
View File
@@ -19,18 +19,32 @@
#include <boost/thread.hpp>
#include "config/ConfigReader.hpp"
#include "logger/Logger.hpp"
#include "DatabaseUpdateService.hpp"
static std::vector<std::string> splitStrings(const std::string& source)
{
std::vector<std::string> res;
std::istringstream oss(source);
std::string str;
while(oss >> str)
res.push_back(str);
return res;
}
namespace Service {
DatabaseUpdateService::DatabaseUpdateService(const Config& config)
DatabaseUpdateService::DatabaseUpdateService()
: _metadataParser(),
_databaseUpdater( config.dbPath, _metadataParser)
_databaseUpdater( ConfigReader::instance().getString("main.database.path"),
_metadataParser)
{
_databaseUpdater.setAudioExtensions(config.audioExtensions);
_databaseUpdater.setVideoExtensions(config.videoExtensions);
_databaseUpdater.setAudioExtensions(splitStrings(ConfigReader::instance().getString("main.database.audio_extensions")));
_databaseUpdater.setVideoExtensions(splitStrings(ConfigReader::instance().getString("main.database.video_extensions")));
}
void
+1 -8
View File
@@ -36,14 +36,7 @@ class DatabaseUpdateService : public Service
typedef std::shared_ptr<DatabaseUpdateService> pointer;
struct Config {
bool enable;
boost::filesystem::path dbPath;
std::vector<std::string> audioExtensions;
std::vector<std::string> videoExtensions;
};
DatabaseUpdateService(const Config& config);
DatabaseUpdateService();
// Service interface
void start(void);
+12 -6
View File
@@ -17,18 +17,24 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/asio/ip/address.hpp>
#include "config/ConfigReader.hpp"
#include "logger/Logger.hpp"
#include "LmsAPIServerService.hpp"
namespace Service {
LmsAPIService::LmsAPIService(const Config& config)
: _server(boost::asio::ip::tcp::endpoint(config.address, config.port),
config.sslCertificatePath,
config.sslPrivateKeyPath,
config.sslTempDhPath,
config.dbPath)
LmsAPIService::LmsAPIService()
: _server(
boost::asio::ip::tcp::endpoint(
boost::asio::ip::address::from_string(ConfigReader::instance().getString("remote.listen-endpoint.addr")),
ConfigReader::instance().getULong("remote.listen-endpoint.port")),
ConfigReader::instance().getString("remote.ssl-crypto.cert"),
ConfigReader::instance().getString("remote.ssl-crypto.key"),
ConfigReader::instance().getString("remote.ssl-crypto.dh"),
ConfigReader::instance().getString("main.database.path"))
{
}
+1 -12
View File
@@ -21,7 +21,6 @@
#define REMOTE_SERVER_SERVICE_HPP
#include <boost/filesystem.hpp>
#include <boost/asio/ip/address.hpp>
#include "config/config.h"
@@ -35,17 +34,7 @@ class LmsAPIService : public Service
{
public:
struct Config {
bool enable;
boost::asio::ip::address address;
unsigned short port;
boost::filesystem::path sslCertificatePath;
boost::filesystem::path sslPrivateKeyPath;
boost::filesystem::path sslTempDhPath;
boost::filesystem::path dbPath;
};
LmsAPIService(const Config& config);
LmsAPIService();
void start(void);
void stop(void);
+11 -12
View File
@@ -22,24 +22,23 @@
#include "UserInterfaceService.hpp"
#include "ui/LmsApplication.hpp"
#include "config/ConfigReader.hpp"
namespace Service {
UserInterfaceService::UserInterfaceService( boost::filesystem::path runAppPath, const Config& config)
UserInterfaceService::UserInterfaceService( boost::filesystem::path runAppPath)
: _server(runAppPath.string())
{
std::vector<std::string> args;
args.push_back(runAppPath.string());
args.push_back("--docroot=" + config.docRootPath.string());
args.push_back("--approot=" + config.appRootPath.string());
{
std::ostringstream oss; oss << config.httpsPort;
args.push_back("--https-port=" + oss.str());
}
args.push_back("--https-address=" + config.httpsAddress.to_string());
args.push_back("--ssl-certificate=" + config.sslCertificatePath.string());
args.push_back("--ssl-private-key=" + config.sslPrivateKeyPath.string());
args.push_back("--ssl-tmp-dh=" + config.sslTempDhPath.string());
args.push_back("--docroot=" + ConfigReader::instance().getString("ui.resources.docroot"));
args.push_back("--approot=" + ConfigReader::instance().getString("ui.resources.approot"));
args.push_back("--https-port=" + std::to_string( ConfigReader::instance().getULong("ui.listen-endpoint.port")));
args.push_back("--https-address=" + ConfigReader::instance().getString("ui.listen-endpoint.addr"));
args.push_back("--ssl-certificate=" + ConfigReader::instance().getString("ui.ssl-crypto.cert"));
args.push_back("--ssl-private-key=" + ConfigReader::instance().getString("ui.ssl-crypto.key"));
args.push_back("--ssl-tmp-dh=" + ConfigReader::instance().getString("ui.ssl-crypto.dh"));
// Construct argc/argv
int argc = args.size();
@@ -55,7 +54,7 @@ UserInterfaceService::UserInterfaceService( boost::filesystem::path runAppPath,
_server.setServerConfiguration (argc, const_cast<char**>(argv));
// bind entry point
_server.addEntryPoint(Wt::Application, boost::bind(UserInterface::LmsApplication::create, _1, config.dbPath));
_server.addEntryPoint(Wt::Application, boost::bind(UserInterface::LmsApplication::create, _1, ConfigReader::instance().getString("main.database.path")));
}
+1 -15
View File
@@ -21,7 +21,6 @@
#define WEB_SERVER_SERVICE_HPP
#include <boost/filesystem.hpp>
#include <boost/asio/ip/address.hpp>
#include <Wt/WServer>
@@ -33,20 +32,7 @@ class UserInterfaceService : public Service
{
public:
struct Config {
bool enable;
boost::filesystem::path docRootPath;
boost::filesystem::path appRootPath;
unsigned short httpsPort;
boost::asio::ip::address httpsAddress;
boost::filesystem::path sslCertificatePath;
boost::filesystem::path sslPrivateKeyPath;
boost::filesystem::path sslTempDhPath;
boost::filesystem::path dbPath;
};
UserInterfaceService(boost::filesystem::path runAppPath,
const Config& config);
UserInterfaceService(boost::filesystem::path runAppPath);
void start(void);
void stop(void);