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