all callbacks implemented (no testing)
authorStanislav Visnovsky <visnov@suse.cz>
Tue, 7 Feb 2006 16:05:50 +0000 (16:05 +0000)
committerStanislav Visnovsky <visnov@suse.cz>
Tue, 7 Feb 2006 16:05:50 +0000 (16:05 +0000)
zypp/ZYppCallbacks.h
zypp/target/TargetCallbackReceiver.cc
zypp/target/TargetCallbackReceiver.h
zypp/target/TargetImpl.cc
zypp/target/rpm/RpmCallbacks.h
zypp/target/rpm/RpmDb.cc
zypp/target/rpm/RpmDb.h
zypp/target/rpm/librpmDb.cv3.cc

index 47721e8..dca1e61 100644 (file)
@@ -48,7 +48,7 @@ namespace zypp
       { return true; }
 
       virtual Action problem(
-        Resolvable::Ptr resolvable_ptr
+        Resolvable::constPtr resolvable_ptr
        , Error error
        , std::string description
       ) { return ABORT; }
@@ -312,20 +312,20 @@ namespace zypp
         };
       
         virtual void start(
-         Resolvable::Ptr resolvable
+         Resolvable::constPtr resolvable
         ) {}
 
-        virtual bool progress(int value, Resolvable::Ptr resolvable) 
+        virtual bool progress(int value, Resolvable::constPtr resolvable) 
         { return true; }
 
         virtual Action problem(
-          Resolvable::Ptr resolvable
+          Resolvable::constPtr resolvable
          , Error error
          , std::string description
         ) { return ABORT; }
 
         virtual void finish(
-          Resolvable::Ptr resolvable
+          Resolvable::constPtr resolvable
           , Error error
          , std::string reason
         ) {}
@@ -342,21 +342,17 @@ namespace zypp
       
         enum Error {
          NO_ERROR,
-          NOT_FOUND,   // the requested Url was not found
-         IO,           // IO error
-         INVALID               // th resolvable is invalid
+         FAILED                // failed to rebuild
         };
       
-        virtual void start(
-         Pathname path
-        ) {}
+        virtual void start(Pathname path) {}
 
         virtual bool progress(int value, Pathname path) 
         { return true; } 
 
         virtual Action problem(
          Pathname path
-         , Error error
+        , Error error
         , std::string description
         ) { return ABORT; }
 
@@ -378,9 +374,7 @@ namespace zypp
       
         enum Error {
          NO_ERROR,
-          NOT_FOUND,   // the requested Url was not found
-         IO,           // IO error
-         INVALID               // th resolvable is invalid
+         FAILED                // conversion failed
         };
       
         virtual void start(
@@ -403,6 +397,37 @@ namespace zypp
         ) {}
       };
 
+       // progress for scanning the database
+      struct ScanDBReport : public callback::ReportBase
+      {
+        enum Action { 
+          ABORT,  // abort and return error
+          RETRY,       // retry
+         IGNORE        // ignore the failure
+        }; 
+      
+        enum Error {
+         NO_ERROR,
+         FAILED                // conversion failed
+        };
+      
+        virtual void start(
+        ) {}
+
+        virtual bool progress(int value) 
+        { return true; }
+
+        virtual Action problem(
+         Error error
+        , std::string description
+        ) { return ABORT; }
+
+        virtual void finish(
+          Error error
+         , std::string reason
+        ) {}
+      };
+
       /////////////////////////////////////////////////////////////////
     } // namespace rpm
     ///////////////////////////////////////////////////////////////////
index 128bc6a..c529a33 100644 (file)
@@ -94,6 +94,77 @@ namespace zypp
            _level = level_r;
        }
 
