changed attributes of header files
[platform/core/location/maps-plugin-here.git] / inc / engine / tilefetcher / TileFetcherCache.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #ifndef TILEFETCHERCACHE_H
18 #define TILEFETCHERCACHE_H
19
20 #include <list>
21 #include <time.h>
22 #include <glib.h>
23 #include "common/HereMaps_global.h"
24
25 #include "tilefetcher/TileFetcherQueryListener.h"
26 #include "common/RestItemHandle.h"
27 #include "common/TileKey.h"
28
29
30
31 TIZEN_MAPS_BEGIN_NAMESPACE
32
33 class TileCache
34 {
35 public:
36         int hash;
37         long size;
38         long hit;
39         long timestamp;
40
41         TileCache(int _hash, long _size=0, long _hit=0)
42         {
43                 hash = _hash;
44                 size = _size;
45                 hit = _hit;
46
47                 time_t _time;
48                 time(&_time);
49                 timestamp = _time;
50         }
51 };
52
53 typedef std::list<TileCache> TileCacheList;
54
55 /**
56  *
57  * This class encapsulates a caching system for map tiles based on the file system.
58  *
59  */
60
61 class TileFetcherCache
62 {
63 public:
64     /**
65      * This method is the default constructor.
66      */
67         TileFetcherCache();
68
69     /**
70      * This method is the (virtual) destructor.
71      */
72         virtual ~TileFetcherCache();
73
74     /**
75      * This method is to get the instance of this class.
76      */
77         static TileFetcherCache& GetInstance();
78
79     /**
80      * This method is to clear caching system.
81      */
82         void shutdown();
83
84     /**
85      * This method is to remove a tile having the hash.
86      */
87         bool remove(const int hash);
88
89     /**
90      * This method is to check if there is a tile having the hash.
91      */
92         bool isFound(const int hash);
93
94     /**
95      * This method is to get the iterator of a tile having the hash.
96      */
97         TileCacheList::iterator find(const int hash);
98
99     /**
100      * This method is to read a tile having the hash from own file system.
101      *
102      * @param   hash    A value of hash indicating the tile
103      * @param   buffer  A buffer to store the map tile
104      * @param   size    A size of map tile (bytes)
105      */
106         unsigned long read(const int hash, unsigned char *&buffer, unsigned long &size);
107
108     /**
109      * This method is to write a tile having the hash to own file system.
110      *
111      * @param   hash    A value of hash indicating the tile
112      * @param   buffer  A buffer stored the map tile
113      * @param   size    A size of map tile (bytes)
114      */
115         unsigned long write(const int hash, const unsigned char *buffer, const unsigned long size);
116
117     /**
118      * This method is to clear all of cache files.
119      */
120         void clearCache();
121
122     /**
123      * This method is to abort the request to get a tile from the cache.
124      */
125         void abort(void *pArg);
126
127     /**
128      * This method is to request to get a tile from the cache.
129      */
130         void fire(void *pArg);
131
132 private:
133         HERE_MAPS_NO_COPY_NO_ASSIGN(TileFetcherCache);
134
135     /**
136      * This method is to initialize the cache by scanning and building the list of already cached tiles.
137      */
138         void __initCache();
139
140     /**
141      * This method is to compare hit rates of tiles to decide which one will be removed.
142      */
143         static bool __compareTileCache(const TileCache& first, const TileCache& second);
144
145     /**
146      * This method is to check if more tiles can be stored.
147      */
148         bool __checkCapacity(void);
149
150     /**
151      * This method is to check if more tiles can be stored with only free space.
152      */
153         bool __isAvailableSpace(void);
154
155     /**
156      * This method is to check if more tiles can be stored with only the count of tiles.
157      */
158         bool __isAvailableCount(void);
159
160     /**
161      * This method is to get the path where tile files are stored in.
162      */
163         bool __getCachePath(char *path, int size);
164
165     /**
166      * This method is to get the path of the tile.
167      */
168         bool __getFilePath(const int hash, char *path, int size);
169
170     /**
171      * This method is to get the path of the tile.
172      */
173         bool __getFilePath(const char *fname, char *path, int size);
174
175     /**
176      * This method is to get the hash from the file name.
177      */
178         int __parseHash(const char *fname);
179
180     /**
181      * This method is a timer callback to delay loading time.
182      */
183         static gboolean __fireTimer(gpointer data);
184
185     /**
186      * This method is a timer callback to delay loading time.
187      */
188         static gboolean __fireIdler(gpointer data);
189
190     /**
191      * This method is a timer destroyer.
192      */
193         static void __timerDestroy(gpointer data);
194
195     /**
196      * This method is a timer destroyer.
197      */
198         static void __idlerDestroy(gpointer data);
199
200         //members
201         class TileFetcherCacheImpl;
202         TileFetcherCacheImpl* m_pImpl;
203
204         char __cachePath[256];
205 };
206
207 TIZEN_MAPS_END_NAMESPACE
208
209 #endif