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;
79 bool isDownloading() const;
82 * Set the handler to be called when the installation successfully
85 * @note If the installation is already complete, the handler is called
88 Install* done(const Callback& cb);
91 Install* done(C* instance, void (C::*mem_func)(Install*))
93 return done(boost::bind(mem_func, instance, _1));
97 * Set the handler to be called when the installation fails or is aborted.
99 * @note If the installation has already failed, the handler is called
102 Install* fail(const Callback& cb);
105 Install* fail(C* instance, void (C::*mem_func)(Install*))
107 return fail(boost::bind(mem_func, instance, _1));
111 * Set the handler to be called when the installation either successfully
112 * completes or fails.
114 * @note If the installation is already complete or has already failed, the
115 * handler is called immediately.
117 Install* always(const Callback& cb);
120 Install* always(C* instance, void (C::*mem_func)(Install*))
122 return always(boost::bind(mem_func, instance, _1));
126 * Set the handler to be called during downloading the installation file
127 * indicating the progress of the download.
130 Install* progress(const ProgressCallback& cb);
133 Install* progress(C* instance,
134 void (C::*mem_func)(Install*, unsigned int, unsigned int))
136 return progress(boost::bind(mem_func, instance, _1, _2, _3));
140 friend class Package;
142 class PackageArchiveDownloader;
143 friend class PackageArchiveDownloader;
145 Install(PackageRef aPkg, const SGPath& aPath);
147 void parseRevision();
148 void writeRevisionFile();
150 void installResult(Delegate::FailureCode aReason);
151 void installProgress(unsigned int aBytes, unsigned int aTotal);
153 PackageRef m_package;
154 unsigned int m_revision; ///< revision on disk
155 SGPath m_path; ///< installation point on disk
157 PackageArchiveDownloader* m_download;
159 Delegate::FailureCode _status;
161 function_list<Callback> _cb_done,
164 function_list<ProgressCallback> _cb_progress;
168 } // of namespace pkg
170 } // of namespace simgear
172 #endif // of SG_PACKAGE_CATALOG_HXX