]> git.mxchange.org Git - simgear.git/blob - simgear/package/Root.hxx
Tweak HTTP code to always sleep.
[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 <memory> // for auto_ptr
23
24 #include <simgear/misc/sg_path.hxx>
25 #include <simgear/package/Delegate.hxx>
26
27 class SGPropertyNode;
28
29 namespace simgear
30 {
31     
32 namespace HTTP {
33     class Client;
34     class Request;
35 }
36     
37 namespace pkg
38 {
39
40 // forward decls
41 class Package;
42 class Catalog;
43 class Install;
44
45 typedef std::vector<Package*> PackageList;
46 typedef std::vector<Catalog*> CatalogList;
47
48 class Root
49 {
50 public:
51     Root(const SGPath& aPath, const std::string& aVersion);
52     virtual ~Root();
53     
54     SGPath path() const;
55     
56     void setLocale(const std::string& aLocale);
57         
58     void setDelegate(Delegate* aDelegate);
59         
60     std::string getLocale() const;
61     
62     CatalogList catalogs() const;
63         
64     void setMaxAgeSeconds(unsigned int seconds);
65     unsigned int maxAgeSeconds() const;
66     
67     void setHTTPClient(HTTP::Client* aHTTP);
68
69     /**
70      * Submit an HTTP request. The Root may delay or queue requests if it needs
71      * too, for example during startup when the HTTP engine may not have been
72      * set yet.
73      */
74     void makeHTTPRequest(HTTP::Request* req);
75     
76     /**
77      * the version string of the root. Catalogs must match this version,
78      * or they will be ignored / rejected.
79      */
80     std::string catalogVersion() const;
81     
82     /**
83      * refresh catalogs which are more than the maximum age (24 hours by default)
84      * set force to true, to download all catalogs regardless of age.
85      */
86     void refresh(bool aForce = false);
87
88     /**
89      * retrieve packages matching a filter.
90      * filter consists of required / minimum values, AND-ed together.
91      */
92     PackageList packagesMatching(const SGPropertyNode* aFilter) const;
93     
94     /**
95      * retrieve all the packages which are installed
96      * and have a pending update
97      */ 
98     PackageList packagesNeedingUpdate() const;
99      
100     Package* getPackageById(const std::string& aId) const;
101     
102     Catalog* getCatalogById(const std::string& aId) const;
103     
104     void scheduleToUpdate(Install* aInstall);
105 private:
106     friend class Install;
107     friend class Catalog;    
108     
109
110     void catalogRefreshBegin(Catalog* aCat);
111     void catalogRefreshComplete(Catalog* aCat, Delegate::FailureCode aReason);
112         
113     void startNext(Install* aCurrent);
114     
115     void startInstall(Install* aInstall);
116     void installProgress(Install* aInstall, unsigned int aBytes, unsigned int aTotal);
117     void finishInstall(Install* aInstall);    
118     void failedInstall(Install* aInstall, Delegate::FailureCode aReason);
119
120     class RootPrivate;
121     std::auto_ptr<RootPrivate> d;
122 };
123     
124 } // of namespace pkg
125
126 } // of namespace simgear
127
128 #endif // of SG_PACKAGE_ROOT_HXX