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