libzypp  11.13.5
ZYppCallbacks.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_ZYPPCALLBACKS_H
13 #define ZYPP_ZYPPCALLBACKS_H
14 
15 #include "zypp/Callback.h"
16 #include "zypp/Resolvable.h"
17 #include "zypp/RepoInfo.h"
18 #include "zypp/Pathname.h"
19 #include "zypp/Package.h"
20 #include "zypp/Patch.h"
21 #include "zypp/Url.h"
22 #include "zypp/ProgressData.h"
24 
26 namespace zypp
27 {
28 
30  {
31  virtual void start( const ProgressData &/*task*/ )
32  {}
33 
34  virtual bool progress( const ProgressData &/*task*/ )
35  { return true; }
36 
37 // virtual Action problem(
38 // Repo /*source*/
39 // , Error /*error*/
40 // , const std::string &/*description*/ )
41 // { return ABORT; }
42 
43  virtual void finish( const ProgressData &/*task*/ )
44  {}
45 
46  };
47 
49  {
50 
53  : _fnc(fnc)
54  , _report(report)
55  , _first(true)
56  {
57  }
58 
59  bool operator()( const ProgressData &progress )
60  {
61  if ( _first )
62  {
63  _report->start(progress);
64  _first = false;
65  }
66 
67  _report->progress(progress);
68  bool value = true;
69  if ( _fnc )
70  value = _fnc(progress);
71 
72 
73  if ( progress.finalReport() )
74  {
75  _report->finish(progress);
76  }
77  return value;
78  }
79 
82  bool _first;
83  };
84 
86 
87  namespace repo
88  {
89  // progress for downloading a resolvable
91  {
92  enum Action {
93  ABORT, // abort and return error
94  RETRY, // retry
95  IGNORE, // ignore this resolvable but continue
96  };
97 
98  enum Error {
100  NOT_FOUND, // the requested Url was not found
101  IO, // IO error
102  INVALID // the downloaded file is invalid
103  };
104 
105  virtual void start(
106  Resolvable::constPtr /*resolvable_ptr*/
107  , const Url &/*url*/
108  ) {}
109 
110 
111  // Dowmload delta rpm:
112  // - path below url reported on start()
113  // - expected download size (0 if unknown)
114  // - download is interruptable
115  // - problems are just informal
116  virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
117  {}
118 
119  virtual bool progressDeltaDownload( int /*value*/ )
120  { return true; }
121 
122  virtual void problemDeltaDownload( const std::string &/*description*/ )
123  {}
124 
125  virtual void finishDeltaDownload()
126  {}
127 
128  // Apply delta rpm:
129  // - local path of downloaded delta
130  // - aplpy is not interruptable
131  // - problems are just informal
132  virtual void startDeltaApply( const Pathname & /*filename*/ )
133  {}
134 
135  virtual void progressDeltaApply( int /*value*/ )
136  {}
137 
138  virtual void problemDeltaApply( const std::string &/*description*/ )
139  {}
140 
141  virtual void finishDeltaApply()
142  {}
143 
144  // Dowmload patch rpm:
145  // - path below url reported on start()
146  // - expected download size (0 if unknown)
147  // - download is interruptable
148  virtual void startPatchDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
149  {}
150 
151  virtual bool progressPatchDownload( int /*value*/ )
152  { return true; }
153 
154  virtual void problemPatchDownload( const std::string &/*description*/ )
155  {}
156 
157  virtual void finishPatchDownload()
158  {}
159 
160 
161  // return false if the download should be aborted right now
162  virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
163  { return true; }
164 
165  virtual Action problem(
166  Resolvable::constPtr /*resolvable_ptr*/
167  , Error /*error*/
168  , const std::string &/*description*/
169  ) { return ABORT; }
170 
171  virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
172  , Error /*error*/
173  , const std::string &/*reason*/
174  ) {}
175  };
176 
177  // progress for probing a source
179  {
180  enum Action {
181  ABORT, // abort and return error
182  RETRY // retry
183  };
184 
185  enum Error {
187  NOT_FOUND, // the requested Url was not found
188  IO, // IO error
189  INVALID, // th source is invalid
191  };
192 
193  virtual void start(const Url &/*url*/) {}
194  virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
195  virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
196  virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
197 
198  virtual bool progress(const Url &/*url*/, int /*value*/)
199  { return true; }
200 
201  virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
202  };
203 
205  {
206  enum Action {
207  ABORT, // abort and return error
208  RETRY, // retry
209  IGNORE // skip refresh, ignore failed refresh
210  };
211 
212  enum Error {
214  NOT_FOUND, // the requested Url was not found
215  IO, // IO error
217  INVALID, // th source is invali
219  };
220 
221  virtual void start( const zypp::Url &/*url*/ ) {}
222  virtual bool progress( int /*value*/ )
223  { return true; }
224 
225  virtual Action problem(
226  const zypp::Url &/*url*/
227  , Error /*error*/
228  , const std::string &/*description*/ )
229  { return ABORT; }
230 
231  virtual void finish(
232  const zypp::Url &/*url*/
233  , Error /*error*/
234  , const std::string &/*reason*/ )
235  {}
236  };
237 
239  {
240  enum Action {
241  ABORT, // abort and return error
242  RETRY, // retry
243  IGNORE // skip refresh, ignore failed refresh
244  };
245 
246  enum Error {
248  NOT_FOUND, // the requested Url was not found
249  IO, // IO error
250  INVALID // th source is invalid
251  };
252 
253  virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/ ) {}
254  virtual bool progress( const ProgressData &/*task*/ )
255  { return true; }
256 
257  virtual Action problem(
258  Repository /*source*/
259  , Error /*error*/
260  , const std::string &/*description*/ )
261  { return ABORT; }
262 
263  virtual void finish(
264  Repository /*source*/
265  , const std::string &/*task*/
266  , Error /*error*/
267  , const std::string &/*reason*/ )
268  {}
269  };
270 
271 
273  } // namespace source
275 
277  namespace media
278  {
279  // media change request callback
281  {
282  enum Action {
283  ABORT, // abort and return error
284  RETRY, // retry
285  IGNORE, // ignore this media in future, not available anymore
286  IGNORE_ID, // ignore wrong medium id
287  CHANGE_URL, // change media URL
288  EJECT // eject the medium
289  };
290 
291  enum Error {
293  NOT_FOUND, // the medie not found at all
294  IO, // error accessing the media
295  INVALID, // media is broken
296  WRONG, // wrong media, need a different one
298  };
299 
314  Url & /* url (I/O parameter) */
315  , unsigned /*mediumNr*/
316  , const std::string & /* label */
317  , Error /*error*/
318  , const std::string & /*description*/
319  , const std::vector<std::string> & /* devices */
320  , unsigned int & /* dev_current (I/O param) */
321  ) { return ABORT; }
322  };
323 
324  // progress for downloading a file
326  {
327  enum Action {
328  ABORT, // abort and return error
329  RETRY, // retry
330  IGNORE // ignore the failure
331  };
332 
333  enum Error {
335  NOT_FOUND, // the requested Url was not found
336  IO, // IO error
337  ACCESS_DENIED, // user authent. failed while accessing restricted file
338  ERROR // other error
339  };
340 
341  virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
342 
351  virtual bool progress(int /*value*/, const Url &/*file*/,
352  double dbps_avg = -1,
353  double dbps_current = -1)
354  { return true; }
355 
356  virtual Action problem(
357  const Url &/*file*/
358  , Error /*error*/
359  , const std::string &/*description*/
360  ) { return ABORT; }
361 
362  virtual void finish(
363  const Url &/*file*/
364  , Error /*error*/
365  , const std::string &/*reason*/
366  ) {}
367  };
368 
369  // authentication issues report
371  {
386  virtual bool prompt(const Url & /* url */,
387  const std::string & /* msg */,
388  AuthData & /* auth_data */)
389  {
390  return false;
391  }
392  };
393 
395  } // namespace media
397 
399  namespace target
400  {
403  {
407  virtual bool show( Patch::constPtr & /*patch*/ )
408  { return true; }
409  };
410 
416  {
417  enum Notify { OUTPUT, PING };
418  enum Action {
419  ABORT, // abort commit and return error
420  RETRY, // (re)try to execute this script
421  IGNORE // ignore any failue and continue
422  };
423 
426  virtual void start( const Package::constPtr & /*package*/,
427  const Pathname & /*script path*/ )
428  {}
433  virtual bool progress( Notify /*OUTPUT or PING*/,
434  const std::string & /*output*/ = std::string() )
435  { return true; }
437  virtual Action problem( const std::string & /*description*/ )
438  { return ABORT; }
440  virtual void finish()
441  {}
442  };
443 
445  namespace rpm
446  {
447 
448  // progress for installing a resolvable
450  {
451  enum Action {
452  ABORT, // abort and return error
453  RETRY, // retry
454  IGNORE // ignore the failure
455  };
456 
457  enum Error {
459  NOT_FOUND, // the requested Url was not found
460  IO, // IO error
461  INVALID // th resolvable is invalid
462  };
463 
464  // the level of RPM pushing
466  enum RpmLevel {
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  , RpmLevel /*level*/
484  ) { return ABORT; }
485 
486  virtual void finish(
487  Resolvable::constPtr /*resolvable*/
488  , Error /*error*/
489  , const std::string &/*reason*/
490  , RpmLevel /*level*/
491  ) {}
492  };
493 
494  // progress for removing a resolvable
496  {
497  enum Action {
498  ABORT, // abort and return error
499  RETRY, // retry
500  IGNORE // ignore the failure
501  };
502 
503  enum Error {
505  NOT_FOUND, // the requested Url was not found
506  IO, // IO error
507  INVALID // th resolvable is invalid
508  };
509 
510  virtual void start(
511  Resolvable::constPtr /*resolvable*/
512  ) {}
513 
514  virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
515  { return true; }
516 
517  virtual Action problem(
518  Resolvable::constPtr /*resolvable*/
519  , Error /*error*/
520  , const std::string &/*description*/
521  ) { return ABORT; }
522 
523  virtual void finish(
524  Resolvable::constPtr /*resolvable*/
525  , Error /*error*/
526  , const std::string &/*reason*/
527  ) {}
528  };
529 
530  // progress for rebuilding the database
532  {
533  enum Action {
534  ABORT, // abort and return error
535  RETRY, // retry
536  IGNORE // ignore the failure
537  };
538 
539  enum Error {
541  FAILED // failed to rebuild
542  };
543 
544  virtual void start(Pathname /*path*/) {}
545 
546  virtual bool progress(int /*value*/, Pathname /*path*/)
547  { return true; }
548 
549  virtual Action problem(
550  Pathname /*path*/
551  , Error /*error*/
552  , const std::string &/*description*/
553  ) { return ABORT; }
554 
555  virtual void finish(
556  Pathname /*path*/
557  , Error /*error*/
558  , const std::string &/*reason*/
559  ) {}
560  };
561 
562  // progress for converting the database
564  {
565  enum Action {
566  ABORT, // abort and return error
567  RETRY, // retry
568  IGNORE // ignore the failure
569  };
570 
571  enum Error {
573  FAILED // conversion failed
574  };
575 
576  virtual void start(
577  Pathname /*path*/
578  ) {}
579 
580  virtual bool progress(int /*value*/, Pathname /*path*/)
581  { return true; }
582 
583  virtual Action problem(
584  Pathname /*path*/
585  , Error /*error*/
586  , const std::string &/*description*/
587  ) { return ABORT; }
588 
589  virtual void finish(
590  Pathname /*path*/
591  , Error /*error*/
592  , const std::string &/*reason*/
593  ) {}
594  };
595 
597  } // namespace rpm
599 
601  } // namespace target
603 
604  class PoolQuery;
605 
613  {
617  enum Action {
621  };
622 
626  enum Error {
629  };
630 
634  virtual void start(
635  ) {}
636 
641  virtual bool progress(int /*value*/)
642  { return true; }
643 
648  virtual Action execute(
649  const PoolQuery& /*error*/
650  ) { return DELETE; }
651 
655  virtual void finish(
656  Error /*error*/
657  ) {}
658 
659  };
660 
665  {
670  enum Action {
674  };
675 
679  enum Error {
682  };
683 
691  };
692 
693  virtual void start() {}
694 
699  virtual bool progress()
700  { return true; }
701 
705  virtual Action conflict(
706  const PoolQuery&,
708  ) { return DELETE; }
709 
710  virtual void finish(
711  Error /*error*/
712  ) {}
713  };
714 
715 
717 } // namespace zypp
719 
720 #endif // ZYPP_ZYPPCALLBACKS_H