]>
Commit | Line | Data |
---|---|---|
1c159e0a JT |
1 | /* |
2 | * Copyright (c) 2017 Jon Turney | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | */ | |
13 | ||
14 | #ifndef LIBSOLV_H | |
15 | #define LIBSOLV_H | |
16 | ||
17 | #include "solv/pool.h" | |
18 | #include "solv/repo.h" | |
1d553f34 | 19 | #include "solv/solver.h" |
1c159e0a JT |
20 | #include "PackageSpecification.h" |
21 | #include "PackageTrust.h" | |
22 | #include "package_source.h" | |
23 | #include "package_depends.h" | |
24 | #include <map> | |
25 | #include <vector> | |
26 | ||
27 | typedef trusts package_stability_t; | |
28 | ||
29 | typedef enum | |
30 | { | |
31 | package_binary, | |
32 | package_source | |
33 | } | |
34 | package_type_t; | |
35 | ||
36 | // --------------------------------------------------------------------------- | |
37 | // interface to class SolverVersion | |
38 | // | |
39 | // a wrapper around a libsolv Solvable | |
40 | // --------------------------------------------------------------------------- | |
41 | ||
42 | class SolverPool; | |
1d553f34 | 43 | class SolverSolution; |
1c159e0a JT |
44 | |
45 | class SolvableVersion | |
46 | { | |
47 | public: | |
48 | SolvableVersion() : id(0), pool(0) {}; | |
49 | SolvableVersion(Id _id, Pool *_pool) : id(_id), pool(_pool) {}; | |
50 | ||
51 | // converted to a bool, this is true if this isn't the result of the default | |
52 | // constructor (an 'empty' version, in some sense) | |
53 | explicit operator bool () const { return (id != 0); } | |
54 | ||
55 | const std::string Name () const; | |
56 | const std::string SDesc () const; | |
57 | // In setup-speak, 'Canonical' version means 'e:v-r', the non-decomposed version | |
58 | const std::string Canonical_version () const; | |
5ebe14e4 | 59 | // Return the dependency list |
1c159e0a | 60 | const PackageDepends depends() const; |
5ebe14e4 KB |
61 | // Return the obsoletes list |
62 | const PackageDepends obsoletes() const; | |
1c159e0a JT |
63 | bool accessible () const; |
64 | package_type_t Type () const; | |
65 | package_stability_t Stability () const; | |
c59b92e8 JT |
66 | // the associated source package name, if this is a binary package |
67 | const std::string sourcePackageName () const; | |
1c159e0a JT |
68 | // the associated source package, if this is a binary package |
69 | SolvableVersion sourcePackage () const; | |
70 | // where this package archive can be obtained from | |
71 | packagesource *source() const; | |
72 | ||
c59b92e8 JT |
73 | // fixup spkg_id |
74 | void fixup_spkg_id(SolvableVersion spkg_id) const; | |
75 | ||
1c159e0a JT |
76 | // utility function to compare package versions |
77 | static int compareVersions(const SolvableVersion &a, const SolvableVersion &b); | |
78 | ||
79 | // comparison operators | |
80 | ||
81 | // these are somewhat necessary as otherwise we are compared as bool values | |
82 | bool operator == (SolvableVersion const &) const; | |
83 | bool operator != (SolvableVersion const &) const; | |
84 | ||
85 | // these are only well defined for versions of the same package | |
86 | bool operator < (SolvableVersion const &) const; | |
87 | bool operator <= (SolvableVersion const &) const; | |
88 | bool operator > (SolvableVersion const &) const; | |
89 | bool operator >= (SolvableVersion const &) const; | |
90 | ||
91 | private: | |
92 | Id id; | |
93 | Pool *pool; | |
94 | ||
95 | friend SolverPool; | |
1d553f34 | 96 | friend SolverSolution; |
5ebe14e4 KB |
97 | |
98 | const PackageDepends deplist(Id keyname) const; | |
1c159e0a JT |
99 | }; |
100 | ||
101 | // --------------------------------------------------------------------------- | |
102 | // Helper class SolvRepo | |
103 | // | |
104 | // --------------------------------------------------------------------------- | |
105 | ||
106 | class SolvRepo | |
107 | { | |
108 | public: | |
3c3d695d KB |
109 | typedef enum |
110 | { | |
111 | priorityLow = 0, | |
112 | priorityNormal, | |
113 | priorityHigh, | |
114 | } priority_t; | |
1c159e0a JT |
115 | Repo *repo; |
116 | Repodata *data; | |
117 | bool test; | |
3c3d695d | 118 | void setPriority(priority_t p) { repo->priority = p; } |
1c159e0a JT |
119 | }; |
120 | ||
121 | // --------------------------------------------------------------------------- | |
122 | // interface to class SolverPool | |
123 | // | |
124 | // a simplified wrapper for libsolv | |
125 | // --------------------------------------------------------------------------- | |
126 | ||
127 | class SolverPool | |
128 | { | |
129 | public: | |
130 | SolverPool(); | |
131 | SolvRepo *getRepo(const std::string &name, bool test = false); | |
132 | ||
133 | // Utility class for passing arguments to addPackage() | |
134 | class addPackageData | |
135 | { | |
136 | public: | |
137 | std::string reponame; | |
138 | std::string version; | |
139 | std::string vendor; | |
140 | std::string sdesc; | |
141 | std::string ldesc; | |
142 | package_stability_t stability; | |
143 | package_type_t type; | |
144 | packagesource archive; | |
145 | PackageSpecification spkg; | |
146 | SolvableVersion spkg_id; | |
147 | PackageDepends *requires; | |
20b98f20 | 148 | PackageDepends *obsoletes; |
1c159e0a JT |
149 | }; |
150 | ||
151 | SolvableVersion addPackage(const std::string& pkgname, | |
152 | const addPackageData &pkgdata); | |
153 | ||
154 | void internalize(void); | |
1d553f34 JT |
155 | void use_test_packages(bool use_test_packages); |
156 | ||
1c159e0a JT |
157 | |
158 | private: | |
159 | Id makedeps(Repo *repo, PackageDepends *requires); | |
160 | Pool *pool; | |
161 | ||
162 | typedef std::map<std::string, SolvRepo *> RepoList; | |
163 | RepoList repos; | |
1d553f34 JT |
164 | |
165 | friend SolverSolution; | |
1c159e0a JT |
166 | }; |
167 | ||
168 | ||
1d553f34 JT |
169 | // --------------------------------------------------------------------------- |
170 | // interface to class SolverTaskQueue | |
171 | // | |
172 | // This is used to contain a set of package install/uninstall tasks selected via | |
173 | // the UI to be passed to solver | |
174 | // --------------------------------------------------------------------------- | |
175 | ||
176 | class SolverTasks | |
177 | { | |
178 | public: | |
179 | enum task | |
180 | { | |
181 | taskInstall, | |
182 | taskUninstall, | |
9deed604 KB |
183 | taskReinstall, |
184 | taskKeep, | |
1d553f34 JT |
185 | }; |
186 | void add(const SolvableVersion &v, task t) | |
187 | { | |
188 | tasks.push_back(taskList::value_type(v, t)); | |
189 | }; | |
16994679 KB |
190 | /* Create solver tasks corresponding to state of database */ |
191 | void setTasks(); | |
192 | ||
1d553f34 | 193 | private: |
389e4dff | 194 | typedef std::vector<std::pair<const SolvableVersion, task>> taskList; |
1d553f34 JT |
195 | taskList tasks; |
196 | ||
197 | friend SolverSolution; | |
198 | }; | |
199 | ||
200 | // --------------------------------------------------------------------------- | |
201 | // SolverTransactionList | |
202 | // | |
203 | // a list of transactions output by the solver | |
204 | // --------------------------------------------------------------------------- | |
205 | ||
206 | class SolverTransaction | |
207 | { | |
208 | public: | |
209 | typedef enum | |
210 | { | |
211 | transIgnore, | |
212 | transInstall, | |
213 | transErase, | |
214 | } transType; | |
215 | ||
216 | SolverTransaction(SolvableVersion version_, transType type_) : | |
217 | version(version_), type(type_) {}; | |
218 | ||
219 | SolvableVersion version; | |
220 | transType type; | |
221 | }; | |
222 | ||
223 | typedef std::vector<SolverTransaction> SolverTransactionList; | |
224 | ||
225 | // --------------------------------------------------------------------------- | |
226 | // interface to class SolverSolution | |
227 | // | |
228 | // A wrapper around the libsolv solver | |
229 | // --------------------------------------------------------------------------- | |
230 | ||
231 | class SolverSolution | |
232 | { | |
233 | public: | |
234 | SolverSolution(SolverPool &_pool) : pool(_pool), solv(NULL) {}; | |
235 | ~SolverSolution(); | |
236 | ||
7c94d449 KB |
237 | /* Reset package database to correspond to trans */ |
238 | void trans2db() const; | |
239 | ||
9a7507eb KB |
240 | /* Reset transaction list to correspond to package database */ |
241 | void db2trans(); | |
242 | ||
45f5ab69 JT |
243 | enum updateMode |
244 | { | |
245 | keep, // don't update | |
246 | updateBest, // update to best version | |
247 | updateForce, // distupdate: downgrade if necessary to best version in repo | |
248 | }; | |
249 | bool update(SolverTasks &tasks, updateMode update, bool use_test_packages, bool include_source); | |
1d553f34 JT |
250 | std::string report() const; |
251 | ||
252 | const SolverTransactionList &transactions() const; | |
253 | ||
254 | private: | |
255 | static SolverTransaction::transType type(Transaction *trans, int pos); | |
256 | ||
257 | SolverPool &pool; | |
258 | Solver *solv; | |
259 | SolverTransactionList trans; | |
260 | }; | |
261 | ||
1c159e0a | 262 | #endif // LIBSOLV_H |