From e86e77ad67f883111d50f0886204ad96c8d0f90b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 9 Jan 2013 08:36:52 +0100 Subject: idle: convert to C++ --- src/ClientIdle.cxx | 5 +-- src/ClientSubscribe.cxx | 5 +-- src/Idle.cxx | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ src/Idle.hxx | 95 +++++++++++++++++++++++++++++++++++++++++++++++ src/Main.cxx | 2 +- src/OtherCommands.cxx | 5 +-- src/OutputCommand.cxx | 2 +- src/PlayerControl.cxx | 6 +-- src/PlayerThread.cxx | 2 +- src/Playlist.cxx | 5 +-- src/PlaylistEdit.cxx | 2 +- src/PlaylistFile.cxx | 2 +- src/PlaylistSave.cxx | 2 +- src/ReplayGainConfig.cxx | 6 +-- src/StickerDatabase.cxx | 5 +-- src/UpdateGlue.cxx | 2 +- src/Volume.cxx | 2 +- src/idle.c | 94 ---------------------------------------------- src/idle.h | 95 ----------------------------------------------- 19 files changed, 207 insertions(+), 227 deletions(-) create mode 100644 src/Idle.cxx create mode 100644 src/Idle.hxx delete mode 100644 src/idle.c delete mode 100644 src/idle.h (limited to 'src') diff --git a/src/ClientIdle.cxx b/src/ClientIdle.cxx index c125a8dfa..c68bee839 100644 --- a/src/ClientIdle.cxx +++ b/src/ClientIdle.cxx @@ -21,10 +21,7 @@ #include "ClientIdle.hxx" #include "ClientInternal.hxx" #include "ClientList.hxx" - -extern "C" { -#include "idle.h" -} +#include "Idle.hxx" #include diff --git a/src/ClientSubscribe.cxx b/src/ClientSubscribe.cxx index a1ad6e68e..fd7a93c84 100644 --- a/src/ClientSubscribe.cxx +++ b/src/ClientSubscribe.cxx @@ -20,10 +20,7 @@ #include "ClientSubscribe.hxx" #include "ClientIdle.hxx" #include "ClientInternal.hxx" - -extern "C" { -#include "idle.h" -} +#include "Idle.hxx" #include #include diff --git a/src/Idle.cxx b/src/Idle.cxx new file mode 100644 index 000000000..4027461c2 --- /dev/null +++ b/src/Idle.cxx @@ -0,0 +1,97 @@ +/* + * 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. + */ + +/* + * Support library for the "idle" command. + * + */ + +#include "config.h" +#include "Idle.hxx" + +extern "C" { +#include "event_pipe.h" +} + +#include +#include + +static unsigned idle_flags; +static GMutex *idle_mutex = NULL; + +static const char *const idle_names[] = { + "database", + "stored_playlist", + "playlist", + "player", + "mixer", + "output", + "options", + "sticker", + "update", + "subscription", + "message", + NULL +}; + +void +idle_init(void) +{ + g_assert(idle_mutex == NULL); + idle_mutex = g_mutex_new(); +} + +void +idle_deinit(void) +{ + g_assert(idle_mutex != NULL); + g_mutex_free(idle_mutex); + idle_mutex = NULL; +} + +void +idle_add(unsigned flags) +{ + assert(flags != 0); + + g_mutex_lock(idle_mutex); + idle_flags |= flags; + g_mutex_unlock(idle_mutex); + + event_pipe_emit(PIPE_EVENT_IDLE); +} + +unsigned +idle_get(void) +{ + unsigned flags; + + g_mutex_lock(idle_mutex); + flags = idle_flags; + idle_flags = 0; + g_mutex_unlock(idle_mutex); + + return flags; +} + +const char*const* +idle_get_names(void) +{ + return idle_names; +} diff --git a/src/Idle.hxx b/src/Idle.hxx new file mode 100644 index 000000000..e77061300 --- /dev/null +++ b/src/Idle.hxx @@ -0,0 +1,95 @@ +/* + * 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. + */ + +/* + * Support library for the "idle" command. + * + */ + +#ifndef MPD_IDLE_HXX +#define MPD_IDLE_HXX + +enum { + /** song database has been updated*/ + IDLE_DATABASE = 0x1, + + /** a stored playlist has been modified, created, deleted or + renamed */ + IDLE_STORED_PLAYLIST = 0x2, + + /** the current playlist has been modified */ + IDLE_PLAYLIST = 0x4, + + /** the player state has changed: play, stop, pause, seek, ... */ + IDLE_PLAYER = 0x8, + + /** the volume has been modified */ + IDLE_MIXER = 0x10, + + /** an audio output device has been enabled or disabled */ + IDLE_OUTPUT = 0x20, + + /** options have changed: crossfade, random, repeat, ... */ + IDLE_OPTIONS = 0x40, + + /** a sticker has been modified. */ + IDLE_STICKER = 0x80, + + /** a database update has started or finished. */ + IDLE_UPDATE = 0x100, + + /** a client has subscribed or unsubscribed to/from a channel */ + IDLE_SUBSCRIPTION = 0x200, + + /** a message on the subscribed channel was receivedd */ + IDLE_MESSAGE = 0x400, +}; + +/** + * Initialize the mutex + */ +void +idle_init(void); + +/** + * Destroy the mutex + */ +void +idle_deinit(void); + +/** + * Adds idle flag (with bitwise "or") and queues notifications to all + * clients. + */ +void +idle_add(unsigned flags); + +/** + * Atomically reads and resets the global idle flags value. + */ +unsigned +idle_get(void); + +/** + * Get idle names + */ +const char*const* +idle_get_names(void); + +#endif diff --git a/src/Main.cxx b/src/Main.cxx index 7ff19538d..cd6392d58 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -39,11 +39,11 @@ #include "tag.h" #include "conf.h" #include "replay_gain_config.h" +#include "Idle.hxx" extern "C" { #include "daemon.h" #include "io_thread.h" -#include "idle.h" #include "path.h" #include "stats.h" #include "sig_handlers.h" diff --git a/src/OtherCommands.cxx b/src/OtherCommands.cxx index d467c30ef..b8cc36cc5 100644 --- a/src/OtherCommands.cxx +++ b/src/OtherCommands.cxx @@ -44,10 +44,7 @@ extern "C" { #include "ClientIdle.hxx" #include "ClientFile.hxx" #include "Client.hxx" - -extern "C" { -#include "idle.h" -} +#include "Idle.hxx" #ifdef ENABLE_SQLITE #include "StickerDatabase.hxx" diff --git a/src/OutputCommand.cxx b/src/OutputCommand.cxx index 3c9ff56fe..f4edaa4a1 100644 --- a/src/OutputCommand.cxx +++ b/src/OutputCommand.cxx @@ -28,12 +28,12 @@ #include "OutputCommand.hxx" #include "OutputAll.hxx" #include "PlayerControl.hxx" +#include "Idle.hxx" extern "C" { #include "output_internal.h" #include "output_plugin.h" #include "mixer_control.h" -#include "idle.h" } extern unsigned audio_output_state_version; diff --git a/src/PlayerControl.cxx b/src/PlayerControl.cxx index 4fa9f75b2..1b5ca597e 100644 --- a/src/PlayerControl.cxx +++ b/src/PlayerControl.cxx @@ -19,11 +19,7 @@ #include "config.h" #include "PlayerControl.hxx" - -extern "C" { -#include "idle.h" -} - +#include "Idle.hxx" #include "song.h" #include "DecoderControl.hxx" #include "Main.hxx" diff --git a/src/PlayerThread.cxx b/src/PlayerThread.cxx index 44534a7d8..bb6f52e02 100644 --- a/src/PlayerThread.cxx +++ b/src/PlayerThread.cxx @@ -31,10 +31,10 @@ #include "PlayerControl.hxx" #include "OutputAll.hxx" #include "tag.h" +#include "Idle.hxx" extern "C" { #include "event_pipe.h" -#include "idle.h" } #include diff --git a/src/Playlist.cxx b/src/Playlist.cxx index 4d1d4897e..a402471da 100644 --- a/src/Playlist.cxx +++ b/src/Playlist.cxx @@ -21,10 +21,7 @@ #include "Playlist.hxx" #include "PlayerControl.hxx" #include "song.h" - -extern "C" { -#include "idle.h" -} +#include "Idle.hxx" #include diff --git a/src/PlaylistEdit.cxx b/src/PlaylistEdit.cxx index 22b7242c1..cdfb77150 100644 --- a/src/PlaylistEdit.cxx +++ b/src/PlaylistEdit.cxx @@ -30,9 +30,9 @@ extern "C" { #include "uri.h" #include "song.h" -#include "idle.h" } +#include "Idle.hxx" #include "DatabaseGlue.hxx" #include "DatabasePlugin.hxx" diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx index a048c02ce..d79bea9c5 100644 --- a/src/PlaylistFile.cxx +++ b/src/PlaylistFile.cxx @@ -29,11 +29,11 @@ #include "Mapper.hxx" #include "TextFile.hxx" #include "conf.h" +#include "Idle.hxx" extern "C" { #include "path.h" #include "uri.h" -#include "idle.h" } #include "glib_compat.h" diff --git a/src/PlaylistSave.cxx b/src/PlaylistSave.cxx index e3b952280..745744490 100644 --- a/src/PlaylistSave.cxx +++ b/src/PlaylistSave.cxx @@ -23,11 +23,11 @@ #include "Playlist.hxx" #include "song.h" #include "Mapper.hxx" +#include "Idle.hxx" extern "C" { #include "path.h" #include "uri.h" -#include "idle.h" } #include "glib_compat.h" diff --git a/src/ReplayGainConfig.cxx b/src/ReplayGainConfig.cxx index 14bb41755..d86c70053 100644 --- a/src/ReplayGainConfig.cxx +++ b/src/ReplayGainConfig.cxx @@ -19,11 +19,7 @@ #include "config.h" #include "replay_gain_config.h" - -extern "C" { -#include "idle.h" -} - +#include "Idle.hxx" #include "conf.h" #include "Playlist.hxx" #include "mpd_error.h" diff --git a/src/StickerDatabase.cxx b/src/StickerDatabase.cxx index 3d6e212d1..2d77e4b63 100644 --- a/src/StickerDatabase.cxx +++ b/src/StickerDatabase.cxx @@ -19,10 +19,7 @@ #include "config.h" #include "StickerDatabase.hxx" - -extern "C" { -#include "idle.h" -} +#include "Idle.hxx" #include #include diff --git a/src/UpdateGlue.cxx b/src/UpdateGlue.cxx index 2edd19cc2..d990ddfe6 100644 --- a/src/UpdateGlue.cxx +++ b/src/UpdateGlue.cxx @@ -24,10 +24,10 @@ #include "UpdateRemove.hxx" #include "Mapper.hxx" #include "DatabaseSimple.hxx" +#include "Idle.hxx" extern "C" { #include "event_pipe.h" -#include "idle.h" #include "stats.h" } diff --git a/src/Volume.cxx b/src/Volume.cxx index 2c954fae9..a046aa942 100644 --- a/src/Volume.cxx +++ b/src/Volume.cxx @@ -20,9 +20,9 @@ #include "config.h" #include "Volume.hxx" #include "MixerAll.hxx" +#include "Idle.hxx" extern "C" { -#include "idle.h" #include "event_pipe.h" } diff --git a/src/idle.c b/src/idle.c deleted file mode 100644 index 2d174d78a..000000000 --- a/src/idle.c +++ /dev/null @@ -1,94 +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. - */ - -/* - * Support library for the "idle" command. - * - */ - -#include "config.h" -#include "idle.h" -#include "event_pipe.h" - -#include -#include - -static unsigned idle_flags; -static GMutex *idle_mutex = NULL; - -static const char *const idle_names[] = { - "database", - "stored_playlist", - "playlist", - "player", - "mixer", - "output", - "options", - "sticker", - "update", - "subscription", - "message", - NULL -}; - -void -idle_init(void) -{ - g_assert(idle_mutex == NULL); - idle_mutex = g_mutex_new(); -} - -void -idle_deinit(void) -{ - g_assert(idle_mutex != NULL); - g_mutex_free(idle_mutex); - idle_mutex = NULL; -} - -void -idle_add(unsigned flags) -{ - assert(flags != 0); - - g_mutex_lock(idle_mutex); - idle_flags |= flags; - g_mutex_unlock(idle_mutex); - - event_pipe_emit(PIPE_EVENT_IDLE); -} - -unsigned -idle_get(void) -{ - unsigned flags; - - g_mutex_lock(idle_mutex); - flags = idle_flags; - idle_flags = 0; - g_mutex_unlock(idle_mutex); - - return flags; -} - -const char*const* -idle_get_names(void) -{ - return idle_names; -} diff --git a/src/idle.h b/src/idle.h deleted file mode 100644 index 0156933c0..000000000 --- a/src/idle.h +++ /dev/null @@ -1,95 +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. - */ - -/* - * Support library for the "idle" command. - * - */ - -#ifndef MPD_IDLE_H -#define MPD_IDLE_H - -enum { - /** song database has been updated*/ - IDLE_DATABASE = 0x1, - - /** a stored playlist has been modified, created, deleted or - renamed */ - IDLE_STORED_PLAYLIST = 0x2, - - /** the current playlist has been modified */ - IDLE_PLAYLIST = 0x4, - - /** the player state has changed: play, stop, pause, seek, ... */ - IDLE_PLAYER = 0x8, - - /** the volume has been modified */ - IDLE_MIXER = 0x10, - - /** an audio output device has been enabled or disabled */ - IDLE_OUTPUT = 0x20, - - /** options have changed: crossfade, random, repeat, ... */ - IDLE_OPTIONS = 0x40, - - /** a sticker has been modified. */ - IDLE_STICKER = 0x80, - - /** a database update has started or finished. */ - IDLE_UPDATE = 0x100, - - /** a client has subscribed or unsubscribed to/from a channel */ - IDLE_SUBSCRIPTION = 0x200, - - /** a message on the subscribed channel was receivedd */ - IDLE_MESSAGE = 0x400, -}; - -/** - * Initialize the mutex - */ -void -idle_init(void); - -/** - * Destroy the mutex - */ -void -idle_deinit(void); - -/** - * Adds idle flag (with bitwise "or") and queues notifications to all - * clients. - */ -void -idle_add(unsigned flags); - -/** - * Atomically reads and resets the global idle flags value. - */ -unsigned -idle_get(void); - -/** - * Get idle names - */ -const char*const* -idle_get_names(void); - -#endif -- cgit v1.2.3