Imported Upstream version 17.23.5
[platform/upstream/libzypp.git] / zypp / target / TargetCallbackReceiver.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/target/TargetCallbackReceiver.cc
10  *
11 */
12 #include <iostream>
13
14 #include <zypp/target/TargetCallbackReceiver.h>
15
16 #include <zypp/target/rpm/RpmCallbacks.h>
17
18 ///////////////////////////////////////////////////////////////////
19 namespace zypp
20 { /////////////////////////////////////////////////////////////////
21   ///////////////////////////////////////////////////////////////////
22   namespace target
23   { /////////////////////////////////////////////////////////////////
24
25         RpmInstallPackageReceiver::RpmInstallPackageReceiver (Resolvable::constPtr res)
26             : callback::ReceiveReport<rpm::RpmInstallReport> ()
27             , _resolvable (res)
28             , _level( target::rpm::InstallResolvableReport::RPM )
29             , _abort (false)
30         {
31         }
32
33         RpmInstallPackageReceiver::~RpmInstallPackageReceiver ()
34         {
35         }
36
37         void RpmInstallPackageReceiver::reportbegin()
38         {
39         }
40
41         void RpmInstallPackageReceiver::reportend()
42         {
43         }
44
45         /** Start the operation */
46         void RpmInstallPackageReceiver::start( const Pathname & name )
47         {
48             _report->start( _resolvable );
49             _abort = false;
50         }
51
52         /**
53          * Inform about progress
54          * Return true on abort
55          */
56         bool RpmInstallPackageReceiver::progress( unsigned percent )
57         {
58             _abort = ! _report->progress( percent, _resolvable );
59             return _abort;
60         }
61
62         rpm::RpmInstallReport::Action
63         RpmInstallPackageReceiver::problem( Exception & excpt_r )
64         {
65             rpm::InstallResolvableReport::Action user =
66                 _report->problem( _resolvable
67                     , rpm::InstallResolvableReport::INVALID
68                     , excpt_r.asUserHistory()
69                     , _level
70                 );
71
72             switch (user) {
73                 case rpm::InstallResolvableReport::RETRY:
74                     return rpm::RpmInstallReport::RETRY;
75                 case rpm::InstallResolvableReport::ABORT:
76                     _abort = true;
77                     return rpm::RpmInstallReport::ABORT;
78                 case rpm::InstallResolvableReport::IGNORE:
79                     return rpm::RpmInstallReport::IGNORE;
80             }
81
82             return rpm::RpmInstallReport::problem( excpt_r );
83         }
84
85         void RpmInstallPackageReceiver::finishInfo( const std::string & info_r )
86         {
87           _finishInfo = info_r;
88         }
89
90         /** Finish operation in case of success */
91         void RpmInstallPackageReceiver::finish()
92         {
93             _report->finish( _resolvable, rpm::InstallResolvableReport::NO_ERROR, _finishInfo, _level );
94         }
95
96         /** Finish operation in case of success */
97         void RpmInstallPackageReceiver::finish( Exception & excpt_r )
98         {
99             _report->finish( _resolvable, rpm::InstallResolvableReport::INVALID, std::string(), _level );
100         }
101
102         void RpmInstallPackageReceiver::tryLevel( target::rpm::InstallResolvableReport::RpmLevel level_r )
103         {
104             _level = level_r;
105         }
106
107
108         /////////////////////////////////////////////////////////////////
109         ///  RpmRemovePackageReceiver
110         /////////////////////////////////////////////////////////////////
111
112         RpmRemovePackageReceiver::RpmRemovePackageReceiver (Resolvable::constPtr res)
113             : callback::ReceiveReport<rpm::RpmRemoveReport> ()
114             , _resolvable (res)
115             , _abort(false)
116         {
117         }
118
119         RpmRemovePackageReceiver::~RpmRemovePackageReceiver ()
120         {
121         }
122
123         void RpmRemovePackageReceiver::reportbegin()
124         {
125         }
126
127         void RpmRemovePackageReceiver::reportend()
128         {
129         }
130
131         /** Start the operation */
132         void RpmRemovePackageReceiver::start( const std::string & name )
133         {
134             _report->start( _resolvable );
135             _abort = false;
136         }
137
138         /**
139          * Inform about progress
140          * Return true on abort
141          */
142         bool RpmRemovePackageReceiver::progress( unsigned percent )
143         {
144             _abort = ! _report->progress( percent, _resolvable );
145             return _abort;
146         }
147
148         rpm::RpmRemoveReport::Action
149         RpmRemovePackageReceiver::problem( Exception & excpt_r )
150         {
151             rpm::RemoveResolvableReport::Action user =
152                 _report->problem( _resolvable
153                     , rpm::RemoveResolvableReport::INVALID
154                     , excpt_r.asUserHistory()
155                 );
156
157             switch (user) {
158                 case rpm::RemoveResolvableReport::RETRY:
159                     return rpm::RpmRemoveReport::RETRY;
160                 case rpm::RemoveResolvableReport::ABORT:
161                     _abort = true;
162                     return rpm::RpmRemoveReport::ABORT;
163                 case rpm::RemoveResolvableReport::IGNORE:
164                     return rpm::RpmRemoveReport::IGNORE;
165             }
166
167             return rpm::RpmRemoveReport::problem( excpt_r );
168         }
169
170         void RpmRemovePackageReceiver::finishInfo( const std::string & info_r )
171         {
172           _finishInfo = info_r;
173         }
174
175         /** Finish operation in case of success */
176         void RpmRemovePackageReceiver::finish()
177         {
178             _report->progress( 100, _resolvable );
179             _report->finish( _resolvable, rpm::RemoveResolvableReport::NO_ERROR, _finishInfo );
180         }
181
182         /** Finish operation in case of success */
183         void RpmRemovePackageReceiver::finish( Exception & excpt_r )
184         {
185             _report->finish( _resolvable, rpm::RemoveResolvableReport::INVALID, std::string() );
186         }
187
188     /////////////////////////////////////////////////////////////////
189   } // namespace target
190   ///////////////////////////////////////////////////////////////////
191
192   /////////////////////////////////////////////////////////////////
193 } // namespace zypp
194 ///////////////////////////////////////////////////////////////////