00001 /*---------------------------------------------------------------------\ 00002 | | 00003 | __ __ ____ _____ ____ | 00004 | \ \ / /_ _/ ___|_ _|___ \ | 00005 | \ V / _` \___ \ | | __) | | 00006 | | | (_| |___) || | / __/ | 00007 | |_|\__,_|____/ |_| |_____| | 00008 | | 00009 | core system | 00010 | (C) SuSE GmbH | 00011 \----------------------------------------------------------------------/ 00012 00013 File: PMManager.h 00014 00015 Author: Michael Andres <ma@suse.de> 00016 Maintainer: Michael Andres <ma@suse.de> 00017 00018 /-*/ 00019 #ifndef PMManager_h 00020 #define PMManager_h 00021 00022 #include <iosfwd> 00023 #include <set> 00024 #include <map> 00025 #include <list> 00026 00027 #include <y2util/Pathname.h> 00028 00029 #include <y2pm/PMObject.h> 00030 #include <y2pm/PMSelectable.h> 00031 #include <y2pm/PMObjectContainerIter.h> 00032 00033 #include <y2pm/PkgDep.h> 00034 #include <y2pm/PkgSet.h> 00035 00037 // 00038 // CLASS NAME : PMManager 00042 class PMManager { 00043 00044 friend std::ostream & operator<<( std::ostream & str, const PMManager & obj ); 00045 00046 PMManager & operator=( const PMManager & ); 00047 PMManager ( const PMManager & ); 00048 00049 public: 00050 00051 typedef std::set<PMSelectablePtr> PMSelectableVec; 00052 00053 private: 00054 00055 typedef std::map<std::string,PMSelectablePtr> PMSelectablePool; 00056 00057 PMSelectablePool _itemPool; 00058 PMSelectableVec _items; 00059 00060 PkgSet* installed; 00061 PkgSet* available; 00062 PkgSet* toinstall; 00063 PkgSet* nowinstalled; 00064 00065 void invalidateSolverSets(); 00066 00067 private: 00068 00069 typedef std::list<PMSelectable::SavedState> SavedList; 00070 00071 SavedList _savedList; 00072 00073 public: 00074 00078 virtual void SaveState(); 00079 00083 virtual bool RestoreState(); 00084 00088 virtual bool DiffState() const; 00089 00093 virtual void ClearSaveState(); 00094 00095 private: 00096 00101 virtual PMObjectPtr assertObjectType( const PMObjectPtr & object_r ) const = 0; 00102 00108 virtual PMSelectablePtr newSelectable( const PkgName & name_r ) const; 00109 00113 virtual void prePSI() {;} 00117 virtual void postPSI() {;} 00121 virtual void prePAC() {;} 00125 virtual void postPAC() {;} 00129 virtual void prePRC() {;} 00133 virtual void postPRC() {;} 00134 00138 virtual void selectableNotify( constPMSelectablePtr item_r, SelState old_r, SelState new_r ); 00139 00140 private: 00141 00145 PMSelectablePtr poolLookup( const std::string & name_r ) const; 00146 00150 PMSelectablePtr poolProvide( const std::string & name_r ); 00151 00158 void poolAdjust(); 00159 00160 void clearAll(); 00161 00162 void checkPool() const; 00163 00164 public: 00165 00166 PMManager(); 00167 virtual ~PMManager(); 00168 00169 public: 00170 00174 void poolSetInstalled( PMObjectContainerIter iter_r ); 00175 00179 void poolAddCandidates( PMObjectContainerIter iter_r ); 00180 00184 void poolRemoveCandidates( PMObjectContainerIter iter_r ); 00185 00190 void poolSortCandidates(); 00191 00192 public: 00193 00197 unsigned size() const { return _items.size(); } 00198 00202 bool empty() const { return _items.empty(); } 00203 00207 PMSelectableVec::const_iterator begin() const { return _items.begin(); } 00208 00212 PMSelectableVec::const_iterator end() const { return _items.end(); } 00213 00217 PMSelectableVec::const_reverse_iterator rbegin() const { return _items.rbegin(); } 00218 00222 PMSelectableVec::const_reverse_iterator rend() const { return _items.rend(); } 00223 00227 PMSelectablePtr getItem( const std::string & name_t ) const { return poolLookup( name_t ); } 00228 00232 PMSelectablePtr operator [] ( const std::string & name_r ) const { return getItem( name_r ); } 00233 00234 public: 00235 00239 void setNothingSelected(); 00240 00241 public: 00242 00249 bool anyMatch( PMSelectable::Test_method fnc_r ) const; 00250 00257 bool anyMatch( PMSelectable::Test_fnc fnc_r ) const; 00258 00262 bool anythingByUser() const { return anyMatch( &PMSelectable::by_user ); } 00263 00267 bool anythingToDelete() const { return anyMatch( &PMSelectable::to_delete ); } 00268 00272 bool anythingToInstall() const { return anyMatch( &PMSelectable::to_install ); } 00273 00274 public: 00275 // solver Part 00276 00288 bool solveInstall(PkgDep::ResultList& good, PkgDep::ErrorResultList& bad, bool filter_conflicts_with_installed = false); 00289 00303 //bool solveUpgrade(PkgDep::ResultList& good, PkgDep::ErrorResultList& bad, PkgDep::SolvableList &to_remove); 00304 00305 00306 //bool solveEverythingRight(PkgDep::ResultList& good, PkgDep::ErrorResultList& bad, PkgDep::SolvableList &to_remove); 00307 00313 bool solveConsistent(PkgDep::ErrorResultList& bad); 00314 00319 //void setMaxRemoveThreshold(unsigned nr); 00320 00321 private: 00322 00323 void buildSets(PkgSet& installed, PkgSet& available, PkgSet& to_install); 00324 00325 public: 00326 00330 virtual void writeSettings(); 00331 00335 virtual void readSettings(); 00336 00337 protected: 00338 00344 virtual Pathname settingsFile() const { return Pathname(); } 00345 }; 00346 00348 00349 #endif // PMManager_h
1.4.4