db/DatabaseListener: add method OnDatabaseSongRemoved()
Decouples db/update/Remove.cpp from global variables.
This commit is contained in:
parent
ce73843014
commit
ff665b37cb
@ -22,9 +22,15 @@
|
|||||||
#include "Partition.hxx"
|
#include "Partition.hxx"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "Stats.hxx"
|
#include "Stats.hxx"
|
||||||
#include "db/DatabaseError.hxx"
|
|
||||||
|
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
|
#include "db/DatabaseError.hxx"
|
||||||
|
#include "db/LightSong.hxx"
|
||||||
|
|
||||||
|
#ifdef ENABLE_SQLITE
|
||||||
|
#include "sticker/StickerDatabase.hxx"
|
||||||
|
#include "sticker/SongSticker.hxx"
|
||||||
|
#endif
|
||||||
|
|
||||||
Database *
|
Database *
|
||||||
Instance::GetDatabase(Error &error)
|
Instance::GetDatabase(Error &error)
|
||||||
@ -34,12 +40,6 @@ Instance::GetDatabase(Error &error)
|
|||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
Instance::DeleteSong(const char *uri)
|
|
||||||
{
|
|
||||||
partition->DeleteSong(uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -68,6 +68,21 @@ Instance::OnDatabaseModified()
|
|||||||
idle_add(IDLE_DATABASE);
|
idle_add(IDLE_DATABASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Instance::OnDatabaseSongRemoved(const LightSong &song)
|
||||||
|
{
|
||||||
|
assert(database != nullptr);
|
||||||
|
|
||||||
|
#ifdef ENABLE_SQLITE
|
||||||
|
/* if the song has a sticker, remove it */
|
||||||
|
if (sticker_enabled())
|
||||||
|
sticker_song_delete(song);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const auto uri = song.GetURI();
|
||||||
|
partition->DeleteSong(uri.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
||||||
|
@ -79,8 +79,6 @@ struct Instance final
|
|||||||
* music_directory was configured).
|
* music_directory was configured).
|
||||||
*/
|
*/
|
||||||
Database *GetDatabase(Error &error);
|
Database *GetDatabase(Error &error);
|
||||||
|
|
||||||
void DeleteSong(const char *uri);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,7 +94,8 @@ struct Instance final
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
virtual void OnDatabaseModified();
|
virtual void OnDatabaseModified() override;
|
||||||
|
virtual void OnDatabaseSongRemoved(const LightSong &song) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
#ifndef MPD_DATABASE_CLIENT_HXX
|
#ifndef MPD_DATABASE_CLIENT_HXX
|
||||||
#define MPD_DATABASE_CLIENT_HXX
|
#define MPD_DATABASE_CLIENT_HXX
|
||||||
|
|
||||||
|
struct LightSong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object that listens to events from the #Database.
|
* An object that listens to events from the #Database.
|
||||||
*
|
*
|
||||||
@ -33,6 +35,12 @@ public:
|
|||||||
* runs the #EventLoop.
|
* runs the #EventLoop.
|
||||||
*/
|
*/
|
||||||
virtual void OnDatabaseModified() = 0;
|
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
|
#endif
|
||||||
|
@ -31,8 +31,8 @@ class DatabaseEditor final {
|
|||||||
UpdateRemoveService remove;
|
UpdateRemoveService remove;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DatabaseEditor(EventLoop &_loop)
|
DatabaseEditor(EventLoop &_loop, DatabaseListener &_listener)
|
||||||
:remove(_loop) {}
|
:remove(_loop, _listener) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caller must lock the #db_mutex.
|
* Caller must lock the #db_mutex.
|
||||||
|
@ -20,20 +20,11 @@
|
|||||||
#include "config.h" /* must be first for large file support */
|
#include "config.h" /* must be first for large file support */
|
||||||
#include "Remove.hxx"
|
#include "Remove.hxx"
|
||||||
#include "UpdateDomain.hxx"
|
#include "UpdateDomain.hxx"
|
||||||
#include "GlobalEvents.hxx"
|
|
||||||
#include "thread/Mutex.hxx"
|
|
||||||
#include "thread/Cond.hxx"
|
|
||||||
#include "db/Song.hxx"
|
#include "db/Song.hxx"
|
||||||
#include "db/LightSong.hxx"
|
#include "db/LightSong.hxx"
|
||||||
#include "Main.hxx"
|
#include "db/DatabaseListener.hxx"
|
||||||
#include "Instance.hxx"
|
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#ifdef ENABLE_SQLITE
|
|
||||||
#include "sticker/StickerDatabase.hxx"
|
|
||||||
#include "sticker/SongSticker.hxx"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,16 +41,7 @@ UpdateRemoveService::RunDeferred()
|
|||||||
FormatDefault(update_domain, "removing %s", uri.c_str());
|
FormatDefault(update_domain, "removing %s", uri.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_SQLITE
|
listener.OnDatabaseSongRemoved(removed_song->Export());
|
||||||
/* 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());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* clear "removed_song" and send signal to update thread */
|
/* clear "removed_song" and send signal to update thread */
|
||||||
remove_mutex.lock();
|
remove_mutex.lock();
|
||||||
|
@ -26,20 +26,23 @@
|
|||||||
#include "thread/Cond.hxx"
|
#include "thread/Cond.hxx"
|
||||||
|
|
||||||
struct Song;
|
struct Song;
|
||||||
|
class DatabaseListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class handles #Song removal. It defers the action to the main
|
* This class handles #Song removal. It defers the action to the main
|
||||||
* thread to ensure that all references to the #Song are gone.
|
* thread to ensure that all references to the #Song are gone.
|
||||||
*/
|
*/
|
||||||
class UpdateRemoveService final : DeferredMonitor {
|
class UpdateRemoveService final : DeferredMonitor {
|
||||||
|
DatabaseListener &listener;
|
||||||
|
|
||||||
Mutex remove_mutex;
|
Mutex remove_mutex;
|
||||||
Cond remove_cond;
|
Cond remove_cond;
|
||||||
|
|
||||||
const Song *removed_song;
|
const Song *removed_song;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UpdateRemoveService(EventLoop &_loop)
|
UpdateRemoveService(EventLoop &_loop, DatabaseListener &_listener)
|
||||||
:DeferredMonitor(_loop) {}
|
:DeferredMonitor(_loop), listener(_listener) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a signal to the main thread which will in turn remove
|
* Sends a signal to the main thread which will in turn remove
|
||||||
|
@ -155,6 +155,6 @@ UpdateService::UpdateService(EventLoop &_loop, SimpleDatabase &_db,
|
|||||||
:DeferredMonitor(_loop), db(_db), listener(_listener),
|
:DeferredMonitor(_loop), db(_db), listener(_listener),
|
||||||
progress(UPDATE_PROGRESS_IDLE),
|
progress(UPDATE_PROGRESS_IDLE),
|
||||||
update_task_id(0),
|
update_task_id(0),
|
||||||
walk(_loop)
|
walk(_loop, _listener)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
UpdateWalk::UpdateWalk(EventLoop &_loop)
|
UpdateWalk::UpdateWalk(EventLoop &_loop, DatabaseListener &_listener)
|
||||||
:editor(_loop)
|
:editor(_loop, _listener)
|
||||||
{
|
{
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
follow_inside_symlinks =
|
follow_inside_symlinks =
|
||||||
|
@ -49,7 +49,7 @@ class UpdateWalk final {
|
|||||||
DatabaseEditor editor;
|
DatabaseEditor editor;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UpdateWalk(EventLoop &_loop);
|
UpdateWalk(EventLoop &_loop, DatabaseListener &_listener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the database was modified.
|
* Returns true if the database was modified.
|
||||||
|
@ -55,6 +55,10 @@ public:
|
|||||||
virtual void OnDatabaseModified() override {
|
virtual void OnDatabaseModified() override {
|
||||||
cout << "DatabaseModified" << endl;
|
cout << "DatabaseModified" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void OnDatabaseSongRemoved(const LightSong &song) override {
|
||||||
|
cout << "SongRemoved " << song.GetURI() << endl;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
Loading…
Reference in New Issue
Block a user