aboutsummaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-02-04 19:16:30 +0100
committerMax Kellermann <max@duempel.org>2014-02-04 19:53:37 +0100
commitff665b37cb92e2a1664bbab207030a1eedfbb036 (patch)
tree1325b9260c35080b5140eed90a65211276aa946c /src/db
parentce738430147427b3bb44063a96cedbae4c53a03d (diff)
downloadmpd-ff665b37cb92e2a1664bbab207030a1eedfbb036.tar.gz
mpd-ff665b37cb92e2a1664bbab207030a1eedfbb036.tar.xz
mpd-ff665b37cb92e2a1664bbab207030a1eedfbb036.zip
db/DatabaseListener: add method OnDatabaseSongRemoved()
Decouples db/update/Remove.cpp from global variables.
Diffstat (limited to '')
-rw-r--r--src/db/DatabaseListener.hxx8
-rw-r--r--src/db/update/Editor.hxx4
-rw-r--r--src/db/update/Remove.cxx22
-rw-r--r--src/db/update/Remove.hxx7
-rw-r--r--src/db/update/UpdateGlue.cxx2
-rw-r--r--src/db/update/Walk.cxx4
-rw-r--r--src/db/update/Walk.hxx2
7 files changed, 21 insertions, 28 deletions
diff --git a/src/db/DatabaseListener.hxx b/src/db/DatabaseListener.hxx
index 4da458866..8b410c2f5 100644
--- a/src/db/DatabaseListener.hxx
+++ b/src/db/DatabaseListener.hxx
@@ -20,6 +20,8 @@
#ifndef MPD_DATABASE_CLIENT_HXX
#define MPD_DATABASE_CLIENT_HXX
+struct LightSong;
+
/**
* An object that listens to events from the #Database.
*
@@ -33,6 +35,12 @@ public:
* runs the #EventLoop.
*/
virtual void OnDatabaseModified() = 0;
+
+ /**
+ * During database update, a song is about to be removed from
+ * the database because the file has disappeared.
+ */
+ virtual void OnDatabaseSongRemoved(const LightSong &song) = 0;
};
#endif
diff --git a/src/db/update/Editor.hxx b/src/db/update/Editor.hxx
index b1c99095f..fc08c2659 100644
--- a/src/db/update/Editor.hxx
+++ b/src/db/update/Editor.hxx
@@ -31,8 +31,8 @@ class DatabaseEditor final {
UpdateRemoveService remove;
public:
- DatabaseEditor(EventLoop &_loop)
- :remove(_loop) {}
+ DatabaseEditor(EventLoop &_loop, DatabaseListener &_listener)
+ :remove(_loop, _listener) {}
/**
* Caller must lock the #db_mutex.
diff --git a/src/db/update/Remove.cxx b/src/db/update/Remove.cxx
index e2c172a4b..102347905 100644
--- a/src/db/update/Remove.cxx
+++ b/src/db/update/Remove.cxx
@@ -20,20 +20,11 @@
#include "config.h" /* must be first for large file support */
#include "Remove.hxx"
#include "UpdateDomain.hxx"
-#include "GlobalEvents.hxx"
-#include "thread/Mutex.hxx"
-#include "thread/Cond.hxx"
#include "db/Song.hxx"
#include "db/LightSong.hxx"
-#include "Main.hxx"
-#include "Instance.hxx"
+#include "db/DatabaseListener.hxx"
#include "Log.hxx"
-#ifdef ENABLE_SQLITE
-#include "sticker/StickerDatabase.hxx"
-#include "sticker/SongSticker.hxx"
-#endif
-
#include <assert.h>
/**
@@ -50,16 +41,7 @@ UpdateRemoveService::RunDeferred()
FormatDefault(update_domain, "removing %s", uri.c_str());
}
-#ifdef ENABLE_SQLITE
- /* if the song has a sticker, remove it */
- if (sticker_enabled())
- sticker_song_delete(removed_song->Export());
-#endif
-
- {
- const auto uri = removed_song->GetURI();
- instance->DeleteSong(uri.c_str());
- }
+ listener.OnDatabaseSongRemoved(removed_song->Export());
/* clear "removed_song" and send signal to update thread */
remove_mutex.lock();
diff --git a/src/db/update/Remove.hxx b/src/db/update/Remove.hxx
index 1970c0a07..5c09f55df 100644
--- a/src/db/update/Remove.hxx
+++ b/src/db/update/Remove.hxx
@@ -26,20 +26,23 @@
#include "thread/Cond.hxx"
struct Song;
+class DatabaseListener;
/**
* This class handles #Song removal. It defers the action to the main
* thread to ensure that all references to the #Song are gone.
*/
class UpdateRemoveService final : DeferredMonitor {
+ DatabaseListener &listener;
+
Mutex remove_mutex;
Cond remove_cond;
const Song *removed_song;
public:
- UpdateRemoveService(EventLoop &_loop)
- :DeferredMonitor(_loop) {}
+ UpdateRemoveService(EventLoop &_loop, DatabaseListener &_listener)
+ :DeferredMonitor(_loop), listener(_listener) {}
/**
* Sends a signal to the main thread which will in turn remove
diff --git a/src/db/update/UpdateGlue.cxx b/src/db/update/UpdateGlue.cxx
index ea1bf6f09..32e817ff1 100644
--- a/src/db/update/UpdateGlue.cxx
+++ b/src/db/update/UpdateGlue.cxx
@@ -155,6 +155,6 @@ UpdateService::UpdateService(EventLoop &_loop, SimpleDatabase &_db,
:DeferredMonitor(_loop), db(_db), listener(_listener),
progress(UPDATE_PROGRESS_IDLE),
update_task_id(0),
- walk(_loop)
+ walk(_loop, _listener)
{
}
diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx
index ed09c1676..c54d5a8d7 100644
--- a/src/db/update/Walk.cxx
+++ b/src/db/update/Walk.cxx
@@ -46,8 +46,8 @@
#include <stdlib.h>
#include <errno.h>
-UpdateWalk::UpdateWalk(EventLoop &_loop)
- :editor(_loop)
+UpdateWalk::UpdateWalk(EventLoop &_loop, DatabaseListener &_listener)
+ :editor(_loop, _listener)
{
#ifndef WIN32
follow_inside_symlinks =
diff --git a/src/db/update/Walk.hxx b/src/db/update/Walk.hxx
index ecb04387d..aa4516917 100644
--- a/src/db/update/Walk.hxx
+++ b/src/db/update/Walk.hxx
@@ -49,7 +49,7 @@ class UpdateWalk final {
DatabaseEditor editor;
public:
- UpdateWalk(EventLoop &_loop);
+ UpdateWalk(EventLoop &_loop, DatabaseListener &_listener);
/**
* Returns true if the database was modified.