db/DatabasePlugin: pass EventThread's EventLoop to create()
Allows database plugins to use the EventThread, e.g. for CURL integration.
This commit is contained in:
parent
7e76656a18
commit
28a2d41b85
@ -193,7 +193,9 @@ static bool
|
||||
glue_db_init_and_load(void)
|
||||
{
|
||||
instance->database =
|
||||
CreateConfiguredDatabase(instance->event_loop, *instance);
|
||||
CreateConfiguredDatabase(instance->event_loop,
|
||||
instance->io_thread.GetEventLoop(),
|
||||
*instance);
|
||||
if (instance->database == nullptr)
|
||||
return true;
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
Database *
|
||||
CreateConfiguredDatabase(EventLoop &main_event_loop,
|
||||
CreateConfiguredDatabase(EventLoop &main_event_loop, EventLoop &io_event_loop,
|
||||
DatabaseListener &listener)
|
||||
{
|
||||
const auto *param = config_get_block(ConfigBlockOption::DATABASE);
|
||||
@ -39,12 +39,12 @@ CreateConfiguredDatabase(EventLoop &main_event_loop,
|
||||
param->line, path->line);
|
||||
|
||||
if (param != nullptr)
|
||||
return DatabaseGlobalInit(main_event_loop,
|
||||
return DatabaseGlobalInit(main_event_loop, io_event_loop,
|
||||
listener, *param);
|
||||
else if (path != nullptr) {
|
||||
ConfigBlock block(path->line);
|
||||
block.AddBlockParam("path", path->value.c_str(), path->line);
|
||||
return DatabaseGlobalInit(main_event_loop,
|
||||
return DatabaseGlobalInit(main_event_loop, io_event_loop,
|
||||
listener, block);
|
||||
} else {
|
||||
/* if there is no override, use the cache directory */
|
||||
@ -61,7 +61,7 @@ CreateConfiguredDatabase(EventLoop &main_event_loop,
|
||||
|
||||
ConfigBlock block;
|
||||
block.AddBlockParam("path", db_file_utf8.c_str(), -1);
|
||||
return DatabaseGlobalInit(main_event_loop,
|
||||
return DatabaseGlobalInit(main_event_loop, io_event_loop,
|
||||
listener, block);
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class Database;
|
||||
* Throws #std::runtime_error on error.
|
||||
*/
|
||||
Database *
|
||||
CreateConfiguredDatabase(EventLoop &main_event_loop,
|
||||
CreateConfiguredDatabase(EventLoop &main_event_loop, EventLoop &io_event_loop,
|
||||
DatabaseListener &listener);
|
||||
|
||||
#endif
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
Database *
|
||||
DatabaseGlobalInit(EventLoop &main_event_loop,
|
||||
EventLoop &io_event_loop,
|
||||
DatabaseListener &listener,
|
||||
const ConfigBlock &block)
|
||||
{
|
||||
@ -39,7 +40,8 @@ DatabaseGlobalInit(EventLoop &main_event_loop,
|
||||
plugin_name);
|
||||
|
||||
try {
|
||||
return plugin->create(main_event_loop, listener, block);
|
||||
return plugin->create(main_event_loop, io_event_loop,
|
||||
listener, block);
|
||||
} catch (...) {
|
||||
std::throw_with_nested(FormatRuntimeError("Failed to initialize database plugin '%s'",
|
||||
plugin_name));
|
||||
|
@ -36,6 +36,7 @@ class Database;
|
||||
*/
|
||||
Database *
|
||||
DatabaseGlobalInit(EventLoop &main_event_loop,
|
||||
EventLoop &io_event_loop,
|
||||
DatabaseListener &listener,
|
||||
const ConfigBlock &block);
|
||||
|
||||
|
@ -49,8 +49,11 @@ struct DatabasePlugin {
|
||||
*
|
||||
* @param main_event_loop the #EventLoop running in the same
|
||||
* thread which invokes #Database methods
|
||||
* @param io_event_loop the #EventLoop running on the
|
||||
* #EventThread, i.e. the one used for background I/O
|
||||
*/
|
||||
Database *(*create)(EventLoop &main_event_loop,
|
||||
EventLoop &io_event_loop,
|
||||
DatabaseListener &listener,
|
||||
const ConfigBlock &block);
|
||||
|
||||
|
@ -107,7 +107,9 @@ public:
|
||||
ProxyDatabase(EventLoop &_loop, DatabaseListener &_listener,
|
||||
const ConfigBlock &block);
|
||||
|
||||
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
||||
static Database *Create(EventLoop &main_event_loop,
|
||||
EventLoop &io_event_loop,
|
||||
DatabaseListener &listener,
|
||||
const ConfigBlock &block);
|
||||
|
||||
void Open() override;
|
||||
@ -345,7 +347,8 @@ ProxyDatabase::ProxyDatabase(EventLoop &_loop, DatabaseListener &_listener,
|
||||
}
|
||||
|
||||
Database *
|
||||
ProxyDatabase::Create(EventLoop &loop, DatabaseListener &listener,
|
||||
ProxyDatabase::Create(EventLoop &loop, EventLoop &,
|
||||
DatabaseListener &listener,
|
||||
const ConfigBlock &block)
|
||||
{
|
||||
return new ProxyDatabase(loop, listener, block);
|
||||
|
@ -83,7 +83,7 @@ inline SimpleDatabase::SimpleDatabase(AllocatedPath &&_path,
|
||||
}
|
||||
|
||||
Database *
|
||||
SimpleDatabase::Create(gcc_unused EventLoop &loop,
|
||||
SimpleDatabase::Create(EventLoop &, EventLoop &,
|
||||
gcc_unused DatabaseListener &listener,
|
||||
const ConfigBlock &block)
|
||||
{
|
||||
|
@ -72,7 +72,9 @@ class SimpleDatabase : public Database {
|
||||
SimpleDatabase(AllocatedPath &&_path, bool _compress);
|
||||
|
||||
public:
|
||||
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
||||
static Database *Create(EventLoop &main_event_loop,
|
||||
EventLoop &io_event_loop,
|
||||
DatabaseListener &listener,
|
||||
const ConfigBlock &block);
|
||||
|
||||
gcc_pure
|
||||
|
@ -75,7 +75,9 @@ class UpnpDatabase : public Database {
|
||||
public:
|
||||
UpnpDatabase():Database(upnp_db_plugin) {}
|
||||
|
||||
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
||||
static Database *Create(EventLoop &main_event_loop,
|
||||
EventLoop &io_event_loop,
|
||||
DatabaseListener &listener,
|
||||
const ConfigBlock &block);
|
||||
|
||||
void Open() override;
|
||||
@ -138,7 +140,7 @@ private:
|
||||
};
|
||||
|
||||
Database *
|
||||
UpnpDatabase::Create(gcc_unused EventLoop &loop,
|
||||
UpnpDatabase::Create(EventLoop &, EventLoop &,
|
||||
gcc_unused DatabaseListener &listener,
|
||||
const ConfigBlock &)
|
||||
{
|
||||
|
@ -138,6 +138,7 @@ try {
|
||||
block.AddBlockParam("path", path->value.c_str(), path->line);
|
||||
|
||||
Database *db = plugin->create(init.GetEventLoop(),
|
||||
init.GetEventLoop(),
|
||||
database_listener, block);
|
||||
|
||||
AtScopeExit(db) { delete db; };
|
||||
|
Loading…
Reference in New Issue
Block a user