2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2008-10-08 11:07:35 +02:00
|
|
|
|
2012-08-02 18:39:17 +02:00
|
|
|
#include "DatabaseGlue.hxx"
|
2022-11-28 21:58:21 +01:00
|
|
|
#include "DatabasePlugin.hxx"
|
2019-02-20 20:32:11 +01:00
|
|
|
#include "Interface.hxx"
|
2014-01-24 16:18:50 +01:00
|
|
|
#include "Registry.hxx"
|
2015-01-21 22:13:44 +01:00
|
|
|
#include "config/Block.hxx"
|
2022-11-28 21:58:21 +01:00
|
|
|
#include "lib/fmt/RuntimeError.hxx"
|
2008-10-08 11:07:35 +02:00
|
|
|
|
2019-02-20 20:32:11 +01:00
|
|
|
DatabasePtr
|
2017-08-24 19:45:23 +02:00
|
|
|
DatabaseGlobalInit(EventLoop &main_event_loop,
|
2017-08-24 19:49:54 +02:00
|
|
|
EventLoop &io_event_loop,
|
2017-08-24 19:45:23 +02:00
|
|
|
DatabaseListener &listener,
|
2016-10-28 23:00:10 +02:00
|
|
|
const ConfigBlock &block)
|
2008-10-08 11:07:35 +02:00
|
|
|
{
|
2012-08-08 08:46:16 +02:00
|
|
|
const char *plugin_name =
|
2015-01-21 22:13:44 +01:00
|
|
|
block.GetBlockValue("plugin", "simple");
|
2013-01-02 19:19:40 +01:00
|
|
|
|
2012-08-08 08:46:16 +02:00
|
|
|
const DatabasePlugin *plugin = GetDatabasePluginByName(plugin_name);
|
2016-10-28 23:00:10 +02:00
|
|
|
if (plugin == nullptr)
|
2022-11-28 21:58:21 +01:00
|
|
|
throw FmtRuntimeError("No such database plugin: {}",
|
|
|
|
plugin_name);
|
2012-08-08 08:46:16 +02:00
|
|
|
|
2017-01-23 18:52:11 +01:00
|
|
|
try {
|
2017-08-24 19:49:54 +02:00
|
|
|
return plugin->create(main_event_loop, io_event_loop,
|
|
|
|
listener, block);
|
2017-01-23 18:52:11 +01:00
|
|
|
} catch (...) {
|
2022-11-28 21:58:21 +01:00
|
|
|
std::throw_with_nested(FmtRuntimeError("Failed to initialize database plugin '{}'",
|
|
|
|
plugin_name));
|
2017-01-23 18:52:11 +01:00
|
|
|
}
|
2008-10-08 11:07:35 +02:00
|
|
|
}
|