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_ROOT_HXX
19 #define SG_PACKAGE_ROOT_HXX
22 #include <memory> // for auto_ptr
24 #include <simgear/misc/sg_path.hxx>
25 #include <simgear/package/Delegate.hxx>
27 #include <simgear/structure/SGReferenced.hxx>
28 #include <simgear/structure/SGSharedPtr.hxx>
48 typedef SGSharedPtr<Package> PackageRef;
49 typedef SGSharedPtr<Catalog> CatalogRef;
50 typedef SGSharedPtr<Install> InstallRef;
52 typedef std::vector<PackageRef> PackageList;
53 typedef std::vector<CatalogRef> CatalogList;
55 class Root : public SGReferenced
58 Root(const SGPath& aPath, const std::string& aVersion);
63 void setLocale(const std::string& aLocale);
65 void setDelegate(Delegate* aDelegate);
67 std::string getLocale() const;
69 CatalogList catalogs() const;
71 void setMaxAgeSeconds(unsigned int seconds);
72 unsigned int maxAgeSeconds() const;
74 void setHTTPClient(HTTP::Client* aHTTP);
77 * Submit an HTTP request. The Root may delay or queue requests if it needs
78 * too, for example during startup when the HTTP engine may not have been
81 void makeHTTPRequest(HTTP::Request* req);
84 * the version string of the root. Catalogs must match this version,
85 * or they will be ignored / rejected.
87 std::string catalogVersion() const;
90 * refresh catalogs which are more than the maximum age (24 hours by default)
91 * set force to true, to download all catalogs regardless of age.
93 void refresh(bool aForce = false);
96 * retrieve packages matching a filter.
97 * filter consists of required / minimum values, AND-ed together.
99 PackageList packagesMatching(const SGPropertyNode* aFilter) const;
102 * retrieve all the packages which are installed
103 * and have a pending update
105 PackageList packagesNeedingUpdate() const;
107 PackageRef getPackageById(const std::string& aId) const;
109 CatalogRef getCatalogById(const std::string& aId) const;
111 void scheduleToUpdate(InstallRef aInstall);
113 friend class Install;
114 friend class Catalog;
117 void catalogRefreshBegin(CatalogRef aCat);
118 void catalogRefreshComplete(CatalogRef aCat, Delegate::FailureCode aReason);
120 void startNext(InstallRef aCurrent);
122 void startInstall(InstallRef aInstall);
123 void installProgress(InstallRef aInstall, unsigned int aBytes, unsigned int aTotal);
124 void finishInstall(InstallRef aInstall);
125 void failedInstall(InstallRef aInstall, Delegate::FailureCode aReason);
128 std::auto_ptr<RootPrivate> d;
131 typedef SGSharedPtr<Root> RootRef;
133 } // of namespace pkg
135 } // of namespace simgear
137 #endif // of SG_PACKAGE_ROOT_HXX