+
+       /////////////////////////////////////////////////////////////////
+       ///  RpmRemovePackageReceiver
+       /////////////////////////////////////////////////////////////////
+
+       RpmRemovePackageReceiver::RpmRemovePackageReceiver (Resolvable::constPtr res)
+           : callback::ReceiveReport<rpm::RpmRemoveReport> ()
+           , _resolvable (res)
+       {
+       }
+
+       RpmRemovePackageReceiver::~RpmRemovePackageReceiver ()
+       {
+       }
+       
+       void RpmRemovePackageReceiver::reportbegin() 
+       {
+       }
+       
+       void RpmRemovePackageReceiver::reportend() 
+       {
+       }
+
+        /** Start the operation */
+        void RpmRemovePackageReceiver::start( const Pathname & name ) 
+       {
+           _report->start( _resolvable );
+       }
+
+        /**
+         * Inform about progress
+         * Return true on abort
+         */
+        bool RpmRemovePackageReceiver::progress( unsigned percent )
+       {
+           return _report->progress( percent, _resolvable );
+       }
+       
+       rpm::RpmRemoveReport::Action 
+       RpmRemovePackageReceiver::problem( Exception & excpt_r )
+       {
+           rpm::RemoveResolvableReport::Action user = 
+               _report->problem( _resolvable
+                   , rpm::RemoveResolvableReport::INVALID
+                   , excpt_r.msg()
+               );
+               
+           switch (user) {
+               case rpm::RemoveResolvableReport::RETRY: 
+                   return rpm::RpmRemoveReport::RETRY;
+               case rpm::RemoveResolvableReport::ABORT: 
+                   return rpm::RpmRemoveReport::ABORT;
+               case rpm::RemoveResolvableReport::IGNORE: 
+                   return rpm::RpmRemoveReport::IGNORE;
+           }
+           
+           return rpm::RpmRemoveReport::problem( excpt_r );
+       }
+
+        /** Finish operation in case of success */
+        void RpmRemovePackageReceiver::finish()
+       {
+           _report->finish( _resolvable, rpm::RemoveResolvableReport::NO_ERROR, std::string() );
+       }
+
+        /** Finish operation in case of success */
+        void RpmRemovePackageReceiver::finish( Exception & excpt_r )
+       {
+           _report->finish( _resolvable, rpm::RemoveResolvableReport::INVALID, std::string() );
+       }
+
     /////////////////////////////////////////////////////////////////
   } // namespace target
   ///////////////////////////////////////////////////////////////////
index aa07a14..9ed17ba 100644 (file)
@@ -59,6 +59,40 @@ namespace zypp
         virtual void finish( Exception & excpt_r );
     };
        
+    class RpmRemovePackageReceiver 
+       : public callback::ReceiveReport<rpm::RpmRemoveReport>
+    {
+       callback::SendReport <rpm::RemoveResolvableReport> _report;
+       Resolvable::constPtr _resolvable;
+
+      public:
+
+       RpmRemovePackageReceiver (Resolvable::constPtr res);
+       virtual ~RpmRemovePackageReceiver ();
+       
+       virtual void reportbegin();
+       
+       virtual void reportend();
+
+        /** Start the operation */
+        virtual void start( const Pathname & name );
+       
+        /**
+         * Inform about progress
+         * Return true on abort
+         */
+        virtual bool progress( unsigned percent );
+
+       /** inform user about a problem */
+       virtual rpm::RpmRemoveReport::Action problem( Exception & excpt_r );
+
+        /** Finish operation in case of success */
+        virtual void finish();
+
+        /** Finish operatin in case of fail, report fail exception */
+        virtual void finish( Exception & excpt_r );
+    };
+       
     /////////////////////////////////////////////////////////////////
   } // namespace target
   ///////////////////////////////////////////////////////////////////
index 7eb8fc1..758876b 100644 (file)
@@ -200,6 +200,10 @@ namespace zypp
          }
          else
          {
+           RpmRemovePackageReceiver progress(it->resolvable());
+           
+           progress.connect();
+
            try {
                rpm().removePackage(p);
            }
@@ -208,7 +212,9 @@ namespace zypp
                WAR << "Remove failed, retrying with --nodeps" << endl;
                rpm().removePackage(p, rpm::RpmDb::RPMINST_NODEPS);
            }
+           progress.disconnect();
          }
+
          MIL << "Successful, resetting transact for " << *it << endl;
          it->status().setNoTransact(ResStatus::USER);
        }
