libzypp 17.31.32
ResStatus.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_RESSTATUS_H
13#define ZYPP_RESSTATUS_H
14
15#include <inttypes.h>
16#include <iosfwd>
17#include <zypp/Bit.h>
18
20namespace zypp
21{
22
23 namespace resstatus
24 {
25 struct UserLockQueryManip;
26 class StatusBackup;
27 }
28
30 //
31 // CLASS NAME : ResStatus
32 //
54 {
55 friend std::ostream & operator<<( std::ostream & str, const ResStatus & obj );
56 friend bool operator==( const ResStatus & lhs, const ResStatus & rhs );
57
58 public:
67 // Bit Ranges within FieldType defined by 1st bit and size:
76 // enlarge FieldType if more bits are needed. It's not yet
77 // checked by the compiler.
79 public:
80
113
131
137
146
153
154 public:
155
157 ResStatus();
158
160 ResStatus( bool isInstalled_r );
161
163 ~ResStatus();
164
171 { return _bitfield; }
172
173 public:
174
177
180
181 public:
182 bool isRecommended() const
183 { return _bitfield.test( RECOMMENDED ); }
184
185 bool isSuggested() const
186 { return _bitfield.test( SUGGESTED ); }
187
188 bool isOrphaned() const
189 { return _bitfield.test( ORPHANED ); }
190
191 bool isUnneeded() const
192 { return _bitfield.test( UNNEEDED ); }
193
194 bool hasWeak() const
195 { return ! fieldValueIs<WeakField>( NO_WEAK ); }
196
199
200 void setRecommended( bool toVal_r = true )
202
203 void setSuggested( bool toVal_r = true )
205
206 void setOrphaned( bool toVal_r = true )
208
209 void setUnneeded( bool toVal_r = true )
211
212 public:
215
218
219 bool isSatisfied() const
221
222 bool isBroken() const
224
227
228 std::string validateValueAsString() const
229 { return validateValueAsString( validate() ); }
230
232 static std::string validateValueAsString( ValidateValue val_r );
233
235 static ValidateValue stringToValidateValue( const std::string & str_r );
236
237 public:
238 // These two are IMMUTABLE!
239
240 bool isInstalled() const
242
243 bool isUninstalled() const
245
246 public:
247
248 bool staysInstalled() const
249 { return isInstalled() && !transacts(); }
250
251 bool wasInstalled() const { return staysInstalled(); } //for old status
252
253 bool isToBeInstalled() const
254 { return isUninstalled() && transacts(); }
255
256 bool staysUninstalled() const
257 { return isUninstalled() && !transacts(); }
258
259 bool wasUninstalled() const { return staysUninstalled(); } // for old status
260
261 bool isToBeUninstalled() const
262 { return isInstalled() && transacts(); }
263
264 bool isLocked() const
266
267 bool isUserLocked() const
268 { return isLocked() && isByUser(); }
269
270 bool isSoftLocked() const
271 { return isKept() && ( isByApplLow() || isByUser() ); }
272
273 bool isKept() const
275
276 bool transacts() const
278
281
283 bool onSystem() const
284 { return( isInstalled() != transacts() ); }
285
287 bool offSystem() const
288 { return ! onSystem(); }
289
290 bool isBySolver() const
292
293 bool isByApplLow() const
295
296 bool isByApplHigh() const
298
299 bool isByUser() const
301
304
306 {
307 if ( isLessThan<TransactByField>( causer ) ) {
309 return true;
310 } else {
311 return false;
312 }
313 }
314
317
320
323
326
329
330 private:
334
338 public:
341
342 public:
343
344 //------------------------------------------------------------------------
345 // get/set functions, returning \c true if requested status change
346 // was successful (i.e. leading to the desired transaction).
347 // If a lower level (e.g.SOLVER) wants to transact, but it's
348 // already set by a higher level, \c true should be returned.
349 // Removing a higher levels transaction bit should fail.
350 //
351 // The may functions checks only, if the action would return true
352 // if it is called.
353
358 {
359 switch ( newVal_r )
360 {
361 case KEEP_STATE:
362 return setTransact( false, causer_r );
363 break;
364 case LOCKED:
365 return setLock( true, causer_r );
366 break;
367 case TRANSACT:
368 return setTransact( true, causer_r );
369 break;
370 }
371 return false;
372 }
373
381
388 {
389 if ( toLock_r == isLocked() )
390 {
391 // we're already in the desired state, but in case of
392 // LOCKED, remember a superior causer.
395 return true;
396 }
397 // Here: Lock status is to be changed:
398 if ( causer_r != USER && causer_r != APPL_HIGH )
399 return false;
400 if ( toLock_r ) {
401 // We're in unlocked state, which includes TRANSACT.
402 // Causer must be allowed to reset this. But from
403 // KEEP_STATE every causer is allowed to set the lock.
404 if ( ! setTransact( false, causer_r ) )
405 return false;
408 } else {
409 // To leave Locked state it needs a superior causer.
411 return false;
413 fieldValueAssign<TransactByField>( SOLVER ); // reset to lowest causer
414 // in order to distinguish from keep_state_by_user
415 }
416 return true;
417 }
418
426
433 {
434 if ( toTansact_r == transacts() )
435 {
436 // we're already in the desired state, but in case of
437 // TRANSACT, remember a superior causer.
440
441 fieldValueAssign<TransactDetailField>( NO_DETAIL ); // Details has to be set again
442 return true;
443 }
444 // Here: transact status is to be changed:
447 return false;
448 }
449
450 if ( toTansact_r )
451 {
453 }
454 else
455 {
457 }
458 fieldValueAssign<TransactDetailField>( NO_DETAIL ); // Details has to be set again
460 return true;
461 }
462
464 {
466 bool ret = setTransact (val_r, causer);
468 return ret;
469 }
470
473 {
474 if ( ! setTransact( false, causer_r ) )
475 return false;
479 return true;
480 }
481
485 {
486 if ( ! setTransact( false, causer_r ) )
487 return false;
490 return true;
491 }
492
504 {
506 && toTansact_r != transacts()
508 {
509 // any transact status change requires a superior causer.
510 return false;
511 }
513 }
514
517
526
528 { return maySetSoftTransact( val_r, causer, causer ); }
529
531 {
532 if (isInstalled()) return false;
533 return setTransact (true, causer);
534 }
535
537 {
539 bool ret = setToBeInstalled (causer);
541 return ret;
542 }
543
545 {
546 if (!isInstalled()) return false;
547 return setTransact (true, causer);
548 }
549
557
558 //------------------------------------------------------------------------
559 // *** These are only for the Resolver ***
560
562 {
563 if (!setToBeUninstalled (SOLVER)) return false;
565 return true;
566 }
567
569 {
570 if (!setToBeUninstalled (causer)) return false;
572 return true;
573 }
574
576 {
577 if (isInstalled()
578 || !setSoftTransact (true, SOLVER))
579 return false;
580
582 return true;
583 }
584
586 {
587 if (!isInstalled()
588 || !setSoftTransact (true, SOLVER))
589 return false;
590
592 return true;
593 }
594
602
606
610
611 bool setSoftInstall (bool flag) {
613 return true;
614 }
615
616 bool setSoftUninstall (bool flag) {
618 return true;
619 }
620
622 {
624 return true;
625 }
626
628 {
630 return true;
631 }
632
633 bool setBroken ()
634 {
636 return true;
637 }
638
640 {
642 return true;
643 }
644
646 {
647 // State field is immutable!
648 if ( _bitfield.value<StateField>() != newStatus_r._bitfield.value<StateField>() )
649 return false;
650 // Transaction state change allowed?
651 if ( ! setTransactValue( newStatus_r.getTransactValue(), newStatus_r.getTransactByValue() ) )
652 return false;
653
654 // Ok, we take it all..
655 _bitfield = newStatus_r._bitfield;
656 return true;
657 }
658
666
667 private:
674
677 template<class TField>
679 { return _bitfield.isEqual<TField>( val_r ); }
680
683 template<class TField>
686
689 template<class TField>
692
693 template<class TField>
695 { return _bitfield.value<TField>() < val_r; }
696
697 private:
700 };
702
704 std::ostream & operator<<( std::ostream & str, const ResStatus & obj );
705
707 std::ostream & operator<<( std::ostream & str, ResStatus::TransactValue obj );
708
710 std::ostream & operator<<( std::ostream & str, ResStatus::TransactByValue obj );
711
713 inline bool operator==( const ResStatus & lhs, const ResStatus & rhs )
714 { return lhs._bitfield == rhs._bitfield; }
715
717 inline bool operator!=( const ResStatus & lhs, const ResStatus & rhs )
718 { return ! (lhs == rhs); }
719
721
722 namespace resstatus
723 {
725 {
726 public:
728 : _status( 0 )
729 {}
730
735
736 void replay()
737 { if ( _status ) _status->_bitfield = _bitfield; }
738
739 private:
742 };
743 }
744
746} // namespace zypp
748#endif // ZYPP_RESSTATUS_H
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:94
reference value() const
Reference to the Tp object.
Status bitfield.
Definition ResStatus.h:54
bool staysUninstalled() const
Definition ResStatus.h:256
bool isLessThan(FieldType val_r)
Definition ResStatus.h:694
bool isLicenceConfirmed() const
Definition ResStatus.h:175
bool isSoftLocked() const
Definition ResStatus.h:270
BitFieldType _bitfield
Definition ResStatus.h:699
@ NO_DETAIL
Detail for no transact, i.e.
Definition ResStatus.h:117
static const ResStatus toBeInstalled
Definition ResStatus.h:661
ValidateValue validate() const
Definition ResStatus.h:213
bool setNonRelevant()
Definition ResStatus.h:639
void setUserLockQueryMatch(bool match_r)
Definition ResStatus.h:335
uint16_t FieldType
Definition ResStatus.h:65
bool isGreaterThan(FieldType val_r)
compare two values.
Definition ResStatus.h:690
bool isToBeInstalledSoft() const
Definition ResStatus.h:321
bit::Range< FieldType, StateField::end, 2 > ValidateField
Definition ResStatus.h:69
bool onSystem() const
True if would be on system after commit.
Definition ResStatus.h:283
~ResStatus()
Dtor.
Definition ResStatus.cc:50
bit::BitField< FieldType > BitFieldType
Definition ResStatus.h:66
bool setToBeUninstalled(TransactByValue causer)
Definition ResStatus.h:544
bool setToBeUninstalledDueToObsolete()
Definition ResStatus.h:561
static const ResStatus toBeUninstalledDueToObsolete
Definition ResStatus.h:664
bool isSuggested() const
Definition ResStatus.h:185
void setLicenceConfirmed(bool toVal_r=true)
Definition ResStatus.h:178
bool setSoftInstall(bool flag)
Definition ResStatus.h:611
void setRecommended(bool toVal_r=true)
Definition ResStatus.h:200
bool isByApplLow() const
Definition ResStatus.h:293
bool maySetSoftTransact(bool val_r, TransactByValue causer)
Definition ResStatus.h:527
static ValidateValue stringToValidateValue(const std::string &str_r)
ValidateValue from string used in the history file.
Definition ResStatus.cc:88
bool maySetTransactValue(TransactValue newVal_r, TransactByValue causer_r)
Definition ResStatus.h:374
bool setTransactValue(TransactValue newVal_r, TransactByValue causer_r)
Set TransactValue.
Definition ResStatus.h:357
bool isUndetermined() const
Definition ResStatus.h:216
bool fieldValueIs(FieldType val_r) const
Return whether the corresponding Field has value val_r.
Definition ResStatus.h:678
bool setSatisfied()
Definition ResStatus.h:627
friend std::ostream & operator<<(std::ostream &str, const ResStatus &obj)
Definition ResStatus.cc:102
bit::Range< FieldType, TransactDetailField::end, 1 > LicenceConfirmedField
Definition ResStatus.h:73
bool isSoftUninstall()
Definition ResStatus.h:607
bool setUndetermined()
Definition ResStatus.h:621
bool setTransact(bool toTansact_r, TransactByValue causer_r)
Toggle between TRANSACT and KEEP_STATE.
Definition ResStatus.h:432
bool isToBeInstalled() const
Definition ResStatus.h:253
bool isBroken() const
Definition ResStatus.h:222
bit::Range< FieldType, LicenceConfirmedField::end, 4 > WeakField
Definition ResStatus.h:74
bool offSystem() const
True if would be off system after commit.
Definition ResStatus.h:287
bool isByApplHigh() const
Definition ResStatus.h:296
void setOrphaned(bool toVal_r=true)
Definition ResStatus.h:206
bool isNonRelevant() const
Definition ResStatus.h:225
bool setToBeInstalled(TransactByValue causer)
Definition ResStatus.h:530
void setUnneeded(bool toVal_r=true)
Definition ResStatus.h:209
bool isLocked() const
Definition ResStatus.h:264
bool isUserLockQueryMatch() const
Definition ResStatus.h:339
bool setStatus(ResStatus newStatus_r)
Definition ResStatus.h:645
bool wasInstalled() const
Definition ResStatus.h:251
bool setToBeUninstalledSoft()
Definition ResStatus.h:585
bool maySetToBeUninstalled(TransactByValue causer)
Definition ResStatus.h:550
bool isKept() const
Definition ResStatus.h:273
bool setSoftLock(TransactByValue causer_r)
Definition ResStatus.h:472
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 staysInstalled() const
Definition ResStatus.h:248
static const ResStatus toBeUninstalledDueToUpgrade
Definition ResStatus.h:663
bool maySetToBeInstalled(TransactByValue causer)
Definition ResStatus.h:536
bool isToBeUninstalledDueToObsolete() const
Definition ResStatus.h:315
bool setSoftTransact(bool toTansact_r, TransactByValue causer_r, TransactByValue causerLimit_r)
Soft toggle between TRANSACT and KEEP_STATE.
Definition ResStatus.h:502
bool isSoftInstall()
Definition ResStatus.h:603
bool isByUser() const
Definition ResStatus.h:299
bit::Range< FieldType, TransactByField::end, 2 > TransactDetailField
Definition ResStatus.h:72
bit::Range< FieldType, TransactField::end, 2 > TransactByField
Definition ResStatus.h:71
bool setSoftTransact(bool toTansact_r, TransactByValue causer_r)
Definition ResStatus.h:515
bool setToBeInstalledSoft()
Definition ResStatus.h:575
static const ResStatus toBeUninstalled
Definition ResStatus.h:662
bit::Range< FieldType, WeakField::end, 1 > UserLockQueryField
Definition ResStatus.h:75
bool transacts() const
Definition ResStatus.h:276
bool isUserLocked() const
Definition ResStatus.h:267
bool wasUninstalled() const
Definition ResStatus.h:259
ResStatus()
Default ctor.
Definition ResStatus.cc:33
bit::Range< FieldType, ValidateField::end, 2 > TransactField
Definition ResStatus.h:70
bool maySetToBeUninstalledSoft()
Definition ResStatus.h:595
bool isRecommended() const
Definition ResStatus.h:182
BitFieldType bitfield() const
Debug helper returning the bitfield.
Definition ResStatus.h:170
bool isInstalled() const
Definition ResStatus.h:240
bool maySetTransact(bool val_r, TransactByValue causer)
Definition ResStatus.h:463
bool isOrphaned() const
Definition ResStatus.h:188
bool operator!=(const ResStatus &lhs, const ResStatus &rhs)
Definition ResStatus.h:717
bool isToBeUninstalled() const
Definition ResStatus.h:261
std::string validateValueAsString() const
Definition ResStatus.h:228
bool isToBeUninstalledDueToUpgrade() const
Definition ResStatus.h:318
TransactByValue getTransactByValue() const
Definition ResStatus.h:302
bit::Range< FieldType, 0, 1 > StateField
Definition ResStatus.h:68
bool resetTransact(TransactByValue causer_r)
Not the same as setTransact( false ).
Definition ResStatus.h:484
bool isSatisfied() const
Definition ResStatus.h:219
void setSuggested(bool toVal_r=true)
Definition ResStatus.h:203
bool setSoftUninstall(bool flag)
Definition ResStatus.h:616
bool maySetSoftTransact(bool val_r, TransactByValue causer, TransactByValue causerLimit_r)
Definition ResStatus.h:518
bool setTransactByValue(TransactByValue causer)
Definition ResStatus.h:305
bool isBySolver() const
Definition ResStatus.h:290
bool isUnneeded() const
Definition ResStatus.h:191
bool maySetLock(bool to_r, TransactByValue causer_r)
Definition ResStatus.h:419
bool hasWeak() const
Definition ResStatus.h:194
bool isToBeInstalledNotSoft() const
Definition ResStatus.h:324
void fieldValueAssign(FieldType val_r)
Set the corresponding Field to value val_r.
Definition ResStatus.h:684
bool setToBeUninstalledDueToUpgrade(TransactByValue causer)
Definition ResStatus.h:568
bool isToBeUninstalledSoft() const
Definition ResStatus.h:327
bool isUninstalled() const
Definition ResStatus.h:243
friend bool operator==(const ResStatus &lhs, const ResStatus &rhs)
An integral type used as BitField.
Definition Bit.h:160
bool test(TInt rhs)
Test whether all bits of rhs are set.
Definition Bit.h:253
BitField & set(TInt rhs, bool doset_r)
Set or unset bits of rhs.
Definition Bit.h:229
BitField & assign(TInt rhs)
Assign Range in rhs to this.
Definition Bit.h:201
TInt value() const
Return the value.
Definition Bit.h:179
bool isEqual(TInt rhs) const
Test for equal value within a Range.
Definition Bit.h:215
StatusBackup(ResStatus &status_r)
Definition ResStatus.h:731
ResStatus::BitFieldType _bitfield
Definition ResStatus.h:741
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
A value with in a Range.
Definition Bit.h:111
Range of bits starting at bit _begin with length _size.
Definition Bit.h:82
Manipulator for ResStatus::UserLockQueryField.
Definition PoolImpl.h:43