From 26f43d1aeeadf48a23cf6fb29d7900720fd4a6ea Mon Sep 17 00:00:00 2001 From: Travis Reitter Date: Mon, 3 Jan 2011 16:23:05 -0800 Subject: [PATCH] Make Folks.Debug a class so we can store state. Helps bgo#638609 - libfolks hard-codes backend names for debugging --- folks/backend-store.vala | 4 +++- folks/debug.vala | 27 +++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/folks/backend-store.vala b/folks/backend-store.vala index e96f27b..d264685 100644 --- a/folks/backend-store.vala +++ b/folks/backend-store.vala @@ -118,8 +118,10 @@ public class Folks.BackendStore : Object { private BackendStore () { + var debug = Debug.dup (); + /* Treat this as a library init function */ - Debug._set_flags (Environment.get_variable ("FOLKS_DEBUG")); + debug._set_flags (Environment.get_variable ("FOLKS_DEBUG")); this.modules = new HashMap (str_hash, str_equal); this._backend_hash = new HashMap (str_hash, str_equal); diff --git a/folks/debug.vala b/folks/debug.vala index 2ba27d6..583bb3f 100644 --- a/folks/debug.vala +++ b/folks/debug.vala @@ -19,8 +19,9 @@ */ using GLib; +using Gee; -namespace Folks.Debug +internal class Folks.Debug : Object { private enum Domains { /* Zero is used for "no debug spew" */ @@ -29,7 +30,9 @@ namespace Folks.Debug KEY_FILE_BACKEND = 1 << 2 } - internal static void _set_flags (string? debug_flags) + private static weak Debug _instance; + + internal void _set_flags (string? debug_flags) { /* FIXME: we obviously shouldn't be hard-coding these. See bgo#638609 */ GLib.DebugKey keys[3] = @@ -55,4 +58,24 @@ namespace Folks.Debug } } } + + internal static Debug dup () + { + if (_instance == null) + { + /* use an intermediate variable to force a strong reference */ + var new_instance = new Debug (); + _instance = new_instance; + + return new_instance; + } + + return _instance; + } + + ~Debug () + { + /* manually clear the singleton _instance */ + _instance = null; + } } -- 2.7.4