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:
@@ -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 <String.h>
|
||||
@@ -12,22 +12,20 @@
|
||||
#include <package/Request.h>
|
||||
|
||||
|
||||
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_
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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 <package/TempfileManager.h>
|
||||
#include <Entry.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
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_
|
||||
|
||||
+44
-32
@@ -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 <ObjectList.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
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<Job> JobList;
|
||||
uint32 fTicketNumber;
|
||||
|
||||
typedef BObjectList<BJob> JobList;
|
||||
JobList fDependencies;
|
||||
JobList fDependantJobs;
|
||||
|
||||
typedef BObjectList<JobStateListener> StateListenerList;
|
||||
typedef BObjectList<BJobStateListener> StateListenerList;
|
||||
StateListenerList fStateListeners;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Package
|
||||
|
||||
} // namespace Haiku
|
||||
} // namespace BPackageKit
|
||||
|
||||
|
||||
#endif // _HAIKU__PACKAGE__JOB_H_
|
||||
#endif // _PACKAGE__JOB_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 <Entry.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
template <class T> 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<BString>& 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_
|
||||
@@ -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 <Entry.h>
|
||||
@@ -14,43 +14,41 @@
|
||||
#include <package/Request.h>
|
||||
|
||||
|
||||
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_
|
||||
|
||||
@@ -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 <Entry.h>
|
||||
@@ -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_
|
||||
|
||||
@@ -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 <Archivable.h>
|
||||
@@ -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_
|
||||
|
||||
@@ -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 <SupportDefs.h>
|
||||
|
||||
#include <package/JobQueue.h>
|
||||
#include <package/Job.h>
|
||||
|
||||
|
||||
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_
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||
* 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 <Directory.h>
|
||||
@@ -13,19 +13,17 @@
|
||||
#include <package/Job.h>
|
||||
|
||||
|
||||
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_
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||
* 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 <Directory.h>
|
||||
@@ -13,19 +13,17 @@
|
||||
#include <package/Job.h>
|
||||
|
||||
|
||||
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_
|
||||
|
||||
@@ -2,19 +2,17 @@
|
||||
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||
* 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 <Entry.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
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_
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||
* 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 <Entry.h>
|
||||
@@ -12,18 +12,16 @@
|
||||
#include <package/Job.h>
|
||||
|
||||
|
||||
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_
|
||||
|
||||
@@ -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 <Locker.h>
|
||||
@@ -12,44 +12,55 @@
|
||||
#include <package/Job.h>
|
||||
|
||||
|
||||
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_
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||
* 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 <Directory.h>
|
||||
@@ -12,11 +12,9 @@
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
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_
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||
* 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 <Directory.h>
|
||||
@@ -14,19 +14,17 @@
|
||||
#include <package/Job.h>
|
||||
|
||||
|
||||
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_
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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)
|
||||
{
|
||||
@@ -2,18 +2,18 @@
|
||||
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
|
||||
* 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 <package/Context.h>
|
||||
|
||||
|
||||
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
|
||||
@@ -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
|
||||
|
||||
@@ -6,28 +6,28 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#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");
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -14,14 +14,14 @@
|
||||
#include <package/AddRepositoryRequest.h>
|
||||
#include <package/Context.h>
|
||||
#include <package/RefreshRepositoryRequest.h>
|
||||
#include <package/Roster.h>
|
||||
#include <package/PackageRoster.h>
|
||||
|
||||
#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)
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <Path.h>
|
||||
|
||||
#include <package/RepositoryConfig.h>
|
||||
#include <package/Roster.h>
|
||||
#include <package/PackageRoster.h>
|
||||
|
||||
#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<BString> 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;
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
|
||||
#include <package/Context.h>
|
||||
#include <package/RefreshRepositoryRequest.h>
|
||||
#include <package/Roster.h>
|
||||
#include <package/PackageRoster.h>
|
||||
|
||||
#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<BString> 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)
|
||||
|
||||
@@ -14,14 +14,12 @@
|
||||
#include <package/Context.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -15,16 +15,15 @@
|
||||
#include <package/RepositoryConfig.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -15,18 +15,16 @@
|
||||
#include <package/ActivateRepositoryConfigJob.h>
|
||||
#include <package/FetchFileJob.h>
|
||||
#include <package/JobQueue.h>
|
||||
#include <package/Roster.h>
|
||||
#include <package/PackageRoster.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -10,24 +10,20 @@
|
||||
#include <package/Attributes.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -15,11 +15,9 @@
|
||||
#include <package/ChecksumAccessors.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -7,7 +7,10 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <package/Context.h>
|
||||
#include <package/TempfileManager.h>
|
||||
|
||||
#include <Directory.h>
|
||||
#include <FindDirectory.h>
|
||||
@@ -15,66 +18,93 @@
|
||||
#include <Path.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -15,14 +15,12 @@
|
||||
#include <Path.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
:
|
||||
|
||||
+57
-32
@@ -14,45 +14,44 @@
|
||||
#include <package/Context.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
+119
-33
@@ -16,20 +16,23 @@
|
||||
#include <package/Job.h>
|
||||
|
||||
|
||||
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<Job*, JobPriorityLess> {
|
||||
|
||||
: public std::set<BJob*, JobPriorityLess> {
|
||||
};
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <package/Roster.h>
|
||||
#include <package/PackageRoster.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -22,51 +22,49 @@
|
||||
#include <package/RepositoryConfig.h>
|
||||
|
||||
|
||||
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<BString>& names)
|
||||
BPackageRoster::GetRepositoryNames(BObjectList<BString>& names)
|
||||
{
|
||||
struct RepositoryNameCollector : public RepositoryConfigVisitor {
|
||||
struct RepositoryNameCollector : public BRepositoryConfigVisitor {
|
||||
RepositoryNameCollector(BObjectList<BString>& _names)
|
||||
: names(_names)
|
||||
{
|
||||
@@ -124,8 +122,8 @@ Roster::GetRepositoryNames(BObjectList<BString>& 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
|
||||
@@ -19,19 +19,17 @@
|
||||
#include <package/JobQueue.h>
|
||||
#include <package/RepositoryCache.h>
|
||||
#include <package/RepositoryConfig.h>
|
||||
#include <package/Roster.h>
|
||||
#include <package/PackageRoster.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -19,12 +19,10 @@
|
||||
#include <Path.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -20,18 +20,16 @@
|
||||
#include <Path.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -9,48 +9,57 @@
|
||||
|
||||
#include <package/Request.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <package/Context.h>
|
||||
#include <package/Job.h>
|
||||
#include <package/JobQueue.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -10,11 +10,9 @@
|
||||
#include <package/TempfileManager.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -14,14 +14,12 @@
|
||||
#include <package/Context.h>
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <package/RepositoryConfig.h>
|
||||
|
||||
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user