]> git.mxchange.org Git - simgear.git/blob - simgear/package/Root.hxx
Expand package-system unit-tests.
[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 #include <simgear/structure/SGReferenced.hxx>
28 #include <simgear/structure/SGSharedPtr.hxx>
29
30 class SGPropertyNode;
31
32 namespace simgear
33 {
34     
35 namespace HTTP {
36     class Client;
37     class Request;
38 }
39     
40 namespace pkg
41 {
42
43 // forward decls
44 class Package;
45 class Catalog;
46 class Install;
47   
48 typedef SGSharedPtr<Package> PackageRef;
49 typedef SGSharedPtr<Catalog> CatalogRef;
50 typedef SGSharedPtr<Install> InstallRef;
51   
52 typedef std::vector<PackageRef> PackageList;
53 typedef std::vector<CatalogRef> CatalogList;
54
55 class Root : public SGReferenced
56 {
57 public:
58     Root(const SGPath& aPath, const std::string& aVersion);
59     virtual ~Root();
60     
61     SGPath path() const;
62     
63     void setLocale(const std::string& aLocale);
64         
65     void addDelegate(Delegate* aDelegate);
66     
67     void removeDelegate(Delegate* aDelegate);
68     
69     std::string getLocale() const;
70     
71     CatalogList catalogs() const;
72         
73     void setMaxAgeSeconds(unsigned int seconds);
74     unsigned int maxAgeSeconds() const;
75     
76     void setHTTPClient(HTTP::Client* aHTTP);
77
78     /**
79      * Submit an HTTP request. The Root may delay or queue requests if it needs
80      * too, for example during startup when the HTTP engine may not have been
81      * set yet.
82      */
83     void makeHTTPRequest(HTTP::Request* req);
84
85     /**
86      * Cancel an HTTP request.
87      */
88     void cancelHTTPRequest(HTTP::Request* req, const std::string& reason);
89     
90     /**
91      * The catalog XML/property version in use. This is used to make incomaptible
92      * changes to the package/catalog syntax
93      */
94     int catalogVersion() const;
95
96     /**
97      * the version string of the application. Catalogs must match this version,
98      * or they will be ignored / rejected.
99      */
100     std::string applicationVersion() const;
101
102     /**
103      * refresh catalogs which are more than the maximum age (24 hours by default)
104      * set force to true, to download all catalogs regardless of age.
105      */
106     void refresh(bool aForce = false);
107
108     /**
109      *
110      */
111     PackageList allPackages() const;
112     
113     /**
114      * retrieve packages matching a filter.
115      * filter consists of required / minimum values, AND-ed together.
116      */
117     PackageList packagesMatching(const SGPropertyNode* aFilter) const;
118     
119     /**
120      * retrieve all the packages which are installed
121      * and have a pending update
122      */ 
123     PackageList packagesNeedingUpdate() const;
124      
125     PackageRef getPackageById(const std::string& aId) const;
126     
127     CatalogRef getCatalogById(const std::string& aId) const;
128     
129     void scheduleToUpdate(InstallRef aInstall);
130     
131     /**
132      * remove a catalog. Will uninstall all packages originating
133      * from the catalog too.
134      */
135     bool removeCatalogById(const std::string& aId);
136     
137     /**
138      * request thumbnail data from the cache / network
139      */
140     void requestThumbnailData(const std::string& aUrl);
141     
142     bool isInstallQueued(InstallRef aInstall) const;
143 private:
144     friend class Install;
145     friend class Catalog;    
146     friend class Package;
147     
148     InstallRef existingInstallForPackage(PackageRef p) const;
149     
150     void catalogRefreshStatus(CatalogRef aCat, Delegate::StatusCode aReason);
151         
152     void startNext(InstallRef aCurrent);
153     
154     void startInstall(InstallRef aInstall);
155     void installProgress(InstallRef aInstall, unsigned int aBytes, unsigned int aTotal);
156     void finishInstall(InstallRef aInstall, Delegate::StatusCode aReason);
157     void cancelDownload(InstallRef aInstall);
158     
159     void registerInstall(InstallRef ins);
160     void unregisterInstall(InstallRef ins);
161     
162     class ThumbnailDownloader;
163     class RootPrivate;
164     std::auto_ptr<RootPrivate> d;
165 };
166   
167 typedef SGSharedPtr<Root> RootRef;
168   
169 } // of namespace pkg
170
171 } // of namespace simgear
172
173 #endif // of SG_PACKAGE_ROOT_HXX