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
This commit is contained in:
Oliver Tappe
2011-01-25 17:07:27 +00:00
parent 5ba9397df3
commit 7d7ed9bf4b
43 changed files with 746 additions and 640 deletions
+12 -16
View File
@@ -2,8 +2,8 @@
* Copyright 2011, Haiku, Inc. * Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__ADD_REPOSITORY_REQUEST_H_ #ifndef _PACKAGE__ADD_REPOSITORY_REQUEST_H_
#define _HAIKU__PACKAGE__ADD_REPOSITORY_REQUEST_H_ #define _PACKAGE__ADD_REPOSITORY_REQUEST_H_
#include <String.h> #include <String.h>
@@ -12,22 +12,20 @@
#include <package/Request.h> #include <package/Request.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
namespace Private { namespace BPrivate {
class ActivateRepositoryConfigJob; class ActivateRepositoryConfigJob;
} }
using Private::ActivateRepositoryConfigJob; using BPrivate::ActivateRepositoryConfigJob;
class AddRepositoryRequest : public Request { class AddRepositoryRequest : public BRequest {
typedef Request inherited; typedef BRequest inherited;
public: public:
AddRepositoryRequest(const Context& context, AddRepositoryRequest(const BContext& context,
const BString& repositoryBaseURL, const BString& repositoryBaseURL,
bool asUserRepository); bool asUserRepository);
virtual ~AddRepositoryRequest(); virtual ~AddRepositoryRequest();
@@ -37,8 +35,8 @@ public:
const BString& RepositoryName() const; const BString& RepositoryName() const;
protected: protected:
// JobStateListener // BJobStateListener
virtual void JobSucceeded(Job* job); virtual void JobSucceeded(BJob* job);
private: private:
BString fRepositoryBaseURL; BString fRepositoryBaseURL;
@@ -50,9 +48,7 @@ private:
}; };
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__ADD_REPOSITORY_REQUEST_H_ #endif // _PACKAGE__ADD_REPOSITORY_REQUEST_H_
+12 -16
View File
@@ -2,30 +2,26 @@
* Copyright 2011, Haiku, Inc. * Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__ATTRIBUTES_H_ #ifndef _PACKAGE__ATTRIBUTES_H_
#define _HAIKU__PACKAGE__ATTRIBUTES_H_ #define _PACKAGE__ATTRIBUTES_H_
namespace Haiku { namespace BPackageKit {
namespace Package {
// attributes used in package and as file attribute, too // attributes used in package and as file attribute, too
extern const char* kNameAttribute; extern const char* kPackageNameAttribute;
extern const char* kVendorAttribute; extern const char* kPackageVendorAttribute;
extern const char* kVersionAttribute; extern const char* kPackageVersionAttribute;
// attributes kept local to packages // attributes kept local to packages
extern const char* kCopyrightAttribute; extern const char* kPackageCopyrightAttribute;
extern const char* kLicenseAttribute; extern const char* kPackageLicenseAttribute;
extern const char* kProvidesAttribute; extern const char* kPackageProvidesAttribute;
extern const char* kRequiresAttribute; extern const char* kPackageRequiresAttribute;
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__ATTRIBUTES_H_ #endif // _PACKAGE__ATTRIBUTES_H_
+29 -24
View File
@@ -2,24 +2,25 @@
* Copyright 2011, Haiku, Inc. * Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__CONTEXT_H_ #ifndef _PACKAGE__CONTEXT_H_
#define _HAIKU__PACKAGE__CONTEXT_H_ #define _PACKAGE__CONTEXT_H_
#include <package/TempfileManager.h> #include <Entry.h>
#include <String.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
class JobStateListener; class BJobStateListener;
using Private::TempfileManager; namespace BPrivate {
class TempfileManager;
}
struct DecisionProvider { struct BDecisionProvider {
virtual ~DecisionProvider(); virtual ~BDecisionProvider();
virtual bool YesNoDecisionNeeded(const BString& description, virtual bool YesNoDecisionNeeded(const BString& description,
const BString& question, const BString& question,
@@ -33,28 +34,32 @@ struct DecisionProvider {
}; };
class Context { class BContext {
public: public:
Context(DecisionProvider& decisionProvider); BContext(BDecisionProvider& decisionProvider,
~Context(); BJobStateListener& jobStateListener);
~BContext();
TempfileManager& GetTempfileManager() const; status_t InitCheck() const;
JobStateListener* GetJobStateListener() const; status_t GetNewTempfile(const BString& baseName,
void SetJobStateListener(JobStateListener* listener); BEntry* entry) const;
DecisionProvider& GetDecisionProvider() const; BDecisionProvider& DecisionProvider() const;
BJobStateListener& JobStateListener() const;
private: private:
mutable TempfileManager fTempfileManager; status_t _Initialize();
DecisionProvider& fDecisionProvider;
JobStateListener* fJobStateListener; BDecisionProvider& fDecisionProvider;
BJobStateListener& fJobStateListener;
status_t fInitStatus;
mutable BPrivate::TempfileManager* fTempfileManager;
}; };
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__CONTEXT_H_ #endif // _PACKAGE__CONTEXT_H_
+44 -32
View File
@@ -2,35 +2,33 @@
* Copyright 2011, Haiku, Inc. * Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__JOB_H_ #ifndef _PACKAGE__JOB_H_
#define _HAIKU__PACKAGE__JOB_H_ #define _PACKAGE__JOB_H_
#include <ObjectList.h> #include <ObjectList.h>
#include <String.h> #include <String.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
class Context; class BContext;
class Job; class BJob;
struct JobStateListener { struct BJobStateListener {
virtual ~JobStateListener(); virtual ~BJobStateListener();
// these default implementations do nothing // these default implementations do nothing
virtual void JobStarted(Job* job); virtual void JobStarted(BJob* job);
virtual void JobSucceeded(Job* job); virtual void JobSucceeded(BJob* job);
virtual void JobFailed(Job* job); virtual void JobFailed(BJob* job);
virtual void JobAborted(Job* job); virtual void JobAborted(BJob* job);
}; };
enum JobState { enum BJobState {
JOB_STATE_WAITING_TO_RUN, JOB_STATE_WAITING_TO_RUN,
JOB_STATE_RUNNING, JOB_STATE_RUNNING,
JOB_STATE_SUCCEEDED, JOB_STATE_SUCCEEDED,
@@ -39,30 +37,38 @@ enum JobState {
}; };
class Job { namespace BPrivate {
class JobQueue;
}
class BJob {
public: public:
Job(const Context& context, BJob(const BContext& context,
const BString& title); const BString& title);
virtual ~Job(); virtual ~BJob();
status_t InitCheck() const; status_t InitCheck() const;
virtual status_t Run(); virtual status_t Run();
const BString& Title() const; const BString& Title() const;
JobState State() const; BJobState State() const;
status_t Result() const; status_t Result() const;
const BString& ErrorString() const; const BString& ErrorString() const;
status_t AddStateListener(JobStateListener* listener); uint32 TicketNumber() const;
status_t RemoveStateListener(
JobStateListener* listener);
status_t AddDependency(Job* job); status_t AddStateListener(BJobStateListener* listener);
status_t RemoveDependency(Job* job); status_t RemoveStateListener(
BJobStateListener* listener);
bool IsRunnable() const;
status_t AddDependency(BJob* job);
status_t RemoveDependency(BJob* job);
int32 CountDependencies() const; int32 CountDependencies() const;
Job* DependantJobAt(int32 index) const; BJob* DependantJobAt(int32 index) const;
protected: protected:
virtual status_t Execute() = 0; virtual status_t Execute() = 0;
virtual void Cleanup(status_t jobResult); virtual void Cleanup(status_t jobResult);
@@ -71,27 +77,33 @@ protected:
void NotifyStateListeners(); void NotifyStateListeners();
const Context& fContext; const BContext& fContext;
private:
friend class BPrivate::JobQueue;
void _SetTicketNumber(uint32 ticketNumber);
void _ClearTicketNumber();
private: private:
status_t fInitStatus; status_t fInitStatus;
BString fTitle; BString fTitle;
JobState fState; BJobState fState;
status_t fResult; status_t fResult;
BString fErrorString; BString fErrorString;
typedef BObjectList<Job> JobList; uint32 fTicketNumber;
typedef BObjectList<BJob> JobList;
JobList fDependencies; JobList fDependencies;
JobList fDependantJobs; JobList fDependantJobs;
typedef BObjectList<JobStateListener> StateListenerList; typedef BObjectList<BJobStateListener> StateListenerList;
StateListenerList fStateListeners; StateListenerList fStateListeners;
}; };
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__JOB_H_ #endif // _PACKAGE__JOB_H_
@@ -2,26 +2,23 @@
* Copyright 2011, Haiku, Inc. * Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__ROSTER_H_ #ifndef _PACKAGE__ROSTER_H_
#define _HAIKU__PACKAGE__ROSTER_H_ #define _PACKAGE__ROSTER_H_
#include <Entry.h> #include <Entry.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Path.h> #include <Path.h>
#include <SupportDefs.h>
template <class T> class BObjectList; template <class T> class BObjectList;
namespace Haiku { namespace BPackageKit {
namespace Package {
struct RepositoryConfigVisitor { struct BRepositoryConfigVisitor {
virtual ~RepositoryConfigVisitor() virtual ~BRepositoryConfigVisitor()
{ {
} }
@@ -29,14 +26,14 @@ struct RepositoryConfigVisitor {
}; };
class RepositoryCache; class BRepositoryCache;
class RepositoryConfig; class BRepositoryConfig;
class Roster { class BPackageRoster {
public: public:
Roster(); BPackageRoster();
~Roster(); ~BPackageRoster();
status_t GetCommonRepositoryCachePath(BPath* path, status_t GetCommonRepositoryCachePath(BPath* path,
bool create = false) const; bool create = false) const;
@@ -51,26 +48,24 @@ public:
status_t GetRepositoryNames(BObjectList<BString>& names); status_t GetRepositoryNames(BObjectList<BString>& names);
status_t VisitCommonRepositoryConfigs( status_t VisitCommonRepositoryConfigs(
RepositoryConfigVisitor& visitor); BRepositoryConfigVisitor& visitor);
status_t VisitUserRepositoryConfigs( status_t VisitUserRepositoryConfigs(
RepositoryConfigVisitor& visitor); BRepositoryConfigVisitor& visitor);
status_t GetRepositoryCache(const BString& name, status_t GetRepositoryCache(const BString& name,
RepositoryCache* repositoryCache); BRepositoryCache* repositoryCache);
status_t GetRepositoryConfig(const BString& name, status_t GetRepositoryConfig(const BString& name,
RepositoryConfig* repositoryConfig); BRepositoryConfig* repositoryConfig);
private: private:
status_t _GetRepositoryPath(BPath* path, bool create, status_t _GetRepositoryPath(BPath* path, bool create,
directory_which whichDir) const; directory_which whichDir) const;
status_t _VisitRepositoryConfigs(const BPath& path, status_t _VisitRepositoryConfigs(const BPath& path,
RepositoryConfigVisitor& visitor); BRepositoryConfigVisitor& visitor);
}; };
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__ROSTER_H_ #endif // _PACKAGE__ROSTER_H_
+17 -19
View File
@@ -2,8 +2,8 @@
* Copyright 2011, Haiku, Inc. * Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__REFRESH_REPOSITORY_REQUEST_H_ #ifndef _PACKAGE__REFRESH_REPOSITORY_REQUEST_H_
#define _HAIKU__PACKAGE__REFRESH_REPOSITORY_REQUEST_H_ #define _PACKAGE__REFRESH_REPOSITORY_REQUEST_H_
#include <Entry.h> #include <Entry.h>
@@ -14,43 +14,41 @@
#include <package/Request.h> #include <package/Request.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
namespace Private { namespace BPrivate {
class ValidateChecksumJob; class ValidateChecksumJob;
} }
using Private::ValidateChecksumJob; using BPrivate::ValidateChecksumJob;
class RefreshRepositoryRequest : public Request {
typedef Request inherited; class BRefreshRepositoryRequest : public BRequest {
typedef BRequest inherited;
public: public:
RefreshRepositoryRequest(const Context& context, BRefreshRepositoryRequest(
const RepositoryConfig& repoConfig); const BContext& context,
virtual ~RefreshRepositoryRequest(); const BRepositoryConfig& repoConfig);
virtual ~BRefreshRepositoryRequest();
virtual status_t CreateInitialJobs(); virtual status_t CreateInitialJobs();
protected: protected:
// JobStateListener // BJobStateListener
virtual void JobSucceeded(Job* job); virtual void JobSucceeded(BJob* job);
private: private:
status_t _FetchRepositoryCache(); status_t _FetchRepositoryCache();
BEntry fFetchedChecksumFile; BEntry fFetchedChecksumFile;
RepositoryConfig fRepoConfig; BRepositoryConfig fRepoConfig;
ValidateChecksumJob* fValidateChecksumJob; ValidateChecksumJob* fValidateChecksumJob;
}; };
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__REFRESH_REPOSITORY_REQUEST_H_ #endif // _PACKAGE__REFRESH_REPOSITORY_REQUEST_H_
+9 -13
View File
@@ -2,8 +2,8 @@
* Copyright 2011, Haiku, Inc. * Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__REPOSITORY_CACHE_H_ #ifndef _PACKAGE__REPOSITORY_CACHE_H_
#define _HAIKU__PACKAGE__REPOSITORY_CACHE_H_ #define _PACKAGE__REPOSITORY_CACHE_H_
#include <Entry.h> #include <Entry.h>
@@ -13,19 +13,17 @@
class BEntry; class BEntry;
namespace Haiku { namespace BPackageKit {
namespace Package {
//class RepositoryHeader; //class RepositoryHeader;
class RepositoryCache { class BRepositoryCache {
public: public:
RepositoryCache(); BRepositoryCache();
RepositoryCache(const BEntry& entry); BRepositoryCache(const BEntry& entry);
virtual ~RepositoryCache(); virtual ~BRepositoryCache();
status_t SetTo(const BEntry& entry); status_t SetTo(const BEntry& entry);
status_t InitCheck() const; status_t InitCheck() const;
@@ -45,9 +43,7 @@ private:
}; };
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__REPOSITORY_CACHE_H_ #endif // _PACKAGE__REPOSITORY_CACHE_H_
+12 -16
View File
@@ -2,8 +2,8 @@
* Copyright 2011, Haiku, Inc. * Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__REPOSITORY_CONFIG_H_ #ifndef _PACKAGE__REPOSITORY_CONFIG_H_
#define _HAIKU__PACKAGE__REPOSITORY_CONFIG_H_ #define _PACKAGE__REPOSITORY_CONFIG_H_
#include <Archivable.h> #include <Archivable.h>
@@ -14,22 +14,20 @@
class BEntry; class BEntry;
namespace Haiku { namespace BPackageKit {
namespace Package {
class RepositoryConfig : public BArchivable { class BRepositoryConfig : public BArchivable {
typedef BArchivable inherited; typedef BArchivable inherited;
public: public:
RepositoryConfig(); BRepositoryConfig();
RepositoryConfig(const BString& name, BRepositoryConfig(const BString& name,
const BString& url, const BString& url,
uint8 priority = kDefaultPriority); uint8 priority = kDefaultPriority);
RepositoryConfig(const BEntry& entry); BRepositoryConfig(const BEntry& entry);
RepositoryConfig(BMessage* data); BRepositoryConfig(BMessage* data);
virtual ~RepositoryConfig(); virtual ~BRepositoryConfig();
virtual status_t Archive(BMessage* data, bool deep = true) const; virtual status_t Archive(BMessage* data, bool deep = true) const;
@@ -52,7 +50,7 @@ public:
void SetIsUserSpecific(bool isUserSpecific); void SetIsUserSpecific(bool isUserSpecific);
public: public:
static RepositoryConfig* Instantiate(BMessage* data); static BRepositoryConfig* Instantiate(BMessage* data);
static const uint8 kDefaultPriority; static const uint8 kDefaultPriority;
static const char* kNameField; static const char* kNameField;
@@ -71,9 +69,7 @@ private:
}; };
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__REPOSITORY_CONFIG_H_ #endif // _PACKAGE__REPOSITORY_CONFIG_H_
+21 -19
View File
@@ -2,46 +2,48 @@
* Copyright 2011, Haiku, Inc. * Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__REQUEST_H_ #ifndef _PACKAGE__REQUEST_H_
#define _HAIKU__PACKAGE__REQUEST_H_ #define _PACKAGE__REQUEST_H_
#include <SupportDefs.h> #include <SupportDefs.h>
#include <package/JobQueue.h> #include <package/Job.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
class Context; class BContext;
using Private::JobQueue; namespace BPrivate {
class JobQueue;
}
using BPrivate::JobQueue;
class Request : protected JobStateListener { class BRequest : protected BJobStateListener {
public: public:
Request(const Context& context); BRequest(const BContext& context);
virtual ~Request(); virtual ~BRequest();
status_t InitCheck() const;
virtual status_t CreateInitialJobs() = 0; virtual status_t CreateInitialJobs() = 0;
Job* PopRunnableJob(); BJob* PopRunnableJob();
protected: protected:
status_t QueueJob(Job* job); status_t QueueJob(BJob* job);
const Context& fContext; const BContext& fContext;
private: private:
JobQueue fJobQueue; status_t fInitStatus;
JobQueue* fJobQueue;
}; };
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__REQUEST_H_ #endif // _PACKAGE__REQUEST_H_
@@ -2,8 +2,8 @@
* Copyright 2011, Oliver Tappe <[email protected]> * Copyright 2011, Oliver Tappe <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CACHE_JOB_H_ #ifndef _PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CACHE_JOB_H_
#define _HAIKU__PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CACHE_JOB_H_ #define _PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CACHE_JOB_H_
#include <Directory.h> #include <Directory.h>
@@ -13,19 +13,17 @@
#include <package/Job.h> #include <package/Job.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
class ActivateRepositoryCacheJob : public Job { class ActivateRepositoryCacheJob : public BJob {
typedef Job inherited; typedef BJob inherited;
public: public:
ActivateRepositoryCacheJob( ActivateRepositoryCacheJob(
const Context& context, const BContext& context,
const BString& title, const BString& title,
const BEntry& fetchedRepoCacheEntry, const BEntry& fetchedRepoCacheEntry,
const BString& repositoryName, const BString& repositoryName,
@@ -42,11 +40,9 @@ private:
}; };
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CACHE_JOB_H_ #endif // _PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CACHE_JOB_H_
@@ -2,8 +2,8 @@
* Copyright 2011, Oliver Tappe <[email protected]> * Copyright 2011, Oliver Tappe <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_ #ifndef _PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_
#define _HAIKU__PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_ #define _PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_
#include <Directory.h> #include <Directory.h>
@@ -13,19 +13,17 @@
#include <package/Job.h> #include <package/Job.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
class ActivateRepositoryConfigJob : public Job { class ActivateRepositoryConfigJob : public BJob {
typedef Job inherited; typedef BJob inherited;
public: public:
ActivateRepositoryConfigJob( ActivateRepositoryConfigJob(
const Context& context, const BContext& context,
const BString& title, const BString& title,
const BEntry& archivedRepoConfigEntry, const BEntry& archivedRepoConfigEntry,
const BString& repositoryBaseURL, const BString& repositoryBaseURL,
@@ -48,11 +46,9 @@ private:
}; };
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_ #endif // _PACKAGE__PRIVATE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_
+7 -11
View File
@@ -2,19 +2,17 @@
* Copyright 2011, Oliver Tappe <[email protected]> * Copyright 2011, Oliver Tappe <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__PRIVATE__CHECKSUM_ACCESSORS_H_ #ifndef _PACKAGE__PRIVATE__CHECKSUM_ACCESSORS_H_
#define _HAIKU__PACKAGE__PRIVATE__CHECKSUM_ACCESSORS_H_ #define _PACKAGE__PRIVATE__CHECKSUM_ACCESSORS_H_
#include <Entry.h> #include <Entry.h>
#include <String.h> #include <String.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
class ChecksumAccessor { class ChecksumAccessor {
@@ -51,11 +49,9 @@ private:
}; };
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__PRIVATE__CHECKSUM_ACCESSORS_H_ #endif // _PACKAGE__PRIVATE__CHECKSUM_ACCESSORS_H_
+10 -14
View File
@@ -2,8 +2,8 @@
* Copyright 2011, Oliver Tappe <[email protected]> * Copyright 2011, Oliver Tappe <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ #ifndef _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_
#define _HAIKU__PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ #define _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_
#include <Entry.h> #include <Entry.h>
@@ -12,18 +12,16 @@
#include <package/Job.h> #include <package/Job.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
class FetchFileJob : public Job { class FetchFileJob : public BJob {
typedef Job inherited; typedef BJob inherited;
public: public:
FetchFileJob(const Context& context, FetchFileJob(const BContext& context,
const BString& title, const BString& title,
const BString& fileURL, const BString& fileURL,
const BEntry& targetEntry); const BEntry& targetEntry);
@@ -39,11 +37,9 @@ private:
}; };
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__PRIVATE__FETCH_FILE_JOB_H_ #endif // _PACKAGE__PRIVATE__FETCH_FILE_JOB_H_
+31 -20
View File
@@ -2,8 +2,8 @@
* Copyright 2011, Haiku, Inc. * Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__JOB_QUEUE_H_ #ifndef _PACKAGE__PRIVATE__JOB_QUEUE_H_
#define _HAIKU__PACKAGE__JOB_QUEUE_H_ #define _PACKAGE__PRIVATE__JOB_QUEUE_H_
#include <Locker.h> #include <Locker.h>
@@ -12,44 +12,55 @@
#include <package/Job.h> #include <package/Job.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
class JobQueue : public JobStateListener { class JobQueue : private BJobStateListener {
public: public:
JobQueue(); JobQueue();
~JobQueue(); virtual ~JobQueue();
status_t AddJob(Job* job); status_t InitCheck() const;
status_t RemoveJob(Job* job);
Job* Pop(); status_t AddJob(BJob* job);
// takes ownership
status_t RemoveJob(BJob* job);
// gives up ownership
// JobStateListener BJob* Pop();
virtual void JobSucceeded(Job* job); // caller owns job
virtual void JobFailed(Job* job);
void Close();
private:
// BJobStateListener
virtual void JobSucceeded(BJob* job);
virtual void JobFailed(BJob* job);
private: private:
struct JobPriorityLess; struct JobPriorityLess;
class JobPriorityQueue; class JobPriorityQueue;
private: private:
void _UpdateDependantJobsOf(Job* job); status_t _Init();
void _RequeueDependantJobsOf(BJob* job);
void _RemoveDependantJobsOf(BJob* job);
BLocker fLock; BLocker fLock;
uint32 fNextTicketNumber;
JobPriorityQueue* fQueuedJobs; JobPriorityQueue* fQueuedJobs;
sem_id fHaveRunnableJobSem;
status_t fInitStatus;
}; };
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__JOB_QUEUE_H_ #endif // _PACKAGE__PRIVATE__JOB_QUEUE_H_
+7 -11
View File
@@ -2,8 +2,8 @@
* Copyright 2011, Oliver Tappe <[email protected]> * Copyright 2011, Oliver Tappe <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__PRIVATE__TEMPFILE_MANAGER_H_ #ifndef _PACKAGE__PRIVATE__TEMPFILE_MANAGER_H_
#define _HAIKU__PACKAGE__PRIVATE__TEMPFILE_MANAGER_H_ #define _PACKAGE__PRIVATE__TEMPFILE_MANAGER_H_
#include <Directory.h> #include <Directory.h>
@@ -12,11 +12,9 @@
#include <SupportDefs.h> #include <SupportDefs.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
class TempfileManager { class TempfileManager {
@@ -37,11 +35,9 @@ private:
}; };
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__PRIVATE__TEMPFILE_MANAGER_H_ #endif // _PACKAGE__PRIVATE__TEMPFILE_MANAGER_H_
+10 -14
View File
@@ -2,8 +2,8 @@
* Copyright 2011, Oliver Tappe <[email protected]> * Copyright 2011, Oliver Tappe <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _HAIKU__PACKAGE__PRIVATE__VALIDATE_CHECKSUM_JOB_H_ #ifndef _PACKAGE__PRIVATE__VALIDATE_CHECKSUM_JOB_H_
#define _HAIKU__PACKAGE__PRIVATE__VALIDATE_CHECKSUM_JOB_H_ #define _PACKAGE__PRIVATE__VALIDATE_CHECKSUM_JOB_H_
#include <Directory.h> #include <Directory.h>
@@ -14,19 +14,17 @@
#include <package/Job.h> #include <package/Job.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
class ValidateChecksumJob : public Job { class ValidateChecksumJob : public BJob {
typedef Job inherited; typedef BJob inherited;
public: public:
ValidateChecksumJob( ValidateChecksumJob(
const Context& context, const BContext& context,
const BString& title, const BString& title,
ChecksumAccessor* expectedChecksumAccessor, ChecksumAccessor* expectedChecksumAccessor,
ChecksumAccessor* realChecksumAccessor, ChecksumAccessor* realChecksumAccessor,
@@ -47,11 +45,9 @@ private:
}; };
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
#endif // _HAIKU__PACKAGE__PRIVATE__VALIDATE_CHECKSUM_JOB_H_ #endif // _PACKAGE__PRIVATE__VALIDATE_CHECKSUM_JOB_H_
@@ -7,11 +7,11 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "MyDecisionProvider.h" #include "DecisionProvider.h"
bool bool
MyDecisionProvider::YesNoDecisionNeeded(const BString& description, DecisionProvider::YesNoDecisionNeeded(const BString& description,
const BString& question, const BString& yes, const BString& no, const BString& question, const BString& yes, const BString& no,
const BString& defaultChoice) const BString& defaultChoice)
{ {
@@ -2,18 +2,18 @@
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de> * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef MY_DECISION_PROVIDER_H #ifndef DECISION_PROVIDER_H
#define MY_DECISION_PROVIDER_H #define DECISION_PROVIDER_H
#include <package/Context.h> #include <package/Context.h>
struct MyDecisionProvider : public Haiku::Package::DecisionProvider { struct DecisionProvider : public BPackageKit::BDecisionProvider {
virtual bool YesNoDecisionNeeded(const BString& description, virtual bool YesNoDecisionNeeded(const BString& description,
const BString& question, const BString& yes, const BString& no, const BString& question, const BString& yes, const BString& no,
const BString& defaultChoice); const BString& defaultChoice);
}; };
#endif // MY_DECISION_PROVIDER_H #endif // DECISION_PROVIDER_H
+2 -2
View File
@@ -6,8 +6,8 @@ BinCommand pkgman :
command_add_repo.cpp command_add_repo.cpp
command_list_repos.cpp command_list_repos.cpp
command_refresh.cpp command_refresh.cpp
MyDecisionProvider.cpp DecisionProvider.cpp
MyJobStateListener.cpp JobStateListener.cpp
pkgman.cpp pkgman.cpp
: :
package be package be
@@ -6,28 +6,28 @@
#include <stdio.h> #include <stdio.h>
#include "MyJobStateListener.h" #include "JobStateListener.h"
#include "pkgman.h" #include "pkgman.h"
using Haiku::Package::Job; using BPackageKit::BJob;
void void
MyJobStateListener::JobStarted(Job* job) JobStateListener::JobStarted(BJob* job)
{ {
printf("%s ...\n", job->Title().String()); printf("%s ...\n", job->Title().String());
} }
void void
MyJobStateListener::JobSucceeded(Job* job) JobStateListener::JobSucceeded(BJob* job)
{ {
} }
void void
MyJobStateListener::JobFailed(Job* job) JobStateListener::JobFailed(BJob* job)
{ {
BString error = job->ErrorString(); BString error = job->ErrorString();
if (error.Length() > 0) { if (error.Length() > 0) {
@@ -39,7 +39,7 @@ MyJobStateListener::JobFailed(Job* job)
void void
MyJobStateListener::JobAborted(Job* job) JobStateListener::JobAborted(BJob* job)
{ {
DIE(job->Result(), "aborted"); DIE(job->Result(), "aborted");
} }
+20
View File
@@ -0,0 +1,20 @@
/*
* Copyright 2011, Oliver Tappe <[email protected]>
* Distributed under the terms of the MIT License.
*/
#ifndef JOB_STATE_LISTENER_H
#define JOB_STATE_LISTENER_H
#include <package/Job.h>
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
-20
View File
@@ -1,20 +0,0 @@
/*
* Copyright 2011, Oliver Tappe <[email protected]>
* Distributed under the terms of the MIT License.
*/
#ifndef MY_JOB_STATE_LISTENER_H
#define MY_JOB_STATE_LISTENER_H
#include <package/Job.h>
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
+19 -13
View File
@@ -14,14 +14,14 @@
#include <package/AddRepositoryRequest.h> #include <package/AddRepositoryRequest.h>
#include <package/Context.h> #include <package/Context.h>
#include <package/RefreshRepositoryRequest.h> #include <package/RefreshRepositoryRequest.h>
#include <package/Roster.h> #include <package/PackageRoster.h>
#include "MyDecisionProvider.h" #include "DecisionProvider.h"
#include "MyJobStateListener.h" #include "JobStateListener.h"
#include "pkgman.h" #include "pkgman.h"
using namespace Haiku::Package; using namespace BPackageKit;
// TODO: internationalization! // TODO: internationalization!
@@ -81,35 +81,41 @@ command_add_repo(int argc, const char* const* argv)
const char* const* repoURLs = argv + optind; const char* const* repoURLs = argv + optind;
int urlCount = argc - optind; int urlCount = argc - optind;
MyDecisionProvider decisionProvider; DecisionProvider decisionProvider;
Context context(decisionProvider); JobStateListener listener;
MyJobStateListener listener; BContext context(decisionProvider, listener);
context.SetJobStateListener(&listener);
status_t result; status_t result;
for (int i = 0; i < urlCount; ++i) { for (int i = 0; i < urlCount; ++i) {
AddRepositoryRequest addRequest(context, repoURLs[i], asUserRepository); 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(); result = addRequest.CreateInitialJobs();
if (result != B_OK) if (result != B_OK)
DIE(result, "unable to create necessary jobs"); DIE(result, "unable to create necessary jobs");
while (Job* job = addRequest.PopRunnableJob()) { while (BJob* job = addRequest.PopRunnableJob()) {
result = job->Run(); result = job->Run();
delete job; delete job;
if (result == B_CANCELED) if (result == B_CANCELED)
return 1; return 1;
} }
// now refresh the repo-cache of the new repository
BString repoName = addRequest.RepositoryName(); BString repoName = addRequest.RepositoryName();
Roster roster; BPackageRoster roster;
RepositoryConfig repoConfig; BRepositoryConfig repoConfig;
roster.GetRepositoryConfig(repoName, &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(); result = refreshRequest.CreateInitialJobs();
if (result != B_OK) if (result != B_OK)
DIE(result, "unable to create necessary jobs"); DIE(result, "unable to create necessary jobs");
while (Job* job = refreshRequest.PopRunnableJob()) { while (BJob* job = refreshRequest.PopRunnableJob()) {
result = job->Run(); result = job->Run();
delete job; delete job;
if (result == B_CANCELED) if (result == B_CANCELED)
+4 -4
View File
@@ -16,7 +16,7 @@
#include <Path.h> #include <Path.h>
#include <package/RepositoryConfig.h> #include <package/RepositoryConfig.h>
#include <package/Roster.h> #include <package/PackageRoster.h>
#include "pkgman.h" #include "pkgman.h"
@@ -24,7 +24,7 @@
// TODO: internationalization! // TODO: internationalization!
using namespace Haiku::Package; using namespace BPackageKit;
static const char* kCommandUsage = static const char* kCommandUsage =
@@ -80,14 +80,14 @@ command_list_repos(int argc, const char* const* argv)
print_command_usage_and_exit(true); print_command_usage_and_exit(true);
BObjectList<BString> repositoryNames(20, true); BObjectList<BString> repositoryNames(20, true);
Roster roster; BPackageRoster roster;
status_t result = roster.GetRepositoryNames(repositoryNames); status_t result = roster.GetRepositoryNames(repositoryNames);
if (result != B_OK) if (result != B_OK)
DIE(result, "can't collect repository names"); DIE(result, "can't collect repository names");
for (int i = 0; i < repositoryNames.CountItems(); ++i) { for (int i = 0; i < repositoryNames.CountItems(); ++i) {
const BString& repoName = *(repositoryNames.ItemAt(i)); const BString& repoName = *(repositoryNames.ItemAt(i));
RepositoryConfig repoConfig; BRepositoryConfig repoConfig;
result = roster.GetRepositoryConfig(repoName, &repoConfig); result = roster.GetRepositoryConfig(repoName, &repoConfig);
if (result != B_OK) { if (result != B_OK) {
BPath path; BPath path;
+14 -12
View File
@@ -13,14 +13,14 @@
#include <package/Context.h> #include <package/Context.h>
#include <package/RefreshRepositoryRequest.h> #include <package/RefreshRepositoryRequest.h>
#include <package/Roster.h> #include <package/PackageRoster.h>
#include "MyDecisionProvider.h" #include "DecisionProvider.h"
#include "MyJobStateListener.h" #include "JobStateListener.h"
#include "pkgman.h" #include "pkgman.h"
using namespace Haiku::Package; using namespace BPackageKit;
// TODO: internationalization! // TODO: internationalization!
@@ -70,14 +70,13 @@ command_refresh(int argc, const char* const* argv)
const char* const* repoArgs = argv + optind; const char* const* repoArgs = argv + optind;
int nameCount = argc - optind; int nameCount = argc - optind;
MyDecisionProvider decisionProvider; DecisionProvider decisionProvider;
Context context(decisionProvider); JobStateListener listener;
MyJobStateListener listener; BContext context(decisionProvider, listener);
context.SetJobStateListener(&listener);
BObjectList<BString> repositoryNames(20, true); BObjectList<BString> repositoryNames(20, true);
Roster roster; BPackageRoster roster;
if (nameCount == 0) { if (nameCount == 0) {
status_t result = roster.GetRepositoryNames(repositoryNames); status_t result = roster.GetRepositoryNames(repositoryNames);
if (result != B_OK) if (result != B_OK)
@@ -94,7 +93,7 @@ command_refresh(int argc, const char* const* argv)
status_t result; status_t result;
for (int i = 0; i < repositoryNames.CountItems(); ++i) { for (int i = 0; i < repositoryNames.CountItems(); ++i) {
const BString& repoName = *(repositoryNames.ItemAt(i)); const BString& repoName = *(repositoryNames.ItemAt(i));
RepositoryConfig repoConfig; BRepositoryConfig repoConfig;
result = roster.GetRepositoryConfig(repoName, &repoConfig); result = roster.GetRepositoryConfig(repoName, &repoConfig);
if (result != B_OK) { if (result != B_OK) {
BPath path; BPath path;
@@ -102,12 +101,15 @@ command_refresh(int argc, const char* const* argv)
WARN(result, "skipping repository-config '%s'", path.Path()); WARN(result, "skipping repository-config '%s'", path.Path());
continue; 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(); result = refreshRequest.CreateInitialJobs();
if (result != B_OK) if (result != B_OK)
DIE(result, "unable to create necessary jobs"); DIE(result, "unable to create necessary jobs");
while (Job* job = refreshRequest.PopRunnableJob()) { while (BJob* job = refreshRequest.PopRunnableJob()) {
result = job->Run(); result = job->Run();
delete job; delete job;
if (result != B_OK) if (result != B_OK)
@@ -14,14 +14,12 @@
#include <package/Context.h> #include <package/Context.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
ActivateRepositoryCacheJob::ActivateRepositoryCacheJob(const Context& context, ActivateRepositoryCacheJob::ActivateRepositoryCacheJob(const BContext& context,
const BString& title, const BEntry& fetchedRepoCacheEntry, const BString& title, const BEntry& fetchedRepoCacheEntry,
const BString& repositoryName, const BDirectory& targetDirectory) const BString& repositoryName, const BDirectory& targetDirectory)
: :
@@ -52,8 +50,6 @@ ActivateRepositoryCacheJob::Execute()
} }
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
@@ -15,16 +15,15 @@
#include <package/RepositoryConfig.h> #include <package/RepositoryConfig.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
ActivateRepositoryConfigJob::ActivateRepositoryConfigJob(const Context& context, ActivateRepositoryConfigJob::ActivateRepositoryConfigJob(
const BString& title, const BEntry& archivedRepoConfigEntry, const BContext& context, const BString& title,
const BString& repositoryBaseURL, const BDirectory& targetDirectory) const BEntry& archivedRepoConfigEntry, const BString& repositoryBaseURL,
const BDirectory& targetDirectory)
: :
inherited(context, title), inherited(context, title),
fArchivedRepoConfigEntry(archivedRepoConfigEntry), fArchivedRepoConfigEntry(archivedRepoConfigEntry),
@@ -51,7 +50,7 @@ ActivateRepositoryConfigJob::Execute()
if ((result = archive.Unflatten(&archiveFile)) != B_OK) if ((result = archive.Unflatten(&archiveFile)) != B_OK)
return result; return result;
RepositoryConfig* repoConfig = RepositoryConfig::Instantiate(&archive); BRepositoryConfig* repoConfig = BRepositoryConfig::Instantiate(&archive);
if (repoConfig == NULL) if (repoConfig == NULL)
return B_BAD_DATA; return B_BAD_DATA;
if ((result = repoConfig->InitCheck()) != B_OK) if ((result = repoConfig->InitCheck()) != B_OK)
@@ -62,7 +61,7 @@ ActivateRepositoryConfigJob::Execute()
BString description = BString("A repository configuration for ") BString description = BString("A repository configuration for ")
<< repoConfig->Name() << " already exists."; << repoConfig->Name() << " already exists.";
BString question("overwrite?"); BString question("overwrite?");
bool yes = fContext.GetDecisionProvider().YesNoDecisionNeeded( bool yes = fContext.DecisionProvider().YesNoDecisionNeeded(
description, question, "yes", "no", "no"); description, question, "yes", "no", "no");
if (!yes) { if (!yes) {
fTargetEntry.Unset(); fTargetEntry.Unset();
@@ -98,8 +97,6 @@ ActivateRepositoryConfigJob::RepositoryName() const
} }
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
+16 -14
View File
@@ -15,18 +15,16 @@
#include <package/ActivateRepositoryConfigJob.h> #include <package/ActivateRepositoryConfigJob.h>
#include <package/FetchFileJob.h> #include <package/FetchFileJob.h>
#include <package/JobQueue.h> #include <package/JobQueue.h>
#include <package/Roster.h> #include <package/PackageRoster.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
using namespace Private; using namespace BPrivate;
AddRepositoryRequest::AddRepositoryRequest(const Context& context, AddRepositoryRequest::AddRepositoryRequest(const BContext& context,
const BString& repositoryBaseURL, bool asUserRepository) const BString& repositoryBaseURL, bool asUserRepository)
: :
inherited(context), inherited(context),
@@ -45,20 +43,26 @@ AddRepositoryRequest::~AddRepositoryRequest()
status_t status_t
AddRepositoryRequest::CreateInitialJobs() 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"; BString repoHeaderURL = BString(fRepositoryBaseURL) << "/" << "repo.header";
FetchFileJob* fetchJob = new (std::nothrow) FetchFileJob(fContext, FetchFileJob* fetchJob = new (std::nothrow) FetchFileJob(fContext,
BString("Fetching repository header from ") << fRepositoryBaseURL, BString("Fetching repository header from ") << fRepositoryBaseURL,
repoHeaderURL, tempEntry); repoHeaderURL, tempEntry);
if (fetchJob == NULL) if (fetchJob == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
status_t result = QueueJob(fetchJob); if ((result = QueueJob(fetchJob)) != B_OK) {
if (result != B_OK) {
delete fetchJob; delete fetchJob;
return result; return result;
} }
Roster roster; BPackageRoster roster;
BPath targetRepoConfigPath; BPath targetRepoConfigPath;
result = fAsUserRepository result = fAsUserRepository
? roster.GetUserRepositoryConfigPath(&targetRepoConfigPath, true) ? roster.GetUserRepositoryConfigPath(&targetRepoConfigPath, true)
@@ -84,7 +88,7 @@ AddRepositoryRequest::CreateInitialJobs()
void void
AddRepositoryRequest::JobSucceeded(Job* job) AddRepositoryRequest::JobSucceeded(BJob* job)
{ {
if (job == fActivateJob) if (job == fActivateJob)
fRepositoryName = fActivateJob->RepositoryName(); fRepositoryName = fActivateJob->RepositoryName();
@@ -98,6 +102,4 @@ AddRepositoryRequest::RepositoryName() const
} }
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
+10 -14
View File
@@ -10,24 +10,20 @@
#include <package/Attributes.h> #include <package/Attributes.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
// attributes used in package and as file attribute, too // attributes used in package and as file attribute, too
const char* kNameAttribute = "PKG:name"; const char* kPackageNameAttribute = "PKG:name";
const char* kPlatformAttribute = "PKG:platform"; const char* kPackagePlatformAttribute = "PKG:platform";
const char* kVendorAttribute = "PKG:vendor"; const char* kPackageVendorAttribute = "PKG:vendor";
const char* kVersionAttribute = "PKG:version"; const char* kPackageVersionAttribute = "PKG:version";
// attributes kept local to packages // attributes kept local to packages
const char* kCopyrightAttribute = "PKG:copyright"; const char* kPackageCopyrightAttribute = "PKG:copyright";
const char* kLicenseAttribute = "PKG:license"; const char* kPackageLicenseAttribute = "PKG:license";
const char* kProvidesAttribute = "PKG:provides"; const char* kPackageProvidesAttribute = "PKG:provides";
const char* kRequiresAttribute = "PKG:requires"; const char* kPackageRequiresAttribute = "PKG:requires";
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
+4 -8
View File
@@ -15,11 +15,9 @@
#include <package/ChecksumAccessors.h> #include <package/ChecksumAccessors.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
#define NIBBLE_AS_HEX(nibble) \ #define NIBBLE_AS_HEX(nibble) \
@@ -129,8 +127,6 @@ GeneralFileChecksumAccessor::GetChecksum(BString& checksum) const
} }
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
+62 -32
View File
@@ -7,7 +7,10 @@
*/ */
#include <new>
#include <package/Context.h> #include <package/Context.h>
#include <package/TempfileManager.h>
#include <Directory.h> #include <Directory.h>
#include <FindDirectory.h> #include <FindDirectory.h>
@@ -15,66 +18,93 @@
#include <Path.h> #include <Path.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
DecisionProvider::~DecisionProvider() using BPrivate::TempfileManager;
BDecisionProvider::~BDecisionProvider()
{ {
} }
Context::Context(DecisionProvider& decisionProvider) BContext::BContext(BDecisionProvider& decisionProvider,
BJobStateListener& jobStateListener)
: :
fDecisionProvider(decisionProvider), fDecisionProvider(decisionProvider),
fJobStateListener(NULL) fJobStateListener(jobStateListener),
fTempfileManager(NULL)
{ {
BPath tempPath; fInitStatus = _Initialize();
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);
} }
Context::~Context() BContext::~BContext()
{ {
delete fTempfileManager;
} }
TempfileManager& status_t
Context::GetTempfileManager() const BContext::InitCheck() const
{ {
return fTempfileManager; return fInitStatus;
} }
JobStateListener* status_t
Context::GetJobStateListener() const 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; return fJobStateListener;
} }
void BDecisionProvider&
Context::SetJobStateListener(JobStateListener* listener) BContext::DecisionProvider() const
{
fJobStateListener = listener;
}
DecisionProvider&
Context::GetDecisionProvider() const
{ {
return fDecisionProvider; 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
+5 -9
View File
@@ -15,14 +15,12 @@
#include <Path.h> #include <Path.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
FetchFileJob::FetchFileJob(const Context& context, const BString& title, FetchFileJob::FetchFileJob(const BContext& context, const BString& title,
const BString& fileURL, const BEntry& targetEntry) const BString& fileURL, const BEntry& targetEntry)
: :
inherited(context, title), inherited(context, title),
@@ -67,8 +65,6 @@ FetchFileJob::Cleanup(status_t jobResult)
} }
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
+1 -1
View File
@@ -13,12 +13,12 @@ SharedLibrary libpackage.so
FetchFileJob.cpp FetchFileJob.cpp
Job.cpp Job.cpp
JobQueue.cpp JobQueue.cpp
PackageRoster.cpp
RefreshRepositoryRequest.cpp RefreshRepositoryRequest.cpp
RepositoryCache.cpp RepositoryCache.cpp
RepositoryConfig.cpp RepositoryConfig.cpp
# RepositoryHeader.cpp # RepositoryHeader.cpp
Request.cpp Request.cpp
Roster.cpp
TempfileManager.cpp TempfileManager.cpp
ValidateChecksumJob.cpp ValidateChecksumJob.cpp
: :
+57 -32
View File
@@ -14,45 +14,44 @@
#include <package/Context.h> #include <package/Context.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
JobStateListener::~JobStateListener() BJobStateListener::~BJobStateListener()
{ {
} }
void void
JobStateListener::JobStarted(Job* job) BJobStateListener::JobStarted(BJob* job)
{ {
} }
void void
JobStateListener::JobSucceeded(Job* job) BJobStateListener::JobSucceeded(BJob* job)
{ {
} }
void void
JobStateListener::JobFailed(Job* job) BJobStateListener::JobFailed(BJob* job)
{ {
} }
void 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), fContext(context),
fTitle(title), fTitle(title),
fState(JOB_STATE_WAITING_TO_RUN) fState(JOB_STATE_WAITING_TO_RUN),
fTicketNumber(0xFFFFFFFFUL)
{ {
if (fTitle.Length() == 0) if (fTitle.Length() == 0)
fInitStatus = B_BAD_VALUE; fInitStatus = B_BAD_VALUE;
@@ -61,55 +60,76 @@ Job::Job(const Context& context, const BString& title)
} }
Job::~Job() BJob::~BJob()
{ {
} }
status_t status_t
Job::InitCheck() const BJob::InitCheck() const
{ {
return fInitStatus; return fInitStatus;
} }
const BString& const BString&
Job::Title() const BJob::Title() const
{ {
return fTitle; return fTitle;
} }
JobState BJobState
Job::State() const BJob::State() const
{ {
return fState; return fState;
} }
status_t status_t
Job::Result() const BJob::Result() const
{ {
return fResult; return fResult;
} }
const BString& const BString&
Job::ErrorString() const BJob::ErrorString() const
{ {
return fErrorString; return fErrorString;
} }
uint32
BJob::TicketNumber() const
{
return fTicketNumber;
}
void 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; fErrorString = error;
} }
status_t status_t
Job::Run() BJob::Run()
{ {
if (fState != JOB_STATE_WAITING_TO_RUN) if (fState != JOB_STATE_WAITING_TO_RUN)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
@@ -132,27 +152,27 @@ Job::Run()
void void
Job::Cleanup(status_t /*jobResult*/) BJob::Cleanup(status_t /*jobResult*/)
{ {
} }
status_t status_t
Job::AddStateListener(JobStateListener* listener) BJob::AddStateListener(BJobStateListener* listener)
{ {
return fStateListeners.AddItem(listener) ? B_OK : B_ERROR; return fStateListeners.AddItem(listener) ? B_OK : B_ERROR;
} }
status_t status_t
Job::RemoveStateListener(JobStateListener* listener) BJob::RemoveStateListener(BJobStateListener* listener)
{ {
return fStateListeners.RemoveItem(listener) ? B_OK : B_ERROR; return fStateListeners.RemoveItem(listener) ? B_OK : B_ERROR;
} }
status_t status_t
Job::AddDependency(Job* job) BJob::AddDependency(BJob* job)
{ {
if (fDependencies.HasItem(job)) if (fDependencies.HasItem(job))
return B_ERROR; return B_ERROR;
@@ -165,7 +185,7 @@ Job::AddDependency(Job* job)
status_t status_t
Job::RemoveDependency(Job* job) BJob::RemoveDependency(BJob* job)
{ {
if (!fDependencies.HasItem(job)) if (!fDependencies.HasItem(job))
return B_ERROR; return B_ERROR;
@@ -177,26 +197,33 @@ Job::RemoveDependency(Job* job)
} }
bool
BJob::IsRunnable() const
{
return fDependencies.IsEmpty();
}
int32 int32
Job::CountDependencies() const BJob::CountDependencies() const
{ {
return fDependencies.CountItems(); return fDependencies.CountItems();
} }
Job* BJob*
Job::DependantJobAt(int32 index) const BJob::DependantJobAt(int32 index) const
{ {
return fDependantJobs.ItemAt(index); return fDependantJobs.ItemAt(index);
} }
void void
Job::NotifyStateListeners() BJob::NotifyStateListeners()
{ {
int32 count = fStateListeners.CountItems(); int32 count = fStateListeners.CountItems();
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
JobStateListener* listener = fStateListeners.ItemAt(i); BJobStateListener* listener = fStateListeners.ItemAt(i);
if (listener == NULL) if (listener == NULL)
continue; continue;
switch (fState) { switch (fState) {
@@ -219,6 +246,4 @@ Job::NotifyStateListeners()
} }
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
+119 -33
View File
@@ -16,20 +16,23 @@
#include <package/Job.h> #include <package/Job.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
struct JobQueue::JobPriorityLess { 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 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(); int32 difference = left->CountDependencies() - right->CountDependencies();
if (difference < 0) if (difference < 0)
@@ -37,21 +40,21 @@ JobQueue::JobPriorityLess::operator()(const Job* left, const Job* right) const
if (difference > 0) if (difference > 0)
return false; return false;
return left->Title() < right->Title(); return left->TicketNumber() < right->TicketNumber();
}; };
class JobQueue::JobPriorityQueue class JobQueue::JobPriorityQueue
: public std::set<Job*, JobPriorityLess> { : public std::set<BJob*, JobPriorityLess> {
}; };
JobQueue::JobQueue() JobQueue::JobQueue()
: :
fLock("job queue"), fLock("job queue"),
fQueuedJobs(new (std::nothrow) JobPriorityQueue()) fNextTicketNumber(1)
{ {
fInitStatus = _Init();
} }
@@ -61,7 +64,14 @@ JobQueue::~JobQueue()
status_t status_t
JobQueue::AddJob(Job* job) JobQueue::InitCheck() const
{
return fInitStatus;
}
status_t
JobQueue::AddJob(BJob* job)
{ {
if (fQueuedJobs == NULL) if (fQueuedJobs == NULL)
return B_NO_INIT; return B_NO_INIT;
@@ -69,12 +79,14 @@ JobQueue::AddJob(Job* job)
BAutolock lock(&fLock); BAutolock lock(&fLock);
if (lock.IsLocked()) { if (lock.IsLocked()) {
try { try {
fQueuedJobs->insert(job); if (!fQueuedJobs->insert(job).second)
return B_NAME_IN_USE;
} catch (const std::bad_alloc& e) { } catch (const std::bad_alloc& e) {
return B_NO_MEMORY; return B_NO_MEMORY;
} catch (...) { } catch (...) {
return B_NO_MEMORY; return B_ERROR;
} }
job->_SetTicketNumber(fNextTicketNumber++);
job->AddStateListener(this); job->AddStateListener(this);
} }
@@ -83,7 +95,7 @@ JobQueue::AddJob(Job* job)
status_t status_t
JobQueue::RemoveJob(Job* job) JobQueue::RemoveJob(BJob* job)
{ {
if (fQueuedJobs == NULL) if (fQueuedJobs == NULL)
return B_NO_INIT; return B_NO_INIT;
@@ -91,10 +103,12 @@ JobQueue::RemoveJob(Job* job)
BAutolock lock(&fLock); BAutolock lock(&fLock);
if (lock.IsLocked()) { if (lock.IsLocked()) {
try { try {
fQueuedJobs->erase(job); if (fQueuedJobs->erase(job) == 0)
return B_NAME_NOT_FOUND;
} catch (...) { } catch (...) {
return B_ERROR; return B_ERROR;
} }
job->_ClearTicketNumber();
job->RemoveStateListener(this); job->RemoveStateListener(this);
} }
@@ -103,20 +117,24 @@ JobQueue::RemoveJob(Job* job)
void void
JobQueue::JobSucceeded(Job* job) JobQueue::JobSucceeded(BJob* job)
{ {
_UpdateDependantJobsOf(job); BAutolock lock(&fLock);
if (lock.IsLocked())
_RequeueDependantJobsOf(job);
} }
void void
JobQueue::JobFailed(Job* job) JobQueue::JobFailed(BJob* job)
{ {
_UpdateDependantJobsOf(job); BAutolock lock(&fLock);
if (lock.IsLocked())
_RemoveDependantJobsOf(job);
} }
Job* BJob*
JobQueue::Pop() JobQueue::Pop()
{ {
BAutolock lock(&fLock); BAutolock lock(&fLock);
@@ -124,6 +142,23 @@ JobQueue::Pop()
JobPriorityQueue::iterator head = fQueuedJobs->begin(); JobPriorityQueue::iterator head = fQueuedJobs->begin();
if (head == fQueuedJobs->end()) if (head == fQueuedJobs->end())
return NULL; 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); fQueuedJobs->erase(head);
return *head; return *head;
} }
@@ -133,27 +168,78 @@ JobQueue::Pop()
void void
JobQueue::_UpdateDependantJobsOf(Job* job) JobQueue::Close()
{ {
if (fHaveRunnableJobSem < 0)
return;
BAutolock lock(&fLock); BAutolock lock(&fLock);
if (lock.IsLocked()) { if (lock.IsLocked()) {
while (Job* dependantJob = job->DependantJobAt(0)) { delete_sem(fHaveRunnableJobSem);
try { fHaveRunnableJobSem = -1;
fQueuedJobs->erase(dependantJob);
} catch (...) { if (fQueuedJobs != NULL) {
} // get rid of all jobs
dependantJob->RemoveDependency(job); for (JobPriorityQueue::iterator iter = fQueuedJobs->begin();
try { iter != fQueuedJobs->end(); ++iter) {
fQueuedJobs->insert(dependantJob); delete (*iter);
} catch (...) {
} }
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
@@ -7,7 +7,7 @@
*/ */
#include <package/Roster.h> #include <package/PackageRoster.h>
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
@@ -22,51 +22,49 @@
#include <package/RepositoryConfig.h> #include <package/RepositoryConfig.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
Roster::Roster() BPackageRoster::BPackageRoster()
{ {
} }
Roster::~Roster() BPackageRoster::~BPackageRoster()
{ {
} }
status_t status_t
Roster::GetCommonRepositoryConfigPath(BPath* path, bool create) const BPackageRoster::GetCommonRepositoryConfigPath(BPath* path, bool create) const
{ {
return _GetRepositoryPath(path, create, B_COMMON_SETTINGS_DIRECTORY); return _GetRepositoryPath(path, create, B_COMMON_SETTINGS_DIRECTORY);
} }
status_t status_t
Roster::GetUserRepositoryConfigPath(BPath* path, bool create) const BPackageRoster::GetUserRepositoryConfigPath(BPath* path, bool create) const
{ {
return _GetRepositoryPath(path, create, B_USER_SETTINGS_DIRECTORY); return _GetRepositoryPath(path, create, B_USER_SETTINGS_DIRECTORY);
} }
status_t status_t
Roster::GetCommonRepositoryCachePath(BPath* path, bool create) const BPackageRoster::GetCommonRepositoryCachePath(BPath* path, bool create) const
{ {
return _GetRepositoryPath(path, create, B_COMMON_CACHE_DIRECTORY); return _GetRepositoryPath(path, create, B_COMMON_CACHE_DIRECTORY);
} }
status_t status_t
Roster::GetUserRepositoryCachePath(BPath* path, bool create) const BPackageRoster::GetUserRepositoryCachePath(BPath* path, bool create) const
{ {
return _GetRepositoryPath(path, create, B_USER_CACHE_DIRECTORY); return _GetRepositoryPath(path, create, B_USER_CACHE_DIRECTORY);
} }
status_t status_t
Roster::VisitCommonRepositoryConfigs(RepositoryConfigVisitor& visitor) BPackageRoster::VisitCommonRepositoryConfigs(BRepositoryConfigVisitor& visitor)
{ {
BPath commonRepositoryConfigPath; BPath commonRepositoryConfigPath;
status_t result status_t result
@@ -79,7 +77,7 @@ Roster::VisitCommonRepositoryConfigs(RepositoryConfigVisitor& visitor)
status_t status_t
Roster::VisitUserRepositoryConfigs(RepositoryConfigVisitor& visitor) BPackageRoster::VisitUserRepositoryConfigs(BRepositoryConfigVisitor& visitor)
{ {
BPath userRepositoryConfigPath; BPath userRepositoryConfigPath;
status_t result = GetUserRepositoryConfigPath(&userRepositoryConfigPath); status_t result = GetUserRepositoryConfigPath(&userRepositoryConfigPath);
@@ -91,9 +89,9 @@ Roster::VisitUserRepositoryConfigs(RepositoryConfigVisitor& visitor)
status_t status_t
Roster::GetRepositoryNames(BObjectList<BString>& names) BPackageRoster::GetRepositoryNames(BObjectList<BString>& names)
{ {
struct RepositoryNameCollector : public RepositoryConfigVisitor { struct RepositoryNameCollector : public BRepositoryConfigVisitor {
RepositoryNameCollector(BObjectList<BString>& _names) RepositoryNameCollector(BObjectList<BString>& _names)
: names(_names) : names(_names)
{ {
@@ -124,8 +122,8 @@ Roster::GetRepositoryNames(BObjectList<BString>& names)
status_t status_t
Roster::GetRepositoryCache(const BString& name, BPackageRoster::GetRepositoryCache(const BString& name,
RepositoryCache* repositoryCache) BRepositoryCache* repositoryCache)
{ {
if (repositoryCache == NULL) if (repositoryCache == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -151,8 +149,8 @@ Roster::GetRepositoryCache(const BString& name,
status_t status_t
Roster::GetRepositoryConfig(const BString& name, BPackageRoster::GetRepositoryConfig(const BString& name,
RepositoryConfig* repositoryConfig) BRepositoryConfig* repositoryConfig)
{ {
if (repositoryConfig == NULL) if (repositoryConfig == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -178,7 +176,7 @@ Roster::GetRepositoryConfig(const BString& name,
status_t status_t
Roster::_GetRepositoryPath(BPath* path, bool create, BPackageRoster::_GetRepositoryPath(BPath* path, bool create,
directory_which whichDir) const directory_which whichDir) const
{ {
if (path == NULL) if (path == NULL)
@@ -203,8 +201,8 @@ Roster::_GetRepositoryPath(BPath* path, bool create,
status_t status_t
Roster::_VisitRepositoryConfigs(const BPath& path, BPackageRoster::_VisitRepositoryConfigs(const BPath& path,
RepositoryConfigVisitor& visitor) BRepositoryConfigVisitor& visitor)
{ {
BDirectory directory(path.Path()); BDirectory directory(path.Path());
status_t result = directory.InitCheck(); status_t result = directory.InitCheck();
@@ -223,6 +221,4 @@ Roster::_VisitRepositoryConfigs(const BPath& path,
} }
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
+25 -23
View File
@@ -19,19 +19,17 @@
#include <package/JobQueue.h> #include <package/JobQueue.h>
#include <package/RepositoryCache.h> #include <package/RepositoryCache.h>
#include <package/RepositoryConfig.h> #include <package/RepositoryConfig.h>
#include <package/Roster.h> #include <package/PackageRoster.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
using namespace Private; using namespace BPrivate;
RefreshRepositoryRequest::RefreshRepositoryRequest(const Context& context, BRefreshRepositoryRequest::BRefreshRepositoryRequest(const BContext& context,
const RepositoryConfig& repoConfig) const BRepositoryConfig& repoConfig)
: :
inherited(context), inherited(context),
fRepoConfig(repoConfig) fRepoConfig(repoConfig)
@@ -39,23 +37,26 @@ RefreshRepositoryRequest::RefreshRepositoryRequest(const Context& context,
} }
RefreshRepositoryRequest::~RefreshRepositoryRequest() BRefreshRepositoryRequest::~BRefreshRepositoryRequest()
{ {
} }
status_t status_t
RefreshRepositoryRequest::CreateInitialJobs() BRefreshRepositoryRequest::CreateInitialJobs()
{ {
Roster roster; status_t result = InitCheck();
status_t result = fRepoConfig.InitCheck();
if (result != B_OK) if (result != B_OK)
return B_NO_INIT;
if ((result = fRepoConfig.InitCheck()) != B_OK)
return result; return result;
// fetch the current checksum and compare with our cache's checksum, // fetch the current checksum and compare with our cache's checksum,
// if they differ, fetch the updated cache // if they differ, fetch the updated cache
fFetchedChecksumFile result = fContext.GetNewTempfile("repochecksum-", &fFetchedChecksumFile);
= fContext.GetTempfileManager().Create("repochecksum-"); if (result != B_OK)
return result;
BString repoChecksumURL BString repoChecksumURL
= BString(fRepoConfig.URL()) << "/" << "repo.sha256"; = BString(fRepoConfig.URL()) << "/" << "repo.sha256";
FetchFileJob* fetchChecksumJob = new (std::nothrow) FetchFileJob( FetchFileJob* fetchChecksumJob = new (std::nothrow) FetchFileJob(
@@ -69,7 +70,8 @@ RefreshRepositoryRequest::CreateInitialJobs()
return result; return result;
} }
RepositoryCache repoCache; BRepositoryCache repoCache;
BPackageRoster roster;
roster.GetRepositoryCache(fRepoConfig.Name(), &repoCache); roster.GetRepositoryCache(fRepoConfig.Name(), &repoCache);
ValidateChecksumJob* validateChecksumJob ValidateChecksumJob* validateChecksumJob
@@ -94,7 +96,7 @@ RefreshRepositoryRequest::CreateInitialJobs()
void void
RefreshRepositoryRequest::JobSucceeded(Job* job) BRefreshRepositoryRequest::JobSucceeded(BJob* job)
{ {
if (job == fValidateChecksumJob if (job == fValidateChecksumJob
&& !fValidateChecksumJob->ChecksumsMatch()) { && !fValidateChecksumJob->ChecksumsMatch()) {
@@ -107,21 +109,23 @@ RefreshRepositoryRequest::JobSucceeded(Job* job)
status_t status_t
RefreshRepositoryRequest::_FetchRepositoryCache() BRefreshRepositoryRequest::_FetchRepositoryCache()
{ {
// download repository cache and put it in either the common/user cache // download repository cache and put it in either the common/user cache
// path, depending on where the corresponding repo-config lives // path, depending on where the corresponding repo-config lives
// job fetching the cache // 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"; BString repoCacheURL = BString(fRepoConfig.URL()) << "/" << "repo";
FetchFileJob* fetchCacheJob = new (std::nothrow) FetchFileJob(fContext, FetchFileJob* fetchCacheJob = new (std::nothrow) FetchFileJob(fContext,
BString("Fetching repository-cache from ") << fRepoConfig.URL(), BString("Fetching repository-cache from ") << fRepoConfig.URL(),
repoCacheURL, tempRepoCache); repoCacheURL, tempRepoCache);
if (fetchCacheJob == NULL) if (fetchCacheJob == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
status_t result = QueueJob(fetchCacheJob); if ((result = QueueJob(fetchCacheJob)) != B_OK) {
if (result != B_OK) {
delete fetchCacheJob; delete fetchCacheJob;
return result; return result;
} }
@@ -143,7 +147,7 @@ RefreshRepositoryRequest::_FetchRepositoryCache()
// job activating the cache // job activating the cache
BPath targetRepoCachePath; BPath targetRepoCachePath;
Roster roster; BPackageRoster roster;
result = fRepoConfig.IsUserSpecific() result = fRepoConfig.IsUserSpecific()
? roster.GetUserRepositoryCachePath(&targetRepoCachePath, true) ? roster.GetUserRepositoryCachePath(&targetRepoCachePath, true)
: roster.GetCommonRepositoryCachePath(&targetRepoCachePath, true); : roster.GetCommonRepositoryCachePath(&targetRepoCachePath, true);
@@ -166,6 +170,4 @@ RefreshRepositoryRequest::_FetchRepositoryCache()
} }
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
+10 -14
View File
@@ -19,12 +19,10 @@
#include <Path.h> #include <Path.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
RepositoryCache::RepositoryCache() BRepositoryCache::BRepositoryCache()
: :
fInitStatus(B_NO_INIT), fInitStatus(B_NO_INIT),
fIsUserSpecific(false) fIsUserSpecific(false)
@@ -32,47 +30,47 @@ RepositoryCache::RepositoryCache()
} }
RepositoryCache::RepositoryCache(const BEntry& entry) BRepositoryCache::BRepositoryCache(const BEntry& entry)
{ {
SetTo(entry); SetTo(entry);
} }
RepositoryCache::~RepositoryCache() BRepositoryCache::~BRepositoryCache()
{ {
} }
status_t status_t
RepositoryCache::InitCheck() const BRepositoryCache::InitCheck() const
{ {
return fInitStatus; return fInitStatus;
} }
const BEntry& const BEntry&
RepositoryCache::Entry() const BRepositoryCache::Entry() const
{ {
return fEntry; return fEntry;
} }
bool bool
RepositoryCache::IsUserSpecific() const BRepositoryCache::IsUserSpecific() const
{ {
return fIsUserSpecific; return fIsUserSpecific;
} }
void void
RepositoryCache::SetIsUserSpecific(bool isUserSpecific) BRepositoryCache::SetIsUserSpecific(bool isUserSpecific)
{ {
fIsUserSpecific = isUserSpecific; fIsUserSpecific = isUserSpecific;
} }
status_t status_t
RepositoryCache::SetTo(const BEntry& entry) BRepositoryCache::SetTo(const BEntry& entry)
{ {
fEntry = entry; fEntry = entry;
fInitStatus = B_NO_INIT; fInitStatus = B_NO_INIT;
@@ -101,6 +99,4 @@ RepositoryCache::SetTo(const BEntry& entry)
} }
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
+29 -33
View File
@@ -20,18 +20,16 @@
#include <Path.h> #include <Path.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
const uint8 RepositoryConfig::kDefaultPriority = 50; const uint8 BRepositoryConfig::kDefaultPriority = 50;
const char* RepositoryConfig::kNameField = "name"; const char* BRepositoryConfig::kNameField = "name";
const char* RepositoryConfig::kURLField = "url"; const char* BRepositoryConfig::kURLField = "url";
const char* RepositoryConfig::kPriorityField = "priority"; const char* BRepositoryConfig::kPriorityField = "priority";
RepositoryConfig::RepositoryConfig() BRepositoryConfig::BRepositoryConfig()
: :
fInitStatus(B_NO_INIT), fInitStatus(B_NO_INIT),
fPriority(kDefaultPriority), fPriority(kDefaultPriority),
@@ -40,13 +38,13 @@ RepositoryConfig::RepositoryConfig()
} }
RepositoryConfig::RepositoryConfig(const BEntry& entry) BRepositoryConfig::BRepositoryConfig(const BEntry& entry)
{ {
SetTo(entry); SetTo(entry);
} }
RepositoryConfig::RepositoryConfig(BMessage* data) BRepositoryConfig::BRepositoryConfig(BMessage* data)
: :
inherited(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) uint8 priority)
: :
fInitStatus(B_OK), fInitStatus(B_OK),
@@ -66,23 +64,23 @@ RepositoryConfig::RepositoryConfig(const BString& name, const BString& url,
} }
RepositoryConfig::~RepositoryConfig() BRepositoryConfig::~BRepositoryConfig()
{ {
} }
/*static*/ RepositoryConfig* /*static*/ BRepositoryConfig*
RepositoryConfig::Instantiate(BMessage* data) BRepositoryConfig::Instantiate(BMessage* data)
{ {
if (validate_instantiation(data, "Haiku::Package::RepositoryConfig")) if (validate_instantiation(data, "BPackageKit::BRepositoryConfig"))
return new (std::nothrow) RepositoryConfig(data); return new (std::nothrow) BRepositoryConfig(data);
return NULL; return NULL;
} }
status_t status_t
RepositoryConfig::Archive(BMessage* data, bool deep) const BRepositoryConfig::Archive(BMessage* data, bool deep) const
{ {
status_t result = inherited::Archive(data, deep); status_t result = inherited::Archive(data, deep);
if (result != B_OK) if (result != B_OK)
@@ -100,7 +98,7 @@ RepositoryConfig::Archive(BMessage* data, bool deep) const
status_t 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); BFile file(&entry, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
status_t result = file.InitCheck(); status_t result = file.InitCheck();
@@ -121,14 +119,14 @@ RepositoryConfig::StoreAsConfigFile(const BEntry& entry) const
status_t status_t
RepositoryConfig::InitCheck() const BRepositoryConfig::InitCheck() const
{ {
return fInitStatus; return fInitStatus;
} }
status_t status_t
RepositoryConfig::SetTo(const BEntry& entry) BRepositoryConfig::SetTo(const BEntry& entry)
{ {
fEntry = entry; fEntry = entry;
fInitStatus = B_NO_INIT; fInitStatus = B_NO_INIT;
@@ -189,7 +187,7 @@ RepositoryConfig::SetTo(const BEntry& entry)
status_t status_t
RepositoryConfig::SetTo(const BMessage* data) BRepositoryConfig::SetTo(const BMessage* data)
{ {
fInitStatus = B_NO_INIT; fInitStatus = B_NO_INIT;
@@ -213,68 +211,66 @@ RepositoryConfig::SetTo(const BMessage* data)
const BString& const BString&
RepositoryConfig::Name() const BRepositoryConfig::Name() const
{ {
return fName; return fName;
} }
const BString& const BString&
RepositoryConfig::URL() const BRepositoryConfig::URL() const
{ {
return fURL; return fURL;
} }
uint8 uint8
RepositoryConfig::Priority() const BRepositoryConfig::Priority() const
{ {
return fPriority; return fPriority;
} }
bool bool
RepositoryConfig::IsUserSpecific() const BRepositoryConfig::IsUserSpecific() const
{ {
return fIsUserSpecific; return fIsUserSpecific;
} }
const BEntry& const BEntry&
RepositoryConfig::Entry() const BRepositoryConfig::Entry() const
{ {
return fEntry; return fEntry;
} }
void void
RepositoryConfig::SetName(const BString& name) BRepositoryConfig::SetName(const BString& name)
{ {
fName = name; fName = name;
} }
void void
RepositoryConfig::SetURL(const BString& url) BRepositoryConfig::SetURL(const BString& url)
{ {
fURL = url; fURL = url;
} }
void void
RepositoryConfig::SetPriority(uint8 priority) BRepositoryConfig::SetPriority(uint8 priority)
{ {
fPriority = priority; fPriority = priority;
} }
void void
RepositoryConfig::SetIsUserSpecific(bool isUserSpecific) BRepositoryConfig::SetIsUserSpecific(bool isUserSpecific)
{ {
fIsUserSpecific = isUserSpecific; fIsUserSpecific = isUserSpecific;
} }
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
+33 -24
View File
@@ -9,48 +9,57 @@
#include <package/Request.h> #include <package/Request.h>
#include <new>
#include <package/Context.h> #include <package/Context.h>
#include <package/Job.h> #include <package/JobQueue.h>
namespace Haiku { namespace BPackageKit {
namespace Package {
Request::Request(const Context& context) BRequest::BRequest(const BContext& context)
: :
fContext(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 status_t
Request::QueueJob(Job* job) BRequest::InitCheck() const
{ {
job->AddStateListener(this); return fInitStatus;
JobStateListener* listener = fContext.GetJobStateListener();
if (listener != NULL)
job->AddStateListener(listener);
return fJobQueue.AddJob(job);
} }
} // 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
+4 -8
View File
@@ -10,11 +10,9 @@
#include <package/TempfileManager.h> #include <package/TempfileManager.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
const BString TempfileManager::kDefaultName = "tmp-pkgkit-file-"; const BString TempfileManager::kDefaultName = "tmp-pkgkit-file-";
@@ -58,8 +56,6 @@ TempfileManager::Create(const BString& baseName)
} }
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
+5 -9
View File
@@ -14,14 +14,12 @@
#include <package/Context.h> #include <package/Context.h>
namespace Haiku { namespace BPackageKit {
namespace Package { namespace BPrivate {
namespace Private {
ValidateChecksumJob::ValidateChecksumJob(const Context& context, ValidateChecksumJob::ValidateChecksumJob(const BContext& context,
const BString& title, ChecksumAccessor* expectedChecksumAccessor, const BString& title, ChecksumAccessor* expectedChecksumAccessor,
ChecksumAccessor* realChecksumAccessor, bool failIfChecksumsDontMatch) ChecksumAccessor* realChecksumAccessor, bool failIfChecksumsDontMatch)
: :
@@ -79,8 +77,6 @@ ValidateChecksumJob::ChecksumsMatch() const
} }
} // namespace Private } // namespace BPrivate
} // namespace Package } // namespace BPackageKit
} // namespace Haiku
+2 -2
View File
@@ -8,7 +8,7 @@
#include <package/RepositoryConfig.h> #include <package/RepositoryConfig.h>
using namespace Haiku::Package; using namespace BPackageKit;
int int
@@ -20,7 +20,7 @@ main(int argc, const char** argv)
return 1; 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(); status_t status = repoConfig.InitCheck();
if (status != B_OK) { if (status != B_OK) {
fprintf(stderr, "couldn't initialize repository-config\n"); fprintf(stderr, "couldn't initialize repository-config\n");