* WIP-commit of the first parts of the package kit and the pkgman
(console-)tool git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40261 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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_
|
||||
|
||||
|
||||
#include <String.h>
|
||||
|
||||
#include <package/Context.h>
|
||||
#include <package/Request.h>
|
||||
|
||||
|
||||
namespace Haiku {
|
||||
|
||||
namespace Package {
|
||||
|
||||
|
||||
class AddRepositoryRequest : public Request {
|
||||
typedef Request inherited;
|
||||
|
||||
public:
|
||||
AddRepositoryRequest(const Context& context,
|
||||
const BString& repositoryURL,
|
||||
bool asUserRepository);
|
||||
virtual ~AddRepositoryRequest();
|
||||
|
||||
virtual status_t CreateJobsToRun(JobQueue& jobQueue);
|
||||
|
||||
private:
|
||||
BString fRepositoryURL;
|
||||
bool fAsUserRepository;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Package
|
||||
|
||||
} // namespace Haiku
|
||||
|
||||
|
||||
#endif // _HAIKU__PACKAGE__ADD_REPOSITORY_REQUEST_H_
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _HAIKU__PACKAGE__CONTEXT_H_
|
||||
#define _HAIKU__PACKAGE__CONTEXT_H_
|
||||
|
||||
|
||||
#include <package/TempEntryManager.h>
|
||||
|
||||
|
||||
namespace Haiku {
|
||||
|
||||
namespace Package {
|
||||
|
||||
|
||||
class JobStateListener;
|
||||
|
||||
|
||||
class Context {
|
||||
public:
|
||||
Context();
|
||||
~Context();
|
||||
|
||||
TempEntryManager& GetTempEntryManager() const;
|
||||
|
||||
JobStateListener* DefaultJobStateListener() const;
|
||||
void SetDefaultJobStateListener(
|
||||
JobStateListener* listener);
|
||||
|
||||
private:
|
||||
mutable TempEntryManager fTempEntryManager;
|
||||
JobStateListener* fDefaultJobStateListener;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Package
|
||||
|
||||
} // namespace Haiku
|
||||
|
||||
|
||||
#endif // _HAIKU__PACKAGE__CONTEXT_H_
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _HAIKU__PACKAGE__JOB_H_
|
||||
#define _HAIKU__PACKAGE__JOB_H_
|
||||
|
||||
|
||||
#include <ObjectList.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
namespace Haiku {
|
||||
|
||||
namespace Package {
|
||||
|
||||
|
||||
class Job;
|
||||
|
||||
struct JobStateListener {
|
||||
virtual ~JobStateListener();
|
||||
|
||||
// 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);
|
||||
};
|
||||
|
||||
|
||||
enum JobState {
|
||||
JOB_STATE_WAITING_TO_RUN,
|
||||
JOB_STATE_RUNNING,
|
||||
JOB_STATE_SUCCEEDED,
|
||||
JOB_STATE_FAILED,
|
||||
JOB_STATE_ABORTED,
|
||||
};
|
||||
|
||||
|
||||
class Job {
|
||||
public:
|
||||
Job(const BString& title);
|
||||
virtual ~Job();
|
||||
|
||||
status_t InitCheck() const;
|
||||
|
||||
virtual status_t Run();
|
||||
|
||||
const BString& Title() const;
|
||||
JobState State() const;
|
||||
status_t Result() const;
|
||||
|
||||
status_t AddStateListener(JobStateListener* listener);
|
||||
status_t RemoveStateListener(
|
||||
JobStateListener* listener);
|
||||
|
||||
status_t AddDependency(Job* job);
|
||||
status_t RemoveDependency(Job* job);
|
||||
int32 CountDependencies() const;
|
||||
|
||||
Job* DependantJobAt(int32 index) const;
|
||||
protected:
|
||||
virtual status_t Execute() = 0;
|
||||
virtual void Cleanup(status_t jobResult);
|
||||
|
||||
void NotifyStateListeners();
|
||||
|
||||
private:
|
||||
status_t fInitStatus;
|
||||
BString fTitle;
|
||||
JobState fState;
|
||||
status_t fResult;
|
||||
|
||||
typedef BObjectList<Job> JobList;
|
||||
JobList fDependencies;
|
||||
JobList fDependantJobs;
|
||||
|
||||
typedef BObjectList<JobStateListener> StateListenerList;
|
||||
StateListenerList fStateListeners;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Package
|
||||
|
||||
} // namespace Haiku
|
||||
|
||||
|
||||
#endif // _HAIKU__PACKAGE__JOB_H_
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _HAIKU__PACKAGE__JOB_QUEUE_H_
|
||||
#define _HAIKU__PACKAGE__JOB_QUEUE_H_
|
||||
|
||||
|
||||
#include <Locker.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <package/Job.h>
|
||||
|
||||
|
||||
namespace Haiku {
|
||||
|
||||
namespace Package {
|
||||
|
||||
|
||||
class JobQueue : public JobStateListener {
|
||||
public:
|
||||
JobQueue();
|
||||
~JobQueue();
|
||||
|
||||
status_t AddJob(Job* job);
|
||||
status_t RemoveJob(Job* job);
|
||||
|
||||
Job* Pop();
|
||||
|
||||
// JobStateListener
|
||||
virtual void JobSucceeded(Job* job);
|
||||
virtual void JobFailed(Job* job);
|
||||
|
||||
private:
|
||||
struct JobPriorityLess;
|
||||
class JobPriorityQueue;
|
||||
|
||||
private:
|
||||
void _UpdateDependantJobsOf(Job* job);
|
||||
|
||||
BLocker fLock;
|
||||
JobPriorityQueue* fQueuedJobs;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Package
|
||||
|
||||
} // namespace Haiku
|
||||
|
||||
|
||||
#endif // _HAIKU__PACKAGE__JOB_QUEUE_H_
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _REPOSITORY_H_
|
||||
#define _REPOSITORY_H_
|
||||
|
||||
|
||||
#include <Archivable.h>
|
||||
|
||||
|
||||
class BMessage;
|
||||
|
||||
|
||||
class BRepository {
|
||||
public:
|
||||
BRepository(const char* url);
|
||||
|
||||
public:
|
||||
static BArchivable* Instantiate(BMessage* archive);
|
||||
};
|
||||
|
||||
|
||||
#endif // _REPOSITORY_H_
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _HAIKU__PACKAGE__REPOSITORY_CONFIG_H_
|
||||
#define _HAIKU__PACKAGE__REPOSITORY_CONFIG_H_
|
||||
|
||||
|
||||
#include <Archivable.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class BEntry;
|
||||
|
||||
|
||||
namespace Haiku {
|
||||
|
||||
namespace Package {
|
||||
|
||||
|
||||
class RepositoryConfig : public BArchivable {
|
||||
typedef BArchivable inherited;
|
||||
|
||||
public:
|
||||
RepositoryConfig();
|
||||
RepositoryConfig(const BString& name,
|
||||
const BString& url,
|
||||
uint8 priority = kDefaultPriority);
|
||||
RepositoryConfig(const BEntry& entry);
|
||||
RepositoryConfig(BMessage* data);
|
||||
virtual ~RepositoryConfig();
|
||||
|
||||
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
||||
|
||||
status_t StoreAsConfigFile(const BEntry& entry) const;
|
||||
|
||||
status_t InitCheck() const;
|
||||
|
||||
const BString& Name() const;
|
||||
const BString& URL() const;
|
||||
uint8 Priority() const;
|
||||
bool IsUserSpecific() const;
|
||||
|
||||
void SetName(const BString& name);
|
||||
void SetURL(const BString& url);
|
||||
void SetPriority(uint8 priority);
|
||||
void SetIsUserSpecific(bool isUserSpecific);
|
||||
|
||||
public:
|
||||
static RepositoryConfig* Instantiate(BMessage* data);
|
||||
|
||||
static const uint8 kDefaultPriority = 50;
|
||||
static const char* kNameField;
|
||||
static const char* kURLField;
|
||||
static const char* kPriorityField;
|
||||
|
||||
private:
|
||||
status_t _InitFrom(const BEntry& entry);
|
||||
status_t _InitFrom(const BMessage* data);
|
||||
|
||||
status_t fInitStatus;
|
||||
|
||||
BString fName;
|
||||
BString fURL;
|
||||
uint8 fPriority;
|
||||
bool fIsUserSpecific;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Package
|
||||
|
||||
} // namespace Haiku
|
||||
|
||||
|
||||
#endif // _HAIKU__PACKAGE__REPOSITORY_CONFIG_H_
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _HAIKU__PACKAGE__REQUEST_H_
|
||||
#define _HAIKU__PACKAGE__REQUEST_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace Haiku {
|
||||
|
||||
namespace Package {
|
||||
|
||||
|
||||
class Context;
|
||||
class Job;
|
||||
class JobQueue;
|
||||
|
||||
|
||||
class Request {
|
||||
public:
|
||||
Request(const Context& context);
|
||||
virtual ~Request();
|
||||
|
||||
virtual status_t CreateJobsToRun(JobQueue& jobQueue) = 0;
|
||||
|
||||
const Context& GetContext() const;
|
||||
|
||||
protected:
|
||||
status_t QueueJob(Job* job, JobQueue& jobQueue) const;
|
||||
private:
|
||||
const Context& fContext;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Package
|
||||
|
||||
} // namespace Haiku
|
||||
|
||||
|
||||
#endif // _HAIKU__PACKAGE__REQUEST_H_
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _HAIKU__PACKAGE__ROSTER_H_
|
||||
#define _HAIKU__PACKAGE__ROSTER_H_
|
||||
|
||||
|
||||
#include <Entry.h>
|
||||
#include <Path.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace Haiku {
|
||||
|
||||
namespace Package {
|
||||
|
||||
|
||||
struct RepositoryConfigVisitor {
|
||||
virtual ~RepositoryConfigVisitor()
|
||||
{
|
||||
}
|
||||
|
||||
virtual status_t operator()(const BEntry& entry) = 0;
|
||||
};
|
||||
|
||||
|
||||
class Roster {
|
||||
public:
|
||||
Roster();
|
||||
~Roster();
|
||||
|
||||
status_t GetCommonRepositoryConfigPath(BPath* path,
|
||||
bool create = false) const;
|
||||
status_t GetUserRepositoryConfigPath(BPath* path,
|
||||
bool create = false) const;
|
||||
|
||||
status_t VisitCommonRepositoryConfigs(
|
||||
RepositoryConfigVisitor& visitor);
|
||||
status_t VisitUserRepositoryConfigs(
|
||||
RepositoryConfigVisitor& visitor);
|
||||
|
||||
private:
|
||||
status_t _VisitRepositoryConfigs(const BPath& path,
|
||||
RepositoryConfigVisitor& visitor);
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace Package
|
||||
|
||||
} // namespace Haiku
|
||||
|
||||
|
||||
#endif // _HAIKU__PACKAGE__ROSTER_H_
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _HAIKU__PACKAGE__TEMP_ENTRY_MANAGER_H_
|
||||
#define _HAIKU__PACKAGE__TEMP_ENTRY_MANAGER_H_
|
||||
|
||||
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <String.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace Haiku {
|
||||
|
||||
namespace Package {
|
||||
|
||||
|
||||
class TempEntryManager {
|
||||
public:
|
||||
TempEntryManager();
|
||||
~TempEntryManager();
|
||||
|
||||
void SetBaseDirectory(const BDirectory& baseDir);
|
||||
|
||||
BEntry Create(const BString& baseName = kDefaultName);
|
||||
|
||||
private:
|
||||
static const BString kDefaultName;
|
||||
|
||||
private:
|
||||
BDirectory fBaseDirectory;
|
||||
vint32 fNextNumber;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Package
|
||||
|
||||
} // namespace Haiku
|
||||
|
||||
|
||||
#endif // _HAIKU__PACKAGE__TEMP_ENTRY_MANAGER_H_
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _HAIKU__PACKAGE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_
|
||||
#define _HAIKU__PACKAGE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_
|
||||
|
||||
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <package/Job.h>
|
||||
|
||||
|
||||
namespace Haiku {
|
||||
|
||||
namespace Package {
|
||||
|
||||
|
||||
class ActivateRepositoryConfigJob : public Job {
|
||||
typedef Job inherited;
|
||||
|
||||
public:
|
||||
ActivateRepositoryConfigJob(
|
||||
const BString& title,
|
||||
const BEntry& archivedRepoConfigEntry,
|
||||
const BDirectory& targetDirectory);
|
||||
virtual ~ActivateRepositoryConfigJob();
|
||||
|
||||
protected:
|
||||
virtual status_t Execute();
|
||||
virtual void Cleanup(status_t jobResult);
|
||||
|
||||
private:
|
||||
BEntry fArchivedRepoConfigEntry;
|
||||
BDirectory fTargetDirectory;
|
||||
BEntry fTargetEntry;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Package
|
||||
|
||||
} // namespace Haiku
|
||||
|
||||
|
||||
#endif // _HAIKU__PACKAGE__ACTIVATE_REPOSITORY_CONFIG_JOB_H_
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _HAIKU__PACKAGE__FETCH_FILE_JOB_H_
|
||||
#define _HAIKU__PACKAGE__FETCH_FILE_JOB_H_
|
||||
|
||||
|
||||
#include <Entry.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <package/Job.h>
|
||||
|
||||
|
||||
namespace Haiku {
|
||||
|
||||
namespace Package {
|
||||
|
||||
|
||||
class FetchFileJob : public Job {
|
||||
typedef Job inherited;
|
||||
|
||||
public:
|
||||
FetchFileJob(const BString& title,
|
||||
const BString& fileURL,
|
||||
const BEntry& targetEntry);
|
||||
virtual ~FetchFileJob();
|
||||
|
||||
protected:
|
||||
virtual status_t Execute();
|
||||
virtual void Cleanup(status_t jobResult);
|
||||
|
||||
private:
|
||||
BString fFileURL;
|
||||
BEntry fTargetEntry;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Package
|
||||
|
||||
} // namespace Haiku
|
||||
|
||||
|
||||
#endif // _HAIKU__PACKAGE__FETCH_FILE_JOB_H_
|
||||
Reference in New Issue
Block a user