From e711e6e42fd7ec3111ba9dc2324fa8efedd6674b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 18 May 2015 18:21:58 +0200 Subject: [PATCH] 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. --- headers/build/os/support/Job.h | 1 + headers/build/private/package/JobQueue.h | 1 - headers/build/private/support/JobPrivate.h | 1 + headers/build/private/support/JobQueue.h | 1 + headers/os/package/AddRepositoryRequest.h | 4 +- headers/os/package/Context.h | 15 +- headers/os/package/Job.h | 80 +----- headers/os/package/RefreshRepositoryRequest.h | 4 +- headers/os/package/Request.h | 21 +- headers/os/support/Job.h | 106 +++++++ .../private/package/manager/PackageManager.h | 10 +- headers/private/support/JobPrivate.h | 41 +++ .../private/{package => support}/JobQueue.h | 14 +- .../haikudepot/model/JobStateListener.cpp | 2 +- src/apps/haikudepot/model/JobStateListener.h | 12 +- src/bin/pkgman/JobStateListener.cpp | 2 +- src/bin/pkgman/JobStateListener.h | 12 +- src/bin/pkgman/PackageManager.cpp | 4 +- src/bin/pkgman/PackageManager.h | 4 +- src/build/libbe/support/Jamfile | 2 + src/build/libpackage/Jamfile | 1 - .../package/ActivateRepositoryConfigJob.cpp | 4 +- src/kits/package/AddRepositoryRequest.cpp | 6 +- src/kits/package/Context.cpp | 6 +- src/kits/package/DropRepositoryRequest.cpp | 4 +- src/kits/package/Jamfile | 1 - src/kits/package/Job.cpp | 236 +--------------- src/kits/package/RefreshRepositoryRequest.cpp | 7 +- src/kits/package/Request.cpp | 13 +- src/kits/package/manager/PackageManager.cpp | 6 +- src/kits/support/Jamfile | 2 + src/kits/support/Job.cpp | 260 ++++++++++++++++++ src/kits/{package => support}/JobQueue.cpp | 23 +- src/servers/package/PackageManager.cpp | 4 +- src/servers/package/PackageManager.h | 8 +- 35 files changed, 519 insertions(+), 399 deletions(-) create mode 100644 headers/build/os/support/Job.h delete mode 100644 headers/build/private/package/JobQueue.h create mode 100644 headers/build/private/support/JobPrivate.h create mode 100644 headers/build/private/support/JobQueue.h create mode 100644 headers/os/support/Job.h create mode 100644 headers/private/support/JobPrivate.h rename headers/private/{package => support}/JobQueue.h (80%) create mode 100644 src/kits/support/Job.cpp rename src/kits/{package => support}/JobQueue.cpp (90%) diff --git a/headers/build/os/support/Job.h b/headers/build/os/support/Job.h new file mode 100644 index 0000000000..07205e792e --- /dev/null +++ b/headers/build/os/support/Job.h @@ -0,0 +1 @@ +#include <../os/support/Job.h> diff --git a/headers/build/private/package/JobQueue.h b/headers/build/private/package/JobQueue.h deleted file mode 100644 index 0a19a4dff0..0000000000 --- a/headers/build/private/package/JobQueue.h +++ /dev/null @@ -1 +0,0 @@ -#include <../private/package/JobQueue.h> diff --git a/headers/build/private/support/JobPrivate.h b/headers/build/private/support/JobPrivate.h new file mode 100644 index 0000000000..ef0c703801 --- /dev/null +++ b/headers/build/private/support/JobPrivate.h @@ -0,0 +1 @@ +#include <../private/support/JobPrivate.h> diff --git a/headers/build/private/support/JobQueue.h b/headers/build/private/support/JobQueue.h new file mode 100644 index 0000000000..668d16abe9 --- /dev/null +++ b/headers/build/private/support/JobQueue.h @@ -0,0 +1 @@ +#include <../private/support/JobQueue.h> diff --git a/headers/os/package/AddRepositoryRequest.h b/headers/os/package/AddRepositoryRequest.h index 0697fa400a..be067d4f13 100644 --- a/headers/os/package/AddRepositoryRequest.h +++ b/headers/os/package/AddRepositoryRequest.h @@ -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; diff --git a/headers/os/package/Context.h b/headers/os/package/Context.h index c5d5244a28..effe09cce0 100644 --- a/headers/os/package/Context.h +++ b/headers/os/package/Context.h @@ -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 +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; diff --git a/headers/os/package/Job.h b/headers/os/package/Job.h index d07e3aa18e..430c6e5849 100644 --- a/headers/os/package/Job.h +++ b/headers/os/package/Job.h @@ -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 -#include +#include 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 JobList; - JobList fDependencies; - JobList fDependantJobs; - - typedef BObjectList StateListenerList; - StateListenerList fStateListeners; }; diff --git a/headers/os/package/RefreshRepositoryRequest.h b/headers/os/package/RefreshRepositoryRequest.h index a03fb8b387..f55f36698c 100644 --- a/headers/os/package/RefreshRepositoryRequest.h +++ b/headers/os/package/RefreshRepositoryRequest.h @@ -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(); diff --git a/headers/os/package/Request.h b/headers/os/package/Request.h index 4bdd917371..a0ba7353ca 100644 --- a/headers/os/package/Request.h +++ b/headers/os/package/Request.h @@ -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 +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; }; diff --git a/headers/os/support/Job.h b/headers/os/support/Job.h new file mode 100644 index 0000000000..3f5e752c17 --- /dev/null +++ b/headers/os/support/Job.h @@ -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 +#include + + +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 JobList; + JobList fDependencies; + JobList fDependantJobs; + + typedef BObjectList StateListenerList; + StateListenerList fStateListeners; +}; + + +} // namespace BSupportKit + + +#endif // _SUPPORT_JOB_H_ diff --git a/headers/private/package/manager/PackageManager.h b/headers/private/package/manager/PackageManager.h index c280fe4ff9..e761151005 100644 --- a/headers/private/package/manager/PackageManager.h +++ b/headers/private/package/manager/PackageManager.h @@ -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(); diff --git a/headers/private/support/JobPrivate.h b/headers/private/support/JobPrivate.h new file mode 100644 index 0000000000..8e9ae814d0 --- /dev/null +++ b/headers/private/support/JobPrivate.h @@ -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 + + +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_ diff --git a/headers/private/package/JobQueue.h b/headers/private/support/JobQueue.h similarity index 80% rename from headers/private/package/JobQueue.h rename to headers/private/support/JobQueue.h index 99cb6d4ebe..6a5efbfb57 100644 --- a/headers/private/package/JobQueue.h +++ b/headers/private/support/JobQueue.h @@ -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 #include -#include +#include -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_ diff --git a/src/apps/haikudepot/model/JobStateListener.cpp b/src/apps/haikudepot/model/JobStateListener.cpp index e200c8a55c..41381e7f9e 100644 --- a/src/apps/haikudepot/model/JobStateListener.cpp +++ b/src/apps/haikudepot/model/JobStateListener.cpp @@ -8,7 +8,7 @@ #include "JobStateListener.h" -using BPackageKit::BJob; +using BSupportKit::BJob; JobStateListener::JobStateListener() diff --git a/src/apps/haikudepot/model/JobStateListener.h b/src/apps/haikudepot/model/JobStateListener.h index 8914adcdda..427d1f4885 100644 --- a/src/apps/haikudepot/model/JobStateListener.h +++ b/src/apps/haikudepot/model/JobStateListener.h @@ -7,17 +7,17 @@ #define JOB_STATE_LISTENER_H -#include +#include -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); }; diff --git a/src/bin/pkgman/JobStateListener.cpp b/src/bin/pkgman/JobStateListener.cpp index 1f27001835..3b35a615af 100644 --- a/src/bin/pkgman/JobStateListener.cpp +++ b/src/bin/pkgman/JobStateListener.cpp @@ -10,7 +10,7 @@ #include "pkgman.h" -using BPackageKit::BJob; +using BSupportKit::BJob; JobStateListener::JobStateListener(uint32 flags) diff --git a/src/bin/pkgman/JobStateListener.h b/src/bin/pkgman/JobStateListener.h index 9ff8c5340e..155c00c83d 100644 --- a/src/bin/pkgman/JobStateListener.h +++ b/src/bin/pkgman/JobStateListener.h @@ -6,10 +6,10 @@ #define JOB_STATE_LISTENER_H -#include +#include -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; diff --git a/src/bin/pkgman/PackageManager.cpp b/src/bin/pkgman/PackageManager.cpp index f8fd1ea6a4..470720889a 100644 --- a/src/bin/pkgman/PackageManager.cpp +++ b/src/bin/pkgman/PackageManager.cpp @@ -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"); } diff --git a/src/bin/pkgman/PackageManager.h b/src/bin/pkgman/PackageManager.h index 475947b9f9..fad711d084 100644 --- a/src/bin/pkgman/PackageManager.h +++ b/src/bin/pkgman/PackageManager.h @@ -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 diff --git a/src/build/libbe/support/Jamfile b/src/build/libbe/support/Jamfile index 0b8bdad86a..7892cb0788 100644 --- a/src/build/libbe/support/Jamfile +++ b/src/build/libbe/support/Jamfile @@ -14,6 +14,8 @@ BuildPlatformMergeObjectPIC support_kit.o : DataIO.cpp DataPositionIOWrapper.cpp Flattenable.cpp + Job.cpp + JobQueue.cpp List.cpp Locker.cpp PointerList.cpp diff --git a/src/build/libpackage/Jamfile b/src/build/libpackage/Jamfile index 73a4d08157..fa1b4e2fa9 100644 --- a/src/build/libpackage/Jamfile +++ b/src/build/libpackage/Jamfile @@ -99,7 +99,6 @@ BuildPlatformSharedLibrary libpackage_build.so FetchFileJob.cpp InstallationLocationInfo.cpp Job.cpp - JobQueue.cpp PackageInfo.cpp PackageInfoContentHandler.cpp PackageInfoParser.cpp diff --git a/src/kits/package/ActivateRepositoryConfigJob.cpp b/src/kits/package/ActivateRepositoryConfigJob.cpp index 07cdbabe0e..a1aadb4a8b 100644 --- a/src/kits/package/ActivateRepositoryConfigJob.cpp +++ b/src/kits/package/ActivateRepositoryConfigJob.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(); } diff --git a/src/kits/package/AddRepositoryRequest.cpp b/src/kits/package/AddRepositoryRequest.cpp index 8c30d6c75b..05df47e703 100644 --- a/src/kits/package/AddRepositoryRequest.cpp +++ b/src/kits/package/AddRepositoryRequest.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: @@ -10,11 +10,11 @@ #include #include +#include #include #include #include -#include #include @@ -88,7 +88,7 @@ AddRepositoryRequest::CreateInitialJobs() void -AddRepositoryRequest::JobSucceeded(BJob* job) +AddRepositoryRequest::JobSucceeded(BSupportKit::BJob* job) { if (job == fActivateJob) fRepositoryName = fActivateJob->RepositoryName(); diff --git a/src/kits/package/Context.cpp b/src/kits/package/Context.cpp index 4b1f7c4974..a5e212c674 100644 --- a/src/kits/package/Context.cpp +++ b/src/kits/package/Context.cpp @@ -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; diff --git a/src/kits/package/DropRepositoryRequest.cpp b/src/kits/package/DropRepositoryRequest.cpp index c4dba669c5..ea54d8626b 100644 --- a/src/kits/package/DropRepositoryRequest.cpp +++ b/src/kits/package/DropRepositoryRequest.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: @@ -10,10 +10,10 @@ #include #include +#include #include #include -#include namespace BPackageKit { diff --git a/src/kits/package/Jamfile b/src/kits/package/Jamfile index bdac6e15d8..787baf6518 100644 --- a/src/kits/package/Jamfile +++ b/src/kits/package/Jamfile @@ -88,7 +88,6 @@ for architectureObject in [ MultiArchSubDirSetup ] { InitTerminateLibPackage.cpp InstallationLocationInfo.cpp Job.cpp - JobQueue.cpp PackageInfo.cpp PackageInfoContentHandler.cpp PackageInfoParser.cpp diff --git a/src/kits/package/Job.cpp b/src/kits/package/Job.cpp index 9ce81f577e..7622b76fc0 100644 --- a/src/kits/package/Job.cpp +++ b/src/kits/package/Job.cpp @@ -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 -#include - -#include - 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 diff --git a/src/kits/package/RefreshRepositoryRequest.cpp b/src/kits/package/RefreshRepositoryRequest.cpp index 58f7a3d74c..b5560659ef 100644 --- a/src/kits/package/RefreshRepositoryRequest.cpp +++ b/src/kits/package/RefreshRepositoryRequest.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: @@ -12,11 +12,12 @@ #include #include +#include + #include #include #include #include -#include #include #include #include @@ -96,7 +97,7 @@ BRefreshRepositoryRequest::CreateInitialJobs() void -BRefreshRepositoryRequest::JobSucceeded(BJob* job) +BRefreshRepositoryRequest::JobSucceeded(BSupportKit::BJob* job) { if (job == fValidateChecksumJob && !fValidateChecksumJob->ChecksumsMatch()) { diff --git a/src/kits/package/Request.cpp b/src/kits/package/Request.cpp index c6dd86ecdb..07a68bc2b7 100644 --- a/src/kits/package/Request.cpp +++ b/src/kits/package/Request.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: @@ -11,14 +11,15 @@ #include +#include + #include -#include 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; diff --git a/src/kits/package/manager/PackageManager.cpp b/src/kits/package/manager/PackageManager.cpp index 37d233963f..901b856233 100644 --- a/src/kits/package/manager/PackageManager.cpp +++ b/src/kits/package/manager/PackageManager.cpp @@ -364,7 +364,7 @@ BPackageManager::InstallationRepository() void -BPackageManager::JobStarted(BJob* job) +BPackageManager::JobStarted(BSupportKit::BJob* job) { if (dynamic_cast(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(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(job) != NULL) { FetchFileJob* fetchJob = (FetchFileJob*)job; diff --git a/src/kits/support/Jamfile b/src/kits/support/Jamfile index 76b3d5e030..39f536c654 100644 --- a/src/kits/support/Jamfile +++ b/src/kits/support/Jamfile @@ -29,6 +29,8 @@ for architectureObject in [ MultiArchSubDirSetup ] { DataPositionIOWrapper.cpp DateTime.cpp Flattenable.cpp + Job.cpp + JobQueue.cpp List.cpp Locker.cpp PointerList.cpp diff --git a/src/kits/support/Job.cpp b/src/kits/support/Job.cpp new file mode 100644 index 0000000000..d9f2b21c02 --- /dev/null +++ b/src/kits/support/Job.cpp @@ -0,0 +1,260 @@ +/* + * Copyright 2011-2015, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Tappe + * Rene Gollent + */ + + +#include + +#include + + +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 diff --git a/src/kits/package/JobQueue.cpp b/src/kits/support/JobQueue.cpp similarity index 90% rename from src/kits/package/JobQueue.cpp rename to src/kits/support/JobQueue.cpp index 4726e88b1d..04b4624bc7 100644 --- a/src/kits/package/JobQueue.cpp +++ b/src/kits/support/JobQueue.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: @@ -7,16 +7,17 @@ */ -#include +#include #include #include +#include -#include +#include -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); } diff --git a/src/servers/package/PackageManager.cpp b/src/servers/package/PackageManager.cpp index 8799aa203b..adaffff756 100644 --- a/src/servers/package/PackageManager.cpp +++ b/src/servers/package/PackageManager.cpp @@ -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:... } diff --git a/src/servers/package/PackageManager.h b/src/servers/package/PackageManager.h index 56f3a44206..123890d48b 100644 --- a/src/servers/package/PackageManager.h +++ b/src/servers/package/PackageManager.h @@ -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 SolverPackageSet;