[Xfce4-commits] <xfce4-panel:devel> Add some internal support for debugging.

Nick Schermer noreply at xfce.org
Mon Feb 1 13:26:01 CET 2010


Updating branch refs/heads/devel
         to b2fe9d57463f08454a69176bb67bd6dadc86f4f7 (commit)
       from c0d0eb00f9fbbfd7834a0016481fbadd89670f9e (commit)

commit b2fe9d57463f08454a69176bb67bd6dadc86f4f7
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Feb 1 12:51:09 2010 +0100

    Add some internal support for debugging.
    
    Internal function for debugging support. It supports debug
    domain filtering through the PANEL_DEBUG environment variable
    (PANEL_DEBUG=1 for all debug output and for example
    PANEL_DEBUG=positining:struts for only the positioning and struts
    debug messages.
    
    For now this is always enabled (ie. compiled) so everyone can easily
    give me debug output without recompiling.

 common/Makefile.am                        |    2 +
 common/panel-debug.c                      |  104 +++++++++++++++++++++++++++++
 common/{panel-builder.h => panel-debug.h} |   24 +++----
 3 files changed, 116 insertions(+), 14 deletions(-)

diff --git a/common/Makefile.am b/common/Makefile.am
index 84eef03..ae2ec96 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -9,6 +9,8 @@ noinst_LTLIBRARIES = \
 	libpanel-common.la
 
 libpanel_common_la_SOURCES = \
+	panel-debug.c \
+	panel-debug.h \
 	panel-builder.c \
 	panel-builder.h \
 	panel-xfconf.c \
diff --git a/common/panel-debug.c b/common/panel-debug.c
new file mode 100644
index 0000000..857bb72
--- /dev/null
+++ b/common/panel-debug.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2010 Nick Schermer <nick at xfce.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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <glib.h>
+#include <common/panel-debug.h>
+#include <common/panel-private.h>
+
+enum
+{
+  DEBUG_LEVEL_UNKNOWN,
+  DEBUG_LEVEL_NONE,
+  DEBUG_LEVEL_ALL_DOMAINS,
+  DEBUG_LEVEL_FILTER_DOMAINS
+};
+
+
+
+void
+panel_debug (const gchar *domain,
+             const gchar *message,
+             ...)
+{
+  static volatile gsize   level__volatile = DEBUG_LEVEL_UNKNOWN;
+  gsize                   level;
+  static gchar          **domains = NULL;
+  const gchar            *value;
+  guint                   i;
+  gchar                  *string;
+  va_list                 args;
+  gboolean                found;
+
+  panel_return_if_fail (domain != NULL);
+  panel_return_if_fail (message != NULL);
+
+  /* initialize the debugging domains */
+  if (g_once_init_enter (&level__volatile))
+    {
+      value = g_getenv ("PANEL_DEBUG");
+      if (G_LIKELY (value == NULL))
+        {
+          level = DEBUG_LEVEL_NONE;
+        }
+      else if (strcmp (value, "1") == 0)
+        {
+          level = DEBUG_LEVEL_ALL_DOMAINS;
+
+          g_printerr (PACKAGE_NAME "(debug): showing all domains\n");
+        }
+      else
+        {
+          level = DEBUG_LEVEL_FILTER_DOMAINS;
+          domains = g_strsplit (value, ":", -1);
+
+          string = g_strjoinv (", ", domains);
+          g_printerr (PACKAGE_NAME "(debug): filter domains (%s)\n", string);
+          g_free (string);
+        }
+
+      g_once_init_leave (&level__volatile, level);
+    }
+
+  /* leave when debug is disabled */
+  if (level__volatile == DEBUG_LEVEL_NONE)
+    return;
+
+  if (level__volatile == DEBUG_LEVEL_FILTER_DOMAINS)
+    {
+      for (i = 0, found = FALSE; domains[i] != NULL && !found; i++)
+        if (strcmp (domains[i], domain) == 0)
+          found = TRUE;
+      if (!found)
+        return;
+    }
+
+  va_start (args, message);
+  string = g_strdup_vprintf (message, args);
+  va_end (args);
+
+  g_printerr (PACKAGE_NAME "(%s): %s\n", domain, string);
+  g_free (string);
+}
diff --git a/common/panel-builder.h b/common/panel-debug.h
similarity index 53%
copy from common/panel-builder.h
copy to common/panel-debug.h
index 553b800..64f5eb3 100644
--- a/common/panel-builder.h
+++ b/common/panel-debug.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Nick Schermer <nick at xfce.org>
+ * Copyright (C) 2010 Nick Schermer <nick at xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -16,20 +16,16 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef __PANEL_BUILDER_H__
-#define __PANEL_BUILDER_H__
+#ifndef __PANEL_DEBUG_H__
+#define __PANEL_DEBUG_H__
 
-#include <gtk/gtk.h>
-#include <libxfce4panel/libxfce4panel.h>
+#define PANEL_DEBUG_DOMAIN_POSITIONING "positioning"
+#define PANEL_DEBUG_DOMAIN_STRUTS      "struts"
 
-/* Hook to make sure GtkBuilder knows are the XfceTitledDialog object */
-#define PANEL_BUILDER_LINK_4UI \
-  if (xfce_titled_dialog_get_type () == 0) \
-    return;
+#define PANEL_DEBUG_BOOL(bool) ((bool) ? "true" : "false")
 
-GtkBuilder *panel_builder_new (XfcePanelPlugin  *panel_plugin,
-                               const gchar      *buffer,
-                               gsize             length,
-                               GObject         **dialog_return) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+void panel_debug (const gchar *domain,
+                  const gchar *message,
+                  ...);
 
-#endif /* !__PANEL_BUILDER_H__ */
+#endif /* !__PANEL_DEBUG_H__ */



More information about the Xfce4-commits mailing list