Remove obsolete ResStatus bits.
[platform/upstream/libzypp.git] / zypp / PoolItem.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/PoolItem.cc
10  *
11 */
12 #include <iostream>
13 #include "zypp/base/Logger.h"
14 #include "zypp/base/DefaultIntegral.h"
15
16 #include "zypp/PoolItem.h"
17 #include "zypp/ResPool.h"
18 #include "zypp/Package.h"
19 #include "zypp/VendorAttr.h"
20
21 using std::endl;
22
23 ///////////////////////////////////////////////////////////////////
24 namespace zypp
25 { /////////////////////////////////////////////////////////////////
26
27   ///////////////////////////////////////////////////////////////////
28   //
29   //    CLASS NAME : PoolItem::Impl
30   //
31   /** PoolItem implementation.
32    * \c _buddy handling:
33    * \li \c ==0 no buddy
34    * \li \c >0 this uses \c _buddy status
35    * \li \c <0 this status used by \c -_buddy
36    */
37   struct PoolItem::Impl
38   {
39     public:
40       Impl() {}
41
42       Impl( ResObject::constPtr res_r,
43             const ResStatus & status_r )
44       : _status( status_r )
45       , _resolvable( res_r )
46       {}
47
48       ResStatus & status() const
49       { return _buddy > 0 ? PoolItem(buddy()).status() : _status; }
50
51       sat::Solvable buddy() const
52       {
53         if ( !_buddy )
54           return sat::Solvable::noSolvable;
55         if ( _buddy < 0 )
56           return sat::Solvable( -_buddy );
57         return sat::Solvable( _buddy );
58       }
59
60       void setBuddy( sat::Solvable solv_r );
61
62       ResObject::constPtr resolvable() const
63       { return _resolvable; }
64
65       ResStatus & statusReset() const
66       {
67         _status.setLock( false, zypp::ResStatus::USER );
68         _status.resetTransact( zypp::ResStatus::USER );
69         return _status;
70       }
71
72     public:
73       bool isUndetermined() const
74       {
75           return status().isUndetermined();
76       }
77
78       bool isRelevant() const
79       {
80           return !status().isNonRelevant();
81       }
82
83       bool isSatisfied() const
84       {
85           return status().isSatisfied();
86       }
87
88       bool isBroken() const
89       {
90           return status().isBroken();
91       }
92
93     private:
94       mutable ResStatus     _status;
95       ResObject::constPtr   _resolvable;
96       DefaultIntegral<sat::detail::IdType,sat::detail::noId> _buddy;
97
98     /** \name Poor man's save/restore state.
99        * \todo There may be better save/restore state strategies.
100      */
101     //@{
102     public:
103       void saveState() const
104       { _savedStatus = status(); }
105       void restoreState() const
106       { status() = _savedStatus; }
107       bool sameState() const
108       {
109         if ( status() == _savedStatus )
110           return true;
111         // some bits changed...
112         if ( status().getTransactValue() != _savedStatus.getTransactValue()
113              && ( ! status().isBySolver() // ignore solver state changes
114                   // removing a user lock also goes to bySolver
115                   || _savedStatus.getTransactValue() == ResStatus::LOCKED ) )
116           return false;
117         if ( status().isLicenceConfirmed() != _savedStatus.isLicenceConfirmed() )
118           return false;
119         return true;
120       }
121     private:
122       mutable ResStatus _savedStatus;
123     //@}
124
125     public:
126       /** Offer default Impl. */
127       static shared_ptr<Impl> nullimpl()
128       {
129         static shared_ptr<Impl> _nullimpl( new Impl );
130         return _nullimpl;
131       }
132   };
133   ///////////////////////////////////////////////////////////////////
134
135   /** \relates PoolItem::Impl Stream output */
136   inline std::ostream & operator<<( std::ostream & str, const PoolItem::Impl & obj )
137   {
138     str << obj.status();
139     if (obj.resolvable())
140         str << *obj.resolvable();
141     else
142         str << "(NULL)";
143     return str;
144   }
145
146   inline void PoolItem::Impl::setBuddy( sat::Solvable solv_r )
147   {
148     PoolItem myBuddy( solv_r );
149     if ( myBuddy )
150     {
151       myBuddy._pimpl->_buddy = -resolvable()->satSolvable().id();
152       _buddy = myBuddy.satSolvable().id();
153       DBG << *this << " has buddy " << myBuddy << endl;
154     }
155   }
156
157   ///////////////////////////////////////////////////////////////////
158   //
159   //    CLASS NAME : PoolItem
160   //
161   ///////////////////////////////////////////////////////////////////
162
163   ///////////////////////////////////////////////////////////////////
164   //
165   //    METHOD NAME : PoolItem::PoolItem
166   //    METHOD TYPE : Ctor
167   //
168   PoolItem::PoolItem()
169   : _pimpl( Impl::nullimpl() )
170   {}
171
172   ///////////////////////////////////////////////////////////////////
173   //
174   //    METHOD NAME : PoolItem::PoolItem
175   //    METHOD TYPE : Ctor
176   //
177   PoolItem::PoolItem( const sat::Solvable & solvable_r )
178   : _pimpl( ResPool::instance().find( solvable_r )._pimpl )
179   {}
180
181   ///////////////////////////////////////////////////////////////////
182   //
183   //    METHOD NAME : PoolItem::PoolItem
184   //    METHOD TYPE : Ctor
185   //
186   PoolItem::PoolItem( const ResObject::constPtr & resolvable_r )
187   : _pimpl( ResPool::instance().find( resolvable_r )._pimpl )
188   {}
189
190   ///////////////////////////////////////////////////////////////////
191   //
192   //    METHOD NAME : PoolItem::PoolItem
193   //    METHOD TYPE : Ctor
194   //
195   PoolItem::PoolItem( Impl * implptr_r )
196   : _pimpl( implptr_r )
197   {}
198
199   ///////////////////////////////////////////////////////////////////
200   //
201   //    METHOD NAME : PoolItem::makePoolItem
202   //    METHOD TYPE : PoolItem
203   //
204   PoolItem PoolItem::makePoolItem( const sat::Solvable & solvable_r )
205   {
206     return PoolItem( new Impl( makeResObject( solvable_r ), solvable_r.isSystem() ) );
207   }
208
209   ///////////////////////////////////////////////////////////////////
210   //
211   //    METHOD NAME : PoolItem::~PoolItem
212   //    METHOD TYPE : Dtor
213   //
214   PoolItem::~PoolItem()
215   {}
216
217   ///////////////////////////////////////////////////////////////////
218   //
219   //    METHOD NAME : PoolItem::pool
220   //    METHOD TYPE : ResPool
221   //
222   ResPool PoolItem::pool() const
223   { return ResPool::instance(); }
224
225   ///////////////////////////////////////////////////////////////////
226   //
227   //    Forward to Impl:
228   //
229   ///////////////////////////////////////////////////////////////////
230
231   ResStatus & PoolItem::status() const
232   { return _pimpl->status(); }
233
234   ResStatus & PoolItem::statusReset() const
235   { return _pimpl->statusReset(); }
236
237   sat::Solvable PoolItem::buddy() const
238   { return _pimpl->buddy(); }
239
240   void PoolItem::setBuddy( sat::Solvable solv_r )
241   { _pimpl->setBuddy( solv_r ); }
242
243   bool PoolItem::isUndetermined() const
244   { return _pimpl->isUndetermined(); }
245
246   bool PoolItem::isRelevant() const
247   { return _pimpl->isRelevant(); }
248
249   bool PoolItem::isSatisfied() const
250   { return _pimpl->isSatisfied(); }
251
252   bool PoolItem::isBroken() const
253   { return _pimpl->isBroken(); }
254
255   void PoolItem::saveState() const
256   { _pimpl->saveState(); }
257
258   void PoolItem::restoreState() const
259   { _pimpl->restoreState(); }
260
261   bool PoolItem::sameState() const
262   { return _pimpl->sameState(); }
263
264   ResObject::constPtr PoolItem::resolvable() const
265   { return _pimpl->resolvable(); }
266
267   /******************************************************************
268    **
269    **   FUNCTION NAME : operator<<
270    **   FUNCTION TYPE : std::ostream &
271   */
272   std::ostream & operator<<( std::ostream & str, const PoolItem & obj )
273   {
274     return str << *obj._pimpl;
275   }
276
277   /////////////////////////////////////////////////////////////////
278 } // namespace zypp
279 ///////////////////////////////////////////////////////////////////