- Progress for YUM sources
[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         , const 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     // progress for probing a source
116     struct ProbeSourceReport : public callback::ReportBase
117     {
118       enum Action {
119         ABORT,  // abort and return error
120         RETRY   // retry
121       };
122
123       enum Error {
124         NO_ERROR,
125         NOT_FOUND,      // the requested Url was not found
126         IO,             // IO error
127         INVALID,                // th source is invalid
128         UNKNOWN    
129       };
130
131       virtual void start(const Url &url) {}
132       virtual void failedProbe( const Url &url, const std::string &type ) {}
133       virtual void successProbe( const Url &url, const std::string &type ) {}
134       virtual void finish(const Url &url, Error error, std::string reason ) {}
135
136       virtual bool progress(const Url &url, int value)
137       { return true; }
138
139       virtual Action problem( const Url &url, Error error, std::string description ) { return ABORT; }
140     };
141     
142     struct SourceCreateReport : public callback::ReportBase
143     {
144       enum Action {
145         ABORT,  // abort and return error
146         RETRY,  // retry
147         IGNORE  // skip refresh, ignore failed refresh
148       };
149
150       enum Error {
151         NO_ERROR,
152         NOT_FOUND,      // the requested Url was not found
153         IO,             // IO error
154         REJECTED,
155         INVALID, // th source is invali
156         UNKNOWN
157       };
158       
159       virtual void start( const zypp::Url &url ) {}
160       virtual bool progress( int value )
161       { return true; }
162
163       virtual Action problem(
164           const zypp::Url &url
165           , Error error
166           , std::string description )
167       { return ABORT; }
168
169       virtual void finish(
170           const zypp::Url &url
171           , Error error
172           , std::string reason )
173       {}
174     };
175     
176     struct SourceReport : public callback::ReportBase
177     {
178       enum Action {
179         ABORT,  // abort and return error
180         RETRY,  // retry
181         IGNORE  // skip refresh, ignore failed refresh
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       };
190       
191       virtual void start( Source_Ref source, const std::string &task ) {}
192       virtual bool progress( int value )
193       { return true; }
194
195       virtual Action problem(
196           Source_Ref source
197           , Error error
198           , std::string description )
199       { return ABORT; }
200
201       virtual void finish(
202           Source_Ref source
203           , const std::string task
204           , Error error
205           , std::string reason )
206       {}
207     };
208     
209     
210     /////////////////////////////////////////////////////////////////
211   } // namespace source
212   ///////////////////////////////////////////////////////////////////
213
214   ///////////////////////////////////////////////////////////////////
215   namespace media
216   {
217     // media change request callback
218     struct MediaChangeReport : public callback::ReportBase
219     {
220       enum Action {
221         ABORT,  // abort and return error
222         RETRY,  // retry
223         IGNORE, // ignore this media in future, not available anymore
224         IGNORE_ID,      // ignore wrong medium id
225         CHANGE_URL,     // change media URL
226         EJECT           // eject the medium
227       };
228
229       enum Error {
230         NO_ERROR,
231         NOT_FOUND,  // the medie not found at all
232         IO,     // error accessing the media
233         INVALID, // media is broken
234         WRONG   // wrong media, need a different one
235       };
236
237       virtual Action requestMedia(
238         const Source_Ref source
239         , unsigned mediumNr
240         , Error error
241         , std::string description
242       ) { return ABORT; }
243     };
244
245     // progress for downloading a file
246     struct DownloadProgressReport : public callback::ReportBase
247     {
248         enum Action {
249           ABORT,  // abort and return error
250           RETRY,        // retry
251           IGNORE        // ignore the failure
252         };
253
254         enum Error {
255           NO_ERROR,
256           NOT_FOUND,    // the requested Url was not found
257           IO            // IO error
258         };
259
260         virtual void start( const Url &file, Pathname localfile ) {}
261
262         virtual bool progress(int value, const Url &file)
263         { return true; }
264
265         virtual Action problem(
266           const Url &file
267           , Error error
268           , std::string description
269         ) { return ABORT; }
270
271         virtual void finish(
272           const Url &file
273           , Error error
274           , std::string reason
275         ) {}
276     };
277
278     /////////////////////////////////////////////////////////////////
279   } // namespace media
280   ///////////////////////////////////////////////////////////////////
281
282   ///////////////////////////////////////////////////////////////////
283   namespace target
284   {
285
286     // resolvable Message
287     struct MessageResolvableReport : public callback::ReportBase
288     {
289         virtual void show(
290           Message::constPtr message
291         ) {}
292     };
293
294     ///////////////////////////////////////////////////////////////////
295     namespace rpm
296     {
297
298       // progress for installing a resolvable
299       struct InstallResolvableReport : public callback::ReportBase
300       {
301         enum Action {
302           ABORT,  // abort and return error
303           RETRY,        // retry
304           IGNORE        // ignore the failure
305         };
306
307         enum Error {
308           NO_ERROR,
309           NOT_FOUND,    // the requested Url was not found
310           IO,           // IO error
311           INVALID               // th resolvable is invalid
312         };
313
314         // the level of RPM pushing
315         enum RpmLevel {
316             RPM,
317             RPM_NODEPS,
318             RPM_NODEPS_FORCE
319         };
320
321         virtual void start(
322           Resolvable::constPtr resolvable
323         ) {}
324
325         virtual bool progress(int value, Resolvable::constPtr resolvable)
326         { return true; }
327
328         virtual Action problem(
329           Resolvable::constPtr resolvable
330           , Error error
331           , std::string description
332           , RpmLevel level
333         ) { return ABORT; }
334
335         virtual void finish(
336           Resolvable::constPtr resolvable
337           , Error error
338           , std::string reason
339           , RpmLevel level
340         ) {}
341       };
342
343       // progress for removing a resolvable
344       struct RemoveResolvableReport : public callback::ReportBase
345       {
346         enum Action {
347           ABORT,  // abort and return error
348           RETRY,        // retry
349           IGNORE        // ignore the failure
350         };
351
352         enum Error {
353           NO_ERROR,
354           NOT_FOUND,    // the requested Url was not found
355           IO,           // IO error
356           INVALID               // th resolvable is invalid
357         };
358
359         virtual void start(
360           Resolvable::constPtr resolvable
361         ) {}
362
363         virtual bool progress(int value, Resolvable::constPtr resolvable)
364         { return true; }
365
366         virtual Action problem(
367           Resolvable::constPtr resolvable
368           , Error error
369           , std::string description
370         ) { return ABORT; }
371
372         virtual void finish(
373           Resolvable::constPtr resolvable
374           , Error error
375           , std::string reason
376         ) {}
377       };
378
379       // progress for rebuilding the database
380       struct RebuildDBReport : public callback::ReportBase
381       {
382         enum Action {
383           ABORT,  // abort and return error
384           RETRY,        // retry
385           IGNORE        // ignore the failure
386         };
387
388         enum Error {
389           NO_ERROR,
390           FAILED                // failed to rebuild
391         };
392
393         virtual void start(Pathname path) {}
394
395         virtual bool progress(int value, Pathname path)
396         { return true; }
397
398         virtual Action problem(
399           Pathname path
400          , Error error
401          , std::string description
402         ) { return ABORT; }
403
404         virtual void finish(
405           Pathname path
406           , Error error
407           , std::string reason
408         ) {}
409       };
410
411       // progress for converting the database
412       struct ConvertDBReport : 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           FAILED                // conversion failed
423         };
424
425         virtual void start(
426           Pathname path
427         ) {}
428
429         virtual bool progress(int value, Pathname path)
430         { return true; }
431
432         virtual Action problem(
433           Pathname path
434           , Error error
435          , std::string description
436         ) { return ABORT; }
437
438         virtual void finish(
439           Pathname path
440           , Error error
441           , std::string reason
442         ) {}
443       };
444
445        // progress for scanning the database
446       struct ScanDBReport : public callback::ReportBase
447       {
448         enum Action {
449           ABORT,  // abort and return error
450           RETRY,        // retry
451           IGNORE        // ignore the failure
452         };
453
454         enum Error {
455           NO_ERROR,
456           FAILED                // conversion failed
457         };
458
459         virtual void start(
460         ) {}
461
462         virtual bool progress(int value)
463         { return true; }
464
465         virtual Action problem(
466           Error error
467          , std::string description
468         ) { return ABORT; }
469
470         virtual void finish(
471           Error error
472           , std::string reason
473         ) {}
474       };
475
476       /////////////////////////////////////////////////////////////////
477     } // namespace rpm
478     ///////////////////////////////////////////////////////////////////
479
480     /////////////////////////////////////////////////////////////////
481   } // namespace target
482   ///////////////////////////////////////////////////////////////////
483
484   /////////////////////////////////////////////////////////////////
485 } // namespace zypp
486 ///////////////////////////////////////////////////////////////////
487
488 #endif // ZYPP_ZYPPCALLBACKS_H