1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ZYppCallbacks.h
12 #ifndef ZYPP_ZYPPCALLBACKS_H
13 #define ZYPP_ZYPPCALLBACKS_H
15 #include "zypp/Callback.h"
16 #include "zypp/Resolvable.h"
17 #include "zypp/RepoInfo.h"
18 #include "zypp/Pathname.h"
19 #include "zypp/Package.h"
20 #include "zypp/Patch.h"
22 #include "zypp/ProgressData.h"
23 #include "zypp/media/MediaUserAuth.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 struct ProgressReport : public callback::ReportBase
31 virtual void start( const ProgressData &/*task*/ )
34 virtual bool progress( const ProgressData &/*task*/ )
37 // virtual Action problem(
40 // , const std::string &/*description*/ )
43 virtual void finish( const ProgressData &/*task*/ )
48 struct ProgressReportAdaptor
51 ProgressReportAdaptor( const ProgressData::ReceiverFnc &fnc,
52 callback::SendReport<ProgressReport> &report )
59 bool operator()( const ProgressData &progress )
63 _report->start(progress);
67 _report->progress(progress);
70 value = _fnc(progress);
73 if ( progress.finalReport() )
75 _report->finish(progress);
80 ProgressData::ReceiverFnc _fnc;
81 callback::SendReport<ProgressReport> &_report;
85 ////////////////////////////////////////////////////////////////////////////
89 // progress for downloading a resolvable
90 struct DownloadResolvableReport : public callback::ReportBase
93 ABORT, // abort and return error
95 IGNORE, // ignore this resolvable but continue
100 NOT_FOUND, // the requested Url was not found
102 INVALID // the downloaded file is invalid
106 Resolvable::constPtr /*resolvable_ptr*/
111 // Dowmload delta rpm:
112 // - path below url reported on start()
113 // - expected download size (0 if unknown)
114 // - download is interruptable
115 // - problems are just informal
116 virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
119 virtual bool progressDeltaDownload( int /*value*/ )
122 virtual void problemDeltaDownload( const std::string &/*description*/ )
125 virtual void finishDeltaDownload()
129 // - local path of downloaded delta
130 // - aplpy is not interruptable
131 // - problems are just informal
132 virtual void startDeltaApply( const Pathname & /*filename*/ )
135 virtual void progressDeltaApply( int /*value*/ )
138 virtual void problemDeltaApply( const std::string &/*description*/ )
141 virtual void finishDeltaApply()
144 // Dowmload patch rpm:
145 // - path below url reported on start()
146 // - expected download size (0 if unknown)
147 // - download is interruptable
148 virtual void startPatchDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
151 virtual bool progressPatchDownload( int /*value*/ )
154 virtual void problemPatchDownload( const std::string &/*description*/ )
157 virtual void finishPatchDownload()
161 // return false if the download should be aborted right now
162 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
165 virtual Action problem(
166 Resolvable::constPtr /*resolvable_ptr*/
168 , const std::string &/*description*/
171 virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
173 , const std::string &/*reason*/
177 // progress for probing a source
178 struct ProbeRepoReport : public callback::ReportBase
181 ABORT, // abort and return error
187 NOT_FOUND, // the requested Url was not found
189 INVALID, // th source is invalid
193 virtual void start(const Url &/*url*/) {}
194 virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
195 virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
196 virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
198 virtual bool progress(const Url &/*url*/, int /*value*/)
201 virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
204 struct RepoCreateReport : public callback::ReportBase
207 ABORT, // abort and return error
209 IGNORE // skip refresh, ignore failed refresh
214 NOT_FOUND, // the requested Url was not found
217 INVALID, // th source is invali
221 virtual void start( const zypp::Url &/*url*/ ) {}
222 virtual bool progress( int /*value*/ )
225 virtual Action problem(
226 const zypp::Url &/*url*/
228 , const std::string &/*description*/ )
232 const zypp::Url &/*url*/
234 , const std::string &/*reason*/ )
238 struct RepoReport : public callback::ReportBase
241 ABORT, // abort and return error
243 IGNORE // skip refresh, ignore failed refresh
248 NOT_FOUND, // the requested Url was not found
250 INVALID // th source is invalid
253 virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/ ) {}
254 virtual bool progress( const ProgressData &/*task*/ )
257 virtual Action problem(
258 Repository /*source*/
260 , const std::string &/*description*/ )
264 Repository /*source*/
265 , const std::string &/*task*/
267 , const std::string &/*reason*/ )
272 /////////////////////////////////////////////////////////////////
273 } // namespace source
274 ///////////////////////////////////////////////////////////////////
276 ///////////////////////////////////////////////////////////////////
279 // media change request callback
280 struct MediaChangeReport : public callback::ReportBase
283 ABORT, // abort and return error
285 IGNORE, // ignore this media in future, not available anymore
286 IGNORE_ID, // ignore wrong medium id
287 CHANGE_URL, // change media URL
288 EJECT // eject the medium
293 NOT_FOUND, // the medie not found at all
294 IO, // error accessing the media
295 INVALID, // media is broken
296 WRONG, // wrong media, need a different one
297 IO_SOFT /**< IO error which can happen on worse connection like timeout exceed */
302 * \param url in: url for which the media is requested,
303 * out: url to use instead of the original one
304 * \param mediumNr requested medium number
305 * \param label label of requested medium
306 * \param error type of error from \ref Error enum
307 * \param description error message (media not desired or error foo occured)
308 * \param devices list of the available devices (for eject)
309 * \param dev_current in: index of the currently used device in the \a devices list
310 * out: index of the devices to be ejected in the \a devices list
311 * \return \ref Action (ABORT by default)
313 virtual Action requestMedia(
314 Url & /* url (I/O parameter) */
315 , unsigned /*mediumNr*/
316 , const std::string & /* label */
318 , const std::string & /*description*/
319 , const std::vector<std::string> & /* devices */
320 , unsigned int & /* dev_current (I/O param) */
324 // progress for downloading a file
325 struct DownloadProgressReport : public callback::ReportBase
328 ABORT, // abort and return error
330 IGNORE // ignore the failure
335 NOT_FOUND, // the requested Url was not found
337 ACCESS_DENIED, // user authent. failed while accessing restricted file
341 virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
346 * \param value Percentage value.
347 * \param file File URI.
348 * \param dbps_avg Average download rate so far. -1 if unknown.
349 * \param dbps_current Current download (cca last 1 sec). -1 if unknown.
351 virtual bool progress(int /*value*/, const Url &/*file*/,
352 double dbps_avg = -1,
353 double dbps_current = -1)
356 virtual Action problem(
359 , const std::string &/*description*/
365 , const std::string &/*reason*/
369 // authentication issues report
370 struct AuthenticationReport : public callback::ReportBase
373 * Prompt for authentication data.
375 * \param url URL which required the authentication
376 * \param msg prompt text
377 * \param auth_data input/output object for handling authentication
378 * data. As an input parameter auth_data can be prefilled with
379 * username (from previous try) or auth_type (available
380 * authentication methods aquired from server (only CurlAuthData)).
381 * As an output parameter it serves for sending username, pasword
382 * or other special data (derived AuthData objects).
383 * \return true if user chooses to continue with authentication,
386 virtual bool prompt(const Url & /* url */,
387 const std::string & /* msg */,
388 AuthData & /* auth_data */)
394 /////////////////////////////////////////////////////////////////
396 ///////////////////////////////////////////////////////////////////
398 ///////////////////////////////////////////////////////////////////
401 /** Request to display the pre commit message of a patch. */
402 struct PatchMessageReport : public callback::ReportBase
404 /** Display \c patch->message().
405 * Return \c true to continue, \c false to abort commit.
407 virtual bool show( Patch::constPtr & /*patch*/ )
411 /** Indicate execution of a patch script. This is a sort of
412 * \c %post script shipped by a package and to be executed
413 * after the package was installed.
415 struct PatchScriptReport : public callback::ReportBase
417 enum Notify { OUTPUT, PING };
419 ABORT, // abort commit and return error
420 RETRY, // (re)try to execute this script
421 IGNORE // ignore any failue and continue
424 /** Start executing the script provided by package.
426 virtual void start( const Package::constPtr & /*package*/,
427 const Pathname & /*script path*/ )
429 /** Progress provides the script output. If the script is quiet,
430 * from time to time still-alive pings are sent to the ui. Returning \c FALSE
431 * aborts script execution.
433 virtual bool progress( Notify /*OUTPUT or PING*/,
434 const std::string & /*output*/ = std::string() )
437 virtual Action problem( const std::string & /*description*/ )
439 /** Report success. */
440 virtual void finish()
444 ///////////////////////////////////////////////////////////////////
448 // progress for installing a resolvable
449 struct InstallResolvableReport : public callback::ReportBase
452 ABORT, // abort and return error
454 IGNORE // ignore the failure
459 NOT_FOUND, // the requested Url was not found
461 INVALID // th resolvable is invalid
464 // the level of RPM pushing
465 /** \deprecated We fortunately no longer do 3 attempts. */
473 Resolvable::constPtr /*resolvable*/
476 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
479 virtual Action problem(
480 Resolvable::constPtr /*resolvable*/
482 , const std::string &/*description*/
487 Resolvable::constPtr /*resolvable*/
489 , const std::string &/*reason*/
494 // progress for removing a resolvable
495 struct RemoveResolvableReport : public callback::ReportBase
498 ABORT, // abort and return error
500 IGNORE // ignore the failure
505 NOT_FOUND, // the requested Url was not found
507 INVALID // th resolvable is invalid
511 Resolvable::constPtr /*resolvable*/
514 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
517 virtual Action problem(
518 Resolvable::constPtr /*resolvable*/
520 , const std::string &/*description*/
524 Resolvable::constPtr /*resolvable*/
526 , const std::string &/*reason*/
530 // progress for rebuilding the database
531 struct RebuildDBReport : public callback::ReportBase
534 ABORT, // abort and return error
536 IGNORE // ignore the failure
541 FAILED // failed to rebuild
544 virtual void start(Pathname /*path*/) {}
546 virtual bool progress(int /*value*/, Pathname /*path*/)
549 virtual Action problem(
552 , const std::string &/*description*/
558 , const std::string &/*reason*/
562 // progress for converting the database
563 struct ConvertDBReport : public callback::ReportBase
566 ABORT, // abort and return error
568 IGNORE // ignore the failure
573 FAILED // conversion failed
580 virtual bool progress(int /*value*/, Pathname /*path*/)
583 virtual Action problem(
586 , const std::string &/*description*/
592 , const std::string &/*reason*/
596 // progress for scanning the database
597 struct ScanDBReport : public callback::ReportBase
600 ABORT, // abort and return error
602 IGNORE // ignore the failure
607 FAILED // conversion failed
613 virtual bool progress(int /*value*/)
616 virtual Action problem(
618 , const std::string &/*description*/
623 , const std::string &/*reason*/
627 /////////////////////////////////////////////////////////////////
629 ///////////////////////////////////////////////////////////////////
631 /////////////////////////////////////////////////////////////////
632 } // namespace target
633 ///////////////////////////////////////////////////////////////////
640 * Callback for cleaning locks which doesn't lock anything in pool.
643 struct CleanEmptyLocksReport : public callback::ReportBase
646 * action performed by cleaning api to specific lock
649 ABORT, /**< abort and return error */
650 DELETE, /**< delete empty lock */
651 IGNORE /**< skip empty lock */
658 NO_ERROR, /**< no problem */
659 ABORTED /** cleaning aborted by user */
663 * cleaning is started
669 * progress of cleaning specifies in percents
670 * \return if continue
672 virtual bool progress(int /*value*/)
676 * When find empty lock ask what to do with it
679 virtual Action execute(
680 const PoolQuery& /*error*/
693 * this callback handles merging old locks with newly added or removed
695 struct SavingLocksReport : public callback::ReportBase
698 * action for old lock which is in conflict
702 ABORT, /**< abort and return error*/
703 DELETE, /**< delete conflicted lock */
704 IGNORE /**< skip conflict lock */
711 NO_ERROR, /**< no problem */
712 ABORTED /**< cleaning aborted by user */
716 * type of conflict of old and new lock
719 SAME_RESULTS, /**< locks lock same item in pool but his parameters is different */
720 INTERSECT /**< locks lock some file and unlocking lock unlock only part
721 * of iti, so removing old lock can unlock more items in pool */
724 virtual void start() {}
728 * \return if continue
730 virtual bool progress()
734 * When user unlock something which is locked by non-identical query
736 virtual Action conflict(
737 const PoolQuery&, /**< problematic query*/
747 /////////////////////////////////////////////////////////////////
749 ///////////////////////////////////////////////////////////////////
751 #endif // ZYPP_ZYPPCALLBACKS_H