- Introduce sane probing, with reporting, And decoupled
[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/Source.h"
18 #include "zypp/Pathname.h"
19 #include "zypp/Message.h"
20 #include "zypp/Url.h"
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 { /////////////////////////////////////////////////////////////////
25   namespace source
26   {
27     // progress for downloading a resolvable
28     struct DownloadResolvableReport : public callback::ReportBase
29     {
30       enum Action {
31         ABORT,  // abort and return error
32         RETRY,  // retry
33         IGNORE, // ignore this resolvable but continue
34       };
35
36       enum Error {
37         NO_ERROR,
38         NOT_FOUND,      // the requested Url was not found
39         IO,             // IO error
40         INVALID         // the downloaded file is invalid
41       };
42
43       virtual void start(
44         Resolvable::constPtr resolvable_ptr
45         , Url url
46       ) {}
47
48
49       // Dowmload delta rpm:
50       // - path below url reported on start()
51       // - expected download size (0 if unknown)
52       // - download is interruptable
53       // - problems are just informal
54       virtual void startDeltaDownload( const Pathname & filename, const ByteCount & downloadsize )
55       {}
56
57       virtual bool progressDeltaDownload( int value )
58       { return true; }
59
60       virtual void problemDeltaDownload( std::string description )
61       {}
62
63       virtual void finishDeltaDownload()
64       {}
65
66       // Apply delta rpm:
67       // - local path of downloaded delta
68       // - aplpy is not interruptable
69       // - problems are just informal
70       virtual void startDeltaApply( const Pathname & filename )
71       {}
72
73       virtual void progressDeltaApply( int value )
74       {}
75
76       virtual void problemDeltaApply( std::string description )
77       {}
78
79       virtual void finishDeltaApply()
80       {}
81
82       // Dowmload patch rpm:
83       // - path below url reported on start()
84       // - expected download size (0 if unknown)
85       // - download is interruptable
86       virtual void startPatchDownload( const Pathname & filename, const ByteCount & downloadsize )
87       {}
88
89       virtual bool progressPatchDownload( int value )
90       { return true; }
91
92       virtual void problemPatchDownload( std::string description )
93       {}
94
95       virtual void finishPatchDownload()
96       {}
97
98
99       // return false if the download should be aborted right now
100       virtual bool progress(int value, Resolvable::constPtr resolvable_ptr)
101       { return true; }
102
103       virtual Action problem(
104         Resolvable::constPtr resolvable_ptr
105         , Error error
106         , std::string description
107       ) { return ABORT; }
108
109       virtual void finish(Resolvable::constPtr resolvable_ptr
110         , Error error
111         , std::string reason
112       ) {}
113     };
114
115
116     // progress for downloading a specific file
117     struct DownloadFileReport : public callback::ReportBase
118     {
119       enum Action {
120         ABORT,  // abort and return error
121         RETRY   // retry
122       };
123
124       enum Error {
125         NO_ERROR,
126         NOT_FOUND,      // the requested Url was not found
127         IO,             // IO error
128         INVALID         // the downloaded file is invalid
129       };
130       virtual void start(
131         Source_Ref source
132         , Url url
133       ) {}
134
135       virtual bool progress(int value, Url url)
136       { return true; }
137
138       virtual Action problem(
139         Url url
140         , Error error
141         , std::string description
142       ) { return ABORT; }
143
144       virtual void finish(
145         Url url
146         , Error error
147         , std::string reason
148       ) {}
149     };
150
151     // progress for refreshing a source data
152     struct RefreshSourceReport : public callback::ReportBase
153     {
154       enum Action {
155         ABORT,  // abort and return error
156         RETRY,  // retry
157         IGNORE  // skip refresh, ignore failed refresh
158       };
159
160       enum Error {
161         NO_ERROR,
162         NOT_FOUND,      // the requested Url was not found
163         IO,             // IO error
164         INVALID         // th source is invalid
165       };
166       virtual void start(
167         Source_Ref source
168         , Url url
169       ) {}
170
171       virtual bool progress(int value, Source_Ref source)
172       { return true; }
173
174       virtual Action problem(
175         Source_Ref source
176         , Error error
177         , std::string description
178       ) { return ABORT; }
179
180       virtual void finish(
181         Source_Ref source
182         , Error error
183         , std::string reason
184       ) {}
185     };
186
187     // DEPRECATED
188     struct CreateSourceReport : public callback::ReportBase
189     {
190       enum Action {
191         ABORT,  // abort and return error
192         RETRY   // retry
193       };
194
195       enum Error {
196         NO_ERROR,
197         NOT_FOUND,      // the requested Url was not found
198         IO,             // IO error
199         INVALID         // th source is invalid
200       };
201
202       virtual void startData(
203         Url source_url
204       ) {}
205
206       virtual void startProbe(Url url) {}
207
208       virtual void endProbe(Url url) {}
209
210       virtual bool progressData(int value, Url url)
211       { return true; }
212
213       virtual Action problem(
214         Url url
215           , Error error
216           , std::string description
217       ) { return ABORT; }
218
219       virtual void finishData(
220         Url url
221         , Error error
222         , std::string reason
223       ) {}
224     };
225
226     // progress for probing a source
227     struct ProbeSourceReport : public callback::ReportBase
228     {
229       enum Action {
230         ABORT,  // abort and return error
231         RETRY   // retry
232       };
233
234       enum Error {
235         NO_ERROR,
236         NOT_FOUND,      // the requested Url was not found
237         IO,             // IO error
238         INVALID         // th source is invalid
239       };
240
241       virtual void start(const Url &url) {}
242       virtual void failedProbe( const Url &url, const std::string &type ) {}
243       virtual void successProbe( const Url &url, const std::string &type ) {}
244       virtual void finish(const Url &url, Error error, std::string reason ) {}
245
246       virtual bool progress(const Url &url, int value)
247       { return true; }
248
249       virtual Action problem( const Url &url, Error error, std::string description ) { return ABORT; }
250     };
251     
252     // progress for refreshing a source data
253     struct SourceProcessReport : public callback::ReportBase
254     {
255       enum Action {
256         ABORT,  // abort and return error
257         RETRY,  // retry
258         IGNORE  // skip refresh, ignore failed refresh
259       };
260
261       enum Error {
262         NO_ERROR,
263         NOT_FOUND,      // the requested Url was not found
264         IO,             // IO error
265         INVALID         // th source is invalid
266       };
267       
268       virtual void start( Source_Ref source ) {}
269       virtual bool progress(int value, Source_Ref source)
270       { return true; }
271
272       virtual Action problem(
273           Source_Ref source
274           , Error error
275           , std::string description )
276       { return ABORT; }
277
278       virtual void finish(
279           Source_Ref source
280           , Error error
281           , std::string reason )
282       {}
283     };
284     
285     
286     /////////////////////////////////////////////////////////////////
287   } // namespace source
288   ///////////////////////////////////////////////////////////////////
289
290   ///////////////////////////////////////////////////////////////////
291   namespace media
292   {
293     // media change request callback
294     struct MediaChangeReport : public callback::ReportBase
295     {
296       enum Action {
297         ABORT,  // abort and return error
298         RETRY,  // retry
299         IGNORE, // ignore this media in future, not available anymore
300         IGNORE_ID,      // ignore wrong medium id
301         CHANGE_URL,     // change media URL
302         EJECT           // eject the medium
303       };
304
305       enum Error {
306         NO_ERROR,
307         NOT_FOUND,  // the medie not found at all
308         IO,     // error accessing the media
309         INVALID, // media is broken
310         WRONG   // wrong media, need a different one
311       };
312
313       virtual Action requestMedia(
314         const Source_Ref source
315         , unsigned mediumNr
316         , Error error
317         , std::string description
318       ) { return ABORT; }
319     };
320
321     // progress for downloading a file
322     struct DownloadProgressReport : public callback::ReportBase
323     {
324         enum Action {
325           ABORT,  // abort and return error
326           RETRY,        // retry
327           IGNORE        // ignore the failure
328         };
329
330         enum Error {
331           NO_ERROR,
332           NOT_FOUND,    // the requested Url was not found
333           IO            // IO error
334         };
335
336         virtual void start( Url file, Pathname localfile ) {}
337
338         virtual bool progress(int value, Url file)
339         { return true; }
340
341         virtual Action problem(
342           Url file
343           , Error error
344           , std::string description
345         ) { return ABORT; }
346
347         virtual void finish(
348           Url file
349           , Error error
350           , std::string reason
351         ) {}
352     };
353
354     /////////////////////////////////////////////////////////////////
355   } // namespace media
356   ///////////////////////////////////////////////////////////////////
357
358   ///////////////////////////////////////////////////////////////////
359   namespace target
360   {
361
362     // resolvable Message
363     struct MessageResolvableReport : public callback::ReportBase
364     {
365         virtual void show(
366           Message::constPtr message
367         ) {}
368     };
369
370     ///////////////////////////////////////////////////////////////////
371     namespace rpm
372     {
373
374       // progress for installing a resolvable
375       struct InstallResolvableReport : public callback::ReportBase
376       {
377         enum Action {
378           ABORT,  // abort and return error
379           RETRY,        // retry
380           IGNORE        // ignore the failure
381         };
382
383         enum Error {
384           NO_ERROR,
385           NOT_FOUND,    // the requested Url was not found
386           IO,           // IO error
387           INVALID               // th resolvable is invalid
388         };
389
390         // the level of RPM pushing
391         enum RpmLevel {
392             RPM,
393             RPM_NODEPS,
394             RPM_NODEPS_FORCE
395         };
396
397         virtual void start(
398           Resolvable::constPtr resolvable
399         ) {}
400
401         virtual bool progress(int value, Resolvable::constPtr resolvable)
402         { return true; }
403
404         virtual Action problem(
405           Resolvable::constPtr resolvable
406           , Error error
407           , std::string description
408           , RpmLevel level
409         ) { return ABORT; }
410
411         virtual void finish(
412           Resolvable::constPtr resolvable
413           , Error error
414           , std::string reason
415           , RpmLevel level
416         ) {}
417       };
418
419       // progress for removing a resolvable
420       struct RemoveResolvableReport : public callback::ReportBase
421       {
422         enum Action {
423           ABORT,  // abort and return error
424           RETRY,        // retry
425           IGNORE        // ignore the failure
426         };
427
428         enum Error {
429           NO_ERROR,
430           NOT_FOUND,    // the requested Url was not found
431           IO,           // IO error
432           INVALID               // th resolvable is invalid
433         };
434
435         virtual void start(
436           Resolvable::constPtr resolvable
437         ) {}
438
439         virtual bool progress(int value, Resolvable::constPtr resolvable)
440         { return true; }
441
442         virtual Action problem(
443           Resolvable::constPtr resolvable
444           , Error error
445           , std::string description
446         ) { return ABORT; }
447
448         virtual void finish(
449           Resolvable::constPtr resolvable
450           , Error error
451           , std::string reason
452         ) {}
453       };
454
455       // progress for rebuilding the database
456       struct RebuildDBReport : public callback::ReportBase
457       {
458         enum Action {
459           ABORT,  // abort and return error
460           RETRY,        // retry
461           IGNORE        // ignore the failure
462         };
463
464         enum Error {
465           NO_ERROR,
466           FAILED                // failed to rebuild
467         };
468
469         virtual void start(Pathname path) {}
470
471         virtual bool progress(int value, Pathname path)
472         { return true; }
473
474         virtual Action problem(
475           Pathname path
476          , Error error
477          , std::string description
478         ) { return ABORT; }
479
480         virtual void finish(
481           Pathname path
482           , Error error
483           , std::string reason
484         ) {}
485       };
486
487       // progress for converting the database
488       struct ConvertDBReport : public callback::ReportBase
489       {
490         enum Action {
491           ABORT,  // abort and return error
492           RETRY,        // retry
493           IGNORE        // ignore the failure
494         };
495
496         enum Error {
497           NO_ERROR,
498           FAILED                // conversion failed
499         };
500
501         virtual void start(
502           Pathname path
503         ) {}
504
505         virtual bool progress(int value, Pathname path)
506         { return true; }
507
508         virtual Action problem(
509           Pathname path
510           , Error error
511          , std::string description
512         ) { return ABORT; }
513
514         virtual void finish(
515           Pathname path
516           , Error error
517           , std::string reason
518         ) {}
519       };
520
521        // progress for scanning the database
522       struct ScanDBReport : public callback::ReportBase
523       {
524         enum Action {
525           ABORT,  // abort and return error
526           RETRY,        // retry
527           IGNORE        // ignore the failure
528         };
529
530         enum Error {
531           NO_ERROR,
532           FAILED                // conversion failed
533         };
534
535         virtual void start(
536         ) {}
537
538         virtual bool progress(int value)
539         { return true; }
540
541         virtual Action problem(
542           Error error
543          , std::string description
544         ) { return ABORT; }
545
546         virtual void finish(
547           Error error
548           , std::string reason
549         ) {}
550       };
551
552       /////////////////////////////////////////////////////////////////
553     } // namespace rpm
554     ///////////////////////////////////////////////////////////////////
555
556     /////////////////////////////////////////////////////////////////
557   } // namespace target
558   ///////////////////////////////////////////////////////////////////
559
560   /////////////////////////////////////////////////////////////////
561 } // namespace zypp
562 ///////////////////////////////////////////////////////////////////
563
564 #endif // ZYPP_ZYPPCALLBACKS_H