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);
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
298 virtual Action requestMedia(
299 Repository /*source*/
300 , unsigned /*mediumNr*/
302 , const std::string &/*description*/
306 // progress for downloading a file
307 struct DownloadProgressReport : public callback::ReportBase
310 ABORT, // abort and return error
312 IGNORE // ignore the failure
317 NOT_FOUND, // the requested Url was not found
319 ACCESS_DENIED, // user authent. failed while accessing restricted file
323 virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
325 virtual bool progress(int /*value*/, const Url &/*file*/)
328 virtual Action problem(
331 , const std::string &/*description*/
337 , const std::string &/*reason*/
341 // authentication issues report
342 struct AuthenticationReport : public callback::ReportBase
345 * Prompt for authentication data.
347 * \param url URL which required the authentication
348 * \param msg prompt text
349 * \param auth_data input/output object for handling authentication
350 * data. As an input parameter auth_data can be prefilled with
351 * username (from previous try) or auth_type (available
352 * authentication methods aquired from server (only CurlAuthData)).
353 * As an output parameter it serves for sending username, pasword
354 * or other special data (derived AuthData objects).
355 * \return true if user chooses to continue with authentication,
358 virtual bool prompt(const Url & /* url */,
359 const std::string & /* msg */,
360 AuthData & /* auth_data */)
366 /////////////////////////////////////////////////////////////////
368 ///////////////////////////////////////////////////////////////////
370 ///////////////////////////////////////////////////////////////////
374 // resolvable Message
375 struct MessageResolvableReport : public callback::ReportBase
378 Message::constPtr /*message*/
383 struct ScriptResolvableReport : public callback::ReportBase
385 enum Task { DO, UNDO };
386 enum Notify { OUTPUT, PING };
388 /** Whether executing do_script on install or undo_script on delete. */
389 virtual void start( const Resolvable::constPtr & /*script_r*/,
390 const Pathname & /*path_r*/,
393 /** Progress provides the script output. If the script is quiet,
394 * from time to time still-alive pings are sent to the ui. Returning \c FALSE
395 * aborts script execution.
397 virtual bool progress( Notify , const std::string & = std::string() )
400 virtual void problem( const std::string & /*description*/ )
402 /** Report success. */
403 virtual void finish()
407 ///////////////////////////////////////////////////////////////////
411 // progress for installing a resolvable
412 struct InstallResolvableReport : public callback::ReportBase
415 ABORT, // abort and return error
417 IGNORE // ignore the failure
422 NOT_FOUND, // the requested Url was not found
424 INVALID // th resolvable is invalid
427 // the level of RPM pushing
435 Resolvable::constPtr /*resolvable*/
438 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
441 virtual Action problem(
442 Resolvable::constPtr /*resolvable*/
444 , const std::string &/*description*/
449 Resolvable::constPtr /*resolvable*/
451 , const std::string &/*reason*/
456 // progress for removing a resolvable
457 struct RemoveResolvableReport : public callback::ReportBase
460 ABORT, // abort and return error
462 IGNORE // ignore the failure
467 NOT_FOUND, // the requested Url was not found
469 INVALID // th resolvable is invalid
473 Resolvable::constPtr /*resolvable*/
476 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
479 virtual Action problem(
480 Resolvable::constPtr /*resolvable*/
482 , const std::string &/*description*/
486 Resolvable::constPtr /*resolvable*/
488 , const std::string &/*reason*/
492 // progress for rebuilding the database
493 struct RebuildDBReport : public callback::ReportBase
496 ABORT, // abort and return error
498 IGNORE // ignore the failure
503 FAILED // failed to rebuild
506 virtual void start(Pathname /*path*/) {}
508 virtual bool progress(int /*value*/, Pathname /*path*/)
511 virtual Action problem(
514 , const std::string &/*description*/
520 , const std::string &/*reason*/
524 // progress for converting the database
525 struct ConvertDBReport : public callback::ReportBase
528 ABORT, // abort and return error
530 IGNORE // ignore the failure
535 FAILED // conversion failed
542 virtual bool progress(int /*value*/, Pathname /*path*/)
545 virtual Action problem(
548 , const std::string &/*description*/
554 , const std::string &/*reason*/
558 // progress for scanning the database
559 struct ScanDBReport : public callback::ReportBase
562 ABORT, // abort and return error
564 IGNORE // ignore the failure
569 FAILED // conversion failed
575 virtual bool progress(int /*value*/)
578 virtual Action problem(
580 , const std::string &/*description*/
585 , const std::string &/*reason*/
589 /////////////////////////////////////////////////////////////////
591 ///////////////////////////////////////////////////////////////////
593 /////////////////////////////////////////////////////////////////
594 } // namespace target
595 ///////////////////////////////////////////////////////////////////
597 /////////////////////////////////////////////////////////////////
599 ///////////////////////////////////////////////////////////////////
601 #endif // ZYPP_ZYPPCALLBACKS_H