libzypp  17.7.2
SelectableImpl.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_UI_SELECTABLEIMPL_H
13 #define ZYPP_UI_SELECTABLEIMPL_H
14 
15 #include <iostream>
16 #include "zypp/base/LogTools.h"
17 
18 #include "zypp/base/PtrTypes.h"
19 
20 #include "zypp/ResPool.h"
21 #include "zypp/Resolver.h"
22 #include "zypp/ui/Selectable.h"
24 
25 using std::endl;
26 
28 namespace zypp
29 {
30  namespace ui
32  {
33 
35  //
36  // CLASS NAME : Selectable::Impl
37  //
43  {
44  public:
45 
50 
55 
57 
58  public:
59  template <class TIterator>
60  Impl( const ResKind & kind_r,
61  const std::string & name_r,
62  TIterator begin_r,
63  TIterator end_r )
64  : _ident( sat::Solvable::SplitIdent( kind_r, name_r ).ident() )
65  , _kind( kind_r )
66  , _name( name_r )
67  {
68  for_( it, begin_r, end_r )
69  {
70  if ( it->status().isInstalled() )
71  _installedItems.insert( *it );
72  else
73  _availableItems.insert( *it );
74  }
75  }
76 
77  public:
79  IdString ident() const
80  { return _ident; }
81 
83  ResKind kind() const
84  { return _kind; }
85 
87  const std::string & name() const
88  { return _name; }
89 
91  Status status() const;
92 
94  bool setStatus( Status state_r, ResStatus::TransactByValue causer_r );
95 
98  {
99  if ( installedEmpty() )
100  return PoolItem();
102  return ret ? ret : *_installedItems.begin();
103  }
104 
110  {
112  if ( ret )
113  return ret;
115  }
116 
121  PoolItem setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r );
122 
129  {
130  for ( const PoolItem & pi : available() )
131  {
132  if ( pi.repository() == repo_r )
133  return pi;
134  }
135  return PoolItem();
136  }
137 
145  {
146  PoolItem defaultCand( defaultCandidate() );
147 
148  // multiversionInstall: This returns the candidate for the last
149  // instance installed. Actually we'd need a list here.
150 
151  if ( installedEmpty() || ! defaultCand )
152  return defaultCand;
153  // Here: installed and defaultCand are non NULL and it's not a
154  // multiversion install.
155 
157  // check vendor change
158  if ( ! ( ResPool::instance().resolver().allowVendorChange()
159  || VendorAttr::instance().equivalent( defaultCand->vendor(), installed->vendor() ) ) )
160  return PoolItem();
161 
162  // check arch change (arch noarch changes are allowed)
163  if ( defaultCand->arch() != installed->arch()
164  && ! ( defaultCand->arch() == Arch_noarch || installed->arch() == Arch_noarch ) )
165  return PoolItem();
166 
167  // check greater edition
168  if ( defaultCand->edition() <= installed->edition() )
169  return PoolItem();
170 
171  return defaultCand;
172  }
173 
176  {
177  PoolItem ret;
178  for ( const PoolItem & pi : available() )
179  {
180  if ( !ret || pi.edition() > ret.edition() )
181  ret = pi;
182  }
183  return ret;
184  }
185 
187  bool identIsAutoInstalled() const
189 
191  bool identicalAvailable( const PoolItem & rhs ) const
192  { return bool(identicalAvailableObj( rhs )); }
193 
195  bool identicalInstalled( const PoolItem & rhs ) const
196  { return bool(identicalInstalledObj( rhs )); }
197 
200  {
201  if ( !availableEmpty() && rhs )
202  {
203  for_( it, _availableItems.begin(), _availableItems.end() )
204  {
205  if ( identical( *it, rhs ) )
206  return *it;
207  }
208  }
209  return PoolItem();
210  }
211 
214  {
215  if ( !installedEmpty() && rhs )
216  {
217  for_( it, _installedItems.begin(), _installedItems.end() )
218  {
219  if ( identical( *it, rhs ) )
220  return *it;
221  }
222  }
223  return PoolItem();
224  }
225 
227  PoolItem theObj() const
228  {
229  PoolItem ret( candidateObj() );
230  if ( ret )
231  return ret;
232  return installedObj();
233  }
234 
236 
237  bool availableEmpty() const
238  { return _availableItems.empty(); }
239 
241  { return _availableItems.size(); }
242 
244  { return _availableItems.begin(); }
245 
247  { return _availableItems.end(); }
248 
250  { return makeIterable( availableBegin(), availableEnd() ); }
251 
253 
254  bool installedEmpty() const
255  { return _installedItems.empty(); }
256 
258  { return _installedItems.size(); }
259 
261  { return _installedItems.begin(); }
262 
264  { return _installedItems.end(); }
265 
267  { return makeIterable( installedBegin(), installedEnd() ); }
268 
270 
271  const PickList & picklist() const
272  {
273  if ( ! _picklistPtr )
274  {
275  _picklistPtr.reset( new PickList );
276  // installed without identical avaialble first:
277  for ( const PoolItem & pi : installed() )
278  {
279  if ( ! identicalAvailable( pi ) )
280  _picklistPtr->push_back( pi );
281  }
282  _picklistPtr->insert( _picklistPtr->end(), availableBegin(), availableEnd() );
283  }
284  return *_picklistPtr;
285  }
286 
287  bool picklistEmpty() const
288  { return picklist().empty(); }
289 
291  { return picklist().size(); }
292 
294  { return picklist().begin(); }
295 
297  { return picklist().end(); }
298 
300 
301  bool isUnmaintained() const
302  { return availableEmpty(); }
303 
304  bool multiversionInstall() const
305  {
306  for ( const PoolItem & pi : picklist() )
307  {
308  if ( pi.multiversionInstall() )
309  return true;
310  }
311  return false;
312  }
313 
314  bool pickInstall( const PoolItem & pi_r, ResStatus::TransactByValue causer_r, bool yesno_r );
315 
316  bool pickDelete( const PoolItem & pi_r, ResStatus::TransactByValue causer_r, bool yesno_r );
317 
318  Status pickStatus( const PoolItem & pi_r ) const;
319 
320  bool setPickStatus( const PoolItem & pi_r, Status state_r, ResStatus::TransactByValue causer_r );
321 
323 
324  bool isUndetermined() const
325  {
326  PoolItem cand( candidateObj() );
327  return ! cand || cand.isUndetermined();
328  }
329  bool isRelevant() const
330  {
331  PoolItem cand( candidateObj() );
332  return cand && cand.isRelevant();
333  }
334  bool isSatisfied() const
335  {
336  PoolItem cand( candidateObj() );
337  return cand && cand.isSatisfied();
338  }
339  bool isBroken() const
340  {
341  PoolItem cand( candidateObj() );
342  return cand && cand.isBroken();
343  }
344 
347 
349  bool hasLicenceConfirmed() const
350  { return candidateObj() && candidateObj().status().isLicenceConfirmed(); }
351 
353  void setLicenceConfirmed( bool val_r )
354  { if ( candidateObj() ) candidateObj().status().setLicenceConfirmed( val_r ); }
355 
356  private:
358  {
359  for ( const PoolItem & pi : installed() )
360  {
361  if ( pi.status().transacts() )
362  return pi;
363  }
364  return PoolItem();
365  }
366 
368  {
369  for ( const PoolItem & pi : available() )
370  {
371  if ( pi.status().transacts() )
372  return pi;
373  }
374  return PoolItem();
375  }
376 
378  {
379  if ( ! installedEmpty() )
380  {
381  // prefer the installed objects arch and vendor
382  bool solver_allowVendorChange( ResPool::instance().resolver().allowVendorChange() );
383  for ( const PoolItem & ipi : installed() )
384  {
385  PoolItem sameArch; // in case there's no same vendor at least stay with same arch.
386  for ( const PoolItem & api : available() )
387  {
388  // 'same arch' includes allowed changes to/from noarch.
389  if ( ipi.arch() == api.arch() || ipi.arch() == Arch_noarch || api.arch() == Arch_noarch )
390  {
391  if ( ! solver_allowVendorChange )
392  {
393  if ( VendorAttr::instance().equivalent( ipi, api ) )
394  return api;
395  else if ( ! sameArch ) // remember best same arch in case no same vendor found
396  sameArch = api;
397  }
398  else // same arch is sufficient
399  return api;
400  }
401  }
402  if ( sameArch )
403  return sameArch;
404  }
405  }
406  if ( _availableItems.empty() )
407  return PoolItem();
408 
409  return *_availableItems.begin();
410  }
411 
412  bool allCandidatesLocked() const
413  {
414  for ( const PoolItem & pi : available() )
415  {
416  if ( ! pi.status().isLocked() )
417  return false;
418  }
419  return( ! _availableItems.empty() );
420  }
421 
422  bool allInstalledLocked() const
423  {
424  for ( const PoolItem & pi : installed() )
425  {
426  if ( ! pi.status().isLocked() )
427  return false;
428  }
429  return( ! _installedItems.empty() );
430  }
431 
432 
433  private:
435  const ResKind _kind;
436  const std::string _name;
442  mutable scoped_ptr<PickList> _picklistPtr;
443  };
445 
447  inline std::ostream & operator<<( std::ostream & str, const Selectable::Impl & obj )
448  {
449  return str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status()
450  << " (I " << obj.installedSize() << ")"
451  << " (A " << obj.availableSize() << ")"
452  << obj.candidateObj();
453  }
454 
456  inline std::ostream & dumpOn( std::ostream & str, const Selectable::Impl & obj )
457  {
458  str << '[' << obj.kind() << ']' << obj.name() << ": " << obj.status()
459  << ( obj.multiversionInstall() ? " (multiversion)" : "") << endl;
460 
461  if ( obj.installedEmpty() )
462  str << " (I 0) {}" << endl << " ";
463  else
464  {
465  PoolItem icand( obj.installedObj() );
466  str << " (I " << obj.installedSize() << ") {" << endl;
467  for ( const PoolItem & pi : obj.installed() )
468  {
469  char t = ' ';
470  if ( pi == icand )
471  {
472  t = 'i';
473  }
474  str << " " << t << " " << pi << endl;
475  }
476  str << "} ";
477  }
478 
479  if ( obj.availableEmpty() )
480  {
481  str << "(A 0) {}" << endl << " ";
482  }
483  else
484  {
485  PoolItem cand( obj.candidateObj() );
486  PoolItem up( obj.updateCandidateObj() );
487  str << "(A " << obj.availableSize() << ") {" << endl;
488  for ( const PoolItem & pi : obj.available() )
489  {
490  char t = ' ';
491  if ( pi == cand )
492  {
493  t = pi == up ? 'C' : 'c';
494  }
495  else if ( pi == up )
496  {
497  t = 'u';
498  }
499  str << " " << t << " " << pi << endl;
500  }
501  str << "} ";
502  }
503 
504  if ( obj.picklistEmpty() )
505  {
506  str << "(P 0) {}";
507  }
508  else
509  {
510  PoolItem cand( obj.candidateObj() );
511  PoolItem up( obj.updateCandidateObj() );
512  str << "(P " << obj.picklistSize() << ") {" << endl;
513  for ( const PoolItem & pi : obj.picklist() )
514  {
515  char t = ' ';
516  if ( pi == cand )
517  {
518  t = pi == up ? 'C' : 'c';
519  }
520  else if ( pi == up )
521  {
522  t = 'u';
523  }
524  str << " " << t << " " << pi << "\t" << obj.pickStatus( pi ) << endl;
525  }
526  str << "} ";
527  }
528 
529  return str;
530  }
532  } // namespace ui
535 } // namespace zypp
537 #endif // ZYPP_UI_SELECTABLEIMPL_H
bool hasLicenceConfirmed() const
Return value of LicenceConfirmed bit.
InstalledItemSet _installedItems
Status pickStatus(const PoolItem &pi_r) const
Status
UI status Status values calculated by Selectable.
Definition: Status.h:34
ResStatus::TransactByValue modifiedBy() const
Return who caused the modification.
AvailableItemSet _availableItems
bool equivalent(const Vendor &lVendor, const Vendor &rVendor) const
Return whether two vendor strings should be treated as the same vendor.
Definition: VendorAttr.cc:264
SelectableTraits::installed_size_type installed_size_type
picklist_iterator picklistEnd() const
scoped_ptr< PickList > _picklistPtr
lazy initialized picklist
bool setStatus(Status state_r, ResStatus::TransactByValue causer_r)
bool identicalInstalled(const PoolItem &rhs) const
True if rhs has the same content as an installed one.
ResStatus & status() const
Returns the current status.
Definition: PoolItem.cc:204
String related utilities and Regular expression matching.
SelectableTraits::available_iterator available_iterator
PoolItem defaultCandidate() const
Access to the sat-pools string space.
Definition: IdString.h:41
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
std::vector< PoolItem > PickList
Edition edition() const
Definition: SolvableType.h:71
bool isSatisfied() const
Whether a relevant items requirements are met.
Definition: PoolItem.cc:210
Iterable< installed_iterator > installed() const
void setLicenceConfirmed(bool toVal_r=true)
Definition: ResStatus.h:178
SelectableTraits::InstalledItemSet InstalledItemSet
std::set< PoolItem, AVOrder > AvailableItemSet
PoolItem setCandidate(const PoolItem &newCandidate_r, ResStatus::TransactByValue causer_r)
Set a userCandidate (out of available objects).
PoolItem theObj() const
Best among all objects.
std::ostream & operator<<(std::ostream &str, const Selectable::Impl &obj)
PoolItem transactingCandidate() const
available_size_type availableSize() const
SelectableTraits::PickList PickList
SelectableTraits::installed_iterator installed_iterator
bool isBroken() const
Whether a relevant items requirements are broken.
Definition: PoolItem.cc:211
bool identIsAutoInstalled() const
Whether an installed solvable with the same ident is flagged as AutoInstalled.
Definition: Solvable.h:134
picklist_iterator picklistBegin() const
PoolItem identicalInstalledObj(const PoolItem &rhs) const
an installed Object with the same content as rhs.
installed_size_type installedSize() const
bool identical(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:214
Impl(const ResKind &kind_r, const std::string &name_r, TIterator begin_r, TIterator end_r)
bool isUndetermined() const
No validation is performed for packages.
Definition: PoolItem.cc:208
AvailableItemSet::const_iterator available_const_iterator
installed_iterator installedEnd() const
PoolItem candidateObj() const
Best among available objects.
AvailableItemSet::const_iterator installed_const_iterator
SelectableTraits::available_const_iterator available_const_iterator
available_iterator availableBegin() const
const std::string & name() const
PoolItem updateCandidateObj() const
The best candidate for update, if there is one.
SelectableTraits::AvailableItemSet AvailableItemSet
std::ostream & dumpOn(std::ostream &str, const Selectable::Impl &obj)
picklist_size_type picklistSize() const
bool identicalAvailable(const PoolItem &rhs) const
True if rhs is installed and one with the same content is available.
PoolItem identicalAvailableObj(const PoolItem &rhs) const
Return an available Object with the same content as rhs.
Iterable< available_iterator > available() const
bool isRelevant() const
Returns true if the solvable is relevant which means e.g.
Definition: PoolItem.cc:209
PoolItem _candidate
The object selected by setCandidateObj() method.
bool isLicenceConfirmed() const
Definition: ResStatus.h:175
Selectable implementation.
SelectableTraits::installed_const_iterator installed_const_iterator
PoolItem highestAvailableVersionObj() const
Simply the highest available version, ignoring priorities and policies.
AvailableItemSet::iterator installed_iterator
available_iterator availableEnd() const
void setLicenceConfirmed(bool val_r)
Set LicenceConfirmed bit.
installed_iterator installedBegin() const
std::set< PoolItem, IOrder > InstalledItemSet
PoolItem transactingInstalled() const
AvailableItemSet::size_type installed_size_type
SelectableTraits::picklist_iterator picklist_iterator
Definition: Selectable.h:67
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
bool setPickStatus(const PoolItem &pi_r, Status state_r, ResStatus::TransactByValue causer_r)
SelectableTraits::available_size_type available_size_type
static const VendorAttr & instance()
Singleton.
Definition: VendorAttr.cc:121
bool pickInstall(const PoolItem &pi_r, ResStatus::TransactByValue causer_r, bool yesno_r)
bool identIsAutoInstalled() const
Whether this ident is flagged as AutoInstalled.
Resolvable kinds.
Definition: ResKind.h:32
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
SelectableTraits::picklist_size_type picklist_size_type
Definition: Selectable.h:68
PoolItem candidateObjFrom(Repository repo_r) const
The best candidate provided by a specific Repository, if there is one.
IdString vendor() const
Definition: SolvableType.h:73
bool pickDelete(const PoolItem &pi_r, ResStatus::TransactByValue causer_r, bool yesno_r)
AvailableItemSet::size_type available_size_type
AvailableItemSet::iterator available_iterator
PoolItem installedObj() const
Installed object (transacting ot highest version).
const PickList & picklist() const
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:33