]> git.mxchange.org Git - simgear.git/blob - simgear/package/Root.hxx
LGPL license on package files.
[simgear.git] / simgear / package / Root.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_ROOT_HXX
19 #define SG_PACKAGE_ROOT_HXX
20
21 #include <vector>
22 #include <map>
23 #include <deque>
24 #include <set>
25
26 #include <simgear/misc/sg_path.hxx>
27 #include <simgear/package/Delegate.hxx>
28
29 class SGPropertyNode;
30
31 namespace simgear
32 {
33     
34 namespace HTTP { class Client; }
35     
36 namespace pkg
37 {
38
39 // forward decls
40 class Package;
41 class Catalog;
42 class Install;
43
44 typedef std::vector<Package*> PackageList;
45 typedef std::vector<Catalog*> CatalogList;
46
47 typedef std::map<std::string, Catalog*> CatalogDict;
48
49 class Root
50 {
51 public:
52     Root(const SGPath& aPath);
53     virtual ~Root();
54     
55     SGPath path() const
56         { return m_path; }
57     
58     void setLocale(const std::string& aLocale);
59         
60     void setDelegate(Delegate* aDelegate);
61         
62     std::string getLocale() const;
63     
64     CatalogList catalogs() const;
65         
66     void setMaxAgeSeconds(int seconds);
67
68     void setHTTPClient(HTTP::Client* aHTTP);
69
70     HTTP::Client* getHTTPClient() const;
71
72     /**
73      * refresh catalogs which are more than the maximum age (24 hours by default)
74      * set force to true, to download all catalogs regardless of age.
75      */
76     void refresh(bool aForce = false);
77
78     /**
79      * retrieve packages matching a filter.
80      * filter consists of required / minimum values, AND-ed together.
81      */
82     PackageList packagesMatching(const SGPropertyNode* aFilter) const;
83     
84     /**
85      * retrieve all the packages which are installed
86      * and have a pending update
87      */ 
88     PackageList packagesNeedingUpdate() const;
89      
90     Package* getPackageById(const std::string& aId) const;
91     
92     Catalog* getCatalogById(const std::string& aId) const;
93     
94     void scheduleToUpdate(Install* aInstall);
95 private:
96     friend class Install;
97     friend class Catalog;    
98     
99
100     void catalogRefreshBegin(Catalog* aCat);
101     void catalogRefreshComplete(Catalog* aCat, bool aSuccess);
102         
103     void startNext(Install* aCurrent);
104     
105     void startInstall(Install* aInstall);
106     void installProgress(Install* aInstall, unsigned int aBytes, unsigned int aTotal);
107     void finishInstall(Install* aInstall);    
108     void failedInstall(Install* aInstall, Delegate::FailureCode aReason);
109     
110     SGPath m_path;
111     std::string m_locale;
112     HTTP::Client* m_http;
113     CatalogDict m_catalogs;
114     unsigned int m_maxAgeSeconds;
115     Delegate* m_delegate;
116     
117     std::set<Catalog*> m_refreshing;
118     std::deque<Install*> m_updateDeque;
119 };  
120     
121 } // of namespace pkg
122
123 } // of namespace simgear
124
125 #endif // of SG_PACKAGE_ROOT_HXX