edsp.h 8.8 KB

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