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