]>
Commit | Line | Data |
---|---|---|
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 | 20 | #include <string> |
6dcae298 | 21 | #include <vector> |
29099cb6 | 22 | |
b9dadc24 DK |
23 | #ifndef APT_8_CLEANER_HEADERS |
24 | #include <apt-pkg/depcache.h> | |
25 | #include <apt-pkg/progress.h> | |
26 | #endif | |
27 | ||
472ff00e DK |
28 | class pkgDepCache; |
29 | class OpProgress; | |
30 | ||
c8a4ce6c | 31 | namespace EDSP /*{{{*/ |
6d38011b | 32 | { |
43c71fad DK |
33 | namespace Request |
34 | { | |
35 | enum Flags | |
36 | { | |
37 | AUTOREMOVE = (1 << 0), /*!< removal of unneeded packages should be performed */ | |
38 | UPGRADE_ALL = (1 << 1), /*!< upgrade all installed packages, like 'apt-get full-upgrade' without forbid flags */ | |
39 | FORBID_NEW_INSTALL = (1 << 2), /*!< forbid the resolver to install new packages */ | |
40 | FORBID_REMOVE = (1 << 3), /*!< forbid the resolver to remove packages */ | |
41 | }; | |
42 | } | |
575e9b5c DK |
43 | /** \brief creates the EDSP request stanza |
44 | * | |
45 | * In the EDSP protocol the first thing send to the resolver is a stanza | |
46 | * encoding the request. This method will write this stanza by looking at | |
47 | * the given Cache and requests the installation of all packages which were | |
48 | * marked for installation in it (equally for remove). | |
49 | * | |
50 | * \param Cache in which the request is encoded | |
51 | * \param output is written to this "file" | |
43c71fad | 52 | * \param flags effecting the request documented in #EDSP::Request::Flags |
b57c0e35 | 53 | * \param Progress is an instance to report progress to |
575e9b5c DK |
54 | * |
55 | * \return true if request was composed successfully, otherwise false | |
56 | */ | |
ef00bd7a | 57 | bool WriteRequest(pkgDepCache &Cache, FileFd &output, |
43c71fad | 58 | unsigned int const flags = 0, |
b57c0e35 | 59 | OpProgress *Progress = NULL); |
ef00bd7a DK |
60 | bool WriteRequest(pkgDepCache &Cache, FILE* output, |
61 | bool const upgrade = false, | |
62 | bool const distUpgrade = false, | |
63 | bool const autoRemove = false, | |
64 | OpProgress *Progress = NULL) APT_DEPRECATED_MSG("Use FileFd-based interface instead"); | |
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 | */ | |
ef00bd7a DK |
83 | bool WriteScenario(pkgDepCache &Cache, FileFd &output, OpProgress *Progress = NULL); |
84 | bool WriteScenario(pkgDepCache &Cache, FILE* output, OpProgress *Progress = NULL) APT_DEPRECATED_MSG("Use FileFd-based interface instead"); | |
575e9b5c DK |
85 | |
86 | /** \brief creates a limited scenario representing the package universe | |
87 | * | |
88 | * This method works similar to #WriteScenario as it works in the same | |
89 | * way but doesn't send the complete universe to the solver but only | |
90 | * packages included in the pkgset which will have only dependencies | |
91 | * on packages which are in the given set. All other dependencies will | |
92 | * be removed, so that this method can be used to create testcases | |
93 | * | |
94 | * \param Cache is the known package universe | |
95 | * \param output is written to this "file" | |
96 | * \param pkgset is a set of packages the universe should be limited to | |
b57c0e35 | 97 | * \param Progress is an instance to report progress to |
575e9b5c DK |
98 | * |
99 | * \return true if universe was composed successfully, otherwise false | |
100 | */ | |
ef00bd7a | 101 | bool WriteLimitedScenario(pkgDepCache &Cache, FileFd &output, |
6dcae298 | 102 | std::vector<bool> const &pkgset, |
b57c0e35 | 103 | OpProgress *Progress = NULL); |
ef00bd7a DK |
104 | bool WriteLimitedScenario(pkgDepCache &Cache, FILE* output, |
105 | APT::PackageSet const &pkgset, | |
106 | OpProgress *Progress = NULL) APT_DEPRECATED_MSG("Use FileFd-based interface instead"); | |
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 | */ | |
c8a4ce6c | 121 | bool 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 | */ | |
c8a4ce6c | 139 | bool ReadRequest(int const input, std::list<std::string> &install, |
43c71fad DK |
140 | std::list<std::string> &remove, unsigned int &flags); |
141 | APT_DEPRECATED_MSG("use the flag-based version instead") bool ReadRequest(int const input, std::list<std::string> &install, | |
40795fca DK |
142 | std::list<std::string> &remove, bool &upgrade, |
143 | bool &distUpgrade, bool &autoRemove); | |
575e9b5c DK |
144 | |
145 | /** \brief takes the request lists and applies it on the cache | |
146 | * | |
147 | * The lists as created by #ReadRequest will be used to find the | |
148 | * packages in question and mark them for install/remove. | |
149 | * No solving is done and no auto-install/-remove. | |
150 | * | |
151 | * \param install is a list of packages to mark for installation | |
152 | * \param remove is a list of packages to mark for removal | |
153 | * \param Cache is there the markers should be set | |
154 | * | |
155 | * \return false if the request couldn't be applied, true otherwise | |
156 | */ | |
c8a4ce6c | 157 | bool ApplyRequest(std::list<std::string> const &install, |
29099cb6 DK |
158 | std::list<std::string> const &remove, |
159 | pkgDepCache &Cache); | |
575e9b5c DK |
160 | |
161 | /** \brief encodes the changes in the Cache as a EDSP solution | |
162 | * | |
163 | * The markers in the Cache are observed and send to given | |
164 | * file. The solution isn't checked for consistency or alike, | |
165 | * so even broken solutions can be written successfully, | |
166 | * but the front-end revicing it will properly fail then. | |
167 | * | |
168 | * \param Cache which represents the solution | |
169 | * \param output to write the stanzas forming the solution to | |
170 | * | |
171 | * \return true if solution could be written, otherwise false | |
172 | */ | |
ef00bd7a DK |
173 | bool WriteSolution(pkgDepCache &Cache, FileFd &output); |
174 | bool WriteSolution(pkgDepCache &Cache, FILE* output) APT_DEPRECATED_MSG("Use FileFd-based interface instead"); | |
575e9b5c DK |
175 | |
176 | /** \brief sends a progress report | |
177 | * | |
178 | * \param percent of the solving completed | |
179 | * \param message the solver wants the user to see | |
180 | * \param output the front-end listens for progress report | |
181 | */ | |
ef00bd7a DK |
182 | bool WriteProgress(unsigned short const percent, const char* const message, FileFd &output); |
183 | bool WriteProgress(unsigned short const percent, const char* const message, FILE* output) APT_DEPRECATED_MSG("Use FileFd-based interface instead"); | |
575e9b5c DK |
184 | |
185 | /** \brief sends an error report | |
186 | * | |
187 | * Solvers are expected to execute successfully even if | |
188 | * they were unable to calculate a solution for a given task. | |
189 | * Obviously they can't send a solution through, so this | |
190 | * methods deals with formatting an error message correctly | |
1e3f4083 | 191 | * so that the front-ends can receive and display it. |
575e9b5c DK |
192 | * |
193 | * The first line of the message should be a short description | |
194 | * of the error so it can be used for dialog titles or alike | |
ebfeeaed DK |
195 | * |
196 | * \param uuid of this error message | |
1e3f4083 | 197 | * \param message is free form text to describe the error |
ebfeeaed | 198 | * \param output the front-end listens for error messages |
575e9b5c | 199 | */ |
ef00bd7a DK |
200 | bool WriteError(char const * const uuid, std::string const &message, FileFd &output); |
201 | bool WriteError(char const * const uuid, std::string const &message, FILE* output) APT_DEPRECATED_MSG("Use FileFd-based interface instead"); | |
ebfeeaed | 202 | |
29099cb6 | 203 | |
575e9b5c DK |
204 | /** \brief executes the given solver and returns the pipe ends |
205 | * | |
206 | * The given solver is executed if it can be found in one of the | |
207 | * configured directories and setup for it is performed. | |
208 | * | |
209 | * \param solver to execute | |
210 | * \param[out] solver_in will be the stdin of the solver | |
211 | * \param[out] solver_out will be the stdout of the solver | |
212 | * | |
5681b3fc | 213 | * \return PID of the started solver or 0 if failure occurred |
575e9b5c | 214 | */ |
c8a4ce6c | 215 | pid_t ExecuteSolver(const char* const solver, int * const solver_in, int * const solver_out, bool /*overload*/); |
5dd00edb | 216 | APT_DEPRECATED_MSG("add a dummy bool parameter to use the overload returning a pid_t") bool ExecuteSolver(const char* const solver, int *solver_in, int *solver_out); |
575e9b5c DK |
217 | |
218 | /** \brief call an external resolver to handle the request | |
219 | * | |
220 | * This method wraps all the methods above to call an external solver | |
221 | * | |
222 | * \param solver to execute | |
223 | * \param Cache with the problem and as universe to work in | |
43c71fad | 224 | * \param flags effecting the request documented in #EDSP::Request::Flags |
b57c0e35 | 225 | * \param Progress is an instance to report progress to |
575e9b5c DK |
226 | * |
227 | * \return true if the solver has successfully solved the problem, | |
228 | * otherwise false | |
229 | */ | |
c8a4ce6c | 230 | bool ResolveExternal(const char* const solver, pkgDepCache &Cache, |
43c71fad DK |
231 | unsigned int const flags = 0, |
232 | OpProgress *Progress = NULL); | |
233 | APT_DEPRECATED_MSG("use the flag-based version instead") bool ResolveExternal(const char* const solver, pkgDepCache &Cache, | |
741b7da9 | 234 | bool const upgrade, bool const distUpgrade, |
b57c0e35 | 235 | bool const autoRemove, OpProgress *Progress = NULL); |
c3392a9f | 236 | } |
6d38011b DK |
237 | /*}}}*/ |
238 | #endif |