index ef74f5d..83fecce 100644 (file)
@@ -27,10 +27,14 @@ namespace zypp {
       ///////////////////////////////////////////////////////////////////
       // Reporting progress of package removing
       ///////////////////////////////////////////////////////////////////
-      class RpmRemoveReport : public HACK::Callback {
-      public:
-        virtual ~RpmRemoveReport()
-        {}
+      struct RpmRemoveReport : public callback::ReportBase {
+
+       enum Action {
+          ABORT,  // abort and return error
+          RETRY,   // retry
+         IGNORE   // ignore
+        };
+
         /** Start the operation */
         virtual void start( const std::string & name )
         { }
@@ -40,16 +44,18 @@ namespace zypp {
          */
         virtual bool progress( unsigned percent )
         { return false; }
+
+       virtual Action problem( Exception & excpt_r )
+        { return ABORT; }
+
         /** Finish operation in case of success */
-        virtual void end()
+        virtual void finish()
         { }
-        /** Finish operatino in case of fail, report fail exception */
-        virtual void end( Exception & excpt_r )
+        /** Finish operation in case of fail, report fail exception */
+        virtual void finish( Exception & excpt_r )
         { }
       };
 
-      extern RpmRemoveReport rpmRemoveReport;
-  
       ///////////////////////////////////////////////////////////////////
       // Reporting progress of package installation
       ///////////////////////////////////////////////////////////////////
@@ -83,84 +89,6 @@ namespace zypp {
         { }
       };
 
-      ///////////////////////////////////////////////////////////////////
-      // Reporting database scanning
-      ///////////////////////////////////////////////////////////////////
-      class ScanDbReport : public HACK::Callback {
-      public:
-        virtual ~ScanDbReport()
-        {}
-        /** Start the operation */
-        virtual void start() 
-        { }
-        /**
-         * Inform about progress
-         * Return true on abort
-         */
-        virtual bool progress( unsigned percent )
-        { return false; }
-        /** Finish operation in case of success */
-        virtual void end()
-        { }
-        /** Finish operatino in case of fail, report fail exception */
-        virtual void end( Exception & excpt_r )
-        { }
-      };
-  
-      extern ScanDbReport scanDbReport;
-
-      ///////////////////////////////////////////////////////////////////
-      // Reporting progress of database rebuild
-      ///////////////////////////////////////////////////////////////////
-      class RebuildDbReport : public HACK::Callback {
-      public:
-        virtual ~RebuildDbReport()
-        {}
-        /** Start the operation */
-        virtual void start() 
-        { }
-        /**
-         * Inform about progress
-         * Return true on abort
-         */
-        virtual bool progress( unsigned percent )
-        { return false; }
-        /** Finish operation in case of success */
-        virtual void end()
-        { }
-        /** Finish operatino in case of fail, report fail exception */
-        virtual void end( Exception & excpt_r )
-        { }
-      };
-  
-      extern RebuildDbReport rebuildDbReport;
-
-      ///////////////////////////////////////////////////////////////////
-      // Reporting progress of database rebuild
-      ///////////////////////////////////////////////////////////////////
-      class ConvertDbReport : public HACK::Callback {
-      public:
-        virtual ~ConvertDbReport()
-        {}
-        /** Start the operation */
-        virtual void start() 
-        { }
-        /**
-         * Inform about progress
-         * Return true on abort
-         */
-        virtual bool progress( unsigned percent )
-        { return false; }
-        /** Finish operation in case of success */
-        virtual void end()
-        { }
-        /** Finish operatino in case of fail, report fail exception */
-        virtual void end( Exception & excpt_r )
-        { }
-      };
-  
-      extern ConvertDbReport convertDbReport;
-
     } // namespace rpm
   } // namespace target
 } // namespace zypp
index 6653a94..e6e1776 100644 (file)
@@ -747,19 +747,22 @@ void RpmDb::closeDatabase()
 //
 void RpmDb::rebuildDatabase()
 {
-  RebuildDbReport report;
+  callback::SendReport<RebuildDBReport> report;
+  
+  report->start( root() + dbPath() );
+  
   try {
     doRebuildDatabase(report);
   }
   catch (RpmException & excpt_r)
   {
-    report.end(excpt_r);
+    report->finish(root() + dbPath(), RebuildDBReport::FAILED, excpt_r.msg());
     ZYPP_RETHROW(excpt_r);
   }
-  report.end();
+  report->finish(root() + dbPath(), RebuildDBReport::NO_ERROR, "");
 }
 
