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 "Package" Package::constPtr of the package
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.
183 virtual void pkgGpgCheck( const UserData & userData_r = UserData() )
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 ///////////////////////////////////////////////////////////////////
340 /// \class ScopedDisableMediaChangeReport
341 /// \brief Temporarily disable MediaChangeReport
342 /// Sometimes helpful to suppress interactive messages connected to
343 /// MediaChangeReport while fallback URLs are avaialble.
344 struct ScopedDisableMediaChangeReport
346 /** Disbale MediaChangeReport if \a condition_r is \c true.*/
347 ScopedDisableMediaChangeReport( bool condition_r = true );
349 shared_ptr<callback::TempConnect<media::MediaChangeReport> > _guard;
352 // progress for downloading a file
353 struct DownloadProgressReport : public callback::ReportBase
356 ABORT, // abort and return error
358 IGNORE // ignore the failure
363 NOT_FOUND, // the requested Url was not found
365 ACCESS_DENIED, // user authent. failed while accessing restricted file
369 virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
374 * \param value Percentage value.
375 * \param file File URI.
376 * \param dbps_avg Average download rate so far. -1 if unknown.
377 * \param dbps_current Current download (cca last 1 sec). -1 if unknown.
379 virtual bool progress(int /*value*/, const Url &/*file*/,
380 double dbps_avg = -1,
381 double dbps_current = -1)
384 virtual Action problem(
387 , const std::string &/*description*/
393 , const std::string &/*reason*/
397 // authentication issues report
398 struct AuthenticationReport : public callback::ReportBase
401 * Prompt for authentication data.
403 * \param url URL which required the authentication
404 * \param msg prompt text
405 * \param auth_data input/output object for handling authentication
406 * data. As an input parameter auth_data can be prefilled with
407 * username (from previous try) or auth_type (available
408 * authentication methods aquired from server (only CurlAuthData)).
409 * As an output parameter it serves for sending username, pasword
410 * or other special data (derived AuthData objects).
411 * \return true if user chooses to continue with authentication,
414 virtual bool prompt(const Url & /* url */,
415 const std::string & /* msg */,
416 AuthData & /* auth_data */)
422 /////////////////////////////////////////////////////////////////
424 ///////////////////////////////////////////////////////////////////
426 ///////////////////////////////////////////////////////////////////
429 /** Request to display the pre commit message of a patch. */
430 struct PatchMessageReport : public callback::ReportBase
432 /** Display \c patch->message().
433 * Return \c true to continue, \c false to abort commit.
435 virtual bool show( Patch::constPtr & /*patch*/ )
439 /** Indicate execution of a patch script. This is a sort of
440 * \c %post script shipped by a package and to be executed
441 * after the package was installed.
443 struct PatchScriptReport : public callback::ReportBase
445 enum Notify { OUTPUT, PING };
447 ABORT, // abort commit and return error
448 RETRY, // (re)try to execute this script
449 IGNORE // ignore any failue and continue
452 /** Start executing the script provided by package.
454 virtual void start( const Package::constPtr & /*package*/,
455 const Pathname & /*script path*/ )
457 /** Progress provides the script output. If the script is quiet,
458 * from time to time still-alive pings are sent to the ui. Returning \c FALSE
459 * aborts script execution.
461 virtual bool progress( Notify /*OUTPUT or PING*/,
462 const std::string & /*output*/ = std::string() )
465 virtual Action problem( const std::string & /*description*/ )
467 /** Report success. */
468 virtual void finish()
472 ///////////////////////////////////////////////////////////////////
473 /// \class FindFileConflictstReport
474 /// \brief Check for package file conflicts in commit (after download)
476 /// File conflict check requires that all packages are downloaded and
477 /// now available in the cache (need to access the filelists). Missing
478 /// packages are omitted from check and their number is reported in
479 /// \a noFilelist_r. This usually happens if download mode 'as-needed'
481 ///////////////////////////////////////////////////////////////////
482 struct FindFileConflictstReport : public callback::ReportBase
485 * \param progress_r Progress counter for packages to check.
486 * \return \c true to continue, \c false upon user abort request.
488 virtual bool start( const ProgressData & progress_r )
492 * \param progress_r Progress counter for packages to check.
493 * \param noFilelist_r Queue of so far skipped solvables (no filelist/not yet downloaded).
494 * \return \c true to continue, \c false upon user abort request.
496 virtual bool progress( const ProgressData & progress_r, const sat::Queue & noFilelist_r )
500 * \param progress_r Progress counter for packages to check.
501 * \param noFilelist_r Queue of skipped solvables (no filelist/not yet downloaded).
502 * \param conflicts_r File conflits queue.
503 * \return \c true to continue, \c false upon user abort request.
505 virtual bool result( const ProgressData & progress_r, const sat::Queue & noFilelist_r, const sat::FileConflicts & conflicts_r )
510 ///////////////////////////////////////////////////////////////////
514 // progress for installing a resolvable
515 struct InstallResolvableReport : public callback::ReportBase
518 ABORT, // abort and return error
520 IGNORE // ignore the failure
525 NOT_FOUND, // the requested Url was not found
527 INVALID // th resolvable is invalid
530 // the level of RPM pushing
531 /** \deprecated We fortunately no longer do 3 attempts. */
535 RPM_NODEPS_FORCE //!< only this one used
539 Resolvable::constPtr /*resolvable*/
542 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
545 virtual Action problem(
546 Resolvable::constPtr /*resolvable*/
548 , const std::string &/*description*/
553 Resolvable::constPtr /*resolvable*/
555 , const std::string &/*reason*/
560 // progress for removing a resolvable
561 struct RemoveResolvableReport : public callback::ReportBase
564 ABORT, // abort and return error
566 IGNORE // ignore the failure
571 NOT_FOUND, // the requested Url was not found
573 INVALID // th resolvable is invalid
577 Resolvable::constPtr /*resolvable*/
580 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
583 virtual Action problem(
584 Resolvable::constPtr /*resolvable*/
586 , const std::string &/*description*/
590 Resolvable::constPtr /*resolvable*/
592 , const std::string &/*reason*/
596 // progress for rebuilding the database
597 struct RebuildDBReport : public callback::ReportBase
600 ABORT, // abort and return error
602 IGNORE // ignore the failure
607 FAILED // failed to rebuild
610 virtual void start(Pathname /*path*/) {}
612 virtual bool progress(int /*value*/, Pathname /*path*/)
615 virtual Action problem(
618 , const std::string &/*description*/
624 , const std::string &/*reason*/
628 // progress for converting the database
629 struct ConvertDBReport : public callback::ReportBase
632 ABORT, // abort and return error
634 IGNORE // ignore the failure
639 FAILED // conversion failed
646 virtual bool progress(int /*value*/, Pathname /*path*/)
649 virtual Action problem(
652 , const std::string &/*description*/
658 , const std::string &/*reason*/
662 /////////////////////////////////////////////////////////////////
664 ///////////////////////////////////////////////////////////////////
666 /////////////////////////////////////////////////////////////////
667 } // namespace target
668 ///////////////////////////////////////////////////////////////////
675 * Callback for cleaning locks which doesn't lock anything in pool.
678 struct CleanEmptyLocksReport : public callback::ReportBase
681 * action performed by cleaning api to specific lock
684 ABORT, /**< abort and return error */
685 DELETE, /**< delete empty lock */
686 IGNORE /**< skip empty lock */
693 NO_ERROR, /**< no problem */
694 ABORTED /** cleaning aborted by user */
698 * cleaning is started
704 * progress of cleaning specifies in percents
705 * \return if continue
707 virtual bool progress(int /*value*/)
711 * When find empty lock ask what to do with it
714 virtual Action execute(
715 const PoolQuery& /*error*/
728 * this callback handles merging old locks with newly added or removed
730 struct SavingLocksReport : public callback::ReportBase
733 * action for old lock which is in conflict
737 ABORT, /**< abort and return error*/
738 DELETE, /**< delete conflicted lock */
739 IGNORE /**< skip conflict lock */
746 NO_ERROR, /**< no problem */
747 ABORTED /**< cleaning aborted by user */
751 * type of conflict of old and new lock
754 SAME_RESULTS, /**< locks lock same item in pool but his parameters is different */
755 INTERSECT /**< locks lock some file and unlocking lock unlock only part
756 * of iti, so removing old lock can unlock more items in pool */
759 virtual void start() {}
763 * \return if continue
765 virtual bool progress()
769 * When user unlock something which is locked by non-identical query
771 virtual Action conflict(
772 const PoolQuery&, /**< problematic query*/
781 ///////////////////////////////////////////////////////////////////
783 /// \brief Generic report for sending messages.
784 ///////////////////////////////////////////////////////////////////
785 struct JobReport : public callback::ReportBase
788 /** message type (use like 'enum class \ref MsgType') */
790 enum Enum { debug, info, warning, error, important, data };
792 typedef base::EnumClass<EMsgTypeDef> MsgType; ///< 'enum class MsgType'
794 /** typsafe map of userdata */
795 typedef callback::UserData UserData;
798 /** Send a ready to show message text. */
799 virtual bool message( MsgType type_r, const std::string & msg_r, const UserData & userData_r ) const
803 /** \name Static sender instance */
805 /** Singleton sender instance */
806 static callback::SendReport<JobReport> & instance(); // impl in ZYppImpl.cc
808 /** send debug message text */
809 static bool debug( const std::string & msg_r, const UserData & userData_r = UserData() )
810 { return instance()->message( MsgType::debug, msg_r, userData_r ); }
812 /** send message text */
813 static bool info( const std::string & msg_r, const UserData & userData_r = UserData() )
814 { return instance()->message( MsgType::info, msg_r, userData_r ); }
816 /** send warning text */
817 static bool warning( const std::string & msg_r, const UserData & userData_r = UserData() )
818 { return instance()->message( MsgType::warning, msg_r, userData_r ); }
820 /** send error text */
821 static bool error( const std::string & msg_r, const UserData & userData_r = UserData() )
822 { return instance()->message( MsgType::error, msg_r, userData_r ); }
824 /** send important message text */
825 static bool important( const std::string & msg_r, const UserData & userData_r = UserData() )
826 { return instance()->message( MsgType::important, msg_r, userData_r ); }
828 /** send data message */
829 static bool data( const std::string & msg_r, const UserData & userData_r = UserData() )
830 { return instance()->message( MsgType::data, msg_r, userData_r ); }
835 /////////////////////////////////////////////////////////////////
837 ///////////////////////////////////////////////////////////////////
839 #endif // ZYPP_ZYPPCALLBACKS_H