libzypp 17.32.2
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
165 ResStatus(const ResStatus &) = default;
167 ResStatus &operator=(const ResStatus &) = default;
169
176 { return _bitfield; }
177
178 public:
179
182
185
186 public:
187 bool isRecommended() const
188 { return _bitfield.test( RECOMMENDED ); }
189
190 bool isSuggested() const
191 { return _bitfield.test( SUGGESTED ); }
192
193 bool isOrphaned() const
194 { return _bitfield.test( ORPHANED ); }
195
196 bool isUnneeded() const
197 { return _bitfield.test( UNNEEDED ); }
198
199 bool hasWeak() const
200 { return ! fieldValueIs<WeakField>( NO_WEAK ); }
201
204
205 void setRecommended( bool toVal_r = true )
207
208 void setSuggested( bool toVal_r = true )
210
211 void setOrphaned( bool toVal_r = true )
213
214 void setUnneeded( bool toVal_r = true )
216
217 public:
220
223
224 bool isSatisfied() const
226
227 bool isBroken() const
229
232
233 std::string validateValueAsString() const
234 { return validateValueAsString( validate() ); }
235
237 static std::string validateValueAsString( ValidateValue val_r );
238
240 static ValidateValue stringToValidateValue( const std::string & str_r );
241
242 public:
243 // These two are IMMUTABLE!
244
245 bool isInstalled() const
247
248 bool isUninstalled() const
250
251 public:
252
253 bool staysInstalled() const
254 { return isInstalled() && !transacts(); }
255
256 bool wasInstalled() const { return staysInstalled(); } //for old status
257
258 bool isToBeInstalled() const
259 { return isUninstalled() && transacts(); }
260
261 bool staysUninstalled() const
262 { return isUninstalled() && !transacts(); }
263
264 bool wasUninstalled() const { return staysUninstalled(); } // for old status
265
266 bool isToBeUninstalled() const
267 { return isInstalled() && transacts(); }
268
269 bool isLocked() const
271
272 bool isUserLocked() const
273 { return isLocked() && isByUser(); }
274
275 bool isSoftLocked() const
276 { return isKept() && ( isByApplLow() || isByUser() ); }
277
278 bool isKept() const
280
281 bool transacts() const
283
286
288 bool onSystem() const
289 { return( isInstalled() != transacts() ); }
290
292 bool offSystem() const
293 { return ! onSystem(); }
294
295 bool isBySolver() const
297
298 bool isByApplLow() const
300
301 bool isByApplHigh() const
303
304 bool isByUser() const
306
309
311 {
312 if ( isLessThan<TransactByField>( causer ) ) {
314 return true;
315 } else {
316 return false;
317 }
318 }
319
322
325
328
331
334
335 private:
339
343 public:
346
347 public:
348
349 //------------------------------------------------------------------------
350 // get/set functions, returning \c true if requested status change
351 // was successful (i.e. leading to the desired transaction).
352 // If a lower level (e.g.SOLVER) wants to transact, but it's
353 // already set by a higher level, \c true should be returned.
354 // Removing a higher levels transaction bit should fail.
355 //
356 // The may functions checks only, if the action would return true
357 // if it is called.
358
363 {
364 switch ( newVal_r )
365 {
366 case KEEP_STATE:
367 return setTransact( false, causer_r );
368 break;
369 case LOCKED:
370 return setLock( true, causer_r );
371 break;
372 case TRANSACT:
373 return setTransact( true, causer_r );
374 break;
375 }
376 return false;
377 }
378
386
393 {
394 if ( toLock_r == isLocked() )
395 {
396 // we're already in the desired state, but in case of
397 // LOCKED, remember a superior causer.
400 return true;
401 }
402 // Here: Lock status is to be changed:
403 if ( causer_r != USER && causer_r != APPL_HIGH )
404 return false;
405 if ( toLock_r ) {
406 // We're in unlocked state, which includes TRANSACT.
407 // Causer must be allowed to reset this. But from
408 // KEEP_STATE every causer is allowed to set the lock.
409 if ( ! setTransact( false, causer_r ) )
410 return false;
413 } else {
414 // To leave Locked state it needs a superior causer.
416 return false;
418 fieldValueAssign<TransactByField>( SOLVER ); // reset to lowest causer
419 // in order to distinguish from keep_state_by_user
420 }
421 return true;
422 }
423
431
438 {
439 if ( toTansact_r == transacts() )
440 {
441 // we're already in the desired state, but in case of
442 // TRANSACT, remember a superior causer.
445
446 fieldValueAssign<TransactDetailField>( NO_DETAIL ); // Details has to be set again
447 return true;
448 }
449 // Here: transact status is to be changed:
452 return false;
453 }
454
455 if ( toTansact_r )
456 {
458 }
459 else
460 {
462 }
463 fieldValueAssign<TransactDetailField>( NO_DETAIL ); // Details has to be set again
465 return true;
466 }
467
469 {
471 bool ret = setTransact (val_r, causer);
473 return ret;
474 }
475
478 {
479 if ( ! setTransact( false, causer_r ) )
480 return false;
484 return true;
485 }
486
490 {
491 if ( ! setTransact( false, causer_r ) )
492 return false;
495 return true;
496 }
497
509 {
511 && toTansact_r != transacts()
513 {
514 // any transact status change requires a superior causer.
515 return false;
516 }
518 }
519
522
531
533 { return maySetSoftTransact( val_r, causer, causer ); }
534
536 {
537 if (isInstalled()) return false;
538 return setTransact (true, causer);
539 }
540
542 {
544 bool ret = setToBeInstalled (causer);
546 return ret;
547 }
548
550 {
551 if (!isInstalled()) return false;
552 return setTransact (true, causer);
553 }
554
562
563 //------------------------------------------------------------------------
564 // *** These are only for the Resolver ***
565
567 {
568 if (!setToBeUninstalled (SOLVER)) return false;
570 return true;
571 }
572
574 {
575 if (!setToBeUninstalled (causer)) return false;
577 return true;
578 }
579
581 {
582 if (isInstalled()
583 || !setSoftTransact (true, SOLVER))
584 return false;
585
587 return true;
588 }
589
591 {
592 if (!isInstalled()
593 || !setSoftTransact (true, SOLVER))
594 return false;
595
597 return true;
598 }
599
607
611
615
616 bool setSoftInstall (bool flag) {
618 return true;
619 }
620
621 bool setSoftUninstall (bool flag) {
623 return true;
624 }
625
627 {
629 return true;
630 }
631
633 {
635 return true;
636 }
637
638 bool setBroken ()
639 {
641 return true;
642 }
643
645 {
647 return true;
648 }
649
651 {
652 // State field is immutable!
653 if ( _bitfield.value<StateField>() != newStatus_r._bitfield.value<StateField>() )
654 return false;
655 // Transaction state change allowed?
656 if ( ! setTransactValue( newStatus_r.getTransactValue(), newStatus_r.getTransactByValue() ) )
657 return false;
658
659 // Ok, we take it all..
660 _bitfield = newStatus_r._bitfield;
661 return true;
662 }
663
671
672 private:
679
682 template<class TField>
684 { return _bitfield.isEqual<TField>( val_r ); }
685
688 template<class TField>
691
694 template<class TField>
697
698 template<class TField>
700 { return _bitfield.value<TField>() < val_r; }
701
702 private:
705 };
707
709 std::ostream & operator<<( std::ostream & str, const ResStatus & obj );
710
712 std::ostream & operator<<( std::ostream & str, ResStatus::TransactValue obj );
713
715 std::ostream & operator<<( std::ostream & str, ResStatus::TransactByValue obj );
716
718 inline bool operator==( const ResStatus & lhs, const ResStatus & rhs )
719 { return lhs._bitfield == rhs._bitfield; }
720
722 inline bool operator!=( const ResStatus & lhs, const ResStatus & rhs )
723 { return ! (lhs == rhs); }
724
726
727 namespace resstatus
728 {
730 {
731 public:
733 : _status( 0 )
734 {}
735
740
741 void replay()
742 { if ( _status ) _status->_bitfield = _bitfield; }
743
744 private:
747 };
748 }
749
751} // namespace zypp
753#endif // ZYPP_RESSTATUS_H
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
reference value() const
Reference to the Tp object.
Status bitfield.
Definition ResStatus.h:54
bool staysUninstalled() const
Definition ResStatus.h:261
bool isLessThan(FieldType val_r)
Definition ResStatus.h:699
bool isLicenceConfirmed() const
Definition ResStatus.h:180
bool isSoftLocked() const
Definition ResStatus.h:275
BitFieldType _bitfield
Definition ResStatus.h:704
@ NO_DETAIL
Detail for no transact, i.e.
Definition ResStatus.h:117
static const ResStatus toBeInstalled
Definition ResStatus.h:666
ValidateValue validate() const
Definition ResStatus.h:218
bool setNonRelevant()
Definition ResStatus.h:644
void setUserLockQueryMatch(bool match_r)
Definition ResStatus.h:340
bool isGreaterThan(FieldType val_r)
compare two values.
Definition ResStatus.h:695
bool isToBeInstalledSoft() const
Definition ResStatus.h:326
bool onSystem() const
True if would be on system after commit.
Definition ResStatus.h:288
~ResStatus()
Dtor.
Definition ResStatus.cc:50
bool setToBeUninstalled(TransactByValue causer)
Definition ResStatus.h:549
bool setToBeUninstalledDueToObsolete()
Definition ResStatus.h:566
static const ResStatus toBeUninstalledDueToObsolete
Definition ResStatus.h:669
bool isSuggested() const
Definition ResStatus.h:190
void setLicenceConfirmed(bool toVal_r=true)
Definition ResStatus.h:183
bool setSoftInstall(bool flag)
Definition ResStatus.h:616
void setRecommended(bool toVal_r=true)
Definition ResStatus.h:205
bool isByApplLow() const
Definition ResStatus.h:298
bool maySetSoftTransact(bool val_r, TransactByValue causer)
Definition ResStatus.h:532
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:379
bool setTransactValue(TransactValue newVal_r, TransactByValue causer_r)
Set TransactValue.
Definition ResStatus.h:362
bool isUndetermined() const
Definition ResStatus.h:221
bool fieldValueIs(FieldType val_r) const
Return whether the corresponding Field has value val_r.
Definition ResStatus.h:683
bool setSatisfied()
Definition ResStatus.h:632
friend std::ostream & operator<<(std::ostream &str, const ResStatus &obj)
Definition ResStatus.cc:102
bool isSoftUninstall()
Definition ResStatus.h:612
bool setUndetermined()
Definition ResStatus.h:626
bool setTransact(bool toTansact_r, TransactByValue causer_r)
Toggle between TRANSACT and KEEP_STATE.
Definition ResStatus.h:437
bool isToBeInstalled() const
Definition ResStatus.h:258
bool isBroken() const
Definition ResStatus.h:227
bool offSystem() const
True if would be off system after commit.
Definition ResStatus.h:292
bool isByApplHigh() const
Definition ResStatus.h:301
void setOrphaned(bool toVal_r=true)
Definition ResStatus.h:211
bool isNonRelevant() const
Definition ResStatus.h:230
bool setToBeInstalled(TransactByValue causer)
Definition ResStatus.h:535
bool setStatus(const ResStatus &newStatus_r)
Definition ResStatus.h:650
void setUnneeded(bool toVal_r=true)
Definition ResStatus.h:214
bool isLocked() const
Definition ResStatus.h:269
bool isUserLockQueryMatch() const
Definition ResStatus.h:344
ResStatus(ResStatus &&) noexcept=default
bool wasInstalled() const
Definition ResStatus.h:256
bool setToBeUninstalledSoft()
Definition ResStatus.h:590
bool maySetToBeUninstalled(TransactByValue causer)
Definition ResStatus.h:555
bool isKept() const
Definition ResStatus.h:278
bool setSoftLock(TransactByValue causer_r)
Definition ResStatus.h:477
bool setLock(bool toLock_r, TransactByValue causer_r)
Apply a lock (prevent transaction).
Definition ResStatus.h:392
TransactValue getTransactValue() const
Definition ResStatus.h:284
bool staysInstalled() const
Definition ResStatus.h:253
static const ResStatus toBeUninstalledDueToUpgrade
Definition ResStatus.h:668
bool maySetToBeInstalled(TransactByValue causer)
Definition ResStatus.h:541
bool isToBeUninstalledDueToObsolete() const
Definition ResStatus.h:320
bool setSoftTransact(bool toTansact_r, TransactByValue causer_r, TransactByValue causerLimit_r)
Soft toggle between TRANSACT and KEEP_STATE.
Definition ResStatus.h:507
bool isSoftInstall()
Definition ResStatus.h:608
bool isByUser() const
Definition ResStatus.h:304
bool setSoftTransact(bool toTansact_r, TransactByValue causer_r)
Definition ResStatus.h:520
bool setToBeInstalledSoft()
Definition ResStatus.h:580
static const ResStatus toBeUninstalled
Definition ResStatus.h:667
bool transacts() const
Definition ResStatus.h:281
bool isUserLocked() const
Definition ResStatus.h:272
bool wasUninstalled() const
Definition ResStatus.h:264
ResStatus()
Default ctor.
Definition ResStatus.cc:33
bool maySetToBeUninstalledSoft()
Definition ResStatus.h:600
bool isRecommended() const
Definition ResStatus.h:187
BitFieldType bitfield() const
Debug helper returning the bitfield.
Definition ResStatus.h:175
bool isInstalled() const
Definition ResStatus.h:245
bool maySetTransact(bool val_r, TransactByValue causer)
Definition ResStatus.h:468
bool isOrphaned() const
Definition ResStatus.h:193
bool operator!=(const ResStatus &lhs, const ResStatus &rhs)
Definition ResStatus.h:722
bool isToBeUninstalled() const
Definition ResStatus.h:266
std::string validateValueAsString() const
Definition ResStatus.h:233
bool isToBeUninstalledDueToUpgrade() const
Definition ResStatus.h:323
TransactByValue getTransactByValue() const
Definition ResStatus.h:307
ResStatus(const ResStatus &)=default
uint16_t FieldType
Definition ResStatus.h:65
bool resetTransact(TransactByValue causer_r)
Not the same as setTransact( false ).
Definition ResStatus.h:489
bool isSatisfied() const
Definition ResStatus.h:224
void setSuggested(bool toVal_r=true)
Definition ResStatus.h:208
bool setSoftUninstall(bool flag)
Definition ResStatus.h:621
bool maySetSoftTransact(bool val_r, TransactByValue causer, TransactByValue causerLimit_r)
Definition ResStatus.h:523
bool setTransactByValue(TransactByValue causer)
Definition ResStatus.h:310
bool isBySolver() const
Definition ResStatus.h:295
bool isUnneeded() const
Definition ResStatus.h:196
bool maySetLock(bool to_r, TransactByValue causer_r)
Definition ResStatus.h:424
bool hasWeak() const
Definition ResStatus.h:199
bool isToBeInstalledNotSoft() const
Definition ResStatus.h:329
void fieldValueAssign(FieldType val_r)
Set the corresponding Field to value val_r.
Definition ResStatus.h:689
bool setToBeUninstalledDueToUpgrade(TransactByValue causer)
Definition ResStatus.h:573
bool isToBeUninstalledSoft() const
Definition ResStatus.h:332
bool isUninstalled() const
Definition ResStatus.h:248
friend bool operator==(const ResStatus &lhs, const ResStatus &rhs)
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:736
ResStatus::BitFieldType _bitfield
Definition ResStatus.h:746
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:44