]> git.mxchange.org Git - simgear.git/commitdiff
pkg::Package: callback for installation start.
authorThomas Geymayer <tomgey@gmail.com>
Mon, 30 Jun 2014 16:36:15 +0000 (18:36 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Mon, 30 Jun 2014 16:36:15 +0000 (18:36 +0200)
Allow eg. Aircraft Center to add listeners to packages to
be called if installation starts.

simgear/package/Package.cxx
simgear/package/Package.hxx

index a5c8d34150c8f6ba4c226d2e9a9da1cb0307cbed..323334b12e6fdcde9094c58fce27ba51a9208038 100644 (file)
@@ -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<Package*>(this));
+  InstallRef install = m_catalog->installForPackage(const_cast<Package*>(this));
+
+  if( cb )
+  {
+    _install_cb.push_back(cb);
+
+    if( install )
+      cb(const_cast<Package*>(this), install);
+  }
+
+  return install;
 }
 
 std::string Package::id() const
index 2c2ce556c350ddf45688852e20b72a4de4a75a16..50783063b9e5c3c775ad1f462f671774a240cb20 100644 (file)
@@ -24,6 +24,7 @@
 #include <simgear/props/props.hxx>
 #include <simgear/misc/strutils.hxx>
 
+#include <simgear/structure/function_list.hxx>
 #include <simgear/structure/SGReferenced.hxx>
 #include <simgear/structure/SGSharedPtr.hxx>
 
@@ -49,12 +50,16 @@ typedef std::vector<PackageRef> PackageList;
   class Package : public SGReferenced
 {
 public:
+
+    typedef boost::function<void(Package*, Install*)> 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<InstallCallback> _install_cb;
 };