edsp.h 9.4 KB

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