edsp.h 9.4 KB

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