Pkg: record live installs in Catalog.
Ensures active Installs can be found immediately after creation.
This commit is contained in:
@@ -216,6 +216,23 @@ Catalog::installedPackages() const
|
||||
return r;
|
||||
}
|
||||
|
||||
InstallRef Catalog::installForPackage(PackageRef pkg) const
|
||||
{
|
||||
PackageInstallDict::const_iterator it = m_installed.find(pkg);
|
||||
if (it == m_installed.end()) {
|
||||
// check if it exists on disk, create
|
||||
|
||||
SGPath p(pkg->pathOnDisk());
|
||||
if (p.exists()) {
|
||||
return Install::createFromPath(p, CatalogRef(const_cast<Catalog*>(this)));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void Catalog::refresh()
|
||||
{
|
||||
Downloader* dl = new Downloader(this, url());
|
||||
@@ -339,6 +356,23 @@ void Catalog::refreshComplete(Delegate::FailureCode aReason)
|
||||
m_root->catalogRefreshComplete(this, aReason);
|
||||
}
|
||||
|
||||
void Catalog::registerInstall(InstallRef ins)
|
||||
{
|
||||
if (!ins || ins->package()->catalog() != this) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_installed[ins->package()] = ins;
|
||||
}
|
||||
|
||||
void Catalog::unregisterInstall(InstallRef ins)
|
||||
{
|
||||
if (!ins || ins->package()->catalog() != this) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_installed.erase(ins->package());
|
||||
}
|
||||
|
||||
} // of namespace pkg
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
#include <map>
|
||||
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/props/props.hxx>
|
||||
@@ -41,7 +42,8 @@ namespace pkg
|
||||
class Package;
|
||||
class Catalog;
|
||||
class Root;
|
||||
|
||||
class Install;
|
||||
|
||||
typedef SGSharedPtr<Package> PackageRef;
|
||||
typedef SGSharedPtr<Catalog> CatalogRef;
|
||||
typedef SGSharedPtr<Install> InstallRef;
|
||||
@@ -100,7 +102,9 @@ public:
|
||||
std::string description() const;
|
||||
|
||||
PackageRef getPackageById(const std::string& aId) const;
|
||||
|
||||
|
||||
InstallRef installForPackage(PackageRef pkg) const;
|
||||
|
||||
/**
|
||||
* test if the catalog data was retrieved longer ago than the
|
||||
* maximum permitted age for this catalog.
|
||||
@@ -118,7 +122,11 @@ private:
|
||||
|
||||
class Downloader;
|
||||
friend class Downloader;
|
||||
|
||||
|
||||
friend class Install;
|
||||
void registerInstall(InstallRef ins);
|
||||
void unregisterInstall(InstallRef ins);
|
||||
|
||||
void parseProps(const SGPropertyNode* aProps);
|
||||
|
||||
void refreshComplete(Delegate::FailureCode aReason);
|
||||
@@ -135,7 +143,12 @@ private:
|
||||
|
||||
PackageList m_packages;
|
||||
time_t m_retrievedTime;
|
||||
};
|
||||
|
||||
// important that this is a weak-ref to Installs,
|
||||
// since it is only cleaned up in the Install destructor
|
||||
typedef std::map<PackageRef, Install*> PackageInstallDict;
|
||||
PackageInstallDict m_installed;
|
||||
};
|
||||
|
||||
} // of namespace pkg
|
||||
|
||||
|
||||
@@ -262,6 +262,12 @@ Install::Install(PackageRef aPkg, const SGPath& aPath) :
|
||||
_status(Delegate::FAIL_IN_PROGRESS)
|
||||
{
|
||||
parseRevision();
|
||||
m_package->catalog()->registerInstall(this);
|
||||
}
|
||||
|
||||
Install::~Install()
|
||||
{
|
||||
m_package->catalog()->unregisterInstall(this);
|
||||
}
|
||||
|
||||
InstallRef Install::createFromPath(const SGPath& aPath, CatalogRef aCat)
|
||||
|
||||
@@ -50,6 +50,8 @@ typedef SGSharedPtr<Install> InstallRef;
|
||||
class Install : public SGReferenced
|
||||
{
|
||||
public:
|
||||
virtual ~Install();
|
||||
|
||||
typedef boost::function<void(Install*)> Callback;
|
||||
typedef boost::function<void(Install*, unsigned int, unsigned int)>
|
||||
ProgressCallback;
|
||||
|
||||
@@ -110,24 +110,20 @@ SGPath Package::pathOnDisk() const
|
||||
|
||||
InstallRef Package::install()
|
||||
{
|
||||
SGPath p(pathOnDisk());
|
||||
if (p.exists()) {
|
||||
return Install::createFromPath(p, m_catalog);
|
||||
InstallRef ins = existingInstall();
|
||||
if (ins) {
|
||||
return ins;
|
||||
}
|
||||
|
||||
InstallRef ins(new Install(this, p));
|
||||
|
||||
// start a new install
|
||||
ins = new Install(this, pathOnDisk());
|
||||
m_catalog->root()->scheduleToUpdate(ins);
|
||||
return ins;
|
||||
}
|
||||
|
||||
InstallRef Package::existingInstall() const
|
||||
{
|
||||
SGPath p(pathOnDisk());
|
||||
if (p.exists()) {
|
||||
return Install::createFromPath(p, m_catalog);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return m_catalog->installForPackage(const_cast<Package*>(this));
|
||||
}
|
||||
|
||||
std::string Package::id() const
|
||||
|
||||
Reference in New Issue
Block a user