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/Repository.h"
00018 #include "zypp/Pathname.h"
00019 #include "zypp/Message.h"
00020 #include "zypp/Url.h"
00021 #include "zypp/ProgressData.h"
00022 #include "zypp/media/MediaUserAuth.h"
00023 
00025 namespace zypp
00026 { 
00027 
00028   struct ProgressReport : public callback::ReportBase
00029   {
00030     virtual void start( const ProgressData &/*task*/ )
00031     {}
00032 
00033     virtual bool progress( const ProgressData &/*task*/ )
00034     { return true; }
00035 
00036 //     virtual Action problem(
00037 //         Repository /*source*/
00038 //         , Error /*error*/
00039 //         , const std::string &/*description*/ )
00040 //     { return ABORT; }
00041 
00042     virtual void finish( const ProgressData &/*task*/ )
00043     {}
00044 
00045   };
00046 
00047   struct ProgressReportAdaptor
00048   {
00049 
00050     ProgressReportAdaptor( const ProgressData::ReceiverFnc &fnc,
00051                            callback::SendReport<ProgressReport> &report )
00052       : _fnc(fnc)
00053       , _report(report)
00054       , _first(true)
00055     {
00056     }
00057 
00058     bool operator()( const ProgressData &progress )
00059     {
00060       if ( _first )
00061       {
00062         _report->start(progress);
00063         _first = false;
00064       }
00065 
00066       _report->progress(progress);
00067       bool value = true;
00068       if ( _fnc )
00069         value = _fnc(progress);
00070 
00071 
00072       if ( progress.finalReport() )
00073       {
00074         _report->finish(progress);
00075       }
00076       return value;
00077     }
00078 
00079     ProgressData::ReceiverFnc _fnc;
00080     callback::SendReport<ProgressReport> &_report;
00081     bool _first;
00082   };
00083 
00085 
00086   namespace repo
00087   {
00088     // progress for downloading a resolvable
00089     struct DownloadResolvableReport : public callback::ReportBase
00090     {
00091       enum Action {
00092         ABORT,  // abort and return error
00093         RETRY,  // retry
00094         IGNORE, // ignore this resolvable but continue
00095       };
00096 
00097       enum Error {
00098         NO_ERROR,
00099         NOT_FOUND,      // the requested Url was not found
00100         IO,             // IO error
00101         INVALID         // the downloaded file is invalid
00102       };
00103 
00104       virtual void start(
00105         Resolvable::constPtr /*resolvable_ptr*/
00106         , const Url &/*url*/
00107       ) {}
00108 
00109 
00110       // Dowmload delta rpm:
00111       // - path below url reported on start()
00112       // - expected download size (0 if unknown)
00113       // - download is interruptable
00114       // - problems are just informal
00115       virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
00116       {}
00117 
00118       virtual bool progressDeltaDownload( int /*value*/ )
00119       { return true; }
00120 
00121       virtual void problemDeltaDownload( const std::string &/*description*/ )
00122       {}
00123 
00124       virtual void finishDeltaDownload()
00125       {}
00126 
00127       // Apply delta rpm:
00128       // - local path of downloaded delta
00129       // - aplpy is not interruptable
00130       // - problems are just informal
00131       virtual void startDeltaApply( const Pathname & /*filename*/ )
00132       {}
00133 
00134       virtual void progressDeltaApply( int /*value*/ )
00135       {}
00136 
00137       virtual void problemDeltaApply( const std::string &/*description*/ )
00138       {}
00139 
00140       virtual void finishDeltaApply()
00141       {}
00142 
00143       // Dowmload patch rpm:
00144       // - path below url reported on start()
00145       // - expected download size (0 if unknown)
00146       // - download is interruptable
00147       virtual void startPatchDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
00148       {}
00149 
00150       virtual bool progressPatchDownload( int /*value*/ )
00151       { return true; }
00152 
00153       virtual void problemPatchDownload( const std::string &/*description*/ )
00154       {}
00155 
00156       virtual void finishPatchDownload()
00157       {}
00158 
00159 
00160       // return false if the download should be aborted right now
00161       virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
00162       { return true; }
00163 
00164       virtual Action problem(
00165         Resolvable::constPtr /*resolvable_ptr*/
00166         , Error /*error*/
00167         , const std::string &/*description*/
00168       ) { return ABORT; }
00169 
00170       virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
00171         , Error /*error*/
00172         , const std::string &/*reason*/
00173       ) {}
00174     };
00175 
00176     // progress for probing a source
00177     struct ProbeRepoReport : public callback::ReportBase
00178     {
00179       enum Action {
00180         ABORT,  // abort and return error
00181         RETRY   // retry
00182       };
00183 
00184       enum Error {
00185         NO_ERROR,
00186         NOT_FOUND,      // the requested Url was not found
00187         IO,             // IO error
00188         INVALID,                // th source is invalid
00189         UNKNOWN
00190       };
00191 
00192       virtual void start(const Url &/*url*/) {}
00193       virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
00194       virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
00195       virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
00196 
00197       virtual bool progress(const Url &/*url*/, int /*value*/)
00198       { return true; }
00199 
00200       virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
00201     };
00202 
00203     struct RepoCreateReport : public callback::ReportBase
00204     {
00205       enum Action {
00206         ABORT,  // abort and return error
00207         RETRY,  // retry
00208         IGNORE  // skip refresh, ignore failed refresh
00209       };
00210 
00211       enum Error {
00212         NO_ERROR,
00213         NOT_FOUND,      // the requested Url was not found
00214         IO,             // IO error
00215         REJECTED,
00216         INVALID, // th source is invali
00217         UNKNOWN
00218       };
00219 
00220       virtual void start( const zypp::Url &/*url*/ ) {}
00221       virtual bool progress( int /*value*/ )
00222       { return true; }
00223 
00224       virtual Action problem(
00225           const zypp::Url &/*url*/
00226           , Error /*error*/
00227           , const std::string &/*description*/ )
00228       { return ABORT; }
00229 
00230       virtual void finish(
00231           const zypp::Url &/*url*/
00232           , Error /*error*/
00233           , const std::string &/*reason*/ )
00234       {}
00235     };
00236 
00237     struct RepoReport : public callback::ReportBase
00238     {
00239       enum Action {
00240         ABORT,  // abort and return error
00241         RETRY,  // retry
00242         IGNORE  // skip refresh, ignore failed refresh
00243       };
00244 
00245       enum Error {
00246         NO_ERROR,
00247         NOT_FOUND,      // the requested Url was not found
00248         IO,             // IO error
00249         INVALID         // th source is invalid
00250       };
00251 
00252       virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/  ) {}
00253       virtual bool progress( const ProgressData &/*task*/ )
00254       { return true; }
00255 
00256       virtual Action problem(
00257           Repository /*source*/
00258           , Error /*error*/
00259           , const std::string &/*description*/ )
00260       { return ABORT; }
00261 
00262       virtual void finish(
00263           Repository /*source*/
00264           , const std::string &/*task*/
00265           , Error /*error*/
00266           , const std::string &/*reason*/ )
00267       {}
00268     };
00269 
00270 
00272   } // namespace source
00274 
00276   namespace media
00277   {
00278     // media change request callback
00279     struct MediaChangeReport : public callback::ReportBase
00280     {
00281       enum Action {
00282         ABORT,  // abort and return error
00283         RETRY,  // retry
00284         IGNORE, // ignore this media in future, not available anymore
00285         IGNORE_ID,      // ignore wrong medium id
00286         CHANGE_URL,     // change media URL
00287         EJECT           // eject the medium
00288       };
00289 
00290       enum Error {
00291         NO_ERROR,
00292         NOT_FOUND,  // the medie not found at all
00293         IO,     // error accessing the media
00294         INVALID, // media is broken
00295         WRONG   // wrong media, need a different one
00296       };
00297 
00298       virtual Action requestMedia(
00299         Url & /* url (I/O parameter) */
00300         , unsigned /*mediumNr*/
00301         , Error /*error*/
00302         , const std::string &/*description*/
00303       ) { return ABORT; }
00304     };
00305 
00306     // progress for downloading a file
00307     struct DownloadProgressReport : public callback::ReportBase
00308     {
00309         enum Action {
00310           ABORT,  // abort and return error
00311           RETRY,        // retry
00312           IGNORE        // ignore the failure
00313         };
00314 
00315         enum Error {
00316           NO_ERROR,
00317           NOT_FOUND,    // the requested Url was not found
00318           IO,           // IO error
00319           ACCESS_DENIED, // user authent. failed while accessing restricted file
00320           ERROR // other error
00321         };
00322 
00323         virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
00324 
00325         virtual bool progress(int /*value*/, const Url &/*file*/)
00326         { return true; }
00327 
00328         virtual Action problem(
00329           const Url &/*file*/
00330           , Error /*error*/
00331           , const std::string &/*description*/
00332         ) { return ABORT; }
00333 
00334         virtual void finish(
00335           const Url &/*file*/
00336           , Error /*error*/
00337           , const std::string &/*reason*/
00338         ) {}
00339     };
00340 
00341     // authentication issues report
00342     struct AuthenticationReport : public callback::ReportBase
00343     {
00358       virtual bool prompt(const Url & /* url */,
00359         const std::string & /* msg */,
00360         AuthData & /* auth_data */)
00361       {
00362         return false;
00363       }
00364     };
00365 
00367   } // namespace media
00369 
00371   namespace target
00372   {
00373 
00374     // resolvable Message
00375     struct MessageResolvableReport : public callback::ReportBase
00376     {
00377         virtual void show(
00378           Message::constPtr /*message*/
00379         ) {}
00380     };
00381 
00382     // resolvable Script
00383     struct ScriptResolvableReport : public callback::ReportBase
00384     {
00385       enum Task   { DO, UNDO };
00386       enum Notify { OUTPUT, PING };
00387 
00389       virtual void start( const Resolvable::constPtr & /*script_r*/,
00390                           const Pathname & /*path_r*/,
00391                           Task )
00392       {}
00397       virtual bool progress( Notify , const std::string & = std::string() )
00398       { return true; }
00400       virtual void problem( const std::string & /*description*/ )
00401       {}
00403       virtual void finish()
00404       {}
00405     };
00406 
00408     namespace rpm
00409     {
00410 
00411       // progress for installing a resolvable
00412       struct InstallResolvableReport : public callback::ReportBase
00413       {
00414         enum Action {
00415           ABORT,  // abort and return error
00416           RETRY,        // retry
00417           IGNORE        // ignore the failure
00418         };
00419 
00420         enum Error {
00421           NO_ERROR,
00422           NOT_FOUND,    // the requested Url was not found
00423           IO,           // IO error
00424           INVALID               // th resolvable is invalid
00425         };
00426 
00427         // the level of RPM pushing
00429         enum RpmLevel {
00430             RPM,
00431             RPM_NODEPS,
00432             RPM_NODEPS_FORCE
00433         };
00434 
00435         virtual void start(
00436           Resolvable::constPtr /*resolvable*/
00437         ) {}
00438 
00439         virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
00440         { return true; }
00441 
00442         virtual Action problem(
00443           Resolvable::constPtr /*resolvable*/
00444           , Error /*error*/
00445           , const std::string &/*description*/
00446           , RpmLevel /*level*/
00447         ) { return ABORT; }
00448 
00449         virtual void finish(
00450           Resolvable::constPtr /*resolvable*/
00451           , Error /*error*/
00452           , const std::string &/*reason*/
00453           , RpmLevel /*level*/
00454         ) {}
00455       };
00456 
00457       // progress for removing a resolvable
00458       struct RemoveResolvableReport : public callback::ReportBase
00459       {
00460         enum Action {
00461           ABORT,  // abort and return error
00462           RETRY,        // retry
00463           IGNORE        // ignore the failure
00464         };
00465 
00466         enum Error {
00467           NO_ERROR,
00468           NOT_FOUND,    // the requested Url was not found
00469           IO,           // IO error
00470           INVALID               // th resolvable is invalid
00471         };
00472 
00473         virtual void start(
00474           Resolvable::constPtr /*resolvable*/
00475         ) {}
00476 
00477         virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
00478         { return true; }
00479 
00480         virtual Action problem(
00481           Resolvable::constPtr /*resolvable*/
00482           , Error /*error*/
00483           , const std::string &/*description*/
00484         ) { return ABORT; }
00485 
00486         virtual void finish(
00487           Resolvable::constPtr /*resolvable*/
00488           , Error /*error*/
00489           , const std::string &/*reason*/
00490         ) {}
00491       };
00492 
00493       // progress for rebuilding the database
00494       struct RebuildDBReport : public callback::ReportBase
00495       {
00496         enum Action {
00497           ABORT,  // abort and return error
00498           RETRY,        // retry
00499           IGNORE        // ignore the failure
00500         };
00501 
00502         enum Error {
00503           NO_ERROR,
00504           FAILED                // failed to rebuild
00505         };
00506 
00507         virtual void start(Pathname /*path*/) {}
00508 
00509         virtual bool progress(int /*value*/, Pathname /*path*/)
00510         { return true; }
00511 
00512         virtual Action problem(
00513           Pathname /*path*/
00514          , Error /*error*/
00515          , const std::string &/*description*/
00516         ) { return ABORT; }
00517 
00518         virtual void finish(
00519           Pathname /*path*/
00520           , Error /*error*/
00521           , const std::string &/*reason*/
00522         ) {}
00523       };
00524 
00525       // progress for converting the database
00526       struct ConvertDBReport : public callback::ReportBase
00527       {
00528         enum Action {
00529           ABORT,  // abort and return error
00530           RETRY,        // retry
00531           IGNORE        // ignore the failure
00532         };
00533 
00534         enum Error {
00535           NO_ERROR,
00536           FAILED                // conversion failed
00537         };
00538 
00539         virtual void start(
00540           Pathname /*path*/
00541         ) {}
00542 
00543         virtual bool progress(int /*value*/, Pathname /*path*/)
00544         { return true; }
00545 
00546         virtual Action problem(
00547           Pathname /*path*/
00548           , Error /*error*/
00549          , const std::string &/*description*/
00550         ) { return ABORT; }
00551 
00552         virtual void finish(
00553           Pathname /*path*/
00554           , Error /*error*/
00555           , const std::string &/*reason*/
00556         ) {}
00557       };
00558 
00559        // progress for scanning the database
00560       struct ScanDBReport : public callback::ReportBase
00561       {
00562         enum Action {
00563           ABORT,  // abort and return error
00564           RETRY,        // retry
00565           IGNORE        // ignore the failure
00566         };
00567 
00568         enum Error {
00569           NO_ERROR,
00570           FAILED                // conversion failed
00571         };
00572 
00573         virtual void start(
00574         ) {}
00575 
00576         virtual bool progress(int /*value*/)
00577         { return true; }
00578 
00579         virtual Action problem(
00580           Error /*error*/
00581          , const std::string &/*description*/
00582         ) { return ABORT; }
00583 
00584         virtual void finish(
00585           Error /*error*/
00586           , const std::string &/*reason*/
00587         ) {}
00588       };
00589 
00591     } // namespace rpm
00593 
00595   } // namespace target
00597 
00599 } // namespace zypp
00601 
00602 #endif // ZYPP_ZYPPCALLBACKS_H

Generated on Tue Sep 25 19:23:11 2007 for libzypp by  doxygen 1.5.3