Flesh out the package kit solver API quite a bit more

* Reorganize things a bit:
  - BSolver is now an abstract base class.
  - A libsolv based implementation, LibsolvSolver, lives in a new
    add-on, which is loaded lazily.
  - Get rid of libpackage_solver. Save for LibsolvSolver everything
    is moved to libpackage.
  - This is a nicer solution for the cyclic dependency caused by
    libsolv (libsolvext to be precise) using the package kit for
    reading repositories and package files.
* Add a solver result data structure and and an accessor the solver.
* Add problem reporting support to the solver. There aren't data
  structures for the problem solutions yet and support for selecting
  solutions and re-solving is missing as well.
This commit is contained in:
Ingo Weinhold
2013-04-03 02:15:57 +00:00
parent 2d0563f357
commit 1a4d020daf
17 changed files with 1321 additions and 351 deletions
+22 -10
View File
@@ -13,30 +13,42 @@ namespace BPackageKit {
class BSolverPackageSpecifierList;
class BSolverProblem;
class BSolverRepository;
class BSolverResult;
class BSolver {
public:
BSolver();
~BSolver();
virtual ~BSolver();
status_t Init();
static status_t Create(BSolver*& _solver);
status_t AddRepository(BSolverRepository* repository);
virtual status_t Init() = 0;
status_t Install(
virtual status_t AddRepository(
BSolverRepository* repository) = 0;
virtual status_t Install(
const BSolverPackageSpecifierList&
packages);
packages) = 0;
private:
class Implementation;
bool HasProblems() const
{ return CountProblems() > 0; }
virtual int32 CountProblems() const = 0;
virtual BSolverProblem* ProblemAt(int32 index) const = 0;
private:
Implementation* fImplementation;
virtual status_t GetResult(BSolverResult& _result) = 0;
protected:
BSolver();
};
// function exported by the libsolv based add-on
extern "C" BSolver* create_solver();
} // namespace BPackageKit
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright 2013, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__SOLVER_PACKAGE_H_
#define _PACKAGE__SOLVER_PACKAGE_H_
#include <package/PackageInfo.h>
namespace BPackageKit {
class BSolverRepository;
class BSolverPackage {
public:
BSolverPackage(BSolverRepository* repository,
const BPackageInfo& packageInfo);
BSolverPackage(const BSolverPackage& other);
~BSolverPackage();
BSolverRepository* Repository() const;
const BPackageInfo& Info() const;
BString Name() const;
BString VersionedName() const;
BSolverPackage& operator=(const BSolverPackage& other);
private:
BSolverRepository* fRepository;
BPackageInfo fInfo;
};
} // namespace BPackageKit
#endif // _PACKAGE__SOLVER_PACKAGE_H_
@@ -28,6 +28,7 @@ public:
bool AppendSpecifier(
const BSolverPackageSpecifier& specifier);
void MakeEmpty();
BSolverPackageSpecifierList& operator=(
const BSolverPackageSpecifierList& other);
+69
View File
@@ -0,0 +1,69 @@
/*
* Copyright 2013, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__SOLVER_PROBLEM_H_
#define _PACKAGE__SOLVER_PROBLEM_H_
#include <package/PackageResolvableExpression.h>
namespace BPackageKit {
class BSolverPackage;
class BSolverProblem {
public:
enum BType {
B_UNSPECIFIED,
B_NOT_IN_DISTUPGRADE_REPOSITORY,
B_INFERIOR_ARCHITECTURE,
B_INSTALLED_PACKAGE_PROBLEM,
B_CONFLICTING_REQUESTS,
B_REQUESTED_RESOLVABLE_NOT_PROVIDED,
B_REQUESTED_RESOLVABLE_PROVIDED_BY_SYSTEM,
B_DEPENDENCY_PROBLEM,
B_PACKAGE_NOT_INSTALLABLE,
B_DEPENDENCY_NOT_PROVIDED,
B_PACKAGE_NAME_CLASH,
B_PACKAGE_CONFLICT,
B_PACKAGE_OBSOLETES_RESOLVABLE,
B_INSTALLED_PACKAGE_OBSOLETES_RESOLVABLE,
B_PACKAGE_IMPLICITLY_OBSOLETES_RESOLVABLE,
B_DEPENDENCY_NOT_INSTALLABLE,
B_SELF_CONFLICT
};
public:
BSolverProblem(BType type,
BSolverPackage* sourcePackage,
BSolverPackage* targetPackage = NULL);
BSolverProblem(BType type,
BSolverPackage* sourcePackage,
BSolverPackage* targetPackage,
const BPackageResolvableExpression&
dependency);
~BSolverProblem();
BType Type() const;
BSolverPackage* SourcePackage() const;
BSolverPackage* TargetPackage() const;
const BPackageResolvableExpression& Dependency() const;
BString ToString() const;
private:
BType fType;
BSolverPackage* fSourcePackage;
BSolverPackage* fTargetPackage;
BPackageResolvableExpression fDependency;
};
} // namespace BPackageKit
#endif // _PACKAGE__SOLVER_PROBLEM_H_
+10 -2
View File
@@ -6,6 +6,7 @@
#define _PACKAGE__SOLVER_REPOSITORY_H_
#include <ObjectList.h>
#include <package/PackageDefs.h>
#include <package/PackageInfoSet.h>
#include <String.h>
@@ -16,6 +17,7 @@ namespace BPackageKit {
class BPackageInfo;
class BRepositoryConfig;
class BSolverPackage;
class BSolverRepository {
@@ -45,21 +47,27 @@ public:
status_t InitCheck();
bool IsInstalled() const;
void SetInstalled(bool isInstalled);
BString Name() const;
uint8 Priority() const;
bool IsEmpty() const;
int32 CountPackages() const;
BSolverPackage* PackageAt(int32 index) const;
status_t AddPackage(const BPackageInfo& info);
status_t AddPackages(
BPackageInstallationLocation location);
Iterator GetIterator() const;
private:
typedef BObjectList<BSolverPackage> PackageList;
private:
BString fName;
uint8 fPriority;
bool fIsInstalled;
BPackageInfoSet fPackages;
PackageList fPackages;
};
+67
View File
@@ -0,0 +1,67 @@
/*
* Copyright 2013, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__SOLVER_RESULT_H_
#define _PACKAGE__SOLVER_RESULT_H_
#include <ObjectList.h>
namespace BPackageKit {
class BSolverPackage;
class BSolverResultElement {
public:
enum BType {
B_TYPE_INSTALL,
B_TYPE_UNINSTALL
};
public:
BSolverResultElement(BType type,
BSolverPackage* package);
BSolverResultElement(
const BSolverResultElement& other);
~BSolverResultElement();
BType Type() const;
BSolverPackage* Package() const;
BSolverResultElement& operator=(const BSolverResultElement& other);
private:
BType fType;
BSolverPackage* fPackage;
};
class BSolverResult {
public:
BSolverResult();
~BSolverResult();
bool IsEmpty() const;
int32 CountElements() const;
const BSolverResultElement* ElementAt(int32 index) const;
void MakeEmpty();
bool AppendElement(
const BSolverResultElement& element);
private:
typedef BObjectList<BSolverResultElement> ElementList;
private:
ElementList fElements;
};
} // namespace BPackageKit
#endif // _PACKAGE__SOLVER_RESULT_H_