/
PoolItem.cc
295 lines (249 loc) · 7.84 KB
/
PoolItem.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*---------------------------------------------------------------------\
| ____ _ __ __ ___ |
| |__ / \ / / . \ . \ |
| / / \ V /| _/ _/ |
| / /__ | | | | | | |
| /_____||_| |_| |_| |
| |
\---------------------------------------------------------------------*/
/** \file zypp/PoolItem.cc
*
*/
#include <iostream>
#include "zypp/base/Logger.h"
#include "zypp/base/DefaultIntegral.h"
#include "zypp/PoolItem.h"
#include "zypp/ResPool.h"
#include "zypp/Package.h"
#include "zypp/VendorAttr.h"
using std::endl;
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : PoolItem::Impl
//
/** PoolItem implementation.
* \c _buddy handling:
* \li \c ==0 no buddy
* \li \c >0 this uses \c _buddy status
* \li \c <0 this status used by \c -_buddy
*/
struct PoolItem::Impl
{
public:
Impl() {}
Impl( ResObject::constPtr res_r,
const ResStatus & status_r )
: _status( status_r )
, _resolvable( res_r )
{}
ResStatus & status() const
{ return _buddy > 0 ? PoolItem(buddy()).status() : _status; }
sat::Solvable buddy() const
{
if ( !_buddy )
return sat::Solvable::noSolvable;
if ( _buddy < 0 )
return sat::Solvable( -_buddy );
return sat::Solvable( _buddy );
}
void setBuddy( sat::Solvable solv_r );
ResObject::constPtr resolvable() const
{ return _resolvable; }
ResStatus & statusReset() const
{
_status.setLock( false, zypp::ResStatus::USER );
_status.resetTransact( zypp::ResStatus::USER );
return _status;
}
public:
bool isUndetermined() const
{
return status().isUndetermined();
}
bool isRelevant() const
{
return !status().isNonRelevant();
}
bool isSatisfied() const
{
return status().isSatisfied();
}
bool isBroken() const
{
return status().isBroken();
}
bool isNeeded() const
{
return status().isToBeInstalled() || ( isBroken() && ! status().isLocked() );
}
bool isUnwanted() const
{
return isBroken() && status().isLocked();
}
private:
mutable ResStatus _status;
ResObject::constPtr _resolvable;
DefaultIntegral<sat::detail::IdType,sat::detail::noId> _buddy;
/** \name Poor man's save/restore state.
* \todo There may be better save/restore state strategies.
*/
//@{
public:
void saveState() const
{ _savedStatus = status(); }
void restoreState() const
{ status() = _savedStatus; }
bool sameState() const
{
if ( status() == _savedStatus )
return true;
// some bits changed...
if ( status().getTransactValue() != _savedStatus.getTransactValue()
&& ( ! status().isBySolver() // ignore solver state changes
// removing a user lock also goes to bySolver
|| _savedStatus.getTransactValue() == ResStatus::LOCKED ) )
return false;
if ( status().isLicenceConfirmed() != _savedStatus.isLicenceConfirmed() )
return false;
return true;
}
private:
mutable ResStatus _savedStatus;
//@}
public:
/** Offer default Impl. */
static shared_ptr<Impl> nullimpl()
{
static shared_ptr<Impl> _nullimpl( new Impl );
return _nullimpl;
}
};
///////////////////////////////////////////////////////////////////
/** \relates PoolItem::Impl Stream output */
inline std::ostream & operator<<( std::ostream & str, const PoolItem::Impl & obj )
{
str << obj.status();
if (obj.resolvable())
str << *obj.resolvable();
else
str << "(NULL)";
return str;
}
inline void PoolItem::Impl::setBuddy( sat::Solvable solv_r )
{
PoolItem myBuddy( solv_r );
if ( myBuddy )
{
myBuddy._pimpl->_buddy = -resolvable()->satSolvable().id();
_buddy = myBuddy.satSolvable().id();
DBG << *this << " has buddy " << myBuddy << endl;
}
}
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : PoolItem
//
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : PoolItem::PoolItem
// METHOD TYPE : Ctor
//
PoolItem::PoolItem()
: _pimpl( Impl::nullimpl() )
{}
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : PoolItem::PoolItem
// METHOD TYPE : Ctor
//
PoolItem::PoolItem( const sat::Solvable & solvable_r )
: _pimpl( ResPool::instance().find( solvable_r )._pimpl )
{}
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : PoolItem::PoolItem
// METHOD TYPE : Ctor
//
PoolItem::PoolItem( const ResObject::constPtr & resolvable_r )
: _pimpl( ResPool::instance().find( resolvable_r )._pimpl )
{}
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : PoolItem::PoolItem
// METHOD TYPE : Ctor
//
PoolItem::PoolItem( Impl * implptr_r )
: _pimpl( implptr_r )
{}
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : PoolItem::makePoolItem
// METHOD TYPE : PoolItem
//
PoolItem PoolItem::makePoolItem( const sat::Solvable & solvable_r )
{
return PoolItem( new Impl( makeResObject( solvable_r ), solvable_r.isSystem() ) );
}
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : PoolItem::~PoolItem
// METHOD TYPE : Dtor
//
PoolItem::~PoolItem()
{}
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : PoolItem::pool
// METHOD TYPE : ResPool
//
ResPool PoolItem::pool() const
{ return ResPool::instance(); }
///////////////////////////////////////////////////////////////////
//
// Forward to Impl:
//
///////////////////////////////////////////////////////////////////
ResStatus & PoolItem::status() const
{ return _pimpl->status(); }
ResStatus & PoolItem::statusReset() const
{ return _pimpl->statusReset(); }
sat::Solvable PoolItem::buddy() const
{ return _pimpl->buddy(); }
void PoolItem::setBuddy( sat::Solvable solv_r )
{ _pimpl->setBuddy( solv_r ); }
bool PoolItem::isUndetermined() const
{ return _pimpl->isUndetermined(); }
bool PoolItem::isRelevant() const
{ return _pimpl->isRelevant(); }
bool PoolItem::isSatisfied() const
{ return _pimpl->isSatisfied(); }
bool PoolItem::isBroken() const
{ return _pimpl->isBroken(); }
bool PoolItem::isNeeded() const
{ return _pimpl->isNeeded(); }
bool PoolItem::isUnwanted() const
{ return _pimpl->isUnwanted(); }
void PoolItem::saveState() const
{ _pimpl->saveState(); }
void PoolItem::restoreState() const
{ _pimpl->restoreState(); }
bool PoolItem::sameState() const
{ return _pimpl->sameState(); }
ResObject::constPtr PoolItem::resolvable() const
{ return _pimpl->resolvable(); }
/******************************************************************
**
** FUNCTION NAME : operator<<
** FUNCTION TYPE : std::ostream &
*/
std::ostream & operator<<( std::ostream & str, const PoolItem & obj )
{
return str << *obj._pimpl;
}
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////