- merge 3728:3847 in 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/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       // Apply delta rpm:
64       // - local path of downloaded delta
65       // - aplpy is not interruptable
66       // - problems are just informal
67       virtual void startDeltaApply( const Pathname & filename )
68       {}
69
70       virtual void progressDeltaApply( int value )
71       {}
72
73       virtual void problemDeltaApply( std::string description )
74       {}
75
76       // Dowmload patch rpm:
77       // - path below url reported on start()
78       // - expected download size (0 if unknown)
79       // - download is interruptable
80       virtual void startPatchDownload( const Pathname & filename, const ByteCount & downloadsize )
81       {}
82
83       virtual bool progressPatchDownload( int value )
84       { return true; }
85
86       virtual void problemPatchDownload( std::string description )
87       {}
88
89
90       // return false if the download should be aborted right now
91       virtual bool progress(int value, Resolvable::constPtr resolvable_ptr)
92       { return true; }
93
94       virtual Action problem(
95         Resolvable::constPtr resolvable_ptr
96         , Error error
97         , std::string description
98       ) { return ABORT; }
99
100       virtual void finish(Resolvable::constPtr resolvable_ptr
101         , Error error
102         , std::string reason
103       ) {}
104     };
105
106
107     // progress for downloading a specific file
108     struct DownloadFileReport : public callback::ReportBase
109     {
110       enum Action {
111         ABORT,  // abort and return error
112         RETRY   // retry
113       };
114
115       enum Error {
116         NO_ERROR,
117         NOT_FOUND,      // the requested Url was not found
118         IO,             // IO error
119         INVALID         // the downloaded file is invalid
120       };
121       virtual void start(
122         Source_Ref source
123         , Url url
124       ) {}
125
126       virtual bool progress(int value, Url url)
127       { return true; }
128
129       virtual Action problem(
130         Url url
131         , Error error
132         , std::string description
133       ) { return ABORT; }
134
135       virtual void finish(
136         Url url
137         , Error error
138         , std::string reason
139       ) {}
140     };
141
142     // progress for refreshing a source data
143     struct RefreshSourceReport : public callback::ReportBase
144     {
145       enum Action {
146         ABORT,  // abort and return error
147         RETRY,  // retry
148         IGNORE  // skip refresh, ignore failed refresh
149       };
150
151       enum Error {
152         NO_ERROR,
153         NOT_FOUND,      // the requested Url was not found
154         IO,             // IO error
155         INVALID         // th source is invalid
156       };
157       virtual void start(
158         Source_Ref source
159         , Url url
160       ) {}
161
162       virtual bool progress(int value, Source_Ref source)
163       { return true; }
164
165       virtual Action problem(
166         Source_Ref source
167         , Error error
168         , std::string description
169       ) { return ABORT; }
170
171       virtual void finish(
172         Source_Ref source
173         , Error error
174         , std::string reason
175       ) {}
176     };
177
178     // progress for creating a source (download and parsing)
179     struct CreateSourceReport : public callback::ReportBase
180     {
181       enum Action {
182         ABORT,  // abort and return error
183         RETRY   // retry
184       };
185
186       enum Error {
187         NO_ERROR,
188         NOT_FOUND,      // the requested Url was not found
189         IO,             // IO error
190         INVALID         // th source is invalid
191       };
192
193       virtual void startData(
194         Url source_url
195       ) {}
196
197       virtual void startProbe(Url url) {}
198
199       virtual void endProbe(Url url) {}
200
201       virtual bool progressData(int value, Url url)
202       { return true; }
203
204       virtual Action problem(
205         Url url
206         , Error error
207         , std::string description
208       ) { return ABORT; }
209
210       virtual void finishData(
211         Url url
212         , Error error
213         , std::string reason
214       ) {}
215     };
216
217     /////////////////////////////////////////////////////////////////
218   } // namespace source
219   ///////////////////////////////////////////////////////////////////
220
221   ///////////////////////////////////////////////////////////////////
222   namespace media
223   {
224     // media change request callback
225     struct MediaChangeReport : public callback::ReportBase
226     {
227       enum Action {
228         ABORT,  // abort and return error
229         RETRY,  // retry
230         IGNORE, // ignore this media in future, not available anymore
231         IGNORE_ID,      // ignore wrong medium id
232         CHANGE_URL,     // change media URL
233         EJECT           // eject the medium
234       };
235
236       enum Error {
237         NO_ERROR,
238         NOT_FOUND,  // the medie not found at all
239         IO,     // error accessing the media
240         INVALID, // media is broken
241         WRONG   // wrong media, need a different one
242       };
243
244       virtual Action requestMedia(
245         const Source_Ref source
246         , unsigned mediumNr
247         , Error error
248         , std::string description
249       ) { return ABORT; }
250     };
251
252     // progress for downloading a file
253     struct DownloadProgressReport : public callback::ReportBase
254     {
255         enum Action {
256           ABORT,  // abort and return error
257           RETRY,        // retry
258           IGNORE        // ignore the failure
259         };
260
261         enum Error {
262           NO_ERROR,
263           NOT_FOUND,    // the requested Url was not found
264           IO            // IO error
265         };
266
267         virtual void start( Url file, Pathname localfile ) {}
268
269         virtual bool progress(int value, Url file)
270         { return true; }
271
272         virtual Action problem(
273           Url file
274           , Error error
275           , std::string description
276         ) { return ABORT; }
277
278         virtual void finish(
279           Url file
280           , Error error
281           , std::string reason
282         ) {}
283     };
284
285     /////////////////////////////////////////////////////////////////
286   } // namespace media
287   ///////////////////////////////////////////////////////////////////
288
289   ///////////////////////////////////////////////////////////////////
290   namespace target
291   {
292
293     // resolvable Message
294     struct MessageResolvableReport : public callback::ReportBase
295     {
296         virtual void show(
297           Message::constPtr message
298         ) {}
299     };
300
301     ///////////////////////////////////////////////////////////////////
302     namespace rpm
303     {
304
305       // progress for installing a resolvable
306       struct InstallResolvableReport : 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           INVALID               // th resolvable is invalid
319         };
320
321         // the level of RPM pushing
322         enum RpmLevel {
323             RPM,
324             RPM_NODEPS,
325             RPM_NODEPS_FORCE
326         };
327
328         virtual void start(
329           Resolvable::constPtr resolvable
330         ) {}
331
332         virtual bool progress(int value, Resolvable::constPtr resolvable)
333         { return true; }
334
335         virtual Action problem(
336           Resolvable::constPtr resolvable
337           , Error error
338           , std::string description
339           , RpmLevel level
340         ) { return ABORT; }
341
342         virtual void finish(
343           Resolvable::constPtr resolvable
344           , Error error
345           , std::string reason
346           , RpmLevel level
347         ) {}
348       };
349
350       // progress for removing a resolvable
351       struct RemoveResolvableReport : public callback::ReportBase
352       {
353         enum Action {
354           ABORT,  // abort and return error
355           RETRY,        // retry
356           IGNORE        // ignore the failure
357         };
358
359         enum Error {
360           NO_ERROR,
361           NOT_FOUND,    // the requested Url was not found
362           IO,           // IO error
363           INVALID               // th resolvable is invalid
364         };
365
366         virtual void start(
367           Resolvable::constPtr resolvable
368         ) {}
369
370         virtual bool progress(int value, Resolvable::constPtr resolvable)
371         { return true; }
372
373         virtual Action problem(
374           Resolvable::constPtr resolvable
375           , Error error
376           , std::string description
377         ) { return ABORT; }
378
379         virtual void finish(
380           Resolvable::constPtr resolvable
381           , Error error
382           , std::string reason
383         ) {}
384       };
385
386       // progress for rebuilding the database
387       struct RebuildDBReport : public callback::ReportBase
388       {
389         enum Action {
390           ABORT,  // abort and return error
391           RETRY,        // retry
392           IGNORE        // ignore the failure
393         };
394
395         enum Error {
396           NO_ERROR,
397           FAILED                // failed to rebuild
398         };
399
400         virtual void start(Pathname path) {}
401
402         virtual bool progress(int value, Pathname path)
403         { return true; }
404
405         virtual Action problem(
406           Pathname path
407          , Error error
408          , std::string description
409         ) { return ABORT; }
410
411         virtual void finish(
412           Pathname path
413           , Error error
414           , std::string reason
415         ) {}
416       };
417
418       // progress for converting the database
419       struct ConvertDBReport : public callback::ReportBase
420       {
421         enum Action {
422           ABORT,  // abort and return error
423           RETRY,        // retry
424           IGNORE        // ignore the failure
425         };
426
427         enum Error {
428           NO_ERROR,
429           FAILED                // conversion failed
430         };
431
432         virtual void start(
433           Pathname path
434         ) {}
435
436         virtual bool progress(int value, Pathname path)
437         { return true; }
438
439         virtual Action problem(
440           Pathname path
441           , Error error
442          , std::string description
443         ) { return ABORT; }
444
445         virtual void finish(
446           Pathname path
447           , Error error
448           , std::string reason
449         ) {}
450       };
451
452        // progress for scanning the database
453       struct ScanDBReport : public callback::ReportBase
454       {
455         enum Action {
456           ABORT,  // abort and return error
457           RETRY,        // retry
458           IGNORE        // ignore the failure
459         };
460
461         enum Error {
462           NO_ERROR,
463           FAILED                // conversion failed
464         };
465
466         virtual void start(
467         ) {}
468
469         virtual bool progress(int value)
470         { return true; }
471
472         virtual Action problem(
473           Error error
474          , std::string description
475         ) { return ABORT; }
476
477         virtual void finish(
478           Error error
479           , std::string reason
480         ) {}
481       };
482
483       /////////////////////////////////////////////////////////////////
484     } // namespace rpm
485     ///////////////////////////////////////////////////////////////////
486
487     /////////////////////////////////////////////////////////////////
488   } // namespace target
489   ///////////////////////////////////////////////////////////////////
490
491   /////////////////////////////////////////////////////////////////
492 } // namespace zypp
493 ///////////////////////////////////////////////////////////////////
494
495 #endif // ZYPP_ZYPPCALLBACKS_H