commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 01/07: runtime: restructure prefs class for


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/07: runtime: restructure prefs class for initializing prefs singleton.
Date: Mon, 30 Jun 2014 02:29:27 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

trondeau pushed a commit to branch master
in repository gnuradio.

commit 6be4c6fc1190f83764a317ad8185bbd6b4f813ba
Author: Tom Rondeau <address@hidden>
Date:   Fri Jun 27 15:07:32 2014 -0400

    runtime: restructure prefs class for initializing prefs singleton.
    
    Boost filesystem has a bug initializing a static variable when linking 
statically. This forces the initialization to happen when the first call to 
prefs::singleton is made.
    
    We should really put the prefs ctor in private, but then swig complains.
---
 gnuradio-runtime/include/gnuradio/prefs.h    |   1 -
 gnuradio-runtime/lib/prefs.cc                |  16 +---
 gnuradio-runtime/python/gnuradio/gr/prefs.py | 127 ---------------------------
 gnuradio-runtime/swig/prefs.i                |   2 -
 4 files changed, 3 insertions(+), 143 deletions(-)

diff --git a/gnuradio-runtime/include/gnuradio/prefs.h 
b/gnuradio-runtime/include/gnuradio/prefs.h
index b675c83..a9a2858 100644
--- a/gnuradio-runtime/include/gnuradio/prefs.h
+++ b/gnuradio-runtime/include/gnuradio/prefs.h
@@ -46,7 +46,6 @@ namespace gr {
   {
   public:
     static prefs *singleton();
-    static void set_singleton(prefs *p);
 
     prefs();
     virtual ~prefs();
diff --git a/gnuradio-runtime/lib/prefs.cc b/gnuradio-runtime/lib/prefs.cc
index d03c677..b7fcaad 100644
--- a/gnuradio-runtime/lib/prefs.cc
+++ b/gnuradio-runtime/lib/prefs.cc
@@ -36,22 +36,12 @@ namespace fs = boost::filesystem;
 
 namespace gr {
 
-  /*
-   * Stub implementations
-   */
-  static prefs s_default_singleton;
-  static prefs *s_singleton = &s_default_singleton;
-
   prefs *
   prefs::singleton()
   {
-    return s_singleton;
-  }
-
-  void
-  prefs::set_singleton(prefs *p)
-  {
-    s_singleton = p;
+    static prefs instance; // Guaranteed to be destroyed.
+                            // Instantiated on first use.
+    return &instance;
   }
 
   prefs::prefs()
diff --git a/gnuradio-runtime/python/gnuradio/gr/prefs.py 
b/gnuradio-runtime/python/gnuradio/gr/prefs.py
deleted file mode 100644
index 17f5bfb..0000000
--- a/gnuradio-runtime/python/gnuradio/gr/prefs.py
+++ /dev/null
@@ -1,127 +0,0 @@
-#
-# Copyright 2006,2009 Free Software Foundation, Inc.
-#
-# This file is part of GNU Radio
-#
-# GNU Radio 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 3, or (at your option)
-# any later version.
-#
-# GNU Radio 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 General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GNU Radio; see the file COPYING.  If not, write to
-# the Free Software Foundation, Inc., 51 Franklin Street,
-# Boston, MA 02110-1301, USA.
-#
-
-import gnuradio_runtime as gsp
-_prefs_base = gsp.prefs
-
-
-import ConfigParser
-import os
-import os.path
-import sys
-import glob
-
-
-def _user_prefs_filename():
-    return os.path.expanduser('~/.gnuradio/config.conf')
-
-def _sys_prefs_dirname():
-    return gsp.prefsdir()
-
-def _bool(x):
-    """
-    Try to coerce obj to a True or False
-    """
-    if isinstance(x, bool):
-        return x
-    if isinstance(x, (float, int)):
-        return bool(x)
-    raise TypeError, x
-
-
-class _prefs(_prefs_base):
-    """
-    Derive our 'real class' from the stubbed out base class that has support
-    for SWIG directors.  This allows C++ code to magically and transparently
-    invoke the methods in this python class.
-    """
-    def __init__(self):
-        _prefs_base.__init__(self)
-        self.cp = ConfigParser.RawConfigParser()
-        self.__getattr__ = lambda self, name: getattr(self.cp, name)
-
-    def _sys_prefs_filenames(self):
-        dir = _sys_prefs_dirname()
-        try:
-            fnames = glob.glob(os.path.join(dir, '*.conf'))
-        except (IOError, OSError):
-            return []
-        fnames.sort()
-        return fnames
-
-    def _read_files(self):
-        filenames = self._sys_prefs_filenames()
-        filenames.append(_user_prefs_filename())
-        #print "filenames: ", filenames
-        self.cp.read(filenames)
-
-    # ----------------------------------------------------------------
-    # These methods override the C++ virtual methods of the same name
-    # ----------------------------------------------------------------
-    def has_section(self, section):
-        return self.cp.has_section(section)
-
-    def has_option(self, section, option):
-        return self.cp.has_option(section, option)
-
-    def get_string(self, section, option, default_val):
-        try:
-            return self.cp.get(section, option)
-        except:
-            return default_val
-
-    def get_bool(self, section, option, default_val):
-        try:
-            return self.cp.getboolean(section, option)
-        except:
-            return default_val
-
-    def get_long(self, section, option, default_val):
-        try:
-            return self.cp.getint(section, option)
-        except:
-            return default_val
-
-    def get_double(self, section, option, default_val):
-        try:
-            return self.cp.getfloat(section, option)
-        except:
-            return default_val
-    # ----------------------------------------------------------------
-    #              End override of C++ virtual methods
-    # ----------------------------------------------------------------
-
-
-_prefs_db = _prefs()
-
-# if GR_DONT_LOAD_PREFS is set, don't load them.
-# (make check uses this to avoid interactions.)
-if os.getenv("GR_DONT_LOAD_PREFS", None) is None:
-    _prefs_db._read_files()
-
-
-_prefs_base.set_singleton(_prefs_db)    # tell C++ what instance to use
-
-def prefs():
-    """
-    Return the global preference data base
-    """
-    return _prefs_db
diff --git a/gnuradio-runtime/swig/prefs.i b/gnuradio-runtime/swig/prefs.i
index f56c791..ac5fab7 100644
--- a/gnuradio-runtime/swig/prefs.i
+++ b/gnuradio-runtime/swig/prefs.i
@@ -24,7 +24,6 @@ class gr::prefs
 {
 public:
   static gr::prefs *singleton();
-  static void set_singleton(gr::prefs *p);
 
   virtual ~prefs();
 
@@ -60,4 +59,3 @@ public:
                           const std::string &option,
                           double val);
 };
-



reply via email to

[Prev in Thread] Current Thread [Next in Thread]