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
146 bool softLockAppliesTo( sat::Solvable solv_r ) const
151 const ContainerT & store() const
156 sat::Pool pool( satpool() );
158 if ( pool.capacity() != _store.capacity() )
160 _store.resize( pool.capacity() );
163 if ( pool.capacity() )
165 for ( sat::detail::SolvableIdType i = pool.capacity()-1; i != 0; --i )
167 sat::Solvable s( i );
168 PoolItem & pi( _store[i] );
171 // the PoolItem got invalidated (e.g unloaded repo)
174 else if ( s && ! pi )
176 // new PoolItem to add
177 pi = PoolItem::makePoolItem( s ); // the only way to create a new one!
178 // and a few checks...
179 if ( hardLockAppliesTo( s ) )
181 pi.status().setLock( true, ResStatus::USER );
183 else if ( softLockAppliesTo( s ) )
185 pi.status().setSoftLock( ResStatus::USER );
195 const Id2ItemT & id2item () const
201 _id2item = Id2ItemT( size() );
202 for_( it, begin(), end() )
204 const sat::Solvable &s = (*it)->satSolvable();
205 sat::detail::IdType id = s.ident().id();
206 if ( s.isKind( ResKind::srcpackage ) )
208 _id2item.insert( std::make_pair( id, *it ) );
210 //INT << _id2item << endl;
211 _id2itemDirty = false;
217 ///////////////////////////////////////////////////////////////////
219 ///////////////////////////////////////////////////////////////////
221 void checkSerial() const
223 if ( _watcher.remember( serial() ) )
225 satpool().prepare(); // always ajust dependencies.
228 void invalidate() const
231 _id2itemDirty = true;
237 /** Watch sat pools serial number. */
238 SerialNumberWatcher _watcher;
239 mutable ContainerT _store;
240 mutable DefaultIntegral<bool,true> _storeDirty;
241 mutable Id2ItemT _id2item;
242 mutable DefaultIntegral<bool,true> _id2itemDirty;
245 mutable shared_ptr<ResPoolProxy> _poolProxy;
247 ///////////////////////////////////////////////////////////////////
249 /////////////////////////////////////////////////////////////////
251 ///////////////////////////////////////////////////////////////////
252 /////////////////////////////////////////////////////////////////
254 ///////////////////////////////////////////////////////////////////
255 #endif // ZYPP_POOL_POOLIMPL_H