diff options
author | Max Kellermann <max@duempel.org> | 2014-02-01 00:26:34 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-04 11:22:33 +0100 |
commit | cf6281a5a758e4b93d67f7fd5804a8cff60ddbf9 (patch) | |
tree | 7368011b1ecf5ae6db6dcafb676fddf03ff9d823 /src/db/DatabaseGlue.cxx | |
parent | f00710a57e80738c33255eaa1347ab776fbce869 (diff) | |
download | mpd-cf6281a5a758e4b93d67f7fd5804a8cff60ddbf9.tar.gz mpd-cf6281a5a758e4b93d67f7fd5804a8cff60ddbf9.tar.xz mpd-cf6281a5a758e4b93d67f7fd5804a8cff60ddbf9.zip |
Instance: add Database attribute
Move from db/DatabaseGlue.cxx, eliminating global variable.
Diffstat (limited to 'src/db/DatabaseGlue.cxx')
-rw-r--r-- | src/db/DatabaseGlue.cxx | 91 |
1 files changed, 4 insertions, 87 deletions
diff --git a/src/db/DatabaseGlue.cxx b/src/db/DatabaseGlue.cxx index f320633c7..30c244334 100644 --- a/src/db/DatabaseGlue.cxx +++ b/src/db/DatabaseGlue.cxx @@ -19,30 +19,18 @@ #include "config.h" #include "DatabaseGlue.hxx" -#include "DatabaseSimple.hxx" #include "Registry.hxx" #include "DatabaseError.hxx" -#include "Directory.hxx" #include "util/Error.hxx" #include "config/ConfigData.hxx" -#include "Stats.hxx" #include "DatabasePlugin.hxx" -#include "plugins/SimpleDatabasePlugin.hxx" -#include <assert.h> #include <string.h> -static Database *db; -static bool db_is_open; -static bool is_simple; - -bool +Database * DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener, - const config_param ¶m, Error &error) + const config_param ¶m, bool &is_simple, Error &error) { - assert(db == nullptr); - assert(!db_is_open); - const char *plugin_name = param.GetBlockValue("plugin", "simple"); is_simple = strcmp(plugin_name, "simple") == 0; @@ -51,79 +39,8 @@ DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener, if (plugin == nullptr) { error.Format(db_domain, "No such database plugin: %s", plugin_name); - return false; + return nullptr; } - db = plugin->create(loop, listener, param, error); - return db != nullptr; -} - -void -DatabaseGlobalDeinit(void) -{ - if (db_is_open) - db->Close(); - - if (db != nullptr) - delete db; -} - -const Database * -GetDatabase() -{ - assert(db == nullptr || db_is_open); - - return db; -} - -const Database * -GetDatabase(Error &error) -{ - assert(db == nullptr || db_is_open); - - if (db == nullptr) - error.Set(db_domain, DB_DISABLED, "No database"); - - return db; -} - -bool -db_is_simple(void) -{ - assert(db == nullptr || db_is_open); - - return is_simple; -} - -SimpleDatabase & -db_get_simple() -{ - assert(is_simple); - assert(db != nullptr); - - return *(SimpleDatabase *)db; -} - -bool -DatabaseGlobalOpen(Error &error) -{ - assert(db != nullptr); - assert(!db_is_open); - - if (!db->Open(error)) - return false; - - db_is_open = true; - - return true; -} - -bool -db_exists() -{ - assert(db != nullptr); - assert(db_is_open); - assert(db_is_simple()); - - return ((SimpleDatabase *)db)->GetUpdateStamp() > 0; + return plugin->create(loop, listener, param, error); } |