libzypp 9.41.1

ZYppCallbacks.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_ZYPPCALLBACKS_H
00013 #define ZYPP_ZYPPCALLBACKS_H
00014 
00015 #include "zypp/Callback.h"
00016 #include "zypp/Resolvable.h"
00017 #include "zypp/RepoInfo.h"
00018 #include "zypp/Pathname.h"
00019 #include "zypp/Package.h"
00020 #include "zypp/Patch.h"
00021 #include "zypp/Url.h"
00022 #include "zypp/ProgressData.h"
00023 #include "zypp/media/MediaUserAuth.h"
00024 
00026 namespace zypp
00027 { 
00028 
00029   struct ProgressReport : public callback::ReportBase
00030   {
00031     virtual void start( const ProgressData &/*task*/ )
00032     {}
00033 
00034     virtual bool progress( const ProgressData &/*task*/ )
00035     { return true; }
00036 
00037 //     virtual Action problem(
00038 //         Repo /*source*/
00039 //         , Error /*error*/
00040 //         , const std::string &/*description*/ )
00041 //     { return ABORT; }
00042 
00043     virtual void finish( const ProgressData &/*task*/ )
00044     {}
00045 
00046   };
00047 
00048   struct ProgressReportAdaptor
00049   {
00050 
00051     ProgressReportAdaptor( const ProgressData::ReceiverFnc &fnc,
00052                            callback::SendReport<ProgressReport> &report )
00053       : _fnc(fnc)
00054       , _report(report)
00055       , _first(true)
00056     {
00057     }
00058 
00059     bool operator()( const ProgressData &progress )
00060     {
00061       if ( _first )
00062       {
00063         _report->start(progress);
00064         _first = false;
00065       }
00066 
00067       _report->progress(progress);
00068       bool value = true;
00069       if ( _fnc )
00070         value = _fnc(progress);
00071 
00072 
00073       if ( progress.finalReport() )
00074       {
00075         _report->finish(progress);
00076       }
00077       return value;
00078     }
00079 
00080     ProgressData::ReceiverFnc _fnc;
00081     callback::SendReport<ProgressReport> &_report;
00082     bool _first;
00083   };
00084 
00086 
00087   namespace repo
00088   {
00089     // progress for downloading a resolvable
00090     struct DownloadResolvableReport : public callback::ReportBase
00091     {
00092       enum Action {
00093         ABORT,  // abort and return error
00094         RETRY,  // retry
00095         IGNORE, // ignore this resolvable but continue
00096       };
00097 
00098       enum Error {
00099         NO_ERROR,
00100         NOT_FOUND,      // the requested Url was not found
00101         IO,             // IO error
00102         INVALID         // the downloaded file is invalid
00103       };
00104 
00105       virtual void start(
00106         Resolvable::constPtr /*resolvable_ptr*/
00107         , const Url &/*url*/
00108       ) {}
00109 
00110 
00111       // Dowmload delta rpm:
00112       // - path below url reported on start()
00113       // - expected download size (0 if unknown)
00114       // - download is interruptable
00115       // - problems are just informal
00116       virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
00117       {}
00118 
00119       virtual bool progressDeltaDownload( int /*value*/ )
00120       { return true; }
00121 
00122       virtual void problemDeltaDownload( const std::string &/*description*/ )
00123       {}
00124 
00125       virtual void finishDeltaDownload()
00126       {}
00127 
00128       // Apply delta rpm:
00129       // - local path of downloaded delta
00130       // - aplpy is not interruptable
00131       // - problems are just informal
00132       virtual void startDeltaApply( const Pathname & /*filename*/ )
00133       {}
00134 
00135       virtual void progressDeltaApply( int /*value*/ )
00136       {}
00137 
00138       virtual void problemDeltaApply( const std::string &/*description*/ )
00139       {}
00140 
00141       virtual void finishDeltaApply()
00142       {}
00143 
00144       // Dowmload patch rpm:
00145       // - path below url reported on start()
00146       // - expected download size (0 if unknown)
00147       // - download is interruptable
00148       virtual void startPatchDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
00149       {}
00150 
00151       virtual bool progressPatchDownload( int /*value*/ )
00152       { return true; }
00153 
00154       virtual void problemPatchDownload( const std::string &/*description*/ )
00155       {}
00156 
00157       virtual void finishPatchDownload()
00158       {}
00159 
00160 
00161       // return false if the download should be aborted right now
00162       virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
00163       { return true; }
00164 
00165       virtual Action problem(
00166         Resolvable::constPtr /*resolvable_ptr*/
00167         , Error /*error*/
00168         , const std::string &/*description*/
00169       ) { return ABORT; }
00170 
00171       virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
00172         , Error /*error*/
00173         , const std::string &/*reason*/
00174       ) {}
00175     };
00176 
00177     // progress for probing a source
00178     struct ProbeRepoReport : public callback::ReportBase
00179     {
00180       enum Action {
00181         ABORT,  // abort and return error
00182         RETRY   // retry
00183       };
00184 
00185       enum Error {
00186         NO_ERROR,
00187         NOT_FOUND,      // the requested Url was not found
00188         IO,             // IO error
00189         INVALID,                // th source is invalid
00190         UNKNOWN
00191       };
00192 
00193       virtual void start(const Url &/*url*/) {}
00194       virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
00195       virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
00196       virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
00197 
00198       virtual bool progress(const Url &/*url*/, int /*value*/)
00199       { return true; }
00200 
00201       virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
00202     };
00203 
00204     struct RepoCreateReport : public callback::ReportBase
00205     {
00206       enum Action {
00207         ABORT,  // abort and return error
00208         RETRY,  // retry
00209         IGNORE  // skip refresh, ignore failed refresh
00210       };
00211 
00212       enum Error {
00213         NO_ERROR,
00214         NOT_FOUND,      // the requested Url was not found
00215         IO,             // IO error
00216         REJECTED,
00217         INVALID, // th source is invali
00218         UNKNOWN
00219       };
00220 
00221       virtual void start( const zypp::Url &/*url*/ ) {}
00222       virtual bool progress( int /*value*/ )
00223       { return true; }
00224 
00225       virtual Action problem(
00226           const zypp::Url &/*url*/
00227           , Error /*error*/
00228           , const std::string &/*description*/ )
00229       { return ABORT; }
00230 
00231       virtual void finish(
00232           const zypp::Url &/*url*/
00233           , Error /*error*/
00234           , const std::string &/*reason*/ )
00235       {}
00236     };
00237 
00238     struct RepoReport : public callback::ReportBase
00239     {
00240       enum Action {
00241         ABORT,  // abort and return error
00242         RETRY,  // retry
00243         IGNORE  // skip refresh, ignore failed refresh
00244       };
00245 
00246       enum Error {
00247         NO_ERROR,
00248         NOT_FOUND,      // the requested Url was not found
00249         IO,             // IO error
00250         INVALID         // th source is invalid
00251       };
00252 
00253       virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/  ) {}
00254       virtual bool progress( const ProgressData &/*task*/ )
00255       { return true; }
00256 
00257       virtual Action problem(
00258           Repository /*source*/
00259           , Error /*error*/
00260           , const std::string &/*description*/ )
00261       { return ABORT; }
00262 
00263       virtual void finish(
00264           Repository /*source*/
00265           , const std::string &/*task*/
00266           , Error /*error*/
00267           , const std::string &/*reason*/ )
00268       {}
00269     };
00270 
00271 
00273   } // namespace source
00275 
00277   namespace media
00278   {
00279     // media change request callback
00280     struct MediaChangeReport : public callback::ReportBase
00281     {
00282       enum Action {
00283         ABORT,  // abort and return error
00284         RETRY,  // retry
00285         IGNORE, // ignore this media in future, not available anymore
00286         IGNORE_ID,      // ignore wrong medium id
00287         CHANGE_URL,     // change media URL
00288         EJECT           // eject the medium
00289       };
00290 
00291       enum Error {
00292         NO_ERROR,
00293         NOT_FOUND,  // the medie not found at all
00294         IO,     // error accessing the media
00295         INVALID, // media is broken
00296         WRONG,  // wrong media, need a different one
00297         IO_SOFT       
00298       };
00299 
00313       virtual Action requestMedia(
00314         Url & /* url (I/O parameter) */
00315         , unsigned /*mediumNr*/
00316         , const std::string & /* label */
00317         , Error /*error*/
00318         , const std::string & /*description*/
00319         , const std::vector<std::string> & /* devices */
00320         , unsigned int & /* dev_current (I/O param) */
00321       ) { return ABORT; }
00322     };
00323 
00329     struct ScopedDisableMediaChangeReport
00330     {
00332       ScopedDisableMediaChangeReport( bool condition_r = true );
00333     private:
00334       shared_ptr<callback::TempConnect<media::MediaChangeReport> > _guard;
00335     };
00336 
00337     // progress for downloading a file
00338     struct DownloadProgressReport : public callback::ReportBase
00339     {
00340         enum Action {
00341           ABORT,  // abort and return error
00342           RETRY,        // retry
00343           IGNORE        // ignore the failure
00344         };
00345 
00346         enum Error {
00347           NO_ERROR,
00348           NOT_FOUND,    // the requested Url was not found
00349           IO,           // IO error
00350           ACCESS_DENIED, // user authent. failed while accessing restricted file
00351           ERROR // other error
00352         };
00353 
00354         virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
00355 
00364         virtual bool progress(int /*value*/, const Url &/*file*/,
00365                               double dbps_avg = -1,
00366                               double dbps_current = -1)
00367         { return true; }
00368 
00369         virtual Action problem(
00370           const Url &/*file*/
00371           , Error /*error*/
00372           , const std::string &/*description*/
00373         ) { return ABORT; }
00374 
00375         virtual void finish(
00376           const Url &/*file*/
00377           , Error /*error*/
00378           , const std::string &/*reason*/
00379         ) {}
00380     };
00381 
00382     // authentication issues report
00383     struct AuthenticationReport : public callback::ReportBase
00384     {
00399       virtual bool prompt(const Url & /* url */,
00400         const std::string & /* msg */,
00401         AuthData & /* auth_data */)
00402       {
00403         return false;
00404       }
00405     };
00406 
00408   } // namespace media
00410 
00412   namespace target
00413   {
00415     struct PatchMessageReport : public callback::ReportBase
00416     {
00420       virtual bool show( Patch::constPtr & /*patch*/ )
00421       { return true; }
00422     };
00423 
00428     struct PatchScriptReport : public callback::ReportBase
00429     {
00430       enum Notify { OUTPUT, PING };
00431       enum Action {
00432         ABORT,  // abort commit and return error
00433         RETRY,  // (re)try to execute this script
00434         IGNORE  // ignore any failue and continue
00435       };
00436 
00439       virtual void start( const Package::constPtr & /*package*/,
00440                           const Pathname & /*script path*/ )
00441       {}
00446       virtual bool progress( Notify /*OUTPUT or PING*/,
00447                              const std::string & /*output*/ = std::string() )
00448       { return true; }
00450       virtual Action problem( const std::string & /*description*/ )
00451       { return ABORT; }
00453       virtual void finish()
00454       {}
00455     };
00456 
00458     namespace rpm
00459     {
00460 
00461       // progress for installing a resolvable
00462       struct InstallResolvableReport : public callback::ReportBase
00463       {
00464         enum Action {
00465           ABORT,  // abort and return error
00466           RETRY,        // retry
00467           IGNORE        // ignore the failure
00468         };
00469 
00470         enum Error {
00471           NO_ERROR,
00472           NOT_FOUND,    // the requested Url was not found
00473           IO,           // IO error
00474           INVALID               // th resolvable is invalid
00475         };
00476 
00477         // the level of RPM pushing
00479         enum RpmLevel {
00480             RPM,
00481             RPM_NODEPS,
00482             RPM_NODEPS_FORCE
00483         };
00484 
00485         virtual void start(
00486           Resolvable::constPtr /*resolvable*/
00487         ) {}
00488 
00489         virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
00490         { return true; }
00491 
00492         virtual Action problem(
00493           Resolvable::constPtr /*resolvable*/
00494           , Error /*error*/
00495           , const std::string &/*description*/
00496           , RpmLevel /*level*/
00497         ) { return ABORT; }
00498 
00499         virtual void finish(
00500           Resolvable::constPtr /*resolvable*/
00501           , Error /*error*/
00502           , const std::string &/*reason*/
00503           , RpmLevel /*level*/
00504         ) {}
00505       };
00506 
00507       // progress for removing a resolvable
00508       struct RemoveResolvableReport : public callback::ReportBase
00509       {
00510         enum Action {
00511           ABORT,  // abort and return error
00512           RETRY,        // retry
00513           IGNORE        // ignore the failure
00514         };
00515 
00516         enum Error {
00517           NO_ERROR,
00518           NOT_FOUND,    // the requested Url was not found
00519           IO,           // IO error
00520           INVALID               // th resolvable is invalid
00521         };
00522 
00523         virtual void start(
00524           Resolvable::constPtr /*resolvable*/
00525         ) {}
00526 
00527         virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
00528         { return true; }
00529 
00530         virtual Action problem(
00531           Resolvable::constPtr /*resolvable*/
00532           , Error /*error*/
00533           , const std::string &/*description*/
00534         ) { return ABORT; }
00535 
00536         virtual void finish(
00537           Resolvable::constPtr /*resolvable*/
00538           , Error /*error*/
00539           , const std::string &/*reason*/
00540         ) {}
00541       };
00542 
00543       // progress for rebuilding the database
00544       struct RebuildDBReport : public callback::ReportBase
00545       {
00546         enum Action {
00547           ABORT,  // abort and return error
00548           RETRY,        // retry
00549           IGNORE        // ignore the failure
00550         };
00551 
00552         enum Error {
00553           NO_ERROR,
00554           FAILED                // failed to rebuild
00555         };
00556 
00557         virtual void start(Pathname /*path*/) {}
00558 
00559         virtual bool progress(int /*value*/, Pathname /*path*/)
00560         { return true; }
00561 
00562         virtual Action problem(
00563           Pathname /*path*/
00564          , Error /*error*/
00565          , const std::string &/*description*/
00566         ) { return ABORT; }
00567 
00568         virtual void finish(
00569           Pathname /*path*/
00570           , Error /*error*/
00571           , const std::string &/*reason*/
00572         ) {}
00573       };
00574 
00575       // progress for converting the database
00576       struct ConvertDBReport : public callback::ReportBase
00577       {
00578         enum Action {
00579           ABORT,  // abort and return error
00580           RETRY,        // retry
00581           IGNORE        // ignore the failure
00582         };
00583 
00584         enum Error {
00585           NO_ERROR,
00586           FAILED                // conversion failed
00587         };
00588 
00589         virtual void start(
00590           Pathname /*path*/
00591         ) {}
00592 
00593         virtual bool progress(int /*value*/, Pathname /*path*/)
00594         { return true; }
00595 
00596         virtual Action problem(
00597           Pathname /*path*/
00598           , Error /*error*/
00599          , const std::string &/*description*/
00600         ) { return ABORT; }
00601 
00602         virtual void finish(
00603           Pathname /*path*/
00604           , Error /*error*/
00605           , const std::string &/*reason*/
00606         ) {}
00607       };
00608 
00610     } // namespace rpm
00612 
00614   } // namespace target
00616 
00617   class PoolQuery;
00618 
00625   struct CleanEmptyLocksReport : public callback::ReportBase
00626   {
00630     enum Action {
00631       ABORT,  
00632       DELETE, 
00633       IGNORE  
00634     };
00635 
00639     enum Error {
00640       NO_ERROR, 
00641       ABORTED 
00642     };
00643 
00647     virtual void start(
00648     ) {}
00649 
00654     virtual bool progress(int /*value*/)
00655     { return true; }
00656 
00661     virtual Action execute(
00662         const PoolQuery& /*error*/
00663      ) { return DELETE; }
00664 
00668      virtual void finish(
00669        Error /*error*/
00670       ) {}
00671 
00672   };
00673 
00677   struct SavingLocksReport : public callback::ReportBase
00678   {
00683     enum Action {
00684       ABORT,  
00685       DELETE, 
00686       IGNORE  
00687     };
00688 
00692     enum Error {
00693       NO_ERROR, 
00694       ABORTED  
00695     };
00696 
00700     enum ConflictState{
00701       SAME_RESULTS, 
00702       INTERSECT 
00704     };
00705 
00706     virtual void start() {}
00707 
00712     virtual bool progress()
00713     { return true; }
00714 
00718     virtual Action conflict(
00719          const PoolQuery&, 
00720        ConflictState
00721      ) { return DELETE; }
00722 
00723      virtual void finish(
00724        Error /*error*/
00725       ) {}
00726   };
00727 
00728 
00730 } // namespace zypp
00732 
00733 #endif // ZYPP_ZYPPCALLBACKS_H