1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/PoolItem.cc
13 #include "zypp/base/Logger.h"
14 #include "zypp/base/DefaultIntegral.h"
16 #include "zypp/PoolItem.h"
17 #include "zypp/ResPool.h"
18 #include "zypp/Package.h"
19 #include "zypp/VendorAttr.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////
29 // CLASS NAME : PoolItem::Impl
31 /** PoolItem implementation.
34 * \li \c >0 this uses \c _buddy status
35 * \li \c <0 this status used by \c -_buddy
42 Impl( ResObject::constPtr res_r,
43 const ResStatus & status_r )
45 , _resolvable( res_r )
48 ResStatus & status() const
49 { return _buddy > 0 ? PoolItem(buddy()).status() : _status; }
51 sat::Solvable buddy() const
54 return sat::Solvable::noSolvable;
56 return sat::Solvable( -_buddy );
57 return sat::Solvable( _buddy );
60 void setBuddy( sat::Solvable solv_r );
62 ResObject::constPtr resolvable() const
63 { return _resolvable; }
65 ResStatus & statusReset() const
67 _status.setLock( false, zypp::ResStatus::USER );
68 _status.resetTransact( zypp::ResStatus::USER );
73 bool isUndetermined() const
75 return status().isUndetermined();
78 bool isRelevant() const
80 return !status().isNonRelevant();
83 bool isSatisfied() const
85 return status().isSatisfied();
90 return status().isBroken();
95 return status().isToBeInstalled() || ( isBroken() && ! status().isLocked() );
98 bool isUnwanted() const
100 return isBroken() && status().isLocked();
104 mutable ResStatus _status;
105 ResObject::constPtr _resolvable;
106 DefaultIntegral<sat::detail::IdType,sat::detail::noId> _buddy;
108 /** \name Poor man's save/restore state.
109 * \todo There may be better save/restore state strategies.
113 void saveState() const
114 { _savedStatus = status(); }
115 void restoreState() const
116 { status() = _savedStatus; }
117 bool sameState() const
119 if ( status() == _savedStatus )
121 // some bits changed...
122 if ( status().getTransactValue() != _savedStatus.getTransactValue()
123 && ( ! status().isBySolver() // ignore solver state changes
124 // removing a user lock also goes to bySolver
125 || _savedStatus.getTransactValue() == ResStatus::LOCKED ) )
127 if ( status().isLicenceConfirmed() != _savedStatus.isLicenceConfirmed() )
132 mutable ResStatus _savedStatus;
136 /** Offer default Impl. */
137 static shared_ptr<Impl> nullimpl()
139 static shared_ptr<Impl> _nullimpl( new Impl );
143 ///////////////////////////////////////////////////////////////////
145 /** \relates PoolItem::Impl Stream output */
146 inline std::ostream & operator<<( std::ostream & str, const PoolItem::Impl & obj )
149 if (obj.resolvable())
150 str << *obj.resolvable();
156 inline void PoolItem::Impl::setBuddy( sat::Solvable solv_r )
158 PoolItem myBuddy( solv_r );
161 if ( myBuddy._pimpl->_buddy )
163 ERR << *this << " would be buddy2 in " << myBuddy << endl;
166 myBuddy._pimpl->_buddy = -resolvable()->satSolvable().id();
167 _buddy = myBuddy.satSolvable().id();
168 DBG << *this << " has buddy " << myBuddy << endl;
172 ///////////////////////////////////////////////////////////////////
174 // CLASS NAME : PoolItem
176 ///////////////////////////////////////////////////////////////////
178 ///////////////////////////////////////////////////////////////////
180 // METHOD NAME : PoolItem::PoolItem
181 // METHOD TYPE : Ctor
184 : _pimpl( Impl::nullimpl() )
187 ///////////////////////////////////////////////////////////////////
189 // METHOD NAME : PoolItem::PoolItem
190 // METHOD TYPE : Ctor
192 PoolItem::PoolItem( const sat::Solvable & solvable_r )
193 : _pimpl( ResPool::instance().find( solvable_r )._pimpl )
196 ///////////////////////////////////////////////////////////////////
198 // METHOD NAME : PoolItem::PoolItem
199 // METHOD TYPE : Ctor
201 PoolItem::PoolItem( const ResObject::constPtr & resolvable_r )
202 : _pimpl( ResPool::instance().find( resolvable_r )._pimpl )
205 ///////////////////////////////////////////////////////////////////
207 // METHOD NAME : PoolItem::PoolItem
208 // METHOD TYPE : Ctor
210 PoolItem::PoolItem( Impl * implptr_r )
211 : _pimpl( implptr_r )
214 ///////////////////////////////////////////////////////////////////
216 // METHOD NAME : PoolItem::makePoolItem
217 // METHOD TYPE : PoolItem
219 PoolItem PoolItem::makePoolItem( const sat::Solvable & solvable_r )
221 return PoolItem( new Impl( makeResObject( solvable_r ), solvable_r.isSystem() ) );
224 ///////////////////////////////////////////////////////////////////
226 // METHOD NAME : PoolItem::~PoolItem
227 // METHOD TYPE : Dtor
229 PoolItem::~PoolItem()
232 ///////////////////////////////////////////////////////////////////
234 // METHOD NAME : PoolItem::pool
235 // METHOD TYPE : ResPool
237 ResPool PoolItem::pool() const
238 { return ResPool::instance(); }
240 ///////////////////////////////////////////////////////////////////
244 ///////////////////////////////////////////////////////////////////
246 ResStatus & PoolItem::status() const
247 { return _pimpl->status(); }
249 ResStatus & PoolItem::statusReset() const
250 { return _pimpl->statusReset(); }
252 sat::Solvable PoolItem::buddy() const
253 { return _pimpl->buddy(); }
255 void PoolItem::setBuddy( sat::Solvable solv_r )
256 { _pimpl->setBuddy( solv_r ); }
258 bool PoolItem::isUndetermined() const
259 { return _pimpl->isUndetermined(); }
261 bool PoolItem::isRelevant() const
262 { return _pimpl->isRelevant(); }
264 bool PoolItem::isSatisfied() const
265 { return _pimpl->isSatisfied(); }
267 bool PoolItem::isBroken() const
268 { return _pimpl->isBroken(); }
270 bool PoolItem::isNeeded() const
271 { return _pimpl->isNeeded(); }
273 bool PoolItem::isUnwanted() const
274 { return _pimpl->isUnwanted(); }
276 void PoolItem::saveState() const
277 { _pimpl->saveState(); }
279 void PoolItem::restoreState() const
280 { _pimpl->restoreState(); }
282 bool PoolItem::sameState() const
283 { return _pimpl->sameState(); }
285 ResObject::constPtr PoolItem::resolvable() const
286 { return _pimpl->resolvable(); }
288 /******************************************************************
290 ** FUNCTION NAME : operator<<
291 ** FUNCTION TYPE : std::ostream &
293 std::ostream & operator<<( std::ostream & str, const PoolItem & obj )
295 return str << *obj._pimpl;
298 /////////////////////////////////////////////////////////////////
300 ///////////////////////////////////////////////////////////////////