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