Make Folks.Debug a class so we can store state.
authorTravis Reitter <travis.reitter@collabora.co.uk>
Tue, 4 Jan 2011 00:23:05 +0000 (16:23 -0800)
committerTravis Reitter <travis.reitter@collabora.co.uk>
Thu, 6 Jan 2011 23:42:42 +0000 (15:42 -0800)
Helps bgo#638609 - libfolks hard-codes backend names for debugging

folks/backend-store.vala
folks/debug.vala

index e96f27b..d264685 100644 (file)
@@ -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<string,unowned Module> (str_hash, str_equal);
       this._backend_hash = new HashMap<string,Backend> (str_hash, str_equal);
index 2ba27d6..583bb3f 100644 (file)
@@ -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;
+    }
 }