- media change callback (provideFile only for now)
[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/Url.h"
20 #include "zypp/media/MediaManager.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       }; 
34       
35       enum Error {
36         NO_ERROR,
37         NOT_FOUND,      // the requested Url was not found
38         IO,             // IO error
39         INVALID         // the downloaded file is invalid
40       };
41
42       virtual void start(
43         Resolvable::Ptr resolvable_ptr
44         , Url url
45       ) {}
46
47       // return true if the download should be aborted right now
48       virtual bool progress(int value, Resolvable::Ptr resolvable_ptr) 
49       { return false; }
50
51       virtual Action problem(
52         Resolvable::Ptr resolvable_ptr
53         , Error error
54         , std::string description
55       ) { return ABORT; }
56
57       virtual void finish(Resolvable::Ptr resolvable_ptr
58         , Error error
59         , std::string reason
60       ) {}
61     };
62     
63
64     // progress for downloading a specific file
65     struct DownloadFileReport : public callback::ReportBase
66     {
67       enum Action { 
68         ABORT,  // abort and return error
69         RETRY   // retry
70       }; 
71       
72       enum Error {
73         NO_ERROR,
74         NOT_FOUND,      // the requested Url was not found
75         IO,             // IO error
76         INVALID         // the downloaded file is invalid
77       };
78       virtual void start(
79         Source_Ref source
80         , Url url
81       ) {}
82
83       virtual bool progress(int value, Url url) 
84       { return false; }
85
86       virtual Action problem(
87         Url url
88         , Error error
89         , std::string description
90       ) { return ABORT; }
91
92       virtual void finish(
93         Url url
94         , Error error
95         , std::string reason
96       ) {}
97     };
98
99     // progress for refreshing a source data
100     struct RefreshSourceReport : public callback::ReportBase
101     {
102       enum Action { 
103         ABORT,  // abort and return error
104         RETRY   // retry
105       }; 
106       
107       enum Error {
108         NO_ERROR,
109         NOT_FOUND,      // the requested Url was not found
110         IO,             // IO error
111         INVALID         // th source is invalid
112       };
113       virtual void start(
114         Source_Ref source
115         , Url url
116       ) {}
117
118       virtual bool progress(int value, Source_Ref source) 
119       { return false; }
120
121       virtual Action problem(
122         Source_Ref source
123         , Error error
124         , std::string description
125       ) { return ABORT; }
126
127       virtual void finish(
128         Source_Ref source
129         , Error error
130         , std::string reason
131       ) {}
132     };
133
134     // progress for creating a source (download and parsing)
135     struct CreateSourceReport : public callback::ReportBase
136     {
137       enum Action { 
138         ABORT,  // abort and return error
139         RETRY   // retry
140       }; 
141       
142       enum Error {
143         NO_ERROR,
144         NOT_FOUND,      // the requested Url was not found
145         IO,             // IO error
146         INVALID         // th source is invalid
147       };
148       virtual void start(
149         Source_Ref source
150         , Url url
151       ) {}
152
153       virtual bool progress(int value, Url url) 
154       { return false; }
155
156       virtual Action problem(
157         Url url
158         , Error error
159         , std::string description
160       ) { return ABORT; }
161
162       virtual void finish(
163         Url url
164         , Error error
165         , std::string reason
166       ) {}
167     };
168     
169     /////////////////////////////////////////////////////////////////
170   } // namespace source
171   ///////////////////////////////////////////////////////////////////
172   
173   ///////////////////////////////////////////////////////////////////
174   namespace media 
175   { 
176     // media change request callback
177     struct MediaChangeReport : public callback::ReportBase
178     {
179       enum Action { 
180         ABORT,  // abort and return error
181         RETRY,  // retry
182         IGNORE, // ignore this media in future, not available anymore
183       }; 
184
185       enum Error { 
186         NO_ERROR,
187         NOT_FOUND,  // the medie not found at all
188         IO,     // error accessing the media
189         INVALID, // media is broken
190         WRONG   // wrong media, need a different one
191       };       
192       
193       virtual Action requestMedia(
194         const media::MediaAccessRef &ref
195         , unsigned mediumNr
196         , Error error
197         , std::string description
198       ) { return ABORT; }
199     };
200
201     /////////////////////////////////////////////////////////////////
202   } // namespace media
203   ///////////////////////////////////////////////////////////////////
204
205   ///////////////////////////////////////////////////////////////////
206   namespace target 
207   { 
208   
209     ///////////////////////////////////////////////////////////////////
210     namespace rpm 
211     { 
212
213       // progress for installing a resolvable
214       struct InstallResolvableReport : public callback::ReportBase
215       {
216         enum Action { 
217           ABORT,  // abort and return error
218           RETRY,        // retry
219           IGNORE        // ignore the failure
220         }; 
221       
222         enum Error {
223           NO_ERROR,
224           NOT_FOUND,    // the requested Url was not found
225           IO,           // IO error
226           INVALID               // th resolvable is invalid
227         };
228       
229         virtual void start(
230           Resolvable::constPtr resolvable
231         ) {}
232
233         virtual bool progress(int value, Resolvable::constPtr resolvable) 
234         { return false; }
235
236         virtual Action problem(
237           Resolvable::constPtr resolvable
238           , Error error
239          , std::string description
240         ) { return ABORT; }
241
242         virtual void finish(
243           Resolvable::constPtr resolvable
244           , Error error
245           , std::string reason
246         ) {}
247       };
248     
249       // progress for removing a resolvable
250       struct RemoveResolvableReport : public callback::ReportBase
251       {
252         enum Action { 
253           ABORT,  // abort and return error
254           RETRY,        // retry
255           IGNORE        // ignore the failure
256         }; 
257       
258         enum Error {
259           NO_ERROR,
260           NOT_FOUND,    // the requested Url was not found
261           IO,           // IO error
262           INVALID               // th resolvable is invalid
263         };
264       
265         virtual void start(
266           Resolvable::Ptr resolvable
267         ) {}
268
269         virtual bool progress(int value, Resolvable::Ptr resolvable) 
270         { return false; }
271
272         virtual Action problem(
273           Resolvable::Ptr resolvable
274           , Error error
275          , std::string description
276         ) { return ABORT; }
277
278         virtual void finish(
279           Resolvable::Ptr resolvable
280           , Error error
281           , std::string reason
282         ) {}
283       };
284     
285       // progress for rebuilding the database
286       struct RebuildDBReport : public callback::ReportBase
287       {
288         enum Action { 
289           ABORT,  // abort and return error
290           RETRY,        // retry
291           IGNORE        // ignore the failure
292         }; 
293       
294         enum Error {
295           NO_ERROR,
296           NOT_FOUND,    // the requested Url was not found
297           IO,           // IO error
298           INVALID               // th resolvable is invalid
299         };
300       
301         virtual void start(
302           Pathname path
303         ) {}
304
305         virtual bool progress(int value, Pathname path) 
306         { return false; } 
307
308         virtual Action problem(
309           Pathname path
310           , Error error
311          , std::string description
312         ) { return ABORT; }
313
314         virtual void finish(
315           Pathname path
316           , Error error
317           , std::string reason
318         ) {}
319       };
320
321       // progress for converting the database
322       struct ConvertDBReport : 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           INVALID               // th resolvable is invalid
335         };
336       
337         virtual void start(
338           Pathname path
339         ) {}
340
341         virtual bool progress(int value, Pathname path) 
342         { return false; }
343
344         virtual Action problem(
345           Pathname path
346           , Error error
347          , std::string description
348         ) { return ABORT; }
349
350         virtual void finish(
351           Pathname path
352           , Error error
353           , std::string reason
354         ) {}
355       };
356
357       /////////////////////////////////////////////////////////////////
358     } // namespace rpm
359     ///////////////////////////////////////////////////////////////////
360
361     /////////////////////////////////////////////////////////////////
362   } // namespace target
363   ///////////////////////////////////////////////////////////////////
364
365   /////////////////////////////////////////////////////////////////
366 } // namespace zypp
367 ///////////////////////////////////////////////////////////////////
368
369 #endif // ZYPP_ZYPPCALLBACKS_H