[med-svn] [aghermann] 19/60: introduce logging facility to libconfig interface

andrei zavada hmmr-guest at alioth.debian.org
Mon Nov 4 23:49:54 UTC 2013


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

hmmr-guest pushed a commit to branch WIP
in repository aghermann.

commit 3755a8a5f0d0593594c8266e60b1ba081d6a80e1
Author: Andrei Zavada <johnhommer at gmail.com>
Date:   Sun Oct 13 20:59:54 2013 +0300

    introduce logging facility to libconfig interface
---
 upstream/src/aghermann/expdesign/dirlevel.cc |    4 ++--
 upstream/src/aghermann/expdesign/loadsave.cc |    4 ++--
 upstream/src/aghermann/ui/mw/loadsave.cc     |    5 ++--
 upstream/src/aghermann/ui/sf/sf.cc           |    9 +++----
 upstream/src/common/config-validate.hh       |   33 ++++++++++++++------------
 5 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/upstream/src/aghermann/expdesign/dirlevel.cc b/upstream/src/aghermann/expdesign/dirlevel.cc
index 952c912..481d95a 100644
--- a/upstream/src/aghermann/expdesign/dirlevel.cc
+++ b/upstream/src/aghermann/expdesign/dirlevel.cc
@@ -85,7 +85,7 @@ load()
 
         try {
                 C.readFile( path().c_str());
-                config.get( C);
+                config.get( C, agh::global::default_log_facility);
                 saved = true;
 
                 return 0;
@@ -111,7 +111,7 @@ save()
 
         try {
                 libconfig::Config C;
-                config.put( C);
+                config.put( C, agh::global::default_log_facility);
                 C.writeFile( p.c_str());
                 saved = true;
 
diff --git a/upstream/src/aghermann/expdesign/loadsave.cc b/upstream/src/aghermann/expdesign/loadsave.cc
index 4e82752..d406e26 100644
--- a/upstream/src/aghermann/expdesign/loadsave.cc
+++ b/upstream/src/aghermann/expdesign/loadsave.cc
@@ -29,7 +29,7 @@ load_settings()
         try {
                 conf.readFile( EXPD_FILE);
 
-                config.get( conf);
+                config.get( conf, agh::global::default_log_facility);
 
                 for ( size_t t = 0; t < ach::TTunable::_basic_tunables; ++t ) {
                         auto& A = conf.lookup(string("tunable.") + ach::tunable_name(t));
@@ -101,7 +101,7 @@ CExpDesign::
 save_settings()
 {
         libconfig::Config C;
-        config.put( C);
+        config.put( C, agh::global::default_log_facility);
 
         // only save _agh_basic_tunables_
         for ( size_t t = 0; t < ach::TTunable::_basic_tunables; ++t )
diff --git a/upstream/src/aghermann/ui/mw/loadsave.cc b/upstream/src/aghermann/ui/mw/loadsave.cc
index 5d54a76..771fc0f 100644
--- a/upstream/src/aghermann/ui/mw/loadsave.cc
+++ b/upstream/src/aghermann/ui/mw/loadsave.cc
@@ -13,6 +13,7 @@
 
 #include "project_strings.h"
 #include "common/config-validate.hh"
+#include "aghermann/globals.hh"
 #include "aghermann/ui/globals.hh"
 #include "mw.hh"
 
@@ -85,7 +86,7 @@ load_settings()
 
         try {
                 conf.readFile( CONF_FILE);
-                config.get( conf);
+                config.get( conf, agh::global::default_log_facility);
 
                 try {
                         auto& SC = conf.lookup("ScoreCodes");
@@ -158,7 +159,7 @@ save_settings()
         _aghtt_placeholder = AghT();
         _aghdd_placeholder = AghD();
 
-        config.put( conf);
+        config.put( conf, agh::global::default_log_facility);
 
         agh::confval::put( conf, "ScoreCodes", ext_score_codes);
 
diff --git a/upstream/src/aghermann/ui/sf/sf.cc b/upstream/src/aghermann/ui/sf/sf.cc
index 5f60f5c..67ce3d9 100644
--- a/upstream/src/aghermann/ui/sf/sf.cc
+++ b/upstream/src/aghermann/ui/sf/sf.cc
@@ -15,6 +15,7 @@
 #include "common/config-validate.hh"
 #include "common/fs.hh"
 #include "libmetrics/bands.hh"
+#include "aghermann/globals.hh"
 #include "aghermann/ica/ica.hh"
 #include "aghermann/expdesign/subject.hh"
 #include "aghermann/ui/misc.hh"
@@ -740,10 +741,10 @@ load_montage()
         } catch (libconfig::FileIOException ex) {
                 return;
         }
-        config.get( conf);
+        config.get( conf, agh::global::default_log_facility);
 
         for ( auto &h : channels ) {
-                h.config.get( conf);
+                h.config.get( conf, agh::global::default_log_facility);
 
               // postprocess a little
                 h.selection_start = h.selection_start_time * h.samplerate();
@@ -767,10 +768,10 @@ SScoringFacility::
 save_montage()
 {
         libconfig::Config conf;
-        config.put( conf);
+        config.put( conf, agh::global::default_log_facility);
 
         for ( auto &h : channels )
-                h.config.put( conf);
+                h.config.put( conf, agh::global::default_log_facility);
 
         try {
                 conf.writeFile (
diff --git a/upstream/src/common/config-validate.hh b/upstream/src/common/config-validate.hh
index 306c305..da52bcd 100644
--- a/upstream/src/common/config-validate.hh
+++ b/upstream/src/common/config-validate.hh
@@ -22,6 +22,7 @@
 #include <libconfig.h++>
 
 #include "string.hh"
+#include "log-facility.hh"
 #include "lang.hh"
 
 #if HAVE_CONFIG_H && !defined(VERSION)
@@ -63,16 +64,16 @@ ensure_path( libconfig::Setting& S, libconfig::Setting::Type type, const string&
 
 template <typename T>
 void
-put( libconfig::Config& C, const string& key, const T& value)
+put( libconfig::Config& C, const string& key, const T& value, agh::log::CLogFacility* lo = nullptr)
 {
         ensure_path( C.getRoot(), libconfig_type_id<T>(), key) = value;
 }
 template <> // specialise for size_t
 inline void
-put( libconfig::Config& C, const string& key, const size_t& value)
+put( libconfig::Config& C, const string& key, const size_t& value, agh::log::CLogFacility* lo)
 {
-        if ( value > INT_MAX )
-                fprintf( stderr, "Value being saved is way too big for any practical purpose (unintialized?): %zu\n", value);
+        if ( value > INT_MAX && lo )
+                lo->msg( agh::log::TLevel::warning, LOG_SOURCE_ISSUER, "Value being saved is way too big for any practical purpose (unintialized?): %zu", value);
         ensure_path( C.getRoot(), libconfig_type_id<int>(), key) = (int)value;
 }
 
@@ -98,8 +99,8 @@ put( libconfig::Config& C, const string& key, const array<T, N>& vl)
 
 
 struct IValidator {
-        virtual void get( const libconfig::Config&) const = 0;
-        virtual void put(       libconfig::Config&) const = 0;
+        virtual void get( const libconfig::Config&, agh::log::CLogFacility*) const = 0;
+        virtual void put(       libconfig::Config&, agh::log::CLogFacility*) const = 0;
         virtual ~IValidator() {}  // -Wdelete-non-virtual-dtor
 };
 
@@ -133,18 +134,19 @@ struct SValidator : IValidator {
               : key (_key), rcp (_rcp), valf (_valf)
                 {}
 
-        void get( const libconfig::Config& C) const
+        void get( const libconfig::Config& C, agh::log::CLogFacility* lo = nullptr) const
                 {
                         T tmp;
                         if ( not C.lookupValue( key, tmp) ) {
-                                fprintf( stderr, "SValidator::get(): key %s not found\n", key.c_str());
+                                if ( lo )
+                                        lo->msg( agh::log::TLevel::warning, LOG_SOURCE_ISSUER, "key %s not found", key.c_str());
                                 return; // leave at default
                         }
                         if ( not valf(tmp) )
                                 throw invalid_argument( string("Bad value for \"") + key + "\"");
                         *rcp = tmp;
                 }
-        void put( libconfig::Config& C) const
+        void put( libconfig::Config& C, agh::log::CLogFacility* lo = nullptr) const
                 {
                         confval::put( C, key, *rcp);
                 }
@@ -173,11 +175,12 @@ struct SValidator : IValidator {
 template <>
 inline void
 SValidator<size_t>::
-get( const libconfig::Config& C) const
+get( const libconfig::Config& C, agh::log::CLogFacility* lo) const
 {
         int tmp; // libconfig doesn't deal in unsigned values
         if ( not C.lookupValue( key, tmp) ) {
-                fprintf( stderr, "SValidator::get(): key %s not found\n", key.c_str());
+                if (lo)
+                        lo->msg( agh::log::TLevel::warning, LOG_SOURCE_ISSUER, "key %s not found", key.c_str());
                 return; // leave at default
         }
         if ( not valf(tmp) )
@@ -234,15 +237,15 @@ class CConfigKeys {
         CConfigKeys& operator()( const K& k, V* v, const F& f)
                 { return S.push_back( new SValidator<V>(k, v, f)), *this; }
 
-        void get( libconfig::Config& C)
+        void get( libconfig::Config& C, agh::log::CLogFacility* lo)
                 {
                         for ( auto& K : S )
-                                K->get( C);
+                                K->get( C, lo);
                 }
-        void put( libconfig::Config& C)
+        void put( libconfig::Config& C, agh::log::CLogFacility* lo)
                 {
                         for ( auto& K : S )
-                                K->put( C);
+                                K->put( C, lo);
                 }
 };
 

-- 
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/aghermann.git



More information about the debian-med-commit mailing list