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/Repository.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(
37 // Repository /*source*/
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);
71 if ( progress.val() == progress.max() )
73 _report->finish(progress);
78 ProgressData::ReceiverFnc _fnc;
79 callback::SendReport<ProgressReport> &_report;
83 ////////////////////////////////////////////////////////////////////////////
87 // progress for downloading a resolvable
88 struct DownloadResolvableReport : public callback::ReportBase
91 ABORT, // abort and return error
93 IGNORE, // ignore this resolvable but continue
98 NOT_FOUND, // the requested Url was not found
100 INVALID // the downloaded file is invalid
104 Resolvable::constPtr /*resolvable_ptr*/
109 // Dowmload delta rpm:
110 // - path below url reported on start()
111 // - expected download size (0 if unknown)
112 // - download is interruptable
113 // - problems are just informal
114 virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
117 virtual bool progressDeltaDownload( int /*value*/ )
120 virtual void problemDeltaDownload( const std::string &/*description*/ )
123 virtual void finishDeltaDownload()
127 // - local path of downloaded delta
128 // - aplpy is not interruptable
129 // - problems are just informal
130 virtual void startDeltaApply( const Pathname & /*filename*/ )
133 virtual void progressDeltaApply( int /*value*/ )
136 virtual void problemDeltaApply( const std::string &/*description*/ )
139 virtual void finishDeltaApply()
142 // Dowmload patch rpm:
143 // - path below url reported on start()
144 // - expected download size (0 if unknown)
145 // - download is interruptable
146 virtual void startPatchDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
149 virtual bool progressPatchDownload( int /*value*/ )
152 virtual void problemPatchDownload( const std::string &/*description*/ )
155 virtual void finishPatchDownload()
159 // return false if the download should be aborted right now
160 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
163 virtual Action problem(
164 Resolvable::constPtr /*resolvable_ptr*/
166 , const std::string &/*description*/
169 virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
171 , const std::string &/*reason*/
175 // progress for probing a source
176 struct ProbeRepoReport : public callback::ReportBase
179 ABORT, // abort and return error
185 NOT_FOUND, // the requested Url was not found
187 INVALID, // th source is invalid
191 virtual void start(const Url &/*url*/) {}
192 virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
193 virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
194 virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
196 virtual bool progress(const Url &/*url*/, int /*value*/)
199 virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
202 struct RepoCreateReport : public callback::ReportBase
205 ABORT, // abort and return error
207 IGNORE // skip refresh, ignore failed refresh
212 NOT_FOUND, // the requested Url was not found
215 INVALID, // th source is invali
219 virtual void start( const zypp::Url &/*url*/ ) {}
220 virtual bool progress( int /*value*/ )
223 virtual Action problem(
224 const zypp::Url &/*url*/
226 , const std::string &/*description*/ )
230 const zypp::Url &/*url*/
232 , const std::string &/*reason*/ )
236 struct RepoReport : 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
248 INVALID // th source is invalid
251 virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/ ) {}
252 virtual bool progress( const ProgressData &/*task*/ )
255 virtual Action problem(
256 Repository /*source*/
258 , const std::string &/*description*/ )
262 Repository /*source*/
263 , const std::string &/*task*/
265 , const std::string &/*reason*/ )
270 /////////////////////////////////////////////////////////////////
271 } // namespace source
272 ///////////////////////////////////////////////////////////////////
274 ///////////////////////////////////////////////////////////////////
277 // media change request callback
278 struct MediaChangeReport : public callback::ReportBase
281 ABORT, // abort and return error
283 IGNORE, // ignore this media in future, not available anymore
284 IGNORE_ID, // ignore wrong medium id
285 CHANGE_URL, // change media URL
286 EJECT // eject the medium
291 NOT_FOUND, // the medie not found at all
292 IO, // error accessing the media
293 INVALID, // media is broken
294 WRONG // wrong media, need a different one
297 virtual Action requestMedia(
298 Repository /*source*/
299 , unsigned /*mediumNr*/
301 , const std::string &/*description*/
305 // progress for downloading a file
306 struct DownloadProgressReport : public callback::ReportBase
309 ABORT, // abort and return error
311 IGNORE // ignore the failure
316 NOT_FOUND, // the requested Url was not found
318 ACCESS_DENIED // user authent. failed while accessing restricted file
321 virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
323 virtual bool progress(int /*value*/, const Url &/*file*/)
326 virtual Action problem(
329 , const std::string &/*description*/
335 , const std::string &/*reason*/
339 // authentication issues report
340 struct AuthenticationReport : public callback::ReportBase
343 * Prompt for authentication data.
345 * \param url URL which required the authentication
346 * \param msg prompt text
347 * \param auth_data input/output object for handling authentication
348 * data. As an input parameter auth_data can be prefilled with
349 * username (from previous try) or auth_type (available
350 * authentication methods aquired from server (only CurlAuthData)).
351 * As an output parameter it serves for sending username, pasword
352 * or other special data (derived AuthData objects).
353 * \return true if user chooses to continue with authentication,
356 virtual bool prompt(const Url & /* url */,
357 const std::string & /* msg */,
358 AuthData & /* auth_data */)
364 /////////////////////////////////////////////////////////////////
366 ///////////////////////////////////////////////////////////////////
368 ///////////////////////////////////////////////////////////////////
372 // resolvable Message
373 struct MessageResolvableReport : public callback::ReportBase
376 Message::constPtr /*message*/
381 struct ScriptResolvableReport : public callback::ReportBase
383 enum Task { DO, UNDO };
384 enum Notify { OUTPUT, PING };
386 /** Whether executing do_script on install or undo_script on delete. */
387 virtual void start( const Resolvable::constPtr & /*script_r*/,
388 const Pathname & /*path_r*/,
391 /** Progress provides the script output. If the script is quiet,
392 * from time to time still-alive pings are sent to the ui. Returning \c FALSE
393 * aborts script execution.
395 virtual bool progress( Notify , const std::string & = std::string() )
398 virtual void problem( const std::string & /*description*/ )
400 /** Report success. */
401 virtual void finish()
405 ///////////////////////////////////////////////////////////////////
409 // progress for installing a resolvable
410 struct InstallResolvableReport : public callback::ReportBase
413 ABORT, // abort and return error
415 IGNORE // ignore the failure
420 NOT_FOUND, // the requested Url was not found
422 INVALID // th resolvable is invalid
425 // the level of RPM pushing
433 Resolvable::constPtr /*resolvable*/
436 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
439 virtual Action problem(
440 Resolvable::constPtr /*resolvable*/
442 , const std::string &/*description*/
447 Resolvable::constPtr /*resolvable*/
449 , const std::string &/*reason*/
454 // progress for removing a resolvable
455 struct RemoveResolvableReport : public callback::ReportBase
458 ABORT, // abort and return error
460 IGNORE // ignore the failure
465 NOT_FOUND, // the requested Url was not found
467 INVALID // th resolvable is invalid
471 Resolvable::constPtr /*resolvable*/
474 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
477 virtual Action problem(
478 Resolvable::constPtr /*resolvable*/
480 , const std::string &/*description*/
484 Resolvable::constPtr /*resolvable*/
486 , const std::string &/*reason*/
490 // progress for rebuilding the database
491 struct RebuildDBReport : public callback::ReportBase
494 ABORT, // abort and return error
496 IGNORE // ignore the failure
501 FAILED // failed to rebuild
504 virtual void start(Pathname /*path*/) {}
506 virtual bool progress(int /*value*/, Pathname /*path*/)
509 virtual Action problem(
512 , const std::string &/*description*/
518 , const std::string &/*reason*/
522 // progress for converting the database
523 struct ConvertDBReport : public callback::ReportBase
526 ABORT, // abort and return error
528 IGNORE // ignore the failure
533 FAILED // conversion failed
540 virtual bool progress(int /*value*/, Pathname /*path*/)
543 virtual Action problem(
546 , const std::string &/*description*/
552 , const std::string &/*reason*/
556 // progress for scanning the database
557 struct ScanDBReport : public callback::ReportBase
560 ABORT, // abort and return error
562 IGNORE // ignore the failure
567 FAILED // conversion failed
573 virtual bool progress(int /*value*/)
576 virtual Action problem(
578 , const std::string &/*description*/
583 , const std::string &/*reason*/
587 /////////////////////////////////////////////////////////////////
589 ///////////////////////////////////////////////////////////////////
591 /////////////////////////////////////////////////////////////////
592 } // namespace target
593 ///////////////////////////////////////////////////////////////////
595 /////////////////////////////////////////////////////////////////
597 ///////////////////////////////////////////////////////////////////
599 #endif // ZYPP_ZYPPCALLBACKS_H