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