1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/detail/PoolImpl.h
12 #ifndef ZYPP_SAT_DETAIL_POOLIMPL_H
13 #define ZYPP_SAT_DETAIL_POOLIMPL_H
16 #include <satsolver/pool.h>
17 #include <satsolver/repo.h>
18 #include <satsolver/solvable.h>
19 #include <satsolver/poolarch.h>
20 #include <satsolver/repo_solv.h>
24 #include "zypp/base/Tr1hash.h"
25 #include "zypp/base/NonCopyable.h"
26 #include "zypp/base/SerialNumber.h"
27 #include "zypp/sat/detail/PoolMember.h"
28 #include "zypp/RepoInfo.h"
29 #include "zypp/Locale.h"
30 #include "zypp/Capability.h"
31 #include "zypp/IdString.h"
33 ///////////////////////////////////////////////////////////////////
35 { /////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////
38 { /////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////
41 { /////////////////////////////////////////////////////////////////
43 ///////////////////////////////////////////////////////////////////
45 // CLASS NAME : PoolImpl
48 class PoolImpl : private base::NonCopyable
57 /** Pointer style access forwarded to sat-pool. */
58 ::_Pool * operator->()
62 /** Serial number changing whenever the content changes. */
63 const SerialNumber & serial() const
66 /** Update housekeeping data (e.g. whatprovides).
67 * \todo actually requires a watcher.
72 /** Invalidate housekeeping data (e.g. whatprovides) if the
73 * pools content changed.
75 void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
77 /** Invalidate housekeeping data (e.g. whatprovides) if dependencies changed.
79 void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
81 /** Callback to resolve namespace dependencies (language, modalias, filesystem, etc.). */
82 static detail::IdType nsCallback( ::_Pool *, void * data, detail::IdType lhs, detail::IdType rhs );
85 /** Reserved system repository alias \c @System. */
86 static const std::string & systemRepoAlias();
88 bool isSystemRepo( ::_Repo * repo_r ) const
89 { return repo_r && _pool->installed == repo_r; }
91 ::_Repo * systemRepo() const
92 { return _pool->installed; }
95 /** \name Actions invalidating housekeeping data.
97 * All methods expect valid arguments being passed.
100 /** Creating a new repo named \a name_r. */
101 ::_Repo * _createRepo( const std::string & name_r );
103 /** Creating a new repo named \a name_r. */
104 void _deleteRepo( ::_Repo * repo_r );
106 /** Adding solv file to a repo.
107 * Except for \c isSystemRepo_r, solvables of incompatible architecture
110 int _addSolv( ::_Repo * repo_r, FILE * file_r );
112 /** Adding helix file to a repo.
113 * Except for \c isSystemRepo_r, solvables of incompatible architecture
116 int _addHelix( ::_Repo * repo_r, FILE * file_r );
118 /** Adding Solvables to a repo. */
119 detail::SolvableIdType _addSolvables( ::_Repo * repo_r, unsigned count_r );
122 /** Helper postprocessing the repo aftr adding solv or helix files. */
123 void _postRepoAdd( ::_Repo * repo_r );
126 /** a \c valid \ref Solvable has a non NULL repo pointer. */
127 bool validSolvable( const ::_Solvable & slv_r ) const
128 { return slv_r.repo; }
129 /** \overload Check also for id_r being in range of _pool->solvables. */
130 bool validSolvable( SolvableIdType id_r ) const
131 { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
132 /** \overload Check also for slv_r being in range of _pool->solvables. */
133 bool validSolvable( const ::_Solvable * slv_r ) const
134 { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
137 ::_Pool * getPool() const
140 /** \todo a quick check whether the repo was meanwhile deleted. */
141 ::_Repo * getRepo( RepoIdType id_r ) const
144 /** Return pointer to the sat-solvable or NULL if it is not valid.
145 * \see \ref validSolvable.
147 ::_Solvable * getSolvable( SolvableIdType id_r ) const
149 if ( validSolvable( id_r ) )
150 return &_pool->solvables[id_r];
155 /** Get id of the first valid \ref Solvable.
156 * This is the next valid after the system solvable.
158 SolvableIdType getFirstId() const
159 { return getNextId( 1 ); }
161 /** Get id of the next valid \ref Solvable.
162 * This goes round robbin. At the end it returns \ref noSolvableId.
163 * Passing \ref noSolvableId it returns the 1st valid \ref Solvable.
164 * \see \ref validSolvable.
166 SolvableIdType getNextId( SolvableIdType id_r ) const
168 for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
170 if ( validSolvable( _pool->solvables[id_r] ) )
178 const RepoInfo & repoInfo( RepoIdType id_r )
179 { return _repoinfos[id_r]; }
181 void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r )
182 { _repoinfos[id_r] = info_r; }
184 void eraseRepoInfo( RepoIdType id_r )
185 { _repoinfos.erase( id_r ); }
188 /** Returns the id stored at \c offset_r in the internal
189 * whatprovidesdata array.
191 const sat::detail::IdType whatProvidesData( unsigned offset_r )
192 { return _pool->whatprovidesdata[offset_r]; }
194 /** Returns offset into the internal whatprovidesdata array.
195 * Use \ref whatProvidesData to get the stored Id.
197 unsigned whatProvides( Capability cap_r )
198 { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
201 /** \name Requested locales. */
203 void setRequestedLocales( const LocaleSet & locales_r );
204 bool addRequestedLocale( const Locale & locale_r );
205 bool eraseRequestedLocale( const Locale & locale_r );
207 const LocaleSet & getRequestedLocales() const
208 { return _requestedLocales; }
210 bool isRequestedLocale( const Locale & locale_r ) const
212 LocaleSet::const_iterator it( _requestedLocales.find( locale_r ) );
213 return it != _requestedLocales.end();
216 const LocaleSet & getAvailableLocales() const;
218 bool isAvailableLocale( const Locale & locale_r ) const
220 const LocaleSet & avl( getAvailableLocales() );
221 LocaleSet::const_iterator it( avl.find( locale_r ) );
222 return it != avl.end();
229 /** Serial number. */
230 SerialNumber _serial;
231 /** Watch serial number. */
232 SerialNumberWatcher _watcher;
233 /** Additional \ref RepoInfo. */
234 std::map<RepoIdType,RepoInfo> _repoinfos;
237 LocaleSet _requestedLocales;
238 mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
239 mutable std::tr1::unordered_set<IdString> _locale2Solver;
241 ///////////////////////////////////////////////////////////////////
243 /////////////////////////////////////////////////////////////////
244 } // namespace detail
245 ///////////////////////////////////////////////////////////////////
246 /////////////////////////////////////////////////////////////////
248 ///////////////////////////////////////////////////////////////////
249 /////////////////////////////////////////////////////////////////
251 ///////////////////////////////////////////////////////////////////
252 #define POOL_SETDIRTY
253 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H