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 <solv/pool.h>
17 #include <solv/repo.h>
18 #include <solv/solvable.h>
19 #include <solv/poolarch.h>
20 #include <solv/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.
70 /** \ref prepare plus some expensive checks done before solving only. */
71 void prepareForSolving() const;
74 /** Invalidate housekeeping data (e.g. whatprovides) if the
75 * pools content changed.
77 void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
79 /** Invalidate housekeeping data (e.g. whatprovides) if dependencies changed.
81 void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
83 /** Callback to resolve namespace dependencies (language, modalias, filesystem, etc.). */
84 static detail::IdType nsCallback( ::_Pool *, void * data, detail::IdType lhs, detail::IdType rhs );
87 /** Reserved system repository alias \c @System. */
88 static const std::string & systemRepoAlias();
90 bool isSystemRepo( ::_Repo * repo_r ) const
91 { return repo_r && _pool->installed == repo_r; }
93 ::_Repo * systemRepo() const
94 { return _pool->installed; }
97 /** \name Actions invalidating housekeeping data.
99 * All methods expect valid arguments being passed.
102 /** Creating a new repo named \a name_r. */
103 ::_Repo * _createRepo( const std::string & name_r );
105 /** Creating a new repo named \a name_r. */
106 void _deleteRepo( ::_Repo * repo_r );
108 /** Adding solv file to a repo.
109 * Except for \c isSystemRepo_r, solvables of incompatible architecture
112 int _addSolv( ::_Repo * repo_r, FILE * file_r );
114 /** Adding helix file to a repo.
115 * Except for \c isSystemRepo_r, solvables of incompatible architecture
118 int _addHelix( ::_Repo * repo_r, FILE * file_r );
120 /** Adding Solvables to a repo. */
121 detail::SolvableIdType _addSolvables( ::_Repo * repo_r, unsigned count_r );
124 /** Helper postprocessing the repo after adding solv or helix files. */
125 void _postRepoAdd( ::_Repo * repo_r );
128 /** a \c valid \ref Solvable has a non NULL repo pointer. */
129 bool validSolvable( const ::_Solvable & slv_r ) const
130 { return slv_r.repo; }
131 /** \overload Check also for id_r being in range of _pool->solvables. */
132 bool validSolvable( SolvableIdType id_r ) const
133 { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
134 /** \overload Check also for slv_r being in range of _pool->solvables. */
135 bool validSolvable( const ::_Solvable * slv_r ) const
136 { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
139 ::_Pool * getPool() const
142 /** \todo a quick check whether the repo was meanwhile deleted. */
143 ::_Repo * getRepo( RepoIdType id_r ) const
146 /** Return pointer to the sat-solvable or NULL if it is not valid.
147 * \see \ref validSolvable.
149 ::_Solvable * getSolvable( SolvableIdType id_r ) const
151 if ( validSolvable( id_r ) )
152 return &_pool->solvables[id_r];
157 /** Get id of the first valid \ref Solvable.
158 * This is the next valid after the system solvable.
160 SolvableIdType getFirstId() const
161 { return getNextId( 1 ); }
163 /** Get id of the next valid \ref Solvable.
164 * This goes round robbin. At the end it returns \ref noSolvableId.
165 * Passing \ref noSolvableId it returns the 1st valid \ref Solvable.
166 * \see \ref validSolvable.
168 SolvableIdType getNextId( SolvableIdType id_r ) const
170 for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
172 if ( validSolvable( _pool->solvables[id_r] ) )
180 const RepoInfo & repoInfo( RepoIdType id_r )
181 { return _repoinfos[id_r]; }
182 /** Also adjust repo priority and subpriority accordingly. */
183 void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r );
185 void eraseRepoInfo( RepoIdType id_r )
186 { _repoinfos.erase( id_r ); }
189 /** Returns the id stored at \c offset_r in the internal
190 * whatprovidesdata array.
192 const sat::detail::IdType whatProvidesData( unsigned offset_r )
193 { return _pool->whatprovidesdata[offset_r]; }
195 /** Returns offset into the internal whatprovidesdata array.
196 * Use \ref whatProvidesData to get the stored Id.
198 unsigned whatProvides( Capability cap_r )
199 { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
202 /** \name Requested locales. */
204 void setTextLocale( const Locale & locale_r );
205 void setRequestedLocales( const LocaleSet & locales_r );
206 bool addRequestedLocale( const Locale & locale_r );
207 bool eraseRequestedLocale( const Locale & locale_r );
209 const LocaleSet & getRequestedLocales() const
210 { return _requestedLocales; }
212 bool isRequestedLocale( const Locale & locale_r ) const
214 LocaleSet::const_iterator it( _requestedLocales.find( locale_r ) );
215 return it != _requestedLocales.end();
218 const LocaleSet & getAvailableLocales() const;
220 bool isAvailableLocale( const Locale & locale_r ) const
222 const LocaleSet & avl( getAvailableLocales() );
223 LocaleSet::const_iterator it( avl.find( locale_r ) );
224 return it != avl.end();
229 /** \name Multiversion install. */
231 typedef IdStringSet MultiversionList;
233 const MultiversionList & multiversionList() const
235 if ( ! _multiversionListPtr )
236 multiversionListInit();
237 return *_multiversionListPtr;
240 bool isMultiversion( IdString ident_r ) const
242 const MultiversionList & l( multiversionList() );
243 return l.find( ident_r ) != l.end();
248 /** \name Installed on behalf of a user request hint. */
250 typedef IdStringSet OnSystemByUserList;
252 const OnSystemByUserList & onSystemByUserList() const
254 if ( ! _onSystemByUserListPtr )
255 onSystemByUserListInit();
256 return *_onSystemByUserListPtr;
259 bool isOnSystemByUser( IdString ident_r ) const
261 const OnSystemByUserList & l( onSystemByUserList() );
262 return l.find( ident_r ) != l.end();
267 /** accessor for etc/sysconfig/storage reading file on demand */
268 const std::set<std::string> & requiredFilesystems() const;
273 /** Serial number. */
274 SerialNumber _serial;
275 /** Watch serial number. */
276 SerialNumberWatcher _watcher;
277 /** Additional \ref RepoInfo. */
278 std::map<RepoIdType,RepoInfo> _repoinfos;
281 LocaleSet _requestedLocales;
282 mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
283 mutable std::tr1::unordered_set<IdString> _locale2Solver;
286 void multiversionListInit() const;
287 mutable scoped_ptr<MultiversionList> _multiversionListPtr;
290 void onSystemByUserListInit() const;
291 mutable scoped_ptr<OnSystemByUserList> _onSystemByUserListPtr;
293 /** filesystems mentioned in /etc/sysconfig/storage */
294 mutable scoped_ptr<std::set<std::string> > _requiredFilesystemsPtr;
296 ///////////////////////////////////////////////////////////////////
298 /////////////////////////////////////////////////////////////////
299 } // namespace detail
300 ///////////////////////////////////////////////////////////////////
301 /////////////////////////////////////////////////////////////////
303 ///////////////////////////////////////////////////////////////////
304 /////////////////////////////////////////////////////////////////
306 ///////////////////////////////////////////////////////////////////
307 #define POOL_SETDIRTY
308 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H