/src/gdal/frmts/wms/minidriver_mrf.h
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * $Id: minidriver_mrf.h 35774 2016-10-17 00:35:33Z lplesea $ |
3 | | * |
4 | | * Project: WMS driver |
5 | | * Purpose: Access a remote MRF tile by tile, using range requests |
6 | | * Author: Lucian Plesea |
7 | | * |
8 | | ****************************************************************************** |
9 | | * Copyright (c) 2016, Lucian Plesea |
10 | | * |
11 | | * SPDX-License-Identifier: MIT |
12 | | ****************************************************************************/ |
13 | | |
14 | | #ifndef MINIDRIVER_MRF_H_INCLUDED |
15 | | #define MINIDRIVER_MRF_H_INCLUDED |
16 | | |
17 | | #include <vector> |
18 | | |
19 | | namespace WMSMiniDriver_MRF_ns |
20 | | { |
21 | | |
22 | | // |
23 | | // Almost like pread, but no thread safety |
24 | | // Unlike pread, the first argument is a pointer to an opaque structure |
25 | | // Return of zero means an error occurred (could be end of file) |
26 | | // |
27 | | typedef size_t (*pread_t)(void *user_data, void *buff, size_t count, |
28 | | off_t offset); |
29 | | |
30 | | // |
31 | | // A sector cache, for up to N sectors of a fixed size M |
32 | | // N has to be at least two, the user specifies extras |
33 | | // Used for session caching the remote index |
34 | | // |
35 | | class SectorCache |
36 | | { |
37 | | public: |
38 | | explicit SectorCache(void *user_data, pread_t fn = nullptr, |
39 | | unsigned int size = 1024, unsigned int count = 2); |
40 | | |
41 | | // Fetches a pointer within the sector to the byte at the given address |
42 | | // No alignment is guaranteed, and only enough bytes to reach the end of the |
43 | | // sector are available |
44 | | void *data(size_t address); |
45 | | |
46 | | private: |
47 | | SectorCache(); |
48 | | |
49 | | struct Sector |
50 | | { |
51 | | std::vector<char> range{}; |
52 | | size_t uid{}; |
53 | | }; |
54 | | |
55 | | // N sectors of M bytes each |
56 | | unsigned int n{}, m{}; |
57 | | |
58 | | // Pointer to an pread like function |
59 | | pread_t reader{}; |
60 | | void *reader_data{}; |
61 | | // To avoid thrashing |
62 | | Sector *last_used{}; |
63 | | std::vector<Sector> store{}; |
64 | | |
65 | | CPL_DISALLOW_COPY_ASSIGN(SectorCache) |
66 | | }; |
67 | | |
68 | | // Size of an image, also used as a tile or pixel location |
69 | | struct ILSize |
70 | | { |
71 | 0 | ILSize() = default; |
72 | | |
73 | | ILSize(GInt32 _x, GInt32 _y, GInt32 _z = 1, GInt32 _c = 1, GInt32 _l = -1) |
74 | 0 | : x(_x), y(_y), z(_z), c(_c), l(_l) |
75 | 0 | { |
76 | 0 | } |
77 | | |
78 | | GInt32 x{}, y{}, z{}, c{}; |
79 | | GIntBig l{}; // Dual use, sometimes it holds the number of pages |
80 | | }; |
81 | | |
82 | | } // namespace WMSMiniDriver_MRF_ns |
83 | | |
84 | | class WMSMiniDriver_MRF final : public WMSMiniDriver |
85 | | { |
86 | | public: |
87 | | WMSMiniDriver_MRF(); |
88 | | ~WMSMiniDriver_MRF() override; |
89 | | |
90 | | virtual CPLErr Initialize(CPLXMLNode *config, |
91 | | char **papszOpenOptions) override; |
92 | | CPLErr EndInit() override; |
93 | | |
94 | | virtual CPLErr |
95 | | TiledImageRequest(WMSHTTPRequest &url, const GDALWMSImageRequestInfo &iri, |
96 | | const GDALWMSTiledImageRequestInfo &tiri) override; |
97 | | |
98 | | enum |
99 | | { |
100 | | tMRF, |
101 | | tBundle, |
102 | | tEND |
103 | | }; |
104 | | |
105 | | private: |
106 | | size_t GetIndexAddress(const GDALWMSTiledImageRequestInfo &tiri) const; |
107 | | |
108 | | // The path or URL for index |
109 | | CPLString m_idxname{}; |
110 | | |
111 | | // Which type of remote file this is, one of the types above |
112 | | int m_type{}; |
113 | | |
114 | | VSILFILE *fp{}; // If index is a file |
115 | | WMSHTTPRequest *m_request{}; // If index is an URL |
116 | | WMSMiniDriver_MRF_ns::SectorCache *index_cache{}; |
117 | | |
118 | | // Per level index offsets, level 0 being the full resolution |
119 | | std::vector<GUIntBig> offsets{}; |
120 | | // Matching pagecounts |
121 | | std::vector<WMSMiniDriver_MRF_ns::ILSize> pages{}; |
122 | | |
123 | | CPL_DISALLOW_COPY_ASSIGN(WMSMiniDriver_MRF) |
124 | | }; |
125 | | |
126 | | #endif /* MINIDRIVER_MRF_H_INCLUDED */ |