commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 20/50: runtime: more generic version of pre


From: git
Subject: [Commit-gnuradio] [gnuradio] 20/50: runtime: more generic version of prefs class.
Date: Wed, 15 Apr 2015 21:07:54 +0000 (UTC)

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

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 7bdd6effd7b6b36ea8d86cb57329a20874fb3290
Author: Tom Rondeau <address@hidden>
Date:   Mon Mar 2 13:44:17 2015 -0500

    runtime: more generic version of prefs class.
    
    Adds another constructor to open a particular file to configure specific 
preferences.
---
 gnuradio-runtime/include/gnuradio/prefs.h | 28 ++++++++++++++++++++++++++--
 gnuradio-runtime/lib/prefs.cc             | 28 ++++++++++++++++++++--------
 gnuradio-runtime/swig/prefs.i             |  4 +++-
 3 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/gnuradio-runtime/include/gnuradio/prefs.h 
b/gnuradio-runtime/include/gnuradio/prefs.h
index a9a2858..8049be7 100644
--- a/gnuradio-runtime/include/gnuradio/prefs.h
+++ b/gnuradio-runtime/include/gnuradio/prefs.h
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2013 Free Software Foundation, Inc.
+ * Copyright 2006,2013,2015 Free Software Foundation, Inc.
  *
  * This file is part of GNU Radio
  *
@@ -47,10 +47,34 @@ namespace gr {
   public:
     static prefs *singleton();
 
+    /*!
+     * \brief Creates an object to read preference files.
+     *
+     * \detail
+     *
+     * If no file name is given (empty arg list or ""), this opens up
+     * the standard GNU Radio configuration files in
+     * prefix/etc/gnuradio/conf.d as well as ~/.gnuradio/config.conf.
+     *
+     * Only access this through the singleton defined here:
+     * prefs *p = prefs::singleton();
+     */
     prefs();
+
     virtual ~prefs();
 
     /*!
+     * If specifying a file name, this opens that specific
+     * configuration file of the standard form containing sections and
+     * key-value pairs:
+     *
+     * [SectionName]
+     * key0 = value0
+     * key1 = value1
+     */
+    void add_config_file(const std::string &configfile);
+
+    /*!
      * \brief Returns the configuration options as a string.
      */
     std::string to_string();
@@ -137,7 +161,7 @@ namespace gr {
 
   protected:
     virtual std::vector<std::string> _sys_prefs_filenames();
-    virtual void _read_files();
+    virtual std::string _read_files(const std::vector<std::string> &filenames);
     virtual void _convert_to_map(const std::string &conf);
     virtual char * option_to_env(std::string section, std::string option);
 
diff --git a/gnuradio-runtime/lib/prefs.cc b/gnuradio-runtime/lib/prefs.cc
index b7fcaad..b303ffd 100644
--- a/gnuradio-runtime/lib/prefs.cc
+++ b/gnuradio-runtime/lib/prefs.cc
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2013 Free Software Foundation, Inc.
+ * Copyright 2006,2013,2015 Free Software Foundation, Inc.
  *
  * This file is part of GNU Radio
  *
@@ -46,7 +46,10 @@ namespace gr {
 
   prefs::prefs()
   {
-    _read_files();
+    std::string config = _read_files(_sys_prefs_filenames());
+
+    // Convert the string into a map
+    _convert_to_map(config);
   }
 
   prefs::~prefs()
@@ -83,13 +86,12 @@ namespace gr {
     return fnames;
   }
 
-  void
-  prefs::_read_files()
+  std::string
+  prefs::_read_files(const std::vector<std::string> &filenames)
   {
     std::string config;
 
-    std::vector<std::string> filenames = _sys_prefs_filenames();
-    std::vector<std::string>::iterator sitr;
+    std::vector<std::string>::const_iterator sitr;
     char tmp[1024];
     for(sitr = filenames.begin(); sitr != filenames.end(); sitr++) {
       fs::ifstream fin(*sitr);
@@ -142,8 +144,7 @@ namespace gr {
       fin.close();
     }
 
-    // Convert the string into a map
-    _convert_to_map(config);
+    return config;
   }
 
   void
@@ -188,6 +189,17 @@ namespace gr {
     }
   }
 
+  void
+  prefs::add_config_file(const std::string &configfile)
+  {
+    std::vector<std::string> filenames;
+    filenames.push_back(configfile);
+
+    std::string config = _read_files(filenames);
+    _convert_to_map(config);
+  }
+
+
   std::string
   prefs::to_string()
   {
diff --git a/gnuradio-runtime/swig/prefs.i b/gnuradio-runtime/swig/prefs.i
index ac5fab7..4774146 100644
--- a/gnuradio-runtime/swig/prefs.i
+++ b/gnuradio-runtime/swig/prefs.i
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2013 Free Software Foundation, Inc.
+ * Copyright 2006,2015 Free Software Foundation, Inc.
  *
  * This file is part of GNU Radio
  *
@@ -25,6 +25,8 @@ class gr::prefs
 public:
   static gr::prefs *singleton();
 
+  void add_config_file(const std::string &configfile);
+
   virtual ~prefs();
 
   std::string to_string();



reply via email to

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