2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef TILEFETCHERCACHE_H
18 #define TILEFETCHERCACHE_H
23 #include "common/HereMaps_global.h"
25 #include "tilefetcher/TileFetcherQueryListener.h"
26 #include "common/RestItemHandle.h"
27 #include "common/TileKey.h"
31 TIZEN_MAPS_BEGIN_NAMESPACE
41 TileCache(int _hash, long _size=0, long _hit=0)
53 typedef std::list<TileCache> TileCacheList;
57 * This class encapsulates a caching system for map tiles based on the file system.
61 class TileFetcherCache
65 * This method is the default constructor.
70 * This method is the (virtual) destructor.
72 virtual ~TileFetcherCache();
75 * This method is to get the instance of this class.
77 static TileFetcherCache& GetInstance();
80 * This method is to clear caching system.
85 * This method is to remove a tile having the hash.
87 bool remove(const int hash);
90 * This method is to check if there is a tile having the hash.
92 bool isFound(const int hash);
95 * This method is to get the iterator of a tile having the hash.
97 TileCacheList::iterator find(const int hash);
100 * This method is to read a tile having the hash from own file system.
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)
106 unsigned long read(const int hash, unsigned char *&buffer, unsigned long &size);
109 * This method is to write a tile having the hash to own file system.
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)
115 unsigned long write(const int hash, const unsigned char *buffer, const unsigned long size);
118 * This method is to clear all of cache files.
123 * This method is to abort the request to get a tile from the cache.
125 void abort(void *pArg);
128 * This method is to request to get a tile from the cache.
130 void fire(void *pArg);
133 HERE_MAPS_NO_COPY_NO_ASSIGN(TileFetcherCache);
136 * This method is to initialize the cache by scanning and building the list of already cached tiles.
141 * This method is to compare hit rates of tiles to decide which one will be removed.
143 static bool __compareTileCache(const TileCache& first, const TileCache& second);
146 * This method is to check if more tiles can be stored.
148 bool __checkCapacity(void);
151 * This method is to check if more tiles can be stored with only free space.
153 bool __isAvailableSpace(void);
156 * This method is to check if more tiles can be stored with only the count of tiles.
158 bool __isAvailableCount(void);
161 * This method is to get the path where tile files are stored in.
163 bool __getCachePath(char *path, int size);
166 * This method is to get the path of the tile.
168 bool __getFilePath(const int hash, char *path, int size);
171 * This method is to get the path of the tile.
173 bool __getFilePath(const char *fname, char *path, int size);
176 * This method is to get the hash from the file name.
178 int __parseHash(const char *fname);
181 * This method is a timer callback to delay loading time.
183 static gboolean __fireTimer(gpointer data);
186 * This method is a timer callback to delay loading time.
188 static gboolean __fireIdler(gpointer data);
191 * This method is a timer destroyer.
193 static void __timerDestroy(gpointer data);
196 * This method is a timer destroyer.
198 static void __idlerDestroy(gpointer data);
201 class TileFetcherCacheImpl;
202 TileFetcherCacheImpl* m_pImpl;
204 char __cachePath[256];
207 TIZEN_MAPS_END_NAMESPACE