diff options
author | Max Kellermann <max@musicpd.org> | 2018-11-19 19:19:20 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-11-19 19:38:20 +0100 |
commit | bda77ffc5b0893a16983b4e3da5ced5beae1ab1f (patch) | |
tree | 34362ac233aa3b55313d1c4f8e3772017382d187 /src | |
parent | ed9ece5ea309bf443acc957dc0b772195db51747 (diff) |
db/Interface: remove IsPlugin(), use `dynamic_cast` instead
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.cxx | 8 | ||||
-rw-r--r-- | src/command/StorageCommands.cxx | 14 | ||||
-rw-r--r-- | src/db/Interface.hxx | 4 | ||||
-rw-r--r-- | src/db/update/Service.cxx | 14 | ||||
-rw-r--r-- | src/storage/StorageState.cxx | 5 |
5 files changed, 15 insertions, 30 deletions
diff --git a/src/Main.cxx b/src/Main.cxx index f9f854486..211627e63 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -216,17 +216,17 @@ glue_db_init_and_load(const ConfigData &config) std::throw_with_nested(std::runtime_error("Failed to open database plugin")); } - if (!instance->database->IsPlugin(simple_db_plugin)) + auto *db = dynamic_cast<SimpleDatabase *>(instance->database); + if (db == nullptr) return true; - SimpleDatabase &db = *(SimpleDatabase *)instance->database; instance->update = new UpdateService(config, - instance->event_loop, db, + instance->event_loop, *db, static_cast<CompositeStorage &>(*instance->storage), *instance); /* run database update after daemonization? */ - return db.FileExists(); + return db->FileExists(); } static bool diff --git a/src/command/StorageCommands.cxx b/src/command/StorageCommands.cxx index cd016586a..ef779a318 100644 --- a/src/command/StorageCommands.cxx +++ b/src/command/StorageCommands.cxx @@ -209,12 +209,9 @@ handle_mount(Client &client, Request args, Response &r) instance.EmitIdle(IDLE_MOUNT); #ifdef ENABLE_DATABASE - Database *_db = instance.database; - if (_db != nullptr && _db->IsPlugin(simple_db_plugin)) { - SimpleDatabase &db = *(SimpleDatabase *)_db; - + if (auto *db = dynamic_cast<SimpleDatabase *>(instance.database)) { try { - db.Mount(local_uri, remote_uri); + db->Mount(local_uri, remote_uri); } catch (...) { composite.Unmount(local_uri); throw; @@ -256,11 +253,8 @@ handle_unmount(Client &client, Request args, Response &r) destroy here */ instance.update->CancelMount(local_uri); - Database *_db = instance.database; - if (_db != nullptr && _db->IsPlugin(simple_db_plugin)) { - SimpleDatabase &db = *(SimpleDatabase *)_db; - - if (db.Unmount(local_uri)) + if (auto *db = dynamic_cast<SimpleDatabase *>(instance.database)) { + if (db->Unmount(local_uri)) // TODO: call Instance::OnDatabaseModified()? instance.EmitIdle(IDLE_DATABASE); } diff --git a/src/db/Interface.hxx b/src/db/Interface.hxx index e7986d6f7..7a700557f 100644 --- a/src/db/Interface.hxx +++ b/src/db/Interface.hxx @@ -52,10 +52,6 @@ public: return plugin; } - bool IsPlugin(const DatabasePlugin &other) const noexcept { - return &plugin == &other; - } - /** * Open the database. Read it into memory if applicable. * diff --git a/src/db/update/Service.cxx b/src/db/update/Service.cxx index deb60a45c..377e80147 100644 --- a/src/db/update/Service.cxx +++ b/src/db/update/Service.cxx @@ -94,11 +94,9 @@ UpdateService::CancelMount(const char *uri) cancel_current = next.IsDefined() && next.storage == storage2; } - Database &_db2 = *lr.directory->mounted_database; - if (_db2.IsPlugin(simple_db_plugin)) { - SimpleDatabase &db2 = static_cast<SimpleDatabase &>(_db2); - queue.Erase(db2); - cancel_current |= next.IsDefined() && next.db == &db2; + if (auto *db2 = dynamic_cast<SimpleDatabase *>(lr.directory->mounted_database)) { + queue.Erase(*db2); + cancel_current |= next.IsDefined() && next.db == db2; } if (cancel_current && walk != nullptr) { @@ -190,12 +188,10 @@ UpdateService::Enqueue(const char *path, bool discard) /* follow the mountpoint, update the mounted database */ - Database &_db2 = *lr.directory->mounted_database; - if (!_db2.IsPlugin(simple_db_plugin)) + db2 = dynamic_cast<SimpleDatabase *>(lr.directory->mounted_database); + if (db2 == nullptr) throw std::runtime_error("Cannot update this type of database"); - db2 = static_cast<SimpleDatabase *>(&_db2); - if (lr.uri == nullptr) { storage2 = storage.GetMount(path); path = ""; diff --git a/src/storage/StorageState.cxx b/src/storage/StorageState.cxx index c26ca2104..5cf2f4428 100644 --- a/src/storage/StorageState.cxx +++ b/src/storage/StorageState.cxx @@ -106,10 +106,9 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance) return true; } - Database *db = instance.database; - if (db != nullptr && db->IsPlugin(simple_db_plugin)) { + if (auto *db = dynamic_cast<SimpleDatabase *>(instance.database)) { try { - ((SimpleDatabase *)db)->Mount(uri.c_str(), url.c_str()); + db->Mount(uri.c_str(), url.c_str()); } catch (...) { FormatError(std::current_exception(), "Failed to restore mount to %s", |