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>
23 #include <tr1/unordered_set>
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 static detail::IdType nsCallback( ::_Pool *, void * data, detail::IdType lhs, detail::IdType rhs );
84 /** \name Actions invalidating housekeeping data.
86 * All methods expect valid arguments being passed.
89 /** Creating a new repo named \a name_r. */
90 RepoIdType _createRepo( const std::string & name_r )
92 setDirty(__FUNCTION__, name_r.c_str() );
93 return ::repo_create( _pool, name_r.c_str() );
96 /** Creating a new repo named \a name_r. */
97 void _deleteRepo( ::_Repo * repo_r )
99 setDirty(__FUNCTION__, repo_r->name );
100 ::repo_free( repo_r, /*reuseids*/false );
101 eraseRepoInfo( repo_r );
104 /** Adding solv file to a repo. */
105 int _addSolv( ::_Repo * repo_r, FILE * file_r );
107 /** Adding Solvables to a repo. */
108 detail::SolvableIdType _addSolvables( ::_Repo * repo_r, unsigned count_r )
110 setDirty(__FUNCTION__, repo_r->name );
111 return ::repo_add_solvable_block( repo_r, count_r );
116 /** a \c valid \ref Solvable has a non NULL repo pointer. */
117 bool validSolvable( const ::_Solvable & slv_r ) const
118 { return slv_r.repo; }
119 /** \overload Check also for id_r being in range of _pool->solvables. */
120 bool validSolvable( SolvableIdType id_r ) const
121 { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
122 /** \overload Check also for slv_r being in range of _pool->solvables. */
123 bool validSolvable( const ::_Solvable * slv_r ) const
124 { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
127 ::_Pool * getPool() const
130 /** \todo a quick check whether the repo was meanwhile deleted. */
131 ::_Repo * getRepo( RepoIdType id_r ) const
134 /** Return pointer to the sat-solvable or NULL if it is not valid.
135 * \see \ref validSolvable.
137 ::_Solvable * getSolvable( SolvableIdType id_r ) const
139 if ( validSolvable( id_r ) )
140 return &_pool->solvables[id_r];
145 /** Get id of the first valid \ref Solvable.
146 * This is the next valid after the system solvable.
148 SolvableIdType getFirstId() const
149 { return getNextId( 1 ); }
151 /** Get id of the next valid \ref Solvable.
152 * This goes round robbin. At the end it returns \ref noSolvableId.
153 * Passing \ref noSolvableId it returns the 1st valid \ref Solvable.
154 * \see \ref validSolvable.
156 SolvableIdType getNextId( SolvableIdType id_r ) const
158 for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
160 if ( validSolvable( _pool->solvables[id_r] ) )
168 const RepoInfo & repoInfo( RepoIdType id_r )
169 { return _repoinfos[id_r]; }
171 void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r )
172 { _repoinfos[id_r] = info_r; }
174 void eraseRepoInfo( RepoIdType id_r )
175 { _repoinfos.erase( id_r ); }
178 const sat::detail::IdType * whatProvides( Capability cap_r )
179 { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
182 /** \name Requested locales. */
184 void setRequestedLocales( const LocaleSet & locales_r );
185 bool addRequestedLocale( const Locale & locale_r );
186 bool eraseRequestedLocale( const Locale & locale_r );
188 const LocaleSet & getRequestedLocales() const
189 { return _requestedLocales; }
191 bool isRequestedLocale( const Locale & locale_r ) const
193 LocaleSet::const_iterator it( _requestedLocales.find( locale_r ) );
194 return it != _requestedLocales.end();
197 const LocaleSet & getAvailableLocales() const;
199 bool isAvailableLocale( const Locale & locale_r ) const
201 const LocaleSet & avl( getAvailableLocales() );
202 LocaleSet::const_iterator it( avl.find( locale_r ) );
203 return it != avl.end();
210 /** Serial number. */
211 SerialNumber _serial;
212 /** Watch serial number. */
213 SerialNumberWatcher _watcher;
214 /** Additional \ref RepoInfo. */
215 std::map<RepoIdType,RepoInfo> _repoinfos;
218 LocaleSet _requestedLocales;
219 mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
220 mutable std::tr1::unordered_set<IdString> _locale2Solver;
222 ///////////////////////////////////////////////////////////////////
224 /////////////////////////////////////////////////////////////////
225 } // namespace detail
226 ///////////////////////////////////////////////////////////////////
227 /////////////////////////////////////////////////////////////////
229 ///////////////////////////////////////////////////////////////////
230 /////////////////////////////////////////////////////////////////
232 ///////////////////////////////////////////////////////////////////
233 #define POOL_SETDIRTY
234 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H