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