1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/pool/PoolImpl.h
12 #ifndef ZYPP_POOL_POOLIMPL_H
13 #define ZYPP_POOL_POOLIMPL_H
17 #include "zypp/base/Easy.h"
18 #include "zypp/base/LogTools.h"
19 #include "zypp/base/SerialNumber.h"
20 #include "zypp/base/Deprecated.h"
22 #include "zypp/pool/PoolTraits.h"
23 #include "zypp/ResPoolProxy.h"
25 #include "zypp/sat/Pool.h"
29 ///////////////////////////////////////////////////////////////////
31 { /////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 { /////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////
38 // CLASS NAME : PoolImpl
43 friend std::ostream & operator<<( std::ostream & str, const PoolImpl & obj );
47 typedef PoolTraits::ItemContainerT ContainerT;
48 typedef PoolTraits::size_type size_type;
49 typedef PoolTraits::const_iterator const_iterator;
50 typedef PoolTraits::Id2ItemT Id2ItemT;
52 typedef PoolTraits::repository_iterator repository_iterator;
54 typedef sat::detail::SolvableIdType SolvableIdType;
64 const sat::Pool satpool() const
65 { return sat::Pool::instance(); }
67 /** Housekeeping data serial number. */
68 const SerialNumber & serial() const
69 { return satpool().serial(); }
71 ///////////////////////////////////////////////////////////////////
73 ///////////////////////////////////////////////////////////////////
77 { return satpool().solvablesEmpty(); }
80 size_type size() const
81 { return satpool().solvablesSize(); }
83 const_iterator begin() const
84 { return make_filter_begin( pool::ByPoolItem(), store() ); }
86 const_iterator end() const
87 { return make_filter_end( pool::ByPoolItem(), store() ); }
90 /** Return the corresponding \ref PoolItem.
91 * Pool and sat pool should be in sync. Returns an empty
92 * \ref PoolItem if there is no corresponding \ref PoolItem.
93 * \see \ref PoolItem::satSolvable.
95 PoolItem find( const sat::Solvable & slv_r ) const
97 const ContainerT & mystore( store() );
98 return( slv_r.id() < mystore.size() ? mystore[slv_r.id()] : PoolItem() );
101 ///////////////////////////////////////////////////////////////////
103 ///////////////////////////////////////////////////////////////////
105 /** \name Save and restore state. */
107 void SaveState( const ResObject::Kind & kind_r );
109 void RestoreState( const ResObject::Kind & kind_r );
112 ///////////////////////////////////////////////////////////////////
114 ///////////////////////////////////////////////////////////////////
116 ResPoolProxy proxy( ResPool self ) const
121 _poolProxy.reset( new ResPoolProxy( self, *this ) );
127 /** Forward list of Repositories that contribute ResObjects from \ref sat::Pool */
128 size_type knownRepositoriesSize() const
129 { checkSerial(); return satpool().reposSize(); }
131 repository_iterator knownRepositoriesBegin() const
132 { checkSerial(); return satpool().reposBegin(); }
134 repository_iterator knownRepositoriesEnd() const
135 { checkSerial(); return satpool().reposEnd(); }
137 ///////////////////////////////////////////////////////////////////
139 ///////////////////////////////////////////////////////////////////
141 bool hardLockAppliesTo( sat::Solvable solv_r ) const
147 typedef PoolTraits::AutoSoftLocks AutoSoftLocks;
148 typedef PoolTraits::autoSoftLocks_iterator autoSoftLocks_iterator;
150 const AutoSoftLocks & autoSoftLocks() const
151 { return _autoSoftLocks; }
153 bool autoSoftLockAppliesTo( sat::Solvable solv_r ) const
154 { return( _autoSoftLocks.find( solv_r.ident() ) != _autoSoftLocks.end() ); }
156 void setAutoSoftLocks( const AutoSoftLocks & newLocks_r )
158 MIL << "Apply " << newLocks_r.size() << " AutoSoftLocks: " << newLocks_r << endl;
159 _autoSoftLocks = newLocks_r;
160 // now adjust the pool status
161 for_( it, begin(), end() )
163 if ( ! it->status().isKept() )
166 if ( newLocks_r.find( it->satSolvable().ident() ) != newLocks_r.end() )
167 it->status().setSoftLock( ResStatus::USER );
169 it->status().resetTransact( ResStatus::USER );
173 void getActiveSoftLocks( AutoSoftLocks & activeLocks_r )
175 activeLocks_r = _autoSoftLocks; // currentsoft-locks
176 AutoSoftLocks todel; // + names to be deleted
177 AutoSoftLocks toins; // - names to be installed
179 for_( it, begin(), end() )
181 ResStatus & status( it->status() );
182 if ( ! status.isByUser() )
185 switch ( status.getTransactValue() )
187 case ResStatus::KEEP_STATE:
188 activeLocks_r.insert( it->satSolvable().ident() );
190 case ResStatus::LOCKED:
193 case ResStatus::TRANSACT:
194 (status.isInstalled() ? todel : toins).insert( it->satSolvable().ident() );
198 for_( it, todel.begin(), todel.end() )
200 activeLocks_r.insert( *it );
202 for_( it, toins.begin(), toins.end() )
204 activeLocks_r.erase( *it );
209 const ContainerT & store() const
214 sat::Pool pool( satpool() );
216 if ( pool.capacity() != _store.capacity() )
218 _store.resize( pool.capacity() );
221 if ( pool.capacity() )
223 for ( sat::detail::SolvableIdType i = pool.capacity()-1; i != 0; --i )
225 sat::Solvable s( i );
226 PoolItem & pi( _store[i] );
229 // the PoolItem got invalidated (e.g unloaded repo)
232 else if ( s && ! pi )
234 // new PoolItem to add
235 pi = PoolItem::makePoolItem( s ); // the only way to create a new one!
236 // and a few checks...
237 if ( hardLockAppliesTo( s ) )
239 pi.status().setLock( true, ResStatus::USER );
241 else if ( autoSoftLockAppliesTo( s ) )
243 pi.status().setSoftLock( ResStatus::USER );
253 const Id2ItemT & id2item () const
259 _id2item = Id2ItemT( size() );
260 for_( it, begin(), end() )
262 const sat::Solvable &s = (*it)->satSolvable();
263 sat::detail::IdType id = s.ident().id();
264 if ( s.isKind( ResKind::srcpackage ) )
266 _id2item.insert( std::make_pair( id, *it ) );
268 //INT << _id2item << endl;
269 _id2itemDirty = false;
274 ///////////////////////////////////////////////////////////////////
276 ///////////////////////////////////////////////////////////////////
278 void checkSerial() const
280 if ( _watcher.remember( serial() ) )
282 satpool().prepare(); // always ajust dependencies.
285 void invalidate() const
288 _id2itemDirty = true;
294 /** Watch sat pools serial number. */
295 SerialNumberWatcher _watcher;
296 mutable ContainerT _store;
297 mutable DefaultIntegral<bool,true> _storeDirty;
298 mutable Id2ItemT _id2item;
299 mutable DefaultIntegral<bool,true> _id2itemDirty;
302 mutable shared_ptr<ResPoolProxy> _poolProxy;
305 /** Set of solvable idents that should be soft locked per default. */
306 AutoSoftLocks _autoSoftLocks;
308 ///////////////////////////////////////////////////////////////////
310 /////////////////////////////////////////////////////////////////
312 ///////////////////////////////////////////////////////////////////
313 /////////////////////////////////////////////////////////////////
315 ///////////////////////////////////////////////////////////////////
316 #endif // ZYPP_POOL_POOLIMPL_H