Commit d76b6f87 authored by Max Kellermann's avatar Max Kellermann

db/update/Service: add SimpleDatabase reference

Don't use the global variables from the DatabaseSimple library.
parent f25ef8d6
......@@ -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
......
......@@ -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
......
......@@ -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.
......
......@@ -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 &param,
Error &error);
......
......@@ -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
......
......@@ -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());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment