[Xfce4-commits] [panel-plugins/xfce4-pulseaudio-plugin] 02/08: Use xfce4-panel debugging methods
noreply at xfce.org
noreply at xfce.org
Tue Mar 3 23:45:57 CET 2015
This is an automated email from the git hooks/post-receive script.
andrzejr pushed a commit to branch master
in repository panel-plugins/xfce4-pulseaudio-plugin.
commit 5057c01c5b6a82e5236e1a536035db8a81c60a76
Author: Guido Berhoerster <guido+xfce at berhoerster.name>
Date: Tue Mar 3 14:38:57 2015 +0100
Use xfce4-panel debugging methods
Use xfce4-panel debuging methods described on
http://docs.xfce.org/xfce/xfce4-panel/debugging#debugging_plugins.
In particular log to stderr and enable debug logging if the PANEL_DEBUG
environment variable is set to "all".
Change G_LOG_DOMAIN to the more intuitive pulseaudio-plugin.
Remove logging to a logfile as multiple plugin instances clobber the
logfile and automatic restart after abort() or crash truncates the
file.
Use pulseaudio_plugin_debug instead of g_debug which provides
additional information.
Conflicts:
panel-plugin/pulseaudio-plugin.c
---
panel-plugin/Makefile.am | 4 +-
panel-plugin/pulseaudio-debug.c | 45 +++++++++++++++++
panel-plugin/pulseaudio-debug.h | 38 +++++++++++++++
panel-plugin/pulseaudio-plugin.c | 100 +++++++++++++++++---------------------
panel-plugin/pulseaudio-volume.c | 27 +++++-----
5 files changed, 145 insertions(+), 69 deletions(-)
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index 60c8c08..907c9c9 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -1,7 +1,7 @@
INCLUDES = \
-I$(top_srcdir) \
- -DG_LOG_DOMAIN=\"libpulseaudio-plugin\" \
+ -DG_LOG_DOMAIN=\"pulseaudio-plugin\" \
-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
$(PLATFORM_CPPFLAGS)
@@ -19,6 +19,8 @@ libpulseaudio_built_sources = \
libpulseaudio_plugin_la_SOURCES = \
$(libpulseaudio_built_sources) \
+ pulseaudio-debug.c \
+ pulseaudio-debug.h \
pulseaudio-volume.c \
pulseaudio-volume.h \
pulseaudio-button.c \
diff --git a/panel-plugin/pulseaudio-debug.c b/panel-plugin/pulseaudio-debug.c
new file mode 100644
index 0000000..0cba907
--- /dev/null
+++ b/panel-plugin/pulseaudio-debug.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015 Guido Berhoerster <guido+xfce at berhoerster.name>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <stdarg.h>
+
+#include "pulseaudio-debug.h"
+
+void
+pulseaudio_debug_real (const gchar *log_domain,
+ const gchar *file,
+ const gchar *func,
+ gint line,
+ const gchar *format, ...)
+{
+ va_list args;
+ gchar *prefixed_format;
+
+ va_start (args, format);
+ prefixed_format = g_strdup_printf ("[%s:%d %s]: %s", file, line, func, format);
+ g_logv (log_domain, G_LOG_LEVEL_DEBUG, prefixed_format, args);
+ va_end (args);
+
+ g_free (prefixed_format);
+}
diff --git a/panel-plugin/pulseaudio-debug.h b/panel-plugin/pulseaudio-debug.h
new file mode 100644
index 0000000..9403b6f
--- /dev/null
+++ b/panel-plugin/pulseaudio-debug.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2015 Guido Berhoerster <guido+xfce at berhoerster.name>
+ *
+ * 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 __PULSEAUDIO_DEBUG_H__
+#define __PULSEAUDIO_DEBUG_H__
+
+#include <glib.h>
+#include <stdarg.h>
+
+G_BEGIN_DECLS
+
+#define pulseaudio_debug(...) pulseaudio_debug_real (G_LOG_DOMAIN, __FILE__, __func__, __LINE__, __VA_ARGS__)
+
+void pulseaudio_debug_real (const gchar *log_domain,
+ const gchar *file,
+ const gchar *func,
+ gint line,
+ const gchar *format, ...) G_GNUC_PRINTF(5, 6);
+
+G_END_DECLS
+
+#endif /* !__PULSEAUDIO_DEBUG_H__ */
diff --git a/panel-plugin/pulseaudio-plugin.c b/panel-plugin/pulseaudio-plugin.c
index 548614b..0f22cc4 100644
--- a/panel-plugin/pulseaudio-plugin.c
+++ b/panel-plugin/pulseaudio-plugin.c
@@ -35,6 +35,7 @@
#include <libxfce4ui/libxfce4ui.h>
#include <libxfce4panel/xfce-panel-plugin.h>
+#include "pulseaudio-debug.h"
#include "pulseaudio-plugin.h"
#include "pulseaudio-config.h"
#include "pulseaudio-volume.h"
@@ -57,6 +58,7 @@
/* prototypes */
+static void pulseaudio_plugin_init_debug (void);
static void pulseaudio_plugin_construct (XfcePanelPlugin *plugin);
static void pulseaudio_plugin_free_data (XfcePanelPlugin *plugin);
static void pulseaudio_plugin_show_about (XfcePanelPlugin *plugin);
@@ -93,9 +95,6 @@ struct _PulseaudioPlugin
/* config dialog builder */
PulseaudioDialog *dialog;
-
- /* log file */
- FILE *logfile;
};
@@ -125,9 +124,12 @@ pulseaudio_plugin_init (PulseaudioPlugin *pulseaudio_plugin)
{
g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
- pulseaudio_plugin->volume = NULL;
- pulseaudio_plugin->button = NULL;
- pulseaudio_plugin->logfile = NULL;
+ /* initialize debug logging */
+ pulseaudio_plugin_init_debug ();
+ pulseaudio_debug("Pulseaudio Panel Plugin initialized");
+
+ pulseaudio_plugin->volume = NULL;
+ pulseaudio_plugin->button = NULL;
}
@@ -146,6 +148,39 @@ pulseaudio_plugin_free_data (XfcePanelPlugin *plugin)
static void
+pulseaudio_plugin_init_debug (void)
+{
+ const gchar *debug_env;
+ gchar **debug_domains;
+ gsize i;
+ gchar *message_debug_env;
+
+ /* enable debug output if the PANEL_DEBUG is set to "all" */
+ debug_env = g_getenv ("PANEL_DEBUG");
+ if ((debug_env != NULL) && (debug_env != '\0'))
+ {
+ debug_domains = g_strsplit (debug_env, ",", -1);
+ for (i = 0; debug_domains[i] != NULL; i++)
+ {
+ g_strstrip (debug_domains[i]);
+
+ if (g_str_equal (debug_domains[i], G_LOG_DOMAIN))
+ break;
+ else if (g_str_equal (debug_domains[i], "all"))
+ {
+ message_debug_env = g_strjoin (" ", G_LOG_DOMAIN, g_getenv ("G_MESSAGES_DEBUG"), NULL);
+ g_setenv ("G_MESSAGES_DEBUG", message_debug_env, TRUE);
+ g_free (message_debug_env);
+ break;
+ }
+ }
+ g_strfreev (debug_domains);
+ }
+}
+
+
+
+static void
pulseaudio_plugin_show_about (XfcePanelPlugin *plugin)
{
GdkPixbuf *icon;
@@ -187,48 +222,6 @@ pulseaudio_plugin_configure_plugin (XfcePanelPlugin *plugin)
-static void
-pulseaudio_plugin_log_handler (const gchar *domain,
- GLogLevelFlags level,
- const gchar *message,
- gpointer data)
-{
- PulseaudioPlugin *pulseaudio_plugin = PULSEAUDIO_PLUGIN (data);
- gchar *path;
- const gchar *prefix;
-
- if (pulseaudio_plugin->logfile == NULL)
- {
- g_mkdir_with_parents (g_get_user_cache_dir (), 0755);
- path = g_build_filename (g_get_user_cache_dir (), "xfce4-pulseaudio-plugin.log", NULL);
- pulseaudio_plugin->logfile = fopen (path, "w");
- g_free (path);
- }
-
- if (pulseaudio_plugin->logfile)
- {
- switch (level & G_LOG_LEVEL_MASK)
- {
- case G_LOG_LEVEL_ERROR: prefix = "ERROR"; break;
- case G_LOG_LEVEL_CRITICAL: prefix = "CRITICAL"; break;
- case G_LOG_LEVEL_WARNING: prefix = "WARNING"; break;
- case G_LOG_LEVEL_MESSAGE: prefix = "MESSAGE"; break;
- case G_LOG_LEVEL_INFO: prefix = "INFO"; break;
- case G_LOG_LEVEL_DEBUG: prefix = "DEBUG"; break;
- default: prefix = "LOG"; break;
- }
-
- fprintf (pulseaudio_plugin->logfile, "%-10s %-25s %s\n", prefix, domain, message);
- fflush (pulseaudio_plugin->logfile);
- }
-
- /* print log to the stdout */
- if (level & G_LOG_LEVEL_ERROR || level & G_LOG_LEVEL_CRITICAL)
- g_log_default_handler (domain, level, message, NULL);
-}
-
-
-
static gboolean
pulseaudio_plugin_size_changed (XfcePanelPlugin *plugin,
gint size)
@@ -264,7 +257,7 @@ pulseaudio_plugin_bind_keys (PulseaudioPlugin *pulseaudio_plugin)
{
gboolean success;
g_return_if_fail (IS_PULSEAUDIO_PLUGIN (pulseaudio_plugin));
- g_debug ("Grabbing volume control keys");
+ pulseaudio_debug ("Grabbing volume control keys");
success = (keybinder_bind (PULSEAUDIO_PLUGIN_LOWER_VOLUME_KEY, pulseaudio_plugin_volume_key_pressed, pulseaudio_plugin) &&
keybinder_bind (PULSEAUDIO_PLUGIN_RAISE_VOLUME_KEY, pulseaudio_plugin_volume_key_pressed, pulseaudio_plugin) &&
@@ -281,7 +274,7 @@ static void
pulseaudio_plugin_unbind_keys (PulseaudioPlugin *pulseaudio_plugin)
{
g_return_if_fail (IS_PULSEAUDIO_PLUGIN (pulseaudio_plugin));
- g_debug ("Releasing volume control keys");
+ pulseaudio_debug ("Releasing volume control keys");
keybinder_unbind (PULSEAUDIO_PLUGIN_LOWER_VOLUME_KEY, pulseaudio_plugin_volume_key_pressed);
keybinder_unbind (PULSEAUDIO_PLUGIN_RAISE_VOLUME_KEY, pulseaudio_plugin_volume_key_pressed);
@@ -298,7 +291,7 @@ pulseaudio_plugin_volume_key_pressed (const char *keystring,
gdouble volume_step = pulseaudio_config_get_volume_step (pulseaudio_plugin->config) / 100.0;
gdouble new_volume;
- g_debug ("%s pressed", keystring);
+ pulseaudio_debug ("%s pressed", keystring);
if (strcmp (keystring, PULSEAUDIO_PLUGIN_RAISE_VOLUME_KEY) == 0)
pulseaudio_volume_set_volume (pulseaudio_plugin->volume, MIN (MAX (volume + volume_step, 0.0), 1.0));
@@ -313,7 +306,7 @@ pulseaudio_plugin_mute_pressed (const char *keystring,
{
PulseaudioPlugin *pulseaudio_plugin = PULSEAUDIO_PLUGIN (user_data);
- g_debug ("%s pressed", keystring);
+ pulseaudio_debug ("%s pressed", keystring);
pulseaudio_volume_toggle_muted (pulseaudio_plugin->volume);
}
@@ -363,9 +356,6 @@ pulseaudio_plugin_construct (XfcePanelPlugin *plugin)
/* setup transation domain */
xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
- /* log messages to a file */
- g_log_set_default_handler (pulseaudio_plugin_log_handler, plugin);
-
/* initialize xfconf */
pulseaudio_plugin->config = pulseaudio_config_new (xfce_panel_plugin_get_property_base (plugin));
diff --git a/panel-plugin/pulseaudio-volume.c b/panel-plugin/pulseaudio-volume.c
index d3e0173..881677a 100644
--- a/panel-plugin/pulseaudio-volume.c
+++ b/panel-plugin/pulseaudio-volume.c
@@ -32,6 +32,7 @@
#include <pulse/pulseaudio.h>
#include <pulse/glib-mainloop.h>
+#include "pulseaudio-debug.h"
#include "pulseaudio-volume.h"
@@ -143,14 +144,14 @@ pulseaudio_volume_sink_info_cb (pa_context *context,
if (volume->muted != muted)
{
- g_debug ("Updated Mute: %d -> %d", volume->muted, muted);
+ pulseaudio_debug ("Updated Mute: %d -> %d", volume->muted, muted);
volume->muted = muted;
g_signal_emit (G_OBJECT (volume), pulseaudio_volume_signals [VOLUME_CHANGED], 0);
}
if (ABS (volume->volume - vol) > 2e-3)
{
- g_debug ("Updated Volume: %04.3f -> %04.3f", volume->volume, vol);
+ pulseaudio_debug ("Updated Volume: %04.3f -> %04.3f", volume->volume, vol);
volume->volume = vol;
g_signal_emit (G_OBJECT (volume), pulseaudio_volume_signals [VOLUME_CHANGED], 0);
}
@@ -166,7 +167,7 @@ pulseaudio_volume_server_info_cb (pa_context *context,
PulseaudioVolume *volume = PULSEAUDIO_VOLUME (userdata);
if (i == NULL) return;
- g_debug ("default sink name = %s\n", i->default_sink_name);
+ pulseaudio_debug ("default sink name = %s\n", i->default_sink_name);
pa_context_get_sink_info_by_name (context, i->default_sink_name, pulseaudio_volume_sink_info_cb, volume);
}
@@ -197,19 +198,19 @@ pulseaudio_volume_subscribe_cb (pa_context *context,
{
case PA_SUBSCRIPTION_EVENT_SINK :
pulseaudio_volume_sink_check (volume, context);
- g_debug ("PulseAudio sink event");
+ pulseaudio_debug ("PulseAudio sink event");
break;
case PA_SUBSCRIPTION_EVENT_SOURCE :
- g_debug ("PulseAudio source event");
+ pulseaudio_debug ("PulseAudio source event");
break;
case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT :
- g_debug ("PulseAudio source output event");
+ pulseaudio_debug ("PulseAudio source output event");
break;
default :
- g_debug ("Unknown PulseAudio event");
+ pulseaudio_debug ("Unknown PulseAudio event");
break;
}
}
@@ -229,7 +230,7 @@ pulseaudio_volume_context_state_cb (pa_context *context,
pa_context_subscribe (context, PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SOURCE | PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, NULL, NULL);
pa_context_set_subscribe_callback (context, pulseaudio_volume_subscribe_cb, volume);
- g_debug ("PulseAudio connection established");
+ pulseaudio_debug ("PulseAudio connection established");
volume->connected = TRUE;
pulseaudio_volume_sink_check (volume, context);
break;
@@ -240,19 +241,19 @@ pulseaudio_volume_context_state_cb (pa_context *context,
break;
case PA_CONTEXT_CONNECTING :
- g_debug ("Connecting to PulseAudio server");
+ pulseaudio_debug ("Connecting to PulseAudio server");
break;
case PA_CONTEXT_SETTING_NAME :
- g_debug ("Setting application name");
+ pulseaudio_debug ("Setting application name");
break;
case PA_CONTEXT_AUTHORIZING :
- g_debug ("Authorizing");
+ pulseaudio_debug ("Authorizing");
break;
case PA_CONTEXT_UNCONNECTED :
- g_debug ("Not connected to PulseAudio server");
+ pulseaudio_debug ("Not connected to PulseAudio server");
break;
default :
@@ -410,7 +411,7 @@ pulseaudio_volume_set_volume_cb2 (pa_context *context,
PulseaudioVolume *volume = PULSEAUDIO_VOLUME (userdata);
if (i == NULL) return;
- //g_debug ("*** %s", pa_cvolume_snprint (st, sizeof (st), &i->volume));
+ //pulseaudio_debug ("*** %s", pa_cvolume_snprint (st, sizeof (st), &i->volume));
pa_cvolume_set (&i->volume, 1, pulseaudio_volume_d2v (volume->volume));
pa_context_set_sink_volume_by_index (context, i->index, &i->volume, pulseaudio_volume_sink_volume_changed, volume);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list