1 /* 2 * Copyright 2013, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef HAIKU_LIBSOLV_SOLVER_H 6 #define HAIKU_LIBSOLV_SOLVER_H 7 8 9 #include <map> 10 11 #include <ObjectList.h> 12 #include <package/solver/Solver.h> 13 #include <package/solver/SolverProblemSolution.h> 14 15 #include <solv/pool.h> 16 #include <solv/solver.h> 17 18 19 using namespace BPackageKit; 20 21 22 namespace BPackageKit { 23 class BPackageResolvableExpression; 24 class BSolverPackage; 25 } 26 27 28 class LibsolvSolver : public BSolver { 29 public: 30 LibsolvSolver(); 31 virtual ~LibsolvSolver(); 32 33 virtual status_t Init(); 34 35 virtual void SetDebugLevel(int32 level); 36 37 virtual status_t AddRepository(BSolverRepository* repository); 38 39 virtual status_t FindPackages(const char* searchString, 40 uint32 flags, 41 BObjectList<BSolverPackage>& _packages); 42 virtual status_t FindPackages( 43 const BSolverPackageSpecifierList& packages, 44 uint32 flags, 45 BObjectList<BSolverPackage>& _packages, 46 const BSolverPackageSpecifier** _unmatched 47 = NULL); 48 49 virtual status_t Install( 50 const BSolverPackageSpecifierList& packages, 51 const BSolverPackageSpecifier** _unmatched 52 = NULL); 53 virtual status_t Uninstall( 54 const BSolverPackageSpecifierList& packages, 55 const BSolverPackageSpecifier** _unmatched 56 = NULL); 57 virtual status_t Update( 58 const BSolverPackageSpecifierList& packages, 59 bool installNotYetInstalled, 60 const BSolverPackageSpecifier** _unmatched 61 = NULL); 62 virtual status_t FullSync(); 63 virtual status_t VerifyInstallation(uint32 flags = 0); 64 65 virtual int32 CountProblems() const; 66 virtual BSolverProblem* ProblemAt(int32 index) const; 67 68 virtual status_t SelectProblemSolution( 69 BSolverProblem* problem, 70 const BSolverProblemSolution* solution); 71 virtual status_t SolveAgain(); 72 73 virtual status_t GetResult(BSolverResult& _result); 74 75 private: 76 struct SolvQueue; 77 struct SolvDataIterator; 78 struct RepositoryInfo; 79 struct Problem; 80 struct Solution; 81 82 typedef BObjectList<RepositoryInfo> RepositoryInfoList; 83 typedef BObjectList<Problem> ProblemList; 84 typedef std::map<Id, BSolverPackage*> SolvableMap; 85 typedef std::map<BSolverPackage*, Id> PackageMap; 86 87 private: 88 status_t _InitPool(); 89 status_t _InitJobQueue(); 90 void _InitSolver(); 91 void _Cleanup(); 92 void _CleanupPool(); 93 void _CleanupJobQueue(); 94 void _CleanupSolver(); 95 96 bool _HaveRepositoriesChanged() const; 97 status_t _AddRepositories(); 98 RepositoryInfo* _InstalledRepository() const; 99 RepositoryInfo* _GetRepositoryInfo( 100 BSolverRepository* repository) const; 101 BSolverPackage* _GetPackage(Id solvableId) const; 102 Id _GetSolvable(BSolverPackage* package) const; 103 104 status_t _AddSpecifiedPackages( 105 const BSolverPackageSpecifierList& packages, 106 const BSolverPackageSpecifier** _unmatched, 107 int additionalFlags); 108 109 status_t _AddProblem(Id problemId); 110 status_t _AddSolution(Problem* problem, Id solutionId); 111 status_t _AddSolutionElement(Solution* solution, 112 Id sourceId, Id targetId); 113 status_t _AddSolutionElement(Solution* solution, 114 BSolverProblemSolutionElement::BType type, 115 Id sourceSolvableId, Id targetSolvableId, 116 const char* selectionString); 117 status_t _GetResolvableExpression(Id id, 118 BPackageResolvableExpression& _expression) 119 const; 120 121 status_t _GetFoundPackages(SolvQueue& selection, 122 uint32 flags, 123 BObjectList<BSolverPackage>& _packages); 124 125 status_t _Solve(); 126 void _SetJobsSolverMode(int solverMode); 127 128 private: 129 Pool* fPool; 130 Solver* fSolver; 131 SolvQueue* fJobs; 132 RepositoryInfoList fRepositoryInfos; 133 RepositoryInfo* fInstalledRepository; 134 // valid only after _AddRepositories() 135 SolvableMap fSolvablePackages; 136 PackageMap fPackageSolvables; 137 ProblemList fProblems; 138 int32 fDebugLevel; 139 }; 140 141 142 #endif // HAIKU_LIBSOLV_SOLVER_H 143