Remove obsolete ResStatus bits.
[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/Package.h"
20 #include "zypp/Patch.h"
21 #include "zypp/Url.h"
22 #include "zypp/ProgressData.h"
23 #include "zypp/media/MediaUserAuth.h"
24
25 ///////////////////////////////////////////////////////////////////
26 namespace zypp
27 { /////////////////////////////////////////////////////////////////
28
29   struct ProgressReport : public callback::ReportBase
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
48   struct ProgressReportAdaptor
49   {
50
51     ProgressReportAdaptor( const ProgressData::ReceiverFnc &fnc,
52                            callback::SendReport<ProgressReport> &report )
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
80     ProgressData::ReceiverFnc _fnc;
81     callback::SendReport<ProgressReport> &_report;
82     bool _first;
83   };
84
85   ////////////////////////////////////////////////////////////////////////////
86
87   namespace repo
88   {
89     // progress for downloading a resolvable
90     struct DownloadResolvableReport : public callback::ReportBase
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 {
99         NO_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
178     struct ProbeRepoReport : public callback::ReportBase
179     {
180       enum Action {
181         ABORT,  // abort and return error
182         RETRY   // retry
183       };
184
185       enum Error {
186         NO_ERROR,
187         NOT_FOUND,      // the requested Url was not found
188         IO,             // IO error
189         INVALID,                // th source is invalid
190         UNKNOWN
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
204     struct RepoCreateReport : public callback::ReportBase
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 {
213         NO_ERROR,
214         NOT_FOUND,      // the requested Url was not found
215         IO,             // IO error
216         REJECTED,
217         INVALID, // th source is invali
218         UNKNOWN
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
238     struct RepoReport : public callback::ReportBase
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 {
247         NO_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
272     /////////////////////////////////////////////////////////////////
273   } // namespace source
274   ///////////////////////////////////////////////////////////////////
275
276   ///////////////////////////////////////////////////////////////////
277   namespace media
278   {
279     // media change request callback
280     struct MediaChangeReport : public callback::ReportBase
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 {
292         NO_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
297         IO_SOFT       /**< IO error which can happen on worse connection like timeout exceed */
298       };
299
300       /**
301        *
302        * \param url         in: url for which the media is requested,
303        *                    out: url to use instead of the original one
304        * \param mediumNr    requested medium number
305        * \param label       label of requested medium
306        * \param error       type of error from \ref Error enum
307        * \param description error message (media not desired or error foo occured)
308        * \param devices     list of the available devices (for eject)
309        * \param dev_current in: index of the currently used device in the \a devices list
310        *                    out: index of the devices to be ejected in the \a devices list
311        * \return \ref Action (ABORT by default)
312        */
313       virtual Action requestMedia(
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
325     struct DownloadProgressReport : public callback::ReportBase
326     {
327         enum Action {
328           ABORT,  // abort and return error
329           RETRY,        // retry
330           IGNORE        // ignore the failure
331         };
332
333         enum Error {
334           NO_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
343         /**
344          * Download progress.
345          *
346          * \param value        Percentage value.
347          * \param file         File URI.
348          * \param dbps_avg     Average download rate so far. -1 if unknown.
349          * \param dbps_current Current download (cca last 1 sec). -1 if unknown.
350          */
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
370     struct AuthenticationReport : public callback::ReportBase
371     {
372       /**
373        * Prompt for authentication data.
374        *
375        * \param url       URL which required the authentication
376        * \param msg       prompt text
377        * \param auth_data input/output object for handling authentication
378        *        data. As an input parameter auth_data can be prefilled with
379        *        username (from previous try) or auth_type (available
380        *        authentication methods aquired from server (only CurlAuthData)).
381        *        As an output parameter it serves for sending username, pasword
382        *        or other special data (derived AuthData objects).
383        * \return true if user chooses to continue with authentication,
384        *         false otherwise
385        */
386       virtual bool prompt(const Url & /* url */,
387         const std::string & /* msg */,
388         AuthData & /* auth_data */)
389       {
390         return false;
391       }
392     };
393
394     /////////////////////////////////////////////////////////////////
395   } // namespace media
396   ///////////////////////////////////////////////////////////////////
397
398   ///////////////////////////////////////////////////////////////////
399   namespace target
400   {
401     /** Request to display the pre commit message of a patch. */
402     struct PatchMessageReport : public callback::ReportBase
403     {
404       /** Display \c patch->message().
405        * Return \c true to continue, \c false to abort commit.
406       */
407       virtual bool show( Patch::constPtr & /*patch*/ )
408       { return true; }
409     };
410
411     /** Indicate execution of a patch script. This is a sort of
412      * \c %post script shipped by a package and to be executed
413      * after the package was installed.
414     */
415     struct PatchScriptReport : public callback::ReportBase
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
424       /** Start executing the script provided by package.
425       */
426       virtual void start( const Package::constPtr & /*package*/,
427                           const Pathname & /*script path*/ )
428       {}
429       /** Progress provides the script output. If the script is quiet,
430        * from time to time still-alive pings are sent to the ui. Returning \c FALSE
431        * aborts script execution.
432       */
433       virtual bool progress( Notify /*OUTPUT or PING*/,
434                              const std::string & /*output*/ = std::string() )
435       { return true; }
436       /** Report error. */
437       virtual Action problem( const std::string & /*description*/ )
438       { return ABORT; }
439       /** Report success. */
440       virtual void finish()
441       {}
442     };
443
444     ///////////////////////////////////////////////////////////////////
445     namespace rpm
446     {
447
448       // progress for installing a resolvable
449       struct InstallResolvableReport : public callback::ReportBase
450       {
451         enum Action {
452           ABORT,  // abort and return error
453           RETRY,        // retry
454           IGNORE        // ignore the failure
455         };
456
457         enum Error {
458           NO_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
465         /** \deprecated We fortunately no longer do 3 attempts. */
466         enum RpmLevel {
467             RPM,
468             RPM_NODEPS,
469             RPM_NODEPS_FORCE
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
495       struct RemoveResolvableReport : public callback::ReportBase
496       {
497         enum Action {
498           ABORT,  // abort and return error
499           RETRY,        // retry
500           IGNORE        // ignore the failure
501         };
502
503         enum Error {
504           NO_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
531       struct RebuildDBReport : public callback::ReportBase
532       {
533         enum Action {
534           ABORT,  // abort and return error
535           RETRY,        // retry
536           IGNORE        // ignore the failure
537         };
538
539         enum Error {
540           NO_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
563       struct ConvertDBReport : public callback::ReportBase
564       {
565         enum Action {
566           ABORT,  // abort and return error
567           RETRY,        // retry
568           IGNORE        // ignore the failure
569         };
570
571         enum Error {
572           NO_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
596       /////////////////////////////////////////////////////////////////
597     } // namespace rpm
598     ///////////////////////////////////////////////////////////////////
599
600     /////////////////////////////////////////////////////////////////
601   } // namespace target
602   ///////////////////////////////////////////////////////////////////
603
604   class PoolQuery;
605
606   /** \name Locks */
607   //@{
608   /**
609    * Callback for cleaning locks which doesn't lock anything in pool.
610    */
611
612   struct CleanEmptyLocksReport : public callback::ReportBase
613   {
614     /**
615      * action performed by cleaning api to specific lock
616      */
617     enum Action {
618       ABORT,  /**< abort and return error */
619       DELETE, /**< delete empty lock    */
620       IGNORE  /**< skip empty lock */
621     };
622
623     /**
624      * result of cleaning
625      */
626     enum Error {
627       NO_ERROR, /**< no problem */
628       ABORTED /** cleaning aborted by user */
629     };
630
631     /**
632      * cleaning is started
633      */
634     virtual void start(
635     ) {}
636
637     /**
638      * progress of cleaning specifies in percents
639      * \return if continue
640      */
641     virtual bool progress(int /*value*/)
642     { return true; }
643
644     /**
645      * When find empty lock ask what to do with it
646      * \return action
647      */
648     virtual Action execute(
649         const PoolQuery& /*error*/
650      ) { return DELETE; }
651
652       /**
653        * cleaning is done
654        */
655      virtual void finish(
656        Error /*error*/
657       ) {}
658
659   };
660
661   /**
662    * this callback handles merging old locks with newly added or removed
663    */
664   struct SavingLocksReport : public callback::ReportBase
665   {
666     /**
667      * action for old lock which is in conflict
668      * \see ConflictState
669      */
670     enum Action {
671       ABORT,  /**< abort and return error*/
672       DELETE, /**< delete conflicted lock    */
673       IGNORE  /**< skip conflict lock */
674     };
675
676     /**
677      * result of merging
678      */
679     enum Error {
680       NO_ERROR, /**< no problem */
681       ABORTED  /**< cleaning aborted by user */
682     };
683
684     /**
685      * type of conflict of old and new lock
686      */
687     enum ConflictState{
688       SAME_RESULTS, /**< locks lock same item in pool but his parameters is different */
689       INTERSECT /**< locks lock some file and unlocking lock unlock only part
690       * of iti, so removing old lock can unlock more items in pool */
691     };
692
693     virtual void start() {}
694
695     /**
696      * merging still live
697      * \return if continue
698      */
699     virtual bool progress()
700     { return true; }
701
702     /**
703      * When user unlock something which is locked by non-identical query
704      */
705     virtual Action conflict(
706          const PoolQuery&, /**< problematic query*/
707        ConflictState
708      ) { return DELETE; }
709
710      virtual void finish(
711        Error /*error*/
712       ) {}
713   };
714
715
716   /////////////////////////////////////////////////////////////////
717 } // namespace zypp
718 ///////////////////////////////////////////////////////////////////
719
720 #endif // ZYPP_ZYPPCALLBACKS_H