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