1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ZYppCallbacks.h
12 #ifndef ZYPP_ZYPPCALLBACKS_H
13 #define ZYPP_ZYPPCALLBACKS_H
15 #include "zypp/base/Gettext.h"
16 #include "zypp/base/EnumClass.h"
17 #include "zypp/Callback.h"
18 #include "zypp/UserData.h"
19 #include "zypp/Resolvable.h"
20 #include "zypp/RepoInfo.h"
21 #include "zypp/Pathname.h"
22 #include "zypp/Package.h"
23 #include "zypp/Patch.h"
25 #include "zypp/ProgressData.h"
26 #include "zypp/media/MediaUserAuth.h"
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////
40 struct ProgressReport : public callback::ReportBase
42 virtual void start( const ProgressData &/*task*/ )
45 virtual bool progress( const ProgressData &/*task*/ )
48 // virtual Action problem(
51 // , const std::string &/*description*/ )
54 virtual void finish( const ProgressData &/*task*/ )
59 struct ProgressReportAdaptor
62 ProgressReportAdaptor( const ProgressData::ReceiverFnc &fnc,
63 callback::SendReport<ProgressReport> &report )
70 bool operator()( const ProgressData &progress )
74 _report->start(progress);
78 bool value = _report->progress(progress);
80 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 // return false if the download should be aborted right now
160 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
163 virtual Action problem(
164 Resolvable::constPtr /*resolvable_ptr*/
166 , const std::string &/*description*/
170 /** Detail information about the result of a performed pkgGpgCheck.
173 * \param "ResObject" ResObject::constPtr of the downloaded package (Package or SrcPackage)
174 * \param "Localpath" Pathname to downloaded package on disk
175 * \param "CheckPackageResult" RpmDb::CheckPackageResult of signature check
176 * \param "CheckPackageDetail" RpmDb::CheckPackageDetail logmessages of rpm signature check
179 * \param "Action" DownloadResolvableReport::Action user advice how to behave on error (ABORT).
180 * If you set just an empty value here, a default probelm report will be triggered.
183 * \param "Package" Replaced by \c "ResObject" in 16.10.0. Package::constPtr of the package (\c nullptr in case of a SrcPackage)
185 virtual void pkgGpgCheck( const UserData & userData_r = UserData() )
188 virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
190 , const std::string &/*reason*/
194 // progress for probing a source
195 struct ProbeRepoReport : public callback::ReportBase
198 ABORT, // abort and return error
204 NOT_FOUND, // the requested Url was not found
206 INVALID, // th source is invalid
210 virtual void start(const Url &/*url*/) {}
211 virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
212 virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
213 virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
215 virtual bool progress(const Url &/*url*/, int /*value*/)
218 virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
221 struct RepoCreateReport : public callback::ReportBase
224 ABORT, // abort and return error
226 IGNORE // skip refresh, ignore failed refresh
231 NOT_FOUND, // the requested Url was not found
234 INVALID, // th source is invali
238 virtual void start( const zypp::Url &/*url*/ ) {}
239 virtual bool progress( int /*value*/ )
242 virtual Action problem(
243 const zypp::Url &/*url*/
245 , const std::string &/*description*/ )
249 const zypp::Url &/*url*/
251 , const std::string &/*reason*/ )
255 struct RepoReport : public callback::ReportBase
258 ABORT, // abort and return error
260 IGNORE // skip refresh, ignore failed refresh
265 NOT_FOUND, // the requested Url was not found
267 INVALID // th source is invalid
270 virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/ ) {}
271 virtual bool progress( const ProgressData &/*task*/ )
274 virtual Action problem(
275 Repository /*source*/
277 , const std::string &/*description*/ )
281 Repository /*source*/
282 , const std::string &/*task*/
284 , const std::string &/*reason*/ )
289 /////////////////////////////////////////////////////////////////
290 } // namespace source
291 ///////////////////////////////////////////////////////////////////
293 ///////////////////////////////////////////////////////////////////
296 // media change request callback
297 struct MediaChangeReport : public callback::ReportBase
300 ABORT, // abort and return error
302 IGNORE, // ignore this media in future, not available anymore
303 IGNORE_ID, // ignore wrong medium id
304 CHANGE_URL, // change media URL
305 EJECT // eject the medium
310 NOT_FOUND, // the medie not found at all
311 IO, // error accessing the media
312 INVALID, // media is broken
313 WRONG, // wrong media, need a different one
314 IO_SOFT /**< IO error which can happen on worse connection like timeout exceed */
319 * \param url in: url for which the media is requested,
320 * out: url to use instead of the original one
321 * \param mediumNr requested medium number
322 * \param label label of requested medium
323 * \param error type of error from \ref Error enum
324 * \param description error message (media not desired or error foo occured)
325 * \param devices list of the available devices (for eject)
326 * \param dev_current in: index of the currently used device in the \a devices list
327 * out: index of the devices to be ejected in the \a devices list
328 * \return \ref Action (ABORT by default)
330 virtual Action requestMedia(
331 Url & /* url (I/O parameter) */
332 , unsigned /*mediumNr*/
333 , const std::string & /* label */
335 , const std::string & /*description*/
336 , const std::vector<std::string> & /* devices */
337 , unsigned int & /* dev_current (I/O param) */
341 ///////////////////////////////////////////////////////////////////
342 /// \class ScopedDisableMediaChangeReport
343 /// \brief Temporarily disable MediaChangeReport
344 /// Sometimes helpful to suppress interactive messages connected to
345 /// MediaChangeReport while fallback URLs are avaialble.
346 struct ScopedDisableMediaChangeReport
348 /** Disbale MediaChangeReport if \a condition_r is \c true.*/
349 ScopedDisableMediaChangeReport( bool condition_r = true );
351 shared_ptr<callback::TempConnect<media::MediaChangeReport> > _guard;
354 // progress for downloading a file
355 struct DownloadProgressReport : public callback::ReportBase
358 ABORT, // abort and return error
360 IGNORE // ignore the failure
365 NOT_FOUND, // the requested Url was not found
367 ACCESS_DENIED, // user authent. failed while accessing restricted file
371 virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
376 * \param value Percentage value.
377 * \param file File URI.
378 * \param dbps_avg Average download rate so far. -1 if unknown.
379 * \param dbps_current Current download (cca last 1 sec). -1 if unknown.
381 virtual bool progress(int /*value*/, const Url &/*file*/,
382 double dbps_avg = -1,
383 double dbps_current = -1)
386 virtual Action problem(
389 , const std::string &/*description*/
395 , const std::string &/*reason*/
399 // authentication issues report
400 struct AuthenticationReport : public callback::ReportBase
403 * Prompt for authentication data.
405 * \param url URL which required the authentication
406 * \param msg prompt text
407 * \param auth_data input/output object for handling authentication
408 * data. As an input parameter auth_data can be prefilled with
409 * username (from previous try) or auth_type (available
410 * authentication methods aquired from server (only CurlAuthData)).
411 * As an output parameter it serves for sending username, pasword
412 * or other special data (derived AuthData objects).
413 * \return true if user chooses to continue with authentication,
416 virtual bool prompt(const Url & /* url */,
417 const std::string & /* msg */,
418 AuthData & /* auth_data */)
424 /////////////////////////////////////////////////////////////////
426 ///////////////////////////////////////////////////////////////////
428 ///////////////////////////////////////////////////////////////////
431 /** Request to display the pre commit message of a patch. */
432 struct PatchMessageReport : public callback::ReportBase
434 /** Display \c patch->message().
435 * Return \c true to continue, \c false to abort commit.
437 virtual bool show( Patch::constPtr & /*patch*/ )
441 /** Indicate execution of a patch script. This is a sort of
442 * \c %post script shipped by a package and to be executed
443 * after the package was installed.
445 struct PatchScriptReport : public callback::ReportBase
447 enum Notify { OUTPUT, PING };
449 ABORT, // abort commit and return error
450 RETRY, // (re)try to execute this script
451 IGNORE // ignore any failue and continue
454 /** Start executing the script provided by package.
456 virtual void start( const Package::constPtr & /*package*/,
457 const Pathname & /*script path*/ )
459 /** Progress provides the script output. If the script is quiet,
460 * from time to time still-alive pings are sent to the ui. Returning \c FALSE
461 * aborts script execution.
463 virtual bool progress( Notify /*OUTPUT or PING*/,
464 const std::string & /*output*/ = std::string() )
467 virtual Action problem( const std::string & /*description*/ )
469 /** Report success. */
470 virtual void finish()
474 ///////////////////////////////////////////////////////////////////
475 /// \class FindFileConflictstReport
476 /// \brief Check for package file conflicts in commit (after download)
478 /// File conflict check requires that all packages are downloaded and
479 /// now available in the cache (need to access the filelists). Missing
480 /// packages are omitted from check and their number is reported in
481 /// \a noFilelist_r. This usually happens if download mode 'as-needed'
483 ///////////////////////////////////////////////////////////////////
484 struct FindFileConflictstReport : public callback::ReportBase
487 * \param progress_r Progress counter for packages to check.
488 * \return \c true to continue, \c false upon user abort request.
490 virtual bool start( const ProgressData & progress_r )
494 * \param progress_r Progress counter for packages to check.
495 * \param noFilelist_r Queue of so far skipped solvables (no filelist/not yet downloaded).
496 * \return \c true to continue, \c false upon user abort request.
498 virtual bool progress( const ProgressData & progress_r, const sat::Queue & noFilelist_r )
502 * \param progress_r Progress counter for packages to check.
503 * \param noFilelist_r Queue of skipped solvables (no filelist/not yet downloaded).
504 * \param conflicts_r File conflits queue.
505 * \return \c true to continue, \c false upon user abort request.
507 virtual bool result( const ProgressData & progress_r, const sat::Queue & noFilelist_r, const sat::FileConflicts & conflicts_r )
512 ///////////////////////////////////////////////////////////////////
516 // progress for installing a resolvable
517 struct InstallResolvableReport : public callback::ReportBase
520 ABORT, // abort and return error
522 IGNORE // ignore the failure
527 NOT_FOUND, // the requested Url was not found
529 INVALID // th resolvable is invalid
532 // the level of RPM pushing
533 /** \deprecated We fortunately no longer do 3 attempts. */
537 RPM_NODEPS_FORCE //!< only this one used
541 Resolvable::constPtr /*resolvable*/
544 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
547 virtual Action problem(
548 Resolvable::constPtr /*resolvable*/
550 , const std::string &/*description*/
555 Resolvable::constPtr /*resolvable*/
557 , const std::string &/*reason*/
562 // progress for removing a resolvable
563 struct RemoveResolvableReport : public callback::ReportBase
566 ABORT, // abort and return error
568 IGNORE // ignore the failure
573 NOT_FOUND, // the requested Url was not found
575 INVALID // th resolvable is invalid
579 Resolvable::constPtr /*resolvable*/
582 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
585 virtual Action problem(
586 Resolvable::constPtr /*resolvable*/
588 , const std::string &/*description*/
592 Resolvable::constPtr /*resolvable*/
594 , const std::string &/*reason*/
598 // progress for rebuilding the database
599 struct RebuildDBReport : public callback::ReportBase
602 ABORT, // abort and return error
604 IGNORE // ignore the failure
609 FAILED // failed to rebuild
612 virtual void start(Pathname /*path*/) {}
614 virtual bool progress(int /*value*/, Pathname /*path*/)
617 virtual Action problem(
620 , const std::string &/*description*/
626 , const std::string &/*reason*/
630 // progress for converting the database
631 struct ConvertDBReport : public callback::ReportBase
634 ABORT, // abort and return error
636 IGNORE // ignore the failure
641 FAILED // conversion failed
648 virtual bool progress(int /*value*/, Pathname /*path*/)
651 virtual Action problem(
654 , const std::string &/*description*/
660 , const std::string &/*reason*/
664 /////////////////////////////////////////////////////////////////
666 ///////////////////////////////////////////////////////////////////
668 /////////////////////////////////////////////////////////////////
669 } // namespace target
670 ///////////////////////////////////////////////////////////////////
677 * Callback for cleaning locks which doesn't lock anything in pool.
680 struct CleanEmptyLocksReport : public callback::ReportBase
683 * action performed by cleaning api to specific lock
686 ABORT, /**< abort and return error */
687 DELETE, /**< delete empty lock */
688 IGNORE /**< skip empty lock */
695 NO_ERROR, /**< no problem */
696 ABORTED /** cleaning aborted by user */
700 * cleaning is started
706 * progress of cleaning specifies in percents
707 * \return if continue
709 virtual bool progress(int /*value*/)
713 * When find empty lock ask what to do with it
716 virtual Action execute(
717 const PoolQuery& /*error*/
730 * this callback handles merging old locks with newly added or removed
732 struct SavingLocksReport : public callback::ReportBase
735 * action for old lock which is in conflict
739 ABORT, /**< abort and return error*/
740 DELETE, /**< delete conflicted lock */
741 IGNORE /**< skip conflict lock */
748 NO_ERROR, /**< no problem */
749 ABORTED /**< cleaning aborted by user */
753 * type of conflict of old and new lock
756 SAME_RESULTS, /**< locks lock same item in pool but his parameters is different */
757 INTERSECT /**< locks lock some file and unlocking lock unlock only part
758 * of iti, so removing old lock can unlock more items in pool */
761 virtual void start() {}
765 * \return if continue
767 virtual bool progress()
771 * When user unlock something which is locked by non-identical query
773 virtual Action conflict(
774 const PoolQuery&, /**< problematic query*/
783 ///////////////////////////////////////////////////////////////////
785 /// \brief Generic report for sending messages.
786 ///////////////////////////////////////////////////////////////////
787 struct JobReport : public callback::ReportBase
790 /** message type (use like 'enum class \ref MsgType') */
792 enum Enum { debug, info, warning, error, important, data };
794 typedef base::EnumClass<EMsgTypeDef> MsgType; ///< 'enum class MsgType'
796 /** typsafe map of userdata */
797 typedef callback::UserData UserData;
800 /** Send a ready to show message text. */
801 virtual bool message( MsgType type_r, const std::string & msg_r, const UserData & userData_r ) const
805 /** \name Static sender instance */
807 /** Singleton sender instance */
808 static callback::SendReport<JobReport> & instance(); // impl in ZYppImpl.cc
810 /** send debug message text */
811 static bool debug( const std::string & msg_r, const UserData & userData_r = UserData() )
812 { return instance()->message( MsgType::debug, msg_r, userData_r ); }
814 /** send message text */
815 static bool info( const std::string & msg_r, const UserData & userData_r = UserData() )
816 { return instance()->message( MsgType::info, msg_r, userData_r ); }
818 /** send warning text */
819 static bool warning( const std::string & msg_r, const UserData & userData_r = UserData() )
820 { return instance()->message( MsgType::warning, msg_r, userData_r ); }
822 /** send error text */
823 static bool error( const std::string & msg_r, const UserData & userData_r = UserData() )
824 { return instance()->message( MsgType::error, msg_r, userData_r ); }
826 /** send important message text */
827 static bool important( const std::string & msg_r, const UserData & userData_r = UserData() )
828 { return instance()->message( MsgType::important, msg_r, userData_r ); }
830 /** send data message */
831 static bool data( const std::string & msg_r, const UserData & userData_r = UserData() )
832 { return instance()->message( MsgType::data, msg_r, userData_r ); }
837 /////////////////////////////////////////////////////////////////
839 ///////////////////////////////////////////////////////////////////
841 #endif // ZYPP_ZYPPCALLBACKS_H