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-21 21:37:01 +02:00
parent 5f9f1ac662
commit e711e6e42f
35 changed files with 519 additions and 399 deletions
+2 -2
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;
+10 -5
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;
+3 -77
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;
};
@@ -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();
+13 -8
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
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_