1 // Copyright (C) 2013 James Turner - zakalawe@mac.com
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #ifndef SG_PACKAGE_INSTALL_HXX
19 #define SG_PACKAGE_INSTALL_HXX
23 #include <simgear/misc/sg_path.hxx>
24 #include <simgear/package/Delegate.hxx>
26 #include <simgear/structure/function_list.hxx>
27 #include <simgear/structure/SGReferenced.hxx>
28 #include <simgear/structure/SGSharedPtr.hxx>
30 #include <boost/bind.hpp>
43 typedef SGSharedPtr<Package> PackageRef;
44 typedef SGSharedPtr<Catalog> CatalogRef;
45 typedef SGSharedPtr<Install> InstallRef;
50 class Install : public SGReferenced
55 typedef boost::function<void(Install*)> Callback;
56 typedef boost::function<void(Install*, unsigned int, unsigned int)>
60 * create from a directory on disk, or fail.
62 static InstallRef createFromPath(const SGPath& aPath, CatalogRef aCat);
64 unsigned int revsion() const
65 { return m_revision; }
67 PackageRef package() const
73 bool hasUpdate() const;
80 * Set the handler to be called when the installation successfully
83 * @note If the installation is already complete, the handler is called
86 Install* done(const Callback& cb);
89 Install* done(C* instance, void (C::*mem_func)(Install*))
91 return done(boost::bind(mem_func, instance, _1));
95 * Set the handler to be called when the installation fails or is aborted.
97 * @note If the installation has already failed, the handler is called
100 Install* fail(const Callback& cb);
103 Install* fail(C* instance, void (C::*mem_func)(Install*))
105 return fail(boost::bind(mem_func, instance, _1));
109 * Set the handler to be called when the installation either successfully
110 * completes or fails.
112 * @note If the installation is already complete or has already failed, the
113 * handler is called immediately.
115 Install* always(const Callback& cb);
118 Install* always(C* instance, void (C::*mem_func)(Install*))
120 return always(boost::bind(mem_func, instance, _1));
124 * Set the handler to be called during downloading the installation file
125 * indicating the progress of the download.
128 Install* progress(const ProgressCallback& cb);
131 Install* progress(C* instance,
132 void (C::*mem_func)(Install*, unsigned int, unsigned int))
134 return progress(boost::bind(mem_func, instance, _1, _2, _3));
138 friend class Package;
140 class PackageArchiveDownloader;
141 friend class PackageArchiveDownloader;
143 Install(PackageRef aPkg, const SGPath& aPath);
145 void parseRevision();
146 void writeRevisionFile();
148 void installResult(Delegate::FailureCode aReason);
149 void installProgress(unsigned int aBytes, unsigned int aTotal);
151 PackageRef m_package;
152 unsigned int m_revision; ///< revision on disk
153 SGPath m_path; ///< installation point on disk
155 PackageArchiveDownloader* m_download;
157 Delegate::FailureCode _status;
159 function_list<Callback> _cb_done,
162 function_list<ProgressCallback> _cb_progress;
166 } // of namespace pkg
168 } // of namespace simgear
170 #endif // of SG_PACKAGE_CATALOG_HXX