From 5faf443038edfb7e79ae423a3499faa3af05d64b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 9 Jan 2013 22:37:47 +0100 Subject: event_pipe.h: convert to C++ --- Makefile.am | 3 +- src/EventPipe.cxx | 2 +- src/EventPipe.hxx | 69 ++++++++++++++++++ src/Idle.cxx | 5 +- src/Main.cxx | 2 +- src/PlayerThread.cxx | 5 +- src/PlaylistGlobal.cxx | 5 +- src/SignalHandlers.cxx | 2 +- src/UpdateGlue.cxx | 2 +- src/UpdateRemove.cxx | 5 +- src/Volume.cxx | 5 +- src/Win32Main.cxx | 5 +- src/event_pipe.h | 77 -------------------- src/mixer/AlsaMixerPlugin.cxx | 2 +- src/mixer/PulseMixerPlugin.cxx | 2 +- test/read_mixer.c | 154 --------------------------------------- test/read_mixer.cxx | 158 +++++++++++++++++++++++++++++++++++++++++ test/run_output.cxx | 2 +- 18 files changed, 241 insertions(+), 264 deletions(-) create mode 100644 src/EventPipe.hxx delete mode 100644 src/event_pipe.h delete mode 100644 test/read_mixer.c create mode 100644 test/read_mixer.cxx diff --git a/Makefile.am b/Makefile.am index 779ddc1a..a564c78b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -96,7 +96,6 @@ mpd_headers = \ src/mixer_api.h \ src/mixer_control.h \ src/mixer_list.h \ - src/event_pipe.h \ src/mixer_plugin.h \ src/mixer_type.h \ src/mixer/software_mixer_plugin.h \ @@ -244,7 +243,7 @@ src_mpd_SOURCES = \ src/io_thread.c src/io_thread.h \ src/Main.cxx src/Main.hxx \ src/Win32Main.cxx \ - src/EventPipe.cxx \ + src/EventPipe.cxx src/EventPipe.hxx \ src/daemon.c \ src/AudioCompress/compress.c \ src/MusicBuffer.cxx src/MusicBuffer.hxx \ diff --git a/src/EventPipe.cxx b/src/EventPipe.cxx index b2c80a3c..6c885c01 100644 --- a/src/EventPipe.cxx +++ b/src/EventPipe.cxx @@ -18,7 +18,7 @@ */ #include "config.h" -#include "event_pipe.h" +#include "EventPipe.hxx" #include "fd_util.h" #include "mpd_error.h" diff --git a/src/EventPipe.hxx b/src/EventPipe.hxx new file mode 100644 index 00000000..f7a0c30f --- /dev/null +++ b/src/EventPipe.hxx @@ -0,0 +1,69 @@ +/* + * 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 */ diff --git a/src/Idle.cxx b/src/Idle.cxx index 4027461c..0d42f7dd 100644 --- a/src/Idle.cxx +++ b/src/Idle.cxx @@ -24,10 +24,7 @@ #include "config.h" #include "Idle.hxx" - -extern "C" { -#include "event_pipe.h" -} +#include "EventPipe.hxx" #include #include diff --git a/src/Main.cxx b/src/Main.cxx index c6694307..a158b5e2 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -43,6 +43,7 @@ #include "Idle.hxx" #include "SignalHandlers.hxx" #include "Log.hxx" +#include "EventPipe.hxx" extern "C" { #include "daemon.h" @@ -55,7 +56,6 @@ extern "C" { #include "input_init.h" #include "playlist_list.h" #include "zeroconf.h" -#include "event_pipe.h" } #include "mpd_error.h" diff --git a/src/PlayerThread.cxx b/src/PlayerThread.cxx index bb6f52e0..14c8a03f 100644 --- a/src/PlayerThread.cxx +++ b/src/PlayerThread.cxx @@ -32,10 +32,7 @@ #include "OutputAll.hxx" #include "tag.h" #include "Idle.hxx" - -extern "C" { -#include "event_pipe.h" -} +#include "EventPipe.hxx" #include diff --git a/src/PlaylistGlobal.cxx b/src/PlaylistGlobal.cxx index 1a5f1141..87f362a2 100644 --- a/src/PlaylistGlobal.cxx +++ b/src/PlaylistGlobal.cxx @@ -27,10 +27,7 @@ #include "Playlist.hxx" #include "Main.hxx" #include "Partition.hxx" - -extern "C" { -#include "event_pipe.h" -} +#include "EventPipe.hxx" static void playlist_tag_event(void) diff --git a/src/SignalHandlers.cxx b/src/SignalHandlers.cxx index dfef9bf8..14da08c7 100644 --- a/src/SignalHandlers.cxx +++ b/src/SignalHandlers.cxx @@ -24,7 +24,7 @@ #include "Log.hxx" #include "Main.hxx" -#include "event_pipe.h" +#include "EventPipe.hxx" #include "mpd_error.h" #include diff --git a/src/UpdateGlue.cxx b/src/UpdateGlue.cxx index 984535be..fba4c186 100644 --- a/src/UpdateGlue.cxx +++ b/src/UpdateGlue.cxx @@ -25,9 +25,9 @@ #include "Mapper.hxx" #include "DatabaseSimple.hxx" #include "Idle.hxx" +#include "EventPipe.hxx" extern "C" { -#include "event_pipe.h" #include "stats.h" } diff --git a/src/UpdateRemove.cxx b/src/UpdateRemove.cxx index 41aa5177..afa7c293 100644 --- a/src/UpdateRemove.cxx +++ b/src/UpdateRemove.cxx @@ -21,10 +21,7 @@ #include "UpdateRemove.hxx" #include "Playlist.hxx" #include "Partition.hxx" - -extern "C" { -#include "event_pipe.h" -} +#include "EventPipe.hxx" #include "song.h" #include "Main.hxx" diff --git a/src/Volume.cxx b/src/Volume.cxx index a046aa94..6a71a696 100644 --- a/src/Volume.cxx +++ b/src/Volume.cxx @@ -21,10 +21,7 @@ #include "Volume.hxx" #include "MixerAll.hxx" #include "Idle.hxx" - -extern "C" { -#include "event_pipe.h" -} +#include "EventPipe.hxx" #include diff --git a/src/Win32Main.cxx b/src/Win32Main.cxx index 8543ea10..710811f4 100644 --- a/src/Win32Main.cxx +++ b/src/Win32Main.cxx @@ -23,10 +23,7 @@ #ifdef WIN32 #include "mpd_error.h" - -extern "C" { -#include "event_pipe.h" -} +#include "EventPipe.hxx" #include diff --git a/src/event_pipe.h b/src/event_pipe.h deleted file mode 100644 index 7c136304..00000000 --- a/src/event_pipe.h +++ /dev/null @@ -1,77 +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 EVENT_PIPE_H -#define EVENT_PIPE_H - -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); - -#ifdef __cplusplus -extern "C" { -#endif - -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); - -#ifdef __cplusplus -} -#endif - -#endif /* MAIN_NOTIFY_H */ diff --git a/src/mixer/AlsaMixerPlugin.cxx b/src/mixer/AlsaMixerPlugin.cxx index 6623d12e..f00bfcb9 100644 --- a/src/mixer/AlsaMixerPlugin.cxx +++ b/src/mixer/AlsaMixerPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "mixer_api.h" #include "output_api.h" -#include "event_pipe.h" +#include "EventPipe.hxx" #include #include diff --git a/src/mixer/PulseMixerPlugin.cxx b/src/mixer/PulseMixerPlugin.cxx index 509b91bc..3b793756 100644 --- a/src/mixer/PulseMixerPlugin.cxx +++ b/src/mixer/PulseMixerPlugin.cxx @@ -22,7 +22,7 @@ #include "mixer_api.h" #include "output/pulse_output_plugin.h" #include "conf.h" -#include "event_pipe.h" +#include "EventPipe.hxx" #include diff --git a/test/read_mixer.c b/test/read_mixer.c deleted file mode 100644 index f6de8177..00000000 --- a/test/read_mixer.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2003-2011 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 "mixer_control.h" -#include "mixer_list.h" -#include "filter_registry.h" -#include "pcm_volume.h" -#include "event_pipe.h" - -#include - -#include -#include -#include - -#ifdef HAVE_PULSE -#include "output/pulse_output_plugin.h" - -void -pulse_output_lock(G_GNUC_UNUSED struct pulse_output *po) -{ -} - -void -pulse_output_unlock(G_GNUC_UNUSED struct pulse_output *po) -{ -} - -void -pulse_output_set_mixer(G_GNUC_UNUSED struct pulse_output *po, - G_GNUC_UNUSED struct pulse_mixer *pm) -{ -} - -void -pulse_output_clear_mixer(G_GNUC_UNUSED struct pulse_output *po, - G_GNUC_UNUSED struct pulse_mixer *pm) -{ -} - -bool -pulse_output_set_volume(G_GNUC_UNUSED struct pulse_output *po, - G_GNUC_UNUSED const struct pa_cvolume *volume, - G_GNUC_UNUSED GError **error_r) -{ - return false; -} - -#endif - -#ifdef HAVE_ROAR -#include "output/roar_output_plugin.h" - -int -roar_output_get_volume(G_GNUC_UNUSED struct roar *roar) -{ - return -1; -} - -bool -roar_output_set_volume(G_GNUC_UNUSED struct roar *roar, - G_GNUC_UNUSED unsigned volume) -{ - return true; -} - -#endif - -void -event_pipe_emit(G_GNUC_UNUSED enum pipe_event event) -{ -} - -const struct filter_plugin * -filter_plugin_by_name(G_GNUC_UNUSED const char *name) -{ - assert(false); - return NULL; -} - -bool -pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED size_t length, - G_GNUC_UNUSED enum sample_format format, - G_GNUC_UNUSED int volume) -{ - assert(false); - return false; -} - -int main(int argc, G_GNUC_UNUSED char **argv) -{ - GError *error = NULL; - struct mixer *mixer; - bool success; - int volume; - - if (argc != 2) { - g_printerr("Usage: read_mixer PLUGIN\n"); - return 1; - } - - g_thread_init(NULL); - - mixer = mixer_new(&alsa_mixer_plugin, NULL, NULL, &error); - if (mixer == NULL) { - g_printerr("mixer_new() failed: %s\n", error->message); - g_error_free(error); - return 2; - } - - success = mixer_open(mixer, &error); - if (!success) { - mixer_free(mixer); - g_printerr("failed to open the mixer: %s\n", error->message); - g_error_free(error); - return 2; - } - - volume = mixer_get_volume(mixer, &error); - mixer_close(mixer); - mixer_free(mixer); - - assert(volume >= -1 && volume <= 100); - - if (volume < 0) { - if (error != NULL) { - g_printerr("failed to read volume: %s\n", - error->message); - g_error_free(error); - } else - g_printerr("failed to read volume\n"); - return 2; - } - - g_print("%d\n", volume); - return 0; -} diff --git a/test/read_mixer.cxx b/test/read_mixer.cxx new file mode 100644 index 00000000..c9392ab7 --- /dev/null +++ b/test/read_mixer.cxx @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2003-2011 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" + +extern "C" { +#include "mixer_control.h" +#include "mixer_list.h" +#include "filter_registry.h" +} + +#include "pcm_volume.h" +#include "EventPipe.hxx" + +#include + +#include +#include +#include + +#ifdef HAVE_PULSE +#include "output/pulse_output_plugin.h" + +void +pulse_output_lock(G_GNUC_UNUSED struct pulse_output *po) +{ +} + +void +pulse_output_unlock(G_GNUC_UNUSED struct pulse_output *po) +{ +} + +void +pulse_output_set_mixer(G_GNUC_UNUSED struct pulse_output *po, + G_GNUC_UNUSED struct pulse_mixer *pm) +{ +} + +void +pulse_output_clear_mixer(G_GNUC_UNUSED struct pulse_output *po, + G_GNUC_UNUSED struct pulse_mixer *pm) +{ +} + +bool +pulse_output_set_volume(G_GNUC_UNUSED struct pulse_output *po, + G_GNUC_UNUSED const struct pa_cvolume *volume, + G_GNUC_UNUSED GError **error_r) +{ + return false; +} + +#endif + +#ifdef HAVE_ROAR +#include "output/roar_output_plugin.h" + +int +roar_output_get_volume(G_GNUC_UNUSED struct roar *roar) +{ + return -1; +} + +bool +roar_output_set_volume(G_GNUC_UNUSED struct roar *roar, + G_GNUC_UNUSED unsigned volume) +{ + return true; +} + +#endif + +void +event_pipe_emit(G_GNUC_UNUSED enum pipe_event event) +{ +} + +const struct filter_plugin * +filter_plugin_by_name(G_GNUC_UNUSED const char *name) +{ + assert(false); + return NULL; +} + +bool +pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED size_t length, + G_GNUC_UNUSED enum sample_format format, + G_GNUC_UNUSED int volume) +{ + assert(false); + return false; +} + +int main(int argc, G_GNUC_UNUSED char **argv) +{ + GError *error = NULL; + struct mixer *mixer; + bool success; + int volume; + + if (argc != 2) { + g_printerr("Usage: read_mixer PLUGIN\n"); + return 1; + } + + g_thread_init(NULL); + + mixer = mixer_new(&alsa_mixer_plugin, NULL, NULL, &error); + if (mixer == NULL) { + g_printerr("mixer_new() failed: %s\n", error->message); + g_error_free(error); + return 2; + } + + success = mixer_open(mixer, &error); + if (!success) { + mixer_free(mixer); + g_printerr("failed to open the mixer: %s\n", error->message); + g_error_free(error); + return 2; + } + + volume = mixer_get_volume(mixer, &error); + mixer_close(mixer); + mixer_free(mixer); + + assert(volume >= -1 && volume <= 100); + + if (volume < 0) { + if (error != NULL) { + g_printerr("failed to read volume: %s\n", + error->message); + g_error_free(error); + } else + g_printerr("failed to read volume\n"); + return 2; + } + + g_print("%d\n", volume); + return 0; +} diff --git a/test/run_output.cxx b/test/run_output.cxx index 97583488..68df5e45 100644 --- a/test/run_output.cxx +++ b/test/run_output.cxx @@ -21,6 +21,7 @@ #include "OutputControl.hxx" #include "conf.h" #include "Idle.hxx" +#include "EventPipe.hxx" extern "C" { #include "output_plugin.h" @@ -29,7 +30,6 @@ extern "C" { #include "audio_parser.h" #include "filter_registry.h" #include "pcm_convert.h" -#include "event_pipe.h" } #include "PlayerControl.hxx" -- cgit v1.2.3