1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ZYppCallbacks.h
12 #ifndef ZYPP_ZYPPCALLBACKS_H
13 #define ZYPP_ZYPPCALLBACKS_H
15 #include "zypp/Callback.h"
16 #include "zypp/Resolvable.h"
17 #include "zypp/RepoInfo.h"
18 #include "zypp/Pathname.h"
19 #include "zypp/Message.h"
21 #include "zypp/ProgressData.h"
22 #include "zypp/media/MediaUserAuth.h"
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
28 struct ProgressReport : public callback::ReportBase
30 virtual void start( const ProgressData &/*task*/ )
33 virtual bool progress( const ProgressData &/*task*/ )
36 // virtual Action problem(
39 // , const std::string &/*description*/ )
42 virtual void finish( const ProgressData &/*task*/ )
47 struct ProgressReportAdaptor
50 ProgressReportAdaptor( const ProgressData::ReceiverFnc &fnc,
51 callback::SendReport<ProgressReport> &report )
58 bool operator()( const ProgressData &progress )
62 _report->start(progress);
66 _report->progress(progress);
69 value = _fnc(progress);
72 if ( progress.finalReport() )
74 _report->finish(progress);
79 ProgressData::ReceiverFnc _fnc;
80 callback::SendReport<ProgressReport> &_report;
84 ////////////////////////////////////////////////////////////////////////////
88 // progress for downloading a resolvable
89 struct DownloadResolvableReport : public callback::ReportBase
92 ABORT, // abort and return error
94 IGNORE, // ignore this resolvable but continue
99 NOT_FOUND, // the requested Url was not found
101 INVALID // the downloaded file is invalid
105 Resolvable::constPtr /*resolvable_ptr*/
110 // Dowmload delta rpm:
111 // - path below url reported on start()
112 // - expected download size (0 if unknown)
113 // - download is interruptable
114 // - problems are just informal
115 virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
118 virtual bool progressDeltaDownload( int /*value*/ )
121 virtual void problemDeltaDownload( const std::string &/*description*/ )
124 virtual void finishDeltaDownload()
128 // - local path of downloaded delta
129 // - aplpy is not interruptable
130 // - problems are just informal
131 virtual void startDeltaApply( const Pathname & /*filename*/ )
134 virtual void progressDeltaApply( int /*value*/ )
137 virtual void problemDeltaApply( const std::string &/*description*/ )
140 virtual void finishDeltaApply()
143 // Dowmload patch rpm:
144 // - path below url reported on start()
145 // - expected download size (0 if unknown)
146 // - download is interruptable
147 virtual void startPatchDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
150 virtual bool progressPatchDownload( int /*value*/ )
153 virtual void problemPatchDownload( const std::string &/*description*/ )
156 virtual void finishPatchDownload()
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*/
170 virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
172 , const std::string &/*reason*/
176 // progress for probing a source
177 struct ProbeRepoReport : public callback::ReportBase
180 ABORT, // abort and return error
186 NOT_FOUND, // the requested Url was not found
188 INVALID, // th source is invalid
192 virtual void start(const Url &/*url*/) {}
193 virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
194 virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
195 virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
197 virtual bool progress(const Url &/*url*/, int /*value*/)
200 virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
203 struct RepoCreateReport : public callback::ReportBase
206 ABORT, // abort and return error
208 IGNORE // skip refresh, ignore failed refresh
213 NOT_FOUND, // the requested Url was not found
216 INVALID, // th source is invali
220 virtual void start( const zypp::Url &/*url*/ ) {}
221 virtual bool progress( int /*value*/ )
224 virtual Action problem(
225 const zypp::Url &/*url*/
227 , const std::string &/*description*/ )
231 const zypp::Url &/*url*/
233 , const std::string &/*reason*/ )
237 struct RepoReport : public callback::ReportBase
240 ABORT, // abort and return error
242 IGNORE // skip refresh, ignore failed refresh
247 NOT_FOUND, // the requested Url was not found
249 INVALID // th source is invalid
252 virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/ ) {}
253 virtual bool progress( const ProgressData &/*task*/ )
256 virtual Action problem(
257 Repository /*source*/
259 , const std::string &/*description*/ )
263 Repository /*source*/
264 , const std::string &/*task*/
266 , const std::string &/*reason*/ )
271 /////////////////////////////////////////////////////////////////
272 } // namespace source
273 ///////////////////////////////////////////////////////////////////
275 ///////////////////////////////////////////////////////////////////
278 // media change request callback
279 struct MediaChangeReport : public callback::ReportBase
282 ABORT, // abort and return error
284 IGNORE, // ignore this media in future, not available anymore
285 IGNORE_ID, // ignore wrong medium id
286 CHANGE_URL, // change media URL
287 EJECT // eject the medium
292 NOT_FOUND, // the medie not found at all
293 IO, // error accessing the media
294 INVALID, // media is broken
295 WRONG, // wrong media, need a different one
296 IO_SOFT /**< IO error which can happen on worse connection like timeout exceed */
301 * \param url in: url for which the media is requested,
302 * out: url to use instead of the original one
303 * \param mediumNr requested medium number
304 * \param label label of requested medium
305 * \param error type of error from \ref Error enum
306 * \param description error message (media not desired or error foo occured)
307 * \param devices list of the available devices (for eject)
308 * \param dev_current in: index of the currently used device in the \a devices list
309 * out: index of the devices to be ejected in the \a devices list
310 * \return \ref Action (ABORT by default)
312 virtual Action requestMedia(
313 Url & /* url (I/O parameter) */
314 , unsigned /*mediumNr*/
315 , const std::string & /* label */
317 , const std::string & /*description*/
318 , const std::vector<std::string> & /* devices */
319 , unsigned int & /* dev_current (I/O param) */
323 // progress for downloading a file
324 struct DownloadProgressReport : public callback::ReportBase
327 ABORT, // abort and return error
329 IGNORE // ignore the failure
334 NOT_FOUND, // the requested Url was not found
336 ACCESS_DENIED, // user authent. failed while accessing restricted file
340 virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
345 * \param value Percentage value.
346 * \param file File URI.
347 * \param dbps_avg Average download rate so far. -1 if unknown.
348 * \param dbps_current Current download (cca last 1 sec). -1 if unknown.
350 virtual bool progress(int /*value*/, const Url &/*file*/,
351 double dbps_avg = -1,
352 double dbps_current = -1)
355 virtual Action problem(
358 , const std::string &/*description*/
364 , const std::string &/*reason*/
368 // authentication issues report
369 struct AuthenticationReport : public callback::ReportBase
372 * Prompt for authentication data.
374 * \param url URL which required the authentication
375 * \param msg prompt text
376 * \param auth_data input/output object for handling authentication
377 * data. As an input parameter auth_data can be prefilled with
378 * username (from previous try) or auth_type (available
379 * authentication methods aquired from server (only CurlAuthData)).
380 * As an output parameter it serves for sending username, pasword
381 * or other special data (derived AuthData objects).
382 * \return true if user chooses to continue with authentication,
385 virtual bool prompt(const Url & /* url */,
386 const std::string & /* msg */,
387 AuthData & /* auth_data */)
393 /////////////////////////////////////////////////////////////////
395 ///////////////////////////////////////////////////////////////////
397 ///////////////////////////////////////////////////////////////////
401 // resolvable Message
402 struct MessageResolvableReport : public callback::ReportBase
405 Message::constPtr /*message*/
410 struct ScriptResolvableReport : public callback::ReportBase
412 enum Task { DO, UNDO };
413 enum Notify { OUTPUT, PING };
415 /** Whether executing do_script on install or undo_script on delete. */
416 virtual void start( const Resolvable::constPtr & /*script_r*/,
417 const Pathname & /*path_r*/,
420 /** Progress provides the script output. If the script is quiet,
421 * from time to time still-alive pings are sent to the ui. Returning \c FALSE
422 * aborts script execution.
424 virtual bool progress( Notify , const std::string & = std::string() )
427 virtual void problem( const std::string & /*description*/ )
429 /** Report success. */
430 virtual void finish()
434 ///////////////////////////////////////////////////////////////////
438 // progress for installing a resolvable
439 struct InstallResolvableReport : public callback::ReportBase
442 ABORT, // abort and return error
444 IGNORE // ignore the failure
449 NOT_FOUND, // the requested Url was not found
451 INVALID // th resolvable is invalid
454 // the level of RPM pushing
455 /** \deprecated We fortunately no longer do 3 attempts. */
463 Resolvable::constPtr /*resolvable*/
466 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
469 virtual Action problem(
470 Resolvable::constPtr /*resolvable*/
472 , const std::string &/*description*/
477 Resolvable::constPtr /*resolvable*/
479 , const std::string &/*reason*/
484 // progress for removing a resolvable
485 struct RemoveResolvableReport : public callback::ReportBase
488 ABORT, // abort and return error
490 IGNORE // ignore the failure
495 NOT_FOUND, // the requested Url was not found
497 INVALID // th resolvable is invalid
501 Resolvable::constPtr /*resolvable*/
504 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
507 virtual Action problem(
508 Resolvable::constPtr /*resolvable*/
510 , const std::string &/*description*/
514 Resolvable::constPtr /*resolvable*/
516 , const std::string &/*reason*/
520 // progress for rebuilding the database
521 struct RebuildDBReport : public callback::ReportBase
524 ABORT, // abort and return error
526 IGNORE // ignore the failure
531 FAILED // failed to rebuild
534 virtual void start(Pathname /*path*/) {}
536 virtual bool progress(int /*value*/, Pathname /*path*/)
539 virtual Action problem(
542 , const std::string &/*description*/
548 , const std::string &/*reason*/
552 // progress for converting the database
553 struct ConvertDBReport : public callback::ReportBase
556 ABORT, // abort and return error
558 IGNORE // ignore the failure
563 FAILED // conversion failed
570 virtual bool progress(int /*value*/, Pathname /*path*/)
573 virtual Action problem(
576 , const std::string &/*description*/
582 , const std::string &/*reason*/
586 // progress for scanning the database
587 struct ScanDBReport : public callback::ReportBase
590 ABORT, // abort and return error
592 IGNORE // ignore the failure
597 FAILED // conversion failed
603 virtual bool progress(int /*value*/)
606 virtual Action problem(
608 , const std::string &/*description*/
613 , const std::string &/*reason*/
617 /////////////////////////////////////////////////////////////////
619 ///////////////////////////////////////////////////////////////////
621 /////////////////////////////////////////////////////////////////
622 } // namespace target
623 ///////////////////////////////////////////////////////////////////
626 ///////////////////////////////////////////////////////////////////
629 struct CleanEmptyLocksReport : public callback::ReportBase
632 ABORT, // abort and return error
633 DELETE, // delete empty lock
634 IGNORE // skip empty lock
639 ABORTED // cleaning aborted
645 virtual bool progress(int /*value*/)
649 * When find empty lock ask what to do with it
651 virtual Action execute(
652 const PoolQuery& /*error*/
661 struct SavingLocksReport : public callback::ReportBase
664 ABORT, // abort and return error
665 DELETE, // delete conflicted lock
666 IGNORE // skip conflict lock
671 ABORTED // cleaning aborted
679 virtual void start() {}
681 virtual bool progress() /*still alive*/
685 * When user unlock something which is locked by non-identical query
687 virtual Action conflict(
688 const PoolQuery&, /*problematic query*/
697 /////////////////////////////////////////////////////////////////
699 ///////////////////////////////////////////////////////////////////
702 /////////////////////////////////////////////////////////////////
704 ///////////////////////////////////////////////////////////////////
706 #endif // ZYPP_ZYPPCALLBACKS_H