aboutsummaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-02-19 23:17:21 +0100
committerMax Kellermann <max@duempel.org>2014-02-19 23:17:21 +0100
commit85b8675e7a11a81bda4b4328e19e433768048911 (patch)
treefa69fa3360f8790331ddf874608d6411aecc14d4 /src/db
parentae594ad92c1a6dc4aee3e83fa4ab94075b0170c1 (diff)
downloadmpd-85b8675e7a11a81bda4b4328e19e433768048911.tar.gz
mpd-85b8675e7a11a81bda4b4328e19e433768048911.tar.xz
mpd-85b8675e7a11a81bda4b4328e19e433768048911.zip
db/Interface: add attribute "plugin"
The new method IsPlugin() replaces the "is_simple" flag.
Diffstat (limited to '')
-rw-r--r--src/db/Configured.cxx4
-rw-r--r--src/db/Configured.hxx2
-rw-r--r--src/db/DatabaseGlue.cxx3
-rw-r--r--src/db/DatabaseGlue.hxx4
-rw-r--r--src/db/Interface.hxx14
-rw-r--r--src/db/plugins/LazyDatabase.cxx3
-rw-r--r--src/db/plugins/LazyDatabase.hxx3
-rw-r--r--src/db/plugins/ProxyDatabasePlugin.cxx3
-rw-r--r--src/db/plugins/SimpleDatabasePlugin.cxx4
-rw-r--r--src/db/plugins/SimpleDatabasePlugin.hxx3
-rw-r--r--src/db/plugins/UpnpDatabasePlugin.cxx2
11 files changed, 32 insertions, 13 deletions
diff --git a/src/db/Configured.cxx b/src/db/Configured.cxx
index edd3159f9..14471402a 100644
--- a/src/db/Configured.cxx
+++ b/src/db/Configured.cxx
@@ -28,7 +28,7 @@
Database *
CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
- bool &is_simple_r, Error &error)
+ Error &error)
{
const struct config_param *param = config_get_param(CONF_DATABASE);
const struct config_param *path = config_get_param(CONF_DB_FILE);
@@ -53,7 +53,7 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
return nullptr;
Database *db = DatabaseGlobalInit(loop, listener, *param,
- is_simple_r, error);
+ error);
delete allocated;
return db;
}
diff --git a/src/db/Configured.hxx b/src/db/Configured.hxx
index 4e4299bfc..5d25b701c 100644
--- a/src/db/Configured.hxx
+++ b/src/db/Configured.hxx
@@ -34,6 +34,6 @@ class Error;
*/
Database *
CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
- bool &is_simple_r, Error &error);
+ Error &error);
#endif
diff --git a/src/db/DatabaseGlue.cxx b/src/db/DatabaseGlue.cxx
index 30c244334..ade5c95f3 100644
--- a/src/db/DatabaseGlue.cxx
+++ b/src/db/DatabaseGlue.cxx
@@ -29,11 +29,10 @@
Database *
DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
- const config_param &param, bool &is_simple, Error &error)
+ const config_param &param, Error &error)
{
const char *plugin_name =
param.GetBlockValue("plugin", "simple");
- is_simple = strcmp(plugin_name, "simple") == 0;
const DatabasePlugin *plugin = GetDatabasePluginByName(plugin_name);
if (plugin == nullptr) {
diff --git a/src/db/DatabaseGlue.hxx b/src/db/DatabaseGlue.hxx
index f562b6d41..70b50def3 100644
--- a/src/db/DatabaseGlue.hxx
+++ b/src/db/DatabaseGlue.hxx
@@ -32,11 +32,9 @@ class Error;
* Initialize the database library.
*
* @param param the database configuration block
- * @param is_simple returns whether this is the "simple" database
- * plugin
*/
Database *
DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
- const config_param &param, bool &is_simple, Error &error);
+ const config_param &param, Error &error);
#endif
diff --git a/src/db/Interface.hxx b/src/db/Interface.hxx
index 4ce927336..11e2da12e 100644
--- a/src/db/Interface.hxx
+++ b/src/db/Interface.hxx
@@ -26,18 +26,32 @@
#include <time.h>
+struct DatabasePlugin;
struct DatabaseStats;
struct DatabaseSelection;
struct LightSong;
class Error;
class Database {
+ const DatabasePlugin &plugin;
+
public:
+ Database(const DatabasePlugin &_plugin)
+ :plugin(_plugin) {}
+
/**
* Free instance data.
*/
virtual ~Database() {}
+ const DatabasePlugin &GetPlugin() const {
+ return plugin;
+ }
+
+ bool IsPlugin(const DatabasePlugin &other) const {
+ return &plugin == &other;
+ }
+
/**
* Open the database. Read it into memory if applicable.
*/
diff --git a/src/db/plugins/LazyDatabase.cxx b/src/db/plugins/LazyDatabase.cxx
index ffa861e36..2b576b1ee 100644
--- a/src/db/plugins/LazyDatabase.cxx
+++ b/src/db/plugins/LazyDatabase.cxx
@@ -23,6 +23,9 @@
#include <assert.h>
+LazyDatabase::LazyDatabase(Database *_db)
+ :Database(_db->GetPlugin()), db(_db), open(false) {}
+
LazyDatabase::~LazyDatabase()
{
assert(!open);
diff --git a/src/db/plugins/LazyDatabase.hxx b/src/db/plugins/LazyDatabase.hxx
index f3fbef5f3..000b63a98 100644
--- a/src/db/plugins/LazyDatabase.hxx
+++ b/src/db/plugins/LazyDatabase.hxx
@@ -35,8 +35,7 @@ class LazyDatabase final : public Database {
public:
gcc_nonnull_all
- LazyDatabase(Database *_db)
- :db(_db), open(false) {}
+ LazyDatabase(Database *_db);
virtual ~LazyDatabase();
diff --git a/src/db/plugins/ProxyDatabasePlugin.cxx b/src/db/plugins/ProxyDatabasePlugin.cxx
index c09468869..035ded8c3 100644
--- a/src/db/plugins/ProxyDatabasePlugin.cxx
+++ b/src/db/plugins/ProxyDatabasePlugin.cxx
@@ -91,7 +91,8 @@ class ProxyDatabase final : public Database, SocketMonitor, IdleMonitor {
public:
ProxyDatabase(EventLoop &_loop, DatabaseListener &_listener)
- :SocketMonitor(_loop), IdleMonitor(_loop),
+ :Database(proxy_db_plugin),
+ SocketMonitor(_loop), IdleMonitor(_loop),
listener(_listener) {}
static Database *Create(EventLoop &loop, DatabaseListener &listener,
diff --git a/src/db/plugins/SimpleDatabasePlugin.cxx b/src/db/plugins/SimpleDatabasePlugin.cxx
index cd13b70cb..9d8966158 100644
--- a/src/db/plugins/SimpleDatabasePlugin.cxx
+++ b/src/db/plugins/SimpleDatabasePlugin.cxx
@@ -40,6 +40,10 @@
static constexpr Domain simple_db_domain("simple_db");
+inline SimpleDatabase::SimpleDatabase()
+ :Database(simple_db_plugin),
+ path(AllocatedPath::Null()) {}
+
Database *
SimpleDatabase::Create(gcc_unused EventLoop &loop,
gcc_unused DatabaseListener &listener,
diff --git a/src/db/plugins/SimpleDatabasePlugin.hxx b/src/db/plugins/SimpleDatabasePlugin.hxx
index 49e3d987d..83a8dc491 100644
--- a/src/db/plugins/SimpleDatabasePlugin.hxx
+++ b/src/db/plugins/SimpleDatabasePlugin.hxx
@@ -50,8 +50,7 @@ class SimpleDatabase : public Database {
mutable unsigned borrowed_song_count;
#endif
- SimpleDatabase()
- :path(AllocatedPath::Null()) {}
+ SimpleDatabase();
public:
gcc_pure
diff --git a/src/db/plugins/UpnpDatabasePlugin.cxx b/src/db/plugins/UpnpDatabasePlugin.cxx
index f7d3a1932..9348d3297 100644
--- a/src/db/plugins/UpnpDatabasePlugin.cxx
+++ b/src/db/plugins/UpnpDatabasePlugin.cxx
@@ -75,6 +75,8 @@ class UpnpDatabase : public Database {
UPnPDeviceDirectory *discovery;
public:
+ UpnpDatabase():Database(upnp_db_plugin) {}
+
static Database *Create(EventLoop &loop, DatabaseListener &listener,
const config_param &param,
Error &error);