libzypp  10.5.0
PoolItem.cc
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 #include "zypp/base/Logger.h"
00014 #include "zypp/base/DefaultIntegral.h"
00015 
00016 #include "zypp/PoolItem.h"
00017 #include "zypp/ResPool.h"
00018 #include "zypp/Package.h"
00019 #include "zypp/VendorAttr.h"
00020 
00021 using std::endl;
00022 
00024 namespace zypp
00025 { 
00026 
00028   //
00029   //    CLASS NAME : PoolItem::Impl
00030   //
00037   struct PoolItem::Impl
00038   {
00039     public:
00040       Impl() {}
00041 
00042       Impl( ResObject::constPtr res_r,
00043             const ResStatus & status_r )
00044       : _status( status_r )
00045       , _resolvable( res_r )
00046       {}
00047 
00048       ResStatus & status() const
00049       { return _buddy > 0 ? PoolItem(buddy()).status() : _status; }
00050 
00051       sat::Solvable buddy() const
00052       {
00053         if ( !_buddy )
00054           return sat::Solvable::noSolvable;
00055         if ( _buddy < 0 )
00056           return sat::Solvable( -_buddy );
00057         return sat::Solvable( _buddy );
00058       }
00059 
00060       void setBuddy( sat::Solvable solv_r );
00061 
00062       ResObject::constPtr resolvable() const
00063       { return _resolvable; }
00064 
00065       ResStatus & statusReset() const
00066       {
00067         _status.setLock( false, zypp::ResStatus::USER );
00068         _status.resetTransact( zypp::ResStatus::USER );
00069         return _status;
00070       }
00071 
00072     public:
00073       bool isUndetermined() const
00074       {
00075           return status().isUndetermined();
00076       }
00077 
00078       bool isRelevant() const
00079       {
00080           return !status().isNonRelevant();
00081       }
00082 
00083       bool isSatisfied() const
00084       {
00085           return status().isSatisfied();
00086       }
00087 
00088       bool isBroken() const
00089       {
00090           return status().isBroken();
00091       }
00092 
00093       bool isNeeded() const
00094       {
00095         return status().isToBeInstalled() || ( isBroken() && ! status().isLocked() );
00096       }
00097 
00098       bool isUnwanted() const
00099       {
00100         return isBroken() && status().isLocked();
00101       }
00102 
00103     private:
00104       mutable ResStatus     _status;
00105       ResObject::constPtr   _resolvable;
00106       DefaultIntegral<sat::detail::IdType,sat::detail::noId> _buddy;
00107 
00112     public:
00113       void saveState() const
00114       { _savedStatus = status(); }
00115       void restoreState() const
00116       { status() = _savedStatus; }
00117       bool sameState() const
00118       {
00119         if ( status() == _savedStatus )
00120           return true;
00121         // some bits changed...
00122         if ( status().getTransactValue() != _savedStatus.getTransactValue()
00123              && ( ! status().isBySolver() // ignore solver state changes
00124                   // removing a user lock also goes to bySolver
00125                   || _savedStatus.getTransactValue() == ResStatus::LOCKED ) )
00126           return false;
00127         if ( status().isLicenceConfirmed() != _savedStatus.isLicenceConfirmed() )
00128           return false;
00129         return true;
00130       }
00131     private:
00132       mutable ResStatus _savedStatus;
00134 
00135     public:
00137       static shared_ptr<Impl> nullimpl()
00138       {
00139         static shared_ptr<Impl> _nullimpl( new Impl );
00140         return _nullimpl;
00141       }
00142   };
00144 
00146   inline std::ostream & operator<<( std::ostream & str, const PoolItem::Impl & obj )
00147   {
00148     str << obj.status();
00149     if (obj.resolvable())
00150         str << *obj.resolvable();
00151     else
00152         str << "(NULL)";
00153     return str;
00154   }
00155 
00156   inline void PoolItem::Impl::setBuddy( sat::Solvable solv_r )
00157   {
00158     PoolItem myBuddy( solv_r );
00159     if ( myBuddy )
00160     {
00161       myBuddy._pimpl->_buddy = -resolvable()->satSolvable().id();
00162       _buddy = myBuddy.satSolvable().id();
00163       DBG << *this << " has buddy " << myBuddy << endl;
00164     }
00165   }
00166 
00168   //
00169   //    CLASS NAME : PoolItem
00170   //
00172 
00174   //
00175   //    METHOD NAME : PoolItem::PoolItem
00176   //    METHOD TYPE : Ctor
00177   //
00178   PoolItem::PoolItem()
00179   : _pimpl( Impl::nullimpl() )
00180   {}
00181 
00183   //
00184   //    METHOD NAME : PoolItem::PoolItem
00185   //    METHOD TYPE : Ctor
00186   //
00187   PoolItem::PoolItem( const sat::Solvable & solvable_r )
00188   : _pimpl( ResPool::instance().find( solvable_r )._pimpl )
00189   {}
00190 
00192   //
00193   //    METHOD NAME : PoolItem::PoolItem
00194   //    METHOD TYPE : Ctor
00195   //
00196   PoolItem::PoolItem( const ResObject::constPtr & resolvable_r )
00197   : _pimpl( ResPool::instance().find( resolvable_r )._pimpl )
00198   {}
00199 
00201   //
00202   //    METHOD NAME : PoolItem::PoolItem
00203   //    METHOD TYPE : Ctor
00204   //
00205   PoolItem::PoolItem( Impl * implptr_r )
00206   : _pimpl( implptr_r )
00207   {}
00208 
00210   //
00211   //    METHOD NAME : PoolItem::makePoolItem
00212   //    METHOD TYPE : PoolItem
00213   //
00214   PoolItem PoolItem::makePoolItem( const sat::Solvable & solvable_r )
00215   {
00216     return PoolItem( new Impl( makeResObject( solvable_r ), solvable_r.isSystem() ) );
00217   }
00218 
00220   //
00221   //    METHOD NAME : PoolItem::~PoolItem
00222   //    METHOD TYPE : Dtor
00223   //
00224   PoolItem::~PoolItem()
00225   {}
00226 
00228   //
00229   //    METHOD NAME : PoolItem::pool
00230   //    METHOD TYPE : ResPool
00231   //
00232   ResPool PoolItem::pool() const
00233   { return ResPool::instance(); }
00234 
00236   //
00237   //    Forward to Impl:
00238   //
00240 
00241   ResStatus & PoolItem::status() const
00242   { return _pimpl->status(); }
00243 
00244   ResStatus & PoolItem::statusReset() const
00245   { return _pimpl->statusReset(); }
00246 
00247   sat::Solvable PoolItem::buddy() const
00248   { return _pimpl->buddy(); }
00249 
00250   void PoolItem::setBuddy( sat::Solvable solv_r )
00251   { _pimpl->setBuddy( solv_r ); }
00252 
00253   bool PoolItem::isUndetermined() const
00254   { return _pimpl->isUndetermined(); }
00255 
00256   bool PoolItem::isRelevant() const
00257   { return _pimpl->isRelevant(); }
00258 
00259   bool PoolItem::isSatisfied() const
00260   { return _pimpl->isSatisfied(); }
00261 
00262   bool PoolItem::isBroken() const
00263   { return _pimpl->isBroken(); }
00264 
00265   bool PoolItem::isNeeded() const
00266   { return _pimpl->isNeeded(); }
00267 
00268   bool PoolItem::isUnwanted() const
00269   { return _pimpl->isUnwanted(); }
00270 
00271   void PoolItem::saveState() const
00272   { _pimpl->saveState(); }
00273 
00274   void PoolItem::restoreState() const
00275   { _pimpl->restoreState(); }
00276 
00277   bool PoolItem::sameState() const
00278   { return _pimpl->sameState(); }
00279 
00280   ResObject::constPtr PoolItem::resolvable() const
00281   { return _pimpl->resolvable(); }
00282 
00283   /******************************************************************
00284    **
00285    **   FUNCTION NAME : operator<<
00286    **   FUNCTION TYPE : std::ostream &
00287   */
00288   std::ostream & operator<<( std::ostream & str, const PoolItem & obj )
00289   {
00290     return str << *obj._pimpl;
00291   }
00292 
00294 } // namespace zypp