Use a signleton JobReport callback sender
authorMichael Andres <ma@suse.de>
Tue, 3 Jun 2014 11:32:55 +0000 (13:32 +0200)
committerMichael Andres <ma@suse.de>
Tue, 3 Jun 2014 15:39:02 +0000 (17:39 +0200)
zypp/ZYppCallbacks.h
zypp/target/RpmPostTransCollector.cc
zypp/zypp_detail/ZYppImpl.cc

index 7f3b73c..b6aa668 100644 (file)
@@ -777,21 +777,25 @@ namespace zypp
     struct _MsgTypeDef {
       enum Enum { info, warning, error };
     };
-    typedef base::EnumClass<_MsgTypeDef> MsgType;      ///< 'enum class MsgType'
 
-    //     virtual bool start()
-    //     virtual bool progress()
-    //     virtual bool problem()
-    //     virtual bool finish()
+    typedef base::EnumClass<_MsgTypeDef> MsgType;      ///< 'enum class MsgType'
 
     /** Send a ready to show message text. */
     virtual bool message( MsgType type_r, const std::string & msg_r ) const { return true; }
-    /** \overload */
-    bool info( const std::string & msg_r ) const       { return message( MsgType::info, msg_r ); }
-    /** \overload */
-    bool warning( const std::string & msg_r ) const    { return message( MsgType::warning, msg_r ); }
-    /** \overload */
-    bool error( const std::string & msg_r ) const      { return message( MsgType::error, msg_r ); }
+
+
+    /** \name Static sender instance */
+    //@{
+    /** Singleton sender instance */
+    static callback::SendReport<JobReport> & instance();       // impl in ZYppImpl.cc
+
+    /** send message text */
+    static bool info( const std::string & msg_r )      { return instance()->message( MsgType::info, msg_r ); }
+    /** send warning text */
+    static bool warning( const std::string & msg_r )   { return instance()->message( MsgType::warning, msg_r ); }
+    /** send error text */
+    static bool error( const std::string & msg_r )     { return instance()->message( MsgType::error, msg_r ); }
+    //@}
   };
 
 
index 18b4cb2..14ceab8 100644 (file)
@@ -80,7 +80,6 @@ namespace zypp
            return;
 
          HistoryLog historylog;
-         callback::SendReport<JobReport> report;
 
          Pathname noRootScriptDir( filesystem::TmpDir::defaultLocation() / tmpDir().basename() );
 
@@ -107,7 +106,7 @@ namespace zypp
                str::Str msg;
                msg << "Output of " << pkgident << " %posttrans script:\n" << scriptmsg;
                historylog.comment( msg, true /*timestamp*/);
-               report->info( msg );
+               JobReport::info( msg );
              }
 
              if ( ret != 0 )
@@ -116,7 +115,7 @@ namespace zypp
                msg << pkgident << " %posttrans script failed (returned " << ret << ")";
                WAR << msg << endl;
                historylog.comment( msg, true /*timestamp*/);
-               report->warning( msg );
+               JobReport::warning( msg );
              }
            }
          }
@@ -130,7 +129,6 @@ namespace zypp
            return;
 
          HistoryLog historylog;
-         callback::SendReport<JobReport> report;
 
          str::Str msg;
          msg << "%posttrans scripts skipped while aborting:\n";
@@ -142,7 +140,7 @@ namespace zypp
          }
 
          historylog.comment( msg, true /*timestamp*/);
-         report->warning( msg );
+         JobReport::warning( msg );
 
          _scripts.clear();
        }
index 79cd1a5..f0023e7 100644 (file)
 #include "zypp/sat/Pool.h"
 #include "zypp/PoolItem.h"
 
+#include "zypp/ZYppCallbacks.h"        // JobReport::instance
+
 using std::endl;
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
+
+  callback::SendReport<JobReport> & JobReport::instance()
+  {
+    static callback::SendReport<JobReport> _report;
+    return _report;
+  }
+
   ///////////////////////////////////////////////////////////////////
   namespace zypp_detail
   { /////////////////////////////////////////////////////////////////