libzypp  17.14.0
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/base/EnumClass.h"
16 #include "zypp/Callback.h"
17 #include "zypp/UserData.h"
18 #include "zypp/Resolvable.h"
19 #include "zypp/RepoInfo.h"
20 #include "zypp/Pathname.h"
21 #include "zypp/Package.h"
22 #include "zypp/Patch.h"
23 #include "zypp/Url.h"
24 #include "zypp/ProgressData.h"
26 
28 namespace zypp
29 {
30 
32  namespace sat
33  {
34  class Queue;
35  class FileConflicts;
36  } // namespace sat
38 
40  {
41  virtual void start( const ProgressData &/*task*/ )
42  {}
43 
44  virtual bool progress( const ProgressData &/*task*/ )
45  { return true; }
46 
47 // virtual Action problem(
48 // Repo /*source*/
49 // , Error /*error*/
50 // , const std::string &/*description*/ )
51 // { return ABORT; }
52 
53  virtual void finish( const ProgressData &/*task*/ )
54  {}
55 
56  };
57 
59  {
60 
63  : _fnc(fnc)
64  , _report(report)
65  , _first(true)
66  {
67  }
68 
69  bool operator()( const ProgressData &progress )
70  {
71  if ( _first )
72  {
73  _report->start(progress);
74  _first = false;
75  }
76 
77  bool value = _report->progress(progress);
78  if ( _fnc )
79  value &= _fnc(progress);
80 
81  if ( progress.finalReport() )
82  {
83  _report->finish(progress);
84  }
85  return value;
86  }
87 
90  bool _first;
91  };
92 
94 
95  namespace repo
96  {
97  // progress for downloading a resolvable
99  {
100  enum Action {
101  ABORT, // abort and return error
102  RETRY, // retry
103  IGNORE, // ignore this resolvable but continue
104  };
105 
106  enum Error {
108  NOT_FOUND, // the requested Url was not found
109  IO, // IO error
110  INVALID // the downloaded file is invalid
111  };
112 
116  virtual void infoInCache( Resolvable::constPtr res_r, const Pathname & localfile_r )
117  {}
118 
119  virtual void start(
120  Resolvable::constPtr /*resolvable_ptr*/
121  , const Url &/*url*/
122  ) {}
123 
124 
125  // Dowmload delta rpm:
126  // - path below url reported on start()
127  // - expected download size (0 if unknown)
128  // - download is interruptable
129  // - problems are just informal
130  virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
131  {}
132 
133  virtual bool progressDeltaDownload( int /*value*/ )
134  { return true; }
135 
136  virtual void problemDeltaDownload( const std::string &/*description*/ )
137  {}
138 
139  virtual void finishDeltaDownload()
140  {}
141 
142  // Apply delta rpm:
143  // - local path of downloaded delta
144  // - aplpy is not interruptable
145  // - problems are just informal
146  virtual void startDeltaApply( const Pathname & /*filename*/ )
147  {}
148 
149  virtual void progressDeltaApply( int /*value*/ )
150  {}
151 
152  virtual void problemDeltaApply( const std::string &/*description*/ )
153  {}
154 
155  virtual void finishDeltaApply()
156  {}
157 
158  // return false if the download should be aborted right now
159  virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
160  { return true; }
161 
162  virtual Action problem(
163  Resolvable::constPtr /*resolvable_ptr*/
164  , Error /*error*/
165  , const std::string &/*description*/
166  ) { return ABORT; }
167 
168 
184  virtual void pkgGpgCheck( const UserData & userData_r = UserData() )
185  {}
186 
187  virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
188  , Error /*error*/
189  , const std::string &/*reason*/
190  ) {}
191  };
192 
193  // progress for probing a source
195  {
196  enum Action {
197  ABORT, // abort and return error
198  RETRY // retry
199  };
200 
201  enum Error {
203  NOT_FOUND, // the requested Url was not found
204  IO, // IO error
205  INVALID, // th source is invalid
207  };
208 
209  virtual void start(const Url &/*url*/) {}
210  virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
211  virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
212  virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
213 
214  virtual bool progress(const Url &/*url*/, int /*value*/)
215  { return true; }
216 
217  virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
218  };
219 
221  {
222  enum Action {
223  ABORT, // abort and return error
224  RETRY, // retry
225  IGNORE // skip refresh, ignore failed refresh
226  };
227 
228  enum Error {
230  NOT_FOUND, // the requested Url was not found
231  IO, // IO error
233  INVALID, // th source is invali
235  };
236 
237  virtual void start( const zypp::Url &/*url*/ ) {}
238  virtual bool progress( int /*value*/ )
239  { return true; }
240 
241  virtual Action problem(
242  const zypp::Url &/*url*/
243  , Error /*error*/
244  , const std::string &/*description*/ )
245  { return ABORT; }
246 
247  virtual void finish(
248  const zypp::Url &/*url*/
249  , Error /*error*/
250  , const std::string &/*reason*/ )
251  {}
252  };
253 
255  {
256  enum Action {
257  ABORT, // abort and return error
258  RETRY, // retry
259  IGNORE // skip refresh, ignore failed refresh
260  };
261 
262  enum Error {
264  NOT_FOUND, // the requested Url was not found
265  IO, // IO error
266  INVALID // th source is invalid
267  };
268 
269  virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/ ) {}
270  virtual bool progress( const ProgressData &/*task*/ )
271  { return true; }
272 
273  virtual Action problem(
274  Repository /*source*/
275  , Error /*error*/
276  , const std::string &/*description*/ )
277  { return ABORT; }
278 
279  virtual void finish(
280  Repository /*source*/
281  , const std::string &/*task*/
282  , Error /*error*/
283  , const std::string &/*reason*/ )
284  {}
285  };
286 
287 
289  } // namespace source
291 
293  namespace media
294  {
295  // media change request callback
297  {
298  enum Action {
299  ABORT, // abort and return error
300  RETRY, // retry
301  IGNORE, // ignore this media in future, not available anymore
302  IGNORE_ID, // ignore wrong medium id
303  CHANGE_URL, // change media URL
304  EJECT // eject the medium
305  };
306 
307  enum Error {
309  NOT_FOUND, // the medie not found at all
310  IO, // error accessing the media
311  INVALID, // media is broken
312  WRONG, // wrong media, need a different one
314  };
315 
330  Url & /* url (I/O parameter) */
331  , unsigned /*mediumNr*/
332  , const std::string & /* label */
333  , Error /*error*/
334  , const std::string & /*description*/
335  , const std::vector<std::string> & /* devices */
336  , unsigned int & /* dev_current (I/O param) */
337  ) { return ABORT; }
338  };
339 
346  {
348  ScopedDisableMediaChangeReport( bool condition_r = true );
349  private:
350  shared_ptr<callback::TempConnect<media::MediaChangeReport> > _guard;
351  };
352 
353  // progress for downloading a file
355  {
356  enum Action {
357  ABORT, // abort and return error
358  RETRY, // retry
359  IGNORE // ignore the failure
360  };
361 
362  enum Error {
364  NOT_FOUND, // the requested Url was not found
365  IO, // IO error
366  ACCESS_DENIED, // user authent. failed while accessing restricted file
367  ERROR // other error
368  };
369 
370  virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
371 
380  virtual bool progress(int /*value*/, const Url &/*file*/,
381  double dbps_avg = -1,
382  double dbps_current = -1)
383  { return true; }
384 
385  virtual Action problem(
386  const Url &/*file*/
387  , Error /*error*/
388  , const std::string &/*description*/
389  ) { return ABORT; }
390 
391  virtual void finish(
392  const Url &/*file*/
393  , Error /*error*/
394  , const std::string &/*reason*/
395  ) {}
396  };
397 
398  // authentication issues report
400  {
415  virtual bool prompt(const Url & /* url */,
416  const std::string & /* msg */,
417  AuthData & /* auth_data */)
418  {
419  return false;
420  }
421  };
422 
424  } // namespace media
426 
428  namespace target
429  {
432  {
436  virtual bool show( Patch::constPtr & /*patch*/ )
437  { return true; }
438  };
439 
445  {
446  enum Notify { OUTPUT, PING };
447  enum Action {
448  ABORT, // abort commit and return error
449  RETRY, // (re)try to execute this script
450  IGNORE // ignore any failue and continue
451  };
452 
455  virtual void start( const Package::constPtr & /*package*/,
456  const Pathname & /*script path*/ )
457  {}
462  virtual bool progress( Notify /*OUTPUT or PING*/,
463  const std::string & /*output*/ = std::string() )
464  { return true; }
466  virtual Action problem( const std::string & /*description*/ )
467  { return ABORT; }
469  virtual void finish()
470  {}
471  };
472 
484  {
489  virtual bool start( const ProgressData & progress_r )
490  { return true; }
491 
497  virtual bool progress( const ProgressData & progress_r, const sat::Queue & noFilelist_r )
498  { return true; }
499 
506  virtual bool result( const ProgressData & progress_r, const sat::Queue & noFilelist_r, const sat::FileConflicts & conflicts_r )
507  { return true; }
508  };
509 
510 
512  namespace rpm
513  {
514 
515  // progress for installing a resolvable
517  {
518  enum Action {
519  ABORT, // abort and return error
520  RETRY, // retry
521  IGNORE // ignore the failure
522  };
523 
524  enum Error {
526  NOT_FOUND, // the requested Url was not found
527  IO, // IO error
528  INVALID // th resolvable is invalid
529  };
530 
531  // the level of RPM pushing
533  enum RpmLevel {
537  };
538 
539  virtual void start(
540  Resolvable::constPtr /*resolvable*/
541  ) {}
542 
543  virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
544  { return true; }
545 
546  virtual Action problem(
547  Resolvable::constPtr /*resolvable*/
548  , Error /*error*/
549  , const std::string &/*description*/
550  , RpmLevel /*level*/
551  ) { return ABORT; }
552 
553  virtual void finish(
554  Resolvable::constPtr /*resolvable*/
555  , Error /*error*/
556  , const std::string &/*reason*/
557  , RpmLevel /*level*/
558  ) {}
559  };
560 
561  // progress for removing a resolvable
563  {
564  enum Action {
565  ABORT, // abort and return error
566  RETRY, // retry
567  IGNORE // ignore the failure
568  };
569 
570  enum Error {
572  NOT_FOUND, // the requested Url was not found
573  IO, // IO error
574  INVALID // th resolvable is invalid
575  };
576 
577  virtual void start(
578  Resolvable::constPtr /*resolvable*/
579  ) {}
580 
581  virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
582  { return true; }
583 
584  virtual Action problem(
585  Resolvable::constPtr /*resolvable*/
586  , Error /*error*/
587  , const std::string &/*description*/
588  ) { return ABORT; }
589 
590  virtual void finish(
591  Resolvable::constPtr /*resolvable*/
592  , Error /*error*/
593  , const std::string &/*reason*/
594  ) {}
595  };
596 
597  // progress for rebuilding the database
599  {
600  enum Action {
601  ABORT, // abort and return error
602  RETRY, // retry
603  IGNORE // ignore the failure
604  };
605 
606  enum Error {
608  FAILED // failed to rebuild
609  };
610 
611  virtual void start(Pathname /*path*/) {}
612 
613  virtual bool progress(int /*value*/, Pathname /*path*/)
614  { return true; }
615 
616  virtual Action problem(
617  Pathname /*path*/
618  , Error /*error*/
619  , const std::string &/*description*/
620  ) { return ABORT; }
621 
622  virtual void finish(
623  Pathname /*path*/
624  , Error /*error*/
625  , const std::string &/*reason*/
626  ) {}
627  };
628 
629  // progress for converting the database
631  {
632  enum Action {
633  ABORT, // abort and return error
634  RETRY, // retry
635  IGNORE // ignore the failure
636  };
637 
638  enum Error {
640  FAILED // conversion failed
641  };
642 
643  virtual void start(
644  Pathname /*path*/
645  ) {}
646 
647  virtual bool progress(int /*value*/, Pathname /*path*/)
648  { return true; }
649 
650  virtual Action problem(
651  Pathname /*path*/
652  , Error /*error*/
653  , const std::string &/*description*/
654  ) { return ABORT; }
655 
656  virtual void finish(
657  Pathname /*path*/
658  , Error /*error*/
659  , const std::string &/*reason*/
660  ) {}
661  };
662 
664  } // namespace rpm
666 
668  } // namespace target
670 
671  class PoolQuery;
672 
680  {
684  enum Action {
688  };
689 
693  enum Error {
696  };
697 
701  virtual void start(
702  ) {}
703 
708  virtual bool progress(int /*value*/)
709  { return true; }
710 
715  virtual Action execute(
716  const PoolQuery& /*error*/
717  ) { return DELETE; }
718 
722  virtual void finish(
723  Error /*error*/
724  ) {}
725 
726  };
727 
732  {
737  enum Action {
741  };
742 
746  enum Error {
749  };
750 
758  };
759 
760  virtual void start() {}
761 
766  virtual bool progress()
767  { return true; }
768 
772  virtual Action conflict(
773  const PoolQuery&,
775  ) { return DELETE; }
776 
777  virtual void finish(
778  Error /*error*/
779  ) {}
780  };
781 
787  {
788  public:
790  struct EMsgTypeDef {
792  };
793  typedef base::EnumClass<EMsgTypeDef> MsgType;
794 
797 
798  public:
800  virtual bool message( MsgType type_r, const std::string & msg_r, const UserData & userData_r ) const
801  { return true; }
802 
803 
807  static callback::SendReport<JobReport> & instance(); // impl in ZYppImpl.cc
808 
810  static bool debug( const std::string & msg_r, const UserData & userData_r = UserData() )
811  { return instance()->message( MsgType::debug, msg_r, userData_r ); }
812 
814  static bool info( const std::string & msg_r, const UserData & userData_r = UserData() )
815  { return instance()->message( MsgType::info, msg_r, userData_r ); }
816 
818  static bool warning( const std::string & msg_r, const UserData & userData_r = UserData() )
819  { return instance()->message( MsgType::warning, msg_r, userData_r ); }
820 
822  static bool error( const std::string & msg_r, const UserData & userData_r = UserData() )
823  { return instance()->message( MsgType::error, msg_r, userData_r ); }
824 
826  static bool important( const std::string & msg_r, const UserData & userData_r = UserData() )
827  { return instance()->message( MsgType::important, msg_r, userData_r ); }
828 
830  static bool data( const std::string & msg_r, const UserData & userData_r = UserData() )
831  { return instance()->message( MsgType::data, msg_r, userData_r ); }
833  };
834 
835 
837 } // namespace zypp
839 
840 #endif // ZYPP_ZYPPCALLBACKS_H