diff options
author | Max Kellermann <max@duempel.org> | 2014-02-19 23:17:21 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-19 23:17:21 +0100 |
commit | 85b8675e7a11a81bda4b4328e19e433768048911 (patch) | |
tree | fa69fa3360f8790331ddf874608d6411aecc14d4 /src | |
parent | ae594ad92c1a6dc4aee3e83fa4ab94075b0170c1 (diff) | |
download | mpd-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/Main.cxx | 5 | ||||
-rw-r--r-- | src/db/Configured.cxx | 4 | ||||
-rw-r--r-- | src/db/Configured.hxx | 2 | ||||
-rw-r--r-- | src/db/DatabaseGlue.cxx | 3 | ||||
-rw-r--r-- | src/db/DatabaseGlue.hxx | 4 | ||||
-rw-r--r-- | src/db/Interface.hxx | 14 | ||||
-rw-r--r-- | src/db/plugins/LazyDatabase.cxx | 3 | ||||
-rw-r--r-- | src/db/plugins/LazyDatabase.hxx | 3 | ||||
-rw-r--r-- | src/db/plugins/ProxyDatabasePlugin.cxx | 3 | ||||
-rw-r--r-- | src/db/plugins/SimpleDatabasePlugin.cxx | 4 | ||||
-rw-r--r-- | src/db/plugins/SimpleDatabasePlugin.hxx | 3 | ||||
-rw-r--r-- | src/db/plugins/UpnpDatabasePlugin.cxx | 2 |
12 files changed, 34 insertions, 16 deletions
diff --git a/src/Main.cxx b/src/Main.cxx index e52b40d58..8fe90fc6f 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -166,11 +166,10 @@ InitStorage(Error &error) static bool glue_db_init_and_load(void) { - bool is_simple; Error error; instance->database = CreateConfiguredDatabase(*instance->event_loop, *instance, - is_simple, error); + error); if (instance->database == nullptr) { if (error.IsDefined()) FatalError(error); @@ -193,7 +192,7 @@ glue_db_init_and_load(void) if (!instance->database->Open(error)) FatalError(error); - if (!is_simple) + if (!instance->database->IsPlugin(simple_db_plugin)) return true; SimpleDatabase &db = *(SimpleDatabase *)instance->database; 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 ¶m, bool &is_simple, Error &error) + const config_param ¶m, 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 ¶m, bool &is_simple, Error &error); + const config_param ¶m, 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 ¶m, Error &error); |