]>
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; | |
66 | // the associated source package, if this is a binary package | |
67 | SolvableVersion sourcePackage () const; | |
68 | // where this package archive can be obtained from | |
69 | packagesource *source() const; | |
70 | ||
71 | // utility function to compare package versions | |
72 | static int compareVersions(const SolvableVersion &a, const SolvableVersion &b); | |
73 | ||
74 | // comparison operators | |
75 | ||
76 | // these are somewhat necessary as otherwise we are compared as bool values | |
77 | bool operator == (SolvableVersion const &) const; | |
78 | bool operator != (SolvableVersion const &) const; | |
79 | ||
80 | // these are only well defined for versions of the same package | |
81 | bool operator < (SolvableVersion const &) const; | |
82 | bool operator <= (SolvableVersion const &) const; | |
83 | bool operator > (SolvableVersion const &) const; | |
84 | bool operator >= (SolvableVersion const &) const; | |
85 | ||
86 | private: | |
87 | Id id; | |
88 | Pool *pool; | |
89 | ||
90 | friend SolverPool; | |
1d553f34 | 91 | friend SolverSolution; |
5ebe14e4 KB |
92 | |
93 | const PackageDepends deplist(Id keyname) const; | |
1c159e0a JT |
94 | }; |
95 | ||
96 | // --------------------------------------------------------------------------- | |
97 | // Helper class SolvRepo | |
98 | // | |
99 | // --------------------------------------------------------------------------- | |
100 | ||
101 | class SolvRepo | |
102 | { | |
103 | public: | |
104 | Repo *repo; | |
105 | Repodata *data; | |
106 | bool test; | |
107 | }; | |
108 | ||
109 | // --------------------------------------------------------------------------- | |
110 | // interface to class SolverPool | |
111 | // | |
112 | // a simplified wrapper for libsolv | |
113 | // --------------------------------------------------------------------------- | |
114 | ||
115 | class SolverPool | |
116 | { | |
117 | public: | |
118 | SolverPool(); | |
119 | SolvRepo *getRepo(const std::string &name, bool test = false); | |
120 | ||
121 | // Utility class for passing arguments to addPackage() | |
122 | class addPackageData | |
123 | { | |
124 | public: | |
125 | std::string reponame; | |
126 | std::string version; | |
127 | std::string vendor; | |
128 | std::string sdesc; | |
129 | std::string ldesc; | |
130 | package_stability_t stability; | |
131 | package_type_t type; | |
132 | packagesource archive; | |
133 | PackageSpecification spkg; | |
134 | SolvableVersion spkg_id; | |
135 | PackageDepends *requires; | |
20b98f20 | 136 | PackageDepends *obsoletes; |
1c159e0a JT |
137 | }; |
138 | ||
139 | SolvableVersion addPackage(const std::string& pkgname, | |
140 | const addPackageData &pkgdata); | |
141 | ||
142 | void internalize(void); | |
1d553f34 JT |
143 | void use_test_packages(bool use_test_packages); |
144 | ||
1c159e0a JT |
145 | |
146 | private: | |
147 | Id makedeps(Repo *repo, PackageDepends *requires); | |
148 | Pool *pool; | |
149 | ||
150 | typedef std::map<std::string, SolvRepo *> RepoList; | |
151 | RepoList repos; | |
1d553f34 JT |
152 | |
153 | friend SolverSolution; | |
1c159e0a JT |
154 | }; |
155 | ||
156 | ||
1d553f34 JT |
157 | // --------------------------------------------------------------------------- |
158 | // interface to class SolverTaskQueue | |
159 | // | |
160 | // This is used to contain a set of package install/uninstall tasks selected via | |
161 | // the UI to be passed to solver | |
162 | // --------------------------------------------------------------------------- | |
163 | ||
164 | class SolverTasks | |
165 | { | |
166 | public: | |
167 | enum task | |
168 | { | |
169 | taskInstall, | |
170 | taskUninstall, | |
9deed604 KB |
171 | taskReinstall, |
172 | taskKeep, | |
1d553f34 JT |
173 | }; |
174 | void add(const SolvableVersion &v, task t) | |
175 | { | |
176 | tasks.push_back(taskList::value_type(v, t)); | |
177 | }; | |
178 | private: | |
179 | typedef std::vector<std::pair<const SolvableVersion &, task>> taskList; | |
180 | taskList tasks; | |
181 | ||
182 | friend SolverSolution; | |
183 | }; | |
184 | ||
185 | // --------------------------------------------------------------------------- | |
186 | // SolverTransactionList | |
187 | // | |
188 | // a list of transactions output by the solver | |
189 | // --------------------------------------------------------------------------- | |
190 | ||
191 | class SolverTransaction | |
192 | { | |
193 | public: | |
194 | typedef enum | |
195 | { | |
196 | transIgnore, | |
197 | transInstall, | |
198 | transErase, | |
199 | } transType; | |
200 | ||
201 | SolverTransaction(SolvableVersion version_, transType type_) : | |
202 | version(version_), type(type_) {}; | |
203 | ||
204 | SolvableVersion version; | |
205 | transType type; | |
206 | }; | |
207 | ||
208 | typedef std::vector<SolverTransaction> SolverTransactionList; | |
209 | ||
210 | // --------------------------------------------------------------------------- | |
211 | // interface to class SolverSolution | |
212 | // | |
213 | // A wrapper around the libsolv solver | |
214 | // --------------------------------------------------------------------------- | |
215 | ||
216 | class SolverSolution | |
217 | { | |
218 | public: | |
219 | SolverSolution(SolverPool &_pool) : pool(_pool), solv(NULL) {}; | |
220 | ~SolverSolution(); | |
221 | ||
222 | bool update(SolverTasks &tasks, bool update, bool use_test_packages, bool include_source); | |
223 | std::string report() const; | |
224 | ||
225 | const SolverTransactionList &transactions() const; | |
226 | ||
227 | private: | |
228 | static SolverTransaction::transType type(Transaction *trans, int pos); | |
229 | ||
230 | SolverPool &pool; | |
231 | Solver *solv; | |
232 | SolverTransactionList trans; | |
233 | }; | |
234 | ||
1c159e0a | 235 | #endif // LIBSOLV_H |