libzypp  13.10.6
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"
15 
16 #include "zypp/PoolItem.h"
17 #include "zypp/ResPool.h"
18 #include "zypp/Package.h"
19 #include "zypp/VendorAttr.h"
20 
21 using std::endl;
22 
24 namespace 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( sat::Solvable solv_r );
61 
63  { return _resolvable; }
64 
66  {
69  return _status;
70  }
71 
72  public:
73  bool isUndetermined() const
74  {
75  return status().isUndetermined();
76  }
77 
78  bool isRelevant() const
79  {
80  return !status().isNonRelevant();
81  }
82 
83  bool isSatisfied() const
84  {
85  return status().isSatisfied();
86  }
87 
88  bool isBroken() const
89  {
90  return status().isBroken();
91  }
92 
93  bool isNeeded() const
94  {
95  return status().isToBeInstalled() || ( isBroken() && ! status().isLocked() );
96  }
97 
98  bool isUnwanted() const
99  {
100  return isBroken() && status().isLocked();
101  }
102 
103  private:
107 
112  public:
113  void saveState() const
114  { _savedStatus = status(); }
115  void restoreState() const
116  { status() = _savedStatus; }
117  bool sameState() const
118  {
119  if ( status() == _savedStatus )
120  return true;
121  // some bits changed...
122  if ( status().getTransactValue() != _savedStatus.getTransactValue()
123  && ( ! status().isBySolver() // ignore solver state changes
124  // removing a user lock also goes to bySolver
126  return false;
128  return false;
129  return true;
130  }
131  private:
134 
135  public:
137  static shared_ptr<Impl> nullimpl()
138  {
139  static shared_ptr<Impl> _nullimpl( new Impl );
140  return _nullimpl;
141  }
142  };
144 
146  inline std::ostream & operator<<( std::ostream & str, const PoolItem::Impl & obj )
147  {
148  str << obj.status();
149  if (obj.resolvable())
150  str << *obj.resolvable();
151  else
152  str << "(NULL)";
153  return str;
154  }
155 
157  {
158  PoolItem myBuddy( solv_r );
159  if ( myBuddy )
160  {
161  myBuddy._pimpl->_buddy = -resolvable()->satSolvable().id();
162  _buddy = myBuddy.satSolvable().id();
163  DBG << *this << " has buddy " << myBuddy << endl;
164  }
165  }
166 
168  //
169  // CLASS NAME : PoolItem
170  //
172 
174  //
175  // METHOD NAME : PoolItem::PoolItem
176  // METHOD TYPE : Ctor
177  //
179  : _pimpl( Impl::nullimpl() )
180  {}
181 
183  //
184  // METHOD NAME : PoolItem::PoolItem
185  // METHOD TYPE : Ctor
186  //
187  PoolItem::PoolItem( const sat::Solvable & solvable_r )
188  : _pimpl( ResPool::instance().find( solvable_r )._pimpl )
189  {}
190 
192  //
193  // METHOD NAME : PoolItem::PoolItem
194  // METHOD TYPE : Ctor
195  //
196  PoolItem::PoolItem( const ResObject::constPtr & resolvable_r )
197  : _pimpl( ResPool::instance().find( resolvable_r )._pimpl )
198  {}
199 
201  //
202  // METHOD NAME : PoolItem::PoolItem
203  // METHOD TYPE : Ctor
204  //
205  PoolItem::PoolItem( Impl * implptr_r )
206  : _pimpl( implptr_r )
207  {}
208 
210  //
211  // METHOD NAME : PoolItem::makePoolItem
212  // METHOD TYPE : PoolItem
213  //
215  {
216  return PoolItem( new Impl( makeResObject( solvable_r ), solvable_r.isSystem() ) );
217  }
218 
220  //
221  // METHOD NAME : PoolItem::~PoolItem
222  // METHOD TYPE : Dtor
223  //
225  {}
226 
228  //
229  // METHOD NAME : PoolItem::pool
230  // METHOD TYPE : ResPool
231  //
233  { return ResPool::instance(); }
234 
236  //
237  // Forward to Impl:
238  //
240 
242  { return _pimpl->status(); }
243 
245  { return _pimpl->statusReset(); }
246 
248  { return _pimpl->buddy(); }
249 
251  { _pimpl->setBuddy( solv_r ); }
252 
254  { return _pimpl->isUndetermined(); }
255 
256  bool PoolItem::isRelevant() const
257  { return _pimpl->isRelevant(); }
258 
260  { return _pimpl->isSatisfied(); }
261 
262  bool PoolItem::isBroken() const
263  { return _pimpl->isBroken(); }
264 
265  bool PoolItem::isNeeded() const
266  { return _pimpl->isNeeded(); }
267 
268  bool PoolItem::isUnwanted() const
269  { return _pimpl->isUnwanted(); }
270 
271  void PoolItem::saveState() const
272  { _pimpl->saveState(); }
273 
275  { _pimpl->restoreState(); }
276 
277  bool PoolItem::sameState() const
278  { return _pimpl->sameState(); }
279 
281  { return _pimpl->resolvable(); }
282 
283  /******************************************************************
284  **
285  ** FUNCTION NAME : operator<<
286  ** FUNCTION TYPE : std::ostream &
287  */
288  std::ostream & operator<<( std::ostream & str, const PoolItem & obj )
289  {
290  return str << *obj._pimpl;
291  }
292 
294 } // namespace zypp
A Solvable object within the sat Pool.
Definition: Solvable.h:55
PoolItem()
Default ctor for use in std::container.
Definition: PoolItem.cc:178
TransactValue getTransactValue() const
Definition: ResStatus.h:267
DefaultIntegral< sat::detail::IdType, sat::detail::noId > _buddy
Definition: PoolItem.cc:106
bool sameState() const
Definition: PoolItem.cc:277
ResStatus & statusReset() const
Reset status.
Definition: PoolItem.cc:244
bool isNeeded() const
Definition: PoolItem.cc:93
void saveState() const
Definition: PoolItem.cc:113
bool isNonRelevant() const
Definition: ResStatus.h:222
ResStatus & status() const
Definition: PoolItem.cc:48
bool isSystem() const
Return whether this Solvable belongs to the system repo.
Definition: Solvable.cc:154
void saveState() const
Definition: PoolItem.cc:271
bool isLocked() const
Definition: ResStatus.h:252
std::ostream & operator<<(std::ostream &str, const PoolItem::Impl &obj)
Definition: PoolItem.cc:146
bool resetTransact(TransactByValue causer_r)
Not the same as setTransact( false ).
Definition: ResStatus.h:473
~PoolItem()
Dtor.
Definition: PoolItem.cc:224
TraitsType::constPtrType constPtr
Definition: ResObject.h:50
static const Solvable noSolvable
Represents no Solvable.
Definition: Solvable.h:71
bool isBroken() const
Definition: PoolItem.cc:88
bool isUndetermined() const
Definition: PoolItem.cc:73
bool isSatisfied() const
Definition: ResStatus.h:216
Impl(ResObject::constPtr res_r, const ResStatus &status_r)
Definition: PoolItem.cc:42
ResStatus _savedStatus
Definition: PoolItem.cc:132
bool isUndetermined() const
No validation is performed for packages.
Definition: PoolItem.cc:253
ResObject::constPtr resolvable() const
Returns the ResObject::constPtr.
Definition: PoolItem.cc:280
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
bool sameState() const
Definition: PoolItem.cc:117
void restoreState() const
Definition: PoolItem.cc:115
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition: PoolItem.cc:137
PoolItem implementation.
Definition: PoolItem.cc:37
sat::Solvable buddy() const
Definition: PoolItem.cc:51
void setBuddy(sat::Solvable solv_r)
Definition: PoolItem.cc:156
ResObject::constPtr resolvable() const
Definition: PoolItem.cc:62
ResStatus & status() const
Returns the current status.
Definition: PoolItem.cc:241
static PoolItem makePoolItem(const sat::Solvable &solvable_r)
PoolItem generator for pool::PoolImpl.
Definition: PoolItem.cc:214
bool isRelevant() const
Returns true if the solvable is relevant which means e.g.
Definition: PoolItem.cc:256
bool isNeeded() const
This includes unlocked broken patches, as well as those already selected to be installed (otherwise c...
Definition: PoolItem.cc:265
bool setLock(bool toLock_r, TransactByValue causer_r)
Apply a lock (prevent transaction).
Definition: ResStatus.h:376
bool isSatisfied() const
Definition: PoolItem.cc:83
void restoreState() const
Definition: PoolItem.cc:274
bool isLicenceConfirmed() const
Definition: ResStatus.h:175
ResObject::constPtr _resolvable
Definition: PoolItem.cc:105
bool isBroken() const
Definition: ResStatus.h:219
bool isUndetermined() const
Definition: ResStatus.h:213
bool isUnwanted() const
Definition: PoolItem.cc:98
bool isBroken() const
Whether a relevant items requirements are broken.
Definition: PoolItem.cc:262
ResStatus & statusReset() const
Definition: PoolItem.cc:65
sat::Solvable buddy() const
Return the buddy we share our status object with.
Definition: PoolItem.cc:247
Global ResObject pool.
Definition: ResPool.h:48
bool isToBeInstalled() const
Definition: ResStatus.h:241
void setBuddy(sat::Solvable solv_r)
Buddies are set by pool::PoolImpl.
Definition: PoolItem.cc:250
friend class Impl
Definition: PoolItem.h:144
sat::Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: PoolItem.h:114
Status bitfield.
Definition: ResStatus.h:53
bool isSatisfied() const
Whether a relevant items requirements are met.
Definition: PoolItem.cc:259
ResObject::Ptr makeResObject(const sat::Solvable &solvable_r)
Create ResObject from sat::Solvable.
Definition: ResObject.cc:123
Reference to a PoolItem connecting ResObject and ResStatus.
Definition: PoolItem.h:50
IdType id() const
Expert backdoor.
Definition: Solvable.h:296
ResPool pool() const
Return the ResPool the item belongs to.
Definition: PoolItem.cc:232
bool isBySolver() const
Definition: ResStatus.h:278
bool isRelevant() const
Definition: PoolItem.cc:78
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PoolItem.h:153
bool isUnwanted() const
Broken (needed) but locked patches.
Definition: PoolItem.cc:268
#define DBG
Definition: Logger.h:46
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:33