From c3b851268e6e900be2bf0bd715435db9010fd591 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 31 Mar 2011 15:10:13 +0200 Subject: =?UTF-8?q?rename=20edspwriter=20to=20straight=20edsp=20in=20tople?= =?UTF-8?q?vel=20as=20it=20does=20more=20than=20just=20writing=20stuff?= =?UTF-8?q?=E2=80=A6=20it=20also=20reads=20and=20can=20work=20for=20both:?= =?UTF-8?q?=20-=20APT=20talking=20to=20an=20external=20solver=20-=20an=20e?= =?UTF-8?q?xternal=20solver=20(understanding=20EDSP)=20talking=20to=20APT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apt-pkg/edsp.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 apt-pkg/edsp.h (limited to 'apt-pkg/edsp.h') diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h new file mode 100644 index 000000000..ef137b8f6 --- /dev/null +++ b/apt-pkg/edsp.h @@ -0,0 +1,32 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + Set of methods to help writing and reading everything needed for EDSP + ##################################################################### */ + /*}}}*/ +#ifndef PKGLIB_EDSP_H +#define PKGLIB_EDSP_H + +#include + +#include + +class EDSP /*{{{*/ +{ +public: + bool static WriteRequest(pkgDepCache &Cache, FILE* output); + bool static WriteScenario(pkgDepCache &Cache, FILE* output); + bool static ReadResponse(FILE* input, pkgDepCache &Cache); + + // ReadScenario is provided by the listparser infrastructure + bool static ReadRequest(FILE* input, std::list &install, + std::list &remove); + bool static ApplyRequest(std::list const &install, + std::list const &remove, + pkgDepCache &Cache); + bool static WriteSolution(pkgDepCache &Cache, FILE* output); + bool static WriteError(std::string const &message, FILE* output); + +}; + /*}}}*/ +#endif -- cgit v1.2.3 From 93794bc92e8d2fd84c6e596e3238c31d0832c271 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 31 Mar 2011 15:32:55 +0200 Subject: WriteRequest according to current EDSP draft --- apt-pkg/edsp.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'apt-pkg/edsp.h') diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h index ef137b8f6..04d8c255f 100644 --- a/apt-pkg/edsp.h +++ b/apt-pkg/edsp.h @@ -14,7 +14,10 @@ class EDSP /*{{{*/ { public: - bool static WriteRequest(pkgDepCache &Cache, FILE* output); + bool static WriteRequest(pkgDepCache &Cache, FILE* output, + bool const Upgrade = false, + bool const DistUpgrade = false, + bool const AutoRemove = false); bool static WriteScenario(pkgDepCache &Cache, FILE* output); bool static ReadResponse(FILE* input, pkgDepCache &Cache); -- cgit v1.2.3 From 6d5bd6147e210bfb93e4ce0009d4e71c5995eab1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 1 Apr 2011 12:04:13 +0200 Subject: Read and apply install/remove requests correctly --- apt-pkg/edsp.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'apt-pkg/edsp.h') diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h index 04d8c255f..742d89b43 100644 --- a/apt-pkg/edsp.h +++ b/apt-pkg/edsp.h @@ -13,6 +13,8 @@ class EDSP /*{{{*/ { + bool static ReadLine(int const input, std::string &line); + public: bool static WriteRequest(pkgDepCache &Cache, FILE* output, bool const Upgrade = false, @@ -22,7 +24,7 @@ public: bool static ReadResponse(FILE* input, pkgDepCache &Cache); // ReadScenario is provided by the listparser infrastructure - bool static ReadRequest(FILE* input, std::list &install, + bool static ReadRequest(int const input, std::list &install, std::list &remove); bool static ApplyRequest(std::list const &install, std::list const &remove, -- cgit v1.2.3 From 40795fca99c72b0b43124cdfffb40e8fa3c4d952 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 1 Apr 2011 13:21:38 +0200 Subject: parse also the action flags Upgrade, Dist-Upgrade and alike from the request --- apt-pkg/edsp.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'apt-pkg/edsp.h') diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h index 742d89b43..75733c2d2 100644 --- a/apt-pkg/edsp.h +++ b/apt-pkg/edsp.h @@ -14,18 +14,20 @@ class EDSP /*{{{*/ { bool static ReadLine(int const input, std::string &line); + bool static StringToBool(char const *answer, bool const defValue); public: bool static WriteRequest(pkgDepCache &Cache, FILE* output, - bool const Upgrade = false, - bool const DistUpgrade = false, - bool const AutoRemove = false); + bool const upgrade = false, + bool const distUpgrade = false, + bool const autoRemove = false); bool static WriteScenario(pkgDepCache &Cache, FILE* output); bool static ReadResponse(FILE* input, pkgDepCache &Cache); // ReadScenario is provided by the listparser infrastructure bool static ReadRequest(int const input, std::list &install, - std::list &remove); + std::list &remove, bool &upgrade, + bool &distUpgrade, bool &autoRemove); bool static ApplyRequest(std::list const &install, std::list const &remove, pkgDepCache &Cache); -- cgit v1.2.3 From 2029276f0343c96481d0d3cbbc367420b4a5f864 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 2 Apr 2011 15:47:14 +0200 Subject: send the scenario through a pipe to the solver and get the solution back The solution is NOT interpreted so far. --- apt-pkg/edsp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg/edsp.h') diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h index 75733c2d2..31f8891f3 100644 --- a/apt-pkg/edsp.h +++ b/apt-pkg/edsp.h @@ -22,7 +22,7 @@ public: bool const distUpgrade = false, bool const autoRemove = false); bool static WriteScenario(pkgDepCache &Cache, FILE* output); - bool static ReadResponse(FILE* input, pkgDepCache &Cache); + bool static ReadResponse(int const input, pkgDepCache &Cache); // ReadScenario is provided by the listparser infrastructure bool static ReadRequest(int const input, std::list &install, -- cgit v1.2.3 From d4f626ff09383873c7b1ae42b744293c940c9c2c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 25 Apr 2011 15:59:19 +0200 Subject: reorganize WriteScenario to add a WriteLimitedScenario in which a scenario can be limited to a subset of packages with only relevant dependencies --- apt-pkg/edsp.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'apt-pkg/edsp.h') diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h index 31f8891f3..db4f06a7c 100644 --- a/apt-pkg/edsp.h +++ b/apt-pkg/edsp.h @@ -8,20 +8,37 @@ #define PKGLIB_EDSP_H #include +#include #include class EDSP /*{{{*/ { + // we could use pkgCache::DepType and ::Priority, but these would be localized stringsā€¦ + static const char * const PrioMap[]; + static const char * const DepMap[]; + bool static ReadLine(int const input, std::string &line); bool static StringToBool(char const *answer, bool const defValue); + void static WriteScenarioVersion(pkgDepCache &Cache, FILE* output, + pkgCache::PkgIterator const &Pkg, + pkgCache::VerIterator const &Ver); + void static WriteScenarioDependency(pkgDepCache &Cache, FILE* output, + pkgCache::PkgIterator const &Pkg, + pkgCache::VerIterator const &Ver); + void static WriteScenarioLimitedDependency(pkgDepCache &Cache, FILE* output, + pkgCache::PkgIterator const &Pkg, + pkgCache::VerIterator const &Ver, + APT::PackageSet const &pkgset); public: bool static WriteRequest(pkgDepCache &Cache, FILE* output, bool const upgrade = false, bool const distUpgrade = false, bool const autoRemove = false); bool static WriteScenario(pkgDepCache &Cache, FILE* output); + bool static WriteLimitedScenario(pkgDepCache &Cache, FILE* output, + APT::PackageSet const &pkgset); bool static ReadResponse(int const input, pkgDepCache &Cache); // ReadScenario is provided by the listparser infrastructure -- cgit v1.2.3 From e876223c704d8cac6246b4aff4bf683fb8b053e3 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 2 May 2011 11:51:44 +0200 Subject: implement optional Progress report in EDSP --- apt-pkg/edsp.h | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-pkg/edsp.h') diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h index db4f06a7c..a05de9448 100644 --- a/apt-pkg/edsp.h +++ b/apt-pkg/edsp.h @@ -49,6 +49,7 @@ public: std::list const &remove, pkgDepCache &Cache); bool static WriteSolution(pkgDepCache &Cache, FILE* output); + bool static WriteProgress(unsigned short const percent, const char* const message, FILE* output); bool static WriteError(std::string const &message, FILE* output); }; -- cgit v1.2.3 From ac5fbff8c55db2bd1cde194600115a874d9d0c73 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 2 May 2011 13:55:51 +0200 Subject: refactor: move solver execution into his own EDSP method --- apt-pkg/edsp.h | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-pkg/edsp.h') diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h index a05de9448..df6e1d21c 100644 --- a/apt-pkg/edsp.h +++ b/apt-pkg/edsp.h @@ -52,6 +52,7 @@ public: bool static WriteProgress(unsigned short const percent, const char* const message, FILE* output); bool static WriteError(std::string const &message, FILE* output); + bool static ExecuteSolver(const char* const solver, int *solver_in, int *solver_out); }; /*}}}*/ #endif -- cgit v1.2.3 From 741b7da9de1d2ab470728f1e7f38b25e0d6a556c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 3 May 2011 10:50:25 +0200 Subject: implement external solver calling for upgrade and dist-upgrade, too --- apt-pkg/edsp.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'apt-pkg/edsp.h') diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h index df6e1d21c..95132ebd0 100644 --- a/apt-pkg/edsp.h +++ b/apt-pkg/edsp.h @@ -53,6 +53,9 @@ public: bool static WriteError(std::string const &message, FILE* output); bool static ExecuteSolver(const char* const solver, int *solver_in, int *solver_out); + bool static ResolveExternal(const char* const solver, pkgDepCache &Cache, + bool const upgrade, bool const distUpgrade, + bool const autoRemove); }; /*}}}*/ #endif -- cgit v1.2.3 From 575e9b5c5c82087ebdbfe1d3660de8fe7e92d5e9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 3 May 2011 14:05:13 +0200 Subject: add a fair round of doxygen comments to the edsp header --- apt-pkg/edsp.h | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 151 insertions(+), 3 deletions(-) (limited to 'apt-pkg/edsp.h') diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h index 95132ebd0..98a70d7f6 100644 --- a/apt-pkg/edsp.h +++ b/apt-pkg/edsp.h @@ -1,7 +1,9 @@ // -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -/* ###################################################################### +/** Description \file edsp.h {{{ + ###################################################################### Set of methods to help writing and reading everything needed for EDSP + with the noteable exception of reading a scenario for conversion into + a Cache as this is handled by edsp interface for listparser and friends ##################################################################### */ /*}}}*/ #ifndef PKGLIB_EDSP_H @@ -32,27 +34,173 @@ class EDSP /*{{{*/ pkgCache::VerIterator const &Ver, APT::PackageSet const &pkgset); public: + /** \brief creates the EDSP request stanza + * + * In the EDSP protocol the first thing send to the resolver is a stanza + * encoding the request. This method will write this stanza by looking at + * the given Cache and requests the installation of all packages which were + * marked for installation in it (equally for remove). + * + * \param Cache in which the request is encoded + * \param output is written to this "file" + * \param upgrade is true if it is an request like apt-get upgrade + * \param distUpgrade is true if it is a request like apt-get dist-upgrade + * \param autoRemove is true if removal of unneeded packages should be performed + * + * \return true if request was composed successfully, otherwise false + */ bool static WriteRequest(pkgDepCache &Cache, FILE* output, bool const upgrade = false, bool const distUpgrade = false, bool const autoRemove = false); + + /** \brief creates the scenario representing the package universe + * + * After the request all known information about a package are send + * to the solver. The output looks similar to a Packages or status file + * + * All packages and version included in this Cache are send, even if + * it doesn't make sense from an APT resolver point of view like versions + * with a negative pin to enable the solver to propose even that as a + * solution or at least to be able to give a hint what can be done to + * statisfy a request. + * + * \param Cache is the known package universe + * \param output is written to this "file" + * + * \return true if universe was composed successfully, otherwise false + */ bool static WriteScenario(pkgDepCache &Cache, FILE* output); + + /** \brief creates a limited scenario representing the package universe + * + * This method works similar to #WriteScenario as it works in the same + * way but doesn't send the complete universe to the solver but only + * packages included in the pkgset which will have only dependencies + * on packages which are in the given set. All other dependencies will + * be removed, so that this method can be used to create testcases + * + * \param Cache is the known package universe + * \param output is written to this "file" + * \param pkgset is a set of packages the universe should be limited to + * + * \return true if universe was composed successfully, otherwise false + */ bool static WriteLimitedScenario(pkgDepCache &Cache, FILE* output, APT::PackageSet const &pkgset); + + /** \brief waits and acts on the information returned from the solver + * + * This method takes care of interpreting whatever the solver sends + * through the standard output like a solution, progress or an error. + * The main thread should handle his control over to this method to + * wait for the solver to finish the given task + * + * \param input file descriptor with the response from the solver + * \param Cache the solution should be applied on if any + * + * \return true if a solution is found and applied correctly, otherwise false + */ bool static ReadResponse(int const input, pkgDepCache &Cache); - // ReadScenario is provided by the listparser infrastructure + /** \brief search and read the request stanza for action later + * + * This method while ignore the input up to the point it finds the + * Request: line as an indicator for the Request stanza. + * The request is stored in the parameters install and remove then, + * as the cache isn't build yet as the scenario follows the request. + * + * \param input file descriptor with the edsp input for the solver + * \param[out] install is a list which gets populated with requested installs + * \param[out] remove is a list which gets populated with requested removals + * \param[out] upgrade is true if it is a request like apt-get upgrade + * \param[out] distUpgrade is true if it is a request like apt-get dist-upgrade + * \param[out] autoRemove is true if removal of uneeded packages should be performed + * + * \return true if the request could be found and worked on, otherwise false + */ bool static ReadRequest(int const input, std::list &install, std::list &remove, bool &upgrade, bool &distUpgrade, bool &autoRemove); + + /** \brief takes the request lists and applies it on the cache + * + * The lists as created by #ReadRequest will be used to find the + * packages in question and mark them for install/remove. + * No solving is done and no auto-install/-remove. + * + * \param install is a list of packages to mark for installation + * \param remove is a list of packages to mark for removal + * \param Cache is there the markers should be set + * + * \return false if the request couldn't be applied, true otherwise + */ bool static ApplyRequest(std::list const &install, std::list const &remove, pkgDepCache &Cache); + + /** \brief encodes the changes in the Cache as a EDSP solution + * + * The markers in the Cache are observed and send to given + * file. The solution isn't checked for consistency or alike, + * so even broken solutions can be written successfully, + * but the front-end revicing it will properly fail then. + * + * \param Cache which represents the solution + * \param output to write the stanzas forming the solution to + * + * \return true if solution could be written, otherwise false + */ bool static WriteSolution(pkgDepCache &Cache, FILE* output); + + /** \brief sends a progress report + * + * \param percent of the solving completed + * \param message the solver wants the user to see + * \param output the front-end listens for progress report + */ bool static WriteProgress(unsigned short const percent, const char* const message, FILE* output); + + /** \brief sends an error report + * + * Solvers are expected to execute successfully even if + * they were unable to calculate a solution for a given task. + * Obviously they can't send a solution through, so this + * methods deals with formatting an error message correctly + * so that the front-ends can recieve and display it. + * + * The first line of the message should be a short description + * of the error so it can be used for dialog titles or alike + */ bool static WriteError(std::string const &message, FILE* output); + /** \brief executes the given solver and returns the pipe ends + * + * The given solver is executed if it can be found in one of the + * configured directories and setup for it is performed. + * + * \param solver to execute + * \param[out] solver_in will be the stdin of the solver + * \param[out] solver_out will be the stdout of the solver + * + * \return true if the solver could be started and the pipes + * are set up correctly, otherwise false and the pipes are invalid + */ bool static ExecuteSolver(const char* const solver, int *solver_in, int *solver_out); + + /** \brief call an external resolver to handle the request + * + * This method wraps all the methods above to call an external solver + * + * \param solver to execute + * \param Cache with the problem and as universe to work in + * \param upgrade is true if it is a request like apt-get upgrade + * \param distUpgrade is true if it is a request like apt-get dist-upgrade + * \param autoRemove is true if unneeded packages should be removed + * + * \return true if the solver has successfully solved the problem, + * otherwise false + */ bool static ResolveExternal(const char* const solver, pkgDepCache &Cache, bool const upgrade, bool const distUpgrade, bool const autoRemove); -- cgit v1.2.3 From ebfeeaedf5bc357170cae971c0f6a1458ff65f65 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 7 May 2011 15:49:51 +0200 Subject: implement correct error reporting --- apt-pkg/edsp.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'apt-pkg/edsp.h') diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h index 98a70d7f6..210188d03 100644 --- a/apt-pkg/edsp.h +++ b/apt-pkg/edsp.h @@ -171,8 +171,13 @@ public: * * The first line of the message should be a short description * of the error so it can be used for dialog titles or alike + * + * \param uuid of this error message + * \param message is free form text to discribe the error + * \param output the front-end listens for error messages */ - bool static WriteError(std::string const &message, FILE* output); + bool static WriteError(char const * const uuid, std::string const &message, FILE* output); + /** \brief executes the given solver and returns the pipe ends * -- cgit v1.2.3 From b57c0e355d7f27a74c860ed73700cf9241cb4e61 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 9 May 2011 18:00:28 +0200 Subject: implement proper progress report with OpProgress --- apt-pkg/edsp.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'apt-pkg/edsp.h') diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h index 210188d03..743c3f5d1 100644 --- a/apt-pkg/edsp.h +++ b/apt-pkg/edsp.h @@ -11,6 +11,7 @@ #include #include +#include #include @@ -46,13 +47,15 @@ public: * \param upgrade is true if it is an request like apt-get upgrade * \param distUpgrade is true if it is a request like apt-get dist-upgrade * \param autoRemove is true if removal of unneeded packages should be performed + * \param Progress is an instance to report progress to * * \return true if request was composed successfully, otherwise false */ bool static WriteRequest(pkgDepCache &Cache, FILE* output, bool const upgrade = false, bool const distUpgrade = false, - bool const autoRemove = false); + bool const autoRemove = false, + OpProgress *Progress = NULL); /** \brief creates the scenario representing the package universe * @@ -67,10 +70,11 @@ public: * * \param Cache is the known package universe * \param output is written to this "file" + * \param Progress is an instance to report progress to * * \return true if universe was composed successfully, otherwise false */ - bool static WriteScenario(pkgDepCache &Cache, FILE* output); + bool static WriteScenario(pkgDepCache &Cache, FILE* output, OpProgress *Progress = NULL); /** \brief creates a limited scenario representing the package universe * @@ -83,11 +87,13 @@ public: * \param Cache is the known package universe * \param output is written to this "file" * \param pkgset is a set of packages the universe should be limited to + * \param Progress is an instance to report progress to * * \return true if universe was composed successfully, otherwise false */ bool static WriteLimitedScenario(pkgDepCache &Cache, FILE* output, - APT::PackageSet const &pkgset); + APT::PackageSet const &pkgset, + OpProgress *Progress = NULL); /** \brief waits and acts on the information returned from the solver * @@ -98,10 +104,11 @@ public: * * \param input file descriptor with the response from the solver * \param Cache the solution should be applied on if any + * \param Progress is an instance to report progress to * * \return true if a solution is found and applied correctly, otherwise false */ - bool static ReadResponse(int const input, pkgDepCache &Cache); + bool static ReadResponse(int const input, pkgDepCache &Cache, OpProgress *Progress = NULL); /** \brief search and read the request stanza for action later * @@ -202,13 +209,14 @@ public: * \param upgrade is true if it is a request like apt-get upgrade * \param distUpgrade is true if it is a request like apt-get dist-upgrade * \param autoRemove is true if unneeded packages should be removed + * \param Progress is an instance to report progress to * * \return true if the solver has successfully solved the problem, * otherwise false */ bool static ResolveExternal(const char* const solver, pkgDepCache &Cache, bool const upgrade, bool const distUpgrade, - bool const autoRemove); + bool const autoRemove, OpProgress *Progress = NULL); }; /*}}}*/ #endif -- cgit v1.2.3