Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

PMSelectable.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                        (C) SuSE GmbH |
00011 \----------------------------------------------------------------------/
00012 
00013    File:       PMSelectable.h
00014 
00015    Author:     Michael Andres <ma@suse.de>
00016    Maintainer: Michael Andres <ma@suse.de>
00017 
00018 /-*/
00019 #ifndef PMSelectable_h
00020 #define PMSelectable_h
00021 
00022 #include <iosfwd>
00023 #include <list>
00024 
00025 #include <y2pm/PMSelectablePtr.h>
00026 
00027 #include <y2pm/PMTypes.h>
00028 #include <y2pm/SelState.h>
00029 #include <y2pm/PkgName.h>
00030 #include <y2pm/PkgArch.h>
00031 #include <y2pm/PMObjectPtr.h>
00032 
00034 //
00035 //      CLASS NAME : PMSelectable
00039 class PMSelectable : public CountedRep {
00040   REP_BODY(PMSelectable);
00041 
00042   public:
00043 
00044     typedef std::list<PMObjectPtr>  PMObjectList;
00045 
00046     class SavedState {
00047       public:
00048         SavedState() {}
00049       private:
00050         friend class PMManager;
00051 
00052         PMSelectablePtr _item;
00053         SelState        _state;
00054         PMObjectPtr     _userCandidateObj;
00055 
00056         SavedState( const PMSelectablePtr & item_r );
00057         bool mayReplay() const;
00058         bool replay();
00059         bool diff() const;
00060     };
00061 
00062   private:
00063 
00064     friend class Y2PM;
00065     static bool setCandidateOrder( PM::CandidateOrder neworder_r );
00066 
00067     typedef bool (*ClistCompare)( const PMObjectPtr & lhs, const PMObjectPtr & rhs );
00068 
00069     static ClistCompare _clistCompare;
00070 
00071     static bool clistAVS( const PMObjectPtr & lhs, const PMObjectPtr & rhs );
00072 
00073     static bool clistASV( const PMObjectPtr & lhs, const PMObjectPtr & rhs );
00074 
00075   private:
00076 
00077     friend class PMManager;
00078     friend class SavedState;
00079 
00080     PMManager * _manager;
00081     SelState    _state;
00082 
00083     void _mgr_attach( PMManager * mgr_r );
00084     void _mgr_detach();
00085 
00086     void _attach_obj( PMObjectPtr & obj_r );
00087     void _detach_obj( PMObjectPtr & obj_r );
00088 
00089     void setInstalledObj( PMObjectPtr obj_r );
00090     void delInstalledObj() { setInstalledObj( PMObjectPtr() ); }
00091 
00092     static bool clistIsBetter( const PMObjectPtr & lhs, const PMObjectPtr & rhs );
00093     void clistAdd( PMObjectPtr obj_r );
00094     void clistDel( PMObjectPtr obj_r );
00095     void clistSort();
00096     void clistClearAll();
00097 
00098     void clearAll();
00099 
00100     bool isEmpty() const;
00101 
00102     void check() const;
00103 
00104   private:
00105 
00106     PkgName _name;
00107 
00108     PMObjectPtr _installedObj;
00109     PMObjectPtr _candidateObj;
00110     PMObjectPtr _userCandidateObj;
00111 
00112     PMObjectList _candidateList;
00113 
00114     PMObjectList::iterator clistLookup( PMObjectPtr obj_r );
00115 
00116     void chooseCandidateObj();
00117     void clearCandidateObj();
00118 
00119   protected:
00120 
00121     PMSelectable();
00122 
00123     PMSelectable( const PkgName & name_r );
00124 
00125     virtual ~PMSelectable();
00126 
00127   public:
00128 
00132     const PkgName & name() const { return _name; }
00133 
00140     PMObjectPtr installedObj() const { return _installedObj; }
00141 
00148     PMObjectPtr candidateObj() const { return _candidateObj; }
00149 
00154     unsigned availableObjs() const { return _candidateList.size(); }
00155 
00159     PMObjectList::const_iterator av_begin() const { return _candidateList.begin(); }
00160 
00164     PMObjectList::const_iterator av_end() const { return _candidateList.end(); }
00165 
00169     PMObjectList::const_reverse_iterator av_rbegin() const { return _candidateList.rbegin(); }
00170 
00174     PMObjectList::const_reverse_iterator av_rend() const { return _candidateList.rend(); }
00175 
00176   public:
00177 
00185     PMObjectPtr theObject() const {
00186       if ( _candidateObj )
00187         return _candidateObj;
00188       if ( _installedObj )
00189         return _installedObj;
00190       PMObjectPtr ret = bestCandidate();
00191       if ( ret )
00192         return ret;
00193       if ( availableObjs() )
00194         return *av_begin();
00195       return PMObjectPtr();
00196     }
00197 
00202     PMObjectPtr autoCandidate() const;
00203 
00207     PMObjectPtr userCandidate() const {
00208       return _userCandidateObj;
00209     }
00210 
00214     PMObjectPtr bestCandidate() const {
00215       PMObjectPtr ret = userCandidate();
00216       if ( ret )
00217         return ret;
00218       return autoCandidate();
00219     }
00220 
00224     bool setUserCandidate( const PMObjectPtr & obj_r );
00225 
00229     bool clrUserCandidate() { return setUserCandidate( PMObjectPtr() ); }
00230 
00231   public:
00232 
00233     // Keep this order, it's used for sorting package lists!
00234     // Dangerous / noteworthy states are sorted first.
00235     //
00236     // sh@suse.de
00237 
00238     enum UI_Status {
00239       S_Protected,           // Keep this unmodified ( have installedObj && S_Protected )
00240       S_Taboo,               // Keep this unmodified ( have no installedObj && S_Taboo)
00241       // requested by user:
00242       S_Del,                 // delete  installedObj ( clears S_Protected if set )
00243       S_Update,              // install candidateObj ( have installedObj, clears S_Protected if set )
00244       S_Install,             // install candidateObj ( have no installedObj, clears S_Taboo if set )
00245       // not requested by user:
00246       S_AutoDel,             // delete  installedObj
00247       S_AutoUpdate,          // install candidateObj ( have installedObj )
00248       S_AutoInstall,         // install candidateObj ( have no installedObj )
00249       // no modification:
00250       S_KeepInstalled,       // no modification      ( have installedObj && !S_Protected, clears S_Protected if set )
00251       S_NoInst,              // no modification      ( have no installedObj && !S_Taboo, clears S_Taboo if set )
00252     };
00253 
00254     friend std::ostream & operator<<( std::ostream & str, UI_Status obj );
00255 
00256   private:
00257 
00261     bool intern_set_status( const UI_Status state_r, const bool doit );
00262 
00263   public:
00264 
00268     bool set_status( const UI_Status state_r );
00269 
00273     bool test_set_status( const UI_Status state_r ) { return intern_set_status( state_r, false ); }
00274 
00278     UI_Status status() const;
00279 
00280   public:
00281 
00285     bool providesSources() const;
00286 
00290     bool set_source_install( const bool install_r );
00291 
00295     bool source_install() const { return _state.is_srcins(); }
00296 
00297   public:
00298 
00299     enum Fate {
00300       TO_DELETE  = -1,
00301       UNMODIFIED = 0,
00302       TO_INSTALL = 1
00303     };
00304 
00305     Fate fate() const {
00306       if ( to_modify() ) {
00307         return( to_delete() ? TO_DELETE : TO_INSTALL );
00308       }
00309       return UNMODIFIED;
00310     }
00311 
00315     void setNothingSelected() { _state.user_unset( true ); }
00316 
00323     bool downgrade_condition() const;
00324 
00326     // public usable part of SelState
00328 
00332     bool has_object()    const { return _state.has_object(); }
00333 
00337     bool has_installed() const { return _state.has_installed(); }
00338 
00342     bool has_candidate() const { return _state.has_candidate(); }
00343 
00347     bool has_both_objects() const { return _state.has_both_objects(); }
00348 
00352     bool has_installed_only() const { return _state.has_installed_only(); }
00353 
00357     bool has_candidate_only() const { return _state.has_candidate_only(); }
00358 
00359   public:
00360 
00364     bool to_modify()     const { return _state.to_modify(); }
00365 
00369     bool to_delete()     const { return _state.to_delete(); }
00370 
00374     bool to_install()    const { return _state.to_install(); }
00375 
00376   public:
00377 
00381     bool by_user()       const { return _state.by_user(); }
00382 
00386     bool by_appl()       const { return _state.by_appl(); }
00387 
00391     bool by_auto()       const { return _state.by_auto(); }
00392 
00393   public:
00394 
00398     bool is_taboo()      const { return _state.is_taboo(); }
00399 
00400   public:
00401 
00406     bool user_unset() { return _state.user_unset( true ); }
00407 
00412     bool user_set_delete() { return _state.user_set_delete( true ); }
00413 
00418     bool user_set_install() { return _state.user_set_install( true ); }
00419 
00423     bool user_set_taboo() { return _state.user_set_taboo( true ); }
00424 
00428     bool user_clr_taboo() { return _state.user_clr_taboo( true ); }
00429 
00430   public:
00431 
00436     bool appl_unset() { return _state.appl_unset( true ); }
00437 
00442     bool appl_set_delete() { return _state.appl_set_delete( true ); }
00443 
00449     bool appl_force_install() { return _state.appl_set_install( true ); }
00450 
00456     bool appl_set_install() { return !downgrade_condition() && appl_force_install(); }
00457 
00458   public:
00459 
00464     bool auto_unset() { return _state.auto_unset( true ); }
00465 
00470     bool auto_set_delete() { return _state.auto_set_delete( true ); }
00471 
00477     bool auto_force_install() { return _state.auto_set_install( true ); }
00478 
00484     bool auto_set_install() { return !downgrade_condition() && auto_force_install(); }
00485 
00486   private:
00487 
00495     bool do_set_onSystem( bool (PMSelectable::*fnc_unset)(), bool (PMSelectable::*fnc_install)() ) {
00496       if ( has_installed() ) {
00497         if ( ! to_delete() )
00498           return true; // already onSystem
00499         return (this->*fnc_unset)();
00500       } else {
00501         if ( to_install() )
00502           return true; // already onSystem
00503         return (this->*fnc_install)();
00504       }
00505     }
00506 
00514     bool do_set_offSystem( bool (PMSelectable::*fnc_unset)(), bool (PMSelectable::*fnc_delete)() ) {
00515       if ( has_installed() ) {
00516         if ( to_delete() )
00517           return true; // already offSystem
00518         return (this->*fnc_delete)();
00519       } else {
00520         if ( ! to_install() )
00521           return true; // already offSystem
00522         return (this->*fnc_unset)();
00523       }
00524     }
00525 
00526   public:
00527 
00534     bool is_onSystem() const {
00535       if ( has_installed() )
00536         return( ! to_delete() );
00537       else
00538         return( to_install() );
00539     }
00540 
00547     bool is_offSystem() const { return( ! is_onSystem() ); }
00548 
00552     bool user_set_onSystem() { return do_set_onSystem( &PMSelectable::user_unset, &PMSelectable::user_set_install ); }
00553 
00557     bool user_set_offSystem() { return do_set_offSystem( &PMSelectable::user_unset, &PMSelectable::user_set_delete ); }
00558 
00562     bool appl_set_onSystem() { return do_set_onSystem( &PMSelectable::appl_unset, &PMSelectable::appl_set_install ); }
00563 
00567     bool appl_set_offSystem() { return do_set_offSystem( &PMSelectable::appl_unset, &PMSelectable::appl_set_delete ); }
00568 
00572     bool auto_set_onSystem() { return do_set_onSystem( &PMSelectable::auto_unset, &PMSelectable::auto_set_install ); }
00573 
00577     bool auto_set_offSystem() { return do_set_offSystem( &PMSelectable::auto_unset, &PMSelectable::auto_set_delete ); }
00578 
00579   public:
00580 
00584     virtual std::ostream & dumpOn( std::ostream & str ) const;
00585 
00589     std::ostream & dumpStateOn( std::ostream & str ) const;
00590 
00591   public:
00592 
00596     typedef bool (PMSelectable::*Test_method)() const;
00597 
00601     typedef bool (*Test_fnc)( const constPMSelectablePtr & sel_r );
00602 
00606     static bool test( const constPMSelectablePtr & sel_r, Test_method fnc_r ) {
00607       if ( sel_r && fnc_r )
00608         return (sel_r.operator->()->*fnc_r)();
00609       return false;
00610     }
00611 };
00612 
00614 
00615 #endif // PMSelectable_h
00616 

Generated on Fri Nov 9 14:30:31 2007 for yast2-packagemanager by doxygen 1.3.6