libzypp 17.31.23
PoolItem.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <zypp/base/Logger.h>
14#include <zypp-core/base/DefaultIntegral>
15
16#include <zypp/PoolItem.h>
17#include <zypp/ResPool.h>
18#include <zypp/Package.h>
19#include <zypp/VendorAttr.h>
20
21using std::endl;
22
24namespace zypp
25{
26
28 //
29 // CLASS NAME : PoolItem::Impl
30 //
38 {
39 public:
40 Impl() {}
41
43 const ResStatus & status_r )
44 : _status( status_r )
45 , _resolvable( res_r )
46 {}
47
48 ResStatus & status() const
49 { return _buddy > 0 ? PoolItem(buddy()).status() : _status; }
50
52 {
53 if ( !_buddy )
55 if ( _buddy < 0 )
56 return sat::Solvable( -_buddy );
57 return sat::Solvable( _buddy );
58 }
59
60 void setBuddy( const sat::Solvable & solv_r );
61
63 { return _resolvable; }
64
66 {
69 return _status;
70 }
71
73 {
76 return _status;
77 }
78
79 public:
80 bool isUndetermined() const
81 {
82 return status().isUndetermined();
83 }
84
85 bool isRelevant() const
86 {
87 return !status().isNonRelevant();
88 }
89
90 bool isSatisfied() const
91 {
92 return status().isSatisfied();
93 }
94
95 bool isBroken() const
96 {
97 return status().isBroken();
98 }
99
100 bool isNeeded() const
101 {
102 return status().isToBeInstalled() || ( isBroken() && ! status().isLocked() );
103 }
104
105 bool isUnwanted() const
106 {
107 return isBroken() && status().isLocked();
108 }
109
110 private:
114
119 public:
120 void saveState() const
121 { _savedStatus = status(); }
122 void restoreState() const
123 { status() = _savedStatus; }
124 bool sameState() const
125 {
126 if ( status() == _savedStatus )
127 return true;
128 // some bits changed...
129 if ( status().getTransactValue() != _savedStatus.getTransactValue()
130 && ( ! status().isBySolver() // ignore solver state changes
131 // removing a user lock also goes to bySolver
133 return false;
134 if ( status().isLicenceConfirmed() != _savedStatus.isLicenceConfirmed() )
135 return false;
136 return true;
137 }
138 private:
141
142 public:
144 static shared_ptr<Impl> nullimpl()
145 {
146 static shared_ptr<Impl> _nullimpl( new Impl );
147 return _nullimpl;
148 }
149 };
151
153 inline std::ostream & operator<<( std::ostream & str, const PoolItem::Impl & obj )
154 {
155 str << obj.status();
156 if (obj.resolvable())
157 str << *obj.resolvable();
158 else
159 str << "(NULL)";
160 return str;
161 }
162
163 inline void PoolItem::Impl::setBuddy( const sat::Solvable & solv_r )
164 {
165 PoolItem myBuddy( solv_r );
166 if ( myBuddy )
167 {
168 if ( myBuddy._pimpl->_buddy )
169 {
170 ERR << *this << " would be buddy2 in " << myBuddy << endl;
171 return;
172 }
173 myBuddy._pimpl->_buddy = -resolvable()->satSolvable().id();
174 _buddy = myBuddy.satSolvable().id();
175 DBG << *this << " has buddy " << myBuddy << endl;
176 }
177 }
178
180 // class PoolItem
182
184 : _pimpl( Impl::nullimpl() )
185 {}
186
187 PoolItem::PoolItem( const sat::Solvable & solvable_r )
188 : _pimpl( ResPool::instance().find( solvable_r )._pimpl )
189 {}
190
192 : _pimpl( ResPool::instance().find( resolvable_r )._pimpl )
193 {}
194
196 : _pimpl( implptr_r )
197 {}
198
200 {
201 return PoolItem( new Impl( makeResObject( solvable_r ), solvable_r.isSystem() ) );
202 }
203
205 {}
206
208 { return ResPool::instance(); }
209
210
211 ResStatus & PoolItem::status() const { return _pimpl->status(); }
212 ResStatus & PoolItem::statusReset() const { return _pimpl->statusReset(); }
213 ResStatus & PoolItem::statusReinit() const { return _pimpl->statusReinit(); }
214 sat::Solvable PoolItem::buddy() const { return _pimpl->buddy(); }
215 void PoolItem::setBuddy( const sat::Solvable & solv_r ) { _pimpl->setBuddy( solv_r ); }
216 bool PoolItem::isUndetermined() const { return _pimpl->isUndetermined(); }
217 bool PoolItem::isRelevant() const { return _pimpl->isRelevant(); }
218 bool PoolItem::isSatisfied() const { return _pimpl->isSatisfied(); }
219 bool PoolItem::isBroken() const { return _pimpl->isBroken(); }
220 bool PoolItem::isNeeded() const { return _pimpl->isNeeded(); }
221 bool PoolItem::isUnwanted() const { return _pimpl->isUnwanted(); }
222
223 void PoolItem::saveState() const { _pimpl->saveState(); }
224 void PoolItem::restoreState() const { _pimpl->restoreState(); }
225 bool PoolItem::sameState() const { return _pimpl->sameState(); }
226 ResObject::constPtr PoolItem::resolvable() const { return _pimpl->resolvable(); }
227
228
229 std::ostream & operator<<( std::ostream & str, const PoolItem & obj )
230 { return str << *obj._pimpl; }
231
232} // namespace zypp
Integral type with defined initial value when default constructed.
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:51
bool isRelevant() const
Returns true if the solvable is relevant which means e.g.
Definition: PoolItem.cc:217
bool isNeeded() const
This includes unlocked broken patches, as well as those already selected to be installed (otherwise c...
Definition: PoolItem.cc:220
void restoreState() const
Definition: PoolItem.cc:224
void saveState() const
Definition: PoolItem.cc:223
ResObject::constPtr resolvable() const
Returns the ResObject::constPtr.
Definition: PoolItem.cc:226
bool sameState() const
Definition: PoolItem.cc:225
bool isBroken() const
Whether a relevant items requirements are broken.
Definition: PoolItem.cc:219
ResStatus & status() const
Returns the current status.
Definition: PoolItem.cc:211
void setBuddy(const sat::Solvable &solv_r)
Buddies are set by pool::PoolImpl.
Definition: PoolItem.cc:215
bool isSatisfied() const
Whether a relevant items requirements are met.
Definition: PoolItem.cc:218
bool isUnwanted() const
Broken (needed) but locked patches.
Definition: PoolItem.cc:221
static PoolItem makePoolItem(const sat::Solvable &solvable_r)
PoolItem generator for pool::PoolImpl.
Definition: PoolItem.cc:199
~PoolItem()
Dtor.
Definition: PoolItem.cc:204
ResStatus & statusReset() const
Resets status to the default state (KEEP_STATE bySOLVER; clears any lock!).
Definition: PoolItem.cc:212
ResPool pool() const
Return the ResPool the item belongs to.
Definition: PoolItem.cc:207
PoolItem()
Default ctor for use in std::container.
Definition: PoolItem.cc:183
sat::Solvable buddy() const
Return the buddy we share our status object with.
Definition: PoolItem.cc:214
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PoolItem.h:157
bool isUndetermined() const
No validation is performed for packages.
Definition: PoolItem.cc:216
ResStatus & statusReinit() const
Resets status to it's initial state in the ResPool (KEEP_STATE bySOLVER or LOCKED byUSER).
Definition: PoolItem.cc:213
TraitsType::constPtrType constPtr
Definition: ResObject.h:43
Global ResObject pool.
Definition: ResPool.h:61
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:37
Status bitfield.
Definition: ResStatus.h:54
bool isLicenceConfirmed() const
Definition: ResStatus.h:175
bool isUndetermined() const
Definition: ResStatus.h:216
bool isToBeInstalled() const
Definition: ResStatus.h:253
bool isBroken() const
Definition: ResStatus.h:222
bool isNonRelevant() const
Definition: ResStatus.h:225
bool isLocked() const
Definition: ResStatus.h:264
bool isUserLockQueryMatch() const
Definition: ResStatus.h:339
bool setLock(bool toLock_r, TransactByValue causer_r)
Apply a lock (prevent transaction).
Definition: ResStatus.h:387
TransactValue getTransactValue() const
Definition: ResStatus.h:279
bool resetTransact(TransactByValue causer_r)
Not the same as setTransact( false ).
Definition: ResStatus.h:484
bool isSatisfied() const
Definition: ResStatus.h:219
A Solvable object within the sat Pool.
Definition: Solvable.h:54
IdType id() const
Expert backdoor.
Definition: Solvable.h:428
static const Solvable noSolvable
Represents no Solvable.
Definition: Solvable.h:75
bool isSystem() const
Return whether this Solvable belongs to the system repo.
Definition: Solvable.cc:373
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
ResObject::Ptr makeResObject(const sat::Solvable &solvable_r)
Create ResObject from sat::Solvable.
Definition: ResObject.cc:43
PoolItem implementation.
Definition: PoolItem.cc:38
bool isNeeded() const
Definition: PoolItem.cc:100
void setBuddy(const sat::Solvable &solv_r)
Definition: PoolItem.cc:163
ResStatus & status() const
Definition: PoolItem.cc:48
bool sameState() const
Definition: PoolItem.cc:124
ResObject::constPtr _resolvable
Definition: PoolItem.cc:112
void restoreState() const
Definition: PoolItem.cc:122
void saveState() const
Definition: PoolItem.cc:120
sat::Solvable buddy() const
Definition: PoolItem.cc:51
bool isBroken() const
Definition: PoolItem.cc:95
std::ostream & operator<<(std::ostream &str, const PoolItem::Impl &obj)
Stream output.
Definition: PoolItem.cc:153
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition: PoolItem.cc:144
bool isRelevant() const
Definition: PoolItem.cc:85
Impl(ResObject::constPtr res_r, const ResStatus &status_r)
Definition: PoolItem.cc:42
bool isUndetermined() const
Definition: PoolItem.cc:80
ResStatus _savedStatus
Definition: PoolItem.cc:139
DefaultIntegral< sat::detail::IdType, sat::detail::noId > _buddy
Definition: PoolItem.cc:113
bool isSatisfied() const
Definition: PoolItem.cc:90
ResStatus & statusReset() const
Definition: PoolItem.cc:65
bool isUnwanted() const
Definition: PoolItem.cc:105
ResStatus & statusReinit() const
Definition: PoolItem.cc:72
ResObject::constPtr resolvable() const
Definition: PoolItem.cc:62
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
#define DBG
Definition: Logger.h:95
#define ERR
Definition: Logger.h:98