[Config] Reworked the services' configuration
This commit is contained in:
+31
-68
@@ -23,89 +23,52 @@
|
||||
|
||||
namespace {
|
||||
|
||||
void splitStrings(const std::string& source, std::vector<std::string>& res)
|
||||
{
|
||||
std::istringstream oss(source);
|
||||
|
||||
std::string str;
|
||||
while(oss >> str)
|
||||
res.push_back(str);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ConfigReader::ConfigReader(boost::filesystem::path p)
|
||||
ConfigReader::ConfigReader()
|
||||
: _config (nullptr)
|
||||
{
|
||||
_config.readFile(p.string().c_str());
|
||||
}
|
||||
|
||||
ConfigReader&
|
||||
ConfigReader::instance()
|
||||
{
|
||||
static ConfigReader instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void
|
||||
ConfigReader::getLoggerConfig(Logger::Config& config)
|
||||
ConfigReader::setFile(boost::filesystem::path p)
|
||||
{
|
||||
config.enableFileLogging = _config.lookupValue("main.logger.file", config.logPath);
|
||||
config.enableConsoleLogging = _config.lookup("main.logger.console");
|
||||
config.minSeverity = static_cast<Severity>((int)_config.lookup("main.logger.level"));
|
||||
if (_config != nullptr)
|
||||
delete _config;
|
||||
|
||||
_config = new libconfig::Config();
|
||||
|
||||
_config->readFile(p.string().c_str());
|
||||
}
|
||||
|
||||
void
|
||||
ConfigReader::getCoverGrabberConfig(CoverArt::Grabber::Config& config)
|
||||
std::string
|
||||
ConfigReader::getString(std::string setting)
|
||||
{
|
||||
std::string extensions = _config.lookup("main.cover.file_extensions");
|
||||
config.maxFileSize = static_cast<unsigned int>(_config.lookup("main.cover.file_max_size"));
|
||||
std::string filenames = _config.lookup("main.cover.file_preferred_names");
|
||||
|
||||
splitStrings(extensions, config.fileExtensions);
|
||||
splitStrings(filenames, config.preferredFileNames);
|
||||
return _config->lookup(setting);
|
||||
}
|
||||
|
||||
void
|
||||
ConfigReader::getUserInterfaceConfig(Service::UserInterfaceService::Config& config)
|
||||
unsigned long
|
||||
ConfigReader::getULong(std::string setting)
|
||||
{
|
||||
|
||||
config.enable = _config.lookup("ui.enable");
|
||||
if (!config.enable)
|
||||
return;
|
||||
|
||||
config.docRootPath = _config.lookup("ui.resources.docroot");
|
||||
config.appRootPath = _config.lookup("ui.resources.approot");
|
||||
config.httpsPort = static_cast<unsigned int>(_config.lookup("ui.listen-endpoint.port"));
|
||||
config.httpsAddress = boost::asio::ip::address::from_string((const char*)_config.lookup("ui.listen-endpoint.addr"));
|
||||
config.sslCertificatePath = _config.lookup("ui.ssl-crypto.cert");
|
||||
config.sslPrivateKeyPath = _config.lookup("ui.ssl-crypto.key");
|
||||
config.sslTempDhPath = _config.lookup("ui.ssl-crypto.dh");
|
||||
|
||||
config.dbPath = _config.lookup("main.database.path");
|
||||
return static_cast<unsigned int>(_config->lookup(setting));
|
||||
}
|
||||
|
||||
#if defined HAVE_LMSAPI
|
||||
void
|
||||
ConfigReader::getLmsAPIConfig(Service::LmsAPIService::Config& config)
|
||||
long
|
||||
ConfigReader::getLong(std::string setting)
|
||||
{
|
||||
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.sslCertificatePath = _config.lookup("remote.ssl-crypto.cert");
|
||||
config.sslPrivateKeyPath = _config.lookup("remote.ssl-crypto.key");
|
||||
config.sslTempDhPath = _config.lookup("remote.ssl-crypto.dh");
|
||||
|
||||
config.dbPath = _config.lookup("main.database.path");
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
ConfigReader::getDatabaseUpdateConfig(Service::DatabaseUpdateService::Config& config)
|
||||
{
|
||||
config.enable = true;
|
||||
|
||||
config.dbPath = _config.lookup("main.database.path");
|
||||
|
||||
std::string audioExtensions = _config.lookup("main.database.audio_extensions");
|
||||
std::string videoExtensions = _config.lookup("main.database.video_extensions");
|
||||
|
||||
splitStrings(audioExtensions, config.audioExtensions);
|
||||
splitStrings(videoExtensions, config.videoExtensions);
|
||||
return _config->lookup(setting);
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigReader::getBool(std::string setting)
|
||||
{
|
||||
return _config->lookup(setting);
|
||||
}
|
||||
|
||||
|
||||
+11
-24
@@ -23,40 +23,27 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <libconfig.h++>
|
||||
|
||||
#include "config/config.h"
|
||||
|
||||
#include "cover/CoverArtGrabber.hpp"
|
||||
#include "logger/Logger.hpp"
|
||||
|
||||
#include "service/UserInterfaceService.hpp"
|
||||
#include "service/DatabaseUpdateService.hpp"
|
||||
#if defined HAVE_LMSAPI
|
||||
#include "service/LmsAPIServerService.hpp"
|
||||
#endif
|
||||
|
||||
class ConfigReader
|
||||
{
|
||||
public:
|
||||
|
||||
ConfigReader(boost::filesystem::path p);
|
||||
ConfigReader(const ConfigReader&) = delete;
|
||||
ConfigReader& operator=(const ConfigReader&) = delete;
|
||||
|
||||
// Logger configuration
|
||||
void getLoggerConfig(Logger::Config& config);
|
||||
static ConfigReader& instance();
|
||||
|
||||
// Covers
|
||||
void getCoverGrabberConfig(CoverArt::Grabber::Config& config);
|
||||
void setFile(boost::filesystem::path p);
|
||||
|
||||
// Service configurations
|
||||
void getUserInterfaceConfig(Service::UserInterfaceService::Config& config);
|
||||
void getDatabaseUpdateConfig(Service::DatabaseUpdateService::Config& config);
|
||||
|
||||
#if defined HAVE_LMSAPI
|
||||
void getLmsAPIConfig(Service::LmsAPIService::Config& config);
|
||||
#endif
|
||||
std::string getString(std::string setting);
|
||||
unsigned long getULong(std::string setting);
|
||||
long getLong(std::string setting);
|
||||
bool getBool(std::string setting);
|
||||
|
||||
private:
|
||||
|
||||
libconfig::Config _config;
|
||||
ConfigReader();
|
||||
|
||||
libconfig::Config *_config;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user