[Xfce4-commits] <xfce4-settings:master> Add functions for debugging in the daemon.

Nick Schermer noreply at xfce.org
Mon Feb 28 17:16:09 CET 2011


Updating branch refs/heads/master
         to 4c0e67b0aca2abc128e502910023d8e61eb298cc (commit)
       from 9ed2268a5d022f1ae270fdcab6e613e17d13e7b8 (commit)

commit 4c0e67b0aca2abc128e502910023d8e61eb298cc
Author: Nick Schermer <nick at xfce.org>
Date:   Wed Feb 23 21:59:35 2011 +0100

    Add functions for debugging in the daemon.
    
    Works like xfce4-panel. You can set the environment
    variable XFSETTINGSD_DEBUG to "1" for minimal debugging
    or specify domain(s) for extensive debugging in a
    particular part of the application. Use "all" or "help"
    for more info.

 xfsettingsd/Makefile.am |    2 +
 xfsettingsd/debug.c     |  130 +++++++++++++++++++++++++++++++++++++++++++++++
 xfsettingsd/debug.h     |   41 +++++++++++++++
 3 files changed, 173 insertions(+), 0 deletions(-)

diff --git a/xfsettingsd/Makefile.am b/xfsettingsd/Makefile.am
index 2d69bd6..0adaa5d 100644
--- a/xfsettingsd/Makefile.am
+++ b/xfsettingsd/Makefile.am
@@ -17,6 +17,8 @@ xfsettingsd_SOURCES = \
 	main.c \
 	accessibility.c \
 	accessibility.h \
+	debug.c \
+	debug.h \
 	clipboard-manager.c \
 	clipboard-manager.h \
 	keyboards.c \
diff --git a/xfsettingsd/debug.c b/xfsettingsd/debug.c
new file mode 100644
index 0000000..4a15357
--- /dev/null
+++ b/xfsettingsd/debug.c
@@ -0,0 +1,130 @@
+/*
+ *  Copyright (c) 2011 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <glib.h>
+
+#include "debug.h"
+
+
+
+static const GDebugKey dbg_keys[] =
+{
+    { "xsettings",  XFSD_DEBUG_XSETTINGS },
+    { "fontconfig", XFSD_DEBUG_FONTCONFIG },
+};
+
+
+static XfsdDebugDomain
+xfsettings_dbg_init (void)
+{
+    static gboolean         inited = FALSE;
+    static XfsdDebugDomain  dbg_domains = 0;
+    const gchar            *value;
+
+    if (!inited)
+    {
+        value = g_getenv ("XFSETTINGSD_DEBUG");
+        if (value != NULL && *value != '\0')
+        {
+            dbg_domains = g_parse_debug_string (value, dbg_keys,
+                                                G_N_ELEMENTS (dbg_keys));
+
+            dbg_domains |= XFSD_DEBUG_YES;
+        }
+
+        inited = TRUE;
+    }
+
+    return dbg_domains;
+}
+
+
+
+static void
+xfsettings_dbg_print (XfsdDebugDomain  domain,
+                      const gchar     *message,
+                      va_list          args)
+{
+    const gchar *domain_name = NULL;
+    guint        i;
+    gchar       *string;
+
+    /* lookup domain name */
+    for (i = 0; i < G_N_ELEMENTS (dbg_keys); i++)
+    {
+        if (dbg_keys[i].value == domain)
+        {
+            domain_name = dbg_keys[i].key;
+            break;
+        }
+    }
+
+    g_assert (domain_name != NULL);
+
+    string = g_strdup_vprintf (message, args);
+    g_printerr (PACKAGE_NAME "(%s): %s\n", domain_name, string);
+    g_free (string);
+}
+
+
+
+void
+xfsettings_dbg (XfsdDebugDomain  domain,
+                const gchar     *message,
+                ...)
+{
+    va_list args;
+
+    g_return_if_fail (message != NULL);
+
+    /* leave when debug is disabled */
+    if (xfsettings_dbg_init () == 0)
+        return;
+
+    va_start (args, message);
+    xfsettings_dbg_print (domain, message, args);
+    va_end (args);
+}
+
+
+
+void
+xfsettings_dbg_filtered (XfsdDebugDomain  domain,
+                         const gchar     *message,
+                         ...)
+{
+    va_list args;
+
+    g_return_if_fail (message != NULL);
+
+    /* leave when the filter does not match */
+    if ((xfsettings_dbg_init () & domain) == 0)
+        return;
+
+    va_start (args, message);
+    xfsettings_dbg_print (domain, message, args);
+    va_end (args);
+}
diff --git a/xfsettingsd/debug.h b/xfsettingsd/debug.h
new file mode 100644
index 0000000..7f60516
--- /dev/null
+++ b/xfsettingsd/debug.h
@@ -0,0 +1,41 @@
+/*
+ *  Copyright (c) 2011 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __DEBUG_H__
+#define __DEBUG_H__
+
+typedef enum
+{
+   XFSD_DEBUG_YES       = 1 << 0,
+
+   /* filter levels */
+   XFSD_DEBUG_XSETTINGS  = 1 << 1,
+   XFSD_DEBUG_FONTCONFIG = 1 << 2
+
+}
+XfsdDebugDomain;
+
+void xfsettings_dbg          (XfsdDebugDomain  domain,
+                              const gchar     *message,
+                              ...) G_GNUC_PRINTF (2, 3);
+
+void xfsettings_dbg_filtered (XfsdDebugDomain  domain,
+                              const gchar     *message,
+                              ...) G_GNUC_PRINTF (2, 3);
+
+#endif /* !__DEBUG_H__ */



More information about the Xfce4-commits mailing list