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