diff options
author | Max Kellermann <max@duempel.org> | 2014-02-04 08:37:05 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-04 09:05:32 +0100 |
commit | d76b6f878e06d052ab54415783c39997939349e0 (patch) | |
tree | 954eb15c6a1f8eaa033285df551f355f6973d758 /src | |
parent | f25ef8d6825c03aec4569c6ad4b9bfb3a9f5d78d (diff) | |
download | mpd-d76b6f878e06d052ab54415783c39997939349e0.tar.gz mpd-d76b6f878e06d052ab54415783c39997939349e0.tar.xz mpd-d76b6f878e06d052ab54415783c39997939349e0.zip |
db/update/Service: add SimpleDatabase reference
Don't use the global variables from the DatabaseSimple library.
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.cxx | 3 | ||||
-rw-r--r-- | src/db/DatabaseGlue.cxx | 18 | ||||
-rw-r--r-- | src/db/DatabaseSimple.hxx | 21 | ||||
-rw-r--r-- | src/db/plugins/SimpleDatabasePlugin.hxx | 4 | ||||
-rw-r--r-- | src/db/update/Service.hxx | 6 | ||||
-rw-r--r-- | src/db/update/UpdateGlue.cxx | 13 |
6 files changed, 24 insertions, 41 deletions
diff --git a/src/Main.cxx b/src/Main.cxx index 06bef5326..3cedfe267 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -68,6 +68,7 @@ #include "db/update/Service.hxx" #include "db/DatabaseGlue.hxx" #include "db/DatabaseSimple.hxx" +#include "db/plugins/SimpleDatabasePlugin.hxx" #endif #ifdef ENABLE_NEIGHBOR_PLUGINS @@ -460,7 +461,7 @@ int mpd_main(int argc, char *argv[]) const bool create_db = !glue_db_init_and_load(); instance->update = db_is_simple() - ? new UpdateService(*main_loop) + ? new UpdateService(*main_loop, db_get_simple()) : nullptr; #endif diff --git a/src/db/DatabaseGlue.cxx b/src/db/DatabaseGlue.cxx index b8aae5be5..f320633c7 100644 --- a/src/db/DatabaseGlue.cxx +++ b/src/db/DatabaseGlue.cxx @@ -95,23 +95,13 @@ db_is_simple(void) return is_simple; } -Directory * -db_get_root(void) +SimpleDatabase & +db_get_simple() { + assert(is_simple); assert(db != nullptr); - assert(db_is_simple()); - - return ((SimpleDatabase *)db)->GetRoot(); -} - -bool -db_save(Error &error) -{ - assert(db != nullptr); - assert(db_is_open); - assert(db_is_simple()); - return ((SimpleDatabase *)db)->Save(error); + return *(SimpleDatabase *)db; } bool diff --git a/src/db/DatabaseSimple.hxx b/src/db/DatabaseSimple.hxx index 5d5680d43..c0f84ab79 100644 --- a/src/db/DatabaseSimple.hxx +++ b/src/db/DatabaseSimple.hxx @@ -22,12 +22,9 @@ #include "Compiler.h" -#include <sys/time.h> - struct config_param; struct Directory; -struct db_selection; -struct db_visitor; +class SimpleDatabase; class Error; /** @@ -38,21 +35,9 @@ class Error; bool db_is_simple(void); -/** - * Returns the root directory object. Returns NULL if there is no - * configured music directory. - * - * May only be used if db_is_simple() returns true. - */ gcc_pure -Directory * -db_get_root(void); - -/** - * May only be used if db_is_simple() returns true. - */ -bool -db_save(Error &error); +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 137a60884..8c7978a91 100644 --- a/src/db/plugins/SimpleDatabasePlugin.hxx +++ b/src/db/plugins/SimpleDatabasePlugin.hxx @@ -59,6 +59,10 @@ public: bool Save(Error &error); + bool FileExists() const { + return mtime > 0; + } + static Database *Create(EventLoop &loop, DatabaseListener &listener, const config_param ¶m, Error &error); diff --git a/src/db/update/Service.hxx b/src/db/update/Service.hxx index 3ea4baea1..815be6dbc 100644 --- a/src/db/update/Service.hxx +++ b/src/db/update/Service.hxx @@ -26,6 +26,8 @@ #include "event/DeferredMonitor.hxx" #include "thread/Thread.hxx" +class SimpleDatabase; + /** * This class manages the update queue and runs the update thread. */ @@ -36,6 +38,8 @@ class UpdateService final : DeferredMonitor { UPDATE_PROGRESS_DONE = 2 }; + SimpleDatabase &db; + Progress progress; bool modified; @@ -53,7 +57,7 @@ class UpdateService final : DeferredMonitor { UpdateWalk walk; public: - UpdateService(EventLoop &_loop); + UpdateService(EventLoop &_loop, SimpleDatabase &_db); /** * Returns a non-zero job id when we are currently updating diff --git a/src/db/update/UpdateGlue.cxx b/src/db/update/UpdateGlue.cxx index 742fbfe98..a13d56926 100644 --- a/src/db/update/UpdateGlue.cxx +++ b/src/db/update/UpdateGlue.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "Service.hxx" #include "UpdateDomain.hxx" -#include "db/DatabaseSimple.hxx" +#include "db/plugins/SimpleDatabasePlugin.hxx" #include "Idle.hxx" #include "util/Error.hxx" #include "Log.hxx" @@ -44,12 +44,12 @@ UpdateService::Task() SetThreadIdlePriority(); - modified = walk.Walk(*db_get_root(), next.path_utf8.c_str(), + modified = walk.Walk(*db.GetRoot(), next.path_utf8.c_str(), next.discard); - if (modified || !db_exists()) { + if (modified || !db.FileExists()) { Error error; - if (!db_save(error)) + if (!db.Save(error)) LogError(error, "Failed to save database"); } @@ -146,8 +146,7 @@ UpdateService::RunDeferred() } } -UpdateService::UpdateService(EventLoop &_loop) - :DeferredMonitor(_loop), walk(_loop) +UpdateService::UpdateService(EventLoop &_loop, SimpleDatabase &_db) + :DeferredMonitor(_loop), db(_db), walk(_loop) { - assert(db_is_simple()); } |