]> git.mxchange.org Git - simgear.git/blob - simgear/package/Catalog.hxx
Tweak HTTP code to always sleep.
[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 #include <simgear/package/Delegate.hxx>
28
29 namespace simgear
30 {
31     
32 namespace HTTP { class Client; }
33     
34 namespace pkg
35 {
36
37 // forward decls
38 class Package;
39 class Catalog;
40 class Root;
41
42 typedef std::vector<Package*> PackageList;
43 typedef std::vector<Catalog*> CatalogList;
44
45 class Catalog
46 {
47 public:
48     virtual ~Catalog();
49     
50     static Catalog* createFromUrl(Root* aRoot, const std::string& aUrl);
51     
52     static Catalog* createFromPath(Root* aRoot, const SGPath& aPath);
53     
54     static CatalogList allCatalogs();
55     
56     Root* root() const
57         { return m_root;};
58     
59     /**
60      * perform a refresh of the catalog contents
61      */
62     void refresh();
63     /**
64      * retrieve packages in this catalog matching a filter.
65      * filter consists of required / minimum values, AND-ed together.
66      */
67     PackageList packagesMatching(const SGPropertyNode* aFilter) const;
68     
69     /**
70      * retrieve all the packages in the catalog which are installed
71      * and have a pendig update
72      */ 
73     PackageList packagesNeedingUpdate() const;
74      
75     SGPath installRoot() const
76          { return m_installRoot; }
77     
78     std::string id() const;
79     
80     std::string url() const;
81     
82     std::string description() const;
83     
84     Package* getPackageById(const std::string& aId) const;
85     
86     /**
87      * test if the catalog data was retrieved longer ago than the
88      * maximum permitted age for this catalog.
89      */
90     bool needsRefresh() const;
91     
92     unsigned int ageInSeconds() const;
93     
94     /**
95      * access the raw property data in the catalog
96      */
97     SGPropertyNode* properties() const;
98 private:
99     Catalog(Root* aRoot);
100     
101     class Downloader;
102     friend class Downloader;
103     
104     void parseProps(const SGPropertyNode* aProps);
105     
106     void refreshComplete(Delegate::FailureCode aReason);
107     
108     void parseTimestamp();
109     void writeTimestamp();
110     
111     std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
112     
113     Root* m_root;
114     SGPropertyNode_ptr m_props;
115     SGPath m_installRoot;
116     
117     PackageList m_packages;
118     time_t m_retrievedTime;
119 };  
120     
121 } // of namespace pkg
122
123 } // of namespace simgear
124
125 #endif // of SG_PACKAGE_CATALOG_HXX