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
298 virtual Action requestMedia(
299 Url & /* url (I/O parameter) */
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
428 /** \deprecated We fortunately no longer do 3 attempts. */
436 Resolvable::constPtr /*resolvable*/
439 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
442 virtual Action problem(
443 Resolvable::constPtr /*resolvable*/
445 , const std::string &/*description*/
450 Resolvable::constPtr /*resolvable*/
452 , const std::string &/*reason*/
457 // progress for removing a resolvable
458 struct RemoveResolvableReport : public callback::ReportBase
461 ABORT, // abort and return error
463 IGNORE // ignore the failure
468 NOT_FOUND, // the requested Url was not found
470 INVALID // th resolvable is invalid
474 Resolvable::constPtr /*resolvable*/
477 virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
480 virtual Action problem(
481 Resolvable::constPtr /*resolvable*/
483 , const std::string &/*description*/
487 Resolvable::constPtr /*resolvable*/
489 , const std::string &/*reason*/
493 // progress for rebuilding the database
494 struct RebuildDBReport : public callback::ReportBase
497 ABORT, // abort and return error
499 IGNORE // ignore the failure
504 FAILED // failed to rebuild
507 virtual void start(Pathname /*path*/) {}
509 virtual bool progress(int /*value*/, Pathname /*path*/)
512 virtual Action problem(
515 , const std::string &/*description*/
521 , const std::string &/*reason*/
525 // progress for converting the database
526 struct ConvertDBReport : public callback::ReportBase
529 ABORT, // abort and return error
531 IGNORE // ignore the failure
536 FAILED // conversion failed
543 virtual bool progress(int /*value*/, Pathname /*path*/)
546 virtual Action problem(
549 , const std::string &/*description*/
555 , const std::string &/*reason*/
559 // progress for scanning the database
560 struct ScanDBReport : public callback::ReportBase
563 ABORT, // abort and return error
565 IGNORE // ignore the failure
570 FAILED // conversion failed
576 virtual bool progress(int /*value*/)
579 virtual Action problem(
581 , const std::string &/*description*/
586 , const std::string &/*reason*/
590 /////////////////////////////////////////////////////////////////
592 ///////////////////////////////////////////////////////////////////
594 /////////////////////////////////////////////////////////////////
595 } // namespace target
596 ///////////////////////////////////////////////////////////////////
598 /////////////////////////////////////////////////////////////////
600 ///////////////////////////////////////////////////////////////////
602 #endif // ZYPP_ZYPPCALLBACKS_H