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/UserData.h"
18 #include "zypp/Resolvable.h"
19 #include "zypp/RepoInfo.h"
20 #include "zypp/Pathname.h"
21 #include "zypp/Package.h"
22 #include "zypp/Patch.h"
24 #include "zypp/ProgressData.h"
25 #include "zypp/media/MediaUserAuth.h"
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////
39 struct ProgressReport : public callback::ReportBase
41 virtual void start( const ProgressData &/*task*/ )
44 virtual bool progress( const ProgressData &/*task*/ )
47 // virtual Action problem(
50 // , const std::string &/*description*/ )
53 virtual void finish( const ProgressData &/*task*/ )
58 struct ProgressReportAdaptor
61 ProgressReportAdaptor( const ProgressData::ReceiverFnc &fnc,
62 callback::SendReport<ProgressReport> &report )
69 bool operator()( const ProgressData &progress )
73 _report->start(progress);
77 bool value = _report->progress(progress);
79 value &= _fnc(progress);
81 if ( progress.finalReport() )
83 _report->finish(progress);
88 ProgressData::ReceiverFnc _fnc;
89 callback::SendReport<ProgressReport> &_report;
93 ////////////////////////////////////////////////////////////////////////////
97 // progress for downloading a resolvable
98 struct DownloadResolvableReport : public callback::ReportBase
101 ABORT, // abort and return error
103 IGNORE, // ignore this resolvable but continue
108 NOT_FOUND, // the requested Url was not found
110 INVALID // the downloaded file is invalid
113 /** Hint that package is available in the local cache (no download needed).
114 * This will be the only trigger for an already cached package.
116 virtual void infoInCache( Resolvable::constPtr res_r, const Pathname & localfile_r )
120 Resolvable::constPtr /*resolvable_ptr*/
125 // Dowmload delta rpm:
126 // - path below url reported on start()
127 // - expected download size (0 if unknown)
128 // - download is interruptable
129 // - problems are just informal
130 virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
133 virtual bool progressDeltaDownload( int /*value*/ )
136 virtual void problemDeltaDownload( const std::string &/*description*/ )
139 virtual void finishDeltaDownload()
143 // - local path of downloaded delta
144 // - aplpy is not interruptable
145 // - problems are just informal
146 virtual void startDeltaApply( const Pathname & /*filename*/ )
149 virtual void progressDeltaApply( int /*value*/ )
152 virtual void problemDeltaApply( const std::string &/*description*/ )
155 virtual void finishDeltaApply()
158 // return false if the download should be aborted right now
159 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
162 virtual Action problem(
163 Resolvable::constPtr /*resolvable_ptr*/
165 , const std::string &/*description*/
169 /** Detail information about the result of a performed pkgGpgCheck.
172 * \param "ResObject" ResObject::constPtr of the downloaded package (Package or SrcPackage)
173 * \param "Localpath" Pathname to downloaded package on disk
174 * \param "CheckPackageResult" RpmDb::CheckPackageResult of signature check
175 * \param "CheckPackageDetail" RpmDb::CheckPackageDetail logmessages of rpm signature check
178 * \param "Action" DownloadResolvableReport::Action user advice how to behave on error (ABORT).
179 * If you set just an empty value here, a default probelm report will be triggered.
182 * \param "Package" Replaced by \c "ResObject" in 16.10.0. Package::constPtr of the package (\c nullptr in case of a SrcPackage)
184 virtual void pkgGpgCheck( const UserData & userData_r = UserData() )
187 virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
189 , const std::string &/*reason*/
193 // progress for probing a source
194 struct ProbeRepoReport : public callback::ReportBase
197 ABORT, // abort and return error
203 NOT_FOUND, // the requested Url was not found
205 INVALID, // th source is invalid
209 virtual void start(const Url &/*url*/) {}
210 virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
211 virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
212 virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
214 virtual bool progress(const Url &/*url*/, int /*value*/)
217 virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
220 struct RepoCreateReport : public callback::ReportBase
223 ABORT, // abort and return error
225 IGNORE // skip refresh, ignore failed refresh
230 NOT_FOUND, // the requested Url was not found
233 INVALID, // th source is invali
237 virtual void start( const zypp::Url &/*url*/ ) {}
238 virtual bool progress( int /*value*/ )
241 virtual Action problem(
242 const zypp::Url &/*url*/
244 , const std::string &/*description*/ )
248 const zypp::Url &/*url*/
250 , const std::string &/*reason*/ )
254 struct RepoReport : public callback::ReportBase
257 ABORT, // abort and return error
259 IGNORE // skip refresh, ignore failed refresh
264 NOT_FOUND, // the requested Url was not found
266 INVALID // th source is invalid
269 virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/ ) {}
270 virtual bool progress( const ProgressData &/*task*/ )
273 virtual Action problem(
274 Repository /*source*/
276 , const std::string &/*description*/ )
280 Repository /*source*/
281 , const std::string &/*task*/
283 , const std::string &/*reason*/ )
288 /////////////////////////////////////////////////////////////////
289 } // namespace source
290 ///////////////////////////////////////////////////////////////////
292 ///////////////////////////////////////////////////////////////////
295 // media change request callback
296 struct MediaChangeReport : public callback::ReportBase
299 ABORT, // abort and return error
301 IGNORE, // ignore this media in future, not available anymore
302 IGNORE_ID, // ignore wrong medium id
303 CHANGE_URL, // change media URL
304 EJECT // eject the medium
309 NOT_FOUND, // the medie not found at all
310 IO, // error accessing the media
311 INVALID, // media is broken
312 WRONG, // wrong media, need a different one
313 IO_SOFT /**< IO error which can happen on worse connection like timeout exceed */
318 * \param url in: url for which the media is requested,
319 * out: url to use instead of the original one
320 * \param mediumNr requested medium number
321 * \param label label of requested medium
322 * \param error type of error from \ref Error enum
323 * \param description error message (media not desired or error foo occured)
324 * \param devices list of the available devices (for eject)
325 * \param dev_current in: index of the currently used device in the \a devices list
326 * out: index of the devices to be ejected in the \a devices list
327 * \return \ref Action (ABORT by default)
329 virtual Action requestMedia(
330 Url & /* url (I/O parameter) */
331 , unsigned /*mediumNr*/
332 , const std::string & /* label */
334 , const std::string & /*description*/
335 , const std::vector<std::string> & /* devices */
336 , unsigned int & /* dev_current (I/O param) */
340 ///////////////////////////////////////////////////////////////////
341 /// \class ScopedDisableMediaChangeReport
342 /// \brief Temporarily disable MediaChangeReport
343 /// Sometimes helpful to suppress interactive messages connected to
344 /// MediaChangeReport while fallback URLs are avaialble.
345 struct ScopedDisableMediaChangeReport
347 /** Disbale MediaChangeReport if \a condition_r is \c true.*/
348 ScopedDisableMediaChangeReport( bool condition_r = true );
350 shared_ptr<callback::TempConnect<media::MediaChangeReport> > _guard;
353 // progress for downloading a file
354 struct DownloadProgressReport : public callback::ReportBase
357 ABORT, // abort and return error
359 IGNORE // ignore the failure
364 NOT_FOUND, // the requested Url was not found
366 ACCESS_DENIED, // user authent. failed while accessing restricted file
370 virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
375 * \param value Percentage value.
376 * \param file File URI.
377 * \param dbps_avg Average download rate so far. -1 if unknown.
378 * \param dbps_current Current download (cca last 1 sec). -1 if unknown.
380 virtual bool progress(int /*value*/, const Url &/*file*/,
381 double dbps_avg = -1,
382 double dbps_current = -1)
385 virtual Action problem(
388 , const std::string &/*description*/
394 , const std::string &/*reason*/
398 // authentication issues report
399 struct AuthenticationReport : public callback::ReportBase
402 * Prompt for authentication data.
404 * \param url URL which required the authentication
405 * \param msg prompt text
406 * \param auth_data input/output object for handling authentication
407 * data. As an input parameter auth_data can be prefilled with
408 * username (from previous try) or auth_type (available
409 * authentication methods aquired from server (only CurlAuthData)).
410 * As an output parameter it serves for sending username, pasword
411 * or other special data (derived AuthData objects).
412 * \return true if user chooses to continue with authentication,
415 virtual bool prompt(const Url & /* url */,
416 const std::string & /* msg */,
417 AuthData & /* auth_data */)
423 /////////////////////////////////////////////////////////////////
425 ///////////////////////////////////////////////////////////////////
427 ///////////////////////////////////////////////////////////////////
430 /** Request to display the pre commit message of a patch. */
431 struct PatchMessageReport : public callback::ReportBase
433 /** Display \c patch->message().
434 * Return \c true to continue, \c false to abort commit.
436 virtual bool show( Patch::constPtr & /*patch*/ )
440 /** Indicate execution of a patch script. This is a sort of
441 * \c %post script shipped by a package and to be executed
442 * after the package was installed.
444 struct PatchScriptReport : public callback::ReportBase
446 enum Notify { OUTPUT, PING };
448 ABORT, // abort commit and return error
449 RETRY, // (re)try to execute this script
450 IGNORE // ignore any failue and continue
453 /** Start executing the script provided by package.
455 virtual void start( const Package::constPtr & /*package*/,
456 const Pathname & /*script path*/ )
458 /** Progress provides the script output. If the script is quiet,
459 * from time to time still-alive pings are sent to the ui. Returning \c FALSE
460 * aborts script execution.
462 virtual bool progress( Notify /*OUTPUT or PING*/,
463 const std::string & /*output*/ = std::string() )
466 virtual Action problem( const std::string & /*description*/ )
468 /** Report success. */
469 virtual void finish()
473 ///////////////////////////////////////////////////////////////////
474 /// \class FindFileConflictstReport
475 /// \brief Check for package file conflicts in commit (after download)
477 /// File conflict check requires that all packages are downloaded and
478 /// now available in the cache (need to access the filelists). Missing
479 /// packages are omitted from check and their number is reported in
480 /// \a noFilelist_r. This usually happens if download mode 'as-needed'
482 ///////////////////////////////////////////////////////////////////
483 struct FindFileConflictstReport : public callback::ReportBase
486 * \param progress_r Progress counter for packages to check.
487 * \return \c true to continue, \c false upon user abort request.
489 virtual bool start( const ProgressData & progress_r )
493 * \param progress_r Progress counter for packages to check.
494 * \param noFilelist_r Queue of so far skipped solvables (no filelist/not yet downloaded).
495 * \return \c true to continue, \c false upon user abort request.
497 virtual bool progress( const ProgressData & progress_r, const sat::Queue & noFilelist_r )
501 * \param progress_r Progress counter for packages to check.
502 * \param noFilelist_r Queue of skipped solvables (no filelist/not yet downloaded).
503 * \param conflicts_r File conflits queue.
504 * \return \c true to continue, \c false upon user abort request.
506 virtual bool result( const ProgressData & progress_r, const sat::Queue & noFilelist_r, const sat::FileConflicts & conflicts_r )
511 ///////////////////////////////////////////////////////////////////
515 // progress for installing a resolvable
516 struct InstallResolvableReport : public callback::ReportBase
519 ABORT, // abort and return error
521 IGNORE // ignore the failure
526 NOT_FOUND, // the requested Url was not found
528 INVALID // th resolvable is invalid
531 // the level of RPM pushing
532 /** \deprecated We fortunately no longer do 3 attempts. */
536 RPM_NODEPS_FORCE //!< only this one used
540 Resolvable::constPtr /*resolvable*/
543 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
546 virtual Action problem(
547 Resolvable::constPtr /*resolvable*/
549 , const std::string &/*description*/
554 Resolvable::constPtr /*resolvable*/
556 , const std::string &/*reason*/
561 // progress for removing a resolvable
562 struct RemoveResolvableReport : public callback::ReportBase
565 ABORT, // abort and return error
567 IGNORE // ignore the failure
572 NOT_FOUND, // the requested Url was not found
574 INVALID // th resolvable is invalid
578 Resolvable::constPtr /*resolvable*/
581 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
584 virtual Action problem(
585 Resolvable::constPtr /*resolvable*/
587 , const std::string &/*description*/
591 Resolvable::constPtr /*resolvable*/
593 , const std::string &/*reason*/
597 // progress for rebuilding the database
598 struct RebuildDBReport : public callback::ReportBase
601 ABORT, // abort and return error
603 IGNORE // ignore the failure
608 FAILED // failed to rebuild
611 virtual void start(Pathname /*path*/) {}
613 virtual bool progress(int /*value*/, Pathname /*path*/)
616 virtual Action problem(
619 , const std::string &/*description*/
625 , const std::string &/*reason*/
629 // progress for converting the database
630 struct ConvertDBReport : public callback::ReportBase
633 ABORT, // abort and return error
635 IGNORE // ignore the failure
640 FAILED // conversion failed
647 virtual bool progress(int /*value*/, Pathname /*path*/)
650 virtual Action problem(
653 , const std::string &/*description*/
659 , const std::string &/*reason*/
663 /////////////////////////////////////////////////////////////////
665 ///////////////////////////////////////////////////////////////////
667 /////////////////////////////////////////////////////////////////
668 } // namespace target
669 ///////////////////////////////////////////////////////////////////
676 * Callback for cleaning locks which doesn't lock anything in pool.
679 struct CleanEmptyLocksReport : public callback::ReportBase
682 * action performed by cleaning api to specific lock
685 ABORT, /**< abort and return error */
686 DELETE, /**< delete empty lock */
687 IGNORE /**< skip empty lock */
694 NO_ERROR, /**< no problem */
695 ABORTED /** cleaning aborted by user */
699 * cleaning is started
705 * progress of cleaning specifies in percents
706 * \return if continue
708 virtual bool progress(int /*value*/)
712 * When find empty lock ask what to do with it
715 virtual Action execute(
716 const PoolQuery& /*error*/
729 * this callback handles merging old locks with newly added or removed
731 struct SavingLocksReport : public callback::ReportBase
734 * action for old lock which is in conflict
738 ABORT, /**< abort and return error*/
739 DELETE, /**< delete conflicted lock */
740 IGNORE /**< skip conflict lock */
747 NO_ERROR, /**< no problem */
748 ABORTED /**< cleaning aborted by user */
752 * type of conflict of old and new lock
755 SAME_RESULTS, /**< locks lock same item in pool but his parameters is different */
756 INTERSECT /**< locks lock some file and unlocking lock unlock only part
757 * of iti, so removing old lock can unlock more items in pool */
760 virtual void start() {}
764 * \return if continue
766 virtual bool progress()
770 * When user unlock something which is locked by non-identical query
772 virtual Action conflict(
773 const PoolQuery&, /**< problematic query*/
782 ///////////////////////////////////////////////////////////////////
784 /// \brief Generic report for sending messages.
785 ///////////////////////////////////////////////////////////////////
786 struct JobReport : public callback::ReportBase
789 /** message type (use like 'enum class \ref MsgType') */
791 enum Enum { debug, info, warning, error, important, data };
793 typedef base::EnumClass<EMsgTypeDef> MsgType; ///< 'enum class MsgType'
795 /** typsafe map of userdata */
796 typedef callback::UserData UserData;
799 /** Send a ready to show message text. */
800 virtual bool message( MsgType type_r, const std::string & msg_r, const UserData & userData_r ) const
804 /** \name Static sender instance */
806 /** Singleton sender instance */
807 static callback::SendReport<JobReport> & instance(); // impl in ZYppImpl.cc
809 /** send debug message text */
810 static bool debug( const std::string & msg_r, const UserData & userData_r = UserData() )
811 { return instance()->message( MsgType::debug, msg_r, userData_r ); }
813 /** send message text */
814 static bool info( const std::string & msg_r, const UserData & userData_r = UserData() )
815 { return instance()->message( MsgType::info, msg_r, userData_r ); }
817 /** send warning text */
818 static bool warning( const std::string & msg_r, const UserData & userData_r = UserData() )
819 { return instance()->message( MsgType::warning, msg_r, userData_r ); }
821 /** send error text */
822 static bool error( const std::string & msg_r, const UserData & userData_r = UserData() )
823 { return instance()->message( MsgType::error, msg_r, userData_r ); }
825 /** send important message text */
826 static bool important( const std::string & msg_r, const UserData & userData_r = UserData() )
827 { return instance()->message( MsgType::important, msg_r, userData_r ); }
829 /** send data message */
830 static bool data( const std::string & msg_r, const UserData & userData_r = UserData() )
831 { return instance()->message( MsgType::data, msg_r, userData_r ); }
836 /////////////////////////////////////////////////////////////////
838 ///////////////////////////////////////////////////////////////////
840 #endif // ZYPP_ZYPPCALLBACKS_H