aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-07-29 23:14:25 +0200
committerMax Kellermann <max@duempel.org>2014-07-29 23:31:27 +0200
commitaa0f06d6b712b1fe40536714ecdb2dd968417be3 (patch)
tree081d8d7b304aa370b5f62daab2da7e18281b2e4d /src
parent0c47685e0291b835034b7f5855eafef9bf69c7c9 (diff)
downloadmpd-aa0f06d6b712b1fe40536714ecdb2dd968417be3.tar.gz
mpd-aa0f06d6b712b1fe40536714ecdb2dd968417be3.tar.xz
mpd-aa0f06d6b712b1fe40536714ecdb2dd968417be3.zip
db/Interface: add virtual method Update()
For database plugins that don't use the UpdateService.
Diffstat (limited to 'src')
-rw-r--r--src/command/OtherCommands.cxx24
-rw-r--r--src/db/Interface.hxx12
2 files changed, 36 insertions, 0 deletions
diff --git a/src/command/OtherCommands.cxx b/src/command/OtherCommands.cxx
index 4f149e58e..a924f77b5 100644
--- a/src/command/OtherCommands.cxx
+++ b/src/command/OtherCommands.cxx
@@ -49,6 +49,7 @@
#ifdef ENABLE_DATABASE
#include "DatabaseCommands.hxx"
+#include "db/Interface.hxx"
#include "db/update/Service.hxx"
#endif
@@ -242,6 +243,25 @@ handle_update(Client &client, UpdateService &update,
}
}
+static CommandResult
+handle_update(Client &client, Database &db,
+ const char *uri_utf8, bool discard)
+{
+ Error error;
+ unsigned id = db.Update(uri_utf8, discard, error);
+ if (id > 0) {
+ client_printf(client, "updating_db: %i\n", id);
+ return CommandResult::OK;
+ } else if (error.IsDefined()) {
+ return print_error(client, error);
+ } else {
+ /* Database::Update() has returned 0 without setting
+ the Error: the method is not implemented */
+ command_error(client, ACK_ERROR_NO_EXIST, "Not implemented");
+ return CommandResult::ERROR;
+ }
+}
+
#endif
static CommandResult
@@ -267,6 +287,10 @@ handle_update(Client &client, unsigned argc, char *argv[], bool discard)
UpdateService *update = client.partition.instance.update;
if (update != nullptr)
return handle_update(client, *update, path, discard);
+
+ Database *db = client.partition.instance.database;
+ if (db != nullptr)
+ return handle_update(client, *db, path, discard);
#else
(void)argc;
(void)argv;
diff --git a/src/db/Interface.hxx b/src/db/Interface.hxx
index 5fc9265e2..152928c79 100644
--- a/src/db/Interface.hxx
+++ b/src/db/Interface.hxx
@@ -116,6 +116,18 @@ public:
Error &error) const = 0;
/**
+ * Update the database. Returns the job id on success, 0 on
+ * error (with #Error set) and 0 if not implemented (#Error
+ * not set).
+ */
+ virtual unsigned Update(gcc_unused const char *uri_utf8,
+ gcc_unused bool discard,
+ gcc_unused Error &error) {
+ /* not implemented: return 0 and don't set an Error */
+ return 0;
+ }
+
+ /**
* Returns the time stamp of the last database update.
* Returns 0 if that is not not known/available.
*/