DatabasePlugin: add interface DatabaseListener
Allow database plugins to announce that they have been modified.
This commit is contained in:
@@ -37,7 +37,8 @@ static bool db_is_open;
|
||||
static bool is_simple;
|
||||
|
||||
bool
|
||||
DatabaseGlobalInit(const config_param ¶m, Error &error)
|
||||
DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
|
||||
const config_param ¶m, Error &error)
|
||||
{
|
||||
assert(db == nullptr);
|
||||
assert(!db_is_open);
|
||||
@@ -53,7 +54,7 @@ DatabaseGlobalInit(const config_param ¶m, Error &error)
|
||||
return false;
|
||||
}
|
||||
|
||||
db = plugin->create(param, error);
|
||||
db = plugin->create(loop, listener, param, error);
|
||||
return db != nullptr;
|
||||
}
|
||||
|
||||
|
@@ -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 ¶m, Error &error);
|
||||
DatabaseGlobalInit(EventLoop &loop, DatabaseListener &listener,
|
||||
const config_param ¶m, Error &error);
|
||||
|
||||
void
|
||||
DatabaseGlobalDeinit(void);
|
||||
|
38
src/DatabaseListener.hxx
Normal file
38
src/DatabaseListener.hxx
Normal file
@@ -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
|
@@ -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 ¶m,
|
||||
Database *(*create)(EventLoop &loop, DatabaseListener &listener,
|
||||
const config_param ¶m,
|
||||
Error &error);
|
||||
};
|
||||
|
||||
|
@@ -48,3 +48,9 @@ Instance::SyncWithPlayer()
|
||||
{
|
||||
partition->SyncWithPlayer();
|
||||
}
|
||||
|
||||
void
|
||||
Instance::OnDatabaseModified()
|
||||
{
|
||||
DatabaseModified();
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -49,7 +49,8 @@ class ProxyDatabase : public Database {
|
||||
mutable time_t update_stamp;
|
||||
|
||||
public:
|
||||
static Database *Create(const config_param ¶m,
|
||||
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
||||
const config_param ¶m,
|
||||
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 ¶m, Error &error)
|
||||
ProxyDatabase::Create(gcc_unused EventLoop &loop,
|
||||
gcc_unused DatabaseListener &listener,
|
||||
const config_param ¶m, Error &error)
|
||||
{
|
||||
ProxyDatabase *db = new ProxyDatabase();
|
||||
if (!db->Configure(param, error)) {
|
||||
|
@@ -38,7 +38,9 @@
|
||||
static constexpr Domain simple_db_domain("simple_db");
|
||||
|
||||
Database *
|
||||
SimpleDatabase::Create(const config_param ¶m, Error &error)
|
||||
SimpleDatabase::Create(gcc_unused EventLoop &loop,
|
||||
gcc_unused DatabaseListener &listener,
|
||||
const config_param ¶m, Error &error)
|
||||
{
|
||||
SimpleDatabase *db = new SimpleDatabase();
|
||||
if (!db->Configure(param, error)) {
|
||||
|
@@ -53,7 +53,8 @@ public:
|
||||
|
||||
bool Save(Error &error);
|
||||
|
||||
static Database *Create(const config_param ¶m,
|
||||
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
||||
const config_param ¶m,
|
||||
Error &error);
|
||||
|
||||
virtual bool Open(Error &error) override;
|
||||
|
@@ -69,7 +69,8 @@ public:
|
||||
: m_lib(0), m_superdir(0), m_root(0)
|
||||
{}
|
||||
|
||||
static Database *Create(const config_param ¶m,
|
||||
static Database *Create(EventLoop &loop, DatabaseListener &listener,
|
||||
const config_param ¶m,
|
||||
Error &error);
|
||||
|
||||
virtual bool Open(Error &error) override;
|
||||
@@ -182,7 +183,9 @@ stringToTokens(const std::string &str,
|
||||
}
|
||||
|
||||
Database *
|
||||
UpnpDatabase::Create(const config_param ¶m, Error &error)
|
||||
UpnpDatabase::Create(gcc_unused EventLoop &loop,
|
||||
gcc_unused DatabaseListener &listener,
|
||||
const config_param ¶m, Error &error)
|
||||
{
|
||||
UpnpDatabase *db = new UpnpDatabase();
|
||||
if (db && !db->Configure(param, error)) {
|
||||
|
Reference in New Issue
Block a user