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