db/DatabasePlugin: add #EventLoop parameter documentation

This commit is contained in:
Max Kellermann 2017-08-24 19:45:23 +02:00
parent 0b93f52ba4
commit 7e76656a18
5 changed files with 20 additions and 9 deletions

View File

@ -28,7 +28,8 @@
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
Database * Database *
CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener) CreateConfiguredDatabase(EventLoop &main_event_loop,
DatabaseListener &listener)
{ {
const auto *param = config_get_block(ConfigBlockOption::DATABASE); const auto *param = config_get_block(ConfigBlockOption::DATABASE);
const auto *path = config_get_param(ConfigOption::DB_FILE); const auto *path = config_get_param(ConfigOption::DB_FILE);
@ -38,11 +39,13 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener)
param->line, path->line); param->line, path->line);
if (param != nullptr) if (param != nullptr)
return DatabaseGlobalInit(loop, listener, *param); return DatabaseGlobalInit(main_event_loop,
listener, *param);
else if (path != nullptr) { else if (path != nullptr) {
ConfigBlock block(path->line); ConfigBlock block(path->line);
block.AddBlockParam("path", path->value.c_str(), path->line); block.AddBlockParam("path", path->value.c_str(), path->line);
return DatabaseGlobalInit(loop, listener, block); return DatabaseGlobalInit(main_event_loop,
listener, block);
} else { } else {
/* if there is no override, use the cache directory */ /* if there is no override, use the cache directory */
@ -58,6 +61,7 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener)
ConfigBlock block; ConfigBlock block;
block.AddBlockParam("path", db_file_utf8.c_str(), -1); block.AddBlockParam("path", db_file_utf8.c_str(), -1);
return DatabaseGlobalInit(loop, listener, block); return DatabaseGlobalInit(main_event_loop,
listener, block);
} }
} }

View File

@ -34,6 +34,7 @@ class Database;
* Throws #std::runtime_error on error. * Throws #std::runtime_error on error.
*/ */
Database * Database *
CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener); CreateConfiguredDatabase(EventLoop &main_event_loop,
DatabaseListener &listener);
#endif #endif

View File

@ -26,7 +26,8 @@
#include "DatabasePlugin.hxx" #include "DatabasePlugin.hxx"
Database * Database *
DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener, DatabaseGlobalInit(EventLoop &main_event_loop,
DatabaseListener &listener,
const ConfigBlock &block) const ConfigBlock &block)
{ {
const char *plugin_name = const char *plugin_name =
@ -38,7 +39,7 @@ DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
plugin_name); plugin_name);
try { try {
return plugin->create(loop, listener, block); return plugin->create(main_event_loop, listener, block);
} catch (...) { } catch (...) {
std::throw_with_nested(FormatRuntimeError("Failed to initialize database plugin '%s'", std::throw_with_nested(FormatRuntimeError("Failed to initialize database plugin '%s'",
plugin_name)); plugin_name));

View File

@ -35,7 +35,8 @@ class Database;
* @param block the database configuration block * @param block the database configuration block
*/ */
Database * Database *
DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener, DatabaseGlobalInit(EventLoop &main_event_loop,
DatabaseListener &listener,
const ConfigBlock &block); const ConfigBlock &block);
#endif #endif

View File

@ -46,8 +46,12 @@ struct DatabasePlugin {
* Allocates and configures a database. * Allocates and configures a database.
* *
* Throws #std::runtime_error on error. * Throws #std::runtime_error on error.
*
* @param main_event_loop the #EventLoop running in the same
* thread which invokes #Database methods
*/ */
Database *(*create)(EventLoop &loop, DatabaseListener &listener, Database *(*create)(EventLoop &main_event_loop,
DatabaseListener &listener,
const ConfigBlock &block); const ConfigBlock &block);
constexpr bool RequireStorage() const { constexpr bool RequireStorage() const {