Do not filter any installed solvables.
[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 #include <tr1/unordered_set>
24
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           static detail::IdType nsCallback( ::_Pool *, void * data, detail::IdType lhs, detail::IdType rhs );
82
83         public:
84           /** \name Actions invalidating housekeeping data.
85            *
86            * All methods expect valid arguments being passed.
87            */
88           //@{
89           /** Creating a new repo named \a name_r. */
90           RepoIdType _createRepo( const std::string & name_r )
91           {
92             setDirty(__FUNCTION__, name_r.c_str() );
93             return ::repo_create( _pool, name_r.c_str() );
94           }
95
96           /** Creating a new repo named \a name_r. */
97           void _deleteRepo( ::_Repo * repo_r )
98           {
99             setDirty(__FUNCTION__, repo_r->name );
100             ::repo_free( repo_r, /*reuseids*/false );
101             eraseRepoInfo( repo_r );
102           }
103
104           /** Adding solv file to a repo.
105            * Except for \c isSystemRepo_r, solvables of incompatible architecture
106            * are filtered out.
107           */
108           int _addSolv( ::_Repo * repo_r, FILE * file_r, bool isSystemRepo_r = false );
109
110           /** Adding Solvables to a repo. */
111           detail::SolvableIdType _addSolvables( ::_Repo * repo_r, unsigned count_r )
112           {
113             setDirty(__FUNCTION__, repo_r->name );
114             return ::repo_add_solvable_block( repo_r, count_r );
115           }
116           //@}
117
118         public:
119           /** a \c valid \ref Solvable has a non NULL repo pointer. */
120           bool validSolvable( const ::_Solvable & slv_r ) const
121           { return slv_r.repo; }
122           /** \overload Check also for id_r being in range of _pool->solvables. */
123           bool validSolvable( SolvableIdType id_r ) const
124           { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
125           /** \overload Check also for slv_r being in range of _pool->solvables. */
126           bool validSolvable( const ::_Solvable * slv_r ) const
127           { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
128
129         public:
130           ::_Pool * getPool() const
131           { return _pool; }
132
133           /** \todo a quick check whether the repo was meanwhile deleted. */
134           ::_Repo * getRepo( RepoIdType id_r ) const
135           { return id_r; }
136
137           /** Return pointer to the sat-solvable or NULL if it is not valid.
138            * \see \ref validSolvable.
139            */
140           ::_Solvable * getSolvable( SolvableIdType id_r ) const
141           {
142             if ( validSolvable( id_r ) )
143               return &_pool->solvables[id_r];
144             return 0;
145           }
146
147         public:
148           /** Get id of the first valid \ref Solvable.
149            * This is the next valid after the system solvable.
150            */
151           SolvableIdType getFirstId()  const
152           { return getNextId( 1 ); }
153
154           /** Get id of the next valid \ref Solvable.
155            * This goes round robbin. At the end it returns \ref noSolvableId.
156            * Passing \ref noSolvableId it returns the 1st valid  \ref Solvable.
157            * \see \ref validSolvable.
158            */
159           SolvableIdType getNextId( SolvableIdType id_r ) const
160           {
161             for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
162             {
163               if ( validSolvable( _pool->solvables[id_r] ) )
164                 return id_r;
165             }
166             return noSolvableId;
167           }
168
169         public:
170           /** */
171           const RepoInfo & repoInfo( RepoIdType id_r )
172           { return _repoinfos[id_r]; }
173           /** */
174           void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r )
175           { _repoinfos[id_r] = info_r; }
176           /** */
177           void eraseRepoInfo( RepoIdType id_r )
178           { _repoinfos.erase( id_r ); }
179
180         public:
181           const sat::detail::IdType * whatProvides( Capability cap_r )
182           { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
183
184         public:
185           /** \name Requested locales. */
186           //@{
187           void setRequestedLocales( const LocaleSet & locales_r );
188           bool addRequestedLocale( const Locale & locale_r );
189           bool eraseRequestedLocale( const Locale & locale_r );
190
191           const LocaleSet & getRequestedLocales() const
192           { return _requestedLocales; }
193
194           bool isRequestedLocale( const Locale & locale_r ) const
195           {
196             LocaleSet::const_iterator it( _requestedLocales.find( locale_r ) );
197             return it != _requestedLocales.end();
198           }
199
200           const LocaleSet & getAvailableLocales() const;
201
202           bool isAvailableLocale( const Locale & locale_r ) const
203           {
204             const LocaleSet & avl( getAvailableLocales() );
205             LocaleSet::const_iterator it( avl.find( locale_r ) );
206             return it != avl.end();
207           }
208           //@}
209
210         private:
211           /** sat-pool. */
212           ::_Pool * _pool;
213           /** Serial number. */
214           SerialNumber _serial;
215           /** Watch serial number. */
216           SerialNumberWatcher _watcher;
217           /** Additional \ref RepoInfo. */
218           std::map<RepoIdType,RepoInfo> _repoinfos;
219
220           /**  */
221           LocaleSet _requestedLocales;
222           mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
223           mutable std::tr1::unordered_set<IdString> _locale2Solver;
224       };
225       ///////////////////////////////////////////////////////////////////
226
227       /////////////////////////////////////////////////////////////////
228     } // namespace detail
229     ///////////////////////////////////////////////////////////////////
230     /////////////////////////////////////////////////////////////////
231   } // namespace sat
232   ///////////////////////////////////////////////////////////////////
233   /////////////////////////////////////////////////////////////////
234 } // namespace zypp
235 ///////////////////////////////////////////////////////////////////
236 #define POOL_SETDIRTY
237 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H