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