edsp.h 10 KB

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