Package Kit: Implement progress notifications.

- BJobStateListener: Add progress state and corresponding hook.
- FetchFileJob: Notify job progress hook on libcurl notifications.
- UserInteractionHandler: Add hooks for download progress and checksum
  validation progress.
- PackageManager: inherit from JobStateListener and watch for job
  notifications for internally generated jobs. Forward to corresponding
  UserInteractionHandler hooks as needed.
- Adapt pkgman, HaikuDepot and package_daemon to above changes.
  Neither HaikuDepot nor package_daemon's progress hooks are wired up to
  do anything yet though.
This commit is contained in:
Rene Gollent
2013-09-29 17:25:33 -04:00
parent fe39d2eb8d
commit 9345049af8
12 changed files with 293 additions and 56 deletions
+4 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2011, Haiku, Inc.
* Copyright 2011-2013, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__JOB_H_
@@ -22,6 +22,7 @@ struct BJobStateListener {
// these default implementations do nothing
virtual void JobStarted(BJob* job);
virtual void JobProgress(BJob* job);
virtual void JobSucceeded(BJob* job);
virtual void JobFailed(BJob* job);
virtual void JobAborted(BJob* job);
@@ -30,7 +31,8 @@ struct BJobStateListener {
enum BJobState {
JOB_STATE_WAITING_TO_RUN,
JOB_STATE_RUNNING,
JOB_STATE_STARTED,
JOB_STATE_IN_PROGRESS,
JOB_STATE_SUCCEEDED,
JOB_STATE_FAILED,
JOB_STATE_ABORTED,
+5
View File
@@ -29,6 +29,10 @@ public:
const BEntry& targetEntry);
virtual ~FetchFileJob();
float DownloadProgress() const;
const char* DownloadURL() const;
const char* DownloadFileName() const;
protected:
virtual status_t Execute();
virtual void Cleanup(status_t jobResult);
@@ -46,6 +50,7 @@ private:
BString fFileURL;
BEntry fTargetEntry;
BFile fTargetFile;
float fDownloadProgress;
};
@@ -4,6 +4,7 @@
*
* Authors:
* Ingo Weinhold <[email protected]>
* Rene Gollent <[email protected]>
*/
#ifndef _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_
#define _PACKAGE__MANAGER__PRIVATE__PACKAGE_MANAGER_H_
@@ -20,6 +21,7 @@
#include <package/ActivationTransaction.h>
#include <package/DaemonClient.h>
#include <package/Job.h>
namespace BPackageKit {
@@ -33,7 +35,7 @@ using BPackageKit::BPrivate::BActivationTransaction;
using BPackageKit::BPrivate::BDaemonClient;
class BPackageManager {
class BPackageManager : protected BJobStateListener {
public:
class RemoteRepository;
class InstalledRepository;
@@ -55,8 +57,7 @@ public:
public:
BPackageManager(
BPackageInstallationLocation location,
BJobStateListener* listener);
BPackageInstallationLocation location);
virtual ~BPackageManager();
void Init(uint32 flags);
@@ -100,6 +101,12 @@ public:
protected:
InstalledRepository& InstallationRepository();
protected:
// BJobStateListener
virtual void JobStarted(BJob* job);
virtual void JobProgress(BJob* job);
virtual void JobSucceeded(BJob* job);
private:
void _HandleProblems();
void _AnalyzeResult();
@@ -141,7 +148,6 @@ protected:
// must be set by the derived class
InstallationInterface* fInstallationInterface;
UserInteractionHandler* fUserInteractionHandler;
BJobStateListener* fJobStateListener;
};
@@ -259,6 +265,19 @@ public:
virtual void Warn(status_t error, const char* format, ...)
= 0;
virtual void ProgressPackageDownloadStarted(
const char* packageName) = 0;
virtual void ProgressPackageDownloadActive(
const char* packageName,
float completionPercentage) = 0;
virtual void ProgressPackageDownloadComplete(
const char* packageName) = 0;
virtual void ProgressPackageChecksumStarted(
const char* title) = 0;
virtual void ProgressPackageChecksumComplete(
const char* title) = 0;
virtual void ProgressStartApplyingChanges(
InstalledRepository& repository) = 0;
virtual void ProgressTransactionCommitted(
+37 -2
View File
@@ -142,10 +142,9 @@ public:
PackageManager::PackageManager(BPackageInstallationLocation location)
:
BPackageManager(location, &fJobStateListener),
BPackageManager(location),
BPackageManager::UserInteractionHandler(),
fDecisionProvider(),
fJobStateListener(),
fClientInstallationInterface(),
fProblemWindow(NULL),
fCurrentInstallPackage(NULL),
@@ -317,6 +316,42 @@ PackageManager::Warn(status_t error, const char* format, ...)
}
void
PackageManager::ProgressPackageDownloadStarted(const char* packageName)
{
// TODO: implement
}
void
PackageManager::ProgressPackageDownloadActive(const char* packageName,
float completionPercentage)
{
// TODO: implement
}
void
PackageManager::ProgressPackageDownloadComplete(const char* packageName)
{
// TODO: implement
}
void
PackageManager::ProgressPackageChecksumStarted(const char* title)
{
// TODO: implement
}
void
PackageManager::ProgressPackageChecksumComplete(const char* title)
{
// TODO: implement
}
void
PackageManager::ProgressStartApplyingChanges(InstalledRepository& repository)
{
+13 -1
View File
@@ -62,6 +62,19 @@ private:
virtual void ConfirmChanges(bool fromMostSpecific);
virtual void Warn(status_t error, const char* format, ...);
virtual void ProgressPackageDownloadStarted(
const char* packageName);
virtual void ProgressPackageDownloadActive(
const char* packageName,
float completionPercentage);
virtual void ProgressPackageDownloadComplete(
const char* packageName);
virtual void ProgressPackageChecksumStarted(
const char* title);
virtual void ProgressPackageChecksumComplete(
const char* title);
virtual void ProgressStartApplyingChanges(
InstalledRepository& repository);
virtual void ProgressTransactionCommitted(
@@ -81,7 +94,6 @@ private:
private:
DecisionProvider fDecisionProvider;
JobStateListener fJobStateListener;
BPackageManager::ClientInstallationInterface
fClientInstallationInterface;
+56 -2
View File
@@ -4,6 +4,7 @@
*
* Authors:
* Ingo Weinhold <ingo_weinhold@gmx.de>
* Rene Gollent <rene@gollent.com>
*/
@@ -23,10 +24,9 @@ using namespace BPackageKit::BPrivate;
PackageManager::PackageManager(BPackageInstallationLocation location)
:
BPackageManager(location, &fJobStateListener),
BPackageManager(location),
BPackageManager::UserInteractionHandler(),
fDecisionProvider(),
fJobStateListener(JobStateListener::EXIT_ON_ABORT),
fClientInstallationInterface()
{
fInstallationInterface = &fClientInstallationInterface;
@@ -39,6 +39,24 @@ PackageManager::~PackageManager()
}
void
PackageManager::JobFailed(BJob* job)
{
BString error = job->ErrorString();
if (error.Length() > 0) {
error.ReplaceAll("\n", "\n*** ");
fprintf(stderr, "%s", error.String());
}
}
void
PackageManager::JobAborted(BJob* job)
{
DIE(job->Result(), "aborted");
}
void
PackageManager::HandleProblems()
{
@@ -134,6 +152,42 @@ PackageManager::Warn(status_t error, const char* format, ...)
}
void
PackageManager::ProgressPackageDownloadStarted(const char* packageName)
{
printf("Downloading %s...\n", packageName);
}
void
PackageManager::ProgressPackageDownloadActive(const char* packageName,
float completionPercentage)
{
// TODO: how to report progress? ncurses perhaps?
}
void
PackageManager::ProgressPackageDownloadComplete(const char* packageName)
{
printf("Finished downloading %s...\n", packageName);
}
void
PackageManager::ProgressPackageChecksumStarted(const char* title)
{
printf("%s...\n", title);
}
void
PackageManager::ProgressPackageChecksumComplete(const char* title)
{
printf("%s complete.\n", title);
}
void
PackageManager::ProgressStartApplyingChanges(InstalledRepository& repository)
{
+18 -2
View File
@@ -4,6 +4,7 @@
*
* Authors:
* Ingo Weinhold <ingo_weinhold@gmx.de>
* Rene Gollent <rene@gollent.com>
*/
#ifndef PACKAGE_MANAGER_H
#define PACKAGE_MANAGER_H
@@ -13,7 +14,6 @@
#include <package/manager/PackageManager.h>
#include "DecisionProvider.h"
#include "JobStateListener.h"
using namespace BPackageKit;
@@ -28,12 +28,29 @@ public:
BPackageInstallationLocation location);
~PackageManager();
virtual void JobFailed(BJob* job);
virtual void JobAborted(BJob* job);
private:
// UserInteractionHandler
virtual void HandleProblems();
virtual void ConfirmChanges(bool fromMostSpecific);
virtual void Warn(status_t error, const char* format, ...);
virtual void ProgressPackageDownloadStarted(
const char* packageName);
virtual void ProgressPackageDownloadActive(
const char* packageName,
float completionPercentage);
virtual void ProgressPackageDownloadComplete(
const char* packageName);
virtual void ProgressPackageChecksumStarted(
const char* packageName);
virtual void ProgressPackageChecksumComplete(
const char* packageName);
virtual void ProgressStartApplyingChanges(
InstalledRepository& repository);
virtual void ProgressTransactionCommitted(
@@ -48,7 +65,6 @@ private:
private:
DecisionProvider fDecisionProvider;
JobStateListener fJobStateListener;
BPackageManager::ClientInstallationInterface
fClientInstallationInterface;
};
+29 -7
View File
@@ -28,7 +28,8 @@ FetchFileJob::FetchFileJob(const BContext& context, const BString& title,
inherited(context, title),
fFileURL(fileURL),
fTargetEntry(targetEntry),
fTargetFile(&targetEntry, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY)
fTargetFile(&targetEntry, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY),
fDownloadProgress(0.0)
{
}
@@ -38,6 +39,27 @@ FetchFileJob::~FetchFileJob()
}
float
FetchFileJob::DownloadProgress() const
{
return fDownloadProgress;
}
const char*
FetchFileJob::DownloadURL() const
{
return fFileURL.String();
}
const char*
FetchFileJob::DownloadFileName() const
{
return fTargetEntry.Name();
}
status_t
FetchFileJob::Execute()
{
@@ -87,19 +109,19 @@ FetchFileJob::Execute()
return B_ERROR;
}
/* if (WIFSIGNALED(cmdResult)
&& (WTERMSIG(cmdResult) == SIGINT || WTERMSIG(cmdResult) == SIGQUIT)) {
return B_CANCELED;
} */
return B_OK;
}
int
FetchFileJob::_ProgressCallback(void *clientp, double dltotal, double dlnow,
FetchFileJob::_ProgressCallback(void *userp, double dltotal, double dlnow,
double ultotal, double ulnow)
{
FetchFileJob* job = reinterpret_cast<FetchFileJob*>(userp);
if (dltotal != 0) {
job->fDownloadProgress = dlnow / dltotal;
job->NotifyStateListeners();
}
return 0;
}
+14 -3
View File
@@ -1,9 +1,10 @@
/*
* Copyright 2011, Haiku, Inc. All Rights Reserved.
* Copyright 2011-2013, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Oliver Tappe <zooey@hirschkaefer.de>
* Rene Gollent <rene@gollent.com>
*/
@@ -28,6 +29,12 @@ BJobStateListener::JobStarted(BJob* job)
}
void
BJobStateListener::JobProgress(BJob* job)
{
}
void
BJobStateListener::JobSucceeded(BJob* job)
{
@@ -134,9 +141,10 @@ BJob::Run()
if (fState != JOB_STATE_WAITING_TO_RUN)
return B_NOT_ALLOWED;
fState = JOB_STATE_RUNNING;
fState = JOB_STATE_STARTED;
NotifyStateListeners();
fState = JOB_STATE_IN_PROGRESS;
fResult = Execute();
Cleanup(fResult);
@@ -227,9 +235,12 @@ BJob::NotifyStateListeners()
if (listener == NULL)
continue;
switch (fState) {
case JOB_STATE_RUNNING:
case JOB_STATE_STARTED:
listener->JobStarted(this);
break;
case JOB_STATE_IN_PROGRESS:
listener->JobProgress(this);
break;
case JOB_STATE_SUCCEEDED:
listener->JobSucceeded(this);
break;
+49 -6
View File
@@ -25,11 +25,17 @@
#include <CopyEngine.h>
#include <package/ActivationTransaction.h>
#include <package/DaemonClient.h>
#include <package/FetchFileJob.h>
#include <package/manager/RepositoryBuilder.h>
#include <package/ValidateChecksumJob.h>
#include "PackageManagerUtils.h"
using BPackageKit::BPrivate::FetchFileJob;
using BPackageKit::BPrivate::ValidateChecksumJob;
namespace BPackageKit {
namespace BManager {
@@ -40,8 +46,7 @@ namespace BPrivate {
// #pragma mark - BPackageManager
BPackageManager::BPackageManager(BPackageInstallationLocation location,
BJobStateListener* listener)
BPackageManager::BPackageManager(BPackageInstallationLocation location)
:
fLocation(location),
fSolver(NULL),
@@ -55,8 +60,7 @@ BPackageManager::BPackageManager(BPackageInstallationLocation location,
fOtherRepositories(10, true),
fTransactions(5, true),
fInstallationInterface(NULL),
fUserInteractionHandler(NULL),
fJobStateListener(listener)
fUserInteractionHandler(NULL)
{
}
@@ -328,6 +332,45 @@ BPackageManager::InstallationRepository()
}
void
BPackageManager::JobStarted(BJob* job)
{
if (dynamic_cast<FetchFileJob*>(job) != NULL) {
FetchFileJob* fetchJob = (FetchFileJob*)job;
fUserInteractionHandler->ProgressPackageDownloadStarted(
fetchJob->DownloadFileName());
} else if (dynamic_cast<ValidateChecksumJob*>(job) != NULL) {
fUserInteractionHandler->ProgressPackageChecksumStarted(
job->Title().String());
}
}
void
BPackageManager::JobProgress(BJob* job)
{
if (dynamic_cast<FetchFileJob*>(job) != NULL) {
FetchFileJob* fetchJob = (FetchFileJob*)job;
fUserInteractionHandler->ProgressPackageDownloadActive(
fetchJob->DownloadFileName(), fetchJob->DownloadProgress());
}
}
void
BPackageManager::JobSucceeded(BJob* job)
{
if (dynamic_cast<FetchFileJob*>(job) != NULL) {
FetchFileJob* fetchJob = (FetchFileJob*)job;
fUserInteractionHandler->ProgressPackageDownloadComplete(
fetchJob->DownloadFileName());
} else if (dynamic_cast<ValidateChecksumJob*>(job) != NULL) {
fUserInteractionHandler->ProgressPackageChecksumComplete(
job->Title().String());
}
}
void
BPackageManager::_HandleProblems()
{
@@ -711,7 +754,7 @@ BPackageManager::DownloadPackage(const BString& fileURL,
const BEntry& targetEntry, const BString& checksum)
{
BDecisionProvider provider;
BContext context(provider, *fJobStateListener);
BContext context(provider, *this);
return DownloadFileRequest(context, fileURL, targetEntry, checksum)
.Process();
}
@@ -721,7 +764,7 @@ status_t
BPackageManager::RefreshRepository(const BRepositoryConfig& repoConfig)
{
BDecisionProvider provider;
BContext context(provider, *fJobStateListener);
BContext context(provider, *this);
return BRefreshRepositoryRequest(context, repoConfig).Process();
}
+31 -17
View File
@@ -43,7 +43,6 @@ PackageManager::PackageManager(Root* root, Volume* volume)
fProblemWindow(NULL)
{
fInstallationInterface = this;
fRequestHandler = this;
fUserInteractionHandler = this;
}
@@ -253,22 +252,6 @@ PackageManager::CommitTransaction(Transaction& transaction,
}
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
PackageManager::HandleProblems()
{
@@ -332,6 +315,37 @@ PackageManager::Warn(status_t error, const char* format, ...)
}
void
PackageManager::ProgressPackageDownloadStarted(const char* packageName)
{
}
void
PackageManager::ProgressPackageDownloadActive(const char* packageName,
float completionPercentage)
{
}
void
PackageManager::ProgressPackageDownloadComplete(const char* packageName)
{
}
void
PackageManager::ProgressPackageChecksumStarted(const char* title)
{
}
void
PackageManager::ProgressPackageChecksumComplete(const char* title)
{
}
void
PackageManager::ProgressStartApplyingChanges(InstalledRepository& repository)
{
+14 -10
View File
@@ -37,9 +37,8 @@ class Volume;
class PackageManager : public BPackageManager,
private BPackageManager::InstallationInterface,
private BPackageManager::RequestHandler,
private BPackageManager::UserInteractionHandler,
private BDecisionProvider, private BJobStateListener {
private BDecisionProvider {
public:
PackageManager(Root* root, Volume* volume);
~PackageManager();
@@ -57,20 +56,25 @@ private:
BDaemonClient::BCommitTransactionResult&
_result);
private:
// RequestHandler
virtual status_t RefreshRepository(
const BRepositoryConfig& repoConfig);
virtual status_t DownloadPackage(const BString& fileURL,
const BEntry& targetEntry,
const BString& checksum);
private:
// UserInteractionHandler
virtual void HandleProblems();
virtual void ConfirmChanges(bool fromMostSpecific);
virtual void Warn(status_t error, const char* format, ...);
virtual void ProgressPackageDownloadStarted(
const char* packageName);
virtual void ProgressPackageDownloadActive(
const char* packageName,
float completionPercentage);
virtual void ProgressPackageDownloadComplete(
const char* packageName);
virtual void ProgressPackageChecksumStarted(
const char* title);
virtual void ProgressPackageChecksumComplete(
const char* title);
virtual void ProgressStartApplyingChanges(
InstalledRepository& repository);
virtual void ProgressTransactionCommitted(