]> cygwin.com Git - cygwin-apps/setup.git/blame - libsolv.h
Allow user to refuse the default problem solutions
[cygwin-apps/setup.git] / libsolv.h
CommitLineData
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
27typedef trusts package_stability_t;
28
29typedef enum
30{
31 package_binary,
32 package_source
33}
34package_type_t;
35
36// ---------------------------------------------------------------------------
37// interface to class SolverVersion
38//
39// a wrapper around a libsolv Solvable
40// ---------------------------------------------------------------------------
41
42class SolverPool;
1d553f34 43class SolverSolution;
1c159e0a
JT
44
45class 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
101class SolvRepo
102{
103public:
3c3d695d
KB
104 typedef enum
105 {
106 priorityLow = 0,
107 priorityNormal,
108 priorityHigh,
109 } priority_t;
1c159e0a
JT
110 Repo *repo;
111 Repodata *data;
112 bool test;
3c3d695d 113 void setPriority(priority_t p) { repo->priority = p; }
1c159e0a
JT
114};
115
116// ---------------------------------------------------------------------------
117// interface to class SolverPool
118//
119// a simplified wrapper for libsolv
120// ---------------------------------------------------------------------------
121
122class SolverPool
123{
124public:
125 SolverPool();
126 SolvRepo *getRepo(const std::string &name, bool test = false);
127
128 // Utility class for passing arguments to addPackage()
129 class addPackageData
130 {
131 public:
132 std::string reponame;
133 std::string version;
134 std::string vendor;
135 std::string sdesc;
136 std::string ldesc;
137 package_stability_t stability;
138 package_type_t type;
139 packagesource archive;
140 PackageSpecification spkg;
141 SolvableVersion spkg_id;
142 PackageDepends *requires;
20b98f20 143 PackageDepends *obsoletes;
1c159e0a
JT
144 };
145
146 SolvableVersion addPackage(const std::string& pkgname,
147 const addPackageData &pkgdata);
148
149 void internalize(void);
1d553f34
JT
150 void use_test_packages(bool use_test_packages);
151
1c159e0a
JT
152
153private:
154 Id makedeps(Repo *repo, PackageDepends *requires);
155 Pool *pool;
156
157 typedef std::map<std::string, SolvRepo *> RepoList;
158 RepoList repos;
1d553f34
JT
159
160 friend SolverSolution;
1c159e0a
JT
161};
162
163
1d553f34
JT
164// ---------------------------------------------------------------------------
165// interface to class SolverTaskQueue
166//
167// This is used to contain a set of package install/uninstall tasks selected via
168// the UI to be passed to solver
169// ---------------------------------------------------------------------------
170
171class SolverTasks
172{
173 public:
174 enum task
175 {
176 taskInstall,
177 taskUninstall,
9deed604
KB
178 taskReinstall,
179 taskKeep,
1d553f34
JT
180 };
181 void add(const SolvableVersion &v, task t)
182 {
183 tasks.push_back(taskList::value_type(v, t));
184 };
16994679
KB
185 /* Create solver tasks corresponding to state of database */
186 void setTasks();
187
1d553f34 188 private:
389e4dff 189 typedef std::vector<std::pair<const SolvableVersion, task>> taskList;
1d553f34
JT
190 taskList tasks;
191
192 friend SolverSolution;
193};
194
195// ---------------------------------------------------------------------------
196// SolverTransactionList
197//
198// a list of transactions output by the solver
199// ---------------------------------------------------------------------------
200
201class SolverTransaction
202{
203 public:
204 typedef enum
205 {
206 transIgnore,
207 transInstall,
208 transErase,
209 } transType;
210
211 SolverTransaction(SolvableVersion version_, transType type_) :
212 version(version_), type(type_) {};
213
214 SolvableVersion version;
215 transType type;
216};
217
218typedef std::vector<SolverTransaction> SolverTransactionList;
219
220// ---------------------------------------------------------------------------
221// interface to class SolverSolution
222//
223// A wrapper around the libsolv solver
224// ---------------------------------------------------------------------------
225
226class SolverSolution
227{
228 public:
229 SolverSolution(SolverPool &_pool) : pool(_pool), solv(NULL) {};
230 ~SolverSolution();
231
7c94d449
KB
232 /* Reset package database to correspond to trans */
233 void trans2db() const;
234
9a7507eb
KB
235 /* Reset transaction list to correspond to package database */
236 void db2trans();
237
1d553f34
JT
238 bool update(SolverTasks &tasks, bool update, bool use_test_packages, bool include_source);
239 std::string report() const;
240
241 const SolverTransactionList &transactions() const;
242
243 private:
244 static SolverTransaction::transType type(Transaction *trans, int pos);
245
246 SolverPool &pool;
247 Solver *solv;
248 SolverTransactionList trans;
249};
250
1c159e0a 251#endif // LIBSOLV_H
This page took 0.041715 seconds and 5 git commands to generate.