EventPipe: rename to GlobalEvents
This commit is contained in:
parent
8782f6d232
commit
26ebfc04b0
@ -243,7 +243,7 @@ src_mpd_SOURCES = \
|
|||||||
src/io_thread.c src/io_thread.h \
|
src/io_thread.c src/io_thread.h \
|
||||||
src/Main.cxx src/Main.hxx \
|
src/Main.cxx src/Main.hxx \
|
||||||
src/Win32Main.cxx \
|
src/Win32Main.cxx \
|
||||||
src/EventPipe.cxx src/EventPipe.hxx \
|
src/GlobalEvents.cxx src/GlobalEvents.hxx \
|
||||||
src/daemon.c \
|
src/daemon.c \
|
||||||
src/AudioCompress/compress.c \
|
src/AudioCompress/compress.c \
|
||||||
src/MusicBuffer.cxx src/MusicBuffer.hxx \
|
src/MusicBuffer.cxx src/MusicBuffer.hxx \
|
||||||
|
@ -1,161 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2003-2013 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 "EventPipe.hxx"
|
|
||||||
#include "thread/Mutex.hxx"
|
|
||||||
#include "fd_util.h"
|
|
||||||
#include "mpd_error.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <glib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
/* for _O_BINARY */
|
|
||||||
#include <fcntl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef G_LOG_DOMAIN
|
|
||||||
#define G_LOG_DOMAIN "event_pipe"
|
|
||||||
|
|
||||||
static int event_pipe[2];
|
|
||||||
static GIOChannel *event_channel;
|
|
||||||
static guint event_pipe_source_id;
|
|
||||||
static Mutex event_pipe_mutex;
|
|
||||||
static bool pipe_events[PIPE_EVENT_MAX];
|
|
||||||
static event_pipe_callback_t event_pipe_callbacks[PIPE_EVENT_MAX];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invoke the callback for a certain event.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
event_pipe_invoke(enum pipe_event event)
|
|
||||||
{
|
|
||||||
assert((unsigned)event < PIPE_EVENT_MAX);
|
|
||||||
assert(event_pipe_callbacks[event] != NULL);
|
|
||||||
|
|
||||||
event_pipe_callbacks[event]();
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
main_notify_event(G_GNUC_UNUSED GIOChannel *source,
|
|
||||||
G_GNUC_UNUSED GIOCondition condition,
|
|
||||||
G_GNUC_UNUSED gpointer data)
|
|
||||||
{
|
|
||||||
char buffer[256];
|
|
||||||
gsize bytes_read;
|
|
||||||
GError *error = NULL;
|
|
||||||
GIOStatus status = g_io_channel_read_chars(event_channel,
|
|
||||||
buffer, sizeof(buffer),
|
|
||||||
&bytes_read, &error);
|
|
||||||
if (status == G_IO_STATUS_ERROR)
|
|
||||||
MPD_ERROR("error reading from pipe: %s", error->message);
|
|
||||||
|
|
||||||
bool events[PIPE_EVENT_MAX];
|
|
||||||
event_pipe_mutex.lock();
|
|
||||||
memcpy(events, pipe_events, sizeof(events));
|
|
||||||
memset(pipe_events, 0, sizeof(pipe_events));
|
|
||||||
event_pipe_mutex.unlock();
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < PIPE_EVENT_MAX; ++i)
|
|
||||||
if (events[i])
|
|
||||||
/* invoke the event handler */
|
|
||||||
event_pipe_invoke(pipe_event(i));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void event_pipe_init(void)
|
|
||||||
{
|
|
||||||
GIOChannel *channel;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = pipe_cloexec_nonblock(event_pipe);
|
|
||||||
if (ret < 0)
|
|
||||||
MPD_ERROR("Couldn't open pipe: %s", strerror(errno));
|
|
||||||
|
|
||||||
#ifndef G_OS_WIN32
|
|
||||||
channel = g_io_channel_unix_new(event_pipe[0]);
|
|
||||||
#else
|
|
||||||
channel = g_io_channel_win32_new_fd(event_pipe[0]);
|
|
||||||
#endif
|
|
||||||
g_io_channel_set_encoding(channel, NULL, NULL);
|
|
||||||
g_io_channel_set_buffered(channel, false);
|
|
||||||
|
|
||||||
event_pipe_source_id = g_io_add_watch(channel, G_IO_IN,
|
|
||||||
main_notify_event, NULL);
|
|
||||||
|
|
||||||
event_channel = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void event_pipe_deinit(void)
|
|
||||||
{
|
|
||||||
g_source_remove(event_pipe_source_id);
|
|
||||||
g_io_channel_unref(event_channel);
|
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
/* By some strange reason this call hangs on Win32 */
|
|
||||||
close(event_pipe[0]);
|
|
||||||
#endif
|
|
||||||
close(event_pipe[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
event_pipe_register(enum pipe_event event, event_pipe_callback_t callback)
|
|
||||||
{
|
|
||||||
assert((unsigned)event < PIPE_EVENT_MAX);
|
|
||||||
assert(event_pipe_callbacks[event] == NULL);
|
|
||||||
|
|
||||||
event_pipe_callbacks[event] = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
void event_pipe_emit(enum pipe_event event)
|
|
||||||
{
|
|
||||||
ssize_t w;
|
|
||||||
|
|
||||||
assert((unsigned)event < PIPE_EVENT_MAX);
|
|
||||||
|
|
||||||
event_pipe_mutex.lock();
|
|
||||||
if (pipe_events[event]) {
|
|
||||||
/* already set: don't write */
|
|
||||||
event_pipe_mutex.unlock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pipe_events[event] = true;
|
|
||||||
event_pipe_mutex.unlock();
|
|
||||||
|
|
||||||
w = write(event_pipe[1], "", 1);
|
|
||||||
if (w < 0 && errno != EAGAIN && errno != EINTR)
|
|
||||||
MPD_ERROR("error writing to pipe: %s", strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
void event_pipe_emit_fast(enum pipe_event event)
|
|
||||||
{
|
|
||||||
assert((unsigned)event < PIPE_EVENT_MAX);
|
|
||||||
|
|
||||||
pipe_events[event] = true;
|
|
||||||
|
|
||||||
G_GNUC_UNUSED ssize_t nbytes = write(event_pipe[1], "", 1);
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2003-2013 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_EVENT_PIPE_HXX
|
|
||||||
#define MPD_EVENT_PIPE_HXX
|
|
||||||
|
|
||||||
enum pipe_event {
|
|
||||||
/** database update was finished */
|
|
||||||
PIPE_EVENT_UPDATE,
|
|
||||||
|
|
||||||
/** during database update, a song was deleted */
|
|
||||||
PIPE_EVENT_DELETE,
|
|
||||||
|
|
||||||
/** an idle event was emitted */
|
|
||||||
PIPE_EVENT_IDLE,
|
|
||||||
|
|
||||||
/** must call playlist_sync() */
|
|
||||||
PIPE_EVENT_PLAYLIST,
|
|
||||||
|
|
||||||
/** the current song's tag has changed */
|
|
||||||
PIPE_EVENT_TAG,
|
|
||||||
|
|
||||||
/** SIGHUP received: reload configuration, roll log file */
|
|
||||||
PIPE_EVENT_RELOAD,
|
|
||||||
|
|
||||||
/** a hardware mixer plugin has detected a change */
|
|
||||||
PIPE_EVENT_MIXER,
|
|
||||||
|
|
||||||
/** shutdown requested */
|
|
||||||
PIPE_EVENT_SHUTDOWN,
|
|
||||||
|
|
||||||
PIPE_EVENT_MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef void (*event_pipe_callback_t)(void);
|
|
||||||
|
|
||||||
void event_pipe_init(void);
|
|
||||||
|
|
||||||
void event_pipe_deinit(void);
|
|
||||||
|
|
||||||
void
|
|
||||||
event_pipe_register(enum pipe_event event, event_pipe_callback_t callback);
|
|
||||||
|
|
||||||
void event_pipe_emit(enum pipe_event event);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Similar to event_pipe_emit(), but aimed for use in signal handlers:
|
|
||||||
* it doesn't lock the mutex, and doesn't log on error. That makes it
|
|
||||||
* potentially lossy, but for its intended use, that does not matter.
|
|
||||||
*/
|
|
||||||
void event_pipe_emit_fast(enum pipe_event event);
|
|
||||||
|
|
||||||
#endif /* MAIN_NOTIFY_H */
|
|
153
src/GlobalEvents.cxx
Normal file
153
src/GlobalEvents.cxx
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2003-2013 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 "thread/Mutex.hxx"
|
||||||
|
#include "fd_util.h"
|
||||||
|
#include "mpd_error.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <glib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#undef G_LOG_DOMAIN
|
||||||
|
#define G_LOG_DOMAIN "global_events"
|
||||||
|
|
||||||
|
namespace GlobalEvents {
|
||||||
|
static int fds[2];
|
||||||
|
static GIOChannel *channel;
|
||||||
|
static guint source_id;
|
||||||
|
static Mutex mutex;
|
||||||
|
static bool flags[MAX];
|
||||||
|
static Handler handlers[MAX];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke the callback for a certain event.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
InvokeGlobalEvent(GlobalEvents::Event event)
|
||||||
|
{
|
||||||
|
assert((unsigned)event < GlobalEvents::MAX);
|
||||||
|
assert(GlobalEvents::handlers[event] != NULL);
|
||||||
|
|
||||||
|
GlobalEvents::handlers[event]();
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
GlobalEventCallback(G_GNUC_UNUSED GIOChannel *source,
|
||||||
|
G_GNUC_UNUSED GIOCondition condition,
|
||||||
|
G_GNUC_UNUSED gpointer data)
|
||||||
|
{
|
||||||
|
char buffer[256];
|
||||||
|
gsize bytes_read;
|
||||||
|
GError *error = NULL;
|
||||||
|
GIOStatus status = g_io_channel_read_chars(GlobalEvents::channel,
|
||||||
|
buffer, sizeof(buffer),
|
||||||
|
&bytes_read, &error);
|
||||||
|
if (status == G_IO_STATUS_ERROR)
|
||||||
|
MPD_ERROR("error reading from pipe: %s", error->message);
|
||||||
|
|
||||||
|
bool events[GlobalEvents::MAX];
|
||||||
|
GlobalEvents::mutex.lock();
|
||||||
|
memcpy(events, GlobalEvents::flags, sizeof(events));
|
||||||
|
memset(GlobalEvents::flags, 0,
|
||||||
|
sizeof(GlobalEvents::flags));
|
||||||
|
GlobalEvents::mutex.unlock();
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < GlobalEvents::MAX; ++i)
|
||||||
|
if (events[i])
|
||||||
|
/* invoke the event handler */
|
||||||
|
InvokeGlobalEvent(GlobalEvents::Event(i));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GlobalEvents::Initialize()
|
||||||
|
{
|
||||||
|
if (pipe_cloexec_nonblock(fds) < 0)
|
||||||
|
MPD_ERROR("Couldn't open pipe: %s", strerror(errno));
|
||||||
|
|
||||||
|
#ifndef G_OS_WIN32
|
||||||
|
channel = g_io_channel_unix_new(fds[0]);
|
||||||
|
#else
|
||||||
|
channel = g_io_channel_win32_new_fd(fds[0]);
|
||||||
|
#endif
|
||||||
|
g_io_channel_set_encoding(channel, NULL, NULL);
|
||||||
|
g_io_channel_set_buffered(channel, false);
|
||||||
|
|
||||||
|
source_id = g_io_add_watch(channel, G_IO_IN,
|
||||||
|
GlobalEventCallback, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GlobalEvents::Deinitialize()
|
||||||
|
{
|
||||||
|
g_source_remove(source_id);
|
||||||
|
g_io_channel_unref(channel);
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
/* By some strange reason this call hangs on Win32 */
|
||||||
|
close(fds[0]);
|
||||||
|
#endif
|
||||||
|
close(fds[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GlobalEvents::Register(Event event, Handler callback)
|
||||||
|
{
|
||||||
|
assert((unsigned)event < MAX);
|
||||||
|
assert(handlers[event] == NULL);
|
||||||
|
|
||||||
|
handlers[event] = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GlobalEvents::Emit(Event event)
|
||||||
|
{
|
||||||
|
assert((unsigned)event < MAX);
|
||||||
|
|
||||||
|
mutex.lock();
|
||||||
|
if (flags[event]) {
|
||||||
|
/* already set: don't write */
|
||||||
|
mutex.unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
flags[event] = true;
|
||||||
|
mutex.unlock();
|
||||||
|
|
||||||
|
ssize_t w = write(fds[1], "", 1);
|
||||||
|
if (w < 0 && errno != EAGAIN && errno != EINTR)
|
||||||
|
MPD_ERROR("error writing to pipe: %s", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GlobalEvents::FastEmit(Event event)
|
||||||
|
{
|
||||||
|
assert((unsigned)event < MAX);
|
||||||
|
|
||||||
|
flags[event] = true;
|
||||||
|
|
||||||
|
G_GNUC_UNUSED ssize_t nbytes = write(fds[1], "", 1);
|
||||||
|
}
|
70
src/GlobalEvents.hxx
Normal file
70
src/GlobalEvents.hxx
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2003-2013 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_GLOBAL_EVENTS_HXX
|
||||||
|
#define MPD_GLOBAL_EVENTS_HXX
|
||||||
|
|
||||||
|
namespace GlobalEvents {
|
||||||
|
enum Event {
|
||||||
|
/** database update was finished */
|
||||||
|
UPDATE,
|
||||||
|
|
||||||
|
/** during database update, a song was deleted */
|
||||||
|
DELETE,
|
||||||
|
|
||||||
|
/** an idle event was emitted */
|
||||||
|
IDLE,
|
||||||
|
|
||||||
|
/** must call playlist_sync() */
|
||||||
|
PLAYLIST,
|
||||||
|
|
||||||
|
/** the current song's tag has changed */
|
||||||
|
TAG,
|
||||||
|
|
||||||
|
/** SIGHUP received: reload configuration, roll log file */
|
||||||
|
RELOAD,
|
||||||
|
|
||||||
|
/** a hardware mixer plugin has detected a change */
|
||||||
|
MIXER,
|
||||||
|
|
||||||
|
/** shutdown requested */
|
||||||
|
SHUTDOWN,
|
||||||
|
|
||||||
|
MAX
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void (*Handler)();
|
||||||
|
|
||||||
|
void Initialize();
|
||||||
|
|
||||||
|
void Deinitialize();
|
||||||
|
|
||||||
|
void Register(Event event, Handler handler);
|
||||||
|
|
||||||
|
void Emit(Event event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similar to event_pipe_emit(), but aimed for use in signal handlers:
|
||||||
|
* it doesn't lock the mutex, and doesn't log on error. That makes it
|
||||||
|
* potentially lossy, but for its intended use, that does not matter.
|
||||||
|
*/
|
||||||
|
void FastEmit(Event event);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* MAIN_NOTIFY_H */
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
@ -71,7 +71,7 @@ idle_add(unsigned flags)
|
|||||||
idle_flags |= flags;
|
idle_flags |= flags;
|
||||||
g_mutex_unlock(idle_mutex);
|
g_mutex_unlock(idle_mutex);
|
||||||
|
|
||||||
event_pipe_emit(PIPE_EVENT_IDLE);
|
GlobalEvents::Emit(GlobalEvents::IDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
|
14
src/Main.cxx
14
src/Main.cxx
@ -43,7 +43,7 @@
|
|||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "SignalHandlers.hxx"
|
#include "SignalHandlers.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "daemon.h"
|
#include "daemon.h"
|
||||||
@ -316,7 +316,7 @@ initialize_decoder_and_player(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* event_pipe callback function for PIPE_EVENT_IDLE
|
* Handler for GlobalEvents::IDLE.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
idle_event_emitted(void)
|
idle_event_emitted(void)
|
||||||
@ -329,7 +329,7 @@ idle_event_emitted(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* event_pipe callback function for PIPE_EVENT_SHUTDOWN
|
* Handler for GlobalEvents::SHUTDOWN.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
shutdown_event_emitted(void)
|
shutdown_event_emitted(void)
|
||||||
@ -406,9 +406,9 @@ int mpd_main(int argc, char *argv[])
|
|||||||
main_loop = g_main_loop_new(NULL, FALSE);
|
main_loop = g_main_loop_new(NULL, FALSE);
|
||||||
main_cond = g_cond_new();
|
main_cond = g_cond_new();
|
||||||
|
|
||||||
event_pipe_init();
|
GlobalEvents::Initialize();
|
||||||
event_pipe_register(PIPE_EVENT_IDLE, idle_event_emitted);
|
GlobalEvents::Register(GlobalEvents::IDLE, idle_event_emitted);
|
||||||
event_pipe_register(PIPE_EVENT_SHUTDOWN, shutdown_event_emitted);
|
GlobalEvents::Register(GlobalEvents::SHUTDOWN, shutdown_event_emitted);
|
||||||
|
|
||||||
path_global_init();
|
path_global_init();
|
||||||
|
|
||||||
@ -537,7 +537,7 @@ int mpd_main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_cond_free(main_cond);
|
g_cond_free(main_cond);
|
||||||
event_pipe_deinit();
|
GlobalEvents::Deinitialize();
|
||||||
|
|
||||||
playlist_list_global_finish();
|
playlist_list_global_finish();
|
||||||
input_stream_global_finish();
|
input_stream_global_finish();
|
||||||
|
@ -52,7 +52,7 @@ win32_main(int argc, char *argv[]);
|
|||||||
* When running as a service reports to service control manager
|
* When running as a service reports to service control manager
|
||||||
* that our service is started.
|
* that our service is started.
|
||||||
* When running as a console application enables console handler that will
|
* When running as a console application enables console handler that will
|
||||||
* trigger PIPE_EVENT_SHUTDOWN when user closes console window
|
* trigger GlobalEvents::SHUTDOWN when user closes console window
|
||||||
* or presses Ctrl+C.
|
* or presses Ctrl+C.
|
||||||
* This function should be called just before entering main loop.
|
* This function should be called just before entering main loop.
|
||||||
*/
|
*/
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include "OutputAll.hxx"
|
#include "OutputAll.hxx"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ player_wait_for_decoder(struct player *player)
|
|||||||
player_unlock(pc);
|
player_unlock(pc);
|
||||||
|
|
||||||
/* call syncPlaylistWithQueue() in the main thread */
|
/* call syncPlaylistWithQueue() in the main thread */
|
||||||
event_pipe_emit(PIPE_EVENT_PLAYLIST);
|
GlobalEvents::Emit(GlobalEvents::PLAYLIST);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -665,7 +665,7 @@ update_song_tag(struct song *song, const struct tag *new_tag)
|
|||||||
|
|
||||||
/* the main thread will update the playlist version when he
|
/* the main thread will update the playlist version when he
|
||||||
receives this event */
|
receives this event */
|
||||||
event_pipe_emit(PIPE_EVENT_TAG);
|
GlobalEvents::Emit(GlobalEvents::TAG);
|
||||||
|
|
||||||
/* notify all clients that the tag of the current song has
|
/* notify all clients that the tag of the current song has
|
||||||
changed */
|
changed */
|
||||||
@ -909,7 +909,7 @@ static void do_play(struct player_control *pc, struct decoder_control *dc)
|
|||||||
player_dc_stop(&player);
|
player_dc_stop(&player);
|
||||||
player_command_finished(pc);
|
player_command_finished(pc);
|
||||||
music_pipe_free(player.pipe);
|
music_pipe_free(player.pipe);
|
||||||
event_pipe_emit(PIPE_EVENT_PLAYLIST);
|
GlobalEvents::Emit(GlobalEvents::PLAYLIST);
|
||||||
player_lock(pc);
|
player_lock(pc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1086,7 +1086,7 @@ static void do_play(struct player_control *pc, struct decoder_control *dc)
|
|||||||
|
|
||||||
player_unlock(pc);
|
player_unlock(pc);
|
||||||
|
|
||||||
event_pipe_emit(PIPE_EVENT_PLAYLIST);
|
GlobalEvents::Emit(GlobalEvents::PLAYLIST);
|
||||||
|
|
||||||
player_lock(pc);
|
player_lock(pc);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include "Playlist.hxx"
|
#include "Playlist.hxx"
|
||||||
#include "Main.hxx"
|
#include "Main.hxx"
|
||||||
#include "Partition.hxx"
|
#include "Partition.hxx"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
playlist_tag_event(void)
|
playlist_tag_event(void)
|
||||||
@ -44,6 +44,6 @@ playlist_event(void)
|
|||||||
void
|
void
|
||||||
playlist_global_init()
|
playlist_global_init()
|
||||||
{
|
{
|
||||||
event_pipe_register(PIPE_EVENT_TAG, playlist_tag_event);
|
GlobalEvents::Register(GlobalEvents::TAG, playlist_tag_event);
|
||||||
event_pipe_register(PIPE_EVENT_PLAYLIST, playlist_event);
|
GlobalEvents::Register(GlobalEvents::PLAYLIST, playlist_event);
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "Main.hxx"
|
#include "Main.hxx"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
#include "mpd_error.h"
|
#include "mpd_error.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
@ -40,7 +40,7 @@ static void exit_signal_handler(G_GNUC_UNUSED int signum)
|
|||||||
|
|
||||||
static void reload_signal_handler(G_GNUC_UNUSED int signum)
|
static void reload_signal_handler(G_GNUC_UNUSED int signum)
|
||||||
{
|
{
|
||||||
event_pipe_emit_fast(PIPE_EVENT_RELOAD);
|
GlobalEvents::FastEmit(GlobalEvents::RELOAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -73,7 +73,7 @@ void initSigHandlers(void)
|
|||||||
x_sigaction(SIGINT, &sa);
|
x_sigaction(SIGINT, &sa);
|
||||||
x_sigaction(SIGTERM, &sa);
|
x_sigaction(SIGTERM, &sa);
|
||||||
|
|
||||||
event_pipe_register(PIPE_EVENT_RELOAD, handle_reload_event);
|
GlobalEvents::Register(GlobalEvents::RELOAD, handle_reload_event);
|
||||||
sa.sa_handler = reload_signal_handler;
|
sa.sa_handler = reload_signal_handler;
|
||||||
x_sigaction(SIGHUP, &sa);
|
x_sigaction(SIGHUP, &sa);
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "Mapper.hxx"
|
#include "Mapper.hxx"
|
||||||
#include "DatabaseSimple.hxx"
|
#include "DatabaseSimple.hxx"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
@ -92,7 +92,7 @@ static void * update_task(void *_path)
|
|||||||
g_free(_path);
|
g_free(_path);
|
||||||
|
|
||||||
progress = UPDATE_PROGRESS_DONE;
|
progress = UPDATE_PROGRESS_DONE;
|
||||||
event_pipe_emit(PIPE_EVENT_UPDATE);
|
GlobalEvents::Emit(GlobalEvents::UPDATE);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ static void update_finished_event(void)
|
|||||||
|
|
||||||
void update_global_init(void)
|
void update_global_init(void)
|
||||||
{
|
{
|
||||||
event_pipe_register(PIPE_EVENT_UPDATE, update_finished_event);
|
GlobalEvents::Register(GlobalEvents::UPDATE, update_finished_event);
|
||||||
|
|
||||||
update_remove_global_init();
|
update_remove_global_init();
|
||||||
update_walk_global_init();
|
update_walk_global_init();
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "UpdateRemove.hxx"
|
#include "UpdateRemove.hxx"
|
||||||
#include "Playlist.hxx"
|
#include "Playlist.hxx"
|
||||||
#include "Partition.hxx"
|
#include "Partition.hxx"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
#include "Main.hxx"
|
#include "Main.hxx"
|
||||||
@ -76,7 +76,7 @@ update_remove_global_init(void)
|
|||||||
remove_mutex = g_mutex_new();
|
remove_mutex = g_mutex_new();
|
||||||
remove_cond = g_cond_new();
|
remove_cond = g_cond_new();
|
||||||
|
|
||||||
event_pipe_register(PIPE_EVENT_DELETE, song_remove_event);
|
GlobalEvents::Register(GlobalEvents::DELETE, song_remove_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -93,7 +93,7 @@ update_remove_song(const struct song *song)
|
|||||||
|
|
||||||
removed_song = song;
|
removed_song = song;
|
||||||
|
|
||||||
event_pipe_emit(PIPE_EVENT_DELETE);
|
GlobalEvents::Emit(GlobalEvents::DELETE);
|
||||||
|
|
||||||
g_mutex_lock(remove_mutex);
|
g_mutex_lock(remove_mutex);
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "Volume.hxx"
|
#include "Volume.hxx"
|
||||||
#include "MixerAll.hxx"
|
#include "MixerAll.hxx"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ static int last_hardware_volume = -1;
|
|||||||
static GTimer *hardware_volume_timer;
|
static GTimer *hardware_volume_timer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for #PIPE_EVENT_MIXER.
|
* Handler for #GlobalEvents::MIXER.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
mixer_event_callback(void)
|
mixer_event_callback(void)
|
||||||
@ -62,7 +62,7 @@ void volume_init(void)
|
|||||||
{
|
{
|
||||||
hardware_volume_timer = g_timer_new();
|
hardware_volume_timer = g_timer_new();
|
||||||
|
|
||||||
event_pipe_register(PIPE_EVENT_MIXER, mixer_event_callback);
|
GlobalEvents::Register(GlobalEvents::MIXER, mixer_event_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
int volume_level_get(void)
|
int volume_level_get(void)
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
#include "mpd_error.h"
|
#include "mpd_error.h"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ service_dispatcher(G_GNUC_UNUSED DWORD control, G_GNUC_UNUSED DWORD event_type,
|
|||||||
switch (control) {
|
switch (control) {
|
||||||
case SERVICE_CONTROL_SHUTDOWN:
|
case SERVICE_CONTROL_SHUTDOWN:
|
||||||
case SERVICE_CONTROL_STOP:
|
case SERVICE_CONTROL_STOP:
|
||||||
event_pipe_emit(PIPE_EVENT_SHUTDOWN);
|
GlobalEvents::Emit(GlobalEvents::SHUTDOWN);
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
default:
|
default:
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
@ -104,7 +104,7 @@ console_handler(DWORD event)
|
|||||||
case CTRL_C_EVENT:
|
case CTRL_C_EVENT:
|
||||||
case CTRL_CLOSE_EVENT:
|
case CTRL_CLOSE_EVENT:
|
||||||
if (!ignore_console_events)
|
if (!ignore_console_events)
|
||||||
event_pipe_emit(PIPE_EVENT_SHUTDOWN);
|
GlobalEvents::Emit(GlobalEvents::SHUTDOWN);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
default:
|
default:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "mixer_api.h"
|
#include "mixer_api.h"
|
||||||
#include "output_api.h"
|
#include "output_api.h"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
@ -211,7 +211,7 @@ static int
|
|||||||
alsa_mixer_elem_callback(G_GNUC_UNUSED snd_mixer_elem_t *elem, unsigned mask)
|
alsa_mixer_elem_callback(G_GNUC_UNUSED snd_mixer_elem_t *elem, unsigned mask)
|
||||||
{
|
{
|
||||||
if (mask & SND_CTL_EVENT_MASK_VALUE)
|
if (mask & SND_CTL_EVENT_MASK_VALUE)
|
||||||
event_pipe_emit(PIPE_EVENT_MIXER);
|
GlobalEvents::Emit(GlobalEvents::MIXER);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include "mixer_api.h"
|
#include "mixer_api.h"
|
||||||
#include "output/pulse_output_plugin.h"
|
#include "output/pulse_output_plugin.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ pulse_mixer_offline(struct pulse_mixer *pm)
|
|||||||
|
|
||||||
pm->online = false;
|
pm->online = false;
|
||||||
|
|
||||||
event_pipe_emit(PIPE_EVENT_MIXER);
|
GlobalEvents::Emit(GlobalEvents::MIXER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,7 +90,7 @@ pulse_mixer_volume_cb(G_GNUC_UNUSED pa_context *context, const pa_sink_input_inf
|
|||||||
pm->online = true;
|
pm->online = true;
|
||||||
pm->volume = i->volume;
|
pm->volume = i->volume;
|
||||||
|
|
||||||
event_pipe_emit(PIPE_EVENT_MIXER);
|
GlobalEvents::Emit(GlobalEvents::MIXER);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -26,7 +26,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include "pcm_volume.h"
|
#include "pcm_volume.h"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ roar_output_set_volume(G_GNUC_UNUSED struct roar *roar,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
event_pipe_emit(G_GNUC_UNUSED enum pipe_event event)
|
GlobalEvents::Emit(gcc_unused Event event)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "OutputControl.hxx"
|
#include "OutputControl.hxx"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "EventPipe.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "output_plugin.h"
|
#include "output_plugin.h"
|
||||||
@ -43,7 +43,7 @@ extern "C" {
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
event_pipe_emit(G_GNUC_UNUSED enum pipe_event event)
|
GlobalEvents::Emit(gcc_unused Event event)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user