- RepoInfoBase added for common SericeInfo and RepoInfo stuff
[platform/upstream/libzypp.git] / zypp / sat / Pool.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/Pool.cc
10  *
11 */
12
13 extern "C"
14 {
15 #include <satsolver/pool.h>
16 #include <satsolver/repo.h>
17 }
18 #include <iostream>
19
20 #include "zypp/base/Easy.h"
21 #include "zypp/base/Logger.h"
22 #include "zypp/base/Gettext.h"
23 #include "zypp/base/Exception.h"
24
25 #include "zypp/AutoDispose.h"
26
27 #include "zypp/sat/detail/PoolImpl.h"
28 #include "zypp/sat/Pool.h"
29 #include "zypp/sat/LookupAttr.h"
30
31 ///////////////////////////////////////////////////////////////////
32 namespace zypp
33 { /////////////////////////////////////////////////////////////////
34   ///////////////////////////////////////////////////////////////////
35   namespace sat
36   { /////////////////////////////////////////////////////////////////
37
38     const std::string & Pool::systemRepoAlias()
39     {
40       static const std::string _val( "@System" );
41       return _val;
42     }
43
44     ::_Pool * Pool::get() const
45     { return myPool().getPool(); }
46
47     Pool::size_type Pool::capacity() const
48     { return myPool()->nsolvables; }
49
50     const SerialNumber & Pool::serial() const
51     { return myPool().serial(); }
52
53     void Pool::prepare() const
54     { return myPool().prepare(); }
55
56     bool Pool::reposEmpty() const
57     { return ! myPool()->nrepos; }
58
59     Pool::size_type Pool::reposSize() const
60     { return myPool()->nrepos; }
61
62     Pool::RepositoryIterator Pool::reposBegin() const
63     { return RepositoryIterator( myPool()->repos ); }
64
65     Pool::RepositoryIterator Pool::reposEnd() const
66     { return RepositoryIterator( myPool()->repos+myPool()->nrepos ); }
67
68     bool Pool::solvablesEmpty() const
69     {
70       // return myPool()->nsolvables;
71       // nsolvables is the array size including
72       // invalid Solvables.
73       for_( it, reposBegin(), reposEnd() )
74       {
75         if ( ! it->solvablesEmpty() )
76           return false;
77       }
78       return true;
79     }
80
81     Pool::size_type Pool::solvablesSize() const
82     {
83       // Do not return myPool()->nsolvables;
84       // nsolvables is the array size including
85       // invalid Solvables.
86       size_type ret = 0;
87       for_( it, reposBegin(), reposEnd() )
88       {
89         ret += it->solvablesSize();
90       }
91       return ret;
92     }
93
94     Pool::SolvableIterator Pool::solvablesBegin() const
95     { return SolvableIterator( myPool().getFirstId() ); }
96
97     Pool::SolvableIterator Pool::solvablesEnd() const
98     { return SolvableIterator(); }
99
100     Repository Pool::reposInsert( const std::string & alias_r )
101     {
102       Repository ret( reposFind( alias_r ) );
103       if ( ret )
104         return ret;
105
106       ret = Repository( myPool()._createRepo( alias_r ) );
107       if ( alias_r == systemRepoAlias() )
108       {
109         // autoprovide (dummy) RepoInfo
110         RepoInfo info;
111         info
112           .setAlias( alias_r )
113           .setName( alias_r )
114           .setAutorefresh( true )
115           .setEnabled( true );
116         ret.setInfo( info );
117       }
118       return ret;
119     }
120
121     Repository Pool::reposFind( const std::string & alias_r ) const
122     {
123       for_( it, reposBegin(), reposEnd() )
124       {
125         if ( alias_r == it->alias() )
126           return *it;
127       }
128       return Repository();
129     }
130
131     Repository Pool::addRepoSolv( const Pathname & file_r, const std::string & alias_r )
132     {
133       // Using a temporay repo! (The additional parenthesis are required.)
134       AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
135       *tmprepo = reposInsert( alias_r );
136       tmprepo->addSolv( file_r );
137
138       // no exceptions so we keep it:
139       tmprepo.resetDispose();
140       return tmprepo;
141     }
142
143     Repository Pool::addRepoSolv( const Pathname & file_r )
144     { return addRepoSolv( file_r, file_r.basename() ); }
145
146     Repository Pool::addRepoSolv( const Pathname & file_r, const RepoInfo & info_r )
147     {
148       Repository ret( addRepoSolv( file_r, info_r.alias() ) );
149       ret.setInfo( info_r );
150       return ret;
151     }
152
153     /////////////////////////////////////////////////////////////////
154
155     void Pool::setRequestedLocales( const LocaleSet & locales_r )
156     { myPool().setRequestedLocales( locales_r ); }
157
158     bool Pool::addRequestedLocale( const Locale & locale_r )
159     { return myPool().addRequestedLocale( locale_r ); }
160
161     bool Pool::eraseRequestedLocale( const Locale & locale_r )
162     { return myPool().eraseRequestedLocale( locale_r ); }
163
164     const LocaleSet & Pool::getRequestedLocales() const
165     { return myPool().getRequestedLocales(); }
166
167     bool Pool::isRequestedLocale( const Locale & locale_r ) const
168     { return myPool().isRequestedLocale( locale_r ); }
169
170     const LocaleSet & Pool::getAvailableLocales() const
171     {  return myPool().getAvailableLocales(); }
172
173     bool Pool::isAvailableLocale( const Locale & locale_r ) const
174     { return myPool().isAvailableLocale( locale_r ); }
175
176    /******************************************************************
177     **
178     **  FUNCTION NAME : operator<<
179     **  FUNCTION TYPE : std::ostream &
180     */
181     std::ostream & operator<<( std::ostream & str, const Pool & obj )
182     {
183       return str << "sat::pool(" << obj.serial() << ")["
184           << obj.capacity() << "]{"
185           << obj.reposSize() << "repos|"
186           << obj.solvablesSize() << "slov}";
187     }
188
189     /////////////////////////////////////////////////////////////////
190   } // namespace sat
191   ///////////////////////////////////////////////////////////////////
192   /////////////////////////////////////////////////////////////////
193 } // namespace zypp
194 ///////////////////////////////////////////////////////////////////