Partition: use CallbackMaskMonitor, replacing class GlobalEvents::Monitor
This commit is contained in:
parent
483daa5882
commit
5ca6026787
@ -132,7 +132,7 @@ libmpd_a_SOURCES = \
|
||||
src/IOThread.cxx src/IOThread.hxx \
|
||||
src/Instance.cxx src/Instance.hxx \
|
||||
src/win32/Win32Main.cxx \
|
||||
src/GlobalEvents.cxx src/GlobalEvents.hxx \
|
||||
src/GlobalEvents.hxx \
|
||||
src/MixRampInfo.hxx \
|
||||
src/MusicBuffer.cxx src/MusicBuffer.hxx \
|
||||
src/MusicPipe.cxx src/MusicPipe.hxx \
|
||||
@ -145,7 +145,6 @@ libmpd_a_SOURCES = \
|
||||
src/player/Control.cxx src/player/Control.hxx \
|
||||
src/player/Listener.hxx \
|
||||
src/PlaylistError.cxx src/PlaylistError.hxx \
|
||||
src/PlaylistGlobal.cxx src/PlaylistGlobal.hxx \
|
||||
src/PlaylistPrint.cxx src/PlaylistPrint.hxx \
|
||||
src/PlaylistSave.cxx src/PlaylistSave.hxx \
|
||||
src/playlist/PlaylistStream.cxx src/playlist/PlaylistStream.hxx \
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2016 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.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "GlobalEvents.hxx"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
inline void
|
||||
GlobalEvents::Monitor::Invoke(Event event)
|
||||
{
|
||||
assert((unsigned)event < GlobalEvents::MAX);
|
||||
assert(handlers[event] != nullptr);
|
||||
|
||||
handlers[event]();
|
||||
}
|
||||
|
||||
void
|
||||
GlobalEvents::Monitor::HandleMask(unsigned f)
|
||||
{
|
||||
for (unsigned i = 0; i < MAX; ++i)
|
||||
if (f & (1u << i))
|
||||
/* invoke the event handler */
|
||||
Invoke(Event(i));
|
||||
}
|
||||
|
||||
void
|
||||
GlobalEvents::Monitor::Register(Event event, Handler callback)
|
||||
{
|
||||
assert((unsigned)event < MAX);
|
||||
|
||||
handlers[event] = callback;
|
||||
}
|
||||
|
||||
void
|
||||
GlobalEvents::Monitor::Emit(Event event)
|
||||
{
|
||||
assert((unsigned)event < MAX);
|
||||
|
||||
const unsigned mask = 1u << unsigned(event);
|
||||
OrMask(mask);
|
||||
}
|
@ -20,8 +20,6 @@
|
||||
#ifndef MPD_GLOBAL_EVENTS_HXX
|
||||
#define MPD_GLOBAL_EVENTS_HXX
|
||||
|
||||
#include "event/MaskMonitor.hxx"
|
||||
|
||||
namespace GlobalEvents {
|
||||
enum Event {
|
||||
/** must call playlist_sync() */
|
||||
@ -32,28 +30,6 @@ namespace GlobalEvents {
|
||||
|
||||
MAX
|
||||
};
|
||||
|
||||
typedef void (*Handler)();
|
||||
|
||||
class Monitor final : MaskMonitor {
|
||||
Handler handlers[MAX];
|
||||
|
||||
public:
|
||||
explicit Monitor(EventLoop &_loop):MaskMonitor(_loop) {}
|
||||
|
||||
void Register(Event event, Handler handler);
|
||||
|
||||
void Emit(Event event);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Invoke the callback for a certain event.
|
||||
*/
|
||||
void Invoke(Event event);
|
||||
|
||||
protected:
|
||||
void HandleMask(unsigned mask) override;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* MAIN_NOTIFY_H */
|
||||
|
@ -45,22 +45,6 @@ Instance::GetDatabase(Error &error)
|
||||
return database;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
Instance::TagModified()
|
||||
{
|
||||
partition->TagModified();
|
||||
}
|
||||
|
||||
void
|
||||
Instance::SyncWithPlayer()
|
||||
{
|
||||
partition->SyncWithPlayer();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DATABASE
|
||||
|
||||
void
|
||||
Instance::OnDatabaseModified()
|
||||
{
|
||||
|
@ -112,17 +112,6 @@ struct Instance final
|
||||
Database *GetDatabase(Error &error);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A tag in the play queue has been modified by the player
|
||||
* thread. Propagate the change to all subsystems.
|
||||
*/
|
||||
void TagModified();
|
||||
|
||||
/**
|
||||
* Synchronize the player with the play queue.
|
||||
*/
|
||||
void SyncWithPlayer();
|
||||
|
||||
private:
|
||||
#ifdef ENABLE_DATABASE
|
||||
virtual void OnDatabaseModified() override;
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "Instance.hxx"
|
||||
#include "CommandLine.hxx"
|
||||
#include "PlaylistFile.hxx"
|
||||
#include "PlaylistGlobal.hxx"
|
||||
#include "MusicChunk.hxx"
|
||||
#include "StateFile.hxx"
|
||||
#include "player/Thread.hxx"
|
||||
@ -523,7 +522,6 @@ try {
|
||||
}
|
||||
|
||||
initPermissions();
|
||||
playlist_global_init();
|
||||
spl_global_init();
|
||||
#ifdef ENABLE_ARCHIVE
|
||||
archive_plugin_init_all();
|
||||
|
@ -30,13 +30,22 @@ Partition::Partition(Instance &_instance,
|
||||
unsigned buffer_chunks,
|
||||
unsigned buffered_before_play)
|
||||
:instance(_instance),
|
||||
global_events(instance.event_loop),
|
||||
global_events(instance.event_loop, *this, &Partition::OnGlobalEvent),
|
||||
playlist(max_length, *this),
|
||||
outputs(*this),
|
||||
pc(*this, outputs, buffer_chunks, buffered_before_play)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Partition::EmitGlobalEvent(GlobalEvents::Event event)
|
||||
{
|
||||
assert((unsigned)event < GlobalEvents::MAX);
|
||||
|
||||
const unsigned mask = 1u << unsigned(event);
|
||||
global_events.OrMask(mask);
|
||||
}
|
||||
|
||||
void
|
||||
Partition::EmitIdle(unsigned mask)
|
||||
{
|
||||
@ -97,13 +106,13 @@ Partition::OnQueueSongStarted()
|
||||
void
|
||||
Partition::OnPlayerSync()
|
||||
{
|
||||
global_events.Emit(GlobalEvents::PLAYLIST);
|
||||
EmitGlobalEvent(GlobalEvents::PLAYLIST);
|
||||
}
|
||||
|
||||
void
|
||||
Partition::OnPlayerTagModified()
|
||||
{
|
||||
global_events.Emit(GlobalEvents::TAG);
|
||||
EmitGlobalEvent(GlobalEvents::TAG);
|
||||
}
|
||||
|
||||
void
|
||||
@ -114,3 +123,13 @@ Partition::OnMixerVolumeChanged(gcc_unused Mixer &mixer, gcc_unused int volume)
|
||||
/* notify clients */
|
||||
EmitIdle(IDLE_MIXER);
|
||||
}
|
||||
|
||||
void
|
||||
Partition::OnGlobalEvent(unsigned mask)
|
||||
{
|
||||
if ((mask & (1u << unsigned(GlobalEvents::TAG))) != 0)
|
||||
TagModified();
|
||||
|
||||
if ((mask & (1u << unsigned(GlobalEvents::PLAYLIST))) != 0)
|
||||
SyncWithPlayer();
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
#ifndef MPD_PARTITION_HXX
|
||||
#define MPD_PARTITION_HXX
|
||||
|
||||
#include "event/MaskMonitor.hxx"
|
||||
#include "GlobalEvents.hxx"
|
||||
#include "queue/Playlist.hxx"
|
||||
#include "queue/Listener.hxx"
|
||||
@ -41,7 +42,7 @@ class SongLoader;
|
||||
struct Partition final : QueueListener, PlayerListener, MixerListener {
|
||||
Instance &instance;
|
||||
|
||||
GlobalEvents::Monitor global_events;
|
||||
CallbackMaskMonitor<Partition> global_events;
|
||||
|
||||
struct playlist playlist;
|
||||
|
||||
@ -54,6 +55,8 @@ struct Partition final : QueueListener, PlayerListener, MixerListener {
|
||||
unsigned buffer_chunks,
|
||||
unsigned buffered_before_play);
|
||||
|
||||
void EmitGlobalEvent(GlobalEvents::Event event);
|
||||
|
||||
void EmitIdle(unsigned mask);
|
||||
|
||||
void ClearQueue() {
|
||||
@ -215,6 +218,9 @@ private:
|
||||
|
||||
/* virtual methods from class MixerListener */
|
||||
virtual void OnMixerVolumeChanged(Mixer &mixer, int volume) override;
|
||||
|
||||
/* callback for #global_events */
|
||||
void OnGlobalEvent(unsigned mask);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2016 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The manager of the global "struct playlist" instance (g_playlist).
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "PlaylistGlobal.hxx"
|
||||
#include "Main.hxx"
|
||||
#include "Instance.hxx"
|
||||
#include "Partition.hxx"
|
||||
|
||||
static void
|
||||
playlist_tag_event(void)
|
||||
{
|
||||
instance->TagModified();
|
||||
}
|
||||
|
||||
static void
|
||||
playlist_event(void)
|
||||
{
|
||||
instance->SyncWithPlayer();
|
||||
}
|
||||
|
||||
void
|
||||
playlist_global_init()
|
||||
{
|
||||
instance->partition->global_events.Register(GlobalEvents::TAG, playlist_tag_event);
|
||||
instance->partition->global_events.Register(GlobalEvents::PLAYLIST, playlist_event);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2016 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_PLAYLIST_GLOBAL_HXX
|
||||
#define MPD_PLAYLIST_GLOBAL_HXX
|
||||
|
||||
void
|
||||
playlist_global_init();
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user