]> git.mxchange.org Git - simgear.git/blob - simgear/package/Catalog.hxx
utf8ToLatin1: return original instead of crashing on non-UTF-8 input
[simgear.git] / simgear / package / Catalog.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_CATALOG_HXX
19 #define SG_PACKAGE_CATALOG_HXX
20
21 #include <vector>
22 #include <ctime>
23
24 #include <simgear/misc/sg_path.hxx>
25 #include <simgear/props/props.hxx>
26
27 #include <simgear/structure/SGReferenced.hxx>
28 #include <simgear/structure/SGSharedPtr.hxx>
29
30 #include <simgear/package/Delegate.hxx>
31
32 namespace simgear
33 {
34     
35 namespace HTTP { class Client; }
36     
37 namespace pkg
38 {
39
40 // forward decls
41 class Package;
42 class Catalog;
43 class Root;
44
45 typedef SGSharedPtr<Package> PackageRef;
46 typedef SGSharedPtr<Catalog> CatalogRef;
47 typedef SGSharedPtr<Install> InstallRef;
48   
49 typedef std::vector<PackageRef> PackageList;
50 typedef std::vector<CatalogRef> CatalogList;
51
52   class Catalog : public SGReferenced
53 {
54 public:
55     virtual ~Catalog();
56     
57     static CatalogRef createFromUrl(Root* aRoot, const std::string& aUrl);
58     
59     static CatalogRef createFromPath(Root* aRoot, const SGPath& aPath);
60     
61     static CatalogList allCatalogs();
62     
63     Root* root() const
64         { return m_root;};
65     
66     /**
67      * perform a refresh of the catalog contents
68      */
69     void refresh();
70
71     /**
72      * Get all packages in this catalog.
73      */
74     PackageList const& packages() const;
75
76     /**
77      * retrieve packages in this catalog matching a filter.
78      * filter consists of required / minimum values, AND-ed together.
79      */
80     PackageList packagesMatching(const SGPropertyNode* aFilter) const;
81
82     /**
83      * packages which are locally installed
84      */
85     PackageList installedPackages() const;
86
87     /**
88      * retrieve all the packages in the catalog which are installed
89      * and have a pendig update
90      */ 
91     PackageList packagesNeedingUpdate() const;
92      
93     SGPath installRoot() const
94          { return m_installRoot; }
95     
96     std::string id() const;
97     
98     std::string url() const;
99     
100     std::string description() const;
101     
102     PackageRef getPackageById(const std::string& aId) const;
103     
104     /**
105      * test if the catalog data was retrieved longer ago than the
106      * maximum permitted age for this catalog.
107      */
108     bool needsRefresh() const;
109     
110     unsigned int ageInSeconds() const;
111     
112     /**
113      * access the raw property data in the catalog
114      */
115     SGPropertyNode* properties() const;
116 private:
117     Catalog(Root* aRoot);
118     
119     class Downloader;
120     friend class Downloader;
121     
122     void parseProps(const SGPropertyNode* aProps);
123     
124     void refreshComplete(Delegate::FailureCode aReason);
125     
126     void parseTimestamp();
127     void writeTimestamp();
128     
129     std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
130     
131     Root* m_root;
132     SGPropertyNode_ptr m_props;
133     SGPath m_installRoot;
134     std::string m_url;
135   
136     PackageList m_packages;
137     time_t m_retrievedTime;
138 };  
139     
140 } // of namespace pkg
141
142 } // of namespace simgear
143
144 #endif // of SG_PACKAGE_CATALOG_HXX