improve lock documentation
[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/RepoInfo.h"
18 #include "zypp/Pathname.h"
19 #include "zypp/Message.h"
20 #include "zypp/Url.h"
21 #include "zypp/ProgressData.h"
22 #include "zypp/media/MediaUserAuth.h"
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 { /////////////////////////////////////////////////////////////////
27
28   struct ProgressReport : public callback::ReportBase
29   {
30     virtual void start( const ProgressData &/*task*/ )
31     {}
32
33     virtual bool progress( const ProgressData &/*task*/ )
34     { return true; }
35
36 //     virtual Action problem(
37 //         Repo /*source*/
38 //         , Error /*error*/
39 //         , const std::string &/*description*/ )
40 //     { return ABORT; }
41
42     virtual void finish( const ProgressData &/*task*/ )
43     {}
44
45   };
46
47   struct ProgressReportAdaptor
48   {
49
50     ProgressReportAdaptor( const ProgressData::ReceiverFnc &fnc,
51                            callback::SendReport<ProgressReport> &report )
52       : _fnc(fnc)
53       , _report(report)
54       , _first(true)
55     {
56     }
57
58     bool operator()( const ProgressData &progress )
59     {
60       if ( _first )
61       {
62         _report->start(progress);
63         _first = false;
64       }
65
66       _report->progress(progress);
67       bool value = true;
68       if ( _fnc )
69         value = _fnc(progress);
70
71
72       if ( progress.finalReport() )
73       {
74         _report->finish(progress);
75       }
76       return value;
77     }
78
79     ProgressData::ReceiverFnc _fnc;
80     callback::SendReport<ProgressReport> &_report;
81     bool _first;
82   };
83
84   ////////////////////////////////////////////////////////////////////////////
85
86   namespace repo
87   {
88     // progress for downloading a resolvable
89     struct DownloadResolvableReport : public callback::ReportBase
90     {
91       enum Action {
92         ABORT,  // abort and return error
93         RETRY,  // retry
94         IGNORE, // ignore this resolvable but continue
95       };
96
97       enum Error {
98         NO_ERROR,
99         NOT_FOUND,      // the requested Url was not found
100         IO,             // IO error
101         INVALID         // the downloaded file is invalid
102       };
103
104       virtual void start(
105         Resolvable::constPtr /*resolvable_ptr*/
106         , const Url &/*url*/
107       ) {}
108
109
110       // Dowmload delta rpm:
111       // - path below url reported on start()
112       // - expected download size (0 if unknown)
113       // - download is interruptable
114       // - problems are just informal
115       virtual void startDeltaDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
116       {}
117
118       virtual bool progressDeltaDownload( int /*value*/ )
119       { return true; }
120
121       virtual void problemDeltaDownload( const std::string &/*description*/ )
122       {}
123
124       virtual void finishDeltaDownload()
125       {}
126
127       // Apply delta rpm:
128       // - local path of downloaded delta
129       // - aplpy is not interruptable
130       // - problems are just informal
131       virtual void startDeltaApply( const Pathname & /*filename*/ )
132       {}
133
134       virtual void progressDeltaApply( int /*value*/ )
135       {}
136
137       virtual void problemDeltaApply( const std::string &/*description*/ )
138       {}
139
140       virtual void finishDeltaApply()
141       {}
142
143       // Dowmload patch rpm:
144       // - path below url reported on start()
145       // - expected download size (0 if unknown)
146       // - download is interruptable
147       virtual void startPatchDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
148       {}
149
150       virtual bool progressPatchDownload( int /*value*/ )
151       { return true; }
152
153       virtual void problemPatchDownload( const std::string &/*description*/ )
154       {}
155
156       virtual void finishPatchDownload()
157       {}
158
159
160       // return false if the download should be aborted right now
161       virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable_ptr*/)
162       { return true; }
163
164       virtual Action problem(
165         Resolvable::constPtr /*resolvable_ptr*/
166         , Error /*error*/
167         , const std::string &/*description*/
168       ) { return ABORT; }
169
170       virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
171         , Error /*error*/
172         , const std::string &/*reason*/
173       ) {}
174     };
175
176     // progress for probing a source
177     struct ProbeRepoReport : public callback::ReportBase
178     {
179       enum Action {
180         ABORT,  // abort and return error
181         RETRY   // retry
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         UNKNOWN
190       };
191
192       virtual void start(const Url &/*url*/) {}
193       virtual void failedProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
194       virtual void successProbe( const Url &/*url*/, const std::string &/*type*/ ) {}
195       virtual void finish(const Url &/*url*/, Error /*error*/, const std::string &/*reason*/ ) {}
196
197       virtual bool progress(const Url &/*url*/, int /*value*/)
198       { return true; }
199
200       virtual Action problem( const Url &/*url*/, Error /*error*/, const std::string &/*description*/ ) { return ABORT; }
201     };
202
203     struct RepoCreateReport : public callback::ReportBase
204     {
205       enum Action {
206         ABORT,  // abort and return error
207         RETRY,  // retry
208         IGNORE  // skip refresh, ignore failed refresh
209       };
210
211       enum Error {
212         NO_ERROR,
213         NOT_FOUND,      // the requested Url was not found
214         IO,             // IO error
215         REJECTED,
216         INVALID, // th source is invali
217         UNKNOWN
218       };
219
220       virtual void start( const zypp::Url &/*url*/ ) {}
221       virtual bool progress( int /*value*/ )
222       { return true; }
223
224       virtual Action problem(
225           const zypp::Url &/*url*/
226           , Error /*error*/
227           , const std::string &/*description*/ )
228       { return ABORT; }
229
230       virtual void finish(
231           const zypp::Url &/*url*/
232           , Error /*error*/
233           , const std::string &/*reason*/ )
234       {}
235     };
236
237     struct RepoReport : public callback::ReportBase
238     {
239       enum Action {
240         ABORT,  // abort and return error
241         RETRY,  // retry
242         IGNORE  // skip refresh, ignore failed refresh
243       };
244
245       enum Error {
246         NO_ERROR,
247         NOT_FOUND,      // the requested Url was not found
248         IO,             // IO error
249         INVALID         // th source is invalid
250       };
251
252       virtual void start( const ProgressData &/*task*/, const RepoInfo /*repo*/  ) {}
253       virtual bool progress( const ProgressData &/*task*/ )
254       { return true; }
255
256       virtual Action problem(
257           Repository /*source*/
258           , Error /*error*/
259           , const std::string &/*description*/ )
260       { return ABORT; }
261
262       virtual void finish(
263           Repository /*source*/
264           , const std::string &/*task*/
265           , Error /*error*/
266           , const std::string &/*reason*/ )
267       {}
268     };
269
270
271     /////////////////////////////////////////////////////////////////
272   } // namespace source
273   ///////////////////////////////////////////////////////////////////
274
275   ///////////////////////////////////////////////////////////////////
276   namespace media
277   {
278     // media change request callback
279     struct MediaChangeReport : public callback::ReportBase
280     {
281       enum Action {
282         ABORT,  // abort and return error
283         RETRY,  // retry
284         IGNORE, // ignore this media in future, not available anymore
285         IGNORE_ID,      // ignore wrong medium id
286         CHANGE_URL,     // change media URL
287         EJECT           // eject the medium
288       };
289
290       enum Error {
291         NO_ERROR,
292         NOT_FOUND,  // the medie not found at all
293         IO,     // error accessing the media
294         INVALID, // media is broken
295         WRONG,  // wrong media, need a different one
296         IO_SOFT       /**< IO error which can happen on worse connection like timeout exceed */
297       };
298
299       /**
300        * 
301        * \param url         in: url for which the media is requested,
302        *                    out: url to use instead of the original one
303        * \param mediumNr    requested medium number
304        * \param label       label of requested medium
305        * \param error       type of error from \ref Error enum
306        * \param description error message (media not desired or error foo occured)
307        * \param devices     list of the available devices (for eject)
308        * \param dev_current in: index of the currently used device in the \a devices list
309        *                    out: index of the devices to be ejected in the \a devices list 
310        * \return \ref Action (ABORT by default)
311        */
312       virtual Action requestMedia(
313         Url & /* url (I/O parameter) */
314         , unsigned /*mediumNr*/
315         , const std::string & /* label */
316         , Error /*error*/
317         , const std::string & /*description*/
318         , const std::vector<std::string> & /* devices */
319         , unsigned int & /* dev_current (I/O param) */
320       ) { return ABORT; }
321     };
322
323     // progress for downloading a file
324     struct DownloadProgressReport : public callback::ReportBase
325     {
326         enum Action {
327           ABORT,  // abort and return error
328           RETRY,        // retry
329           IGNORE        // ignore the failure
330         };
331
332         enum Error {
333           NO_ERROR,
334           NOT_FOUND,    // the requested Url was not found
335           IO,           // IO error
336           ACCESS_DENIED, // user authent. failed while accessing restricted file
337           ERROR // other error
338         };
339
340         virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
341
342         /**
343          * Download progress.
344          * 
345          * \param value        Percentage value.
346          * \param file         File URI.
347          * \param dbps_avg     Average download rate so far. -1 if unknown.
348          * \param dbps_current Current download (cca last 1 sec). -1 if unknown.
349          */
350         virtual bool progress(int /*value*/, const Url &/*file*/,
351                               double dbps_avg = -1,
352                               double dbps_current = -1)
353         { return true; }
354
355         virtual Action problem(
356           const Url &/*file*/
357           , Error /*error*/
358           , const std::string &/*description*/
359         ) { return ABORT; }
360
361         virtual void finish(
362           const Url &/*file*/
363           , Error /*error*/
364           , const std::string &/*reason*/
365         ) {}
366     };
367
368     // authentication issues report
369     struct AuthenticationReport : public callback::ReportBase
370     {
371       /**
372        * Prompt for authentication data.
373        *
374        * \param url       URL which required the authentication
375        * \param msg       prompt text
376        * \param auth_data input/output object for handling authentication
377        *        data. As an input parameter auth_data can be prefilled with
378        *        username (from previous try) or auth_type (available
379        *        authentication methods aquired from server (only CurlAuthData)).
380        *        As an output parameter it serves for sending username, pasword
381        *        or other special data (derived AuthData objects).
382        * \return true if user chooses to continue with authentication,
383        *         false otherwise
384        */
385       virtual bool prompt(const Url & /* url */,
386         const std::string & /* msg */,
387         AuthData & /* auth_data */)
388       {
389         return false;
390       }
391     };
392
393     /////////////////////////////////////////////////////////////////
394   } // namespace media
395   ///////////////////////////////////////////////////////////////////
396
397   ///////////////////////////////////////////////////////////////////
398   namespace target
399   {
400
401     // resolvable Message
402     struct MessageResolvableReport : public callback::ReportBase
403     {
404         virtual void show(
405           Message::constPtr /*message*/
406         ) {}
407     };
408
409     // resolvable Script
410     struct ScriptResolvableReport : public callback::ReportBase
411     {
412       enum Task   { DO, UNDO };
413       enum Notify { OUTPUT, PING };
414
415       /** Whether executing do_script on install or undo_script on delete. */
416       virtual void start( const Resolvable::constPtr & /*script_r*/,
417                           const Pathname & /*path_r*/,
418                           Task )
419       {}
420       /** Progress provides the script output. If the script is quiet,
421        * from time to time still-alive pings are sent to the ui. Returning \c FALSE
422        * aborts script execution.
423       */
424       virtual bool progress( Notify , const std::string & = std::string() )
425       { return true; }
426       /** Report error. */
427       virtual void problem( const std::string & /*description*/ )
428       {}
429       /** Report success. */
430       virtual void finish()
431       {}
432     };
433
434     ///////////////////////////////////////////////////////////////////
435     namespace rpm
436     {
437
438       // progress for installing a resolvable
439       struct InstallResolvableReport : public callback::ReportBase
440       {
441         enum Action {
442           ABORT,  // abort and return error
443           RETRY,        // retry
444           IGNORE        // ignore the failure
445         };
446
447         enum Error {
448           NO_ERROR,
449           NOT_FOUND,    // the requested Url was not found
450           IO,           // IO error
451           INVALID               // th resolvable is invalid
452         };
453
454         // the level of RPM pushing
455         /** \deprecated We fortunately no longer do 3 attempts. */
456         enum RpmLevel {
457             RPM,
458             RPM_NODEPS,
459             RPM_NODEPS_FORCE
460         };
461
462         virtual void start(
463           Resolvable::constPtr /*resolvable*/
464         ) {}
465
466         virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
467         { return true; }
468
469         virtual Action problem(
470           Resolvable::constPtr /*resolvable*/
471           , Error /*error*/
472           , const std::string &/*description*/
473           , RpmLevel /*level*/
474         ) { return ABORT; }
475
476         virtual void finish(
477           Resolvable::constPtr /*resolvable*/
478           , Error /*error*/
479           , const std::string &/*reason*/
480           , RpmLevel /*level*/
481         ) {}
482       };
483
484       // progress for removing a resolvable
485       struct RemoveResolvableReport : public callback::ReportBase
486       {
487         enum Action {
488           ABORT,  // abort and return error
489           RETRY,        // retry
490           IGNORE        // ignore the failure
491         };
492
493         enum Error {
494           NO_ERROR,
495           NOT_FOUND,    // the requested Url was not found
496           IO,           // IO error
497           INVALID               // th resolvable is invalid
498         };
499
500         virtual void start(
501           Resolvable::constPtr /*resolvable*/
502         ) {}
503
504         virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
505         { return true; }
506
507         virtual Action problem(
508           Resolvable::constPtr /*resolvable*/
509           , Error /*error*/
510           , const std::string &/*description*/
511         ) { return ABORT; }
512
513         virtual void finish(
514           Resolvable::constPtr /*resolvable*/
515           , Error /*error*/
516           , const std::string &/*reason*/
517         ) {}
518       };
519
520       // progress for rebuilding the database
521       struct RebuildDBReport : public callback::ReportBase
522       {
523         enum Action {
524           ABORT,  // abort and return error
525           RETRY,        // retry
526           IGNORE        // ignore the failure
527         };
528
529         enum Error {
530           NO_ERROR,
531           FAILED                // failed to rebuild
532         };
533
534         virtual void start(Pathname /*path*/) {}
535
536         virtual bool progress(int /*value*/, Pathname /*path*/)
537         { return true; }
538
539         virtual Action problem(
540           Pathname /*path*/
541          , Error /*error*/
542          , const std::string &/*description*/
543         ) { return ABORT; }
544
545         virtual void finish(
546           Pathname /*path*/
547           , Error /*error*/
548           , const std::string &/*reason*/
549         ) {}
550       };
551
552       // progress for converting the database
553       struct ConvertDBReport : public callback::ReportBase
554       {
555         enum Action {
556           ABORT,  // abort and return error
557           RETRY,        // retry
558           IGNORE        // ignore the failure
559         };
560
561         enum Error {
562           NO_ERROR,
563           FAILED                // conversion failed
564         };
565
566         virtual void start(
567           Pathname /*path*/
568         ) {}
569
570         virtual bool progress(int /*value*/, Pathname /*path*/)
571         { return true; }
572
573         virtual Action problem(
574           Pathname /*path*/
575           , Error /*error*/
576          , const std::string &/*description*/
577         ) { return ABORT; }
578
579         virtual void finish(
580           Pathname /*path*/
581           , Error /*error*/
582           , const std::string &/*reason*/
583         ) {}
584       };
585
586        // progress for scanning the database
587       struct ScanDBReport : public callback::ReportBase
588       {
589         enum Action {
590           ABORT,  // abort and return error
591           RETRY,        // retry
592           IGNORE        // ignore the failure
593         };
594
595         enum Error {
596           NO_ERROR,
597           FAILED                // conversion failed
598         };
599
600         virtual void start(
601         ) {}
602
603         virtual bool progress(int /*value*/)
604         { return true; }
605
606         virtual Action problem(
607           Error /*error*/
608          , const std::string &/*description*/
609         ) { return ABORT; }
610
611         virtual void finish(
612           Error /*error*/
613           , const std::string &/*reason*/
614         ) {}
615       };
616
617       /////////////////////////////////////////////////////////////////
618     } // namespace rpm
619     ///////////////////////////////////////////////////////////////////
620
621     /////////////////////////////////////////////////////////////////
622   } // namespace target
623   ///////////////////////////////////////////////////////////////////
624
625   class PoolQuery;
626
627   /** \name Locks */
628   //@{
629   /**
630    * Callback for cleaning locks which doesn't lock anything in pool.
631    */
632
633   struct CleanEmptyLocksReport : public callback::ReportBase
634   {
635     /**
636      * action performed by cleaning api to specific lock
637      */
638     enum Action {
639       ABORT,  /**< abort and return error */
640       DELETE, /**< delete empty lock    */
641       IGNORE  /**< skip empty lock */
642     };
643
644     /**
645      * result of cleaning
646      */
647     enum Error {
648       NO_ERROR, /**< no problem */
649       ABORTED /** cleaning aborted by user */
650     };
651
652     /**
653      * cleaning is started
654      */
655     virtual void start(
656     ) {}
657
658     /**
659      * progress of cleaning specifies in percents
660      * \return if continue
661      */
662     virtual bool progress(int /*value*/)
663     { return true; }
664
665     /**
666      * When find empty lock ask what to do with it
667      * \return action
668      */
669     virtual Action execute(
670         const PoolQuery& /*error*/
671      ) { return DELETE; }
672
673       /**
674        * cleaning is done
675        */
676      virtual void finish(
677        Error /*error*/
678       ) {}
679
680   };
681
682   /**
683    * this callback handles merging old locks with newly added or removed
684    */
685   struct SavingLocksReport : public callback::ReportBase
686   {
687     /**
688      * action for old lock which is in conflict
689      * \see ConflictState
690      */
691     enum Action {
692       ABORT,  /**< abort and return error*/
693       DELETE, /**< delete conflicted lock    */
694       IGNORE  /**< skip conflict lock */
695     };
696
697     /**
698      * result of merging
699      */
700     enum Error {
701       NO_ERROR, /**< no problem */
702       ABORTED  /**< cleaning aborted by user */
703     };
704
705     /**
706      * type of conflict of old and new lock
707      */
708     enum ConflictState{
709       SAME_RESULTS, /**< locks lock same item in pool but his parameters is different */
710       INTERSECT /**< locks lock some file and unlocking lock unlock only part
711       * of iti, so removing old lock can unlock more items in pool */
712     };
713
714     virtual void start() {}
715
716     /**
717      * merging still live
718      * \return if continue
719      */
720     virtual bool progress()
721     { return true; }
722
723     /**
724      * When user unlock something which is locked by non-identical query
725      */
726     virtual Action conflict(
727          const PoolQuery&, /**< problematic query*/
728        ConflictState 
729      ) { return DELETE; }
730
731      virtual void finish(
732        Error /*error*/
733       ) {}
734   };
735
736
737   /////////////////////////////////////////////////////////////////
738 } // namespace zypp
739 ///////////////////////////////////////////////////////////////////
740
741 #endif // ZYPP_ZYPPCALLBACKS_H