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:
Axel Dörfler 2015-05-18 18:21:58 +02:00
parent 5f9f1ac662
commit e711e6e42f
35 changed files with 519 additions and 399 deletions

View File

@ -0,0 +1 @@
#include <../os/support/Job.h>

View File

@ -1 +0,0 @@
#include <../private/package/JobQueue.h>

View File

@ -0,0 +1 @@
#include <../private/support/JobPrivate.h>

View File

@ -0,0 +1 @@
#include <../private/support/JobQueue.h>

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011, Haiku, Inc.
* Copyright 2011-2015, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__ADD_REPOSITORY_REQUEST_H_
@ -36,7 +36,7 @@ public:
protected:
// BJobStateListener
virtual void JobSucceeded(BJob* job);
virtual void JobSucceeded(BSupportKit::BJob* job);
private:
BString fRepositoryBaseURL;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011, Haiku, Inc.
* Copyright 2011-2015, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__CONTEXT_H_
@ -10,10 +10,14 @@
#include <String.h>
namespace BSupportKit {
class BJobStateListener;
}
namespace BPackageKit {
class BJobStateListener;
namespace BPrivate {
class TempfileManager;
}
@ -37,7 +41,8 @@ struct BDecisionProvider {
class BContext {
public:
BContext(BDecisionProvider& decisionProvider,
BJobStateListener& jobStateListener);
BSupportKit::BJobStateListener&
jobStateListener);
~BContext();
status_t InitCheck() const;
@ -46,13 +51,13 @@ public:
BEntry* entry) const;
BDecisionProvider& DecisionProvider() const;
BJobStateListener& JobStateListener() const;
BSupportKit::BJobStateListener& JobStateListener() const;
private:
status_t _Initialize();
BDecisionProvider& fDecisionProvider;
BJobStateListener& fJobStateListener;
BSupportKit::BJobStateListener& fJobStateListener;
status_t fInitStatus;
mutable BPrivate::TempfileManager* fTempfileManager;

View File

@ -1,42 +1,18 @@
/*
* Copyright 2011-2013, Haiku, Inc.
* Copyright 2011-2015, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__JOB_H_
#define _PACKAGE__JOB_H_
#include <ObjectList.h>
#include <String.h>
#include <support/Job.h>
namespace BPackageKit {
class BContext;
class BJob;
struct BJobStateListener {
virtual ~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);
};
enum BJobState {
JOB_STATE_WAITING_TO_RUN,
JOB_STATE_STARTED,
JOB_STATE_IN_PROGRESS,
JOB_STATE_SUCCEEDED,
JOB_STATE_FAILED,
JOB_STATE_ABORTED,
};
namespace BPrivate {
@ -44,64 +20,14 @@ namespace BPrivate {
}
class BJob {
class BJob : public BSupportKit::BJob {
public:
BJob(const BContext& context,
const BString& title);
virtual ~BJob();
status_t InitCheck() const;
virtual status_t Run();
const BString& Title() const;
BJobState State() const;
status_t Result() const;
const BString& ErrorString() const;
uint32 TicketNumber() const;
status_t AddStateListener(BJobStateListener* listener);
status_t RemoveStateListener(
BJobStateListener* listener);
bool IsRunnable() const;
status_t AddDependency(BJob* job);
status_t RemoveDependency(BJob* job);
int32 CountDependencies() const;
BJob* DependantJobAt(int32 index) const;
protected:
virtual status_t Execute() = 0;
virtual void Cleanup(status_t jobResult);
void SetErrorString(const BString&);
void NotifyStateListeners();
const BContext& fContext;
private:
friend class BPrivate::JobQueue;
void _SetTicketNumber(uint32 ticketNumber);
void _ClearTicketNumber();
private:
status_t fInitStatus;
BString fTitle;
BJobState fState;
status_t fResult;
BString fErrorString;
uint32 fTicketNumber;
typedef BObjectList<BJob> JobList;
JobList fDependencies;
JobList fDependantJobs;
typedef BObjectList<BJobStateListener> StateListenerList;
StateListenerList fStateListeners;
};

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011, Haiku, Inc.
* Copyright 2011-2015, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__REFRESH_REPOSITORY_REQUEST_H_
@ -36,7 +36,7 @@ public:
protected:
// BJobStateListener
virtual void JobSucceeded(BJob* job);
virtual void JobSucceeded(BSupportKit::BJob* job);
private:
status_t _FetchRepositoryCache();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011, Haiku, Inc.
* Copyright 2011-2015, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__REQUEST_H_
@ -11,16 +11,20 @@
#include <package/Job.h>
namespace BSupportKit {
namespace BPrivate {
class JobQueue;
}
}
namespace BPackageKit {
class BContext;
namespace BPrivate {
class JobQueue;
}
class BRequest : protected BJobStateListener {
class BRequest : protected BSupportKit::BJobStateListener {
public:
BRequest(const BContext& context);
virtual ~BRequest();
@ -29,18 +33,19 @@ public:
virtual status_t CreateInitialJobs() = 0;
BJob* PopRunnableJob();
BSupportKit::BJob* PopRunnableJob();
status_t Process(bool failIfCanceledOnly = false);
protected:
status_t QueueJob(BJob* job);
status_t QueueJob(BSupportKit::BJob* job);
const BContext& fContext;
protected:
status_t fInitStatus;
BPrivate::JobQueue* fJobQueue;
BSupportKit::BPrivate::JobQueue*
fJobQueue;
};

106
headers/os/support/Job.h Normal file
View File

@ -0,0 +1,106 @@
/*
* Copyright 2011-2015, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _SUPPORT_JOB_H_
#define _SUPPORT_JOB_H_
#include <ObjectList.h>
#include <String.h>
namespace BSupportKit {
class BJob;
struct BJobStateListener {
virtual ~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);
};
enum BJobState {
B_JOB_STATE_WAITING_TO_RUN,
B_JOB_STATE_STARTED,
B_JOB_STATE_IN_PROGRESS,
B_JOB_STATE_SUCCEEDED,
B_JOB_STATE_FAILED,
B_JOB_STATE_ABORTED,
};
class BJob {
public:
BJob(const BString& title);
virtual ~BJob();
status_t InitCheck() const;
virtual status_t Run();
const BString& Title() const;
BJobState State() const;
status_t Result() const;
const BString& ErrorString() const;
uint32 TicketNumber() const;
status_t AddStateListener(BJobStateListener* listener);
status_t RemoveStateListener(
BJobStateListener* listener);
bool IsRunnable() const;
status_t AddDependency(BJob* job);
status_t RemoveDependency(BJob* job);
int32 CountDependencies() const;
BJob* DependantJobAt(int32 index) const;
class Private;
protected:
virtual status_t Execute() = 0;
virtual void Cleanup(status_t jobResult);
void SetErrorString(const BString&);
void NotifyStateListeners();
private:
friend class Private;
void _SetTicketNumber(uint32 ticketNumber);
void _ClearTicketNumber();
private:
status_t fInitStatus;
BString fTitle;
BJobState fState;
status_t fResult;
BString fErrorString;
uint32 fTicketNumber;
typedef BObjectList<BJob> JobList;
JobList fDependencies;
JobList fDependantJobs;
typedef BObjectList<BJobStateListener> StateListenerList;
StateListenerList fStateListeners;
};
} // namespace BSupportKit
#endif // _SUPPORT_JOB_H_

View File

@ -29,7 +29,7 @@
namespace BPackageKit {
class BCommitTransactionResult;
@ -42,7 +42,7 @@ using BPackageKit::BPrivate::BActivationTransaction;
using BPackageKit::BPrivate::BDaemonClient;
class BPackageManager : protected BJobStateListener {
class BPackageManager : protected BSupportKit::BJobStateListener {
public:
class RemoteRepository;
class LocalRepository;
@ -118,9 +118,9 @@ protected:
protected:
// BJobStateListener
virtual void JobStarted(BJob* job);
virtual void JobProgress(BJob* job);
virtual void JobSucceeded(BJob* job);
virtual void JobStarted(BSupportKit::BJob* job);
virtual void JobProgress(BSupportKit::BJob* job);
virtual void JobSucceeded(BSupportKit::BJob* job);
private:
void _HandleProblems();

View File

@ -0,0 +1,41 @@
/*
* Copyright 2015, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _JOB_PRIVATE_H_
#define _JOB_PRIVATE_H_
#include <Job.h>
namespace BSupportKit {
class BJob::Private {
public:
Private(BJob& job)
:
fJob(job)
{
}
void SetTicketNumber(uint32 ticketNumber)
{
fJob._SetTicketNumber(ticketNumber);
}
void ClearTicketNumber()
{
fJob._ClearTicketNumber();
}
private:
BJob& fJob;
};
} // namespace BSupportKit
#endif // _JOB_PRIVATE_H_

View File

@ -1,18 +1,18 @@
/*
* Copyright 2011, Haiku, Inc.
* Copyright 2011-2015, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__PRIVATE__JOB_QUEUE_H_
#define _PACKAGE__PRIVATE__JOB_QUEUE_H_
#ifndef _SUPPORT_PRIVATE_JOB_QUEUE_H_
#define _SUPPORT_PRIVATE_JOB_QUEUE_H_
#include <Locker.h>
#include <SupportDefs.h>
#include <package/Job.h>
#include <Job.h>
namespace BPackageKit {
namespace BSupportKit {
namespace BPrivate {
@ -60,7 +60,7 @@ private:
} // namespace BPrivate
} // namespace BPackageKit
} // namespace BSupportKit
#endif // _PACKAGE__PRIVATE__JOB_QUEUE_H_
#endif // _SUPPORT_PRIVATE_JOB_QUEUE_H_

View File

@ -8,7 +8,7 @@
#include "JobStateListener.h"
using BPackageKit::BJob;
using BSupportKit::BJob;
JobStateListener::JobStateListener()

View File

@ -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);
};

View File

@ -10,7 +10,7 @@
#include "pkgman.h"
using BPackageKit::BJob;
using BSupportKit::BJob;
JobStateListener::JobStateListener(uint32 flags)

View File

@ -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;

View File

@ -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");
}

View File

@ -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

View File

@ -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

View File

@ -99,7 +99,6 @@ BuildPlatformSharedLibrary libpackage_build.so
FetchFileJob.cpp
InstallationLocationInfo.cpp
Job.cpp
JobQueue.cpp
PackageInfo.cpp
PackageInfoContentHandler.cpp
PackageInfoParser.cpp

View File

@ -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();
}

View File

@ -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();

View File

@ -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;

View File

@ -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 {

View File

@ -88,7 +88,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
InitTerminateLibPackage.cpp
InstallationLocationInfo.cpp
Job.cpp
JobQueue.cpp
PackageInfo.cpp
PackageInfoContentHandler.cpp
PackageInfoParser.cpp

View File

@ -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

View File

@ -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()) {

View File

@ -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;

View File

@ -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;

View File

@ -29,6 +29,8 @@ for architectureObject in [ MultiArchSubDirSetup ] {
DataPositionIOWrapper.cpp
DateTime.cpp
Flattenable.cpp
Job.cpp
JobQueue.cpp
List.cpp
Locker.cpp
PointerList.cpp

260
src/kits/support/Job.cpp Normal file
View File

@ -0,0 +1,260 @@
/*
* Copyright 2011-2015, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Oliver Tappe <zooey@hirschkaefer.de>
* Rene Gollent <rene@gollent.com>
*/
#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

View File

@ -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);
}

View File

@ -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:...
}

View File

@ -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;