]> git.mxchange.org Git - simgear.git/blob - simgear/package/Root.hxx
576b23c7d29777936cb9bbdc28d806609c87b51b
[simgear.git] / simgear / package / Root.hxx
1
2
3 #ifndef SG_PACKAGE_ROOT_HXX
4 #define SG_PACKAGE_ROOT_HXX
5
6 #include <vector>
7 #include <map>
8 #include <deque>
9 #include <set>
10
11 #include <simgear/misc/sg_path.hxx>
12 #include <simgear/package/Delegate.hxx>
13
14 class SGPropertyNode;
15
16 namespace simgear
17 {
18     
19 namespace HTTP { class Client; }
20     
21 namespace pkg
22 {
23
24 // forward decls
25 class Package;
26 class Catalog;
27 class Install;
28
29 typedef std::vector<Package*> PackageList;
30 typedef std::vector<Catalog*> CatalogList;
31
32 typedef std::map<std::string, Catalog*> CatalogDict;
33
34 class Root
35 {
36 public:
37     Root(const SGPath& aPath);
38     virtual ~Root();
39     
40     SGPath path() const
41         { return m_path; }
42     
43     void setLocale(const std::string& aLocale);
44         
45     void setDelegate(Delegate* aDelegate);
46         
47     std::string getLocale() const;
48     
49     CatalogList catalogs() const;
50         
51     void setMaxAgeSeconds(int seconds);
52
53     void setHTTPClient(HTTP::Client* aHTTP);
54
55     HTTP::Client* getHTTPClient() const;
56
57     /**
58      * refresh catalogs which are more than the maximum age (24 hours by default)
59      * set force to true, to download all catalogs regardless of age.
60      */
61     void refresh(bool aForce = false);
62
63     /**
64      * retrieve packages 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 which are installed
71      * and have a pending update
72      */ 
73     PackageList packagesNeedingUpdate() const;
74      
75     Package* getPackageById(const std::string& aId) const;
76     
77     Catalog* getCatalogById(const std::string& aId) const;
78     
79     void scheduleToUpdate(Install* aInstall);
80 private:
81     friend class Install;
82     friend class Catalog;    
83     
84
85     void catalogRefreshBegin(Catalog* aCat);
86     void catalogRefreshComplete(Catalog* aCat, bool aSuccess);
87         
88     void startNext(Install* aCurrent);
89     
90     void startInstall(Install* aInstall);
91     void installProgress(Install* aInstall, unsigned int aBytes, unsigned int aTotal);
92     void finishInstall(Install* aInstall);    
93     void failedInstall(Install* aInstall, Delegate::FailureCode aReason);
94     
95     SGPath m_path;
96     std::string m_locale;
97     HTTP::Client* m_http;
98     CatalogDict m_catalogs;
99     unsigned int m_maxAgeSeconds;
100     Delegate* m_delegate;
101     
102     std::set<Catalog*> m_refreshing;
103     std::deque<Install*> m_updateDeque;
104 };  
105     
106 } // of namespace pkg
107
108 } // of namespace simgear
109
110 #endif // of SG_PACKAGE_ROOT_HXX