libzypp
10.5.0
|
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 00324 // progress for downloading a file 00325 struct DownloadProgressReport : public callback::ReportBase 00326 { 00327 enum Action { 00328 ABORT, // abort and return error 00329 RETRY, // retry 00330 IGNORE // ignore the failure 00331 }; 00332 00333 enum Error { 00334 NO_ERROR, 00335 NOT_FOUND, // the requested Url was not found 00336 IO, // IO error 00337 ACCESS_DENIED, // user authent. failed while accessing restricted file 00338 ERROR // other error 00339 }; 00340 00341 virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {} 00342 00351 virtual bool progress(int /*value*/, const Url &/*file*/, 00352 double dbps_avg = -1, 00353 double dbps_current = -1) 00354 { return true; } 00355 00356 virtual Action problem( 00357 const Url &/*file*/ 00358 , Error /*error*/ 00359 , const std::string &/*description*/ 00360 ) { return ABORT; } 00361 00362 virtual void finish( 00363 const Url &/*file*/ 00364 , Error /*error*/ 00365 , const std::string &/*reason*/ 00366 ) {} 00367 }; 00368 00369 // authentication issues report 00370 struct AuthenticationReport : public callback::ReportBase 00371 { 00386 virtual bool prompt(const Url & /* url */, 00387 const std::string & /* msg */, 00388 AuthData & /* auth_data */) 00389 { 00390 return false; 00391 } 00392 }; 00393 00395 } // namespace media 00397 00399 namespace target 00400 { 00402 struct PatchMessageReport : public callback::ReportBase 00403 { 00407 virtual bool show( Patch::constPtr & /*patch*/ ) 00408 { return true; } 00409 }; 00410 00415 struct PatchScriptReport : public callback::ReportBase 00416 { 00417 enum Notify { OUTPUT, PING }; 00418 enum Action { 00419 ABORT, // abort commit and return error 00420 RETRY, // (re)try to execute this script 00421 IGNORE // ignore any failue and continue 00422 }; 00423 00426 virtual void start( const Package::constPtr & /*package*/, 00427 const Pathname & /*script path*/ ) 00428 {} 00433 virtual bool progress( Notify /*OUTPUT or PING*/, 00434 const std::string & /*output*/ = std::string() ) 00435 { return true; } 00437 virtual Action problem( const std::string & /*description*/ ) 00438 { return ABORT; } 00440 virtual void finish() 00441 {} 00442 }; 00443 00445 namespace rpm 00446 { 00447 00448 // progress for installing a resolvable 00449 struct InstallResolvableReport : public callback::ReportBase 00450 { 00451 enum Action { 00452 ABORT, // abort and return error 00453 RETRY, // retry 00454 IGNORE // ignore the failure 00455 }; 00456 00457 enum Error { 00458 NO_ERROR, 00459 NOT_FOUND, // the requested Url was not found 00460 IO, // IO error 00461 INVALID // th resolvable is invalid 00462 }; 00463 00464 // the level of RPM pushing 00466 enum RpmLevel { 00467 RPM, 00468 RPM_NODEPS, 00469 RPM_NODEPS_FORCE 00470 }; 00471 00472 virtual void start( 00473 Resolvable::constPtr /*resolvable*/ 00474 ) {} 00475 00476 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/) 00477 { return true; } 00478 00479 virtual Action problem( 00480 Resolvable::constPtr /*resolvable*/ 00481 , Error /*error*/ 00482 , const std::string &/*description*/ 00483 , RpmLevel /*level*/ 00484 ) { return ABORT; } 00485 00486 virtual void finish( 00487 Resolvable::constPtr /*resolvable*/ 00488 , Error /*error*/ 00489 , const std::string &/*reason*/ 00490 , RpmLevel /*level*/ 00491 ) {} 00492 }; 00493 00494 // progress for removing a resolvable 00495 struct RemoveResolvableReport : public callback::ReportBase 00496 { 00497 enum Action { 00498 ABORT, // abort and return error 00499 RETRY, // retry 00500 IGNORE // ignore the failure 00501 }; 00502 00503 enum Error { 00504 NO_ERROR, 00505 NOT_FOUND, // the requested Url was not found 00506 IO, // IO error 00507 INVALID // th resolvable is invalid 00508 }; 00509 00510 virtual void start( 00511 Resolvable::constPtr /*resolvable*/ 00512 ) {} 00513 00514 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/) 00515 { return true; } 00516 00517 virtual Action problem( 00518 Resolvable::constPtr /*resolvable*/ 00519 , Error /*error*/ 00520 , const std::string &/*description*/ 00521 ) { return ABORT; } 00522 00523 virtual void finish( 00524 Resolvable::constPtr /*resolvable*/ 00525 , Error /*error*/ 00526 , const std::string &/*reason*/ 00527 ) {} 00528 }; 00529 00530 // progress for rebuilding the database 00531 struct RebuildDBReport : public callback::ReportBase 00532 { 00533 enum Action { 00534 ABORT, // abort and return error 00535 RETRY, // retry 00536 IGNORE // ignore the failure 00537 }; 00538 00539 enum Error { 00540 NO_ERROR, 00541 FAILED // failed to rebuild 00542 }; 00543 00544 virtual void start(Pathname /*path*/) {} 00545 00546 virtual bool progress(int /*value*/, Pathname /*path*/) 00547 { return true; } 00548 00549 virtual Action problem( 00550 Pathname /*path*/ 00551 , Error /*error*/ 00552 , const std::string &/*description*/ 00553 ) { return ABORT; } 00554 00555 virtual void finish( 00556 Pathname /*path*/ 00557 , Error /*error*/ 00558 , const std::string &/*reason*/ 00559 ) {} 00560 }; 00561 00562 // progress for converting the database 00563 struct ConvertDBReport : public callback::ReportBase 00564 { 00565 enum Action { 00566 ABORT, // abort and return error 00567 RETRY, // retry 00568 IGNORE // ignore the failure 00569 }; 00570 00571 enum Error { 00572 NO_ERROR, 00573 FAILED // conversion failed 00574 }; 00575 00576 virtual void start( 00577 Pathname /*path*/ 00578 ) {} 00579 00580 virtual bool progress(int /*value*/, Pathname /*path*/) 00581 { return true; } 00582 00583 virtual Action problem( 00584 Pathname /*path*/ 00585 , Error /*error*/ 00586 , const std::string &/*description*/ 00587 ) { return ABORT; } 00588 00589 virtual void finish( 00590 Pathname /*path*/ 00591 , Error /*error*/ 00592 , const std::string &/*reason*/ 00593 ) {} 00594 }; 00595 00597 } // namespace rpm 00599 00601 } // namespace target 00603 00604 class PoolQuery; 00605 00612 struct CleanEmptyLocksReport : public callback::ReportBase 00613 { 00617 enum Action { 00618 ABORT, 00619 DELETE, 00620 IGNORE 00621 }; 00622 00626 enum Error { 00627 NO_ERROR, 00628 ABORTED 00629 }; 00630 00634 virtual void start( 00635 ) {} 00636 00641 virtual bool progress(int /*value*/) 00642 { return true; } 00643 00648 virtual Action execute( 00649 const PoolQuery& /*error*/ 00650 ) { return DELETE; } 00651 00655 virtual void finish( 00656 Error /*error*/ 00657 ) {} 00658 00659 }; 00660 00664 struct SavingLocksReport : public callback::ReportBase 00665 { 00670 enum Action { 00671 ABORT, 00672 DELETE, 00673 IGNORE 00674 }; 00675 00679 enum Error { 00680 NO_ERROR, 00681 ABORTED 00682 }; 00683 00687 enum ConflictState{ 00688 SAME_RESULTS, 00689 INTERSECT 00691 }; 00692 00693 virtual void start() {} 00694 00699 virtual bool progress() 00700 { return true; } 00701 00705 virtual Action conflict( 00706 const PoolQuery&, 00707 ConflictState 00708 ) { return DELETE; } 00709 00710 virtual void finish( 00711 Error /*error*/ 00712 ) {} 00713 }; 00714 00715 00717 } // namespace zypp 00719 00720 #endif // ZYPP_ZYPPCALLBACKS_H