edsp.h 9.5 KB

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