notify: convert to C++
This commit is contained in:
parent
e0a97a030f
commit
b8cda53bd3
@ -46,7 +46,6 @@ src_mpd_LDADD = \
|
|||||||
|
|
||||||
mpd_headers = \
|
mpd_headers = \
|
||||||
src/check.h \
|
src/check.h \
|
||||||
src/notify.h \
|
|
||||||
src/ack.h \
|
src/ack.h \
|
||||||
src/ape.h \
|
src/ape.h \
|
||||||
src/audio_format.h \
|
src/audio_format.h \
|
||||||
@ -166,7 +165,7 @@ src_mpd_SOURCES = \
|
|||||||
src/thread/GLibCond.hxx \
|
src/thread/GLibCond.hxx \
|
||||||
src/glib_socket.h \
|
src/glib_socket.h \
|
||||||
src/clock.c src/clock.h \
|
src/clock.c src/clock.h \
|
||||||
src/notify.c \
|
src/notify.cxx src/notify.hxx \
|
||||||
src/audio_config.c src/audio_config.h \
|
src/audio_config.c src/audio_config.h \
|
||||||
src/audio_check.c \
|
src/audio_check.c \
|
||||||
src/audio_format.c \
|
src/audio_format.c \
|
||||||
|
@ -32,10 +32,7 @@ extern "C" {
|
|||||||
#include "MusicChunk.hxx"
|
#include "MusicChunk.hxx"
|
||||||
#include "mpd_error.h"
|
#include "mpd_error.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
#include "notify.hxx"
|
||||||
extern "C" {
|
|
||||||
#include "notify.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -113,8 +110,6 @@ audio_output_all_init(struct player_control *pc)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
notify_init(&audio_output_client_notify);
|
|
||||||
|
|
||||||
num_audio_outputs = audio_output_config_count();
|
num_audio_outputs = audio_output_config_count();
|
||||||
audio_outputs = g_new(struct audio_output *, num_audio_outputs);
|
audio_outputs = g_new(struct audio_output *, num_audio_outputs);
|
||||||
|
|
||||||
@ -161,8 +156,6 @@ audio_output_all_finish(void)
|
|||||||
g_free(audio_outputs);
|
g_free(audio_outputs);
|
||||||
audio_outputs = NULL;
|
audio_outputs = NULL;
|
||||||
num_audio_outputs = 0;
|
num_audio_outputs = 0;
|
||||||
|
|
||||||
notify_deinit(&audio_output_client_notify);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -211,7 +204,7 @@ audio_output_all_finished(void)
|
|||||||
static void audio_output_wait_all(void)
|
static void audio_output_wait_all(void)
|
||||||
{
|
{
|
||||||
while (!audio_output_all_finished())
|
while (!audio_output_all_finished())
|
||||||
notify_wait(&audio_output_client_notify);
|
audio_output_client_notify.Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,9 +26,9 @@ extern "C" {
|
|||||||
#include "output_internal.h"
|
#include "output_internal.h"
|
||||||
#include "mixer_control.h"
|
#include "mixer_control.h"
|
||||||
#include "mixer_plugin.h"
|
#include "mixer_plugin.h"
|
||||||
#include "notify.h"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "notify.hxx"
|
||||||
#include "filter/ReplayGainFilterPlugin.hxx"
|
#include "filter/ReplayGainFilterPlugin.hxx"
|
||||||
#include "filter_plugin.h"
|
#include "filter_plugin.h"
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ static void ao_command_wait(struct audio_output *ao)
|
|||||||
{
|
{
|
||||||
while (ao->command != AO_COMMAND_NONE) {
|
while (ao->command != AO_COMMAND_NONE) {
|
||||||
g_mutex_unlock(ao->mutex);
|
g_mutex_unlock(ao->mutex);
|
||||||
notify_wait(&audio_output_client_notify);
|
audio_output_client_notify.Wait();
|
||||||
g_mutex_lock(ao->mutex);
|
g_mutex_lock(ao->mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,9 @@ extern "C" {
|
|||||||
#include "pcm_mix.h"
|
#include "pcm_mix.h"
|
||||||
#include "filter_plugin.h"
|
#include "filter_plugin.h"
|
||||||
#include "filter/convert_filter_plugin.h"
|
#include "filter/convert_filter_plugin.h"
|
||||||
#include "notify.h"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "notify.hxx"
|
||||||
#include "filter/ReplayGainFilterPlugin.hxx"
|
#include "filter/ReplayGainFilterPlugin.hxx"
|
||||||
#include "PlayerControl.hxx"
|
#include "PlayerControl.hxx"
|
||||||
#include "MusicPipe.hxx"
|
#include "MusicPipe.hxx"
|
||||||
@ -52,7 +52,7 @@ static void ao_command_finished(struct audio_output *ao)
|
|||||||
ao->command = AO_COMMAND_NONE;
|
ao->command = AO_COMMAND_NONE;
|
||||||
|
|
||||||
g_mutex_unlock(ao->mutex);
|
g_mutex_unlock(ao->mutex);
|
||||||
notify_signal(&audio_output_client_notify);
|
audio_output_client_notify.Signal();
|
||||||
g_mutex_lock(ao->mutex);
|
g_mutex_lock(ao->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
58
src/notify.c
58
src/notify.c
@ -1,58 +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 "notify.h"
|
|
||||||
|
|
||||||
void notify_init(struct notify *notify)
|
|
||||||
{
|
|
||||||
notify->mutex = g_mutex_new();
|
|
||||||
notify->cond = g_cond_new();
|
|
||||||
notify->pending = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void notify_deinit(struct notify *notify)
|
|
||||||
{
|
|
||||||
g_mutex_free(notify->mutex);
|
|
||||||
g_cond_free(notify->cond);
|
|
||||||
}
|
|
||||||
|
|
||||||
void notify_wait(struct notify *notify)
|
|
||||||
{
|
|
||||||
g_mutex_lock(notify->mutex);
|
|
||||||
while (!notify->pending)
|
|
||||||
g_cond_wait(notify->cond, notify->mutex);
|
|
||||||
notify->pending = false;
|
|
||||||
g_mutex_unlock(notify->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void notify_signal(struct notify *notify)
|
|
||||||
{
|
|
||||||
g_mutex_lock(notify->mutex);
|
|
||||||
notify->pending = true;
|
|
||||||
g_cond_signal(notify->cond);
|
|
||||||
g_mutex_unlock(notify->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void notify_clear(struct notify *notify)
|
|
||||||
{
|
|
||||||
g_mutex_lock(notify->mutex);
|
|
||||||
notify->pending = false;
|
|
||||||
g_mutex_unlock(notify->mutex);
|
|
||||||
}
|
|
45
src/notify.cxx
Normal file
45
src/notify.cxx
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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 "notify.hxx"
|
||||||
|
|
||||||
|
void
|
||||||
|
notify::Wait()
|
||||||
|
{
|
||||||
|
const ScopeLock protect(mutex);
|
||||||
|
while (!pending)
|
||||||
|
cond.wait(mutex);
|
||||||
|
pending = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
notify::Signal()
|
||||||
|
{
|
||||||
|
const ScopeLock protect(mutex);
|
||||||
|
pending = true;
|
||||||
|
cond.signal();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
notify::Clear()
|
||||||
|
{
|
||||||
|
const ScopeLock protect(mutex);
|
||||||
|
pending = false;
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||||
* http://www.musicpd.org
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -17,37 +17,37 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MPD_NOTIFY_H
|
#ifndef MPD_NOTIFY_HXX
|
||||||
#define MPD_NOTIFY_H
|
#define MPD_NOTIFY_HXX
|
||||||
|
|
||||||
#include <glib.h>
|
#include "thread/Mutex.hxx"
|
||||||
|
#include "thread/Cond.hxx"
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
struct notify {
|
struct notify {
|
||||||
GMutex *mutex;
|
Mutex mutex;
|
||||||
GCond *cond;
|
Cond cond;
|
||||||
bool pending;
|
bool pending;
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
constexpr
|
||||||
|
#endif
|
||||||
|
notify():pending(false) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait for a notification. Return immediately if we have already
|
||||||
|
* been notified since we last returned from notify_wait().
|
||||||
|
*/
|
||||||
|
void Wait();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify the thread. This function never blocks.
|
||||||
|
*/
|
||||||
|
void Signal();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears a pending notification.
|
||||||
|
*/
|
||||||
|
void Clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
void notify_init(struct notify *notify);
|
|
||||||
|
|
||||||
void notify_deinit(struct notify *notify);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wait for a notification. Return immediately if we have already
|
|
||||||
* been notified since we last returned from notify_wait().
|
|
||||||
*/
|
|
||||||
void notify_wait(struct notify *notify);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notify the thread. This function never blocks.
|
|
||||||
*/
|
|
||||||
void notify_signal(struct notify *notify);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears a pending notification.
|
|
||||||
*/
|
|
||||||
void notify_clear(struct notify *notify);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user