aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-11 01:01:54 +0100
committerMax Kellermann <max@duempel.org>2014-01-11 01:01:54 +0100
commit114df1f137d5a32cdde64d43712fb602c2f93ebb (patch)
treeb0f1b51cfed7ef50b1e98a241dcfd8d8c17a2791 /src
parent00adf7ff173afbe7fe13734a27d6ee19096ce640 (diff)
downloadmpd-114df1f137d5a32cdde64d43712fb602c2f93ebb.tar.gz
mpd-114df1f137d5a32cdde64d43712fb602c2f93ebb.tar.xz
mpd-114df1f137d5a32cdde64d43712fb602c2f93ebb.zip
DatabasePlugin: add interface DatabaseListener
Allow database plugins to announce that they have been modified.
Diffstat (limited to 'src')
-rw-r--r--src/DatabaseGlue.cxx5
-rw-r--r--src/DatabaseGlue.hxx5
-rw-r--r--src/DatabaseListener.hxx38
-rw-r--r--src/DatabasePlugin.hxx5
-rw-r--r--src/Instance.cxx6
-rw-r--r--src/Instance.hxx7
-rw-r--r--src/Main.cxx2
-rw-r--r--src/db/ProxyDatabasePlugin.cxx7
-rw-r--r--src/db/SimpleDatabasePlugin.cxx4
-rw-r--r--src/db/SimpleDatabasePlugin.hxx3
-rw-r--r--src/db/UpnpDatabasePlugin.cxx7
11 files changed, 77 insertions, 12 deletions
diff --git a/src/DatabaseGlue.cxx b/src/DatabaseGlue.cxx
index f64b31738..d5aad0522 100644
--- a/src/DatabaseGlue.cxx
+++ b/src/DatabaseGlue.cxx
@@ -37,7 +37,8 @@ static bool db_is_open;
static bool is_simple;
bool
-DatabaseGlobalInit(const config_param &param, Error &error)
+DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
+ const config_param &param, Error &error)
{
assert(db == nullptr);
assert(!db_is_open);
@@ -53,7 +54,7 @@ DatabaseGlobalInit(const config_param &param, Error &error)
return false;
}
- db = plugin->create(param, error);
+ db = plugin->create(loop, listener, param, error);
return db != nullptr;
}
diff --git a/src/DatabaseGlue.hxx b/src/DatabaseGlue.hxx
index 725aa302a..bf4699ff6 100644
--- a/src/DatabaseGlue.hxx
+++ b/src/DatabaseGlue.hxx
@@ -23,6 +23,8 @@
#include "Compiler.h"
struct config_param;
+class EventLoop;
+class DatabaseListener;
class Database;
class Error;
@@ -32,7 +34,8 @@ class Error;
* @param param the database configuration block
*/
bool
-DatabaseGlobalInit(const config_param &param, Error &error);
+DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
+ const config_param &param, Error &error);
void
DatabaseGlobalDeinit(void);
diff --git a/src/DatabaseListener.hxx b/src/DatabaseListener.hxx
new file mode 100644
index 000000000..4da458866
--- /dev/null
+++ b/src/DatabaseListener.hxx
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_DATABASE_CLIENT_HXX
+#define MPD_DATABASE_CLIENT_HXX
+
+/**
+ * An object that listens to events from the #Database.
+ *
+ * @see #Instance
+ */
+class DatabaseListener {
+public:
+ /**
+ * The database has been modified. This must be called in the
+ * thread that has created the #Database instance and that
+ * runs the #EventLoop.
+ */
+ virtual void OnDatabaseModified() = 0;
+};
+
+#endif
diff --git a/src/DatabasePlugin.hxx b/src/DatabasePlugin.hxx
index ccf899389..e42c3bbd3 100644
--- a/src/DatabasePlugin.hxx
+++ b/src/DatabasePlugin.hxx
@@ -37,6 +37,8 @@ struct DatabaseSelection;
struct db_visitor;
struct Song;
class Error;
+class EventLoop;
+class DatabaseListener;
struct DatabaseStats {
/**
@@ -149,7 +151,8 @@ struct DatabasePlugin {
/**
* Allocates and configures a database.
*/
- Database *(*create)(const config_param &param,
+ Database *(*create)(EventLoop &loop, DatabaseListener &listener,
+ const config_param &param,
Error &error);
};
diff --git a/src/Instance.cxx b/src/Instance.cxx
index 4fe399a2d..e9a308848 100644
--- a/src/Instance.cxx
+++ b/src/Instance.cxx
@@ -48,3 +48,9 @@ Instance::SyncWithPlayer()
{
partition->SyncWithPlayer();
}
+
+void
+Instance::OnDatabaseModified()
+{
+ DatabaseModified();
+}
diff --git a/src/Instance.hxx b/src/Instance.hxx
index 45b1e44f1..160e713b0 100644
--- a/src/Instance.hxx
+++ b/src/Instance.hxx
@@ -21,11 +21,13 @@
#define MPD_INSTANCE_HXX
#include "check.h"
+#include "DatabaseListener.hxx"
+#include "Compiler.h"
class ClientList;
struct Partition;
-struct Instance {
+struct Instance final : public DatabaseListener {
ClientList *client_list;
Partition *partition;
@@ -48,6 +50,9 @@ struct Instance {
* Synchronize the player with the play queue.
*/
void SyncWithPlayer();
+
+private:
+ virtual void OnDatabaseModified();
};
#endif
diff --git a/src/Main.cxx b/src/Main.cxx
index da8458340..624c6216d 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -186,7 +186,7 @@ glue_db_init_and_load(void)
return true;
Error error;
- if (!DatabaseGlobalInit(*param, error))
+ if (!DatabaseGlobalInit(*main_loop, *instance, *param, error))
FatalError(error);
delete allocated;
diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx
index 344edb900..e8d64003c 100644
--- a/src/db/ProxyDatabasePlugin.cxx
+++ b/src/db/ProxyDatabasePlugin.cxx
@@ -49,7 +49,8 @@ class ProxyDatabase : public Database {
mutable time_t update_stamp;
public:
- static Database *Create(const config_param &param,
+ static Database *Create(EventLoop &loop, DatabaseListener &listener,
+ const config_param &param,
Error &error);
virtual bool Open(Error &error) override;
@@ -218,7 +219,9 @@ SendConstraints(mpd_connection *connection, const DatabaseSelection &selection)
}
Database *
-ProxyDatabase::Create(const config_param &param, Error &error)
+ProxyDatabase::Create(gcc_unused EventLoop &loop,
+ gcc_unused DatabaseListener &listener,
+ const config_param &param, Error &error)
{
ProxyDatabase *db = new ProxyDatabase();
if (!db->Configure(param, error)) {
diff --git a/src/db/SimpleDatabasePlugin.cxx b/src/db/SimpleDatabasePlugin.cxx
index a46aa60b2..31d4213a5 100644
--- a/src/db/SimpleDatabasePlugin.cxx
+++ b/src/db/SimpleDatabasePlugin.cxx
@@ -38,7 +38,9 @@
static constexpr Domain simple_db_domain("simple_db");
Database *
-SimpleDatabase::Create(const config_param &param, Error &error)
+SimpleDatabase::Create(gcc_unused EventLoop &loop,
+ gcc_unused DatabaseListener &listener,
+ const config_param &param, Error &error)
{
SimpleDatabase *db = new SimpleDatabase();
if (!db->Configure(param, error)) {
diff --git a/src/db/SimpleDatabasePlugin.hxx b/src/db/SimpleDatabasePlugin.hxx
index dfe981dd8..98cbb96f0 100644
--- a/src/db/SimpleDatabasePlugin.hxx
+++ b/src/db/SimpleDatabasePlugin.hxx
@@ -53,7 +53,8 @@ public:
bool Save(Error &error);
- static Database *Create(const config_param &param,
+ static Database *Create(EventLoop &loop, DatabaseListener &listener,
+ const config_param &param,
Error &error);
virtual bool Open(Error &error) override;
diff --git a/src/db/UpnpDatabasePlugin.cxx b/src/db/UpnpDatabasePlugin.cxx
index ec86aa400..5c15fffeb 100644
--- a/src/db/UpnpDatabasePlugin.cxx
+++ b/src/db/UpnpDatabasePlugin.cxx
@@ -69,7 +69,8 @@ public:
: m_lib(0), m_superdir(0), m_root(0)
{}
- static Database *Create(const config_param &param,
+ static Database *Create(EventLoop &loop, DatabaseListener &listener,
+ const config_param &param,
Error &error);
virtual bool Open(Error &error) override;
@@ -182,7 +183,9 @@ stringToTokens(const std::string &str,
}
Database *
-UpnpDatabase::Create(const config_param &param, Error &error)
+UpnpDatabase::Create(gcc_unused EventLoop &loop,
+ gcc_unused DatabaseListener &listener,
+ const config_param &param, Error &error)
{
UpnpDatabase *db = new UpnpDatabase();
if (db && !db->Configure(param, error)) {