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
26 #include <simgear/misc/sg_path.hxx>
27 #include <simgear/package/Delegate.hxx>
34 namespace HTTP { class Client; }
44 typedef std::vector<Package*> PackageList;
45 typedef std::vector<Catalog*> CatalogList;
47 typedef std::map<std::string, Catalog*> CatalogDict;
52 Root(const SGPath& aPath, const std::string& aVersion);
58 void setLocale(const std::string& aLocale);
60 void setDelegate(Delegate* aDelegate);
62 std::string getLocale() const;
64 CatalogList catalogs() const;
66 void setMaxAgeSeconds(int seconds);
68 void setHTTPClient(HTTP::Client* aHTTP);
70 HTTP::Client* getHTTPClient() const;
73 * the version string of the root. Catalogs must match this version,
74 * or they will be ignored / rejected.
76 std::string catalogVersion() const;
79 * refresh catalogs which are more than the maximum age (24 hours by default)
80 * set force to true, to download all catalogs regardless of age.
82 void refresh(bool aForce = false);
85 * retrieve packages matching a filter.
86 * filter consists of required / minimum values, AND-ed together.
88 PackageList packagesMatching(const SGPropertyNode* aFilter) const;
91 * retrieve all the packages which are installed
92 * and have a pending update
94 PackageList packagesNeedingUpdate() const;
96 Package* getPackageById(const std::string& aId) const;
98 Catalog* getCatalogById(const std::string& aId) const;
100 void scheduleToUpdate(Install* aInstall);
102 friend class Install;
103 friend class Catalog;
106 void catalogRefreshBegin(Catalog* aCat);
107 void catalogRefreshComplete(Catalog* aCat, Delegate::FailureCode aReason);
109 void startNext(Install* aCurrent);
111 void startInstall(Install* aInstall);
112 void installProgress(Install* aInstall, unsigned int aBytes, unsigned int aTotal);
113 void finishInstall(Install* aInstall);
114 void failedInstall(Install* aInstall, Delegate::FailureCode aReason);
117 std::string m_locale;
118 HTTP::Client* m_http;
119 CatalogDict m_catalogs;
120 unsigned int m_maxAgeSeconds;
121 Delegate* m_delegate;
122 std::string m_version;
124 std::set<Catalog*> m_refreshing;
125 std::deque<Install*> m_updateDeque;
128 } // of namespace pkg
130 } // of namespace simgear
132 #endif // of SG_PACKAGE_ROOT_HXX