Config is no longer a singleton as such
This commit is contained in:
+22
-22
@@ -41,28 +41,28 @@ std::vector<std::string> generateWtConfig(std::string execPath)
|
|||||||
{
|
{
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
|
|
||||||
const boost::filesystem::path wtConfigPath {Config::instance().getPath("working-dir") / "wt_config.xml"};
|
const boost::filesystem::path wtConfigPath {getService<Config>()->getPath("working-dir") / "wt_config.xml"};
|
||||||
const boost::filesystem::path wtLogFilePath {Config::instance().getPath("working-dir") / "lms.log"};
|
const boost::filesystem::path wtLogFilePath {getService<Config>()->getPath("working-dir") / "lms.log"};
|
||||||
const boost::filesystem::path wtAccessLogFilePath {Config::instance().getPath("working-dir") / "lms.access.log"};
|
const boost::filesystem::path wtAccessLogFilePath {getService<Config>()->getPath("working-dir") / "lms.access.log"};
|
||||||
|
|
||||||
args.push_back(execPath);
|
args.push_back(execPath);
|
||||||
args.push_back("--config=" + wtConfigPath.string());
|
args.push_back("--config=" + wtConfigPath.string());
|
||||||
args.push_back("--docroot=" + Config::instance().getString("docroot"));
|
args.push_back("--docroot=" + getService<Config>()->getString("docroot"));
|
||||||
args.push_back("--approot=" + Config::instance().getString("approot"));
|
args.push_back("--approot=" + getService<Config>()->getString("approot"));
|
||||||
args.push_back("--resources-dir=" + Config::instance().getString("wt-resources"));
|
args.push_back("--resources-dir=" + getService<Config>()->getString("wt-resources"));
|
||||||
|
|
||||||
if (Config::instance().getBool("tls-enable", false))
|
if (getService<Config>()->getBool("tls-enable", false))
|
||||||
{
|
{
|
||||||
args.push_back("--https-port=" + std::to_string( Config::instance().getULong("listen-port", 5082)));
|
args.push_back("--https-port=" + std::to_string( getService<Config>()->getULong("listen-port", 5082)));
|
||||||
args.push_back("--https-address=" + Config::instance().getString("listen-addr", "0.0.0.0"));
|
args.push_back("--https-address=" + getService<Config>()->getString("listen-addr", "0.0.0.0"));
|
||||||
args.push_back("--ssl-certificate=" + Config::instance().getString("tls-cert"));
|
args.push_back("--ssl-certificate=" + getService<Config>()->getString("tls-cert"));
|
||||||
args.push_back("--ssl-private-key=" + Config::instance().getString("tls-key"));
|
args.push_back("--ssl-private-key=" + getService<Config>()->getString("tls-key"));
|
||||||
args.push_back("--ssl-tmp-dh=" + Config::instance().getString("tls-dh"));
|
args.push_back("--ssl-tmp-dh=" + getService<Config>()->getString("tls-dh"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
args.push_back("--http-port=" + std::to_string( Config::instance().getULong("listen-port", 5082)));
|
args.push_back("--http-port=" + std::to_string( getService<Config>()->getULong("listen-port", 5082)));
|
||||||
args.push_back("--http-address=" + Config::instance().getString("listen-addr", "0.0.0.0"));
|
args.push_back("--http-address=" + getService<Config>()->getString("listen-addr", "0.0.0.0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
args.push_back("--accesslog=" + wtAccessLogFilePath.string());
|
args.push_back("--accesslog=" + wtAccessLogFilePath.string());
|
||||||
@@ -72,8 +72,8 @@ std::vector<std::string> generateWtConfig(std::string execPath)
|
|||||||
|
|
||||||
pt.put("server.application-settings.<xmlattr>.location", "*");
|
pt.put("server.application-settings.<xmlattr>.location", "*");
|
||||||
pt.put("server.application-settings.log-file", wtLogFilePath.string());
|
pt.put("server.application-settings.log-file", wtLogFilePath.string());
|
||||||
pt.put("server.application-settings.log-config", Config::instance().getString("log-config", "* -debug -info:WebRequest"));
|
pt.put("server.application-settings.log-config", getService<Config>()->getString("log-config", "* -debug -info:WebRequest"));
|
||||||
pt.put("server.application-settings.behind-reverse-proxy", Config::instance().getBool("behind-reverse-proxy", false));
|
pt.put("server.application-settings.behind-reverse-proxy", getService<Config>()->getBool("behind-reverse-proxy", false));
|
||||||
pt.put("server.application-settings.progressive-bootstrap", true);
|
pt.put("server.application-settings.progressive-bootstrap", true);
|
||||||
|
|
||||||
std::ofstream oss(wtConfigPath.string().c_str(), std::ios::out);
|
std::ofstream oss(wtConfigPath.string().c_str(), std::ios::out);
|
||||||
@@ -99,11 +99,11 @@ int main(int argc, char* argv[])
|
|||||||
// Make pstream work with ffmpeg
|
// Make pstream work with ffmpeg
|
||||||
close(STDIN_FILENO);
|
close(STDIN_FILENO);
|
||||||
|
|
||||||
Config::instance().setFile(configFilePath);
|
ServiceProvider<Config>::create(configFilePath);
|
||||||
|
|
||||||
// Make sure the working directory exists
|
// Make sure the working directory exists
|
||||||
boost::filesystem::create_directories(Config::instance().getPath("working-dir"));
|
boost::filesystem::create_directories(getService<Config>()->getPath("working-dir"));
|
||||||
boost::filesystem::create_directories(Config::instance().getPath("working-dir") / "cache");
|
boost::filesystem::create_directories(getService<Config>()->getPath("working-dir") / "cache");
|
||||||
|
|
||||||
// Construct WT configuration and get the argc/argv back
|
// Construct WT configuration and get the argc/argv back
|
||||||
std::vector<std::string> wtServerArgs = generateWtConfig(argv[0]);
|
std::vector<std::string> wtServerArgs = generateWtConfig(argv[0]);
|
||||||
@@ -124,12 +124,12 @@ int main(int argc, char* argv[])
|
|||||||
Av::Transcoder::init();
|
Av::Transcoder::init();
|
||||||
|
|
||||||
// Initializing a connection pool to the database that will be shared along services
|
// Initializing a connection pool to the database that will be shared along services
|
||||||
Database::Database database {Config::instance().getPath("working-dir") / "lms.db"};
|
Database::Database database {getService<Config>()->getPath("working-dir") / "lms.db"};
|
||||||
|
|
||||||
UserInterface::LmsApplicationGroupContainer appGroups;
|
UserInterface::LmsApplicationGroupContainer appGroups;
|
||||||
|
|
||||||
// Service initialization order is important
|
// Service initialization order is important
|
||||||
ServiceProvider<Auth::AuthService>::create(Config::instance().getULong("login-throttler-max-entriees", 10000));
|
ServiceProvider<Auth::AuthService>::create(getService<Config>()->getULong("login-throttler-max-entriees", 10000));
|
||||||
Scanner::MediaScanner& mediaScanner {ServiceProvider<Scanner::MediaScanner>::create(database.createSession())};
|
Scanner::MediaScanner& mediaScanner {ServiceProvider<Scanner::MediaScanner>::create(database.createSession())};
|
||||||
|
|
||||||
Similarity::FeaturesScannerAddon similarityFeaturesScannerAddon {database.createSession()};
|
Similarity::FeaturesScannerAddon similarityFeaturesScannerAddon {database.createSession()};
|
||||||
@@ -144,7 +144,7 @@ int main(int argc, char* argv[])
|
|||||||
API::Subsonic::SubsonicResource subsonicResource {database};
|
API::Subsonic::SubsonicResource subsonicResource {database};
|
||||||
|
|
||||||
// bind API resources
|
// bind API resources
|
||||||
if (Config::instance().getBool("api-subsonic", true))
|
if (getService<Config>()->getBool("api-subsonic", true))
|
||||||
{
|
{
|
||||||
for (const std::string& path : API::Subsonic::SubsonicResource::getPaths())
|
for (const std::string& path : API::Subsonic::SubsonicResource::getPaths())
|
||||||
server.addResource(&subsonicResource, path);
|
server.addResource(&subsonicResource, path);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <boost/property_tree/json_parser.hpp>
|
#include <boost/property_tree/json_parser.hpp>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
#include "main/Service.hpp"
|
||||||
#include "utils/Config.hpp"
|
#include "utils/Config.hpp"
|
||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ getJsonData(const std::string& mbid)
|
|||||||
static const std::string defaultAPIURL = "https://acousticbrainz.org/api/v1/";
|
static const std::string defaultAPIURL = "https://acousticbrainz.org/api/v1/";
|
||||||
|
|
||||||
std::string data;
|
std::string data;
|
||||||
std::string url = Config::instance().getString("acousticbrainz-api-url", defaultAPIURL) + mbid + "/low-level";
|
std::string url = getService<Config>()->getString("acousticbrainz-api-url", defaultAPIURL) + mbid + "/low-level";
|
||||||
|
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include <boost/property_tree/xml_parser.hpp>
|
#include <boost/property_tree/xml_parser.hpp>
|
||||||
|
|
||||||
|
#include "main/Service.hpp"
|
||||||
#include "utils/Config.hpp"
|
#include "utils/Config.hpp"
|
||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
#include "utils/Utils.hpp"
|
#include "utils/Utils.hpp"
|
||||||
@@ -32,7 +33,7 @@ namespace Similarity {
|
|||||||
static
|
static
|
||||||
boost::filesystem::path getCacheDirectory()
|
boost::filesystem::path getCacheDirectory()
|
||||||
{
|
{
|
||||||
return Config::instance().getPath("working-dir") / "cache" / "features";
|
return getService<Config>()->getPath("working-dir") / "cache" / "features";
|
||||||
}
|
}
|
||||||
|
|
||||||
static boost::filesystem::path getCacheNetworkFilePath()
|
static boost::filesystem::path getCacheNetworkFilePath()
|
||||||
@@ -239,7 +240,7 @@ FeaturesCache::read()
|
|||||||
void
|
void
|
||||||
FeaturesCache::write()
|
FeaturesCache::write()
|
||||||
{
|
{
|
||||||
boost::filesystem::create_directories(Config::instance().getPath("working-dir") / "cache" / "features");
|
boost::filesystem::create_directories(getService<Config>()->getPath("working-dir") / "cache" / "features");
|
||||||
|
|
||||||
if (!networkToCacheFile(_network, getCacheNetworkFilePath())
|
if (!networkToCacheFile(_network, getCacheNetworkFilePath())
|
||||||
|| !objectPositionToCacheFile(_trackPositions, getCacheTrackPositionsFilePath()))
|
|| !objectPositionToCacheFile(_trackPositions, getCacheTrackPositionsFilePath()))
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ UserView::refreshView()
|
|||||||
|
|
||||||
// Demo account
|
// Demo account
|
||||||
t->setFormWidget(UserModel::DemoField, std::make_unique<Wt::WCheckBox>());
|
t->setFormWidget(UserModel::DemoField, std::make_unique<Wt::WCheckBox>());
|
||||||
if (!userId && Config::instance().getBool("demo", false))
|
if (!userId && getService<Config>()->getBool("demo", false))
|
||||||
t->setCondition("if-demo", true);
|
t->setCondition("if-demo", true);
|
||||||
|
|
||||||
Wt::WPushButton* saveBtn = t->bindNew<Wt::WPushButton>("save-btn", Wt::WString::tr(userId ? "Lms.save" : "Lms.create"));
|
Wt::WPushButton* saveBtn = t->bindNew<Wt::WPushButton>("save-btn", Wt::WString::tr(userId ? "Lms.save" : "Lms.create"));
|
||||||
|
|||||||
+7
-16
@@ -24,25 +24,16 @@
|
|||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
|
|
||||||
|
|
||||||
Config&
|
Config::Config(const boost::filesystem::path& p)
|
||||||
Config::instance()
|
|
||||||
{
|
{
|
||||||
static Config instance;
|
_config.readFile(p.string().c_str());
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Config::setFile(const boost::filesystem::path& p)
|
|
||||||
{
|
|
||||||
_config = std::make_unique<libconfig::Config>();
|
|
||||||
_config->readFile(p.string().c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
Config::getString(const std::string& setting, const std::string& def, const std::set<std::string>& allowedValues)
|
Config::getString(const std::string& setting, const std::string& def, const std::set<std::string>& allowedValues)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
std::string res {(const char*)_config->lookup(setting)};
|
std::string res {(const char*)_config.lookup(setting)};
|
||||||
|
|
||||||
if (!allowedValues.empty() && allowedValues.find(res) == allowedValues.end())
|
if (!allowedValues.empty() && allowedValues.find(res) == allowedValues.end())
|
||||||
{
|
{
|
||||||
@@ -62,7 +53,7 @@ boost::filesystem::path
|
|||||||
Config::getPath(const std::string& setting, const boost::filesystem::path& path)
|
Config::getPath(const std::string& setting, const boost::filesystem::path& path)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
const char* res = _config->lookup(setting);
|
const char* res = _config.lookup(setting);
|
||||||
return boost::filesystem::path(std::string(res));
|
return boost::filesystem::path(std::string(res));
|
||||||
}
|
}
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
@@ -75,7 +66,7 @@ unsigned long
|
|||||||
Config::getULong(const std::string& setting, unsigned long def)
|
Config::getULong(const std::string& setting, unsigned long def)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return static_cast<unsigned int>(_config->lookup(setting));
|
return static_cast<unsigned int>(_config.lookup(setting));
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
@@ -87,7 +78,7 @@ long
|
|||||||
Config::getLong(const std::string& setting, long def)
|
Config::getLong(const std::string& setting, long def)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return _config->lookup(setting);
|
return _config.lookup(setting);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
@@ -99,7 +90,7 @@ bool
|
|||||||
Config::getBool(const std::string& setting, bool def)
|
Config::getBool(const std::string& setting, bool def)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return _config->lookup(setting);
|
return _config.lookup(setting);
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,16 +27,14 @@
|
|||||||
class Config final
|
class Config final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Config(const boost::filesystem::path& p);
|
||||||
|
~Config() = default;
|
||||||
|
|
||||||
Config(const Config&) = delete;
|
Config(const Config&) = delete;
|
||||||
Config& operator=(const Config&) = delete;
|
Config& operator=(const Config&) = delete;
|
||||||
Config(Config&&) = delete;
|
Config(Config&&) = delete;
|
||||||
Config& operator=(Config&&) = delete;
|
Config& operator=(Config&&) = delete;
|
||||||
|
|
||||||
static Config& instance();
|
|
||||||
|
|
||||||
void setFile(const boost::filesystem::path& p);
|
|
||||||
|
|
||||||
// Default values are returned in case of setting not found
|
// Default values are returned in case of setting not found
|
||||||
std::string getString(const std::string& setting, const std::string& def = "", const std::set<std::string>& allowedValues = {});
|
std::string getString(const std::string& setting, const std::string& def = "", const std::set<std::string>& allowedValues = {});
|
||||||
boost::filesystem::path getPath(const std::string& setting, const boost::filesystem::path& def = boost::filesystem::path());
|
boost::filesystem::path getPath(const std::string& setting, const boost::filesystem::path& def = boost::filesystem::path());
|
||||||
@@ -46,8 +44,6 @@ class Config final
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Config() = default;
|
libconfig::Config _config;
|
||||||
|
|
||||||
std::unique_ptr<libconfig::Config> _config;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user