merge REFACTORING-10_3 back to trunk
[platform/upstream/libzypp.git] / zypp / ZYppCallbacks.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ZYppCallbacks.h
10  *
11 */
12 #ifndef ZYPP_ZYPPCALLBACKS_H
13 #define ZYPP_ZYPPCALLBACKS_H
14
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"
20 #include "zypp/Url.h"
21 #include "zypp/ProgressData.h"
22 #include "zypp/media/MediaUserAuth.h"
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 { /////////////////////////////////////////////////////////////////
27   
28   struct ProgressReport : public callback::ReportBase
29   {
30     virtual void start( const ProgressData &/*task*/ )
31     {}
32     
33     virtual bool progress( const ProgressData &/*task*/ )
34     { return true; }
35
36 //     virtual Action problem(
37 //         Repository /*source*/
38 //         , Error /*error*/
39 //         , const std::string &/*description*/ )
40 //     { return ABORT; }
41
42     virtual void finish( const ProgressData &/*task*/ )
43     {}
44
45   };
46
47   struct ProgressReportAdaptor
48   {
49     
50     ProgressReportAdaptor( const ProgressData::ReceiverFnc &fnc,
51                            callback::SendReport<ProgressReport> &report )
52       : _fnc(fnc)
53       , _report(report)
54       , _first(true)
55     {
56     }
57     
58     bool operator()( const ProgressData &progress )
59     {
60       if ( _first )
61       {
62         _report->start(progress);
63         _first = false;
64       }
65       
66       _report->progress(progress);
67       bool value = true;
68       if ( _fnc )
69         value = _fnc(progress);
70       
71       if ( progress.val() == progress.max() )
72       {
73         _report->finish(progress);
74       }
75       return value;
76     }
77     
78     ProgressData::ReceiverFnc _fnc;
79     callback::SendReport<ProgressReport> &_report;
80     bool _first;
81   };
82   
83   ////////////////////////////////////////////////////////////////////////////
84   
85   namespace repo
86   {
87     // progress for downloading a resolvable
88     struct DownloadResolvableReport : public callback::ReportBase
89     {
90       enum Action {
91         ABORT,  // abort and return error
92         RETRY,  // retry
93         IGNORE, // ignore this resolvable but continue
94       };
95
96       enum Error {
97         NO_ERROR,
98         NOT_FOUND,      // the requested Url was not found
99         IO,             // IO error
100         INVALID         // the downloaded file is invalid
101       };
102
103       virtual void start(
104         Resolvable::constPtr /*resolvable_ptr*/
105         , const Url &/*url*/
106       ) {}
107
108
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*/ )
115       {}
116
117       virtual bool progressDeltaDownload( int /*value*/ )
118       { return true; }
119
120       virtual void problemDeltaDownload( const std::string &/*description*/ )
121       {}
122
123       virtual void finishDeltaDownload()
124       {}
125
126       // Apply delta rpm:
127       // - local path of downloaded delta
128       // - aplpy is not interruptable
129       // - problems are just informal
130       virtual void startDeltaApply( const Pathname & /*filename*/ )
131       {}
132
133       virtual void progressDeltaApply( int /*value*/ )
134       {}
135
136       virtual void problemDeltaApply( const std::string &/*description*/ )
137       {}
138
139       virtual void finishDeltaApply()
140       {}
141
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*/ )
147       {}
148
149       virtual bool progressPatchDownload( int /*value*/ )
150       { return true; }
151
152       virtual void problemPatchDownload( const std::string &/*description*/ )
153       {}
154
155       virtual void finishPatchDownload()
156       {}
157
158
159       // return false if the download should be aborted right now
160       virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
161       { return true; }
162
163       virtual Action problem(
164         Resolvable::constPtr /*resolvable_ptr*/
165         , Error /*error*/
166         , const std::string &/*description*/
167       ) { return ABORT; }
168
169       virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
170         , Error /*error*/
171         , const std::string &/*reason*/
172       ) {}
173     };
174
175     // progress for probing a source
176     struct ProbeRepoReport : public callback::ReportBase
177     {
178       enum Action {
179         ABORT,  // abort and return error
180         RETRY   // retry
181       };
182
183       enum Error {
184         NO_ERROR,
185         NOT_FOUND,      // the requested Url was not found
186         IO,             // IO error
187         INVALID,                // th source is invalid
188         UNKNOWN
189       };
190
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*/ ) {}
195
196       virtual bool progress(const Url &/*url*/, int /*value*/)
197       { return true; }
198
199       virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
200     };
201
202     struct RepoCreateReport : public callback::ReportBase
203     {
204       enum Action {
205         ABORT,  // abort and return error
206         RETRY,  // retry
207         IGNORE  // skip refresh, ignore failed refresh
208       };
209
210       enum Error {
211         NO_ERROR,
212         NOT_FOUND,      // the requested Url was not found
213         IO,             // IO error
214         REJECTED,
215         INVALID, // th source is invali
216         UNKNOWN
217       };
218
219       virtual void start( const zypp::Url &/*url*/ ) {}
220       virtual bool progress( int /*value*/ )
221       { return true; }
222
223       virtual Action problem(
224           const zypp::Url &/*url*/
225           , Error /*error*/
226           , const std::string &/*description*/ )
227       { return ABORT; }
228
229       virtual void finish(
230           const zypp::Url &/*url*/
231           , Error /*error*/
232           , const std::string &/*reason*/ )
233       {}
234     };
235
236     struct RepoReport : public callback::ReportBase
237     {
238       enum Action {
239         ABORT,  // abort and return error
240         RETRY,  // retry
241         IGNORE  // skip refresh, ignore failed refresh
242       };
243
244       enum Error {
245         NO_ERROR,
246         NOT_FOUND,      // the requested Url was not found
247         IO,             // IO error
248         INVALID         // th source is invalid
249       };
250
251       virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/  ) {}
252       virtual bool progress( const ProgressData &/*task*/ )
253       { return true; }
254
255       virtual Action problem(
256           Repository /*source*/
257           , Error /*error*/
258           , const std::string &/*description*/ )
259       { return ABORT; }
260
261       virtual void finish(
262           Repository /*source*/
263           , const std::string &/*task*/
264           , Error /*error*/
265           , const std::string &/*reason*/ )
266       {}
267     };
268
269
270     /////////////////////////////////////////////////////////////////
271   } // namespace source
272   ///////////////////////////////////////////////////////////////////
273
274   ///////////////////////////////////////////////////////////////////
275   namespace media
276   {
277     // media change request callback
278     struct MediaChangeReport : public callback::ReportBase
279     {
280       enum Action {
281         ABORT,  // abort and return error
282         RETRY,  // retry
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
287       };
288
289       enum Error {
290         NO_ERROR,
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
295       };
296
297       virtual Action requestMedia(
298         Repository /*source*/
299         , unsigned /*mediumNr*/
300         , Error /*error*/
301         , const std::string &/*description*/
302       ) { return ABORT; }
303     };
304
305     // progress for downloading a file
306     struct DownloadProgressReport : public callback::ReportBase
307     {
308         enum Action {
309           ABORT,  // abort and return error
310           RETRY,        // retry
311           IGNORE        // ignore the failure
312         };
313
314         enum Error {
315           NO_ERROR,
316           NOT_FOUND,    // the requested Url was not found
317           IO,           // IO error
318           ACCESS_DENIED // user authent. failed while accessing restricted file
319         };
320
321         virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
322
323         virtual bool progress(int /*value*/, const Url &/*file*/)
324         { return true; }
325
326         virtual Action problem(
327           const Url &/*file*/
328           , Error /*error*/
329           , const std::string &/*description*/
330         ) { return ABORT; }
331
332         virtual void finish(
333           const Url &/*file*/
334           , Error /*error*/
335           , const std::string &/*reason*/
336         ) {}
337     };
338
339     // authentication issues report
340     struct AuthenticationReport : public callback::ReportBase
341     {
342       /**
343        * Prompt for authentication data.
344        * 
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,
354        *         false otherwise
355        */
356       virtual bool prompt(const Url & /* url */,
357         const std::string & /* msg */,
358         AuthData & /* auth_data */)
359       {
360         return false;
361       }
362     };
363
364     /////////////////////////////////////////////////////////////////
365   } // namespace media
366   ///////////////////////////////////////////////////////////////////
367
368   ///////////////////////////////////////////////////////////////////
369   namespace target
370   {
371
372     // resolvable Message
373     struct MessageResolvableReport : public callback::ReportBase
374     {
375         virtual void show(
376           Message::constPtr /*message*/
377         ) {}
378     };
379
380     // resolvable Script
381     struct ScriptResolvableReport : public callback::ReportBase
382     {
383       enum Task   { DO, UNDO };
384       enum Notify { OUTPUT, PING };
385
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*/,
389                           Task )
390       {}
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.
394       */
395       virtual bool progress( Notify , const std::string & = std::string() )
396       { return true; }
397       /** Report error. */
398       virtual void problem( const std::string & /*description*/ )
399       {}
400       /** Report success. */
401       virtual void finish()
402       {}
403     };
404
405     ///////////////////////////////////////////////////////////////////
406     namespace rpm
407     {
408
409       // progress for installing a resolvable
410       struct InstallResolvableReport : public callback::ReportBase
411       {
412         enum Action {
413           ABORT,  // abort and return error
414           RETRY,        // retry
415           IGNORE        // ignore the failure
416         };
417
418         enum Error {
419           NO_ERROR,
420           NOT_FOUND,    // the requested Url was not found
421           IO,           // IO error
422           INVALID               // th resolvable is invalid
423         };
424
425         // the level of RPM pushing
426         enum RpmLevel {
427             RPM,
428             RPM_NODEPS,
429             RPM_NODEPS_FORCE
430         };
431
432         virtual void start(
433           Resolvable::constPtr /*resolvable*/
434         ) {}
435
436         virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
437         { return true; }
438
439         virtual Action problem(
440           Resolvable::constPtr /*resolvable*/
441           , Error /*error*/
442           , const std::string &/*description*/
443           , RpmLevel /*level*/
444         ) { return ABORT; }
445
446         virtual void finish(
447           Resolvable::constPtr /*resolvable*/
448           , Error /*error*/
449           , const std::string &/*reason*/
450           , RpmLevel /*level*/
451         ) {}
452       };
453
454       // progress for removing a resolvable
455       struct RemoveResolvableReport : public callback::ReportBase
456       {
457         enum Action {
458           ABORT,  // abort and return error
459           RETRY,        // retry
460           IGNORE        // ignore the failure
461         };
462
463         enum Error {
464           NO_ERROR,
465           NOT_FOUND,    // the requested Url was not found
466           IO,           // IO error
467           INVALID               // th resolvable is invalid
468         };
469
470         virtual void start(
471           Resolvable::constPtr /*resolvable*/
472         ) {}
473
474         virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
475         { return true; }
476
477         virtual Action problem(
478           Resolvable::constPtr /*resolvable*/
479           , Error /*error*/
480           , const std::string &/*description*/
481         ) { return ABORT; }
482
483         virtual void finish(
484           Resolvable::constPtr /*resolvable*/
485           , Error /*error*/
486           , const std::string &/*reason*/
487         ) {}
488       };
489
490       // progress for rebuilding the database
491       struct RebuildDBReport : public callback::ReportBase
492       {
493         enum Action {
494           ABORT,  // abort and return error
495           RETRY,        // retry
496           IGNORE        // ignore the failure
497         };
498
499         enum Error {
500           NO_ERROR,
501           FAILED                // failed to rebuild
502         };
503
504         virtual void start(Pathname /*path*/) {}
505
506         virtual bool progress(int /*value*/, Pathname /*path*/)
507         { return true; }
508
509         virtual Action problem(
510           Pathname /*path*/
511          , Error /*error*/
512          , const std::string &/*description*/
513         ) { return ABORT; }
514
515         virtual void finish(
516           Pathname /*path*/
517           , Error /*error*/
518           , const std::string &/*reason*/
519         ) {}
520       };
521
522       // progress for converting the database
523       struct ConvertDBReport : public callback::ReportBase
524       {
525         enum Action {
526           ABORT,  // abort and return error
527           RETRY,        // retry
528           IGNORE        // ignore the failure
529         };
530
531         enum Error {
532           NO_ERROR,
533           FAILED                // conversion failed
534         };
535
536         virtual void start(
537           Pathname /*path*/
538         ) {}
539
540         virtual bool progress(int /*value*/, Pathname /*path*/)
541         { return true; }
542
543         virtual Action problem(
544           Pathname /*path*/
545           , Error /*error*/
546          , const std::string &/*description*/
547         ) { return ABORT; }
548
549         virtual void finish(
550           Pathname /*path*/
551           , Error /*error*/
552           , const std::string &/*reason*/
553         ) {}
554       };
555
556        // progress for scanning the database
557       struct ScanDBReport : public callback::ReportBase
558       {
559         enum Action {
560           ABORT,  // abort and return error
561           RETRY,        // retry
562           IGNORE        // ignore the failure
563         };
564
565         enum Error {
566           NO_ERROR,
567           FAILED                // conversion failed
568         };
569
570         virtual void start(
571         ) {}
572
573         virtual bool progress(int /*value*/)
574         { return true; }
575
576         virtual Action problem(
577           Error /*error*/
578          , const std::string &/*description*/
579         ) { return ABORT; }
580
581         virtual void finish(
582           Error /*error*/
583           , const std::string &/*reason*/
584         ) {}
585       };
586
587       /////////////////////////////////////////////////////////////////
588     } // namespace rpm
589     ///////////////////////////////////////////////////////////////////
590
591     /////////////////////////////////////////////////////////////////
592   } // namespace target
593   ///////////////////////////////////////////////////////////////////
594
595   /////////////////////////////////////////////////////////////////
596 } // namespace zypp
597 ///////////////////////////////////////////////////////////////////
598
599 #endif // ZYPP_ZYPPCALLBACKS_H