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
24 #include <simgear/misc/sg_path.hxx>
25 #include <simgear/props/props.hxx>
27 #include <simgear/structure/SGReferenced.hxx>
28 #include <simgear/structure/SGSharedPtr.hxx>
30 #include <simgear/package/Delegate.hxx>
35 namespace HTTP { class Client; }
45 typedef SGSharedPtr<Package> PackageRef;
46 typedef SGSharedPtr<Catalog> CatalogRef;
47 typedef SGSharedPtr<Install> InstallRef;
49 typedef std::vector<PackageRef> PackageList;
50 typedef std::vector<CatalogRef> CatalogList;
52 class Catalog : public SGReferenced
57 static CatalogRef createFromUrl(Root* aRoot, const std::string& aUrl);
59 static CatalogRef createFromPath(Root* aRoot, const SGPath& aPath);
61 static CatalogList allCatalogs();
67 * perform a refresh of the catalog contents
71 * retrieve packages in this catalog matching a filter.
72 * filter consists of required / minimum values, AND-ed together.
74 PackageList packagesMatching(const SGPropertyNode* aFilter) const;
77 * packages which are locally installed
79 PackageList installedPackages() const;
82 * retrieve all the packages in the catalog which are installed
83 * and have a pendig update
85 PackageList packagesNeedingUpdate() const;
87 SGPath installRoot() const
88 { return m_installRoot; }
90 std::string id() const;
92 std::string url() const;
94 std::string description() const;
96 PackageRef getPackageById(const std::string& aId) const;
99 * test if the catalog data was retrieved longer ago than the
100 * maximum permitted age for this catalog.
102 bool needsRefresh() const;
104 unsigned int ageInSeconds() const;
107 * access the raw property data in the catalog
109 SGPropertyNode* properties() const;
111 Catalog(Root* aRoot);
114 friend class Downloader;
116 void parseProps(const SGPropertyNode* aProps);
118 void refreshComplete(Delegate::FailureCode aReason);
120 void parseTimestamp();
121 void writeTimestamp();
123 std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
126 SGPropertyNode_ptr m_props;
127 SGPath m_installRoot;
130 PackageList m_packages;
131 time_t m_retrievedTime;
134 } // of namespace pkg
136 } // of namespace simgear
138 #endif // of SG_PACKAGE_CATALOG_HXX