adapt to satpool now recording the system repo
[platform/upstream/libzypp.git] / zypp / sat / detail / PoolImpl.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/detail/PoolImpl.h
10  *
11 */
12 #ifndef ZYPP_SAT_DETAIL_POOLIMPL_H
13 #define ZYPP_SAT_DETAIL_POOLIMPL_H
14 extern "C"
15 {
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>
21 }
22 #include <iosfwd>
23
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"
32
33 ///////////////////////////////////////////////////////////////////
34 namespace zypp
35 { /////////////////////////////////////////////////////////////////
36   ///////////////////////////////////////////////////////////////////
37   namespace sat
38   { /////////////////////////////////////////////////////////////////
39     ///////////////////////////////////////////////////////////////////
40     namespace detail
41     { /////////////////////////////////////////////////////////////////
42
43       ///////////////////////////////////////////////////////////////////
44       //
45       //        CLASS NAME : PoolImpl
46       //
47       /** */
48       class PoolImpl : private base::NonCopyable
49       {
50         public:
51           /** Default ctor */
52           PoolImpl();
53
54           /** Dtor */
55           ~PoolImpl();
56
57           /** Pointer style access forwarded to sat-pool. */
58           ::_Pool * operator->()
59           { return _pool; }
60
61         public:
62           /** Serial number changing whenever the content changes. */
63           const SerialNumber & serial() const
64           { return _serial; }
65
66           /** Update housekeeping data (e.g. whatprovides).
67            * \todo actually requires a watcher.
68            */
69           void prepare() const;
70
71         private:
72           /** Invalidate housekeeping data (e.g. whatprovides) if the
73            *  pools content changed.
74            */
75           void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
76
77           /** Invalidate housekeeping data (e.g. whatprovides) if dependencies changed.
78            */
79           void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
80
81           /** Callback to resolve namespace dependencies (language, modalias, filesystem, etc.). */
82           static detail::IdType nsCallback( ::_Pool *, void * data, detail::IdType lhs, detail::IdType rhs );
83
84         public:
85           /** Reserved system repository alias \c @System. */
86           static const std::string & systemRepoAlias();
87
88           bool isSystemRepo( ::_Repo * repo_r ) const
89           { return repo_r && _pool->installed == repo_r; }
90
91         public:
92           /** \name Actions invalidating housekeeping data.
93            *
94            * All methods expect valid arguments being passed.
95            */
96           //@{
97           /** Creating a new repo named \a name_r. */
98           ::_Repo * _createRepo( const std::string & name_r );
99
100           /** Creating a new repo named \a name_r. */
101           void _deleteRepo( ::_Repo * repo_r );
102
103           /** Adding solv file to a repo.
104            * Except for \c isSystemRepo_r, solvables of incompatible architecture
105            * are filtered out.
106           */
107           int _addSolv( ::_Repo * repo_r, FILE * file_r );
108
109           /** Adding Solvables to a repo. */
110           detail::SolvableIdType _addSolvables( ::_Repo * repo_r, unsigned count_r );
111           //@}
112
113         public:
114           /** a \c valid \ref Solvable has a non NULL repo pointer. */
115           bool validSolvable( const ::_Solvable & slv_r ) const
116           { return slv_r.repo; }
117           /** \overload Check also for id_r being in range of _pool->solvables. */
118           bool validSolvable( SolvableIdType id_r ) const
119           { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
120           /** \overload Check also for slv_r being in range of _pool->solvables. */
121           bool validSolvable( const ::_Solvable * slv_r ) const
122           { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
123
124         public:
125           ::_Pool * getPool() const
126           { return _pool; }
127
128           /** \todo a quick check whether the repo was meanwhile deleted. */
129           ::_Repo * getRepo( RepoIdType id_r ) const
130           { return id_r; }
131
132           /** Return pointer to the sat-solvable or NULL if it is not valid.
133            * \see \ref validSolvable.
134            */
135           ::_Solvable * getSolvable( SolvableIdType id_r ) const
136           {
137             if ( validSolvable( id_r ) )
138               return &_pool->solvables[id_r];
139             return 0;
140           }
141
142         public:
143           /** Get id of the first valid \ref Solvable.
144            * This is the next valid after the system solvable.
145            */
146           SolvableIdType getFirstId()  const
147           { return getNextId( 1 ); }
148
149           /** Get id of the next valid \ref Solvable.
150            * This goes round robbin. At the end it returns \ref noSolvableId.
151            * Passing \ref noSolvableId it returns the 1st valid  \ref Solvable.
152            * \see \ref validSolvable.
153            */
154           SolvableIdType getNextId( SolvableIdType id_r ) const
155           {
156             for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
157             {
158               if ( validSolvable( _pool->solvables[id_r] ) )
159                 return id_r;
160             }
161             return noSolvableId;
162           }
163
164         public:
165           /** */
166           const RepoInfo & repoInfo( RepoIdType id_r )
167           { return _repoinfos[id_r]; }
168           /** */
169           void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r )
170           { _repoinfos[id_r] = info_r; }
171           /** */
172           void eraseRepoInfo( RepoIdType id_r )
173           { _repoinfos.erase( id_r ); }
174
175         public:
176           /** Returns the id stored at \c offset_r in the internal
177            * whatprovidesdata array.
178           */
179           const sat::detail::IdType whatProvidesData( unsigned offset_r )
180           { return _pool->whatprovidesdata[offset_r]; }
181
182           /** Returns offset into the internal whatprovidesdata array.
183            * Use \ref whatProvidesData to get the stored Id.
184           */
185           unsigned whatProvides( Capability cap_r )
186           { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
187
188         public:
189           /** \name Requested locales. */
190           //@{
191           void setRequestedLocales( const LocaleSet & locales_r );
192           bool addRequestedLocale( const Locale & locale_r );
193           bool eraseRequestedLocale( const Locale & locale_r );
194
195           const LocaleSet & getRequestedLocales() const
196           { return _requestedLocales; }
197
198           bool isRequestedLocale( const Locale & locale_r ) const
199           {
200             LocaleSet::const_iterator it( _requestedLocales.find( locale_r ) );
201             return it != _requestedLocales.end();
202           }
203
204           const LocaleSet & getAvailableLocales() const;
205
206           bool isAvailableLocale( const Locale & locale_r ) const
207           {
208             const LocaleSet & avl( getAvailableLocales() );
209             LocaleSet::const_iterator it( avl.find( locale_r ) );
210             return it != avl.end();
211           }
212           //@}
213
214         private:
215           /** sat-pool. */
216           ::_Pool * _pool;
217           /** Serial number. */
218           SerialNumber _serial;
219           /** Watch serial number. */
220           SerialNumberWatcher _watcher;
221           /** Additional \ref RepoInfo. */
222           std::map<RepoIdType,RepoInfo> _repoinfos;
223
224           /**  */
225           LocaleSet _requestedLocales;
226           mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
227           mutable std::tr1::unordered_set<IdString> _locale2Solver;
228       };
229       ///////////////////////////////////////////////////////////////////
230
231       /////////////////////////////////////////////////////////////////
232     } // namespace detail
233     ///////////////////////////////////////////////////////////////////
234     /////////////////////////////////////////////////////////////////
235   } // namespace sat
236   ///////////////////////////////////////////////////////////////////
237   /////////////////////////////////////////////////////////////////
238 } // namespace zypp
239 ///////////////////////////////////////////////////////////////////
240 #define POOL_SETDIRTY
241 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H