edsp.h 10 KB

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