aboutsummaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/db')
-rw-r--r--src/db/DatabaseGlue.cxx91
-rw-r--r--src/db/DatabaseGlue.hxx28
-rw-r--r--src/db/DatabasePrint.cxx7
-rw-r--r--src/db/DatabaseQueue.cxx3
-rw-r--r--src/db/DatabaseSimple.hxx4
-rw-r--r--src/db/plugins/SimpleDatabasePlugin.hxx3
6 files changed, 16 insertions, 120 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 &param, Error &error)
+ const config_param &param, 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);
}
diff --git a/src/db/DatabaseGlue.hxx b/src/db/DatabaseGlue.hxx
index 78032edb2..f562b6d41 100644
--- a/src/db/DatabaseGlue.hxx
+++ b/src/db/DatabaseGlue.hxx
@@ -32,31 +32,11 @@ class Error;
* Initialize the database library.
*
* @param param the database configuration block
+ * @param is_simple returns whether this is the "simple" database
+ * plugin
*/
-bool
+Database *
DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
- const config_param &param, Error &error);
-
-void
-DatabaseGlobalDeinit(void);
-
-bool
-DatabaseGlobalOpen(Error &error);
-
-/**
- * Returns the global #Database instance. May return nullptr if this MPD
- * configuration has no database (no music_directory was configured).
- */
-gcc_const
-const Database *
-GetDatabase();
-
-/**
- * Returns the global #Database instance. May return nullptr if this MPD
- * configuration has no database (no music_directory was configured).
- */
-gcc_pure
-const Database *
-GetDatabase(Error &error);
+ const config_param &param, bool &is_simple, Error &error);
#endif
diff --git a/src/db/DatabasePrint.cxx b/src/db/DatabasePrint.cxx
index 9ed0b0826..669a804be 100644
--- a/src/db/DatabasePrint.cxx
+++ b/src/db/DatabasePrint.cxx
@@ -28,7 +28,6 @@
#include "LightSong.hxx"
#include "LightDirectory.hxx"
#include "PlaylistInfo.hxx"
-#include "DatabaseGlue.hxx"
#include "DatabasePlugin.hxx"
#include <functional>
@@ -129,7 +128,7 @@ bool
db_selection_print(Client &client, const DatabaseSelection &selection,
bool full, Error &error)
{
- const Database *db = GetDatabase(error);
+ const Database *db = client.GetDatabase(error);
if (db == nullptr)
return false;
@@ -173,7 +172,7 @@ searchStatsForSongsIn(Client &client, const char *name,
const SongFilter *filter,
Error &error)
{
- const Database *db = GetDatabase(error);
+ const Database *db = client.GetDatabase(error);
if (db == nullptr)
return false;
@@ -229,7 +228,7 @@ listAllUniqueTags(Client &client, int type,
const SongFilter *filter,
Error &error)
{
- const Database *db = GetDatabase(error);
+ const Database *db = client.GetDatabase(error);
if (db == nullptr)
return false;
diff --git a/src/db/DatabaseQueue.cxx b/src/db/DatabaseQueue.cxx
index ee1dbd57c..f2a0951a6 100644
--- a/src/db/DatabaseQueue.cxx
+++ b/src/db/DatabaseQueue.cxx
@@ -22,6 +22,7 @@
#include "DatabaseGlue.hxx"
#include "DatabasePlugin.hxx"
#include "Partition.hxx"
+#include "Instance.hxx"
#include "util/Error.hxx"
#include "DetachedSong.hxx"
#include "Mapper.hxx"
@@ -47,7 +48,7 @@ bool
AddFromDatabase(Partition &partition, const DatabaseSelection &selection,
Error &error)
{
- const Database *db = GetDatabase(error);
+ const Database *db = partition.instance.GetDatabase(error);
if (db == nullptr)
return false;
diff --git a/src/db/DatabaseSimple.hxx b/src/db/DatabaseSimple.hxx
index c0f84ab79..1e527958f 100644
--- a/src/db/DatabaseSimple.hxx
+++ b/src/db/DatabaseSimple.hxx
@@ -35,10 +35,6 @@ class Error;
bool
db_is_simple(void);
-gcc_pure
-SimpleDatabase &
-db_get_simple();
-
/**
* Returns true if there is a valid database file on the disk.
*
diff --git a/src/db/plugins/SimpleDatabasePlugin.hxx b/src/db/plugins/SimpleDatabasePlugin.hxx
index 8c7978a91..83434393c 100644
--- a/src/db/plugins/SimpleDatabasePlugin.hxx
+++ b/src/db/plugins/SimpleDatabasePlugin.hxx
@@ -59,6 +59,9 @@ public:
bool Save(Error &error);
+ /**
+ * Returns true if there is a valid database file on the disk.
+ */
bool FileExists() const {
return mtime > 0;
}