]> git.mxchange.org Git - simgear.git/blob - simgear/package/Catalog.hxx
LGPL license on package files.
[simgear.git] / simgear / package / Catalog.hxx
1 // Copyright (C) 2013  James Turner - zakalawe@mac.com
2 //
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.
7 //
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.
12 //
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.
16 //
17
18 #ifndef SG_PACKAGE_CATALOG_HXX
19 #define SG_PACKAGE_CATALOG_HXX
20
21 #include <vector>
22 #include <ctime>
23
24 #include <simgear/misc/sg_path.hxx>
25 #include <simgear/props/props.hxx>
26
27 namespace simgear
28 {
29     
30 namespace HTTP { class Client; }
31     
32 namespace pkg
33 {
34
35 // forward decls
36 class Package;
37 class Catalog;
38 class Root;
39
40 typedef std::vector<Package*> PackageList;
41 typedef std::vector<Catalog*> CatalogList;
42
43 class Catalog
44 {
45 public:
46     virtual ~Catalog();
47     
48     static Catalog* createFromUrl(Root* aRoot, const std::string& aUrl);
49     
50     static Catalog* createFromPath(Root* aRoot, const SGPath& aPath);
51     
52     static CatalogList allCatalogs();
53     
54     Root* root() const
55         { return m_root;};
56     
57     /**
58      * perform a refresh of the catalog contents
59      */
60     void refresh();
61     /**
62      * retrieve packages in this catalog matching a filter.
63      * filter consists of required / minimum values, AND-ed together.
64      */
65     PackageList packagesMatching(const SGPropertyNode* aFilter) const;
66     
67     /**
68      * retrieve all the packages in the catalog which are installed
69      * and have a pendig update
70      */ 
71     PackageList packagesNeedingUpdate() const;
72      
73     SGPath installRoot() const
74          { return m_installRoot; }
75     
76     std::string id() const;
77     
78     std::string url() const;
79     
80     std::string description() const;
81     
82     Package* getPackageById(const std::string& aId) const;
83     
84     unsigned int ageInSeconds() const;
85     
86     /**
87      * access the raw property data in the catalog
88      */
89     SGPropertyNode* properties() const;
90 private:
91     Catalog(Root* aRoot);
92     
93     class Downloader;
94     friend class Downloader;
95     
96     void parseProps(const SGPropertyNode* aProps);
97     
98     void refreshComplete(bool aSuccess);
99     
100     void parseTimestamp();
101     void writeTimestamp();
102     
103     std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
104     
105     Root* m_root;
106     SGPropertyNode_ptr m_props;
107     SGPath m_installRoot;
108     
109     PackageList m_packages;
110     time_t m_retrievedTime;
111 };  
112     
113 } // of namespace pkg
114
115 } // of namespace simgear
116
117 #endif // of SG_PACKAGE_CATALOG_HXX