From 9868fb03a2930486ae6ef644061e42602715705b Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Mon, 30 Jun 2014 18:36:15 +0200 Subject: [PATCH] pkg::Package: callback for installation start. Allow eg. Aircraft Center to add listeners to packages to be called if installation starts. --- simgear/package/Package.cxx | 17 +++++++++++++++-- simgear/package/Package.hxx | 9 ++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/simgear/package/Package.cxx b/simgear/package/Package.cxx index a5c8d341..323334b1 100644 --- a/simgear/package/Package.cxx +++ b/simgear/package/Package.cxx @@ -131,12 +131,25 @@ InstallRef Package::install() // start a new install ins = new Install(this, pathOnDisk()); m_catalog->root()->scheduleToUpdate(ins); + + _install_cb(this, ins); + return ins; } -InstallRef Package::existingInstall() const +InstallRef Package::existingInstall(const InstallCallback& cb) const { - return m_catalog->installForPackage(const_cast(this)); + InstallRef install = m_catalog->installForPackage(const_cast(this)); + + if( cb ) + { + _install_cb.push_back(cb); + + if( install ) + cb(const_cast(this), install); + } + + return install; } std::string Package::id() const diff --git a/simgear/package/Package.hxx b/simgear/package/Package.hxx index 2c2ce556..50783063 100644 --- a/simgear/package/Package.hxx +++ b/simgear/package/Package.hxx @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -49,12 +50,16 @@ typedef std::vector PackageList; class Package : public SGReferenced { public: + + typedef boost::function InstallCallback; + /** * get or create an install for the package */ InstallRef install(); - InstallRef existingInstall() const; + InstallRef + existingInstall(const InstallCallback& cb = InstallCallback()) const; bool isInstalled() const; @@ -138,6 +143,8 @@ private: std::string m_id; string_set m_tags; CatalogRef m_catalog; + + mutable function_list _install_cb; };