add basic locale interface to ResPool, remove deprecated _gxx hashes
[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/IdString.h"
31
32 ///////////////////////////////////////////////////////////////////
33 namespace zypp
34 { /////////////////////////////////////////////////////////////////
35   ///////////////////////////////////////////////////////////////////
36   namespace sat
37   { /////////////////////////////////////////////////////////////////
38     ///////////////////////////////////////////////////////////////////
39     namespace detail
40     { /////////////////////////////////////////////////////////////////
41
42       ///////////////////////////////////////////////////////////////////
43       //
44       //        CLASS NAME : PoolImpl
45       //
46       /** */
47       class PoolImpl : private base::NonCopyable
48       {
49         public:
50           /** Default ctor */
51           PoolImpl();
52
53           /** Dtor */
54           ~PoolImpl();
55
56           /** Pointer style access forwarded to sat-pool. */
57           ::_Pool * operator->()
58           { return _pool; }
59
60         public:
61           /** Serial number changing whenever the content changes. */
62           const SerialNumber & serial() const
63           { return _serial; }
64
65           /** Update housekeeping data (e.g. whatprovides).
66            * \todo actually requires a watcher.
67            */
68           void prepare() const;
69
70         private:
71           /** Invalidate housekeeping data (e.g. whatprovides) if the
72            *  pools content changed.
73            */
74           void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
75
76           /** Invalidate housekeeping data (e.g. whatprovides) if dependencies changed.
77            */
78           void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
79
80           static detail::IdType nsCallback( ::_Pool *, void * data, detail::IdType lhs, detail::IdType rhs );
81
82         public:
83           /** \name Actions invalidating housekeeping data.
84            *
85            * All methods expect valid arguments being passed.
86            */
87           //@{
88           /** Creating a new repo named \a name_r. */
89           RepoIdType _createRepo( const std::string & name_r )
90           {
91             setDirty(__FUNCTION__, name_r.c_str() );
92             return ::repo_create( _pool, name_r.c_str() );
93           }
94
95           /** Creating a new repo named \a name_r. */
96           void _deleteRepo( ::_Repo * repo_r )
97           {
98             setDirty(__FUNCTION__, repo_r->name );
99             ::repo_free( repo_r, /*reuseids*/false );
100             eraseRepoInfo( repo_r );
101           }
102
103           /** Adding solv file to a repo. */
104           int _addSolv( ::_Repo * repo_r, FILE * file_r );
105
106           /** Adding Solvables to a repo. */
107           detail::SolvableIdType _addSolvables( ::_Repo * repo_r, unsigned count_r )
108           {
109             setDirty(__FUNCTION__, repo_r->name );
110             return ::repo_add_solvable_block( repo_r, count_r );
111           }
112           //@}
113
114         public:
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 ); }
124
125         public:
126           ::_Pool * getPool() const
127           { return _pool; }
128
129           /** \todo a quick check whether the repo was meanwhile deleted. */
130           ::_Repo * getRepo( RepoIdType id_r ) const
131           { return id_r; }
132
133           /** Return pointer to the sat-solvable or NULL if it is not valid.
134            * \see \ref validSolvable.
135            */
136           ::_Solvable * getSolvable( SolvableIdType id_r ) const
137           {
138             if ( validSolvable( id_r ) )
139               return &_pool->solvables[id_r];
140             return 0;
141           }
142
143         public:
144           /** Get id of the first valid \ref Solvable.
145            * This is the next valid after the system solvable.
146            */
147           SolvableIdType getFirstId()  const
148           { return getNextId( 1 ); }
149
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.
154            */
155           SolvableIdType getNextId( SolvableIdType id_r ) const
156           {
157             for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
158             {
159               if ( validSolvable( _pool->solvables[id_r] ) )
160                 return id_r;
161             }
162             return noSolvableId;
163           }
164
165         public:
166           /** */
167           const RepoInfo & repoInfo( RepoIdType id_r )
168           { return _repoinfos[id_r]; }
169           /** */
170           void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r )
171           { _repoinfos[id_r] = info_r; }
172           /** */
173           void eraseRepoInfo( RepoIdType id_r )
174           { _repoinfos.erase( id_r ); }
175
176         public:
177           /** \name Requested locales. */
178           //@{
179           void setRequestedLocales( const LocaleSet & locales_r );
180           bool addRequestedLocale( const Locale & locale_r );
181           bool eraseRequestedLocale( const Locale & locale_r );
182
183           const LocaleSet & getRequestedLocales() const
184           { return _requestedLocales; }
185
186           bool isRequestedLocale( const Locale & locale_r ) const
187           {
188             LocaleSet::const_iterator it( _requestedLocales.find( locale_r ) );
189             return it != _requestedLocales.end();
190           }
191
192           const LocaleSet & getAvailableLocales() const
193           {
194             if ( _availableLocales.size() != _localeCollector.size() )
195             {
196               _availableLocales.clear();
197               for_( it, _localeCollector.begin(), _localeCollector.end() )
198                 _availableLocales.insert( Locale( *it ) );
199             }
200             return _availableLocales;
201           }
202
203           bool isAvailableLocale( const Locale & locale_r ) const
204           {
205             const LocaleSet & avl( getAvailableLocales() );
206             LocaleSet::const_iterator it( avl.find( locale_r ) );
207             return it != avl.end();
208           }
209
210         //@}
211
212         private:
213           /** sat-pool. */
214           ::_Pool * _pool;
215           /** Serial number. */
216           SerialNumber _serial;
217           /** Watch serial number. */
218           SerialNumberWatcher _watcher;
219           /** Additional \ref RepoInfo. */
220           std::map<RepoIdType,RepoInfo> _repoinfos;
221
222           /**  */
223           LocaleSet _requestedLocales;
224           mutable LocaleSet _availableLocales;
225           mutable std::tr1::unordered_set<IdString> _localeCollector;
226           mutable std::tr1::unordered_set<IdString> _locale2Solver;
227       };
228       ///////////////////////////////////////////////////////////////////
229
230       /////////////////////////////////////////////////////////////////
231     } // namespace detail
232     ///////////////////////////////////////////////////////////////////
233     /////////////////////////////////////////////////////////////////
234   } // namespace sat
235   ///////////////////////////////////////////////////////////////////
236   /////////////////////////////////////////////////////////////////
237 } // namespace zypp
238 ///////////////////////////////////////////////////////////////////
239 #define POOL_SETDIRTY
240 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H