Moved BJob, and JobQueue into the support kit.
* Put it in the BSupportKit namespace, following the style introduced with the package kit for now. * The BSupportKit::BJob class no longer knows about the package kit's Context class. However, the BPackageKit::BJob class does. * Due to the namespace juggling, a lot of files had to be touched. * The JobQueue class remains private. * Due to the way Haiku is built on itself, you cannot build this change under Haiku with an older release.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include "JobStateListener.h"
|
||||
|
||||
|
||||
using BPackageKit::BJob;
|
||||
using BSupportKit::BJob;
|
||||
|
||||
|
||||
JobStateListener::JobStateListener()
|
||||
|
||||
@@ -7,17 +7,17 @@
|
||||
#define JOB_STATE_LISTENER_H
|
||||
|
||||
|
||||
#include <package/Job.h>
|
||||
#include <Job.h>
|
||||
|
||||
|
||||
class JobStateListener : public BPackageKit::BJobStateListener {
|
||||
class JobStateListener : public BSupportKit::BJobStateListener {
|
||||
public:
|
||||
JobStateListener();
|
||||
|
||||
virtual void JobStarted(BPackageKit::BJob* job);
|
||||
virtual void JobSucceeded(BPackageKit::BJob* job);
|
||||
virtual void JobFailed(BPackageKit::BJob* job);
|
||||
virtual void JobAborted(BPackageKit::BJob* job);
|
||||
virtual void JobStarted(BSupportKit::BJob* job);
|
||||
virtual void JobSucceeded(BSupportKit::BJob* job);
|
||||
virtual void JobFailed(BSupportKit::BJob* job);
|
||||
virtual void JobAborted(BSupportKit::BJob* job);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "pkgman.h"
|
||||
|
||||
|
||||
using BPackageKit::BJob;
|
||||
using BSupportKit::BJob;
|
||||
|
||||
|
||||
JobStateListener::JobStateListener(uint32 flags)
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
#define JOB_STATE_LISTENER_H
|
||||
|
||||
|
||||
#include <package/Job.h>
|
||||
#include <Job.h>
|
||||
|
||||
|
||||
class JobStateListener : public BPackageKit::BJobStateListener {
|
||||
class JobStateListener : public BSupportKit::BJobStateListener {
|
||||
public:
|
||||
enum {
|
||||
EXIT_ON_ERROR = 0x01,
|
||||
@@ -22,10 +22,10 @@ public:
|
||||
uint32 flags = EXIT_ON_ERROR
|
||||
| EXIT_ON_ABORT);
|
||||
|
||||
virtual void JobStarted(BPackageKit::BJob* job);
|
||||
virtual void JobSucceeded(BPackageKit::BJob* job);
|
||||
virtual void JobFailed(BPackageKit::BJob* job);
|
||||
virtual void JobAborted(BPackageKit::BJob* job);
|
||||
virtual void JobStarted(BSupportKit::BJob* job);
|
||||
virtual void JobSucceeded(BSupportKit::BJob* job);
|
||||
virtual void JobFailed(BSupportKit::BJob* job);
|
||||
virtual void JobAborted(BSupportKit::BJob* job);
|
||||
|
||||
private:
|
||||
uint32 fFlags;
|
||||
|
||||
@@ -53,7 +53,7 @@ PackageManager::SetInteractive(bool interactive)
|
||||
|
||||
|
||||
void
|
||||
PackageManager::JobFailed(BJob* job)
|
||||
PackageManager::JobFailed(BSupportKit::BJob* job)
|
||||
{
|
||||
BString error = job->ErrorString();
|
||||
if (error.Length() > 0) {
|
||||
@@ -64,7 +64,7 @@ PackageManager::JobFailed(BJob* job)
|
||||
|
||||
|
||||
void
|
||||
PackageManager::JobAborted(BJob* job)
|
||||
PackageManager::JobAborted(BSupportKit::BJob* job)
|
||||
{
|
||||
DIE(job->Result(), "aborted");
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ public:
|
||||
|
||||
void SetInteractive(bool interactive);
|
||||
|
||||
virtual void JobFailed(BJob* job);
|
||||
virtual void JobAborted(BJob* job);
|
||||
virtual void JobFailed(BSupportKit::BJob* job);
|
||||
virtual void JobAborted(BSupportKit::BJob* job);
|
||||
|
||||
private:
|
||||
// UserInteractionHandler
|
||||
|
||||
@@ -14,6 +14,8 @@ BuildPlatformMergeObjectPIC <libbe_build>support_kit.o :
|
||||
DataIO.cpp
|
||||
DataPositionIOWrapper.cpp
|
||||
Flattenable.cpp
|
||||
Job.cpp
|
||||
JobQueue.cpp
|
||||
List.cpp
|
||||
Locker.cpp
|
||||
PointerList.cpp
|
||||
|
||||
@@ -99,7 +99,6 @@ BuildPlatformSharedLibrary libpackage_build.so
|
||||
FetchFileJob.cpp
|
||||
InstallationLocationInfo.cpp
|
||||
Job.cpp
|
||||
JobQueue.cpp
|
||||
PackageInfo.cpp
|
||||
PackageInfoContentHandler.cpp
|
||||
PackageInfoParser.cpp
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -77,7 +77,7 @@ ActivateRepositoryConfigJob::Execute()
|
||||
void
|
||||
ActivateRepositoryConfigJob::Cleanup(status_t jobResult)
|
||||
{
|
||||
if (jobResult != B_OK && State() != JOB_STATE_ABORTED
|
||||
if (jobResult != B_OK && State() != BSupportKit::B_JOB_STATE_ABORTED
|
||||
&& fTargetEntry.InitCheck() == B_OK)
|
||||
fTargetEntry.Remove();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -10,11 +10,11 @@
|
||||
#include <package/AddRepositoryRequest.h>
|
||||
|
||||
#include <Directory.h>
|
||||
#include <JobQueue.h>
|
||||
#include <Path.h>
|
||||
|
||||
#include <package/ActivateRepositoryConfigJob.h>
|
||||
#include <package/FetchFileJob.h>
|
||||
#include <package/JobQueue.h>
|
||||
#include <package/PackageRoster.h>
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ AddRepositoryRequest::CreateInitialJobs()
|
||||
|
||||
|
||||
void
|
||||
AddRepositoryRequest::JobSucceeded(BJob* job)
|
||||
AddRepositoryRequest::JobSucceeded(BSupportKit::BJob* job)
|
||||
{
|
||||
if (job == fActivateJob)
|
||||
fRepositoryName = fActivateJob->RepositoryName();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -39,7 +39,7 @@ BDecisionProvider::YesNoDecisionNeeded(const BString& description,
|
||||
|
||||
|
||||
BContext::BContext(BDecisionProvider& decisionProvider,
|
||||
BJobStateListener& jobStateListener)
|
||||
BSupportKit::BJobStateListener& jobStateListener)
|
||||
:
|
||||
fDecisionProvider(decisionProvider),
|
||||
fJobStateListener(jobStateListener),
|
||||
@@ -74,7 +74,7 @@ BContext::GetNewTempfile(const BString& baseName, BEntry* entry) const
|
||||
}
|
||||
|
||||
|
||||
BJobStateListener&
|
||||
BSupportKit::BJobStateListener&
|
||||
BContext::JobStateListener() const
|
||||
{
|
||||
return fJobStateListener;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -10,10 +10,10 @@
|
||||
#include <package/DropRepositoryRequest.h>
|
||||
|
||||
#include <Directory.h>
|
||||
#include <JobQueue.h>
|
||||
#include <Path.h>
|
||||
|
||||
#include <package/RemoveRepositoryJob.h>
|
||||
#include <package/JobQueue.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
@@ -88,7 +88,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
InitTerminateLibPackage.cpp
|
||||
InstallationLocationInfo.cpp
|
||||
Job.cpp
|
||||
JobQueue.cpp
|
||||
PackageInfo.cpp
|
||||
PackageInfoContentHandler.cpp
|
||||
PackageInfoParser.cpp
|
||||
|
||||
+3
-233
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -10,60 +10,15 @@
|
||||
|
||||
#include <package/Job.h>
|
||||
|
||||
#include <Errors.h>
|
||||
|
||||
#include <package/Context.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
|
||||
BJobStateListener::~BJobStateListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJobStateListener::JobStarted(BJob* job)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJobStateListener::JobProgress(BJob* job)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJobStateListener::JobSucceeded(BJob* job)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJobStateListener::JobFailed(BJob* job)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJobStateListener::JobAborted(BJob* job)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BJob::BJob(const BContext& context, const BString& title)
|
||||
:
|
||||
fContext(context),
|
||||
fTitle(title),
|
||||
fState(JOB_STATE_WAITING_TO_RUN),
|
||||
fTicketNumber(0xFFFFFFFFUL)
|
||||
BSupportKit::BJob(title),
|
||||
fContext(context)
|
||||
{
|
||||
if (fTitle.Length() == 0)
|
||||
fInitStatus = B_BAD_VALUE;
|
||||
else
|
||||
fInitStatus = B_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,189 +27,4 @@ BJob::~BJob()
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::InitCheck() const
|
||||
{
|
||||
return fInitStatus;
|
||||
}
|
||||
|
||||
|
||||
const BString&
|
||||
BJob::Title() const
|
||||
{
|
||||
return fTitle;
|
||||
}
|
||||
|
||||
|
||||
BJobState
|
||||
BJob::State() const
|
||||
{
|
||||
return fState;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::Result() const
|
||||
{
|
||||
return fResult;
|
||||
}
|
||||
|
||||
|
||||
const BString&
|
||||
BJob::ErrorString() const
|
||||
{
|
||||
return fErrorString;
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
BJob::TicketNumber() const
|
||||
{
|
||||
return fTicketNumber;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJob::_SetTicketNumber(uint32 ticketNumber)
|
||||
{
|
||||
fTicketNumber = ticketNumber;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJob::_ClearTicketNumber()
|
||||
{
|
||||
fTicketNumber = 0xFFFFFFFFUL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJob::SetErrorString(const BString& error)
|
||||
{
|
||||
fErrorString = error;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::Run()
|
||||
{
|
||||
if (fState != JOB_STATE_WAITING_TO_RUN)
|
||||
return B_NOT_ALLOWED;
|
||||
|
||||
fState = JOB_STATE_STARTED;
|
||||
NotifyStateListeners();
|
||||
|
||||
fState = JOB_STATE_IN_PROGRESS;
|
||||
fResult = Execute();
|
||||
Cleanup(fResult);
|
||||
|
||||
fState = fResult == B_OK
|
||||
? JOB_STATE_SUCCEEDED
|
||||
: fResult == B_CANCELED
|
||||
? JOB_STATE_ABORTED
|
||||
: JOB_STATE_FAILED;
|
||||
NotifyStateListeners();
|
||||
|
||||
return fResult;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJob::Cleanup(status_t /*jobResult*/)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::AddStateListener(BJobStateListener* listener)
|
||||
{
|
||||
return fStateListeners.AddItem(listener) ? B_OK : B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::RemoveStateListener(BJobStateListener* listener)
|
||||
{
|
||||
return fStateListeners.RemoveItem(listener) ? B_OK : B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::AddDependency(BJob* job)
|
||||
{
|
||||
if (fDependencies.HasItem(job))
|
||||
return B_ERROR;
|
||||
|
||||
if (fDependencies.AddItem(job) && job->fDependantJobs.AddItem(this))
|
||||
return B_OK;
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::RemoveDependency(BJob* job)
|
||||
{
|
||||
if (!fDependencies.HasItem(job))
|
||||
return B_ERROR;
|
||||
|
||||
if (fDependencies.RemoveItem(job) && job->fDependantJobs.RemoveItem(this))
|
||||
return B_OK;
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BJob::IsRunnable() const
|
||||
{
|
||||
return fDependencies.IsEmpty();
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BJob::CountDependencies() const
|
||||
{
|
||||
return fDependencies.CountItems();
|
||||
}
|
||||
|
||||
|
||||
BJob*
|
||||
BJob::DependantJobAt(int32 index) const
|
||||
{
|
||||
return fDependantJobs.ItemAt(index);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJob::NotifyStateListeners()
|
||||
{
|
||||
int32 count = fStateListeners.CountItems();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
BJobStateListener* listener = fStateListeners.ItemAt(i);
|
||||
if (listener == NULL)
|
||||
continue;
|
||||
switch (fState) {
|
||||
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;
|
||||
case JOB_STATE_FAILED:
|
||||
listener->JobFailed(this);
|
||||
break;
|
||||
case JOB_STATE_ABORTED:
|
||||
listener->JobAborted(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPackageKit
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -12,11 +12,12 @@
|
||||
#include <Directory.h>
|
||||
#include <Path.h>
|
||||
|
||||
#include <JobQueue.h>
|
||||
|
||||
#include <package/ActivateRepositoryCacheJob.h>
|
||||
#include <package/ChecksumAccessors.h>
|
||||
#include <package/ValidateChecksumJob.h>
|
||||
#include <package/FetchFileJob.h>
|
||||
#include <package/JobQueue.h>
|
||||
#include <package/RepositoryCache.h>
|
||||
#include <package/RepositoryConfig.h>
|
||||
#include <package/PackageRoster.h>
|
||||
@@ -96,7 +97,7 @@ BRefreshRepositoryRequest::CreateInitialJobs()
|
||||
|
||||
|
||||
void
|
||||
BRefreshRepositoryRequest::JobSucceeded(BJob* job)
|
||||
BRefreshRepositoryRequest::JobSucceeded(BSupportKit::BJob* job)
|
||||
{
|
||||
if (job == fValidateChecksumJob
|
||||
&& !fValidateChecksumJob->ChecksumsMatch()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -11,14 +11,15 @@
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <JobQueue.h>
|
||||
|
||||
#include <package/Context.h>
|
||||
#include <package/JobQueue.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
|
||||
|
||||
using BPrivate::JobQueue;
|
||||
using BSupportKit::BPrivate::JobQueue;
|
||||
|
||||
|
||||
BRequest::BRequest(const BContext& context)
|
||||
@@ -42,7 +43,7 @@ BRequest::InitCheck() const
|
||||
}
|
||||
|
||||
|
||||
BJob*
|
||||
BSupportKit::BJob*
|
||||
BRequest::PopRunnableJob()
|
||||
{
|
||||
if (fJobQueue == NULL)
|
||||
@@ -63,7 +64,7 @@ BRequest::Process(bool failIfCanceledOnly)
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
while (BJob* job = PopRunnableJob()) {
|
||||
while (BSupportKit::BJob* job = PopRunnableJob()) {
|
||||
error = job->Run();
|
||||
delete job;
|
||||
if (error != B_OK) {
|
||||
@@ -77,7 +78,7 @@ BRequest::Process(bool failIfCanceledOnly)
|
||||
|
||||
|
||||
status_t
|
||||
BRequest::QueueJob(BJob* job)
|
||||
BRequest::QueueJob(BSupportKit::BJob* job)
|
||||
{
|
||||
if (fJobQueue == NULL)
|
||||
return B_NO_INIT;
|
||||
|
||||
@@ -364,7 +364,7 @@ BPackageManager::InstallationRepository()
|
||||
|
||||
|
||||
void
|
||||
BPackageManager::JobStarted(BJob* job)
|
||||
BPackageManager::JobStarted(BSupportKit::BJob* job)
|
||||
{
|
||||
if (dynamic_cast<FetchFileJob*>(job) != NULL) {
|
||||
FetchFileJob* fetchJob = (FetchFileJob*)job;
|
||||
@@ -378,7 +378,7 @@ BPackageManager::JobStarted(BJob* job)
|
||||
|
||||
|
||||
void
|
||||
BPackageManager::JobProgress(BJob* job)
|
||||
BPackageManager::JobProgress(BSupportKit::BJob* job)
|
||||
{
|
||||
if (dynamic_cast<FetchFileJob*>(job) != NULL) {
|
||||
FetchFileJob* fetchJob = (FetchFileJob*)job;
|
||||
@@ -390,7 +390,7 @@ BPackageManager::JobProgress(BJob* job)
|
||||
|
||||
|
||||
void
|
||||
BPackageManager::JobSucceeded(BJob* job)
|
||||
BPackageManager::JobSucceeded(BSupportKit::BJob* job)
|
||||
{
|
||||
if (dynamic_cast<FetchFileJob*>(job) != NULL) {
|
||||
FetchFileJob* fetchJob = (FetchFileJob*)job;
|
||||
|
||||
@@ -29,6 +29,8 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
DataPositionIOWrapper.cpp
|
||||
DateTime.cpp
|
||||
Flattenable.cpp
|
||||
Job.cpp
|
||||
JobQueue.cpp
|
||||
List.cpp
|
||||
Locker.cpp
|
||||
PointerList.cpp
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Oliver Tappe <[email protected]>
|
||||
* Rene Gollent <[email protected]>
|
||||
*/
|
||||
|
||||
|
||||
#include <Job.h>
|
||||
|
||||
#include <Errors.h>
|
||||
|
||||
|
||||
namespace BSupportKit {
|
||||
|
||||
|
||||
BJobStateListener::~BJobStateListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJobStateListener::JobStarted(BJob* job)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJobStateListener::JobProgress(BJob* job)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJobStateListener::JobSucceeded(BJob* job)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJobStateListener::JobFailed(BJob* job)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJobStateListener::JobAborted(BJob* job)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
BJob::BJob(const BString& title)
|
||||
:
|
||||
fTitle(title),
|
||||
fState(B_JOB_STATE_WAITING_TO_RUN),
|
||||
fTicketNumber(0xFFFFFFFFUL)
|
||||
{
|
||||
if (fTitle.Length() == 0)
|
||||
fInitStatus = B_BAD_VALUE;
|
||||
else
|
||||
fInitStatus = B_OK;
|
||||
}
|
||||
|
||||
|
||||
BJob::~BJob()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::InitCheck() const
|
||||
{
|
||||
return fInitStatus;
|
||||
}
|
||||
|
||||
|
||||
const BString&
|
||||
BJob::Title() const
|
||||
{
|
||||
return fTitle;
|
||||
}
|
||||
|
||||
|
||||
BJobState
|
||||
BJob::State() const
|
||||
{
|
||||
return fState;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::Result() const
|
||||
{
|
||||
return fResult;
|
||||
}
|
||||
|
||||
|
||||
const BString&
|
||||
BJob::ErrorString() const
|
||||
{
|
||||
return fErrorString;
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
BJob::TicketNumber() const
|
||||
{
|
||||
return fTicketNumber;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJob::_SetTicketNumber(uint32 ticketNumber)
|
||||
{
|
||||
fTicketNumber = ticketNumber;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJob::_ClearTicketNumber()
|
||||
{
|
||||
fTicketNumber = 0xFFFFFFFFUL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJob::SetErrorString(const BString& error)
|
||||
{
|
||||
fErrorString = error;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::Run()
|
||||
{
|
||||
if (fState != B_JOB_STATE_WAITING_TO_RUN)
|
||||
return B_NOT_ALLOWED;
|
||||
|
||||
fState = B_JOB_STATE_STARTED;
|
||||
NotifyStateListeners();
|
||||
|
||||
fState = B_JOB_STATE_IN_PROGRESS;
|
||||
fResult = Execute();
|
||||
Cleanup(fResult);
|
||||
|
||||
fState = fResult == B_OK
|
||||
? B_JOB_STATE_SUCCEEDED
|
||||
: fResult == B_CANCELED
|
||||
? B_JOB_STATE_ABORTED
|
||||
: B_JOB_STATE_FAILED;
|
||||
NotifyStateListeners();
|
||||
|
||||
return fResult;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJob::Cleanup(status_t /*jobResult*/)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::AddStateListener(BJobStateListener* listener)
|
||||
{
|
||||
return fStateListeners.AddItem(listener) ? B_OK : B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::RemoveStateListener(BJobStateListener* listener)
|
||||
{
|
||||
return fStateListeners.RemoveItem(listener) ? B_OK : B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::AddDependency(BJob* job)
|
||||
{
|
||||
if (fDependencies.HasItem(job))
|
||||
return B_ERROR;
|
||||
|
||||
if (fDependencies.AddItem(job) && job->fDependantJobs.AddItem(this))
|
||||
return B_OK;
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BJob::RemoveDependency(BJob* job)
|
||||
{
|
||||
if (!fDependencies.HasItem(job))
|
||||
return B_ERROR;
|
||||
|
||||
if (fDependencies.RemoveItem(job) && job->fDependantJobs.RemoveItem(this))
|
||||
return B_OK;
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BJob::IsRunnable() const
|
||||
{
|
||||
return fDependencies.IsEmpty();
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BJob::CountDependencies() const
|
||||
{
|
||||
return fDependencies.CountItems();
|
||||
}
|
||||
|
||||
|
||||
BJob*
|
||||
BJob::DependantJobAt(int32 index) const
|
||||
{
|
||||
return fDependantJobs.ItemAt(index);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BJob::NotifyStateListeners()
|
||||
{
|
||||
int32 count = fStateListeners.CountItems();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
BJobStateListener* listener = fStateListeners.ItemAt(i);
|
||||
if (listener == NULL)
|
||||
continue;
|
||||
switch (fState) {
|
||||
case B_JOB_STATE_STARTED:
|
||||
listener->JobStarted(this);
|
||||
break;
|
||||
case B_JOB_STATE_IN_PROGRESS:
|
||||
listener->JobProgress(this);
|
||||
break;
|
||||
case B_JOB_STATE_SUCCEEDED:
|
||||
listener->JobSucceeded(this);
|
||||
break;
|
||||
case B_JOB_STATE_FAILED:
|
||||
listener->JobFailed(this);
|
||||
break;
|
||||
case B_JOB_STATE_ABORTED:
|
||||
listener->JobAborted(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPackageKit
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -7,16 +7,17 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <package/JobQueue.h>
|
||||
#include <JobQueue.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
#include <Autolock.h>
|
||||
#include <Job.h>
|
||||
|
||||
#include <package/Job.h>
|
||||
#include <JobPrivate.h>
|
||||
|
||||
|
||||
namespace BPackageKit {
|
||||
namespace BSupportKit {
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
@@ -26,11 +27,11 @@ struct JobQueue::JobPriorityLess {
|
||||
};
|
||||
|
||||
|
||||
// sort jobs by:
|
||||
// 1. descending count of dependencies (only jobs without dependencies are
|
||||
// runnable)
|
||||
// 2. job ticket number (order in which jobs were added to the queue)
|
||||
//
|
||||
/*! Sort jobs by:
|
||||
1. descending count of dependencies (only jobs without dependencies are
|
||||
runnable)
|
||||
2. job ticket number (order in which jobs were added to the queue)
|
||||
*/
|
||||
bool
|
||||
JobQueue::JobPriorityLess::operator()(const BJob* left, const BJob* right) const
|
||||
{
|
||||
@@ -86,7 +87,7 @@ JobQueue::AddJob(BJob* job)
|
||||
} catch (...) {
|
||||
return B_ERROR;
|
||||
}
|
||||
job->_SetTicketNumber(fNextTicketNumber++);
|
||||
BJob::Private(*job).SetTicketNumber(fNextTicketNumber++);
|
||||
job->AddStateListener(this);
|
||||
}
|
||||
|
||||
@@ -108,7 +109,7 @@ JobQueue::RemoveJob(BJob* job)
|
||||
} catch (...) {
|
||||
return B_ERROR;
|
||||
}
|
||||
job->_ClearTicketNumber();
|
||||
BJob::Private(*job).ClearTicketNumber();
|
||||
job->RemoveStateListener(this);
|
||||
}
|
||||
|
||||
@@ -363,14 +363,14 @@ PackageManager::ProgressApplyingChangesDone(InstalledRepository& repository)
|
||||
|
||||
|
||||
void
|
||||
PackageManager::JobFailed(BJob* job)
|
||||
PackageManager::JobFailed(BSupportKit::BJob* job)
|
||||
{
|
||||
// TODO:...
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageManager::JobAborted(BJob* job)
|
||||
PackageManager::JobAborted(BSupportKit::BJob* job)
|
||||
{
|
||||
// TODO:...
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
|
||||
using BPackageKit::BCommitTransactionResult;
|
||||
using BPackageKit::BContext;
|
||||
using BPackageKit::BJob;
|
||||
using BPackageKit::BJobStateListener;
|
||||
using BPackageKit::BPackageInstallationLocation;
|
||||
using BPackageKit::BRepositoryConfig;
|
||||
using BPackageKit::BSolverPackage;
|
||||
using BSupportKit::BJob;
|
||||
using BSupportKit::BJobStateListener;
|
||||
|
||||
using BPackageKit::BPrivate::BDaemonClient;
|
||||
using BPackageKit::BManager::BPrivate::BPackageManager;
|
||||
@@ -84,8 +84,8 @@ private:
|
||||
|
||||
private:
|
||||
// BJobStateListener
|
||||
virtual void JobFailed(BJob* job);
|
||||
virtual void JobAborted(BJob* job);
|
||||
virtual void JobFailed(BSupportKit::BJob* job);
|
||||
virtual void JobAborted(BSupportKit::BJob* job);
|
||||
|
||||
private:
|
||||
typedef std::set<BSolverPackage*> SolverPackageSet;
|
||||
|
||||
Reference in New Issue
Block a user