]> git.saurik.com Git - apt.git/blame - apt-pkg/edsp.h
cleanup datatypes mix used in binary cache
[apt.git] / apt-pkg / edsp.h
CommitLineData
6d38011b 1// -*- mode: cpp; mode: fold -*-
575e9b5c
DK
2/** Description \file edsp.h {{{
3 ######################################################################
6d38011b 4 Set of methods to help writing and reading everything needed for EDSP
1e3f4083 5 with the notable exception of reading a scenario for conversion into
575e9b5c 6 a Cache as this is handled by edsp interface for listparser and friends
6d38011b
DK
7 ##################################################################### */
8 /*}}}*/
c3b85126
DK
9#ifndef PKGLIB_EDSP_H
10#define PKGLIB_EDSP_H
6d38011b 11
15fc8636 12#include <apt-pkg/cacheset.h>
453b82a3
DK
13#include <apt-pkg/pkgcache.h>
14#include <apt-pkg/cacheiterators.h>
ce62f1de 15#include <apt-pkg/macros.h>
453b82a3
DK
16
17#include <stdio.h>
6d38011b 18
472ff00e 19#include <list>
29099cb6
DK
20#include <string>
21
b9dadc24
DK
22#ifndef APT_8_CLEANER_HEADERS
23#include <apt-pkg/depcache.h>
24#include <apt-pkg/progress.h>
25#endif
26
472ff00e
DK
27class pkgDepCache;
28class OpProgress;
29
c3b85126 30class EDSP /*{{{*/
6d38011b 31{
d4f626ff
DK
32 // we could use pkgCache::DepType and ::Priority, but these would be localized stringsā€¦
33 static const char * const PrioMap[];
34 static const char * const DepMap[];
35
ce62f1de
DK
36 APT_HIDDEN bool static ReadLine(int const input, std::string &line);
37 APT_HIDDEN bool static StringToBool(char const *answer, bool const defValue);
6d5bd614 38
ce62f1de 39 APT_HIDDEN void static WriteScenarioVersion(pkgDepCache &Cache, FILE* output,
d4f626ff
DK
40 pkgCache::PkgIterator const &Pkg,
41 pkgCache::VerIterator const &Ver);
ce62f1de 42 APT_HIDDEN void static WriteScenarioDependency(FILE* output,
d4f626ff 43 pkgCache::VerIterator const &Ver);
ce62f1de 44 APT_HIDDEN void static WriteScenarioLimitedDependency(FILE* output,
d4f626ff
DK
45 pkgCache::VerIterator const &Ver,
46 APT::PackageSet const &pkgset);
6d38011b 47public:
575e9b5c
DK
48 /** \brief creates the EDSP request stanza
49 *
50 * In the EDSP protocol the first thing send to the resolver is a stanza
51 * encoding the request. This method will write this stanza by looking at
52 * the given Cache and requests the installation of all packages which were
53 * marked for installation in it (equally for remove).
54 *
55 * \param Cache in which the request is encoded
56 * \param output is written to this "file"
57 * \param upgrade is true if it is an request like apt-get upgrade
58 * \param distUpgrade is true if it is a request like apt-get dist-upgrade
59 * \param autoRemove is true if removal of unneeded packages should be performed
b57c0e35 60 * \param Progress is an instance to report progress to
575e9b5c
DK
61 *
62 * \return true if request was composed successfully, otherwise false
63 */
93794bc9 64 bool static WriteRequest(pkgDepCache &Cache, FILE* output,
40795fca
DK
65 bool const upgrade = false,
66 bool const distUpgrade = false,
b57c0e35
DK
67 bool const autoRemove = false,
68 OpProgress *Progress = NULL);
575e9b5c
DK
69
70 /** \brief creates the scenario representing the package universe
71 *
72 * After the request all known information about a package are send
73 * to the solver. The output looks similar to a Packages or status file
74 *
75 * All packages and version included in this Cache are send, even if
76 * it doesn't make sense from an APT resolver point of view like versions
77 * with a negative pin to enable the solver to propose even that as a
78 * solution or at least to be able to give a hint what can be done to
79 * statisfy a request.
80 *
81 * \param Cache is the known package universe
82 * \param output is written to this "file"
b57c0e35 83 * \param Progress is an instance to report progress to
575e9b5c
DK
84 *
85 * \return true if universe was composed successfully, otherwise false
86 */
b57c0e35 87 bool static WriteScenario(pkgDepCache &Cache, FILE* output, OpProgress *Progress = NULL);
575e9b5c
DK
88
89 /** \brief creates a limited scenario representing the package universe
90 *
91 * This method works similar to #WriteScenario as it works in the same
92 * way but doesn't send the complete universe to the solver but only
93 * packages included in the pkgset which will have only dependencies
94 * on packages which are in the given set. All other dependencies will
95 * be removed, so that this method can be used to create testcases
96 *
97 * \param Cache is the known package universe
98 * \param output is written to this "file"
99 * \param pkgset is a set of packages the universe should be limited to
b57c0e35 100 * \param Progress is an instance to report progress to
575e9b5c
DK
101 *
102 * \return true if universe was composed successfully, otherwise false
103 */
d4f626ff 104 bool static WriteLimitedScenario(pkgDepCache &Cache, FILE* output,
b57c0e35
DK
105 APT::PackageSet const &pkgset,
106 OpProgress *Progress = NULL);
575e9b5c
DK
107
108 /** \brief waits and acts on the information returned from the solver
109 *
110 * This method takes care of interpreting whatever the solver sends
111 * through the standard output like a solution, progress or an error.
112 * The main thread should handle his control over to this method to
113 * wait for the solver to finish the given task
114 *
115 * \param input file descriptor with the response from the solver
116 * \param Cache the solution should be applied on if any
b57c0e35 117 * \param Progress is an instance to report progress to
575e9b5c
DK
118 *
119 * \return true if a solution is found and applied correctly, otherwise false
120 */
b57c0e35 121 bool static ReadResponse(int const input, pkgDepCache &Cache, OpProgress *Progress = NULL);
29099cb6 122
575e9b5c
DK
123 /** \brief search and read the request stanza for action later
124 *
125 * This method while ignore the input up to the point it finds the
126 * Request: line as an indicator for the Request stanza.
127 * The request is stored in the parameters install and remove then,
128 * as the cache isn't build yet as the scenario follows the request.
129 *
130 * \param input file descriptor with the edsp input for the solver
131 * \param[out] install is a list which gets populated with requested installs
132 * \param[out] remove is a list which gets populated with requested removals
133 * \param[out] upgrade is true if it is a request like apt-get upgrade
134 * \param[out] distUpgrade is true if it is a request like apt-get dist-upgrade
135 * \param[out] autoRemove is true if removal of uneeded packages should be performed
136 *
137 * \return true if the request could be found and worked on, otherwise false
138 */
6d5bd614 139 bool static ReadRequest(int const input, std::list<std::string> &install,
40795fca
DK
140 std::list<std::string> &remove, bool &upgrade,
141 bool &distUpgrade, bool &autoRemove);
575e9b5c
DK
142
143 /** \brief takes the request lists and applies it on the cache
144 *
145 * The lists as created by #ReadRequest will be used to find the
146 * packages in question and mark them for install/remove.
147 * No solving is done and no auto-install/-remove.
148 *
149 * \param install is a list of packages to mark for installation
150 * \param remove is a list of packages to mark for removal
151 * \param Cache is there the markers should be set
152 *
153 * \return false if the request couldn't be applied, true otherwise
154 */
29099cb6
DK
155 bool static ApplyRequest(std::list<std::string> const &install,
156 std::list<std::string> const &remove,
157 pkgDepCache &Cache);
575e9b5c
DK
158
159 /** \brief encodes the changes in the Cache as a EDSP solution
160 *
161 * The markers in the Cache are observed and send to given
162 * file. The solution isn't checked for consistency or alike,
163 * so even broken solutions can be written successfully,
164 * but the front-end revicing it will properly fail then.
165 *
166 * \param Cache which represents the solution
167 * \param output to write the stanzas forming the solution to
168 *
169 * \return true if solution could be written, otherwise false
170 */
e3674d91 171 bool static WriteSolution(pkgDepCache &Cache, FILE* output);
575e9b5c
DK
172
173 /** \brief sends a progress report
174 *
175 * \param percent of the solving completed
176 * \param message the solver wants the user to see
177 * \param output the front-end listens for progress report
178 */
e876223c 179 bool static WriteProgress(unsigned short const percent, const char* const message, FILE* output);
575e9b5c
DK
180
181 /** \brief sends an error report
182 *
183 * Solvers are expected to execute successfully even if
184 * they were unable to calculate a solution for a given task.
185 * Obviously they can't send a solution through, so this
186 * methods deals with formatting an error message correctly
1e3f4083 187 * so that the front-ends can receive and display it.
575e9b5c
DK
188 *
189 * The first line of the message should be a short description
190 * of the error so it can be used for dialog titles or alike
ebfeeaed
DK
191 *
192 * \param uuid of this error message
1e3f4083 193 * \param message is free form text to describe the error
ebfeeaed 194 * \param output the front-end listens for error messages
575e9b5c 195 */
ebfeeaed
DK
196 bool static WriteError(char const * const uuid, std::string const &message, FILE* output);
197
29099cb6 198
575e9b5c
DK
199 /** \brief executes the given solver and returns the pipe ends
200 *
201 * The given solver is executed if it can be found in one of the
202 * configured directories and setup for it is performed.
203 *
204 * \param solver to execute
205 * \param[out] solver_in will be the stdin of the solver
206 * \param[out] solver_out will be the stdout of the solver
207 *
5681b3fc 208 * \return PID of the started solver or 0 if failure occurred
575e9b5c 209 */
5681b3fc
DK
210 pid_t static ExecuteSolver(const char* const solver, int * const solver_in, int * const solver_out, bool /*overload*/);
211 APT_DEPRECATED bool static ExecuteSolver(const char* const solver, int *solver_in, int *solver_out);
575e9b5c
DK
212
213 /** \brief call an external resolver to handle the request
214 *
215 * This method wraps all the methods above to call an external solver
216 *
217 * \param solver to execute
218 * \param Cache with the problem and as universe to work in
219 * \param upgrade is true if it is a request like apt-get upgrade
220 * \param distUpgrade is true if it is a request like apt-get dist-upgrade
221 * \param autoRemove is true if unneeded packages should be removed
b57c0e35 222 * \param Progress is an instance to report progress to
575e9b5c
DK
223 *
224 * \return true if the solver has successfully solved the problem,
225 * otherwise false
226 */
741b7da9
DK
227 bool static ResolveExternal(const char* const solver, pkgDepCache &Cache,
228 bool const upgrade, bool const distUpgrade,
b57c0e35 229 bool const autoRemove, OpProgress *Progress = NULL);
6d38011b
DK
230};
231 /*}}}*/
232#endif