Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
114df1f1
Commit
114df1f1
authored
Jan 11, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DatabasePlugin: add interface DatabaseListener
Allow database plugins to announce that they have been modified.
parent
00adf7ff
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
93 additions
and
13 deletions
+93
-13
Makefile.am
Makefile.am
+2
-0
DatabaseGlue.cxx
src/DatabaseGlue.cxx
+3
-2
DatabaseGlue.hxx
src/DatabaseGlue.hxx
+4
-1
DatabaseListener.hxx
src/DatabaseListener.hxx
+38
-0
DatabasePlugin.hxx
src/DatabasePlugin.hxx
+4
-1
Instance.cxx
src/Instance.cxx
+6
-0
Instance.hxx
src/Instance.hxx
+6
-1
Main.cxx
src/Main.cxx
+1
-1
ProxyDatabasePlugin.cxx
src/db/ProxyDatabasePlugin.cxx
+5
-2
SimpleDatabasePlugin.cxx
src/db/SimpleDatabasePlugin.cxx
+3
-1
SimpleDatabasePlugin.hxx
src/db/SimpleDatabasePlugin.hxx
+2
-1
UpnpDatabasePlugin.cxx
src/db/UpnpDatabasePlugin.cxx
+5
-2
DumpDatabase.cxx
test/DumpDatabase.cxx
+14
-1
No files found.
Makefile.am
View file @
114df1f1
...
...
@@ -114,6 +114,7 @@ src_mpd_SOURCES = \
src/DatabaseLock.cxx src/DatabaseLock.hxx
\
src/DatabaseSave.cxx src/DatabaseSave.hxx
\
src/DatabasePlugin.hxx
\
src/DatabaseListener.hxx
\
src/DatabaseVisitor.hxx
\
src/DatabaseSelection.cxx src/DatabaseSelection.hxx
\
src/ExcludeList.cxx src/ExcludeList.hxx
\
...
...
@@ -1202,6 +1203,7 @@ test_DumpDatabase_LDADD = \
$(TAG_LIBS)
\
libconf.a
\
libutil.a
\
libevent.a
\
libsystem.a
\
libfs.a
\
$(GLIB_LIBS)
...
...
src/DatabaseGlue.cxx
View file @
114df1f1
...
...
@@ -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 ¶m, Error &error)
return
false
;
}
db
=
plugin
->
create
(
param
,
error
);
db
=
plugin
->
create
(
loop
,
listener
,
param
,
error
);
return
db
!=
nullptr
;
}
...
...
src/DatabaseGlue.hxx
View file @
114df1f1
...
...
@@ -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
);
...
...
src/DatabaseListener.hxx
0 → 100644
View file @
114df1f1
/*
* 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
src/DatabasePlugin.hxx
View file @
114df1f1
...
...
@@ -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
);
};
...
...
src/Instance.cxx
View file @
114df1f1
...
...
@@ -48,3 +48,9 @@ Instance::SyncWithPlayer()
{
partition
->
SyncWithPlayer
();
}
void
Instance
::
OnDatabaseModified
()
{
DatabaseModified
();
}
src/Instance.hxx
View file @
114df1f1
...
...
@@ -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
src/Main.cxx
View file @
114df1f1
...
...
@@ -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
;
...
...
src/db/ProxyDatabasePlugin.cxx
View file @
114df1f1
...
...
@@ -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
))
{
...
...
src/db/SimpleDatabasePlugin.cxx
View file @
114df1f1
...
...
@@ -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
))
{
...
...
src/db/SimpleDatabasePlugin.hxx
View file @
114df1f1
...
...
@@ -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
;
...
...
src/db/UpnpDatabasePlugin.cxx
View file @
114df1f1
...
...
@@ -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
))
{
...
...
test/DumpDatabase.cxx
View file @
114df1f1
...
...
@@ -21,6 +21,7 @@
#include "DatabaseRegistry.hxx"
#include "DatabasePlugin.hxx"
#include "DatabaseSelection.hxx"
#include "DatabaseListener.hxx"
#include "Directory.hxx"
#include "Song.hxx"
#include "PlaylistVector.hxx"
...
...
@@ -28,6 +29,7 @@
#include "ConfigData.hxx"
#include "tag/TagConfig.hxx"
#include "fs/Path.hxx"
#include "event/Loop.hxx"
#include "util/Error.hxx"
#include <glib.h>
...
...
@@ -48,6 +50,13 @@ InputStream::LockRead(void *, size_t, Error &)
}
#endif
class
MyDatabaseListener
final
:
public
DatabaseListener
{
public
:
virtual
void
OnDatabaseModified
()
override
{
cout
<<
"DatabaseModified"
<<
endl
;
}
};
static
bool
DumpDirectory
(
const
Directory
&
directory
,
Error
&
)
{
...
...
@@ -108,6 +117,9 @@ main(int argc, char **argv)
TagLoadConfig
();
EventLoop
event_loop
;
MyDatabaseListener
database_listener
;
/* do it */
const
struct
config_param
*
path
=
config_get_param
(
CONF_DB_FILE
);
...
...
@@ -115,7 +127,8 @@ main(int argc, char **argv)
if
(
path
!=
nullptr
)
param
.
AddBlockParam
(
"path"
,
path
->
value
.
c_str
(),
path
->
line
);
Database
*
db
=
plugin
->
create
(
param
,
error
);
Database
*
db
=
plugin
->
create
(
event_loop
,
database_listener
,
param
,
error
);
if
(
db
==
nullptr
)
{
cerr
<<
error
.
GetMessage
()
<<
endl
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment