]> git.mxchange.org Git - simgear.git/blob - simgear/package/Catalog.hxx
Initial work on package management.
[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     int ageInSeconds() const;
68 private:
69     Catalog(Root* aRoot);
70     
71     class Downloader;
72     friend class Downloader;
73     
74     void parseProps(const SGPropertyNode* aProps);
75     
76     void refreshComplete(bool aSuccess);
77     
78     void parseTimestamp();
79     void writeTimestamp();
80     
81     std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
82     
83     Root* m_root;
84     SGPropertyNode_ptr m_props;
85     SGPath m_installRoot;
86     
87     PackageList m_packages;
88     time_t m_retrievedTime;
89 };  
90     
91 } // of namespace pkg
92
93 } // of namespace simgear
94
95 #endif // of SG_PACKAGE_CATALOG_HXX