libzypp 17.37.17
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#include <zypp/Globals.h>
19
21namespace zypp
22{
23
24 namespace resstatus
25 {
26 struct UserLockQueryManip;
27 class StatusBackup;
28 }
29
31 //
32 // CLASS NAME : ResStatus
33 //
55 {
56 friend std::ostream & operator<<( std::ostream & str, const ResStatus & obj );
57 friend bool operator==( const ResStatus & lhs, const ResStatus & rhs );
58
59 public:
66 using FieldType = uint16_t;
68 // Bit Ranges within FieldType defined by 1st bit and size:
77 // enlarge FieldType if more bits are needed. It's not yet
78 // checked by the compiler.
80 public:
81
114
132
138
147
153
154
155 public:
156
158 ResStatus();
159
161 ResStatus( bool isInstalled_r );
162
164 ~ResStatus();
165
166 ResStatus(const ResStatus &) = default;
167 ResStatus(ResStatus &&) noexcept = default;
168 ResStatus &operator=(const ResStatus &) = default;
169 ResStatus &operator=(ResStatus &&) noexcept = default;
170
177 { return _bitfield; }
178
179 public:
180
183
186
187 public:
188 bool isRecommended() const
189 { return _bitfield.test( RECOMMENDED ); }
190
191 bool isSuggested() const
192 { return _bitfield.test( SUGGESTED ); }
193
194 bool isOrphaned() const
195 { return _bitfield.test( ORPHANED ); }
196
197 bool isUnneeded() const
198 { return _bitfield.test( UNNEEDED ); }
199
200 bool hasWeak() const
201 { return ! fieldValueIs<WeakField>( NO_WEAK ); }
202
205
206 void setRecommended( bool toVal_r = true )
207 { _bitfield.set( RECOMMENDED, toVal_r ); }
208
209 void setSuggested( bool toVal_r = true )
210 { _bitfield.set( SUGGESTED, toVal_r ); }
211
212 void setOrphaned( bool toVal_r = true )
213 { _bitfield.set( ORPHANED, toVal_r ); }
214
215 void setUnneeded( bool toVal_r = true )
216 { _bitfield.set( UNNEEDED, toVal_r ); }
217
218 public:
220 { return (ValidateValue)_bitfield.value<ValidateField>(); }
221
224
225 bool isSatisfied() const
227
228 bool isBroken() const
230
233
234 std::string validateValueAsString() const
235 { return validateValueAsString( validate() ); }
236
238 static std::string validateValueAsString( ValidateValue val_r );
239
241 static ValidateValue stringToValidateValue( const std::string & str_r );
242
243 public:
244 // These two are IMMUTABLE!
245
246 bool isInstalled() const
248
249 bool isUninstalled() const
251
252 public:
253
254 bool staysInstalled() const
255 { return isInstalled() && !transacts(); }
256
257 bool wasInstalled() const { return staysInstalled(); } //for old status
258
259 bool isToBeInstalled() const
260 { return isUninstalled() && transacts(); }
261
262 bool staysUninstalled() const
263 { return isUninstalled() && !transacts(); }
264
265 bool wasUninstalled() const { return staysUninstalled(); } // for old status
266
267 bool isToBeUninstalled() const
268 { return isInstalled() && transacts(); }
269
270 bool isLocked() const
272
273 bool isUserLocked() const
274 { return isLocked() && isByUser(); }
275
276 bool isSoftLocked() const
277 { return isKept() && ( isByApplLow() || isByUser() ); }
278
279 bool isKept() const
281
282 bool transacts() const
284
287
289 bool onSystem() const
290 { return( isInstalled() != transacts() ); }
291
293 bool offSystem() const
294 { return ! onSystem(); }
295
296 bool isBySolver() const
298
299 bool isByApplLow() const
301
302 bool isByApplHigh() const
304
305 bool isByUser() const
307
310
312 {
313 if ( isLessThan<TransactByField>( causer ) ) {
315 return true;
316 } else {
317 return false;
318 }
319 }
320
323
326
329
332
335
336 private:
340
343
344 public:
347
348 public:
349
350 //------------------------------------------------------------------------
351 // get/set functions, returning \c true if requested status change
352 // was successful (i.e. leading to the desired transaction).
353 // If a lower level (e.g.SOLVER) wants to transact, but it's
354 // already set by a higher level, \c true should be returned.
355 // Removing a higher levels transaction bit should fail.
356 //
357 // The may functions checks only, if the action would return true
358 // if it is called.
359
364 {
365 switch ( newVal_r )
366 {
367 case KEEP_STATE:
368 return setTransact( false, causer_r );
369 break;
370 case LOCKED:
371 return setLock( true, causer_r );
372 break;
373 case TRANSACT:
374 return setTransact( true, causer_r );
375 break;
376 }
377 return false;
378 }
379
381 {
383 bool ret = setTransactValue( newVal_r, causer_r );
384 _bitfield = savBitfield;
385 return ret;
386 }
387
393 bool setLock( bool toLock_r, TransactByValue causer_r )
394 {
395 if ( toLock_r == isLocked() )
396 {
397 // we're already in the desired state, but in case of
398 // LOCKED, remember a superior causer.
399 if ( isLocked() && isLessThan<TransactByField>( causer_r ) )
401 return true;
402 }
403 // Here: Lock status is to be changed:
404 if ( causer_r != USER && causer_r != APPL_HIGH )
405 return false;
406 if ( toLock_r ) {
407 // We're in unlocked state, which includes TRANSACT.
408 // Causer must be allowed to reset this. But from
409 // KEEP_STATE every causer is allowed to set the lock.
410 if ( ! setTransact( false, causer_r ) )
411 return false;
414 } else {
415 // To leave Locked state it needs a superior causer.
416 if ( isGreaterThan<TransactByField>( causer_r ) )
417 return false;
419 fieldValueAssign<TransactByField>( SOLVER ); // reset to lowest causer
420 // in order to distinguish from keep_state_by_user
421 }
422 return true;
423 }
424
425 bool maySetLock( bool to_r, TransactByValue causer_r )
426 {
428 bool ret = setLock( to_r, causer_r );
429 _bitfield = savBitfield;
430 return ret;
431 }
432
438 bool setTransact( bool toTansact_r, TransactByValue causer_r )
439 {
440 if ( toTansact_r == transacts() )
441 {
442 // we're already in the desired state, but in case of
443 // TRANSACT, remember a superior causer.
444 if ( transacts() && isLessThan<TransactByField>( causer_r ) )
446
447 fieldValueAssign<TransactDetailField>( NO_DETAIL ); // Details has to be set again
448 return true;
449 }
450 // Here: transact status is to be changed:
452 && isGreaterThan<TransactByField>( causer_r ) ) {
453 return false;
454 }
455
456 if ( toTansact_r )
457 {
459 }
460 else
461 {
463 }
464 fieldValueAssign<TransactDetailField>( NO_DETAIL ); // Details has to be set again
466 return true;
467 }
468
469 bool maySetTransact( bool val_r, TransactByValue causer )
470 {
472 bool ret = setTransact (val_r, causer);
473 _bitfield = savBitfield;
474 return ret;
475 }
476
479 {
480 if ( ! setTransact( false, causer_r ) )
481 return false;
483 && isLessThan<TransactByField>( causer_r ) )
485 return true;
486 }
487
491 {
492 if ( ! setTransact( false, causer_r ) )
493 return false;
496 return true;
497 }
498
508 bool setSoftTransact( bool toTansact_r, TransactByValue causer_r,
509 TransactByValue causerLimit_r )
510 {
512 && toTansact_r != transacts()
513 && isGreaterThan<TransactByField>( causerLimit_r ) )
514 {
515 // any transact status change requires a superior causer.
516 return false;
517 }
518 return setTransact( toTansact_r, causer_r );
519 }
520
521 bool setSoftTransact( bool toTansact_r, TransactByValue causer_r )
522 { return setSoftTransact( toTansact_r, causer_r, causer_r ); }
523
524 bool maySetSoftTransact( bool val_r, TransactByValue causer,
525 TransactByValue causerLimit_r )
526 {
528 bool ret = setSoftTransact( val_r, causer, causerLimit_r );
529 _bitfield = savBitfield;
530 return ret;
531 }
532
533 bool maySetSoftTransact( bool val_r, TransactByValue causer )
534 { return maySetSoftTransact( val_r, causer, causer ); }
535
537 {
538 if (isInstalled()) return false;
539 return setTransact (true, causer);
540 }
541
543 {
545 bool ret = setToBeInstalled (causer);
546 _bitfield = savBitfield;
547 return ret;
548 }
549
551 {
552 if (!isInstalled()) return false;
553 return setTransact (true, causer);
554 }
555
557 {
559 bool ret = setToBeUninstalled (causer);
560 _bitfield = savBitfield;
561 return ret;
562 }
563
564 //------------------------------------------------------------------------
565 // *** These are only for the Resolver ***
566
568 {
569 if (!setToBeUninstalled (SOLVER)) return false;
571 return true;
572 }
573
575 {
576 if (!setToBeUninstalled (causer)) return false;
578 return true;
579 }
580
582 {
583 if (isInstalled()
584 || !setSoftTransact (true, SOLVER))
585 return false;
586
588 return true;
589 }
590
592 {
593 if (!isInstalled()
594 || !setSoftTransact (true, SOLVER))
595 return false;
596
598 return true;
599 }
600
602 {
604 bool ret = setToBeUninstalledSoft ();
605 _bitfield = savBitfield;
606 return ret;
607 }
608
612
616
617 bool setSoftInstall (bool flag) {
619 return true;
620 }
621
622 bool setSoftUninstall (bool flag) {
624 return true;
625 }
626
628 {
630 return true;
631 }
632
634 {
636 return true;
637 }
638
639 bool setBroken ()
640 {
642 return true;
643 }
644
646 {
648 return true;
649 }
650
651 bool setStatus( const ResStatus& newStatus_r )
652 {
653 // State field is immutable!
654 if ( _bitfield.value<StateField>() != newStatus_r._bitfield.value<StateField>() )
655 return false;
656 // Transaction state change allowed?
657 if ( ! setTransactValue( newStatus_r.getTransactValue(), newStatus_r.getTransactByValue() ) )
658 return false;
659
660 // Ok, we take it all..
661 _bitfield = newStatus_r._bitfield;
662 return true;
663 }
664
672
673 private:
680
683 template<class TField>
684 bool fieldValueIs( FieldType val_r ) const
685 { return _bitfield.isEqual<TField>( val_r ); }
686
689 template<class TField>
691 { _bitfield.assign<TField>( val_r ); }
692
695 template<class TField>
697 { return _bitfield.value<TField>() > val_r; }
698
699 template<class TField>
700 bool isLessThan( FieldType val_r )
701 { return _bitfield.value<TField>() < val_r; }
702
703 private:
706 };
707
708
710 std::ostream & operator<<( std::ostream & str, const ResStatus & obj ) ZYPP_API;
711
713 std::ostream & operator<<( std::ostream & str, ResStatus::TransactValue obj ) ZYPP_API;
714
716 std::ostream & operator<<( std::ostream & str, ResStatus::TransactByValue obj ) ZYPP_API;
717
719 inline bool operator==( const ResStatus & lhs, const ResStatus & rhs )
720 { return lhs._bitfield == rhs._bitfield; }
721
723 inline bool operator!=( const ResStatus & lhs, const ResStatus & rhs )
724 { return ! (lhs == rhs); }
725
727
728 namespace resstatus
729 {
731 {
732 public:
734 : _status( 0 )
735 {}
736
738 : _status( &status_r )
740 {}
741
742 void replay()
743 { if ( _status ) _status->_bitfield = _bitfield; }
744
745 private:
748 };
749 }
750
752} // namespace zypp
754#endif // ZYPP_RESSTATUS_H
Status bitfield.
Definition ResStatus.h:55
bool staysUninstalled() const
Definition ResStatus.h:262
bool isLessThan(FieldType val_r)
Definition ResStatus.h:700
bool isLicenceConfirmed() const
Definition ResStatus.h:181
bool isSoftLocked() const
Definition ResStatus.h:276
BitFieldType _bitfield
Definition ResStatus.h:705
@ NO_DETAIL
Detail for no transact, i.e.
Definition ResStatus.h:118
static const ResStatus toBeInstalled
Definition ResStatus.h:667
ValidateValue validate() const
Definition ResStatus.h:219
bool setNonRelevant()
Definition ResStatus.h:645
void setUserLockQueryMatch(bool match_r)
Definition ResStatus.h:341
bool isGreaterThan(FieldType val_r)
compare two values.
Definition ResStatus.h:696
bit::Range< FieldType, WeakField::end, 1 > UserLockQueryField
Definition ResStatus.h:76
bool isToBeInstalledSoft() const
Definition ResStatus.h:327
bit::Range< FieldType, TransactField::end, 2 > TransactByField
Definition ResStatus.h:72
bool onSystem() const
True if would be on system after commit.
Definition ResStatus.h:289
bool setToBeUninstalled(TransactByValue causer)
Definition ResStatus.h:550
bool setToBeUninstalledDueToObsolete()
Definition ResStatus.h:567
static const ResStatus toBeUninstalledDueToObsolete
Definition ResStatus.h:670
bool isSuggested() const
Definition ResStatus.h:191
bit::Range< FieldType, LicenceConfirmedField::end, 4 > WeakField
Definition ResStatus.h:75
void setLicenceConfirmed(bool toVal_r=true)
Definition ResStatus.h:184
bool setSoftInstall(bool flag)
Definition ResStatus.h:617
void setRecommended(bool toVal_r=true)
Definition ResStatus.h:206
bool isByApplLow() const
Definition ResStatus.h:299
bool maySetSoftTransact(bool val_r, TransactByValue causer)
Definition ResStatus.h:533
bool maySetTransactValue(TransactValue newVal_r, TransactByValue causer_r)
Definition ResStatus.h:380
bool setTransactValue(TransactValue newVal_r, TransactByValue causer_r)
Set TransactValue.
Definition ResStatus.h:363
bool isUndetermined() const
Definition ResStatus.h:222
bool fieldValueIs(FieldType val_r) const
Return whether the corresponding Field has value val_r.
Definition ResStatus.h:684
bool setSatisfied()
Definition ResStatus.h:633
bool isSoftUninstall()
Definition ResStatus.h:613
bool setUndetermined()
Definition ResStatus.h:627
bool setTransact(bool toTansact_r, TransactByValue causer_r)
Toggle between TRANSACT and KEEP_STATE.
Definition ResStatus.h:438
bool isToBeInstalled() const
Definition ResStatus.h:259
bool isBroken() const
Definition ResStatus.h:228
bool offSystem() const
True if would be off system after commit.
Definition ResStatus.h:293
bool isByApplHigh() const
Definition ResStatus.h:302
void setOrphaned(bool toVal_r=true)
Definition ResStatus.h:212
bool isNonRelevant() const
Definition ResStatus.h:231
bool setToBeInstalled(TransactByValue causer)
Definition ResStatus.h:536
bool setStatus(const ResStatus &newStatus_r)
Definition ResStatus.h:651
void setUnneeded(bool toVal_r=true)
Definition ResStatus.h:215
bit::Range< FieldType, ValidateField::end, 2 > TransactField
Definition ResStatus.h:71
bool isLocked() const
Definition ResStatus.h:270
bool isUserLockQueryMatch() const
Definition ResStatus.h:345
ResStatus(ResStatus &&) noexcept=default
bool wasInstalled() const
Definition ResStatus.h:257
bool setToBeUninstalledSoft()
Definition ResStatus.h:591
bool maySetToBeUninstalled(TransactByValue causer)
Definition ResStatus.h:556
bool isKept() const
Definition ResStatus.h:279
bool setSoftLock(TransactByValue causer_r)
Definition ResStatus.h:478
bool setLock(bool toLock_r, TransactByValue causer_r)
Apply a lock (prevent transaction).
Definition ResStatus.h:393
TransactValue getTransactValue() const
Definition ResStatus.h:285
bool staysInstalled() const
Definition ResStatus.h:254
static const ResStatus toBeUninstalledDueToUpgrade
Definition ResStatus.h:669
bit::Range< FieldType, 0, 1 > StateField
Definition ResStatus.h:69
bool maySetToBeInstalled(TransactByValue causer)
Definition ResStatus.h:542
bool isToBeUninstalledDueToObsolete() const
Definition ResStatus.h:321
bool setSoftTransact(bool toTansact_r, TransactByValue causer_r, TransactByValue causerLimit_r)
Soft toggle between TRANSACT and KEEP_STATE.
Definition ResStatus.h:508
bool isSoftInstall()
Definition ResStatus.h:609
bool isByUser() const
Definition ResStatus.h:305
bool setSoftTransact(bool toTansact_r, TransactByValue causer_r)
Definition ResStatus.h:521
bool setToBeInstalledSoft()
Definition ResStatus.h:581
bit::Range< FieldType, TransactDetailField::end, 1 > LicenceConfirmedField
Definition ResStatus.h:74
static const ResStatus toBeUninstalled
Definition ResStatus.h:668
bool transacts() const
Definition ResStatus.h:282
bool isUserLocked() const
Definition ResStatus.h:273
bool wasUninstalled() const
Definition ResStatus.h:265
ResStatus()
Default ctor.
Definition ResStatus.cc:33
bit::BitField< FieldType > BitFieldType
Definition ResStatus.h:67
bit::Range< FieldType, TransactByField::end, 2 > TransactDetailField
Definition ResStatus.h:73
bool maySetToBeUninstalledSoft()
Definition ResStatus.h:601
bool isRecommended() const
Definition ResStatus.h:188
BitFieldType bitfield() const
Debug helper returning the bitfield.
Definition ResStatus.h:176
bool isInstalled() const
Definition ResStatus.h:246
bool maySetTransact(bool val_r, TransactByValue causer)
Definition ResStatus.h:469
bool isOrphaned() const
Definition ResStatus.h:194
bool operator!=(const ResStatus &lhs, const ResStatus &rhs)
Definition ResStatus.h:723
bool isToBeUninstalled() const
Definition ResStatus.h:267
std::string validateValueAsString() const
Definition ResStatus.h:234
bool isToBeUninstalledDueToUpgrade() const
Definition ResStatus.h:324
TransactByValue getTransactByValue() const
Definition ResStatus.h:308
ResStatus(const ResStatus &)=default
uint16_t FieldType
Definition ResStatus.h:66
bool resetTransact(TransactByValue causer_r)
Not the same as setTransact( false ).
Definition ResStatus.h:490
bool isSatisfied() const
Definition ResStatus.h:225
void setSuggested(bool toVal_r=true)
Definition ResStatus.h:209
bool setSoftUninstall(bool flag)
Definition ResStatus.h:622
bool maySetSoftTransact(bool val_r, TransactByValue causer, TransactByValue causerLimit_r)
Definition ResStatus.h:524
bit::Range< FieldType, StateField::end, 2 > ValidateField
Definition ResStatus.h:70
bool setTransactByValue(TransactByValue causer)
Definition ResStatus.h:311
bool isBySolver() const
Definition ResStatus.h:296
bool isUnneeded() const
Definition ResStatus.h:197
bool maySetLock(bool to_r, TransactByValue causer_r)
Definition ResStatus.h:425
bool hasWeak() const
Definition ResStatus.h:200
bool isToBeInstalledNotSoft() const
Definition ResStatus.h:330
void fieldValueAssign(FieldType val_r)
Set the corresponding Field to value val_r.
Definition ResStatus.h:690
bool setToBeUninstalledDueToUpgrade(TransactByValue causer)
Definition ResStatus.h:574
bool isToBeUninstalledSoft() const
Definition ResStatus.h:333
bool isUninstalled() const
Definition ResStatus.h:249
friend bool operator==(const ResStatus &lhs, const ResStatus &rhs)
An integral type used as BitField.
Definition Bit.h:160
TInt value() const
Return the value.
Definition Bit.h:179
StatusBackup(ResStatus &status_r)
Definition ResStatus.h:737
ResStatus::BitFieldType _bitfield
Definition ResStatus.h:747
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)
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
A value with in a Range.
Definition Bit.h:111
static const IntT value
Definition Bit.h:115
Range of bits starting at bit _begin with length _size.
Definition Bit.h:82
Manipulator for ResStatus::UserLockQueryField.
Definition PoolImpl.h:44