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/IdString.h"
32 ///////////////////////////////////////////////////////////////////
34 { /////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////
37 { /////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////
40 { /////////////////////////////////////////////////////////////////
42 ///////////////////////////////////////////////////////////////////
44 // CLASS NAME : PoolImpl
47 class PoolImpl : private base::NonCopyable
56 /** Pointer style access forwarded to sat-pool. */
57 ::_Pool * operator->()
61 /** Serial number changing whenever the content changes. */
62 const SerialNumber & serial() const
65 /** Update housekeeping data (e.g. whatprovides).
66 * \todo actually requires a watcher.
71 /** Invalidate housekeeping data (e.g. whatprovides) if the
72 * pools content changed.
74 void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
76 /** Invalidate housekeeping data (e.g. whatprovides) if dependencies changed.
78 void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
80 static detail::IdType nsCallback( ::_Pool *, void * data, detail::IdType lhs, detail::IdType rhs );
83 /** \name Actions invalidating housekeeping data.
85 * All methods expect valid arguments being passed.
88 /** Creating a new repo named \a name_r. */
89 RepoIdType _createRepo( const std::string & name_r )
91 setDirty(__FUNCTION__, name_r.c_str() );
92 return ::repo_create( _pool, name_r.c_str() );
95 /** Creating a new repo named \a name_r. */
96 void _deleteRepo( ::_Repo * repo_r )
98 setDirty(__FUNCTION__, repo_r->name );
99 ::repo_free( repo_r, /*reuseids*/false );
100 eraseRepoInfo( repo_r );
103 /** Adding solv file to a repo. */
104 int _addSolv( ::_Repo * repo_r, FILE * file_r );
106 /** Adding Solvables to a repo. */
107 detail::SolvableIdType _addSolvables( ::_Repo * repo_r, unsigned count_r )
109 setDirty(__FUNCTION__, repo_r->name );
110 return ::repo_add_solvable_block( repo_r, count_r );
115 /** a \c valid \ref Solvable has a non NULL repo pointer. */
116 bool validSolvable( const ::_Solvable & slv_r ) const
117 { return slv_r.repo; }
118 /** \overload Check also for id_r being in range of _pool->solvables. */
119 bool validSolvable( SolvableIdType id_r ) const
120 { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
121 /** \overload Check also for slv_r being in range of _pool->solvables. */
122 bool validSolvable( const ::_Solvable * slv_r ) const
123 { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
126 ::_Pool * getPool() const
129 /** \todo a quick check whether the repo was meanwhile deleted. */
130 ::_Repo * getRepo( RepoIdType id_r ) const
133 /** Return pointer to the sat-solvable or NULL if it is not valid.
134 * \see \ref validSolvable.
136 ::_Solvable * getSolvable( SolvableIdType id_r ) const
138 if ( validSolvable( id_r ) )
139 return &_pool->solvables[id_r];
144 /** Get id of the first valid \ref Solvable.
145 * This is the next valid after the system solvable.
147 SolvableIdType getFirstId() const
148 { return getNextId( 1 ); }
150 /** Get id of the next valid \ref Solvable.
151 * This goes round robbin. At the end it returns \ref noSolvableId.
152 * Passing \ref noSolvableId it returns the 1st valid \ref Solvable.
153 * \see \ref validSolvable.
155 SolvableIdType getNextId( SolvableIdType id_r ) const
157 for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
159 if ( validSolvable( _pool->solvables[id_r] ) )
167 const RepoInfo & repoInfo( RepoIdType id_r )
168 { return _repoinfos[id_r]; }
170 void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r )
171 { _repoinfos[id_r] = info_r; }
173 void eraseRepoInfo( RepoIdType id_r )
174 { _repoinfos.erase( id_r ); }
177 /** \name Requested locales. */
179 void setRequestedLocales( const LocaleSet & locales_r );
180 bool addRequestedLocale( const Locale & locale_r );
181 bool eraseRequestedLocale( const Locale & locale_r );
183 const LocaleSet & getRequestedLocales() const
184 { return _requestedLocales; }
186 bool isRequestedLocale( const Locale & locale_r ) const
188 LocaleSet::const_iterator it( _requestedLocales.find( locale_r ) );
189 return it != _requestedLocales.end();
192 const LocaleSet & getAvailableLocales() const
194 if ( _availableLocales.size() != _localeCollector.size() )
196 _availableLocales.clear();
197 for_( it, _localeCollector.begin(), _localeCollector.end() )
198 _availableLocales.insert( Locale( *it ) );
200 return _availableLocales;
203 bool isAvailableLocale( const Locale & locale_r ) const
205 const LocaleSet & avl( getAvailableLocales() );
206 LocaleSet::const_iterator it( avl.find( locale_r ) );
207 return it != avl.end();
215 /** Serial number. */
216 SerialNumber _serial;
217 /** Watch serial number. */
218 SerialNumberWatcher _watcher;
219 /** Additional \ref RepoInfo. */
220 std::map<RepoIdType,RepoInfo> _repoinfos;
223 LocaleSet _requestedLocales;
224 mutable LocaleSet _availableLocales;
225 mutable std::tr1::unordered_set<IdString> _localeCollector;
226 mutable std::tr1::unordered_set<IdString> _locale2Solver;
228 ///////////////////////////////////////////////////////////////////
230 /////////////////////////////////////////////////////////////////
231 } // namespace detail
232 ///////////////////////////////////////////////////////////////////
233 /////////////////////////////////////////////////////////////////
235 ///////////////////////////////////////////////////////////////////
236 /////////////////////////////////////////////////////////////////
238 ///////////////////////////////////////////////////////////////////
239 #define POOL_SETDIRTY
240 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H