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 // return false if the download should be aborted right now
161 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
164 virtual Action problem(
165 Resolvable::constPtr /*resolvable_ptr*/
167 , const std::string &/*description*/
171 /** Detail information about the result of a performed pkgGpgCheck.
174 * \param "ResObject" ResObject::constPtr of the downloaded package (Package or SrcPackage)
175 * \param "Localpath" Pathname to downloaded package on disk
176 * \param "CheckPackageResult" RpmDb::CheckPackageResult of signature check
177 * \param "CheckPackageDetail" RpmDb::CheckPackageDetail logmessages of rpm signature check
180 * \param "Action" DownloadResolvableReport::Action user advice how to behave on error (ABORT).
181 * If you set just an empty value here, a default probelm report will be triggered.
184 * \param "Package" Replaced by \c "ResObject" in 16.10.0. Package::constPtr of the package (\c nullptr in case of a SrcPackage)
186 virtual void pkgGpgCheck( const UserData & userData_r = UserData() )
189 virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
191 , const std::string &/*reason*/
195 // progress for probing a source
196 struct ProbeRepoReport : public callback::ReportBase
199 ABORT, // abort and return error
205 NOT_FOUND, // the requested Url was not found
207 INVALID, // th source is invalid
211 virtual void start(const Url &/*url*/) {}
212 virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
213 virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
214 virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
216 virtual bool progress(const Url &/*url*/, int /*value*/)
219 virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
222 struct RepoCreateReport : public callback::ReportBase
225 ABORT, // abort and return error
227 IGNORE // skip refresh, ignore failed refresh
232 NOT_FOUND, // the requested Url was not found
235 INVALID, // th source is invali
239 virtual void start( const zypp::Url &/*url*/ ) {}
240 virtual bool progress( int /*value*/ )
243 virtual Action problem(
244 const zypp::Url &/*url*/
246 , const std::string &/*description*/ )
250 const zypp::Url &/*url*/
252 , const std::string &/*reason*/ )
256 struct RepoReport : public callback::ReportBase
259 ABORT, // abort and return error
261 IGNORE // skip refresh, ignore failed refresh
266 NOT_FOUND, // the requested Url was not found
268 INVALID // th source is invalid
271 virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/ ) {}
272 virtual bool progress( const ProgressData &/*task*/ )
275 virtual Action problem(
276 Repository /*source*/
278 , const std::string &/*description*/ )
282 Repository /*source*/
283 , const std::string &/*task*/
285 , const std::string &/*reason*/ )
290 /////////////////////////////////////////////////////////////////
291 } // namespace source
292 ///////////////////////////////////////////////////////////////////
294 ///////////////////////////////////////////////////////////////////
297 // media change request callback
298 struct MediaChangeReport : public callback::ReportBase
301 ABORT, // abort and return error
303 IGNORE, // ignore this media in future, not available anymore
304 IGNORE_ID, // ignore wrong medium id
305 CHANGE_URL, // change media URL
306 EJECT // eject the medium
311 NOT_FOUND, // the medie not found at all
312 IO, // error accessing the media
313 INVALID, // media is broken
314 WRONG, // wrong media, need a different one
315 IO_SOFT /**< IO error which can happen on worse connection like timeout exceed */
320 * \param url in: url for which the media is requested,
321 * out: url to use instead of the original one
322 * \param mediumNr requested medium number
323 * \param label label of requested medium
324 * \param error type of error from \ref Error enum
325 * \param description error message (media not desired or error foo occured)
326 * \param devices list of the available devices (for eject)
327 * \param dev_current in: index of the currently used device in the \a devices list
328 * out: index of the devices to be ejected in the \a devices list
329 * \return \ref Action (ABORT by default)
331 virtual Action requestMedia(
332 Url & /* url (I/O parameter) */
333 , unsigned /*mediumNr*/
334 , const std::string & /* label */
336 , const std::string & /*description*/
337 , const std::vector<std::string> & /* devices */
338 , unsigned int & /* dev_current (I/O param) */
342 ///////////////////////////////////////////////////////////////////
343 /// \class ScopedDisableMediaChangeReport
344 /// \brief Temporarily disable MediaChangeReport
345 /// Sometimes helpful to suppress interactive messages connected to
346 /// MediaChangeReport while fallback URLs are avaialble.
347 struct ScopedDisableMediaChangeReport
349 /** Disbale MediaChangeReport if \a condition_r is \c true.*/
350 ScopedDisableMediaChangeReport( bool condition_r = true );
352 shared_ptr<callback::TempConnect<media::MediaChangeReport> > _guard;
355 // progress for downloading a file
356 struct DownloadProgressReport : public callback::ReportBase
359 ABORT, // abort and return error
361 IGNORE // ignore the failure
366 NOT_FOUND, // the requested Url was not found
368 ACCESS_DENIED, // user authent. failed while accessing restricted file
372 virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
377 * \param value Percentage value.
378 * \param file File URI.
379 * \param dbps_avg Average download rate so far. -1 if unknown.
380 * \param dbps_current Current download (cca last 1 sec). -1 if unknown.
382 virtual bool progress(int /*value*/, const Url &/*file*/,
383 double dbps_avg = -1,
384 double dbps_current = -1)
387 virtual Action problem(
390 , const std::string &/*description*/
396 , const std::string &/*reason*/
400 // authentication issues report
401 struct AuthenticationReport : public callback::ReportBase
404 * Prompt for authentication data.
406 * \param url URL which required the authentication
407 * \param msg prompt text
408 * \param auth_data input/output object for handling authentication
409 * data. As an input parameter auth_data can be prefilled with
410 * username (from previous try) or auth_type (available
411 * authentication methods aquired from server (only CurlAuthData)).
412 * As an output parameter it serves for sending username, pasword
413 * or other special data (derived AuthData objects).
414 * \return true if user chooses to continue with authentication,
417 virtual bool prompt(const Url & /* url */,
418 const std::string & /* msg */,
419 AuthData & /* auth_data */)
425 /////////////////////////////////////////////////////////////////
427 ///////////////////////////////////////////////////////////////////
429 ///////////////////////////////////////////////////////////////////
432 /** Request to display the pre commit message of a patch. */
433 struct PatchMessageReport : public callback::ReportBase
435 /** Display \c patch->message().
436 * Return \c true to continue, \c false to abort commit.
438 virtual bool show( Patch::constPtr & /*patch*/ )
442 /** Indicate execution of a patch script. This is a sort of
443 * \c %post script shipped by a package and to be executed
444 * after the package was installed.
446 struct PatchScriptReport : public callback::ReportBase
448 enum Notify { OUTPUT, PING };
450 ABORT, // abort commit and return error
451 RETRY, // (re)try to execute this script
452 IGNORE // ignore any failue and continue
455 /** Start executing the script provided by package.
457 virtual void start( const Package::constPtr & /*package*/,
458 const Pathname & /*script path*/ )
460 /** Progress provides the script output. If the script is quiet,
461 * from time to time still-alive pings are sent to the ui. Returning \c FALSE
462 * aborts script execution.
464 virtual bool progress( Notify /*OUTPUT or PING*/,
465 const std::string & /*output*/ = std::string() )
468 virtual Action problem( const std::string & /*description*/ )
470 /** Report success. */
471 virtual void finish()
475 ///////////////////////////////////////////////////////////////////
476 /// \class FindFileConflictstReport
477 /// \brief Check for package file conflicts in commit (after download)
479 /// File conflict check requires that all packages are downloaded and
480 /// now available in the cache (need to access the filelists). Missing
481 /// packages are omitted from check and their number is reported in
482 /// \a noFilelist_r. This usually happens if download mode 'as-needed'
484 ///////////////////////////////////////////////////////////////////
485 struct FindFileConflictstReport : public callback::ReportBase
488 * \param progress_r Progress counter for packages to check.
489 * \return \c true to continue, \c false upon user abort request.
491 virtual bool start( const ProgressData & progress_r )
495 * \param progress_r Progress counter for packages to check.
496 * \param noFilelist_r Queue of so far skipped solvables (no filelist/not yet downloaded).
497 * \return \c true to continue, \c false upon user abort request.
499 virtual bool progress( const ProgressData & progress_r, const sat::Queue & noFilelist_r )
503 * \param progress_r Progress counter for packages to check.
504 * \param noFilelist_r Queue of skipped solvables (no filelist/not yet downloaded).
505 * \param conflicts_r File conflits queue.
506 * \return \c true to continue, \c false upon user abort request.
508 virtual bool result( const ProgressData & progress_r, const sat::Queue & noFilelist_r, const sat::FileConflicts & conflicts_r )
513 ///////////////////////////////////////////////////////////////////
517 // progress for installing a resolvable
518 struct InstallResolvableReport : public callback::ReportBase
521 ABORT, // abort and return error
523 IGNORE // ignore the failure
528 NOT_FOUND, // the requested Url was not found
530 INVALID // th resolvable is invalid
533 // the level of RPM pushing
534 /** \deprecated We fortunately no longer do 3 attempts. */
538 RPM_NODEPS_FORCE //!< only this one used
542 Resolvable::constPtr /*resolvable*/
545 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
548 virtual Action problem(
549 Resolvable::constPtr /*resolvable*/
551 , const std::string &/*description*/
556 Resolvable::constPtr /*resolvable*/
558 , const std::string &/*reason*/
563 // progress for removing a resolvable
564 struct RemoveResolvableReport : public callback::ReportBase
567 ABORT, // abort and return error
569 IGNORE // ignore the failure
574 NOT_FOUND, // the requested Url was not found
576 INVALID // th resolvable is invalid
580 Resolvable::constPtr /*resolvable*/
583 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
586 virtual Action problem(
587 Resolvable::constPtr /*resolvable*/
589 , const std::string &/*description*/
593 Resolvable::constPtr /*resolvable*/
595 , const std::string &/*reason*/
599 // progress for rebuilding the database
600 struct RebuildDBReport : public callback::ReportBase
603 ABORT, // abort and return error
605 IGNORE // ignore the failure
610 FAILED // failed to rebuild
613 virtual void start(Pathname /*path*/) {}
615 virtual bool progress(int /*value*/, Pathname /*path*/)
618 virtual Action problem(
621 , const std::string &/*description*/
627 , const std::string &/*reason*/
631 // progress for converting the database
632 struct ConvertDBReport : public callback::ReportBase
635 ABORT, // abort and return error
637 IGNORE // ignore the failure
642 FAILED // conversion failed
649 virtual bool progress(int /*value*/, Pathname /*path*/)
652 virtual Action problem(
655 , const std::string &/*description*/
661 , const std::string &/*reason*/
665 /////////////////////////////////////////////////////////////////
667 ///////////////////////////////////////////////////////////////////
669 /////////////////////////////////////////////////////////////////
670 } // namespace target
671 ///////////////////////////////////////////////////////////////////
678 * Callback for cleaning locks which doesn't lock anything in pool.
681 struct CleanEmptyLocksReport : public callback::ReportBase
684 * action performed by cleaning api to specific lock
687 ABORT, /**< abort and return error */
688 DELETE, /**< delete empty lock */
689 IGNORE /**< skip empty lock */
696 NO_ERROR, /**< no problem */
697 ABORTED /** cleaning aborted by user */
701 * cleaning is started
707 * progress of cleaning specifies in percents
708 * \return if continue
710 virtual bool progress(int /*value*/)
714 * When find empty lock ask what to do with it
717 virtual Action execute(
718 const PoolQuery& /*error*/
731 * this callback handles merging old locks with newly added or removed
733 struct SavingLocksReport : public callback::ReportBase
736 * action for old lock which is in conflict
740 ABORT, /**< abort and return error*/
741 DELETE, /**< delete conflicted lock */
742 IGNORE /**< skip conflict lock */
749 NO_ERROR, /**< no problem */
750 ABORTED /**< cleaning aborted by user */
754 * type of conflict of old and new lock
757 SAME_RESULTS, /**< locks lock same item in pool but his parameters is different */
758 INTERSECT /**< locks lock some file and unlocking lock unlock only part
759 * of iti, so removing old lock can unlock more items in pool */
762 virtual void start() {}
766 * \return if continue
768 virtual bool progress()
772 * When user unlock something which is locked by non-identical query
774 virtual Action conflict(
775 const PoolQuery&, /**< problematic query*/
784 ///////////////////////////////////////////////////////////////////
786 /// \brief Generic report for sending messages.
787 ///////////////////////////////////////////////////////////////////
788 struct JobReport : public callback::ReportBase
791 /** message type (use like 'enum class \ref MsgType') */
793 enum Enum { debug, info, warning, error, important, data };
795 typedef base::EnumClass<EMsgTypeDef> MsgType; ///< 'enum class MsgType'
797 /** typsafe map of userdata */
798 typedef callback::UserData UserData;
801 /** Send a ready to show message text. */
802 virtual bool message( MsgType type_r, const std::string & msg_r, const UserData & userData_r ) const
806 /** \name Static sender instance */
808 /** Singleton sender instance */
809 static callback::SendReport<JobReport> & instance(); // impl in ZYppImpl.cc
811 /** send debug message text */
812 static bool debug( const std::string & msg_r, const UserData & userData_r = UserData() )
813 { return instance()->message( MsgType::debug, msg_r, userData_r ); }
815 /** send message text */
816 static bool info( const std::string & msg_r, const UserData & userData_r = UserData() )
817 { return instance()->message( MsgType::info, msg_r, userData_r ); }
819 /** send warning text */
820 static bool warning( const std::string & msg_r, const UserData & userData_r = UserData() )
821 { return instance()->message( MsgType::warning, msg_r, userData_r ); }
823 /** send error text */
824 static bool error( const std::string & msg_r, const UserData & userData_r = UserData() )
825 { return instance()->message( MsgType::error, msg_r, userData_r ); }
827 /** send important message text */
828 static bool important( const std::string & msg_r, const UserData & userData_r = UserData() )
829 { return instance()->message( MsgType::important, msg_r, userData_r ); }
831 /** send data message */
832 static bool data( const std::string & msg_r, const UserData & userData_r = UserData() )
833 { return instance()->message( MsgType::data, msg_r, userData_r ); }
838 /////////////////////////////////////////////////////////////////
840 ///////////////////////////////////////////////////////////////////
842 #endif // ZYPP_ZYPPCALLBACKS_H