* Introduce Version class representing a version. * Introduce Dependency and Resolvable class and add lists of either to Package. * Parse package attributes and add dependencies and resolvables to Package. * Add a mount type to Volume and add a respective mount parameter "mount-type" (values "system", "common", "home", "custom"). Also implies the shine-through type, if that's not given. * Introduce class PackageFamily which groups equally named and versioned packages. * Add class PackageFSRoot. Each instance represents a possible file system root (separate roots for different chroot environments). Tracks Volumes belonging to the same root and their packages.
136 lines
2.6 KiB
C++
136 lines
2.6 KiB
C++
/*
|
|
* Copyright 2009-2011, Ingo Weinhold, [email protected].
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef PACKAGE_H
|
|
#define PACKAGE_H
|
|
|
|
|
|
#include <Referenceable.h>
|
|
|
|
#include <util/DoublyLinkedList.h>
|
|
#include <util/khash.h>
|
|
#include <util/OpenHashTable.h>
|
|
|
|
#include <lock.h>
|
|
|
|
#include "Dependency.h"
|
|
#include "PackageNode.h"
|
|
#include "Resolvable.h"
|
|
|
|
|
|
class PackageDomain;
|
|
class PackageFamily;
|
|
class Version;
|
|
|
|
|
|
class Package : public BReferenceable,
|
|
public DoublyLinkedListLinkImpl<Package> {
|
|
public:
|
|
Package(PackageDomain* domain, dev_t deviceID,
|
|
ino_t nodeID);
|
|
~Package();
|
|
|
|
status_t Init(const char* fileName);
|
|
|
|
PackageDomain* Domain() const { return fDomain; }
|
|
const char* FileName() const { return fFileName; }
|
|
|
|
status_t SetName(const char* name);
|
|
const char* Name() const { return fName; }
|
|
|
|
void SetVersion(::Version* version);
|
|
// takes over object ownership
|
|
::Version* Version() const
|
|
{ return fVersion; }
|
|
|
|
void SetFamily(PackageFamily* family)
|
|
{ fFamily = family; }
|
|
PackageFamily* Family() const
|
|
{ return fFamily; }
|
|
|
|
Package*& FileNameHashTableNext()
|
|
{ return fFileNameHashTableNext; }
|
|
|
|
void AddNode(PackageNode* node);
|
|
void AddResolvable(Resolvable* resolvable);
|
|
void AddDependency(Dependency* dependency);
|
|
|
|
int Open();
|
|
void Close();
|
|
|
|
const PackageNodeList& Nodes() const { return fNodes; }
|
|
|
|
private:
|
|
mutex fLock;
|
|
PackageDomain* fDomain;
|
|
char* fFileName;
|
|
char* fName;
|
|
::Version* fVersion;
|
|
PackageFamily* fFamily;
|
|
int fFD;
|
|
uint32 fOpenCount;
|
|
Package* fFileNameHashTableNext;
|
|
ino_t fNodeID;
|
|
dev_t fDeviceID;
|
|
PackageNodeList fNodes;
|
|
ResolvableList fResolvables;
|
|
DependencyList fDependencies;
|
|
};
|
|
|
|
|
|
struct PackageCloser {
|
|
PackageCloser(Package* package)
|
|
:
|
|
fPackage(package)
|
|
{
|
|
}
|
|
|
|
~PackageCloser()
|
|
{
|
|
if (fPackage != NULL)
|
|
fPackage->Close();
|
|
}
|
|
|
|
void Detach()
|
|
{
|
|
fPackage = NULL;
|
|
}
|
|
|
|
private:
|
|
Package* fPackage;
|
|
};
|
|
|
|
|
|
struct PackageFileNameHashDefinition {
|
|
typedef const char* KeyType;
|
|
typedef Package ValueType;
|
|
|
|
size_t HashKey(const char* key) const
|
|
{
|
|
return hash_hash_string(key);
|
|
}
|
|
|
|
size_t Hash(const Package* value) const
|
|
{
|
|
return HashKey(value->FileName());
|
|
}
|
|
|
|
bool Compare(const char* key, const Package* value) const
|
|
{
|
|
return strcmp(value->FileName(), key) == 0;
|
|
}
|
|
|
|
Package*& GetLink(Package* value) const
|
|
{
|
|
return value->FileNameHashTableNext();
|
|
}
|
|
};
|
|
|
|
|
|
typedef BOpenHashTable<PackageFileNameHashDefinition> PackageFileNameHashTable;
|
|
typedef DoublyLinkedList<Package> PackageList;
|
|
|
|
|
|
#endif // PACKAGE_H
|