[gedit/wip/debug-utility: 2/2] GeditDebugUtility: a utility class for debugging
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/debug-utility: 2/2] GeditDebugUtility: a utility class for debugging
- Date: Wed, 13 May 2015 14:14:41 +0000 (UTC)
commit 2112c32091c2566789fb196278d48059f8e1236a
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed May 13 15:37:38 2015 +0200
GeditDebugUtility: a utility class for debugging
gedit/Makefile.am | 2 +
gedit/gedit-debug-utility.c | 96 +++++++++++++++++++++++++++++++++++++++++++
gedit/gedit-debug-utility.h | 19 ++++++++
po/POTFILES.in | 1 +
4 files changed, 118 insertions(+), 0 deletions(-)
---
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index 15adf68..1698345 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -101,6 +101,7 @@ gedit_built_sources = \
gedit_NOINST_H_FILES = \
gedit/gedit-close-confirmation-dialog.h \
gedit/gedit-commands-private.h \
+ gedit/gedit-debug-utility.h \
gedit/gedit-dirs.h \
gedit/gedit-document-private.h \
gedit/gedit-documents-panel.h \
@@ -170,6 +171,7 @@ gedit_libgedit_c_files = \
gedit/gedit-commands-search.c \
gedit/gedit-commands-view.c \
gedit/gedit-debug.c \
+ gedit/gedit-debug-utility.c \
gedit/gedit-dirs.c \
gedit/gedit-document.c \
gedit/gedit-documents-panel.c \
diff --git a/gedit/gedit-debug-utility.c b/gedit/gedit-debug-utility.c
new file mode 100644
index 0000000..757884b
--- /dev/null
+++ b/gedit/gedit-debug-utility.c
@@ -0,0 +1,96 @@
+/*
+ * gedit-debug-utility.c
+ *
+ * Copyright (C) 2015 - Sébastien Wilmet <swilmet gnome org>
+ */
+
+#include "gedit-debug-utility.h"
+
+struct _GeditDebugUtility
+{
+ GObject parent;
+
+ guint64 enabled_sections;
+ guint64 all_sections;
+};
+
+G_DEFINE_TYPE (GeditDebugUtility, _gedit_debug_utility, G_TYPE_OBJECT)
+
+#if 0
+static void
+_gedit_debug_utility_finalize (GObject *object)
+{
+
+ G_OBJECT_CLASS (gedit_debug_utility_parent_class)->finalize (object);
+}
+#endif
+
+static void
+_gedit_debug_utility_class_init (GeditDebugUtilityClass *klass)
+{
+#if 0
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = _gedit_debug_utility_finalize;
+#endif
+}
+
+static void
+_gedit_debug_utility_init (GeditDebugUtility *debug)
+{
+}
+
+void
+_gedit_debug_utility_new (void)
+{
+ return g_object_new (GEDIT_TYPE_DEBUG_UTILITY, NULL);
+}
+
+/* Checks that @section_flag contains only one flag (one bit at 1, all other
+ * bits at 0).
+ */
+static gboolean
+is_valid_flag (guint64 section_flag)
+{
+ guint64 value = section_flag;
+
+ while (value > 1)
+ {
+ if ((value % 2) == 1)
+ {
+ return FALSE;
+ }
+
+ value >>= 1;
+ }
+
+ return value == 1;
+}
+
+void
+_gedit_debug_utility_add_section (GeditDebugUtility *debug,
+ const gchar *section_name,
+ guint64 section_flag)
+{
+ guint64 all_sections_prev;
+
+ g_return_if_fail (GEDIT_IS_DEBUG_UTILITY (debug));
+ g_return_if_fail (is_valid_flag (section_flag));
+
+ all_sections_prev = debug->all_sections;
+ debug->all_sections |= section_flag;
+
+ if (debug->all_sections == all_sections_prev)
+ {
+ g_warning ("Debug section '%s' uses the same flag value (" G_GUINT64_FORMAT ") "
+ "as another section.",
+ section_name,
+ section_flag);
+ return;
+ }
+
+ if (g_getenv (section_name))
+ {
+ debug->enabled_sections |= section_flag;
+ }
+}
diff --git a/gedit/gedit-debug-utility.h b/gedit/gedit-debug-utility.h
new file mode 100644
index 0000000..399f8f4
--- /dev/null
+++ b/gedit/gedit-debug-utility.h
@@ -0,0 +1,19 @@
+/*
+ * gedit-debug-utility.h
+ *
+ * Copyright (C) 2015 - Sébastien Wilmet <swilmet gnome org>
+ */
+
+#ifndef __GEDIT_DEBUG_UTILITY_H__
+#define __GEDIT_DEBUG_UTILITY_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_DEBUG_UTILITY _gedit_debug_utility_get_type ()
+G_DECLARE_FINAL_TYPE (GeditDebugUtility, _gedit_debug_utility, GEDIT, DEBUG_UTILITY, GObject)
+
+G_END_DECLS
+
+#endif /* __GEDIT_DEBUG_UTILITY_H__ */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 822f2fb..3e1f351 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -12,6 +12,7 @@ gedit/gedit-commands-file.c
gedit/gedit-commands-help.c
gedit/gedit-commands-search.c
gedit/gedit-debug.c
+gedit/gedit-debug-utility.c
gedit/gedit-document.c
gedit/gedit-documents-panel.c
gedit/gedit-encodings-combo-box.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]