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 
00015 #include "zypp/PoolItem.h"
00016 #include "zypp/Package.h"
00017 #include "zypp/SystemResObject.h"
00018 #include "zypp/VendorAttr.h"
00019 
00020 using std::endl;
00021 
00023 namespace zypp
00024 { 
00025 
00027   //
00028   //    CLASS NAME : PoolItem_Ref::Impl
00029   //
00031   struct PoolItem_Ref::Impl
00032   {
00033     Impl()
00034     {}
00035 
00036     Impl( ResObject::constPtr res_r,
00037           const ResStatus & status_r = ResStatus() )
00038     : _status( status_r )
00039     , _resolvable( res_r )
00040     {
00041       autoprotect();
00042     }
00043 
00044     ResStatus & status() const
00045     { return _status; }
00046 
00047     ResStatus & statusReset() const
00048     {
00049       if ( ! autoprotect() )
00050         {
00051           _status.setLock( false, zypp::ResStatus::USER );
00052           _status.resetTransact( zypp::ResStatus::USER );
00053         }
00054       return _status;
00055     }
00056 
00057     ResObject::constPtr resolvable() const
00058     { return _resolvable; }
00059 
00060     bool autoprotect() const;
00061 
00062   private:
00063     mutable ResStatus   _status;
00064     ResObject::constPtr _resolvable;
00065 
00070   public:
00071     void saveState() const
00072     { _savedStatus = _status; }
00073     void restoreState() const
00074     { _status = _savedStatus; }
00075     bool sameState() const
00076     {
00077       if (    _status.getTransactValue() != _savedStatus.getTransactValue()
00078            && !_status.isBySolver() )
00079         return false;
00080       if ( _status.isLicenceConfirmed() != _savedStatus.isLicenceConfirmed() )
00081         return false;
00082       return true;
00083     }
00084   private:
00085     mutable ResStatus _savedStatus;
00087 
00088   public:
00090     static shared_ptr<Impl> nullimpl()
00091     {
00092       static shared_ptr<Impl> _nullimpl( new Impl );
00093       return _nullimpl;
00094     }
00095   };
00097 
00099   inline std::ostream & operator<<( std::ostream & str, const PoolItem_Ref::Impl & obj )
00100   {
00101     str << obj.status();
00102     if (obj.resolvable())
00103         str << *obj.resolvable();
00104     else
00105         str << "(NULL)";
00106     return str;
00107   }
00108 
00109   inline bool PoolItem_Ref::Impl::autoprotect() const
00110   {
00111     // always lock System resolvable
00112     if ( isKind<SystemResObject>( _resolvable ) )
00113       {
00114         _status.setLock( true, zypp::ResStatus::USER );
00115         return true;
00116       }
00117 
00118     if ( _status.isInstalled()
00119          && isKind<Package>( _resolvable )
00120          && VendorAttr::instance().autoProtect( _resolvable->vendor() ) )
00121       {
00122         _status.setLock( true, zypp::ResStatus::USER );
00123         MIL << "Protect vendor '" << _resolvable->vendor() << "' " << *this << endl;
00124         return true;
00125       }
00126     return false;
00127   }
00128 
00130   //
00131   //    CLASS NAME : PoolItem_Ref
00132   //
00134 
00136   //
00137   //    METHOD NAME : PoolItem_Ref::PoolItem_Ref
00138   //    METHOD TYPE : Ctor
00139   //
00140   PoolItem_Ref::PoolItem_Ref()
00141   : _pimpl( Impl::nullimpl() )
00142   {}
00143 
00145   //
00146   //    METHOD NAME : PoolItem_Ref::PoolItem_Ref
00147   //    METHOD TYPE : Ctor
00148   //
00149   PoolItem_Ref::PoolItem_Ref( ResObject::constPtr res_r )
00150   : _pimpl( new Impl( res_r ) )
00151   {}
00152 
00154   //
00155   //    METHOD NAME : PoolItem_Ref::PoolItem_Ref
00156   //    METHOD TYPE : Ctor
00157   //
00158   PoolItem_Ref::PoolItem_Ref( ResObject::constPtr res_r, const ResStatus & status_r )
00159   : _pimpl( new Impl( res_r, status_r ) )
00160   {}
00161 
00163   //
00164   //    METHOD NAME : PoolItem_Ref::~PoolItem_Ref
00165   //    METHOD TYPE : Dtor
00166   //
00167   PoolItem_Ref::~PoolItem_Ref()
00168   {}
00169 
00171   //
00172   //    Forward to Impl:
00173   //
00175 
00176   ResStatus & PoolItem_Ref::status() const
00177   { return _pimpl->status(); }
00178 
00179   ResStatus & PoolItem_Ref::statusReset() const
00180   { return _pimpl->statusReset(); }
00181 
00182   ResObject::constPtr PoolItem_Ref::resolvable() const
00183   { return _pimpl->resolvable(); }
00184 
00185   void PoolItem_Ref::saveState() const
00186   { _pimpl->saveState(); }
00187 
00188   void PoolItem_Ref::restoreState() const
00189   { _pimpl->restoreState(); }
00190 
00191   bool PoolItem_Ref::sameState() const
00192   { return _pimpl->sameState(); }
00193 
00194   /******************************************************************
00195    **
00196    **   FUNCTION NAME : operator<<
00197    **   FUNCTION TYPE : std::ostream &
00198   */
00199   std::ostream & operator<<( std::ostream & str, const PoolItem_Ref & obj )
00200   {
00201     return str << *obj._pimpl;
00202   }
00203 
00205 } // namespace zypp

Generated on Thu Jul 6 00:07:22 2006 for zypp by  doxygen 1.4.6