1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ZYppCallbacks.h
12 #ifndef ZYPP_ZYPPCALLBACKS_H
13 #define ZYPP_ZYPPCALLBACKS_H
15 #include "zypp/base/EnumClass.h"
16 #include "zypp/Callback.h"
17 #include "zypp/Resolvable.h"
18 #include "zypp/RepoInfo.h"
19 #include "zypp/Pathname.h"
20 #include "zypp/Package.h"
21 #include "zypp/Patch.h"
23 #include "zypp/ProgressData.h"
24 #include "zypp/media/MediaUserAuth.h"
26 ///////////////////////////////////////////////////////////////////
28 { /////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////
38 struct ProgressReport : public callback::ReportBase
40 virtual void start( const ProgressData &/*task*/ )
43 virtual bool progress( const ProgressData &/*task*/ )
46 // virtual Action problem(
49 // , const std::string &/*description*/ )
52 virtual void finish( const ProgressData &/*task*/ )
57 struct ProgressReportAdaptor
60 ProgressReportAdaptor( const ProgressData::ReceiverFnc &fnc,
61 callback::SendReport<ProgressReport> &report )
68 bool operator()( const ProgressData &progress )
72 _report->start(progress);
76 _report->progress(progress);
79 value = _fnc(progress);
82 if ( progress.finalReport() )
84 _report->finish(progress);
89 ProgressData::ReceiverFnc _fnc;
90 callback::SendReport<ProgressReport> &_report;
94 ////////////////////////////////////////////////////////////////////////////
98 // progress for downloading a resolvable
99 struct DownloadResolvableReport : public callback::ReportBase
102 ABORT, // abort and return error
104 IGNORE, // ignore this resolvable but continue
109 NOT_FOUND, // the requested Url was not found
111 INVALID // the downloaded file is invalid
114 /** Hint that package is available in the local cache (no download needed).
115 * This will be the only trigger for an already cached package.
117 virtual void infoInCache( Resolvable::constPtr res_r, const Pathname & localfile_r )
121 Resolvable::constPtr /*resolvable_ptr*/
126 // Dowmload delta rpm:
127 // - path below url reported on start()
128 // - expected download size (0 if unknown)
129 // - download is interruptable
130 // - problems are just informal
131 virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
134 virtual bool progressDeltaDownload( int /*value*/ )
137 virtual void problemDeltaDownload( const std::string &/*description*/ )
140 virtual void finishDeltaDownload()
144 // - local path of downloaded delta
145 // - aplpy is not interruptable
146 // - problems are just informal
147 virtual void startDeltaApply( const Pathname & /*filename*/ )
150 virtual void progressDeltaApply( int /*value*/ )
153 virtual void problemDeltaApply( const std::string &/*description*/ )
156 virtual void finishDeltaApply()
159 // Dowmload patch rpm:
160 // - path below url reported on start()
161 // - expected download size (0 if unknown)
162 // - download is interruptable
163 virtual void startPatchDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
166 virtual bool progressPatchDownload( int /*value*/ )
169 virtual void problemPatchDownload( const std::string &/*description*/ )
172 virtual void finishPatchDownload()
176 // return false if the download should be aborted right now
177 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
180 virtual Action problem(
181 Resolvable::constPtr /*resolvable_ptr*/
183 , const std::string &/*description*/
186 virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
188 , const std::string &/*reason*/
192 // progress for probing a source
193 struct ProbeRepoReport : public callback::ReportBase
196 ABORT, // abort and return error
202 NOT_FOUND, // the requested Url was not found
204 INVALID, // th source is invalid
208 virtual void start(const Url &/*url*/) {}
209 virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
210 virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
211 virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
213 virtual bool progress(const Url &/*url*/, int /*value*/)
216 virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
219 struct RepoCreateReport : public callback::ReportBase
222 ABORT, // abort and return error
224 IGNORE // skip refresh, ignore failed refresh
229 NOT_FOUND, // the requested Url was not found
232 INVALID, // th source is invali
236 virtual void start( const zypp::Url &/*url*/ ) {}
237 virtual bool progress( int /*value*/ )
240 virtual Action problem(
241 const zypp::Url &/*url*/
243 , const std::string &/*description*/ )
247 const zypp::Url &/*url*/
249 , const std::string &/*reason*/ )
253 struct RepoReport : public callback::ReportBase
256 ABORT, // abort and return error
258 IGNORE // skip refresh, ignore failed refresh
263 NOT_FOUND, // the requested Url was not found
265 INVALID // th source is invalid
268 virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/ ) {}
269 virtual bool progress( const ProgressData &/*task*/ )
272 virtual Action problem(
273 Repository /*source*/
275 , const std::string &/*description*/ )
279 Repository /*source*/
280 , const std::string &/*task*/
282 , const std::string &/*reason*/ )
287 /////////////////////////////////////////////////////////////////
288 } // namespace source
289 ///////////////////////////////////////////////////////////////////
291 ///////////////////////////////////////////////////////////////////
294 // media change request callback
295 struct MediaChangeReport : public callback::ReportBase
298 ABORT, // abort and return error
300 IGNORE, // ignore this media in future, not available anymore
301 IGNORE_ID, // ignore wrong medium id
302 CHANGE_URL, // change media URL
303 EJECT // eject the medium
308 NOT_FOUND, // the medie not found at all
309 IO, // error accessing the media
310 INVALID, // media is broken
311 WRONG, // wrong media, need a different one
312 IO_SOFT /**< IO error which can happen on worse connection like timeout exceed */
317 * \param url in: url for which the media is requested,
318 * out: url to use instead of the original one
319 * \param mediumNr requested medium number
320 * \param label label of requested medium
321 * \param error type of error from \ref Error enum
322 * \param description error message (media not desired or error foo occured)
323 * \param devices list of the available devices (for eject)
324 * \param dev_current in: index of the currently used device in the \a devices list
325 * out: index of the devices to be ejected in the \a devices list
326 * \return \ref Action (ABORT by default)
328 virtual Action requestMedia(
329 Url & /* url (I/O parameter) */
330 , unsigned /*mediumNr*/
331 , const std::string & /* label */
333 , const std::string & /*description*/
334 , const std::vector<std::string> & /* devices */
335 , unsigned int & /* dev_current (I/O param) */
339 // progress for downloading a file
340 struct DownloadProgressReport : public callback::ReportBase
343 ABORT, // abort and return error
345 IGNORE // ignore the failure
350 NOT_FOUND, // the requested Url was not found
352 ACCESS_DENIED, // user authent. failed while accessing restricted file
356 virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
361 * \param value Percentage value.
362 * \param file File URI.
363 * \param dbps_avg Average download rate so far. -1 if unknown.
364 * \param dbps_current Current download (cca last 1 sec). -1 if unknown.
366 virtual bool progress(int /*value*/, const Url &/*file*/,
367 double dbps_avg = -1,
368 double dbps_current = -1)
371 virtual Action problem(
374 , const std::string &/*description*/
380 , const std::string &/*reason*/
384 // authentication issues report
385 struct AuthenticationReport : public callback::ReportBase
388 * Prompt for authentication data.
390 * \param url URL which required the authentication
391 * \param msg prompt text
392 * \param auth_data input/output object for handling authentication
393 * data. As an input parameter auth_data can be prefilled with
394 * username (from previous try) or auth_type (available
395 * authentication methods aquired from server (only CurlAuthData)).
396 * As an output parameter it serves for sending username, pasword
397 * or other special data (derived AuthData objects).
398 * \return true if user chooses to continue with authentication,
401 virtual bool prompt(const Url & /* url */,
402 const std::string & /* msg */,
403 AuthData & /* auth_data */)
409 /////////////////////////////////////////////////////////////////
411 ///////////////////////////////////////////////////////////////////
413 ///////////////////////////////////////////////////////////////////
416 /** Request to display the pre commit message of a patch. */
417 struct PatchMessageReport : public callback::ReportBase
419 /** Display \c patch->message().
420 * Return \c true to continue, \c false to abort commit.
422 virtual bool show( Patch::constPtr & /*patch*/ )
426 /** Indicate execution of a patch script. This is a sort of
427 * \c %post script shipped by a package and to be executed
428 * after the package was installed.
430 struct PatchScriptReport : public callback::ReportBase
432 enum Notify { OUTPUT, PING };
434 ABORT, // abort commit and return error
435 RETRY, // (re)try to execute this script
436 IGNORE // ignore any failue and continue
439 /** Start executing the script provided by package.
441 virtual void start( const Package::constPtr & /*package*/,
442 const Pathname & /*script path*/ )
444 /** Progress provides the script output. If the script is quiet,
445 * from time to time still-alive pings are sent to the ui. Returning \c FALSE
446 * aborts script execution.
448 virtual bool progress( Notify /*OUTPUT or PING*/,
449 const std::string & /*output*/ = std::string() )
452 virtual Action problem( const std::string & /*description*/ )
454 /** Report success. */
455 virtual void finish()
459 ///////////////////////////////////////////////////////////////////
460 /// \class FindFileConflictstReport
461 /// \brief Check for package file conflicts in commit (after download)
463 /// File conflict check requires that all packages are downloaded and
464 /// now available in the cache (need to access the filelists). Missing
465 /// packages are omitted from check and their number is reported in
466 /// \a noFilelist_r. This usually happens if download mode 'as-needed'
468 ///////////////////////////////////////////////////////////////////
469 struct FindFileConflictstReport : public callback::ReportBase
472 * \param progress_r Progress counter for packages to check.
473 * \return \c true to continue, \c false upon user abort request.
475 virtual bool start( const ProgressData & progress_r )
479 * \param progress_r Progress counter for packages to check.
480 * \param noFilelist_r Queue of so far skipped solvables (no filelist/not yet downloaded).
481 * \return \c true to continue, \c false upon user abort request.
483 virtual bool progress( const ProgressData & progress_r, const sat::Queue & noFilelist_r )
487 * \param progress_r Progress counter for packages to check.
488 * \param noFilelist_r Queue of skipped solvables (no filelist/not yet downloaded).
489 * \param conflicts_r File conflits queue.
490 * \return \c true to continue, \c false upon user abort request.
492 virtual bool result( const ProgressData & progress_r, const sat::Queue & noFilelist_r, const sat::FileConflicts & conflicts_r )
497 ///////////////////////////////////////////////////////////////////
501 // progress for installing a resolvable
502 struct InstallResolvableReport : public callback::ReportBase
505 ABORT, // abort and return error
507 IGNORE // ignore the failure
512 NOT_FOUND, // the requested Url was not found
514 INVALID // th resolvable is invalid
517 // the level of RPM pushing
518 /** \deprecated We fortunately no longer do 3 attempts. */
522 RPM_NODEPS_FORCE //!< only this one used
526 Resolvable::constPtr /*resolvable*/
529 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
532 virtual Action problem(
533 Resolvable::constPtr /*resolvable*/
535 , const std::string &/*description*/
540 Resolvable::constPtr /*resolvable*/
542 , const std::string &/*reason*/
547 // progress for removing a resolvable
548 struct RemoveResolvableReport : public callback::ReportBase
551 ABORT, // abort and return error
553 IGNORE // ignore the failure
558 NOT_FOUND, // the requested Url was not found
560 INVALID // th resolvable is invalid
564 Resolvable::constPtr /*resolvable*/
567 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
570 virtual Action problem(
571 Resolvable::constPtr /*resolvable*/
573 , const std::string &/*description*/
577 Resolvable::constPtr /*resolvable*/
579 , const std::string &/*reason*/
583 // progress for rebuilding the database
584 struct RebuildDBReport : public callback::ReportBase
587 ABORT, // abort and return error
589 IGNORE // ignore the failure
594 FAILED // failed to rebuild
597 virtual void start(Pathname /*path*/) {}
599 virtual bool progress(int /*value*/, Pathname /*path*/)
602 virtual Action problem(
605 , const std::string &/*description*/
611 , const std::string &/*reason*/
615 // progress for converting the database
616 struct ConvertDBReport : public callback::ReportBase
619 ABORT, // abort and return error
621 IGNORE // ignore the failure
626 FAILED // conversion failed
633 virtual bool progress(int /*value*/, Pathname /*path*/)
636 virtual Action problem(
639 , const std::string &/*description*/
645 , const std::string &/*reason*/
649 /////////////////////////////////////////////////////////////////
651 ///////////////////////////////////////////////////////////////////
653 /////////////////////////////////////////////////////////////////
654 } // namespace target
655 ///////////////////////////////////////////////////////////////////
662 * Callback for cleaning locks which doesn't lock anything in pool.
665 struct CleanEmptyLocksReport : public callback::ReportBase
668 * action performed by cleaning api to specific lock
671 ABORT, /**< abort and return error */
672 DELETE, /**< delete empty lock */
673 IGNORE /**< skip empty lock */
680 NO_ERROR, /**< no problem */
681 ABORTED /** cleaning aborted by user */
685 * cleaning is started
691 * progress of cleaning specifies in percents
692 * \return if continue
694 virtual bool progress(int /*value*/)
698 * When find empty lock ask what to do with it
701 virtual Action execute(
702 const PoolQuery& /*error*/
715 * this callback handles merging old locks with newly added or removed
717 struct SavingLocksReport : public callback::ReportBase
720 * action for old lock which is in conflict
724 ABORT, /**< abort and return error*/
725 DELETE, /**< delete conflicted lock */
726 IGNORE /**< skip conflict lock */
733 NO_ERROR, /**< no problem */
734 ABORTED /**< cleaning aborted by user */
738 * type of conflict of old and new lock
741 SAME_RESULTS, /**< locks lock same item in pool but his parameters is different */
742 INTERSECT /**< locks lock some file and unlocking lock unlock only part
743 * of iti, so removing old lock can unlock more items in pool */
746 virtual void start() {}
750 * \return if continue
752 virtual bool progress()
756 * When user unlock something which is locked by non-identical query
758 virtual Action conflict(
759 const PoolQuery&, /**< problematic query*/
770 ///////////////////////////////////////////////////////////////////
772 /// \brief Generic report for sending messages.
773 ///////////////////////////////////////////////////////////////////
774 struct JobReport : public callback::ReportBase
776 /** message type (use like 'enum class \ref MsgType') */
778 enum Enum { info, warning, error };
781 typedef base::EnumClass<_MsgTypeDef> MsgType; ///< 'enum class MsgType'
783 /** Send a ready to show message text. */
784 virtual bool message( MsgType type_r, const std::string & msg_r ) const { return true; }
787 /** \name Static sender instance */
789 /** Singleton sender instance */
790 static callback::SendReport<JobReport> & instance(); // impl in ZYppImpl.cc
792 /** send message text */
793 static bool info( const MessageString & msg_r ) { return instance()->message( MsgType::info, msg_r ); }
794 /** send warning text */
795 static bool warning( const MessageString & msg_r ) { return instance()->message( MsgType::warning, msg_r ); }
796 /** send error text */
797 static bool error( const MessageString & msg_r ) { return instance()->message( MsgType::error, msg_r ); }
802 /////////////////////////////////////////////////////////////////
804 ///////////////////////////////////////////////////////////////////
806 #endif // ZYPP_ZYPPCALLBACKS_H