-void RpmDb::doRebuildDatabase(RebuildDbReport & report)
+void RpmDb::doRebuildDatabase(callback::SendReport<RebuildDBReport> & report)
 {
   FAILIFNOTINITIALIZED;
 
@@ -792,7 +795,7 @@ void RpmDb::doRebuildDatabase(RebuildDbReport & report)
   while ( systemReadLine( line ) ) {
     if ( newMaster() ) { // file is removed at the end of rebuild.
       // current size should be upper limit for new db
-      report.progress( (100 * newMaster.size()) / dbMaster.size());
+      report->progress( (100 * newMaster.size()) / dbMaster.size(), root() + dbPath());
     }
 
     if ( line.compare( 0, 2, "D:" ) ) {
@@ -807,7 +810,7 @@ void RpmDb::doRebuildDatabase(RebuildDbReport & report)
   if ( rpm_status != 0 ) {
     ZYPP_THROW(RpmSubprocessException(string("rpm failed with message: ") + errmsg));
   } else {
-    report.progress( 100 ); // 100%
+    report->progress( 100, root() + dbPath() ); // 100%
   }
 }
 
@@ -972,15 +975,18 @@ bool RpmDb::packagesValid() const
 //
 const std::list<Package::Ptr> & RpmDb::getPackages()
 {
-  ScanDbReport report;
+  callback::SendReport<ScanDBReport> report;
+  
+  report->start ();
+  
   try {
     const std::list<Package::Ptr> & ret = doGetPackages(report);
-    report.end();
+    report->finish(ScanDBReport::NO_ERROR, "");
     return ret;
   }
   catch (RpmException & excpt_r)
   {
-    report.end(excpt_r);
+    report->finish(ScanDBReport::FAILED, excpt_r.msg ());
     ZYPP_RETHROW(excpt_r);
   }
 #warning fixme
@@ -989,7 +995,7 @@ const std::list<Package::Ptr> & RpmDb::getPackages()
 }
 
 
-const std::list<Package::Ptr> & RpmDb::doGetPackages(ScanDbReport & report)
+const std::list<Package::Ptr> & RpmDb::doGetPackages(callback::SendReport<ScanDBReport> & report)
 {
   if ( packagesValid() ) {
     return _packages._list;
@@ -1021,7 +1027,7 @@ const std::list<Package::Ptr> & RpmDb::doGetPackages(ScanDbReport & report)
   unsigned current = 0;
 
   CapFactory _f;
-  for ( iter.findAll(); *iter; ++iter, ++current, report.progress( (100*current)/expect)) {
+  for ( iter.findAll(); *iter; ++iter, ++current, report->progress( (100*current)/expect)) {
 
     string name = iter->tag_name();
     if ( name == string( "gpg-pubkey" ) ) {
@@ -1841,20 +1847,23 @@ void RpmDb::removePackage( Package::constPtr package, unsigned flags )
 //
 void RpmDb::removePackage( const string & name_r, unsigned flags )
 {
-  RpmRemoveReport report;
+  callback::SendReport<RpmRemoveReport> report;
+  
+  report->start( name_r );
+
   try {
     doRemovePackage(name_r, flags, report);
   }
   catch (RpmException & excpt_r)
   {
-    report.end(excpt_r);
+    report->finish(excpt_r);
     ZYPP_RETHROW(excpt_r);
   }
-  report.end();
+  report->finish();
 }
 
 
-void RpmDb::doRemovePackage( const string & name_r, unsigned flags, RpmRemoveReport & report )
+void RpmDb::doRemovePackage( const string & name_r, unsigned flags, callback::SendReport<RpmRemoveReport> & report )
 {
     FAILIFNOTINITIALIZED;
     Logfile progresslog;
@@ -1868,9 +1877,9 @@ void RpmDb::doRemovePackage( const string & name_r, unsigned flags, RpmRemoveRep
       if ( ! backupPackage( name_r ) ) {
        ERR << "backup of " << name_r << " failed" << endl;
       }
-      report.progress( 0 );
+      report->progress( 0 );
     } else {
-      report.progress( 100 );
+      report->progress( 100 );
     }
 
     // run rpm
@@ -1901,12 +1910,12 @@ void RpmDb::doRemovePackage( const string & name_r, unsigned flags, RpmRemoveRep
     // 5  - command started
     // 50 - command completed
     // 100 if no error
-    report.progress( 5 );
+    report->progress( 5 );
     while (systemReadLine(line))
     {
        rpmmsg += line+'\n';
     }
-    report.progress( 50 );
+    report->progress( 50 );
     int rpm_status = systemStatus();
 
     if ( rpm_status != 0 ) {
index 60d2b69..c899c47 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "zypp/target/rpm/RpmHeader.h"
 #include "zypp/target/rpm/RpmCallbacks.h"
+#include "zypp/ZYppCallbacks.h"
 
 namespace zypp {
   namespace target {
@@ -545,10 +546,10 @@ namespace zypp {
           static bool setInstallationLogfile( const Pathname & filename );
 
        protected:
-         void doRemovePackage( const std::string & name_r, unsigned flags, RpmRemoveReport & report );
+         void doRemovePackage( const std::string & name_r, unsigned flags, callback::SendReport<RpmRemoveReport> & report );
          void doInstallPackage( const Pathname & filename, unsigned flags, callback::SendReport<RpmInstallReport> & report );
-         const std::list<Package::Ptr> & doGetPackages(ScanDbReport & report);
-         void doRebuildDatabase(RebuildDbReport & report);
+         const std::list<Package::Ptr> & doGetPackages(callback::SendReport<ScanDBReport> & report);
+         void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report);
          
       
       };
index 451ae09..aff98e2 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "zypp/target/rpm/librpmDb.h"
 #include "zypp/target/rpm/RpmCallbacks.h"
+#include "zypp/ZYppCallbacks.h"
 
 extern "C" {
 #include <string.h>
@@ -337,7 +338,7 @@ using namespace std;
 **     FUNCTION TYPE : int
 */
 void internal_convertV3toV4( const Pathname & v3db_r, const librpmDb::constPtr & v4db_r,
-                               ConvertDbReport & report )
+                               callback::SendReport<ConvertDBReport> & report )
 {
 //  Timecount _t( "convert V3 to V4" );
   MIL << "Convert rpm3 database to rpm4" << endl;
@@ -387,7 +388,7 @@ void internal_convertV3toV4( const Pathname & v3db_r, const librpmDb::constPtr &
   unsigned failed      = 0;
   unsigned ignored     = 0;
   unsigned alreadyInV4 = 0;
-  report.progress( (100 * (failed + ignored + alreadyInV4) / max) );
+  report->progress( (100 * (failed + ignored + alreadyInV4) / max), v3db_r );
 
   if ( !max ) {
     Fclose( fd );
@@ -401,7 +402,7 @@ void internal_convertV3toV4( const Pathname & v3db_r, const librpmDb::constPtr &
   bool proceed = true;
   for ( int offset = fadFirstOffset(fd); offset && proceed /*!= CBSuggest::CANCEL*/;
        offset = fadNextOffset(fd, offset),
-       report.progress( (100 * (failed + ignored + alreadyInV4) / max) ) )
+       report->progress( (100 * (failed + ignored + alreadyInV4) / max), v3db_r ) )
   {
 
     // have to use lseek instead of Fseek because headerRead
@@ -496,17 +497,17 @@ void internal_convertV3toV4( const Pathname & v3db_r, const librpmDb::constPtr &
       void convertV3toV4( const Pathname & v3db_r, const librpmDb::constPtr & v4db_r )
       {
         // report
-        ConvertDbReport report;
-        report.start();
+        callback::SendReport<ConvertDBReport> report;
+        report->start(v3db_r);
        try { 
          internal_convertV3toV4( v3db_r, v4db_r, report );
        }
        catch (RpmException & excpt_r)
        {
-         report.end(excpt_r);
+         report->finish(v3db_r, ConvertDBReport::FAILED,excpt_r.msg());
          ZYPP_RETHROW(excpt_r);
        }
-        report.end();
+        report->finish(v3db_r, ConvertDBReport::NO_ERROR, "");
       }
 
     } // namespace rpm