BPackageManager: Eliminate RequestHandler.

- Pull functionality back into package manager itself since the extra
  indirection doesn't really buy us anything in this case, as neither
  request that it handles requires a decision provider.
- Adjust pkgman and HaikuDepot accordingly.
This commit is contained in:
Rene Gollent
2013-09-29 17:25:32 -04:00
parent 672795a37e
commit fe39d2eb8d
6 changed files with 47 additions and 70 deletions
@@ -41,7 +41,6 @@ public:
class InstallationInterface; class InstallationInterface;
class ClientInstallationInterface; class ClientInstallationInterface;
class UserInteractionHandler; class UserInteractionHandler;
class RequestHandler;
typedef BObjectList<RemoteRepository> RemoteRepositoryList; typedef BObjectList<RemoteRepository> RemoteRepositoryList;
typedef BObjectList<InstalledRepository> InstalledRepositoryList; typedef BObjectList<InstalledRepository> InstalledRepositoryList;
@@ -56,8 +55,9 @@ public:
public: public:
BPackageManager( BPackageManager(
BPackageInstallationLocation location); BPackageInstallationLocation location,
~BPackageManager(); BJobStateListener* listener);
virtual ~BPackageManager();
void Init(uint32 flags); void Init(uint32 flags);
@@ -90,6 +90,13 @@ public:
void VerifyInstallation(); void VerifyInstallation();
virtual status_t DownloadPackage(const BString& fileURL,
const BEntry& targetEntry,
const BString& checksum);
virtual status_t RefreshRepository(
const BRepositoryConfig& repoConfig);
protected: protected:
InstalledRepository& InstallationRepository(); InstalledRepository& InstallationRepository();
@@ -133,8 +140,8 @@ protected:
// must be set by the derived class // must be set by the derived class
InstallationInterface* fInstallationInterface; InstallationInterface* fInstallationInterface;
RequestHandler* fRequestHandler;
UserInteractionHandler* fUserInteractionHandler; UserInteractionHandler* fUserInteractionHandler;
BJobStateListener* fJobStateListener;
}; };
@@ -243,18 +250,6 @@ private:
}; };
class BPackageManager::RequestHandler {
public:
virtual ~RequestHandler();
virtual status_t RefreshRepository(
const BRepositoryConfig& repoConfig) = 0;
virtual status_t DownloadPackage(const BString& fileURL,
const BEntry& targetEntry,
const BString& checksum) = 0;
};
class BPackageManager::UserInteractionHandler { class BPackageManager::UserInteractionHandler {
public: public:
virtual ~UserInteractionHandler(); virtual ~UserInteractionHandler();
+4 -6
View File
@@ -142,18 +142,16 @@ public:
PackageManager::PackageManager(BPackageInstallationLocation location) PackageManager::PackageManager(BPackageInstallationLocation location)
: :
BPackageManager(location), BPackageManager(location, &fJobStateListener),
BPackageManager::UserInteractionHandler(), BPackageManager::UserInteractionHandler(),
fDecisionProvider(), fDecisionProvider(),
fJobStateListener(), fJobStateListener(),
fContext(fDecisionProvider, fJobStateListener),
fClientInstallationInterface(), fClientInstallationInterface(),
fProblemWindow(NULL), fProblemWindow(NULL),
fCurrentInstallPackage(NULL), fCurrentInstallPackage(NULL),
fCurrentUninstallPackage(NULL) fCurrentUninstallPackage(NULL)
{ {
fInstallationInterface = &fClientInstallationInterface; fInstallationInterface = &fClientInstallationInterface;
fRequestHandler = this;
fUserInteractionHandler = this; fUserInteractionHandler = this;
} }
@@ -228,7 +226,7 @@ PackageManager::RefreshRepository(const BRepositoryConfig& repoConfig)
{ {
status_t result; status_t result;
try { try {
result = BRefreshRepositoryRequest(fContext, repoConfig).Process(); result = BPackageManager::RefreshRepository(repoConfig);
} catch (BFatalErrorException ex) { } catch (BFatalErrorException ex) {
fprintf(stderr, "Fatal error occurred while refreshing repository: " fprintf(stderr, "Fatal error occurred while refreshing repository: "
"%s (%s)\n", ex.Message().String(), ex.Details().String()); "%s (%s)\n", ex.Message().String(), ex.Details().String());
@@ -249,8 +247,8 @@ PackageManager::DownloadPackage(const BString& fileURL,
{ {
status_t result; status_t result;
try { try {
result = DownloadFileRequest(fContext, fileURL, targetEntry, checksum) result = BPackageManager::DownloadPackage(fileURL, targetEntry,
.Process(); checksum);
} catch (BFatalErrorException ex) { } catch (BFatalErrorException ex) {
fprintf(stderr, "Fatal error occurred while downloading package: " fprintf(stderr, "Fatal error occurred while downloading package: "
"%s: %s (%s)\n", fileURL.String(), ex.Message().String(), "%s: %s (%s)\n", fileURL.String(), ex.Message().String(),
-4
View File
@@ -37,7 +37,6 @@ using BPackageKit::BManager::BPrivate::BPackageManager;
class PackageManager : public BPackageManager, class PackageManager : public BPackageManager,
private BPackageManager::RequestHandler,
private BPackageManager::UserInteractionHandler { private BPackageManager::UserInteractionHandler {
public: public:
PackageManager( PackageManager(
@@ -51,8 +50,6 @@ public:
PackageInfoRef package, PackageInfoRef package,
bool install); bool install);
private:
// RequestHandler
virtual status_t RefreshRepository( virtual status_t RefreshRepository(
const BRepositoryConfig& repoConfig); const BRepositoryConfig& repoConfig);
virtual status_t DownloadPackage(const BString& fileURL, virtual status_t DownloadPackage(const BString& fileURL,
@@ -85,7 +82,6 @@ private:
private: private:
DecisionProvider fDecisionProvider; DecisionProvider fDecisionProvider;
JobStateListener fJobStateListener; JobStateListener fJobStateListener;
BContext fContext;
BPackageManager::ClientInstallationInterface BPackageManager::ClientInstallationInterface
fClientInstallationInterface; fClientInstallationInterface;
+1 -19
View File
@@ -23,15 +23,13 @@ using namespace BPackageKit::BPrivate;
PackageManager::PackageManager(BPackageInstallationLocation location) PackageManager::PackageManager(BPackageInstallationLocation location)
: :
BPackageManager(location), BPackageManager(location, &fJobStateListener),
BPackageManager::UserInteractionHandler(), BPackageManager::UserInteractionHandler(),
fDecisionProvider(), fDecisionProvider(),
fJobStateListener(JobStateListener::EXIT_ON_ABORT), fJobStateListener(JobStateListener::EXIT_ON_ABORT),
fContext(fDecisionProvider, fJobStateListener),
fClientInstallationInterface() fClientInstallationInterface()
{ {
fInstallationInterface = &fClientInstallationInterface; fInstallationInterface = &fClientInstallationInterface;
fRequestHandler = this;
fUserInteractionHandler = this; fUserInteractionHandler = this;
} }
@@ -41,22 +39,6 @@ PackageManager::~PackageManager()
} }
status_t
PackageManager::RefreshRepository(const BRepositoryConfig& repoConfig)
{
return BRefreshRepositoryRequest(fContext, repoConfig).Process();
}
status_t
PackageManager::DownloadPackage(const BString& fileURL,
const BEntry& targetEntry, const BString& checksum)
{
return DownloadFileRequest(fContext, fileURL, targetEntry, checksum)
.Process();
}
void void
PackageManager::HandleProblems() PackageManager::HandleProblems()
{ {
-10
View File
@@ -22,21 +22,12 @@ using BManager::BPrivate::BPackageManager;
class PackageManager : public BPackageManager, class PackageManager : public BPackageManager,
private BPackageManager::RequestHandler,
private BPackageManager::UserInteractionHandler { private BPackageManager::UserInteractionHandler {
public: public:
PackageManager( PackageManager(
BPackageInstallationLocation location); BPackageInstallationLocation location);
~PackageManager(); ~PackageManager();
private:
// RequestHandler
virtual status_t RefreshRepository(
const BRepositoryConfig& repoConfig);
virtual status_t DownloadPackage(const BString& fileURL,
const BEntry& targetEntry,
const BString& checksum);
private: private:
// UserInteractionHandler // UserInteractionHandler
virtual void HandleProblems(); virtual void HandleProblems();
@@ -58,7 +49,6 @@ private:
private: private:
DecisionProvider fDecisionProvider; DecisionProvider fDecisionProvider;
JobStateListener fJobStateListener; JobStateListener fJobStateListener;
BContext fContext;
BPackageManager::ClientInstallationInterface BPackageManager::ClientInstallationInterface
fClientInstallationInterface; fClientInstallationInterface;
}; };
+29 -13
View File
@@ -4,13 +4,16 @@
* *
* Authors: * Authors:
* Ingo Weinhold <ingo_weinhold@gmx.de> * Ingo Weinhold <ingo_weinhold@gmx.de>
* Rene Gollent <rene@gollent.com>
*/ */
#include <package/manager/PackageManager.h> #include <package/manager/PackageManager.h>
#include <Directory.h> #include <Directory.h>
#include <package/DownloadFileRequest.h>
#include <package/PackageRoster.h> #include <package/PackageRoster.h>
#include <package/RefreshRepositoryRequest.h>
#include <package/RepositoryCache.h> #include <package/RepositoryCache.h>
#include <package/solver/SolverPackage.h> #include <package/solver/SolverPackage.h>
#include <package/solver/SolverPackageSpecifier.h> #include <package/solver/SolverPackageSpecifier.h>
@@ -37,7 +40,8 @@ namespace BPrivate {
// #pragma mark - BPackageManager // #pragma mark - BPackageManager
BPackageManager::BPackageManager(BPackageInstallationLocation location) BPackageManager::BPackageManager(BPackageInstallationLocation location,
BJobStateListener* listener)
: :
fLocation(location), fLocation(location),
fSolver(NULL), fSolver(NULL),
@@ -51,8 +55,8 @@ BPackageManager::BPackageManager(BPackageInstallationLocation location)
fOtherRepositories(10, true), fOtherRepositories(10, true),
fTransactions(5, true), fTransactions(5, true),
fInstallationInterface(NULL), fInstallationInterface(NULL),
fRequestHandler(NULL), fUserInteractionHandler(NULL),
fUserInteractionHandler(NULL) fJobStateListener(listener)
{ {
} }
@@ -483,7 +487,7 @@ BPackageManager::_PreparePackageChanges(
BString url = remoteRepository->Config().PackagesURL(); BString url = remoteRepository->Config().PackagesURL();
url << '/' << fileName; url << '/' << fileName;
status_t error = fRequestHandler->DownloadPackage(url, entry, status_t error = DownloadPackage(url, entry,
package->Info().Checksum()); package->Info().Checksum());
if (error != B_OK) if (error != B_OK)
DIE(error, "failed to download package"); DIE(error, "failed to download package");
@@ -671,7 +675,7 @@ BPackageManager::_GetRepositoryCache(BPackageRoster& roster,
if (!refresh && roster.GetRepositoryCache(config.Name(), &_cache) == B_OK) if (!refresh && roster.GetRepositoryCache(config.Name(), &_cache) == B_OK)
return B_OK; return B_OK;
status_t error = fRequestHandler->RefreshRepository(config); status_t error = RefreshRepository(config);
if (error != B_OK) { if (error != B_OK) {
fUserInteractionHandler->Warn(error, fUserInteractionHandler->Warn(error,
"refreshing repository \"%s\" failed", config.Name().String()); "refreshing repository \"%s\" failed", config.Name().String());
@@ -702,6 +706,26 @@ BPackageManager::_NextSpecificInstallationLocation()
} }
status_t
BPackageManager::DownloadPackage(const BString& fileURL,
const BEntry& targetEntry, const BString& checksum)
{
BDecisionProvider provider;
BContext context(provider, *fJobStateListener);
return DownloadFileRequest(context, fileURL, targetEntry, checksum)
.Process();
}
status_t
BPackageManager::RefreshRepository(const BRepositoryConfig& repoConfig)
{
BDecisionProvider provider;
BContext context(provider, *fJobStateListener);
return BRefreshRepositoryRequest(context, repoConfig).Process();
}
// #pragma mark - RemoteRepository // #pragma mark - RemoteRepository
@@ -869,14 +893,6 @@ BPackageManager::ClientInstallationInterface::CommitTransaction(
} }
// #pragma mark - RequestHandler
BPackageManager::RequestHandler::~RequestHandler()
{
}
// #pragma mark - UserInteractionHandler // #pragma mark - UserInteractionHandler