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