From 7d7ed9bf4bdd7bc31e31143c402c4f96a324b30b Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Tue, 25 Jan 2011 17:07:27 +0000 Subject: [PATCH] Mostly style-related changes to package kit: * drop 'Haiku' namespace * rename 'Package' namespace to 'BPackageKit' * renamed all public classes to begin with a 'B' * renamed BPackageKit::Roster to BPackageKit::BPackageRoster to not clash with the BRoster from the application kit. * fix some instances of public headers including private ones Some functional changes, too: * JobQueue now removes and deletes dependants of failed jobs automatically * JobQueue supports waiting for jobs to become runnable * added a couple of InitCheck() methods where they make sense and invoke those in users of these classes git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40287 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/package/AddRepositoryRequest.h | 28 ++-- headers/os/package/Attributes.h | 28 ++-- headers/os/package/Context.h | 53 +++--- headers/os/package/Job.h | 76 +++++---- .../os/package/{Roster.h => PackageRoster.h} | 39 ++--- headers/os/package/RefreshRepositoryRequest.h | 36 ++--- headers/os/package/RepositoryCache.h | 22 ++- headers/os/package/RepositoryConfig.h | 28 ++-- headers/os/package/Request.h | 40 ++--- .../package/ActivateRepositoryCacheJob.h | 24 ++- .../package/ActivateRepositoryConfigJob.h | 24 ++- headers/private/package/ChecksumAccessors.h | 18 +-- headers/private/package/FetchFileJob.h | 24 ++- headers/private/package/JobQueue.h | 51 +++--- headers/private/package/TempfileManager.h | 18 +-- headers/private/package/ValidateChecksumJob.h | 24 ++- ...isionProvider.cpp => DecisionProvider.cpp} | 4 +- ...yDecisionProvider.h => DecisionProvider.h} | 8 +- src/bin/pkgman/Jamfile | 4 +- ...StateListener.cpp => JobStateListener.cpp} | 12 +- src/bin/pkgman/JobStateListener.h | 20 +++ src/bin/pkgman/MyJobStateListener.h | 20 --- src/bin/pkgman/command_add_repo.cpp | 32 ++-- src/bin/pkgman/command_list_repos.cpp | 8 +- src/bin/pkgman/command_refresh.cpp | 26 +-- .../package/ActivateRepositoryCacheJob.cpp | 14 +- .../package/ActivateRepositoryConfigJob.cpp | 23 ++- src/kits/package/AddRepositoryRequest.cpp | 30 ++-- src/kits/package/Attributes.cpp | 24 ++- src/kits/package/ChecksumAccessors.cpp | 12 +- src/kits/package/Context.cpp | 94 +++++++---- src/kits/package/FetchFileJob.cpp | 14 +- src/kits/package/Jamfile | 2 +- src/kits/package/Job.cpp | 89 ++++++---- src/kits/package/JobQueue.cpp | 152 ++++++++++++++---- .../package/{Roster.cpp => PackageRoster.cpp} | 44 +++-- src/kits/package/RefreshRepositoryRequest.cpp | 48 +++--- src/kits/package/RepositoryCache.cpp | 24 ++- src/kits/package/RepositoryConfig.cpp | 62 ++++--- src/kits/package/Request.cpp | 57 ++++--- src/kits/package/TempfileManager.cpp | 12 +- src/kits/package/ValidateChecksumJob.cpp | 14 +- src/tests/kits/package/make_repo.cpp | 4 +- 43 files changed, 746 insertions(+), 640 deletions(-) rename headers/os/package/{Roster.h => PackageRoster.h} (64%) rename src/bin/pkgman/{MyDecisionProvider.cpp => DecisionProvider.cpp} (91%) rename src/bin/pkgman/{MyDecisionProvider.h => DecisionProvider.h} (65%) rename src/bin/pkgman/{MyJobStateListener.cpp => JobStateListener.cpp} (66%) create mode 100644 src/bin/pkgman/JobStateListener.h delete mode 100644 src/bin/pkgman/MyJobStateListener.h rename src/kits/package/{Roster.cpp => PackageRoster.cpp} (77%) diff --git a/headers/os/package/AddRepositoryRequest.h b/headers/os/package/AddRepositoryRequest.h index fe038f5f45..0697fa400a 100644 --- a/headers/os/package/AddRepositoryRequest.h +++ b/headers/os/package/AddRepositoryRequest.h @@ -2,8 +2,8 @@ * Copyright 2011, Haiku, Inc. * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__ADD_REPOSITORY_REQUEST_H_ -#define _HAIKU__PACKAGE__ADD_REPOSITORY_REQUEST_H_ +#ifndef _PACKAGE__ADD_REPOSITORY_REQUEST_H_ +#define _PACKAGE__ADD_REPOSITORY_REQUEST_H_ #include @@ -12,22 +12,20 @@ #include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -namespace Private { +namespace BPrivate { class ActivateRepositoryConfigJob; } -using Private::ActivateRepositoryConfigJob; +using BPrivate::ActivateRepositoryConfigJob; -class AddRepositoryRequest : public Request { - typedef Request inherited; +class AddRepositoryRequest : public BRequest { + typedef BRequest inherited; public: - AddRepositoryRequest(const Context& context, + AddRepositoryRequest(const BContext& context, const BString& repositoryBaseURL, bool asUserRepository); virtual ~AddRepositoryRequest(); @@ -37,8 +35,8 @@ public: const BString& RepositoryName() const; protected: - // JobStateListener - virtual void JobSucceeded(Job* job); + // BJobStateListener + virtual void JobSucceeded(BJob* job); private: BString fRepositoryBaseURL; @@ -50,9 +48,7 @@ private: }; -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__ADD_REPOSITORY_REQUEST_H_ +#endif // _PACKAGE__ADD_REPOSITORY_REQUEST_H_ diff --git a/headers/os/package/Attributes.h b/headers/os/package/Attributes.h index c2e3359c63..0b5fe1c794 100644 --- a/headers/os/package/Attributes.h +++ b/headers/os/package/Attributes.h @@ -2,30 +2,26 @@ * Copyright 2011, Haiku, Inc. * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__ATTRIBUTES_H_ -#define _HAIKU__PACKAGE__ATTRIBUTES_H_ +#ifndef _PACKAGE__ATTRIBUTES_H_ +#define _PACKAGE__ATTRIBUTES_H_ -namespace Haiku { - -namespace Package { +namespace BPackageKit { // attributes used in package and as file attribute, too -extern const char* kNameAttribute; -extern const char* kVendorAttribute; -extern const char* kVersionAttribute; +extern const char* kPackageNameAttribute; +extern const char* kPackageVendorAttribute; +extern const char* kPackageVersionAttribute; // attributes kept local to packages -extern const char* kCopyrightAttribute; -extern const char* kLicenseAttribute; -extern const char* kProvidesAttribute; -extern const char* kRequiresAttribute; +extern const char* kPackageCopyrightAttribute; +extern const char* kPackageLicenseAttribute; +extern const char* kPackageProvidesAttribute; +extern const char* kPackageRequiresAttribute; -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__ATTRIBUTES_H_ +#endif // _PACKAGE__ATTRIBUTES_H_ diff --git a/headers/os/package/Context.h b/headers/os/package/Context.h index 4c5ace011c..e0d70da1ea 100644 --- a/headers/os/package/Context.h +++ b/headers/os/package/Context.h @@ -2,24 +2,25 @@ * Copyright 2011, Haiku, Inc. * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__CONTEXT_H_ -#define _HAIKU__PACKAGE__CONTEXT_H_ +#ifndef _PACKAGE__CONTEXT_H_ +#define _PACKAGE__CONTEXT_H_ -#include +#include +#include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -class JobStateListener; -using Private::TempfileManager; +class BJobStateListener; +namespace BPrivate { + class TempfileManager; +} -struct DecisionProvider { - virtual ~DecisionProvider(); +struct BDecisionProvider { + virtual ~BDecisionProvider(); virtual bool YesNoDecisionNeeded(const BString& description, const BString& question, @@ -33,28 +34,32 @@ struct DecisionProvider { }; -class Context { +class BContext { public: - Context(DecisionProvider& decisionProvider); - ~Context(); + BContext(BDecisionProvider& decisionProvider, + BJobStateListener& jobStateListener); + ~BContext(); - TempfileManager& GetTempfileManager() const; + status_t InitCheck() const; - JobStateListener* GetJobStateListener() const; - void SetJobStateListener(JobStateListener* listener); + status_t GetNewTempfile(const BString& baseName, + BEntry* entry) const; - DecisionProvider& GetDecisionProvider() const; + BDecisionProvider& DecisionProvider() const; + BJobStateListener& JobStateListener() const; private: - mutable TempfileManager fTempfileManager; - DecisionProvider& fDecisionProvider; - JobStateListener* fJobStateListener; + status_t _Initialize(); + + BDecisionProvider& fDecisionProvider; + BJobStateListener& fJobStateListener; + status_t fInitStatus; + + mutable BPrivate::TempfileManager* fTempfileManager; }; -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__CONTEXT_H_ +#endif // _PACKAGE__CONTEXT_H_ diff --git a/headers/os/package/Job.h b/headers/os/package/Job.h index 00b75be6f3..2a8983451f 100644 --- a/headers/os/package/Job.h +++ b/headers/os/package/Job.h @@ -2,35 +2,33 @@ * Copyright 2011, Haiku, Inc. * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__JOB_H_ -#define _HAIKU__PACKAGE__JOB_H_ +#ifndef _PACKAGE__JOB_H_ +#define _PACKAGE__JOB_H_ #include #include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -class Context; -class Job; +class BContext; +class BJob; -struct JobStateListener { - virtual ~JobStateListener(); +struct BJobStateListener { + virtual ~BJobStateListener(); // these default implementations do nothing - virtual void JobStarted(Job* job); - virtual void JobSucceeded(Job* job); - virtual void JobFailed(Job* job); - virtual void JobAborted(Job* job); + virtual void JobStarted(BJob* job); + virtual void JobSucceeded(BJob* job); + virtual void JobFailed(BJob* job); + virtual void JobAborted(BJob* job); }; -enum JobState { +enum BJobState { JOB_STATE_WAITING_TO_RUN, JOB_STATE_RUNNING, JOB_STATE_SUCCEEDED, @@ -39,30 +37,38 @@ enum JobState { }; -class Job { +namespace BPrivate { + class JobQueue; +} + + +class BJob { public: - Job(const Context& context, + BJob(const BContext& context, const BString& title); - virtual ~Job(); + virtual ~BJob(); status_t InitCheck() const; virtual status_t Run(); const BString& Title() const; - JobState State() const; + BJobState State() const; status_t Result() const; const BString& ErrorString() const; - status_t AddStateListener(JobStateListener* listener); - status_t RemoveStateListener( - JobStateListener* listener); + uint32 TicketNumber() const; - status_t AddDependency(Job* job); - status_t RemoveDependency(Job* job); + 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; - Job* DependantJobAt(int32 index) const; + BJob* DependantJobAt(int32 index) const; protected: virtual status_t Execute() = 0; virtual void Cleanup(status_t jobResult); @@ -71,27 +77,33 @@ protected: void NotifyStateListeners(); - const Context& fContext; + const BContext& fContext; + +private: + friend class BPrivate::JobQueue; + void _SetTicketNumber(uint32 ticketNumber); + void _ClearTicketNumber(); + private: status_t fInitStatus; BString fTitle; - JobState fState; + BJobState fState; status_t fResult; BString fErrorString; - typedef BObjectList JobList; + uint32 fTicketNumber; + + typedef BObjectList JobList; JobList fDependencies; JobList fDependantJobs; - typedef BObjectList StateListenerList; + typedef BObjectList StateListenerList; StateListenerList fStateListeners; }; -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__JOB_H_ +#endif // _PACKAGE__JOB_H_ diff --git a/headers/os/package/Roster.h b/headers/os/package/PackageRoster.h similarity index 64% rename from headers/os/package/Roster.h rename to headers/os/package/PackageRoster.h index 5834083598..f1b44b40e3 100644 --- a/headers/os/package/Roster.h +++ b/headers/os/package/PackageRoster.h @@ -2,26 +2,23 @@ * Copyright 2011, Haiku, Inc. * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__ROSTER_H_ -#define _HAIKU__PACKAGE__ROSTER_H_ +#ifndef _PACKAGE__ROSTER_H_ +#define _PACKAGE__ROSTER_H_ #include #include #include -#include template class BObjectList; -namespace Haiku { - -namespace Package { +namespace BPackageKit { -struct RepositoryConfigVisitor { - virtual ~RepositoryConfigVisitor() +struct BRepositoryConfigVisitor { + virtual ~BRepositoryConfigVisitor() { } @@ -29,14 +26,14 @@ struct RepositoryConfigVisitor { }; -class RepositoryCache; -class RepositoryConfig; +class BRepositoryCache; +class BRepositoryConfig; -class Roster { +class BPackageRoster { public: - Roster(); - ~Roster(); + BPackageRoster(); + ~BPackageRoster(); status_t GetCommonRepositoryCachePath(BPath* path, bool create = false) const; @@ -51,26 +48,24 @@ public: status_t GetRepositoryNames(BObjectList& names); status_t VisitCommonRepositoryConfigs( - RepositoryConfigVisitor& visitor); + BRepositoryConfigVisitor& visitor); status_t VisitUserRepositoryConfigs( - RepositoryConfigVisitor& visitor); + BRepositoryConfigVisitor& visitor); status_t GetRepositoryCache(const BString& name, - RepositoryCache* repositoryCache); + BRepositoryCache* repositoryCache); status_t GetRepositoryConfig(const BString& name, - RepositoryConfig* repositoryConfig); + BRepositoryConfig* repositoryConfig); private: status_t _GetRepositoryPath(BPath* path, bool create, directory_which whichDir) const; status_t _VisitRepositoryConfigs(const BPath& path, - RepositoryConfigVisitor& visitor); + BRepositoryConfigVisitor& visitor); }; -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__ROSTER_H_ +#endif // _PACKAGE__ROSTER_H_ diff --git a/headers/os/package/RefreshRepositoryRequest.h b/headers/os/package/RefreshRepositoryRequest.h index 8ff4c16414..a03fb8b387 100644 --- a/headers/os/package/RefreshRepositoryRequest.h +++ b/headers/os/package/RefreshRepositoryRequest.h @@ -2,8 +2,8 @@ * Copyright 2011, Haiku, Inc. * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__REFRESH_REPOSITORY_REQUEST_H_ -#define _HAIKU__PACKAGE__REFRESH_REPOSITORY_REQUEST_H_ +#ifndef _PACKAGE__REFRESH_REPOSITORY_REQUEST_H_ +#define _PACKAGE__REFRESH_REPOSITORY_REQUEST_H_ #include @@ -14,43 +14,41 @@ #include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -namespace Private { +namespace BPrivate { class ValidateChecksumJob; } -using Private::ValidateChecksumJob; +using BPrivate::ValidateChecksumJob; -class RefreshRepositoryRequest : public Request { - typedef Request inherited; + +class BRefreshRepositoryRequest : public BRequest { + typedef BRequest inherited; public: - RefreshRepositoryRequest(const Context& context, - const RepositoryConfig& repoConfig); - virtual ~RefreshRepositoryRequest(); + BRefreshRepositoryRequest( + const BContext& context, + const BRepositoryConfig& repoConfig); + virtual ~BRefreshRepositoryRequest(); virtual status_t CreateInitialJobs(); protected: - // JobStateListener - virtual void JobSucceeded(Job* job); + // BJobStateListener + virtual void JobSucceeded(BJob* job); private: status_t _FetchRepositoryCache(); BEntry fFetchedChecksumFile; - RepositoryConfig fRepoConfig; + BRepositoryConfig fRepoConfig; ValidateChecksumJob* fValidateChecksumJob; }; -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__REFRESH_REPOSITORY_REQUEST_H_ +#endif // _PACKAGE__REFRESH_REPOSITORY_REQUEST_H_ diff --git a/headers/os/package/RepositoryCache.h b/headers/os/package/RepositoryCache.h index f63a7d627a..6c40f54f29 100644 --- a/headers/os/package/RepositoryCache.h +++ b/headers/os/package/RepositoryCache.h @@ -2,8 +2,8 @@ * Copyright 2011, Haiku, Inc. * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__REPOSITORY_CACHE_H_ -#define _HAIKU__PACKAGE__REPOSITORY_CACHE_H_ +#ifndef _PACKAGE__REPOSITORY_CACHE_H_ +#define _PACKAGE__REPOSITORY_CACHE_H_ #include @@ -13,19 +13,17 @@ class BEntry; -namespace Haiku { - -namespace Package { +namespace BPackageKit { //class RepositoryHeader; -class RepositoryCache { +class BRepositoryCache { public: - RepositoryCache(); - RepositoryCache(const BEntry& entry); - virtual ~RepositoryCache(); + BRepositoryCache(); + BRepositoryCache(const BEntry& entry); + virtual ~BRepositoryCache(); status_t SetTo(const BEntry& entry); status_t InitCheck() const; @@ -45,9 +43,7 @@ private: }; -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__REPOSITORY_CACHE_H_ +#endif // _PACKAGE__REPOSITORY_CACHE_H_ diff --git a/headers/os/package/RepositoryConfig.h b/headers/os/package/RepositoryConfig.h index 1ee3c2e732..52d5f79970 100644 --- a/headers/os/package/RepositoryConfig.h +++ b/headers/os/package/RepositoryConfig.h @@ -2,8 +2,8 @@ * Copyright 2011, Haiku, Inc. * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__REPOSITORY_CONFIG_H_ -#define _HAIKU__PACKAGE__REPOSITORY_CONFIG_H_ +#ifndef _PACKAGE__REPOSITORY_CONFIG_H_ +#define _PACKAGE__REPOSITORY_CONFIG_H_ #include @@ -14,22 +14,20 @@ class BEntry; -namespace Haiku { - -namespace Package { +namespace BPackageKit { -class RepositoryConfig : public BArchivable { +class BRepositoryConfig : public BArchivable { typedef BArchivable inherited; public: - RepositoryConfig(); - RepositoryConfig(const BString& name, + BRepositoryConfig(); + BRepositoryConfig(const BString& name, const BString& url, uint8 priority = kDefaultPriority); - RepositoryConfig(const BEntry& entry); - RepositoryConfig(BMessage* data); - virtual ~RepositoryConfig(); + BRepositoryConfig(const BEntry& entry); + BRepositoryConfig(BMessage* data); + virtual ~BRepositoryConfig(); virtual status_t Archive(BMessage* data, bool deep = true) const; @@ -52,7 +50,7 @@ public: void SetIsUserSpecific(bool isUserSpecific); public: - static RepositoryConfig* Instantiate(BMessage* data); + static BRepositoryConfig* Instantiate(BMessage* data); static const uint8 kDefaultPriority; static const char* kNameField; @@ -71,9 +69,7 @@ private: }; -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__REPOSITORY_CONFIG_H_ +#endif // _PACKAGE__REPOSITORY_CONFIG_H_ diff --git a/headers/os/package/Request.h b/headers/os/package/Request.h index 8763feafb3..57ae1af807 100644 --- a/headers/os/package/Request.h +++ b/headers/os/package/Request.h @@ -2,46 +2,48 @@ * Copyright 2011, Haiku, Inc. * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__REQUEST_H_ -#define _HAIKU__PACKAGE__REQUEST_H_ +#ifndef _PACKAGE__REQUEST_H_ +#define _PACKAGE__REQUEST_H_ #include -#include +#include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -class Context; -using Private::JobQueue; +class BContext; +namespace BPrivate { + class JobQueue; +} +using BPrivate::JobQueue; -class Request : protected JobStateListener { +class BRequest : protected BJobStateListener { public: - Request(const Context& context); - virtual ~Request(); + BRequest(const BContext& context); + virtual ~BRequest(); + + status_t InitCheck() const; virtual status_t CreateInitialJobs() = 0; - Job* PopRunnableJob(); + BJob* PopRunnableJob(); protected: - status_t QueueJob(Job* job); + status_t QueueJob(BJob* job); - const Context& fContext; + const BContext& fContext; private: - JobQueue fJobQueue; + status_t fInitStatus; + JobQueue* fJobQueue; }; -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__REQUEST_H_ +#endif // _PACKAGE__REQUEST_H_ diff --git a/headers/private/package/ActivateRepositoryCacheJob.h b/headers/private/package/ActivateRepositoryCacheJob.h index 78414af072..09009fb7bc 100644 --- a/headers/private/package/ActivateRepositoryCacheJob.h +++ b/headers/private/package/ActivateRepositoryCacheJob.h @@ -2,8 +2,8 @@ * Copyright 2011, Oliver Tappe * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CACHE_JOB_H_ -#define _HAIKU__PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CACHE_JOB_H_ +#ifndef _PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CACHE_JOB_H_ +#define _PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CACHE_JOB_H_ #include @@ -13,19 +13,17 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { -class ActivateRepositoryCacheJob : public Job { - typedef Job inherited; +class ActivateRepositoryCacheJob : public BJob { + typedef BJob inherited; public: ActivateRepositoryCacheJob( - const Context& context, + const BContext& context, const BString& title, const BEntry& fetchedRepoCacheEntry, const BString& repositoryName, @@ -42,11 +40,9 @@ private: }; -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CACHE_JOB_H_ +#endif // _PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CACHE_JOB_H_ diff --git a/headers/private/package/ActivateRepositoryConfigJob.h b/headers/private/package/ActivateRepositoryConfigJob.h index 5aef02c091..8df69b7025 100644 --- a/headers/private/package/ActivateRepositoryConfigJob.h +++ b/headers/private/package/ActivateRepositoryConfigJob.h @@ -2,8 +2,8 @@ * Copyright 2011, Oliver Tappe * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_ -#define _HAIKU__PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_ +#ifndef _PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_ +#define _PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_ #include @@ -13,19 +13,17 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { -class ActivateRepositoryConfigJob : public Job { - typedef Job inherited; +class ActivateRepositoryConfigJob : public BJob { + typedef BJob inherited; public: ActivateRepositoryConfigJob( - const Context& context, + const BContext& context, const BString& title, const BEntry& archivedRepoConfigEntry, const BString& repositoryBaseURL, @@ -48,11 +46,9 @@ private: }; -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_ +#endif // _PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_ diff --git a/headers/private/package/ChecksumAccessors.h b/headers/private/package/ChecksumAccessors.h index 4555e55987..8872cd5606 100644 --- a/headers/private/package/ChecksumAccessors.h +++ b/headers/private/package/ChecksumAccessors.h @@ -2,19 +2,17 @@ * Copyright 2011, Oliver Tappe * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__PRIVATE__CHECKSUM_ACCESSORS_H_ -#define _HAIKU__PACKAGE__PRIVATE__CHECKSUM_ACCESSORS_H_ +#ifndef _PACKAGE__PRIVATE__CHECKSUM_ACCESSORS_H_ +#define _PACKAGE__PRIVATE__CHECKSUM_ACCESSORS_H_ #include #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { class ChecksumAccessor { @@ -51,11 +49,9 @@ private: }; -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__PRIVATE__CHECKSUM_ACCESSORS_H_ +#endif // _PACKAGE__PRIVATE__CHECKSUM_ACCESSORS_H_ diff --git a/headers/private/package/FetchFileJob.h b/headers/private/package/FetchFileJob.h index 44e3248d19..60ee799477 100644 --- a/headers/private/package/FetchFileJob.h +++ b/headers/private/package/FetchFileJob.h @@ -2,8 +2,8 @@ * Copyright 2011, Oliver Tappe * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ -#define _HAIKU__PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ +#ifndef _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ +#define _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ #include @@ -12,18 +12,16 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { -class FetchFileJob : public Job { - typedef Job inherited; +class FetchFileJob : public BJob { + typedef BJob inherited; public: - FetchFileJob(const Context& context, + FetchFileJob(const BContext& context, const BString& title, const BString& fileURL, const BEntry& targetEntry); @@ -39,11 +37,9 @@ private: }; -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ +#endif // _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ diff --git a/headers/private/package/JobQueue.h b/headers/private/package/JobQueue.h index 37c8d06766..99cb6d4ebe 100644 --- a/headers/private/package/JobQueue.h +++ b/headers/private/package/JobQueue.h @@ -2,8 +2,8 @@ * Copyright 2011, Haiku, Inc. * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__JOB_QUEUE_H_ -#define _HAIKU__PACKAGE__JOB_QUEUE_H_ +#ifndef _PACKAGE__PRIVATE__JOB_QUEUE_H_ +#define _PACKAGE__PRIVATE__JOB_QUEUE_H_ #include @@ -12,44 +12,55 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { -class JobQueue : public JobStateListener { +class JobQueue : private BJobStateListener { public: JobQueue(); - ~JobQueue(); + virtual ~JobQueue(); - status_t AddJob(Job* job); - status_t RemoveJob(Job* job); + status_t InitCheck() const; - Job* Pop(); + status_t AddJob(BJob* job); + // takes ownership + status_t RemoveJob(BJob* job); + // gives up ownership - // JobStateListener - virtual void JobSucceeded(Job* job); - virtual void JobFailed(Job* job); + BJob* Pop(); + // caller owns job + + void Close(); + +private: + // BJobStateListener + virtual void JobSucceeded(BJob* job); + virtual void JobFailed(BJob* job); private: struct JobPriorityLess; class JobPriorityQueue; private: - void _UpdateDependantJobsOf(Job* job); + status_t _Init(); + + void _RequeueDependantJobsOf(BJob* job); + void _RemoveDependantJobsOf(BJob* job); BLocker fLock; + uint32 fNextTicketNumber; JobPriorityQueue* fQueuedJobs; + sem_id fHaveRunnableJobSem; + + status_t fInitStatus; }; -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__JOB_QUEUE_H_ +#endif // _PACKAGE__PRIVATE__JOB_QUEUE_H_ diff --git a/headers/private/package/TempfileManager.h b/headers/private/package/TempfileManager.h index 835a30fc79..e53ebadaf6 100644 --- a/headers/private/package/TempfileManager.h +++ b/headers/private/package/TempfileManager.h @@ -2,8 +2,8 @@ * Copyright 2011, Oliver Tappe * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__PRIVATE__TEMPFILE_MANAGER_H_ -#define _HAIKU__PACKAGE__PRIVATE__TEMPFILE_MANAGER_H_ +#ifndef _PACKAGE__PRIVATE__TEMPFILE_MANAGER_H_ +#define _PACKAGE__PRIVATE__TEMPFILE_MANAGER_H_ #include @@ -12,11 +12,9 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { class TempfileManager { @@ -37,11 +35,9 @@ private: }; -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__PRIVATE__TEMPFILE_MANAGER_H_ +#endif // _PACKAGE__PRIVATE__TEMPFILE_MANAGER_H_ diff --git a/headers/private/package/ValidateChecksumJob.h b/headers/private/package/ValidateChecksumJob.h index aafd065b84..7cc0c4fd99 100644 --- a/headers/private/package/ValidateChecksumJob.h +++ b/headers/private/package/ValidateChecksumJob.h @@ -2,8 +2,8 @@ * Copyright 2011, Oliver Tappe * Distributed under the terms of the MIT License. */ -#ifndef _HAIKU__PACKAGE__PRIVATE__VALIDATE_CHECKSUM_JOB_H_ -#define _HAIKU__PACKAGE__PRIVATE__VALIDATE_CHECKSUM_JOB_H_ +#ifndef _PACKAGE__PRIVATE__VALIDATE_CHECKSUM_JOB_H_ +#define _PACKAGE__PRIVATE__VALIDATE_CHECKSUM_JOB_H_ #include @@ -14,19 +14,17 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { -class ValidateChecksumJob : public Job { - typedef Job inherited; +class ValidateChecksumJob : public BJob { + typedef BJob inherited; public: ValidateChecksumJob( - const Context& context, + const BContext& context, const BString& title, ChecksumAccessor* expectedChecksumAccessor, ChecksumAccessor* realChecksumAccessor, @@ -47,11 +45,9 @@ private: }; -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit -#endif // _HAIKU__PACKAGE__PRIVATE__VALIDATE_CHECKSUM_JOB_H_ +#endif // _PACKAGE__PRIVATE__VALIDATE_CHECKSUM_JOB_H_ diff --git a/src/bin/pkgman/MyDecisionProvider.cpp b/src/bin/pkgman/DecisionProvider.cpp similarity index 91% rename from src/bin/pkgman/MyDecisionProvider.cpp rename to src/bin/pkgman/DecisionProvider.cpp index 59a3f4c954..1c5e2d42ab 100644 --- a/src/bin/pkgman/MyDecisionProvider.cpp +++ b/src/bin/pkgman/DecisionProvider.cpp @@ -7,11 +7,11 @@ #include #include -#include "MyDecisionProvider.h" +#include "DecisionProvider.h" bool -MyDecisionProvider::YesNoDecisionNeeded(const BString& description, +DecisionProvider::YesNoDecisionNeeded(const BString& description, const BString& question, const BString& yes, const BString& no, const BString& defaultChoice) { diff --git a/src/bin/pkgman/MyDecisionProvider.h b/src/bin/pkgman/DecisionProvider.h similarity index 65% rename from src/bin/pkgman/MyDecisionProvider.h rename to src/bin/pkgman/DecisionProvider.h index 57bafdf480..74de90f592 100644 --- a/src/bin/pkgman/MyDecisionProvider.h +++ b/src/bin/pkgman/DecisionProvider.h @@ -2,18 +2,18 @@ * Copyright 2011, Oliver Tappe * Distributed under the terms of the MIT License. */ -#ifndef MY_DECISION_PROVIDER_H -#define MY_DECISION_PROVIDER_H +#ifndef DECISION_PROVIDER_H +#define DECISION_PROVIDER_H #include -struct MyDecisionProvider : public Haiku::Package::DecisionProvider { +struct DecisionProvider : public BPackageKit::BDecisionProvider { virtual bool YesNoDecisionNeeded(const BString& description, const BString& question, const BString& yes, const BString& no, const BString& defaultChoice); }; -#endif // MY_DECISION_PROVIDER_H +#endif // DECISION_PROVIDER_H diff --git a/src/bin/pkgman/Jamfile b/src/bin/pkgman/Jamfile index ee20e6d4a6..c433f82480 100644 --- a/src/bin/pkgman/Jamfile +++ b/src/bin/pkgman/Jamfile @@ -6,8 +6,8 @@ BinCommand pkgman : command_add_repo.cpp command_list_repos.cpp command_refresh.cpp - MyDecisionProvider.cpp - MyJobStateListener.cpp + DecisionProvider.cpp + JobStateListener.cpp pkgman.cpp : package be diff --git a/src/bin/pkgman/MyJobStateListener.cpp b/src/bin/pkgman/JobStateListener.cpp similarity index 66% rename from src/bin/pkgman/MyJobStateListener.cpp rename to src/bin/pkgman/JobStateListener.cpp index d62b2bb497..f410703257 100644 --- a/src/bin/pkgman/MyJobStateListener.cpp +++ b/src/bin/pkgman/JobStateListener.cpp @@ -6,28 +6,28 @@ #include -#include "MyJobStateListener.h" +#include "JobStateListener.h" #include "pkgman.h" -using Haiku::Package::Job; +using BPackageKit::BJob; void -MyJobStateListener::JobStarted(Job* job) +JobStateListener::JobStarted(BJob* job) { printf("%s ...\n", job->Title().String()); } void -MyJobStateListener::JobSucceeded(Job* job) +JobStateListener::JobSucceeded(BJob* job) { } void -MyJobStateListener::JobFailed(Job* job) +JobStateListener::JobFailed(BJob* job) { BString error = job->ErrorString(); if (error.Length() > 0) { @@ -39,7 +39,7 @@ MyJobStateListener::JobFailed(Job* job) void -MyJobStateListener::JobAborted(Job* job) +JobStateListener::JobAborted(BJob* job) { DIE(job->Result(), "aborted"); } diff --git a/src/bin/pkgman/JobStateListener.h b/src/bin/pkgman/JobStateListener.h new file mode 100644 index 0000000000..f765301403 --- /dev/null +++ b/src/bin/pkgman/JobStateListener.h @@ -0,0 +1,20 @@ +/* + * Copyright 2011, Oliver Tappe + * Distributed under the terms of the MIT License. + */ +#ifndef JOB_STATE_LISTENER_H +#define JOB_STATE_LISTENER_H + + +#include + + +struct JobStateListener : public BPackageKit::BJobStateListener { + virtual void JobStarted(BPackageKit::BJob* job); + virtual void JobSucceeded(BPackageKit::BJob* job); + virtual void JobFailed(BPackageKit::BJob* job); + virtual void JobAborted(BPackageKit::BJob* job); +}; + + +#endif // JOB_STATE_LISTENER_H diff --git a/src/bin/pkgman/MyJobStateListener.h b/src/bin/pkgman/MyJobStateListener.h deleted file mode 100644 index 42f2ed0d57..0000000000 --- a/src/bin/pkgman/MyJobStateListener.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2011, Oliver Tappe - * Distributed under the terms of the MIT License. - */ -#ifndef MY_JOB_STATE_LISTENER_H -#define MY_JOB_STATE_LISTENER_H - - -#include - - -struct MyJobStateListener : public Haiku::Package::JobStateListener { - virtual void JobStarted(Haiku::Package::Job* job); - virtual void JobSucceeded(Haiku::Package::Job* job); - virtual void JobFailed(Haiku::Package::Job* job); - virtual void JobAborted(Haiku::Package::Job* job); -}; - - -#endif // MY_JOB_STATE_LISTENER_H diff --git a/src/bin/pkgman/command_add_repo.cpp b/src/bin/pkgman/command_add_repo.cpp index 7e2c2662d0..ba34b524c2 100644 --- a/src/bin/pkgman/command_add_repo.cpp +++ b/src/bin/pkgman/command_add_repo.cpp @@ -14,14 +14,14 @@ #include #include #include -#include +#include -#include "MyDecisionProvider.h" -#include "MyJobStateListener.h" +#include "DecisionProvider.h" +#include "JobStateListener.h" #include "pkgman.h" -using namespace Haiku::Package; +using namespace BPackageKit; // TODO: internationalization! @@ -81,35 +81,41 @@ command_add_repo(int argc, const char* const* argv) const char* const* repoURLs = argv + optind; int urlCount = argc - optind; - MyDecisionProvider decisionProvider; - Context context(decisionProvider); - MyJobStateListener listener; - context.SetJobStateListener(&listener); + DecisionProvider decisionProvider; + JobStateListener listener; + BContext context(decisionProvider, listener); status_t result; for (int i = 0; i < urlCount; ++i) { AddRepositoryRequest addRequest(context, repoURLs[i], asUserRepository); + result = addRequest.InitCheck(); + if (result != B_OK) + DIE(result, "unable to create request for adding repository"); result = addRequest.CreateInitialJobs(); if (result != B_OK) DIE(result, "unable to create necessary jobs"); - while (Job* job = addRequest.PopRunnableJob()) { + while (BJob* job = addRequest.PopRunnableJob()) { result = job->Run(); delete job; if (result == B_CANCELED) return 1; } + // now refresh the repo-cache of the new repository BString repoName = addRequest.RepositoryName(); - Roster roster; - RepositoryConfig repoConfig; + BPackageRoster roster; + BRepositoryConfig repoConfig; roster.GetRepositoryConfig(repoName, &repoConfig); - RefreshRepositoryRequest refreshRequest(context, repoConfig); + BRefreshRepositoryRequest refreshRequest(context, repoConfig); + result = refreshRequest.InitCheck(); + if (result != B_OK) + DIE(result, "unable to create request for refreshing repository"); result = refreshRequest.CreateInitialJobs(); if (result != B_OK) DIE(result, "unable to create necessary jobs"); - while (Job* job = refreshRequest.PopRunnableJob()) { + while (BJob* job = refreshRequest.PopRunnableJob()) { result = job->Run(); delete job; if (result == B_CANCELED) diff --git a/src/bin/pkgman/command_list_repos.cpp b/src/bin/pkgman/command_list_repos.cpp index f1af938fbb..cbdca698de 100644 --- a/src/bin/pkgman/command_list_repos.cpp +++ b/src/bin/pkgman/command_list_repos.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include "pkgman.h" @@ -24,7 +24,7 @@ // TODO: internationalization! -using namespace Haiku::Package; +using namespace BPackageKit; static const char* kCommandUsage = @@ -80,14 +80,14 @@ command_list_repos(int argc, const char* const* argv) print_command_usage_and_exit(true); BObjectList repositoryNames(20, true); - Roster roster; + BPackageRoster roster; status_t result = roster.GetRepositoryNames(repositoryNames); if (result != B_OK) DIE(result, "can't collect repository names"); for (int i = 0; i < repositoryNames.CountItems(); ++i) { const BString& repoName = *(repositoryNames.ItemAt(i)); - RepositoryConfig repoConfig; + BRepositoryConfig repoConfig; result = roster.GetRepositoryConfig(repoName, &repoConfig); if (result != B_OK) { BPath path; diff --git a/src/bin/pkgman/command_refresh.cpp b/src/bin/pkgman/command_refresh.cpp index 30e1cfa5d8..7118fa9f8d 100644 --- a/src/bin/pkgman/command_refresh.cpp +++ b/src/bin/pkgman/command_refresh.cpp @@ -13,14 +13,14 @@ #include #include -#include +#include -#include "MyDecisionProvider.h" -#include "MyJobStateListener.h" +#include "DecisionProvider.h" +#include "JobStateListener.h" #include "pkgman.h" -using namespace Haiku::Package; +using namespace BPackageKit; // TODO: internationalization! @@ -70,14 +70,13 @@ command_refresh(int argc, const char* const* argv) const char* const* repoArgs = argv + optind; int nameCount = argc - optind; - MyDecisionProvider decisionProvider; - Context context(decisionProvider); - MyJobStateListener listener; - context.SetJobStateListener(&listener); + DecisionProvider decisionProvider; + JobStateListener listener; + BContext context(decisionProvider, listener); BObjectList repositoryNames(20, true); - Roster roster; + BPackageRoster roster; if (nameCount == 0) { status_t result = roster.GetRepositoryNames(repositoryNames); if (result != B_OK) @@ -94,7 +93,7 @@ command_refresh(int argc, const char* const* argv) status_t result; for (int i = 0; i < repositoryNames.CountItems(); ++i) { const BString& repoName = *(repositoryNames.ItemAt(i)); - RepositoryConfig repoConfig; + BRepositoryConfig repoConfig; result = roster.GetRepositoryConfig(repoName, &repoConfig); if (result != B_OK) { BPath path; @@ -102,12 +101,15 @@ command_refresh(int argc, const char* const* argv) WARN(result, "skipping repository-config '%s'", path.Path()); continue; } - RefreshRepositoryRequest refreshRequest(context, repoConfig); + BRefreshRepositoryRequest refreshRequest(context, repoConfig); + result = refreshRequest.InitCheck(); + if (result != B_OK) + DIE(result, "unable to create request for refreshing repository"); result = refreshRequest.CreateInitialJobs(); if (result != B_OK) DIE(result, "unable to create necessary jobs"); - while (Job* job = refreshRequest.PopRunnableJob()) { + while (BJob* job = refreshRequest.PopRunnableJob()) { result = job->Run(); delete job; if (result != B_OK) diff --git a/src/kits/package/ActivateRepositoryCacheJob.cpp b/src/kits/package/ActivateRepositoryCacheJob.cpp index ab13cf4671..fdede8c972 100644 --- a/src/kits/package/ActivateRepositoryCacheJob.cpp +++ b/src/kits/package/ActivateRepositoryCacheJob.cpp @@ -14,14 +14,12 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { -ActivateRepositoryCacheJob::ActivateRepositoryCacheJob(const Context& context, +ActivateRepositoryCacheJob::ActivateRepositoryCacheJob(const BContext& context, const BString& title, const BEntry& fetchedRepoCacheEntry, const BString& repositoryName, const BDirectory& targetDirectory) : @@ -52,8 +50,6 @@ ActivateRepositoryCacheJob::Execute() } -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/kits/package/ActivateRepositoryConfigJob.cpp b/src/kits/package/ActivateRepositoryConfigJob.cpp index 322e405ceb..6fcadf3623 100644 --- a/src/kits/package/ActivateRepositoryConfigJob.cpp +++ b/src/kits/package/ActivateRepositoryConfigJob.cpp @@ -15,16 +15,15 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { -ActivateRepositoryConfigJob::ActivateRepositoryConfigJob(const Context& context, - const BString& title, const BEntry& archivedRepoConfigEntry, - const BString& repositoryBaseURL, const BDirectory& targetDirectory) +ActivateRepositoryConfigJob::ActivateRepositoryConfigJob( + const BContext& context, const BString& title, + const BEntry& archivedRepoConfigEntry, const BString& repositoryBaseURL, + const BDirectory& targetDirectory) : inherited(context, title), fArchivedRepoConfigEntry(archivedRepoConfigEntry), @@ -51,7 +50,7 @@ ActivateRepositoryConfigJob::Execute() if ((result = archive.Unflatten(&archiveFile)) != B_OK) return result; - RepositoryConfig* repoConfig = RepositoryConfig::Instantiate(&archive); + BRepositoryConfig* repoConfig = BRepositoryConfig::Instantiate(&archive); if (repoConfig == NULL) return B_BAD_DATA; if ((result = repoConfig->InitCheck()) != B_OK) @@ -62,7 +61,7 @@ ActivateRepositoryConfigJob::Execute() BString description = BString("A repository configuration for ") << repoConfig->Name() << " already exists."; BString question("overwrite?"); - bool yes = fContext.GetDecisionProvider().YesNoDecisionNeeded( + bool yes = fContext.DecisionProvider().YesNoDecisionNeeded( description, question, "yes", "no", "no"); if (!yes) { fTargetEntry.Unset(); @@ -98,8 +97,6 @@ ActivateRepositoryConfigJob::RepositoryName() const } -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/kits/package/AddRepositoryRequest.cpp b/src/kits/package/AddRepositoryRequest.cpp index eea51048b5..509fdcb933 100644 --- a/src/kits/package/AddRepositoryRequest.cpp +++ b/src/kits/package/AddRepositoryRequest.cpp @@ -15,18 +15,16 @@ #include #include #include -#include +#include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -using namespace Private; +using namespace BPrivate; -AddRepositoryRequest::AddRepositoryRequest(const Context& context, +AddRepositoryRequest::AddRepositoryRequest(const BContext& context, const BString& repositoryBaseURL, bool asUserRepository) : inherited(context), @@ -45,20 +43,26 @@ AddRepositoryRequest::~AddRepositoryRequest() status_t AddRepositoryRequest::CreateInitialJobs() { - BEntry tempEntry = fContext.GetTempfileManager().Create("repoheader-"); + status_t result = InitCheck(); + if (result != B_OK) + return B_NO_INIT; + + BEntry tempEntry; + result = fContext.GetNewTempfile("repoheader-", &tempEntry); + if (result != B_OK) + return result; BString repoHeaderURL = BString(fRepositoryBaseURL) << "/" << "repo.header"; FetchFileJob* fetchJob = new (std::nothrow) FetchFileJob(fContext, BString("Fetching repository header from ") << fRepositoryBaseURL, repoHeaderURL, tempEntry); if (fetchJob == NULL) return B_NO_MEMORY; - status_t result = QueueJob(fetchJob); - if (result != B_OK) { + if ((result = QueueJob(fetchJob)) != B_OK) { delete fetchJob; return result; } - Roster roster; + BPackageRoster roster; BPath targetRepoConfigPath; result = fAsUserRepository ? roster.GetUserRepositoryConfigPath(&targetRepoConfigPath, true) @@ -84,7 +88,7 @@ AddRepositoryRequest::CreateInitialJobs() void -AddRepositoryRequest::JobSucceeded(Job* job) +AddRepositoryRequest::JobSucceeded(BJob* job) { if (job == fActivateJob) fRepositoryName = fActivateJob->RepositoryName(); @@ -98,6 +102,4 @@ AddRepositoryRequest::RepositoryName() const } -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/kits/package/Attributes.cpp b/src/kits/package/Attributes.cpp index 02ee18dc57..7df7d22f10 100644 --- a/src/kits/package/Attributes.cpp +++ b/src/kits/package/Attributes.cpp @@ -10,24 +10,20 @@ #include -namespace Haiku { - -namespace Package { +namespace BPackageKit { // attributes used in package and as file attribute, too -const char* kNameAttribute = "PKG:name"; -const char* kPlatformAttribute = "PKG:platform"; -const char* kVendorAttribute = "PKG:vendor"; -const char* kVersionAttribute = "PKG:version"; +const char* kPackageNameAttribute = "PKG:name"; +const char* kPackagePlatformAttribute = "PKG:platform"; +const char* kPackageVendorAttribute = "PKG:vendor"; +const char* kPackageVersionAttribute = "PKG:version"; // attributes kept local to packages -const char* kCopyrightAttribute = "PKG:copyright"; -const char* kLicenseAttribute = "PKG:license"; -const char* kProvidesAttribute = "PKG:provides"; -const char* kRequiresAttribute = "PKG:requires"; +const char* kPackageCopyrightAttribute = "PKG:copyright"; +const char* kPackageLicenseAttribute = "PKG:license"; +const char* kPackageProvidesAttribute = "PKG:provides"; +const char* kPackageRequiresAttribute = "PKG:requires"; -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/kits/package/ChecksumAccessors.cpp b/src/kits/package/ChecksumAccessors.cpp index 6abc6e3c30..8ec09c9e90 100644 --- a/src/kits/package/ChecksumAccessors.cpp +++ b/src/kits/package/ChecksumAccessors.cpp @@ -15,11 +15,9 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { #define NIBBLE_AS_HEX(nibble) \ @@ -129,8 +127,6 @@ GeneralFileChecksumAccessor::GetChecksum(BString& checksum) const } -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/kits/package/Context.cpp b/src/kits/package/Context.cpp index 792b5ef25e..eec15b3412 100644 --- a/src/kits/package/Context.cpp +++ b/src/kits/package/Context.cpp @@ -7,7 +7,10 @@ */ +#include + #include +#include #include #include @@ -15,66 +18,93 @@ #include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -DecisionProvider::~DecisionProvider() +using BPrivate::TempfileManager; + + +BDecisionProvider::~BDecisionProvider() { } -Context::Context(DecisionProvider& decisionProvider) +BContext::BContext(BDecisionProvider& decisionProvider, + BJobStateListener& jobStateListener) : fDecisionProvider(decisionProvider), - fJobStateListener(NULL) + fJobStateListener(jobStateListener), + fTempfileManager(NULL) { - BPath tempPath; - if (find_directory(B_COMMON_TEMP_DIRECTORY, &tempPath) != B_OK) - tempPath.SetTo("/tmp"); - BDirectory tempDirectory(tempPath.Path()); - - BString contextName = BString("pkgkit-context-") << find_thread(NULL); - BDirectory baseDirectory; - tempDirectory.CreateDirectory(contextName.String(), &baseDirectory); - fTempfileManager.SetBaseDirectory(baseDirectory); + fInitStatus = _Initialize(); } -Context::~Context() +BContext::~BContext() { + delete fTempfileManager; } -TempfileManager& -Context::GetTempfileManager() const +status_t +BContext::InitCheck() const { - return fTempfileManager; + return fInitStatus; } -JobStateListener* -Context::GetJobStateListener() const +status_t +BContext::GetNewTempfile(const BString& baseName, BEntry* entry) const +{ + if (entry == NULL) + return B_BAD_VALUE; + if (fTempfileManager == NULL) + return B_NO_INIT; + *entry = fTempfileManager->Create(baseName); + return entry->InitCheck(); +} + + +BJobStateListener& +BContext::JobStateListener() const { return fJobStateListener; } -void -Context::SetJobStateListener(JobStateListener* listener) -{ - fJobStateListener = listener; -} - - -DecisionProvider& -Context::GetDecisionProvider() const +BDecisionProvider& +BContext::DecisionProvider() const { return fDecisionProvider; } -} // namespace Package +status_t +BContext::_Initialize() +{ + fTempfileManager = new (std::nothrow) TempfileManager(); + if (fTempfileManager == NULL) + return B_NO_MEMORY; -} // namespace Haiku + BPath tempPath; + status_t result = find_directory(B_COMMON_TEMP_DIRECTORY, &tempPath, true); + if (result != B_OK) + return result; + BDirectory tempDirectory(tempPath.Path()); + if ((result = tempDirectory.InitCheck()) != B_OK) + return result; + + BString contextName = BString("pkgkit-context-") << find_thread(NULL); + BDirectory baseDirectory; + result = tempDirectory.CreateDirectory(contextName.String(), + &baseDirectory); + if (result != B_OK) + return result; + + fTempfileManager->SetBaseDirectory(baseDirectory); + + return B_OK; +} + + +} // namespace BPackageKit diff --git a/src/kits/package/FetchFileJob.cpp b/src/kits/package/FetchFileJob.cpp index b79c465ab6..afbcc5c6cc 100644 --- a/src/kits/package/FetchFileJob.cpp +++ b/src/kits/package/FetchFileJob.cpp @@ -15,14 +15,12 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { -FetchFileJob::FetchFileJob(const Context& context, const BString& title, +FetchFileJob::FetchFileJob(const BContext& context, const BString& title, const BString& fileURL, const BEntry& targetEntry) : inherited(context, title), @@ -67,8 +65,6 @@ FetchFileJob::Cleanup(status_t jobResult) } -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/kits/package/Jamfile b/src/kits/package/Jamfile index 4e3243c848..fdc10af289 100644 --- a/src/kits/package/Jamfile +++ b/src/kits/package/Jamfile @@ -13,12 +13,12 @@ SharedLibrary libpackage.so FetchFileJob.cpp Job.cpp JobQueue.cpp + PackageRoster.cpp RefreshRepositoryRequest.cpp RepositoryCache.cpp RepositoryConfig.cpp # RepositoryHeader.cpp Request.cpp - Roster.cpp TempfileManager.cpp ValidateChecksumJob.cpp : diff --git a/src/kits/package/Job.cpp b/src/kits/package/Job.cpp index eb03f0c667..92ca209f80 100644 --- a/src/kits/package/Job.cpp +++ b/src/kits/package/Job.cpp @@ -14,45 +14,44 @@ #include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -JobStateListener::~JobStateListener() +BJobStateListener::~BJobStateListener() { } void -JobStateListener::JobStarted(Job* job) +BJobStateListener::JobStarted(BJob* job) { } void -JobStateListener::JobSucceeded(Job* job) +BJobStateListener::JobSucceeded(BJob* job) { } void -JobStateListener::JobFailed(Job* job) +BJobStateListener::JobFailed(BJob* job) { } void -JobStateListener::JobAborted(Job* job) +BJobStateListener::JobAborted(BJob* job) { } -Job::Job(const Context& context, const BString& title) +BJob::BJob(const BContext& context, const BString& title) : fContext(context), fTitle(title), - fState(JOB_STATE_WAITING_TO_RUN) + fState(JOB_STATE_WAITING_TO_RUN), + fTicketNumber(0xFFFFFFFFUL) { if (fTitle.Length() == 0) fInitStatus = B_BAD_VALUE; @@ -61,55 +60,76 @@ Job::Job(const Context& context, const BString& title) } -Job::~Job() +BJob::~BJob() { } status_t -Job::InitCheck() const +BJob::InitCheck() const { return fInitStatus; } const BString& -Job::Title() const +BJob::Title() const { return fTitle; } -JobState -Job::State() const +BJobState +BJob::State() const { return fState; } status_t -Job::Result() const +BJob::Result() const { return fResult; } const BString& -Job::ErrorString() const +BJob::ErrorString() const { return fErrorString; } +uint32 +BJob::TicketNumber() const +{ + return fTicketNumber; +} + + void -Job::SetErrorString(const BString& error) +BJob::_SetTicketNumber(uint32 ticketNumber) +{ + fTicketNumber = ticketNumber; +} + + +void +BJob::_ClearTicketNumber() +{ + fTicketNumber = 0xFFFFFFFFUL; +} + + +void +BJob::SetErrorString(const BString& error) { fErrorString = error; } status_t -Job::Run() +BJob::Run() { if (fState != JOB_STATE_WAITING_TO_RUN) return B_NOT_ALLOWED; @@ -132,27 +152,27 @@ Job::Run() void -Job::Cleanup(status_t /*jobResult*/) +BJob::Cleanup(status_t /*jobResult*/) { } status_t -Job::AddStateListener(JobStateListener* listener) +BJob::AddStateListener(BJobStateListener* listener) { return fStateListeners.AddItem(listener) ? B_OK : B_ERROR; } status_t -Job::RemoveStateListener(JobStateListener* listener) +BJob::RemoveStateListener(BJobStateListener* listener) { return fStateListeners.RemoveItem(listener) ? B_OK : B_ERROR; } status_t -Job::AddDependency(Job* job) +BJob::AddDependency(BJob* job) { if (fDependencies.HasItem(job)) return B_ERROR; @@ -165,7 +185,7 @@ Job::AddDependency(Job* job) status_t -Job::RemoveDependency(Job* job) +BJob::RemoveDependency(BJob* job) { if (!fDependencies.HasItem(job)) return B_ERROR; @@ -177,26 +197,33 @@ Job::RemoveDependency(Job* job) } +bool +BJob::IsRunnable() const +{ + return fDependencies.IsEmpty(); +} + + int32 -Job::CountDependencies() const +BJob::CountDependencies() const { return fDependencies.CountItems(); } -Job* -Job::DependantJobAt(int32 index) const +BJob* +BJob::DependantJobAt(int32 index) const { return fDependantJobs.ItemAt(index); } void -Job::NotifyStateListeners() +BJob::NotifyStateListeners() { int32 count = fStateListeners.CountItems(); for (int i = 0; i < count; ++i) { - JobStateListener* listener = fStateListeners.ItemAt(i); + BJobStateListener* listener = fStateListeners.ItemAt(i); if (listener == NULL) continue; switch (fState) { @@ -219,6 +246,4 @@ Job::NotifyStateListeners() } -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/kits/package/JobQueue.cpp b/src/kits/package/JobQueue.cpp index 687ce5da26..182856a602 100644 --- a/src/kits/package/JobQueue.cpp +++ b/src/kits/package/JobQueue.cpp @@ -16,20 +16,23 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { struct JobQueue::JobPriorityLess { - bool operator()(const Job* left, const Job* right) const; + bool operator()(const BJob* left, const BJob* right) const; }; +// 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 Job* left, const Job* right) const +JobQueue::JobPriorityLess::operator()(const BJob* left, const BJob* right) const { int32 difference = left->CountDependencies() - right->CountDependencies(); if (difference < 0) @@ -37,21 +40,21 @@ JobQueue::JobPriorityLess::operator()(const Job* left, const Job* right) const if (difference > 0) return false; - return left->Title() < right->Title(); + return left->TicketNumber() < right->TicketNumber(); }; class JobQueue::JobPriorityQueue - : public std::set { - + : public std::set { }; JobQueue::JobQueue() : fLock("job queue"), - fQueuedJobs(new (std::nothrow) JobPriorityQueue()) + fNextTicketNumber(1) { + fInitStatus = _Init(); } @@ -61,7 +64,14 @@ JobQueue::~JobQueue() status_t -JobQueue::AddJob(Job* job) +JobQueue::InitCheck() const +{ + return fInitStatus; +} + + +status_t +JobQueue::AddJob(BJob* job) { if (fQueuedJobs == NULL) return B_NO_INIT; @@ -69,12 +79,14 @@ JobQueue::AddJob(Job* job) BAutolock lock(&fLock); if (lock.IsLocked()) { try { - fQueuedJobs->insert(job); + if (!fQueuedJobs->insert(job).second) + return B_NAME_IN_USE; } catch (const std::bad_alloc& e) { return B_NO_MEMORY; } catch (...) { - return B_NO_MEMORY; + return B_ERROR; } + job->_SetTicketNumber(fNextTicketNumber++); job->AddStateListener(this); } @@ -83,7 +95,7 @@ JobQueue::AddJob(Job* job) status_t -JobQueue::RemoveJob(Job* job) +JobQueue::RemoveJob(BJob* job) { if (fQueuedJobs == NULL) return B_NO_INIT; @@ -91,10 +103,12 @@ JobQueue::RemoveJob(Job* job) BAutolock lock(&fLock); if (lock.IsLocked()) { try { - fQueuedJobs->erase(job); + if (fQueuedJobs->erase(job) == 0) + return B_NAME_NOT_FOUND; } catch (...) { return B_ERROR; } + job->_ClearTicketNumber(); job->RemoveStateListener(this); } @@ -103,20 +117,24 @@ JobQueue::RemoveJob(Job* job) void -JobQueue::JobSucceeded(Job* job) +JobQueue::JobSucceeded(BJob* job) { - _UpdateDependantJobsOf(job); + BAutolock lock(&fLock); + if (lock.IsLocked()) + _RequeueDependantJobsOf(job); } void -JobQueue::JobFailed(Job* job) +JobQueue::JobFailed(BJob* job) { - _UpdateDependantJobsOf(job); + BAutolock lock(&fLock); + if (lock.IsLocked()) + _RemoveDependantJobsOf(job); } -Job* +BJob* JobQueue::Pop() { BAutolock lock(&fLock); @@ -124,6 +142,23 @@ JobQueue::Pop() JobPriorityQueue::iterator head = fQueuedJobs->begin(); if (head == fQueuedJobs->end()) return NULL; + while (!(*head)->IsRunnable()) { + // we need to wait until a job becomes runnable + status_t result; + do { + lock.Unlock(); + result = acquire_sem(fHaveRunnableJobSem); + if (!lock.Lock()) + return NULL; + } while (result == B_INTERRUPTED); + if (result != B_OK) + return NULL; + + // fetch current head, it must be runnable now + head = fQueuedJobs->begin(); + if (head == fQueuedJobs->end()) + return NULL; + } fQueuedJobs->erase(head); return *head; } @@ -133,27 +168,78 @@ JobQueue::Pop() void -JobQueue::_UpdateDependantJobsOf(Job* job) +JobQueue::Close() { + if (fHaveRunnableJobSem < 0) + return; + BAutolock lock(&fLock); if (lock.IsLocked()) { - while (Job* dependantJob = job->DependantJobAt(0)) { - try { - fQueuedJobs->erase(dependantJob); - } catch (...) { - } - dependantJob->RemoveDependency(job); - try { - fQueuedJobs->insert(dependantJob); - } catch (...) { + delete_sem(fHaveRunnableJobSem); + fHaveRunnableJobSem = -1; + + if (fQueuedJobs != NULL) { + // get rid of all jobs + for (JobPriorityQueue::iterator iter = fQueuedJobs->begin(); + iter != fQueuedJobs->end(); ++iter) { + delete (*iter); } + fQueuedJobs->clear(); } } } -} // namespace Private +status_t +JobQueue::_Init() +{ + status_t result = fLock.InitCheck(); + if (result != B_OK) + return result; -} // namespace Package + fQueuedJobs = new (std::nothrow) JobPriorityQueue(); + if (fQueuedJobs == NULL) + return B_NO_MEMORY; -} // namespace Haiku + fHaveRunnableJobSem = create_sem(0, "have runnable job"); + if (fHaveRunnableJobSem < 0) + return fHaveRunnableJobSem; + + return B_OK; +} + + +void +JobQueue::_RequeueDependantJobsOf(BJob* job) +{ + while (BJob* dependantJob = job->DependantJobAt(0)) { + try { + fQueuedJobs->erase(dependantJob); + } catch (...) { + } + dependantJob->RemoveDependency(job); + try { + fQueuedJobs->insert(dependantJob); + } catch (...) { + } + } +} + + +void +JobQueue::_RemoveDependantJobsOf(BJob* job) +{ + while (BJob* dependantJob = job->DependantJobAt(0)) { + try { + fQueuedJobs->erase(dependantJob); + } catch (...) { + } + _RemoveDependantJobsOf(dependantJob); + delete job; + } +} + + +} // namespace BPrivate + +} // namespace BPackageKit diff --git a/src/kits/package/Roster.cpp b/src/kits/package/PackageRoster.cpp similarity index 77% rename from src/kits/package/Roster.cpp rename to src/kits/package/PackageRoster.cpp index 4b63f934e6..66674faad6 100644 --- a/src/kits/package/Roster.cpp +++ b/src/kits/package/PackageRoster.cpp @@ -7,7 +7,7 @@ */ -#include +#include #include #include @@ -22,51 +22,49 @@ #include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -Roster::Roster() +BPackageRoster::BPackageRoster() { } -Roster::~Roster() +BPackageRoster::~BPackageRoster() { } status_t -Roster::GetCommonRepositoryConfigPath(BPath* path, bool create) const +BPackageRoster::GetCommonRepositoryConfigPath(BPath* path, bool create) const { return _GetRepositoryPath(path, create, B_COMMON_SETTINGS_DIRECTORY); } status_t -Roster::GetUserRepositoryConfigPath(BPath* path, bool create) const +BPackageRoster::GetUserRepositoryConfigPath(BPath* path, bool create) const { return _GetRepositoryPath(path, create, B_USER_SETTINGS_DIRECTORY); } status_t -Roster::GetCommonRepositoryCachePath(BPath* path, bool create) const +BPackageRoster::GetCommonRepositoryCachePath(BPath* path, bool create) const { return _GetRepositoryPath(path, create, B_COMMON_CACHE_DIRECTORY); } status_t -Roster::GetUserRepositoryCachePath(BPath* path, bool create) const +BPackageRoster::GetUserRepositoryCachePath(BPath* path, bool create) const { return _GetRepositoryPath(path, create, B_USER_CACHE_DIRECTORY); } status_t -Roster::VisitCommonRepositoryConfigs(RepositoryConfigVisitor& visitor) +BPackageRoster::VisitCommonRepositoryConfigs(BRepositoryConfigVisitor& visitor) { BPath commonRepositoryConfigPath; status_t result @@ -79,7 +77,7 @@ Roster::VisitCommonRepositoryConfigs(RepositoryConfigVisitor& visitor) status_t -Roster::VisitUserRepositoryConfigs(RepositoryConfigVisitor& visitor) +BPackageRoster::VisitUserRepositoryConfigs(BRepositoryConfigVisitor& visitor) { BPath userRepositoryConfigPath; status_t result = GetUserRepositoryConfigPath(&userRepositoryConfigPath); @@ -91,9 +89,9 @@ Roster::VisitUserRepositoryConfigs(RepositoryConfigVisitor& visitor) status_t -Roster::GetRepositoryNames(BObjectList& names) +BPackageRoster::GetRepositoryNames(BObjectList& names) { - struct RepositoryNameCollector : public RepositoryConfigVisitor { + struct RepositoryNameCollector : public BRepositoryConfigVisitor { RepositoryNameCollector(BObjectList& _names) : names(_names) { @@ -124,8 +122,8 @@ Roster::GetRepositoryNames(BObjectList& names) status_t -Roster::GetRepositoryCache(const BString& name, - RepositoryCache* repositoryCache) +BPackageRoster::GetRepositoryCache(const BString& name, + BRepositoryCache* repositoryCache) { if (repositoryCache == NULL) return B_BAD_VALUE; @@ -151,8 +149,8 @@ Roster::GetRepositoryCache(const BString& name, status_t -Roster::GetRepositoryConfig(const BString& name, - RepositoryConfig* repositoryConfig) +BPackageRoster::GetRepositoryConfig(const BString& name, + BRepositoryConfig* repositoryConfig) { if (repositoryConfig == NULL) return B_BAD_VALUE; @@ -178,7 +176,7 @@ Roster::GetRepositoryConfig(const BString& name, status_t -Roster::_GetRepositoryPath(BPath* path, bool create, +BPackageRoster::_GetRepositoryPath(BPath* path, bool create, directory_which whichDir) const { if (path == NULL) @@ -203,8 +201,8 @@ Roster::_GetRepositoryPath(BPath* path, bool create, status_t -Roster::_VisitRepositoryConfigs(const BPath& path, - RepositoryConfigVisitor& visitor) +BPackageRoster::_VisitRepositoryConfigs(const BPath& path, + BRepositoryConfigVisitor& visitor) { BDirectory directory(path.Path()); status_t result = directory.InitCheck(); @@ -223,6 +221,4 @@ Roster::_VisitRepositoryConfigs(const BPath& path, } -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/kits/package/RefreshRepositoryRequest.cpp b/src/kits/package/RefreshRepositoryRequest.cpp index bf09d4b8bd..c1194a32ba 100644 --- a/src/kits/package/RefreshRepositoryRequest.cpp +++ b/src/kits/package/RefreshRepositoryRequest.cpp @@ -19,19 +19,17 @@ #include #include #include -#include +#include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -using namespace Private; +using namespace BPrivate; -RefreshRepositoryRequest::RefreshRepositoryRequest(const Context& context, - const RepositoryConfig& repoConfig) +BRefreshRepositoryRequest::BRefreshRepositoryRequest(const BContext& context, + const BRepositoryConfig& repoConfig) : inherited(context), fRepoConfig(repoConfig) @@ -39,23 +37,26 @@ RefreshRepositoryRequest::RefreshRepositoryRequest(const Context& context, } -RefreshRepositoryRequest::~RefreshRepositoryRequest() +BRefreshRepositoryRequest::~BRefreshRepositoryRequest() { } status_t -RefreshRepositoryRequest::CreateInitialJobs() +BRefreshRepositoryRequest::CreateInitialJobs() { - Roster roster; - status_t result = fRepoConfig.InitCheck(); + status_t result = InitCheck(); if (result != B_OK) + return B_NO_INIT; + + if ((result = fRepoConfig.InitCheck()) != B_OK) return result; // fetch the current checksum and compare with our cache's checksum, // if they differ, fetch the updated cache - fFetchedChecksumFile - = fContext.GetTempfileManager().Create("repochecksum-"); + result = fContext.GetNewTempfile("repochecksum-", &fFetchedChecksumFile); + if (result != B_OK) + return result; BString repoChecksumURL = BString(fRepoConfig.URL()) << "/" << "repo.sha256"; FetchFileJob* fetchChecksumJob = new (std::nothrow) FetchFileJob( @@ -69,7 +70,8 @@ RefreshRepositoryRequest::CreateInitialJobs() return result; } - RepositoryCache repoCache; + BRepositoryCache repoCache; + BPackageRoster roster; roster.GetRepositoryCache(fRepoConfig.Name(), &repoCache); ValidateChecksumJob* validateChecksumJob @@ -94,7 +96,7 @@ RefreshRepositoryRequest::CreateInitialJobs() void -RefreshRepositoryRequest::JobSucceeded(Job* job) +BRefreshRepositoryRequest::JobSucceeded(BJob* job) { if (job == fValidateChecksumJob && !fValidateChecksumJob->ChecksumsMatch()) { @@ -107,21 +109,23 @@ RefreshRepositoryRequest::JobSucceeded(Job* job) status_t -RefreshRepositoryRequest::_FetchRepositoryCache() +BRefreshRepositoryRequest::_FetchRepositoryCache() { // download repository cache and put it in either the common/user cache // path, depending on where the corresponding repo-config lives // job fetching the cache - BEntry tempRepoCache = fContext.GetTempfileManager().Create("repocache-"); + BEntry tempRepoCache; + status_t result = fContext.GetNewTempfile("repocache-", &tempRepoCache); + if (result != B_OK) + return result; BString repoCacheURL = BString(fRepoConfig.URL()) << "/" << "repo"; FetchFileJob* fetchCacheJob = new (std::nothrow) FetchFileJob(fContext, BString("Fetching repository-cache from ") << fRepoConfig.URL(), repoCacheURL, tempRepoCache); if (fetchCacheJob == NULL) return B_NO_MEMORY; - status_t result = QueueJob(fetchCacheJob); - if (result != B_OK) { + if ((result = QueueJob(fetchCacheJob)) != B_OK) { delete fetchCacheJob; return result; } @@ -143,7 +147,7 @@ RefreshRepositoryRequest::_FetchRepositoryCache() // job activating the cache BPath targetRepoCachePath; - Roster roster; + BPackageRoster roster; result = fRepoConfig.IsUserSpecific() ? roster.GetUserRepositoryCachePath(&targetRepoCachePath, true) : roster.GetCommonRepositoryCachePath(&targetRepoCachePath, true); @@ -166,6 +170,4 @@ RefreshRepositoryRequest::_FetchRepositoryCache() } -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/kits/package/RepositoryCache.cpp b/src/kits/package/RepositoryCache.cpp index ce1bf475c9..8707fda80c 100644 --- a/src/kits/package/RepositoryCache.cpp +++ b/src/kits/package/RepositoryCache.cpp @@ -19,12 +19,10 @@ #include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -RepositoryCache::RepositoryCache() +BRepositoryCache::BRepositoryCache() : fInitStatus(B_NO_INIT), fIsUserSpecific(false) @@ -32,47 +30,47 @@ RepositoryCache::RepositoryCache() } -RepositoryCache::RepositoryCache(const BEntry& entry) +BRepositoryCache::BRepositoryCache(const BEntry& entry) { SetTo(entry); } -RepositoryCache::~RepositoryCache() +BRepositoryCache::~BRepositoryCache() { } status_t -RepositoryCache::InitCheck() const +BRepositoryCache::InitCheck() const { return fInitStatus; } const BEntry& -RepositoryCache::Entry() const +BRepositoryCache::Entry() const { return fEntry; } bool -RepositoryCache::IsUserSpecific() const +BRepositoryCache::IsUserSpecific() const { return fIsUserSpecific; } void -RepositoryCache::SetIsUserSpecific(bool isUserSpecific) +BRepositoryCache::SetIsUserSpecific(bool isUserSpecific) { fIsUserSpecific = isUserSpecific; } status_t -RepositoryCache::SetTo(const BEntry& entry) +BRepositoryCache::SetTo(const BEntry& entry) { fEntry = entry; fInitStatus = B_NO_INIT; @@ -101,6 +99,4 @@ RepositoryCache::SetTo(const BEntry& entry) } -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/kits/package/RepositoryConfig.cpp b/src/kits/package/RepositoryConfig.cpp index 0271aca988..857f075a31 100644 --- a/src/kits/package/RepositoryConfig.cpp +++ b/src/kits/package/RepositoryConfig.cpp @@ -20,18 +20,16 @@ #include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -const uint8 RepositoryConfig::kDefaultPriority = 50; -const char* RepositoryConfig::kNameField = "name"; -const char* RepositoryConfig::kURLField = "url"; -const char* RepositoryConfig::kPriorityField = "priority"; +const uint8 BRepositoryConfig::kDefaultPriority = 50; +const char* BRepositoryConfig::kNameField = "name"; +const char* BRepositoryConfig::kURLField = "url"; +const char* BRepositoryConfig::kPriorityField = "priority"; -RepositoryConfig::RepositoryConfig() +BRepositoryConfig::BRepositoryConfig() : fInitStatus(B_NO_INIT), fPriority(kDefaultPriority), @@ -40,13 +38,13 @@ RepositoryConfig::RepositoryConfig() } -RepositoryConfig::RepositoryConfig(const BEntry& entry) +BRepositoryConfig::BRepositoryConfig(const BEntry& entry) { SetTo(entry); } -RepositoryConfig::RepositoryConfig(BMessage* data) +BRepositoryConfig::BRepositoryConfig(BMessage* data) : inherited(data) { @@ -54,7 +52,7 @@ RepositoryConfig::RepositoryConfig(BMessage* data) } -RepositoryConfig::RepositoryConfig(const BString& name, const BString& url, +BRepositoryConfig::BRepositoryConfig(const BString& name, const BString& url, uint8 priority) : fInitStatus(B_OK), @@ -66,23 +64,23 @@ RepositoryConfig::RepositoryConfig(const BString& name, const BString& url, } -RepositoryConfig::~RepositoryConfig() +BRepositoryConfig::~BRepositoryConfig() { } -/*static*/ RepositoryConfig* -RepositoryConfig::Instantiate(BMessage* data) +/*static*/ BRepositoryConfig* +BRepositoryConfig::Instantiate(BMessage* data) { - if (validate_instantiation(data, "Haiku::Package::RepositoryConfig")) - return new (std::nothrow) RepositoryConfig(data); + if (validate_instantiation(data, "BPackageKit::BRepositoryConfig")) + return new (std::nothrow) BRepositoryConfig(data); return NULL; } status_t -RepositoryConfig::Archive(BMessage* data, bool deep) const +BRepositoryConfig::Archive(BMessage* data, bool deep) const { status_t result = inherited::Archive(data, deep); if (result != B_OK) @@ -100,7 +98,7 @@ RepositoryConfig::Archive(BMessage* data, bool deep) const status_t -RepositoryConfig::StoreAsConfigFile(const BEntry& entry) const +BRepositoryConfig::StoreAsConfigFile(const BEntry& entry) const { BFile file(&entry, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); status_t result = file.InitCheck(); @@ -121,14 +119,14 @@ RepositoryConfig::StoreAsConfigFile(const BEntry& entry) const status_t -RepositoryConfig::InitCheck() const +BRepositoryConfig::InitCheck() const { return fInitStatus; } status_t -RepositoryConfig::SetTo(const BEntry& entry) +BRepositoryConfig::SetTo(const BEntry& entry) { fEntry = entry; fInitStatus = B_NO_INIT; @@ -189,7 +187,7 @@ RepositoryConfig::SetTo(const BEntry& entry) status_t -RepositoryConfig::SetTo(const BMessage* data) +BRepositoryConfig::SetTo(const BMessage* data) { fInitStatus = B_NO_INIT; @@ -213,68 +211,66 @@ RepositoryConfig::SetTo(const BMessage* data) const BString& -RepositoryConfig::Name() const +BRepositoryConfig::Name() const { return fName; } const BString& -RepositoryConfig::URL() const +BRepositoryConfig::URL() const { return fURL; } uint8 -RepositoryConfig::Priority() const +BRepositoryConfig::Priority() const { return fPriority; } bool -RepositoryConfig::IsUserSpecific() const +BRepositoryConfig::IsUserSpecific() const { return fIsUserSpecific; } const BEntry& -RepositoryConfig::Entry() const +BRepositoryConfig::Entry() const { return fEntry; } void -RepositoryConfig::SetName(const BString& name) +BRepositoryConfig::SetName(const BString& name) { fName = name; } void -RepositoryConfig::SetURL(const BString& url) +BRepositoryConfig::SetURL(const BString& url) { fURL = url; } void -RepositoryConfig::SetPriority(uint8 priority) +BRepositoryConfig::SetPriority(uint8 priority) { fPriority = priority; } void -RepositoryConfig::SetIsUserSpecific(bool isUserSpecific) +BRepositoryConfig::SetIsUserSpecific(bool isUserSpecific) { fIsUserSpecific = isUserSpecific; } -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/kits/package/Request.cpp b/src/kits/package/Request.cpp index eb4f1a6a6d..7005c5e325 100644 --- a/src/kits/package/Request.cpp +++ b/src/kits/package/Request.cpp @@ -9,48 +9,57 @@ #include +#include + #include -#include +#include -namespace Haiku { - -namespace Package { +namespace BPackageKit { -Request::Request(const Context& context) +BRequest::BRequest(const BContext& context) : fContext(context), - fJobQueue() + fJobQueue(new (std::nothrow) JobQueue()) { + fInitStatus = fJobQueue == NULL ? B_NO_MEMORY : B_OK; } -Request::~Request() +BRequest::~BRequest() { } -Job* -Request::PopRunnableJob() -{ - return fJobQueue.Pop(); -} - - status_t -Request::QueueJob(Job* job) +BRequest::InitCheck() const { - job->AddStateListener(this); - - JobStateListener* listener = fContext.GetJobStateListener(); - if (listener != NULL) - job->AddStateListener(listener); - - return fJobQueue.AddJob(job); + return fInitStatus; } -} // namespace Package +BJob* +BRequest::PopRunnableJob() +{ + if (fJobQueue == NULL) + return NULL; -} // namespace Haiku + return fJobQueue->Pop(); +} + + +status_t +BRequest::QueueJob(BJob* job) +{ + if (fJobQueue == NULL) + return B_NO_INIT; + + job->AddStateListener(this); + job->AddStateListener(&fContext.JobStateListener()); + + return fJobQueue->AddJob(job); +} + + +} // namespace BPackageKit diff --git a/src/kits/package/TempfileManager.cpp b/src/kits/package/TempfileManager.cpp index 0e0f91e3f7..17295542cf 100644 --- a/src/kits/package/TempfileManager.cpp +++ b/src/kits/package/TempfileManager.cpp @@ -10,11 +10,9 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { const BString TempfileManager::kDefaultName = "tmp-pkgkit-file-"; @@ -58,8 +56,6 @@ TempfileManager::Create(const BString& baseName) } -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/kits/package/ValidateChecksumJob.cpp b/src/kits/package/ValidateChecksumJob.cpp index f2f051b6da..9896bfb748 100644 --- a/src/kits/package/ValidateChecksumJob.cpp +++ b/src/kits/package/ValidateChecksumJob.cpp @@ -14,14 +14,12 @@ #include -namespace Haiku { +namespace BPackageKit { -namespace Package { - -namespace Private { +namespace BPrivate { -ValidateChecksumJob::ValidateChecksumJob(const Context& context, +ValidateChecksumJob::ValidateChecksumJob(const BContext& context, const BString& title, ChecksumAccessor* expectedChecksumAccessor, ChecksumAccessor* realChecksumAccessor, bool failIfChecksumsDontMatch) : @@ -79,8 +77,6 @@ ValidateChecksumJob::ChecksumsMatch() const } -} // namespace Private +} // namespace BPrivate -} // namespace Package - -} // namespace Haiku +} // namespace BPackageKit diff --git a/src/tests/kits/package/make_repo.cpp b/src/tests/kits/package/make_repo.cpp index 7ef859751e..93015d3e06 100644 --- a/src/tests/kits/package/make_repo.cpp +++ b/src/tests/kits/package/make_repo.cpp @@ -8,7 +8,7 @@ #include -using namespace Haiku::Package; +using namespace BPackageKit; int @@ -20,7 +20,7 @@ main(int argc, const char** argv) return 1; } - RepositoryConfig repoConfig(argv[1], argv[2], atoi(argv[3])); + BRepositoryConfig repoConfig(argv[1], argv[2], atoi(argv[3])); status_t status = repoConfig.InitCheck(); if (status != B_OK) { fprintf(stderr, "couldn't initialize repository-config\n");