db/update/Service: add SimpleDatabase reference
Don't use the global variables from the DatabaseSimple library.
This commit is contained in:
parent
f25ef8d682
commit
d76b6f878e
@ -68,6 +68,7 @@
|
|||||||
#include "db/update/Service.hxx"
|
#include "db/update/Service.hxx"
|
||||||
#include "db/DatabaseGlue.hxx"
|
#include "db/DatabaseGlue.hxx"
|
||||||
#include "db/DatabaseSimple.hxx"
|
#include "db/DatabaseSimple.hxx"
|
||||||
|
#include "db/plugins/SimpleDatabasePlugin.hxx"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
||||||
@ -460,7 +461,7 @@ int mpd_main(int argc, char *argv[])
|
|||||||
const bool create_db = !glue_db_init_and_load();
|
const bool create_db = !glue_db_init_and_load();
|
||||||
|
|
||||||
instance->update = db_is_simple()
|
instance->update = db_is_simple()
|
||||||
? new UpdateService(*main_loop)
|
? new UpdateService(*main_loop, db_get_simple())
|
||||||
: nullptr;
|
: nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -95,23 +95,13 @@ db_is_simple(void)
|
|||||||
return is_simple;
|
return is_simple;
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory *
|
SimpleDatabase &
|
||||||
db_get_root(void)
|
db_get_simple()
|
||||||
{
|
{
|
||||||
|
assert(is_simple);
|
||||||
assert(db != nullptr);
|
assert(db != nullptr);
|
||||||
assert(db_is_simple());
|
|
||||||
|
|
||||||
return ((SimpleDatabase *)db)->GetRoot();
|
return *(SimpleDatabase *)db;
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
db_save(Error &error)
|
|
||||||
{
|
|
||||||
assert(db != nullptr);
|
|
||||||
assert(db_is_open);
|
|
||||||
assert(db_is_simple());
|
|
||||||
|
|
||||||
return ((SimpleDatabase *)db)->Save(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -22,12 +22,9 @@
|
|||||||
|
|
||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
struct config_param;
|
struct config_param;
|
||||||
struct Directory;
|
struct Directory;
|
||||||
struct db_selection;
|
class SimpleDatabase;
|
||||||
struct db_visitor;
|
|
||||||
class Error;
|
class Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,21 +35,9 @@ class Error;
|
|||||||
bool
|
bool
|
||||||
db_is_simple(void);
|
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
|
gcc_pure
|
||||||
Directory *
|
SimpleDatabase &
|
||||||
db_get_root(void);
|
db_get_simple();
|
||||||
|
|
||||||
/**
|
|
||||||
* May only be used if db_is_simple() returns true.
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
db_save(Error &error);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if there is a valid database file on the disk.
|
* Returns true if there is a valid database file on the disk.
|
||||||
|
@ -59,6 +59,10 @@ public:
|
|||||||
|
|
||||||
bool Save(Error &error);
|
bool Save(Error &error);
|
||||||
|
|
||||||
|
bool FileExists() const {
|
||||||
|
return mtime > 0;
|
||||||
|
}
|
||||||
|
|
||||||
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
||||||
const config_param ¶m,
|
const config_param ¶m,
|
||||||
Error &error);
|
Error &error);
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
#include "event/DeferredMonitor.hxx"
|
#include "event/DeferredMonitor.hxx"
|
||||||
#include "thread/Thread.hxx"
|
#include "thread/Thread.hxx"
|
||||||
|
|
||||||
|
class SimpleDatabase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manages the update queue and runs the update thread.
|
* This class manages the update queue and runs the update thread.
|
||||||
*/
|
*/
|
||||||
@ -36,6 +38,8 @@ class UpdateService final : DeferredMonitor {
|
|||||||
UPDATE_PROGRESS_DONE = 2
|
UPDATE_PROGRESS_DONE = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SimpleDatabase &db;
|
||||||
|
|
||||||
Progress progress;
|
Progress progress;
|
||||||
|
|
||||||
bool modified;
|
bool modified;
|
||||||
@ -53,7 +57,7 @@ class UpdateService final : DeferredMonitor {
|
|||||||
UpdateWalk walk;
|
UpdateWalk walk;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UpdateService(EventLoop &_loop);
|
UpdateService(EventLoop &_loop, SimpleDatabase &_db);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a non-zero job id when we are currently updating
|
* Returns a non-zero job id when we are currently updating
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Service.hxx"
|
#include "Service.hxx"
|
||||||
#include "UpdateDomain.hxx"
|
#include "UpdateDomain.hxx"
|
||||||
#include "db/DatabaseSimple.hxx"
|
#include "db/plugins/SimpleDatabasePlugin.hxx"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
@ -44,12 +44,12 @@ UpdateService::Task()
|
|||||||
|
|
||||||
SetThreadIdlePriority();
|
SetThreadIdlePriority();
|
||||||
|
|
||||||
modified = walk.Walk(*db_get_root(), next.path_utf8.c_str(),
|
modified = walk.Walk(*db.GetRoot(), next.path_utf8.c_str(),
|
||||||
next.discard);
|
next.discard);
|
||||||
|
|
||||||
if (modified || !db_exists()) {
|
if (modified || !db.FileExists()) {
|
||||||
Error error;
|
Error error;
|
||||||
if (!db_save(error))
|
if (!db.Save(error))
|
||||||
LogError(error, "Failed to save database");
|
LogError(error, "Failed to save database");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,8 +146,7 @@ UpdateService::RunDeferred()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateService::UpdateService(EventLoop &_loop)
|
UpdateService::UpdateService(EventLoop &_loop, SimpleDatabase &_db)
|
||||||
:DeferredMonitor(_loop), walk(_loop)
|
:DeferredMonitor(_loop), db(_db), walk(_loop)
|
||||||
{
|
{
|
||||||
assert(db_is_simple());
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user