[folks] Push flag setting into the Debug constructor.



commit e962ee0505a30b89e143a87db7fcfec4c31b1ee7
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Tue Jan 4 11:26:34 2011 -0800

    Push flag setting into the Debug constructor.
    
    Helps bgo#638609 - libfolks hard-codes backend names for debugging

 folks/backend-store.vala |    5 +--
 folks/debug.vala         |   49 +++++++++++++++++++++------------------------
 2 files changed, 25 insertions(+), 29 deletions(-)
---
diff --git a/folks/backend-store.vala b/folks/backend-store.vala
index 89dd778..cb40821 100644
--- a/folks/backend-store.vala
+++ b/folks/backend-store.vala
@@ -119,10 +119,9 @@ public class Folks.BackendStore : Object {
 
   private BackendStore ()
     {
-      this._debug = Debug.dup ();
-
       /* Treat this as a library init function */
-      this._debug._set_flags (Environment.get_variable ("FOLKS_DEBUG"));
+      this._debug = Debug.dup (Environment.get_variable ("FOLKS_DEBUG"));
+
       /* register the core debug messages */
       this._debug._register_domain ("folks");
 
diff --git a/folks/debug.vala b/folks/debug.vala
index 396dff3..5e11cea 100644
--- a/folks/debug.vala
+++ b/folks/debug.vala
@@ -34,26 +34,6 @@ internal class Folks.Debug : Object
   private HashSet<string> _domains;
   private bool _all = false;
 
-  internal void _set_flags (string? debug_flags)
-    {
-      this._all = false;
-      this._domains = new HashSet<string> (str_hash, str_equal);
-
-      if (debug_flags == null || debug_flags == "")
-        return;
-
-      var domains_split = debug_flags.split (",");
-      foreach (var domain in domains_split)
-        {
-          var domain_lower = domain.down ();
-
-          if (GLib.strcmp (domain_lower, "all") == 0)
-            this._all = true;
-          else
-            this._domains.add (domain_lower);
-        }
-    }
-
   /* turn off debug output for the given domain unless it was in the FOLKS_DEBUG
    * environment variable (or 'all' was set) */
   internal void _register_domain (string domain)
@@ -72,18 +52,35 @@ internal class Folks.Debug : Object
           (domain_arg, flags, message) => {});
     }
 
-  internal static Debug dup ()
+  internal static Debug dup (string? debug_flags)
     {
-      if (_instance == null)
+      var retval = _instance;
+
+      if (retval == null)
         {
           /* use an intermediate variable to force a strong reference */
-          var new_instance = new Debug ();
-          _instance = new_instance;
+          retval = new Debug ();
+          _instance = retval;
+        }
+
+      retval._all = false;
+      retval._domains = new HashSet<string> (str_hash, str_equal);
+
+      if (debug_flags != null && debug_flags != "")
+        {
+          var domains_split = debug_flags.split (",");
+          foreach (var domain in domains_split)
+            {
+              var domain_lower = domain.down ();
 
-          return new_instance;
+              if (GLib.strcmp (domain_lower, "all") == 0)
+                retval._all = true;
+              else
+                retval._domains.add (domain_lower);
+            }
         }
 
-      return _instance;
+      return retval;
     }
 
   ~Debug ()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]