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_CATALOG_HXX
19 #define SG_PACKAGE_CATALOG_HXX
25 #include <boost/bind.hpp>
27 #include <simgear/misc/sg_path.hxx>
28 #include <simgear/props/props.hxx>
30 #include <simgear/structure/SGReferenced.hxx>
31 #include <simgear/structure/SGSharedPtr.hxx>
32 #include <simgear/structure/function_list.hxx>
33 #include <simgear/io/HTTPRequest.hxx>
35 #include <simgear/package/Delegate.hxx>
40 namespace HTTP { class Client; }
51 typedef SGSharedPtr<Package> PackageRef;
52 typedef SGSharedPtr<Catalog> CatalogRef;
53 typedef SGSharedPtr<Install> InstallRef;
55 typedef std::vector<PackageRef> PackageList;
56 typedef std::vector<CatalogRef> CatalogList;
58 class Catalog : public SGReferenced
63 static CatalogRef createFromUrl(Root* aRoot, const std::string& aUrl);
65 static CatalogRef createFromPath(Root* aRoot, const SGPath& aPath);
71 * uninstall this catalog entirely, including all installed packages
76 * perform a refresh of the catalog contents
81 * Get all packages in this catalog.
83 PackageList const& packages() const;
86 * retrieve packages in this catalog matching a filter.
87 * filter consists of required / minimum values, AND-ed together.
89 PackageList packagesMatching(const SGPropertyNode* aFilter) const;
92 * packages which are locally installed
94 PackageList installedPackages() const;
97 * retrieve all the packages in the catalog which are installed
98 * and have a pendig update
100 PackageList packagesNeedingUpdate() const;
102 SGPath installRoot() const
103 { return m_installRoot; }
105 std::string id() const;
107 std::string url() const;
109 std::string name() const;
111 std::string description() const;
113 PackageRef getPackageById(const std::string& aId) const;
115 PackageRef getPackageByPath(const std::string& aPath) const;
118 * test if the catalog data was retrieved longer ago than the
119 * maximum permitted age for this catalog.
121 bool needsRefresh() const;
123 unsigned int ageInSeconds() const;
126 * access the raw property data in the catalog
128 SGPropertyNode* properties() const;
130 Delegate::StatusCode status() const;
132 typedef boost::function<void(Catalog*)> Callback;
134 void addStatusCallback(const Callback& cb);
137 void addStatusCallback(C* instance, void (C::*mem_func)(Catalog*))
139 return addStatusCallback(boost::bind(mem_func, instance, _1));
142 Catalog(Root* aRoot);
145 friend class Downloader;
147 void parseProps(const SGPropertyNode* aProps);
149 void refreshComplete(Delegate::StatusCode aReason);
151 void parseTimestamp();
152 void writeTimestamp();
154 std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
156 void changeStatus(Delegate::StatusCode newStatus);
159 SGPropertyNode_ptr m_props;
160 SGPath m_installRoot;
162 Delegate::StatusCode m_status;
163 HTTP::Request_ptr m_refreshRequest;
165 PackageList m_packages;
166 time_t m_retrievedTime;
168 typedef std::map<std::string, Package*> PackageWeakMap;
169 PackageWeakMap m_variantDict;
171 function_list<Callback> m_statusCallbacks;
174 } // of namespace pkg
176 } // of namespace simgear
178 #endif // of SG_PACKAGE_CATALOG_HXX