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 _report->progress(progress);
80 value = _fnc(progress);
83 if ( progress.finalReport() )
85 _report->finish(progress);
90 ProgressData::ReceiverFnc _fnc;
91 callback::SendReport<ProgressReport> &_report;
95 ////////////////////////////////////////////////////////////////////////////
99 // progress for downloading a resolvable
100 struct DownloadResolvableReport : public callback::ReportBase
103 ABORT, // abort and return error
105 IGNORE, // ignore this resolvable but continue
110 NOT_FOUND, // the requested Url was not found
112 INVALID // the downloaded file is invalid
115 /** Hint that package is available in the local cache (no download needed).
116 * This will be the only trigger for an already cached package.
118 virtual void infoInCache( Resolvable::constPtr res_r, const Pathname & localfile_r )
122 Resolvable::constPtr /*resolvable_ptr*/
127 // Dowmload delta rpm:
128 // - path below url reported on start()
129 // - expected download size (0 if unknown)
130 // - download is interruptable
131 // - problems are just informal
132 virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
135 virtual bool progressDeltaDownload( int /*value*/ )
138 virtual void problemDeltaDownload( const std::string &/*description*/ )
141 virtual void finishDeltaDownload()
145 // - local path of downloaded delta
146 // - aplpy is not interruptable
147 // - problems are just informal
148 virtual void startDeltaApply( const Pathname & /*filename*/ )
151 virtual void progressDeltaApply( int /*value*/ )
154 virtual void problemDeltaApply( const std::string &/*description*/ )
157 virtual void finishDeltaApply()
160 /** \deprecated Unused since 2008 */
161 virtual ZYPP_DEPRECATED void startPatchDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
164 /** \deprecated Unused since 2008 */
165 virtual ZYPP_DEPRECATED bool progressPatchDownload( int /*value*/ )
168 /** \deprecated Unused since 2008 */
169 virtual ZYPP_DEPRECATED void problemPatchDownload( const std::string &/*description*/ )
172 /** \deprecated Unused since 2008 */
173 virtual ZYPP_DEPRECATED void finishPatchDownload()
177 // return false if the download should be aborted right now
178 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
181 virtual Action problem(
182 Resolvable::constPtr /*resolvable_ptr*/
184 , const std::string &/*description*/
188 /** Detail information about the result of a performed pkgGpgCheck.
191 * \param "ResObject" ResObject::constPtr of the downloaded package (Package or SrcPackage)
192 * \param "Localpath" Pathname to downloaded package on disk
193 * \param "CheckPackageResult" RpmDb::CheckPackageResult of signature check
194 * \param "CheckPackageDetail" RpmDb::CheckPackageDetail logmessages of rpm signature check
197 * \param "Action" DownloadResolvableReport::Action user advice how to behave on error (ABORT).
198 * If you set just an empty value here, a default probelm report will be triggered.
201 * \param "Package" Replaced by \c "ResObject" in 16.10.0. Package::constPtr of the package (\c nullptr in case of a SrcPackage)
203 virtual void pkgGpgCheck( const UserData & userData_r = UserData() )
206 virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
208 , const std::string &/*reason*/
212 // progress for probing a source
213 struct ProbeRepoReport : public callback::ReportBase
216 ABORT, // abort and return error
222 NOT_FOUND, // the requested Url was not found
224 INVALID, // th source is invalid
228 virtual void start(const Url &/*url*/) {}
229 virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
230 virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
231 virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
233 virtual bool progress(const Url &/*url*/, int /*value*/)
236 virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
239 struct RepoCreateReport : public callback::ReportBase
242 ABORT, // abort and return error
244 IGNORE // skip refresh, ignore failed refresh
249 NOT_FOUND, // the requested Url was not found
252 INVALID, // th source is invali
256 virtual void start( const zypp::Url &/*url*/ ) {}
257 virtual bool progress( int /*value*/ )
260 virtual Action problem(
261 const zypp::Url &/*url*/
263 , const std::string &/*description*/ )
267 const zypp::Url &/*url*/
269 , const std::string &/*reason*/ )
273 struct RepoReport : public callback::ReportBase
276 ABORT, // abort and return error
278 IGNORE // skip refresh, ignore failed refresh
283 NOT_FOUND, // the requested Url was not found
285 INVALID // th source is invalid
288 virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/ ) {}
289 virtual bool progress( const ProgressData &/*task*/ )
292 virtual Action problem(
293 Repository /*source*/
295 , const std::string &/*description*/ )
299 Repository /*source*/
300 , const std::string &/*task*/
302 , const std::string &/*reason*/ )
307 /////////////////////////////////////////////////////////////////
308 } // namespace source
309 ///////////////////////////////////////////////////////////////////
311 ///////////////////////////////////////////////////////////////////
314 // media change request callback
315 struct MediaChangeReport : public callback::ReportBase
318 ABORT, // abort and return error
320 IGNORE, // ignore this media in future, not available anymore
321 IGNORE_ID, // ignore wrong medium id
322 CHANGE_URL, // change media URL
323 EJECT // eject the medium
328 NOT_FOUND, // the medie not found at all
329 IO, // error accessing the media
330 INVALID, // media is broken
331 WRONG, // wrong media, need a different one
332 IO_SOFT /**< IO error which can happen on worse connection like timeout exceed */
337 * \param url in: url for which the media is requested,
338 * out: url to use instead of the original one
339 * \param mediumNr requested medium number
340 * \param label label of requested medium
341 * \param error type of error from \ref Error enum
342 * \param description error message (media not desired or error foo occured)
343 * \param devices list of the available devices (for eject)
344 * \param dev_current in: index of the currently used device in the \a devices list
345 * out: index of the devices to be ejected in the \a devices list
346 * \return \ref Action (ABORT by default)
348 virtual Action requestMedia(
349 Url & /* url (I/O parameter) */
350 , unsigned /*mediumNr*/
351 , const std::string & /* label */
353 , const std::string & /*description*/
354 , const std::vector<std::string> & /* devices */
355 , unsigned int & /* dev_current (I/O param) */
359 ///////////////////////////////////////////////////////////////////
360 /// \class ScopedDisableMediaChangeReport
361 /// \brief Temporarily disable MediaChangeReport
362 /// Sometimes helpful to suppress interactive messages connected to
363 /// MediaChangeReport while fallback URLs are avaialble.
364 struct ScopedDisableMediaChangeReport
366 /** Disbale MediaChangeReport if \a condition_r is \c true.*/
367 ScopedDisableMediaChangeReport( bool condition_r = true );
369 shared_ptr<callback::TempConnect<media::MediaChangeReport> > _guard;
372 // progress for downloading a file
373 struct DownloadProgressReport : public callback::ReportBase
376 ABORT, // abort and return error
378 IGNORE // ignore the failure
383 NOT_FOUND, // the requested Url was not found
385 ACCESS_DENIED, // user authent. failed while accessing restricted file
389 virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
394 * \param value Percentage value.
395 * \param file File URI.
396 * \param dbps_avg Average download rate so far. -1 if unknown.
397 * \param dbps_current Current download (cca last 1 sec). -1 if unknown.
399 virtual bool progress(int /*value*/, const Url &/*file*/,
400 double dbps_avg = -1,
401 double dbps_current = -1)
404 virtual Action problem(
407 , const std::string &/*description*/
413 , const std::string &/*reason*/
417 // authentication issues report
418 struct AuthenticationReport : public callback::ReportBase
421 * Prompt for authentication data.
423 * \param url URL which required the authentication
424 * \param msg prompt text
425 * \param auth_data input/output object for handling authentication
426 * data. As an input parameter auth_data can be prefilled with
427 * username (from previous try) or auth_type (available
428 * authentication methods aquired from server (only CurlAuthData)).
429 * As an output parameter it serves for sending username, pasword
430 * or other special data (derived AuthData objects).
431 * \return true if user chooses to continue with authentication,
434 virtual bool prompt(const Url & /* url */,
435 const std::string & /* msg */,
436 AuthData & /* auth_data */)
442 /////////////////////////////////////////////////////////////////
444 ///////////////////////////////////////////////////////////////////
446 ///////////////////////////////////////////////////////////////////
449 /** Request to display the pre commit message of a patch. */
450 struct PatchMessageReport : public callback::ReportBase
452 /** Display \c patch->message().
453 * Return \c true to continue, \c false to abort commit.
455 virtual bool show( Patch::constPtr & /*patch*/ )
459 /** Indicate execution of a patch script. This is a sort of
460 * \c %post script shipped by a package and to be executed
461 * after the package was installed.
463 struct PatchScriptReport : public callback::ReportBase
465 enum Notify { OUTPUT, PING };
467 ABORT, // abort commit and return error
468 RETRY, // (re)try to execute this script
469 IGNORE // ignore any failue and continue
472 /** Start executing the script provided by package.
474 virtual void start( const Package::constPtr & /*package*/,
475 const Pathname & /*script path*/ )
477 /** Progress provides the script output. If the script is quiet,
478 * from time to time still-alive pings are sent to the ui. Returning \c FALSE
479 * aborts script execution.
481 virtual bool progress( Notify /*OUTPUT or PING*/,
482 const std::string & /*output*/ = std::string() )
485 virtual Action problem( const std::string & /*description*/ )
487 /** Report success. */
488 virtual void finish()
492 ///////////////////////////////////////////////////////////////////
493 /// \class FindFileConflictstReport
494 /// \brief Check for package file conflicts in commit (after download)
496 /// File conflict check requires that all packages are downloaded and
497 /// now available in the cache (need to access the filelists). Missing
498 /// packages are omitted from check and their number is reported in
499 /// \a noFilelist_r. This usually happens if download mode 'as-needed'
501 ///////////////////////////////////////////////////////////////////
502 struct FindFileConflictstReport : public callback::ReportBase
505 * \param progress_r Progress counter for packages to check.
506 * \return \c true to continue, \c false upon user abort request.
508 virtual bool start( const ProgressData & progress_r )
512 * \param progress_r Progress counter for packages to check.
513 * \param noFilelist_r Queue of so far skipped solvables (no filelist/not yet downloaded).
514 * \return \c true to continue, \c false upon user abort request.
516 virtual bool progress( const ProgressData & progress_r, const sat::Queue & noFilelist_r )
520 * \param progress_r Progress counter for packages to check.
521 * \param noFilelist_r Queue of skipped solvables (no filelist/not yet downloaded).
522 * \param conflicts_r File conflits queue.
523 * \return \c true to continue, \c false upon user abort request.
525 virtual bool result( const ProgressData & progress_r, const sat::Queue & noFilelist_r, const sat::FileConflicts & conflicts_r )
530 ///////////////////////////////////////////////////////////////////
534 // progress for installing a resolvable
535 struct InstallResolvableReport : public callback::ReportBase
538 ABORT, // abort and return error
540 IGNORE // ignore the failure
545 NOT_FOUND, // the requested Url was not found
547 INVALID // th resolvable is invalid
550 // the level of RPM pushing
551 /** \deprecated We fortunately no longer do 3 attempts. */
555 RPM_NODEPS_FORCE //!< only this one used
559 Resolvable::constPtr /*resolvable*/
562 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
565 virtual Action problem(
566 Resolvable::constPtr /*resolvable*/
568 , const std::string &/*description*/
573 Resolvable::constPtr /*resolvable*/
575 , const std::string &/*reason*/
580 // progress for removing a resolvable
581 struct RemoveResolvableReport : public callback::ReportBase
584 ABORT, // abort and return error
586 IGNORE // ignore the failure
591 NOT_FOUND, // the requested Url was not found
593 INVALID // th resolvable is invalid
597 Resolvable::constPtr /*resolvable*/
600 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
603 virtual Action problem(
604 Resolvable::constPtr /*resolvable*/
606 , const std::string &/*description*/
610 Resolvable::constPtr /*resolvable*/
612 , const std::string &/*reason*/
616 // progress for rebuilding the database
617 struct RebuildDBReport : public callback::ReportBase
620 ABORT, // abort and return error
622 IGNORE // ignore the failure
627 FAILED // failed to rebuild
630 virtual void start(Pathname /*path*/) {}
632 virtual bool progress(int /*value*/, Pathname /*path*/)
635 virtual Action problem(
638 , const std::string &/*description*/
644 , const std::string &/*reason*/
648 // progress for converting the database
649 struct ConvertDBReport : public callback::ReportBase
652 ABORT, // abort and return error
654 IGNORE // ignore the failure
659 FAILED // conversion failed
666 virtual bool progress(int /*value*/, Pathname /*path*/)
669 virtual Action problem(
672 , const std::string &/*description*/
678 , const std::string &/*reason*/
682 /////////////////////////////////////////////////////////////////
684 ///////////////////////////////////////////////////////////////////
686 /////////////////////////////////////////////////////////////////
687 } // namespace target
688 ///////////////////////////////////////////////////////////////////
695 * Callback for cleaning locks which doesn't lock anything in pool.
698 struct CleanEmptyLocksReport : public callback::ReportBase
701 * action performed by cleaning api to specific lock
704 ABORT, /**< abort and return error */
705 DELETE, /**< delete empty lock */
706 IGNORE /**< skip empty lock */
713 NO_ERROR, /**< no problem */
714 ABORTED /** cleaning aborted by user */
718 * cleaning is started
724 * progress of cleaning specifies in percents
725 * \return if continue
727 virtual bool progress(int /*value*/)
731 * When find empty lock ask what to do with it
734 virtual Action execute(
735 const PoolQuery& /*error*/
748 * this callback handles merging old locks with newly added or removed
750 struct SavingLocksReport : public callback::ReportBase
753 * action for old lock which is in conflict
757 ABORT, /**< abort and return error*/
758 DELETE, /**< delete conflicted lock */
759 IGNORE /**< skip conflict lock */
766 NO_ERROR, /**< no problem */
767 ABORTED /**< cleaning aborted by user */
771 * type of conflict of old and new lock
774 SAME_RESULTS, /**< locks lock same item in pool but his parameters is different */
775 INTERSECT /**< locks lock some file and unlocking lock unlock only part
776 * of iti, so removing old lock can unlock more items in pool */
779 virtual void start() {}
783 * \return if continue
785 virtual bool progress()
789 * When user unlock something which is locked by non-identical query
791 virtual Action conflict(
792 const PoolQuery&, /**< problematic query*/
801 ///////////////////////////////////////////////////////////////////
803 /// \brief Generic report for sending messages.
804 ///////////////////////////////////////////////////////////////////
805 struct JobReport : public callback::ReportBase
808 /** message type (use like 'enum class \ref MsgType') */
810 enum Enum { debug, info, warning, error, important, data };
812 typedef base::EnumClass<_MsgTypeDef> MsgType; ///< 'enum class MsgType'
814 /** typsafe map of userdata */
815 typedef callback::UserData UserData;
818 /** Send a ready to show message text. */
819 virtual bool message( MsgType type_r, const std::string & msg_r, const UserData & userData_r ) const
823 /** \name Static sender instance */
825 /** Singleton sender instance */
826 static callback::SendReport<JobReport> & instance(); // impl in ZYppImpl.cc
828 /** send debug message text */
829 static bool debug( const MessageString & msg_r, const UserData & userData_r = UserData() )
830 { return instance()->message( MsgType::debug, msg_r, userData_r ); }
832 /** send message text */
833 static bool info( const MessageString & msg_r, const UserData & userData_r = UserData() )
834 { return instance()->message( MsgType::info, msg_r, userData_r ); }
836 /** send warning text */
837 static bool warning( const MessageString & msg_r, const UserData & userData_r = UserData() )
838 { return instance()->message( MsgType::warning, msg_r, userData_r ); }
840 /** send error text */
841 static bool error( const MessageString & msg_r, const UserData & userData_r = UserData() )
842 { return instance()->message( MsgType::error, msg_r, userData_r ); }
844 /** send important message text */
845 static bool important( const MessageString & msg_r, const UserData & userData_r = UserData() )
846 { return instance()->message( MsgType::important, msg_r, userData_r ); }
848 /** send data message */
849 static bool data( const MessageString & msg_r, const UserData & userData_r = UserData() )
850 { return instance()->message( MsgType::data, msg_r, userData_r ); }
855 /////////////////////////////////////////////////////////////////
857 ///////////////////////////////////////////////////////////////////
859 #endif // ZYPP_ZYPPCALLBACKS_H