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 "Package" Package::constPtr of the package
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.
200 virtual void pkgGpgCheck( const UserData & userData_r = UserData() )
203 virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
205 , const std::string &/*reason*/
209 // progress for probing a source
210 struct ProbeRepoReport : public callback::ReportBase
213 ABORT, // abort and return error
219 NOT_FOUND, // the requested Url was not found
221 INVALID, // th source is invalid
225 virtual void start(const Url &/*url*/) {}
226 virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
227 virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
228 virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
230 virtual bool progress(const Url &/*url*/, int /*value*/)
233 virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
236 struct RepoCreateReport : public callback::ReportBase
239 ABORT, // abort and return error
241 IGNORE // skip refresh, ignore failed refresh
246 NOT_FOUND, // the requested Url was not found
249 INVALID, // th source is invali
253 virtual void start( const zypp::Url &/*url*/ ) {}
254 virtual bool progress( int /*value*/ )
257 virtual Action problem(
258 const zypp::Url &/*url*/
260 , const std::string &/*description*/ )
264 const zypp::Url &/*url*/
266 , const std::string &/*reason*/ )
270 struct RepoReport : public callback::ReportBase
273 ABORT, // abort and return error
275 IGNORE // skip refresh, ignore failed refresh
280 NOT_FOUND, // the requested Url was not found
282 INVALID // th source is invalid
285 virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/ ) {}
286 virtual bool progress( const ProgressData &/*task*/ )
289 virtual Action problem(
290 Repository /*source*/
292 , const std::string &/*description*/ )
296 Repository /*source*/
297 , const std::string &/*task*/
299 , const std::string &/*reason*/ )
304 /////////////////////////////////////////////////////////////////
305 } // namespace source
306 ///////////////////////////////////////////////////////////////////
308 ///////////////////////////////////////////////////////////////////
311 // media change request callback
312 struct MediaChangeReport : public callback::ReportBase
315 ABORT, // abort and return error
317 IGNORE, // ignore this media in future, not available anymore
318 IGNORE_ID, // ignore wrong medium id
319 CHANGE_URL, // change media URL
320 EJECT // eject the medium
325 NOT_FOUND, // the medie not found at all
326 IO, // error accessing the media
327 INVALID, // media is broken
328 WRONG, // wrong media, need a different one
329 IO_SOFT /**< IO error which can happen on worse connection like timeout exceed */
334 * \param url in: url for which the media is requested,
335 * out: url to use instead of the original one
336 * \param mediumNr requested medium number
337 * \param label label of requested medium
338 * \param error type of error from \ref Error enum
339 * \param description error message (media not desired or error foo occured)
340 * \param devices list of the available devices (for eject)
341 * \param dev_current in: index of the currently used device in the \a devices list
342 * out: index of the devices to be ejected in the \a devices list
343 * \return \ref Action (ABORT by default)
345 virtual Action requestMedia(
346 Url & /* url (I/O parameter) */
347 , unsigned /*mediumNr*/
348 , const std::string & /* label */
350 , const std::string & /*description*/
351 , const std::vector<std::string> & /* devices */
352 , unsigned int & /* dev_current (I/O param) */
356 ///////////////////////////////////////////////////////////////////
357 /// \class ScopedDisableMediaChangeReport
358 /// \brief Temporarily disable MediaChangeReport
359 /// Sometimes helpful to suppress interactive messages connected to
360 /// MediaChangeReport while fallback URLs are avaialble.
361 struct ScopedDisableMediaChangeReport
363 /** Disbale MediaChangeReport if \a condition_r is \c true.*/
364 ScopedDisableMediaChangeReport( bool condition_r = true );
366 shared_ptr<callback::TempConnect<media::MediaChangeReport> > _guard;
369 // progress for downloading a file
370 struct DownloadProgressReport : public callback::ReportBase
373 ABORT, // abort and return error
375 IGNORE // ignore the failure
380 NOT_FOUND, // the requested Url was not found
382 ACCESS_DENIED, // user authent. failed while accessing restricted file
386 virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
391 * \param value Percentage value.
392 * \param file File URI.
393 * \param dbps_avg Average download rate so far. -1 if unknown.
394 * \param dbps_current Current download (cca last 1 sec). -1 if unknown.
396 virtual bool progress(int /*value*/, const Url &/*file*/,
397 double dbps_avg = -1,
398 double dbps_current = -1)
401 virtual Action problem(
404 , const std::string &/*description*/
410 , const std::string &/*reason*/
414 // authentication issues report
415 struct AuthenticationReport : public callback::ReportBase
418 * Prompt for authentication data.
420 * \param url URL which required the authentication
421 * \param msg prompt text
422 * \param auth_data input/output object for handling authentication
423 * data. As an input parameter auth_data can be prefilled with
424 * username (from previous try) or auth_type (available
425 * authentication methods aquired from server (only CurlAuthData)).
426 * As an output parameter it serves for sending username, pasword
427 * or other special data (derived AuthData objects).
428 * \return true if user chooses to continue with authentication,
431 virtual bool prompt(const Url & /* url */,
432 const std::string & /* msg */,
433 AuthData & /* auth_data */)
439 /////////////////////////////////////////////////////////////////
441 ///////////////////////////////////////////////////////////////////
443 ///////////////////////////////////////////////////////////////////
446 /** Request to display the pre commit message of a patch. */
447 struct PatchMessageReport : public callback::ReportBase
449 /** Display \c patch->message().
450 * Return \c true to continue, \c false to abort commit.
452 virtual bool show( Patch::constPtr & /*patch*/ )
456 /** Indicate execution of a patch script. This is a sort of
457 * \c %post script shipped by a package and to be executed
458 * after the package was installed.
460 struct PatchScriptReport : public callback::ReportBase
462 enum Notify { OUTPUT, PING };
464 ABORT, // abort commit and return error
465 RETRY, // (re)try to execute this script
466 IGNORE // ignore any failue and continue
469 /** Start executing the script provided by package.
471 virtual void start( const Package::constPtr & /*package*/,
472 const Pathname & /*script path*/ )
474 /** Progress provides the script output. If the script is quiet,
475 * from time to time still-alive pings are sent to the ui. Returning \c FALSE
476 * aborts script execution.
478 virtual bool progress( Notify /*OUTPUT or PING*/,
479 const std::string & /*output*/ = std::string() )
482 virtual Action problem( const std::string & /*description*/ )
484 /** Report success. */
485 virtual void finish()
489 ///////////////////////////////////////////////////////////////////
490 /// \class FindFileConflictstReport
491 /// \brief Check for package file conflicts in commit (after download)
493 /// File conflict check requires that all packages are downloaded and
494 /// now available in the cache (need to access the filelists). Missing
495 /// packages are omitted from check and their number is reported in
496 /// \a noFilelist_r. This usually happens if download mode 'as-needed'
498 ///////////////////////////////////////////////////////////////////
499 struct FindFileConflictstReport : public callback::ReportBase
502 * \param progress_r Progress counter for packages to check.
503 * \return \c true to continue, \c false upon user abort request.
505 virtual bool start( const ProgressData & progress_r )
509 * \param progress_r Progress counter for packages to check.
510 * \param noFilelist_r Queue of so far skipped solvables (no filelist/not yet downloaded).
511 * \return \c true to continue, \c false upon user abort request.
513 virtual bool progress( const ProgressData & progress_r, const sat::Queue & noFilelist_r )
517 * \param progress_r Progress counter for packages to check.
518 * \param noFilelist_r Queue of skipped solvables (no filelist/not yet downloaded).
519 * \param conflicts_r File conflits queue.
520 * \return \c true to continue, \c false upon user abort request.
522 virtual bool result( const ProgressData & progress_r, const sat::Queue & noFilelist_r, const sat::FileConflicts & conflicts_r )
527 ///////////////////////////////////////////////////////////////////
531 // progress for installing a resolvable
532 struct InstallResolvableReport : public callback::ReportBase
535 ABORT, // abort and return error
537 IGNORE // ignore the failure
542 NOT_FOUND, // the requested Url was not found
544 INVALID // th resolvable is invalid
547 // the level of RPM pushing
548 /** \deprecated We fortunately no longer do 3 attempts. */
552 RPM_NODEPS_FORCE //!< only this one used
556 Resolvable::constPtr /*resolvable*/
559 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
562 virtual Action problem(
563 Resolvable::constPtr /*resolvable*/
565 , const std::string &/*description*/
570 Resolvable::constPtr /*resolvable*/
572 , const std::string &/*reason*/
577 // progress for removing a resolvable
578 struct RemoveResolvableReport : public callback::ReportBase
581 ABORT, // abort and return error
583 IGNORE // ignore the failure
588 NOT_FOUND, // the requested Url was not found
590 INVALID // th resolvable is invalid
594 Resolvable::constPtr /*resolvable*/
597 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
600 virtual Action problem(
601 Resolvable::constPtr /*resolvable*/
603 , const std::string &/*description*/
607 Resolvable::constPtr /*resolvable*/
609 , const std::string &/*reason*/
613 // progress for rebuilding the database
614 struct RebuildDBReport : public callback::ReportBase
617 ABORT, // abort and return error
619 IGNORE // ignore the failure
624 FAILED // failed to rebuild
627 virtual void start(Pathname /*path*/) {}
629 virtual bool progress(int /*value*/, Pathname /*path*/)
632 virtual Action problem(
635 , const std::string &/*description*/
641 , const std::string &/*reason*/
645 // progress for converting the database
646 struct ConvertDBReport : public callback::ReportBase
649 ABORT, // abort and return error
651 IGNORE // ignore the failure
656 FAILED // conversion failed
663 virtual bool progress(int /*value*/, Pathname /*path*/)
666 virtual Action problem(
669 , const std::string &/*description*/
675 , const std::string &/*reason*/
679 /////////////////////////////////////////////////////////////////
681 ///////////////////////////////////////////////////////////////////
683 /////////////////////////////////////////////////////////////////
684 } // namespace target
685 ///////////////////////////////////////////////////////////////////
692 * Callback for cleaning locks which doesn't lock anything in pool.
695 struct CleanEmptyLocksReport : public callback::ReportBase
698 * action performed by cleaning api to specific lock
701 ABORT, /**< abort and return error */
702 DELETE, /**< delete empty lock */
703 IGNORE /**< skip empty lock */
710 NO_ERROR, /**< no problem */
711 ABORTED /** cleaning aborted by user */
715 * cleaning is started
721 * progress of cleaning specifies in percents
722 * \return if continue
724 virtual bool progress(int /*value*/)
728 * When find empty lock ask what to do with it
731 virtual Action execute(
732 const PoolQuery& /*error*/
745 * this callback handles merging old locks with newly added or removed
747 struct SavingLocksReport : public callback::ReportBase
750 * action for old lock which is in conflict
754 ABORT, /**< abort and return error*/
755 DELETE, /**< delete conflicted lock */
756 IGNORE /**< skip conflict lock */
763 NO_ERROR, /**< no problem */
764 ABORTED /**< cleaning aborted by user */
768 * type of conflict of old and new lock
771 SAME_RESULTS, /**< locks lock same item in pool but his parameters is different */
772 INTERSECT /**< locks lock some file and unlocking lock unlock only part
773 * of iti, so removing old lock can unlock more items in pool */
776 virtual void start() {}
780 * \return if continue
782 virtual bool progress()
786 * When user unlock something which is locked by non-identical query
788 virtual Action conflict(
789 const PoolQuery&, /**< problematic query*/
798 ///////////////////////////////////////////////////////////////////
800 /// \brief Generic report for sending messages.
801 ///////////////////////////////////////////////////////////////////
802 struct JobReport : public callback::ReportBase
805 /** message type (use like 'enum class \ref MsgType') */
807 enum Enum { debug, info, warning, error, important, data };
809 typedef base::EnumClass<_MsgTypeDef> MsgType; ///< 'enum class MsgType'
811 /** typsafe map of userdata */
812 typedef callback::UserData UserData;
815 /** Send a ready to show message text. */
816 virtual bool message( MsgType type_r, const std::string & msg_r, const UserData & userData_r ) const
820 /** \name Static sender instance */
822 /** Singleton sender instance */
823 static callback::SendReport<JobReport> & instance(); // impl in ZYppImpl.cc
825 /** send debug message text */
826 static bool debug( const MessageString & msg_r, const UserData & userData_r = UserData() )
827 { return instance()->message( MsgType::debug, msg_r, userData_r ); }
829 /** send message text */
830 static bool info( const MessageString & msg_r, const UserData & userData_r = UserData() )
831 { return instance()->message( MsgType::info, msg_r, userData_r ); }
833 /** send warning text */
834 static bool warning( const MessageString & msg_r, const UserData & userData_r = UserData() )
835 { return instance()->message( MsgType::warning, msg_r, userData_r ); }
837 /** send error text */
838 static bool error( const MessageString & msg_r, const UserData & userData_r = UserData() )
839 { return instance()->message( MsgType::error, msg_r, userData_r ); }
841 /** send important message text */
842 static bool important( const MessageString & msg_r, const UserData & userData_r = UserData() )
843 { return instance()->message( MsgType::important, msg_r, userData_r ); }
845 /** send data message */
846 static bool data( const MessageString & msg_r, const UserData & userData_r = UserData() )
847 { return instance()->message( MsgType::data, msg_r, userData_r ); }
852 /////////////////////////////////////////////////////////////////
854 ///////////////////////////////////////////////////////////////////
856 #endif // ZYPP_ZYPPCALLBACKS_H