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