storage/Configured: use struct ConfigData
This commit is contained in:
parent
667daab056
commit
d2594c6380
@ -166,9 +166,9 @@ glue_mapper_init(const ConfigData &config)
|
|||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
|
|
||||||
static void
|
static void
|
||||||
InitStorage(EventLoop &event_loop)
|
InitStorage(const ConfigData &config, EventLoop &event_loop)
|
||||||
{
|
{
|
||||||
auto storage = CreateConfiguredStorage(event_loop);
|
auto storage = CreateConfiguredStorage(config, event_loop);
|
||||||
if (storage == nullptr)
|
if (storage == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ glue_db_init_and_load(const ConfigData &config)
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (instance->database->GetPlugin().flags & DatabasePlugin::FLAG_REQUIRE_STORAGE) {
|
if (instance->database->GetPlugin().flags & DatabasePlugin::FLAG_REQUIRE_STORAGE) {
|
||||||
InitStorage(instance->io_thread.GetEventLoop());
|
InitStorage(config, instance->io_thread.GetEventLoop());
|
||||||
|
|
||||||
if (instance->storage == nullptr) {
|
if (instance->storage == nullptr) {
|
||||||
delete instance->database;
|
delete instance->database;
|
||||||
@ -204,7 +204,7 @@ glue_db_init_and_load(const ConfigData &config)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (IsStorageConfigured())
|
if (IsStorageConfigured(config))
|
||||||
LogDefault(config_domain,
|
LogDefault(config_domain,
|
||||||
"Ignoring the storage configuration "
|
"Ignoring the storage configuration "
|
||||||
"because the database does not need it");
|
"because the database does not need it");
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include "Registry.hxx"
|
#include "Registry.hxx"
|
||||||
#include "StorageInterface.hxx"
|
#include "StorageInterface.hxx"
|
||||||
#include "plugins/LocalStorage.hxx"
|
#include "plugins/LocalStorage.hxx"
|
||||||
#include "config/Global.hxx"
|
#include "config/Data.hxx"
|
||||||
#include "config/Domain.hxx"
|
#include "config/Domain.hxx"
|
||||||
#include "fs/StandardDirectory.hxx"
|
#include "fs/StandardDirectory.hxx"
|
||||||
#include "fs/CheckFile.hxx"
|
#include "fs/CheckFile.hxx"
|
||||||
@ -42,9 +42,9 @@ CreateConfiguredStorageUri(EventLoop &event_loop, const char *uri)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static AllocatedPath
|
static AllocatedPath
|
||||||
GetConfiguredMusicDirectory()
|
GetConfiguredMusicDirectory(const ConfigData &config)
|
||||||
{
|
{
|
||||||
AllocatedPath path = config_get_path(ConfigOption::MUSIC_DIR);
|
AllocatedPath path = config.GetPath(ConfigOption::MUSIC_DIR);
|
||||||
if (path.IsNull())
|
if (path.IsNull())
|
||||||
path = GetUserMusicDir();
|
path = GetUserMusicDir();
|
||||||
|
|
||||||
@ -52,9 +52,9 @@ GetConfiguredMusicDirectory()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static std::unique_ptr<Storage>
|
static std::unique_ptr<Storage>
|
||||||
CreateConfiguredStorageLocal()
|
CreateConfiguredStorageLocal(const ConfigData &config)
|
||||||
{
|
{
|
||||||
AllocatedPath path = GetConfiguredMusicDirectory();
|
AllocatedPath path = GetConfiguredMusicDirectory(config);
|
||||||
if (path.IsNull())
|
if (path.IsNull())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
@ -64,17 +64,17 @@ CreateConfiguredStorageLocal()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Storage>
|
std::unique_ptr<Storage>
|
||||||
CreateConfiguredStorage(EventLoop &event_loop)
|
CreateConfiguredStorage(const ConfigData &config, EventLoop &event_loop)
|
||||||
{
|
{
|
||||||
auto uri = config_get_string(ConfigOption::MUSIC_DIR);
|
auto uri = config.GetString(ConfigOption::MUSIC_DIR);
|
||||||
if (uri != nullptr && uri_has_scheme(uri))
|
if (uri != nullptr && uri_has_scheme(uri))
|
||||||
return CreateConfiguredStorageUri(event_loop, uri);
|
return CreateConfiguredStorageUri(event_loop, uri);
|
||||||
|
|
||||||
return CreateConfiguredStorageLocal();
|
return CreateConfiguredStorageLocal(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
IsStorageConfigured() noexcept
|
IsStorageConfigured(const ConfigData &config) noexcept
|
||||||
{
|
{
|
||||||
return config_get_string(ConfigOption::MUSIC_DIR) != nullptr;
|
return config.GetParam(ConfigOption::MUSIC_DIR) != nullptr;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
struct ConfigData;
|
||||||
class Storage;
|
class Storage;
|
||||||
class EventLoop;
|
class EventLoop;
|
||||||
|
|
||||||
@ -35,13 +36,13 @@ class EventLoop;
|
|||||||
* Throws #std::runtime_error on error.
|
* Throws #std::runtime_error on error.
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<Storage>
|
std::unique_ptr<Storage>
|
||||||
CreateConfiguredStorage(EventLoop &event_loop);
|
CreateConfiguredStorage(const ConfigData &config, EventLoop &event_loop);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if there is configuration for a #Storage instance.
|
* Returns true if there is configuration for a #Storage instance.
|
||||||
*/
|
*/
|
||||||
gcc_const
|
gcc_const
|
||||||
bool
|
bool
|
||||||
IsStorageConfigured() noexcept;
|
IsStorageConfigured(const ConfigData &config) noexcept;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user