Commit 2841c81b authored by Jiří Techet's avatar Jiří Techet

Introduce new memory cache and remove non-persistent file cache

The new memory cache can store specified number of tiles in
memory without storing them to the disk. It replaces
the temporary file cache - it was a bit scary to recursively
delete some directories and libchamplain shouldn't do things
like that.
Signed-off-by: 's avatarJiří Techet <techet@gmail.com>
parent 537d540c
......@@ -34,6 +34,7 @@ libchamplain_headers = \
champlain-map-source-chain.h \
champlain-tile-source.h \
champlain-tile-cache.h \
champlain-memory-cache.h \
champlain-network-tile-source.h \
champlain-file-cache.h \
champlain-map-source-factory.h \
......@@ -70,6 +71,7 @@ libchamplain_@CHAMPLAIN_API_VERSION@_la_SOURCES = \
champlain-map-source-chain.c \
champlain-tile-source.c \
champlain-tile-cache.c \
champlain-memory-cache.c \
champlain-network-tile-source.c \
champlain-file-cache.c \
champlain-map-source-factory.c \
......@@ -101,6 +103,7 @@ libchamplain_include_HEADERS = \
champlain-map-source-chain.h \
champlain-tile-source.h \
champlain-tile-cache.h \
champlain-memory-cache.h \
champlain-network-tile-source.h \
champlain-file-cache.h \
champlain-map-source-factory.h \
......
This diff is collapsed.
......@@ -57,7 +57,7 @@ GType champlain_file_cache_get_type (void);
ChamplainFileCache* champlain_file_cache_new (void);
ChamplainFileCache* champlain_file_cache_new_full (guint size_limit,
const gchar *cache_dir, gboolean persistent);
const gchar *cache_dir);
guint champlain_file_cache_get_size_limit (ChamplainFileCache *file_cache);
void champlain_file_cache_set_size_limit (ChamplainFileCache *file_cache,
......
......@@ -149,7 +149,7 @@ tile_rendered_cb (ChamplainTile *tile,
champlain_map_source_fill_tile (next_source, tile);
g_object_unref (map_source);
g_signal_handlers_disconnect_by_func (tile, tile_rendered_cb, data);
g_signal_handlers_disconnect_by_func (tile, tile_rendered_cb, map_source);
}
static void
......
This diff is collapsed.
/*
* Copyright (C) 2010 Jiri Techet <techet@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if !defined (__CHAMPLAIN_CHAMPLAIN_H_INSIDE__) && !defined (CHAMPLAIN_COMPILATION)
#error "Only <champlain/champlain.h> can be included directly."
#endif
#ifndef _CHAMPLAIN_MEMORY_CACHE_H_
#define _CHAMPLAIN_MEMORY_CACHE_H_
#include <glib-object.h>
#include <champlain/champlain-tile-cache.h>
G_BEGIN_DECLS
#define CHAMPLAIN_TYPE_MEMORY_CACHE (champlain_memory_cache_get_type ())
#define CHAMPLAIN_MEMORY_CACHE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CHAMPLAIN_TYPE_MEMORY_CACHE, ChamplainMemoryCache))
#define CHAMPLAIN_MEMORY_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CHAMPLAIN_TYPE_MEMORY_CACHE, ChamplainMemoryCacheClass))
#define CHAMPLAIN_IS_MEMORY_CACHE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CHAMPLAIN_TYPE_MEMORY_CACHE))
#define CHAMPLAIN_IS_MEMORY_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CHAMPLAIN_TYPE_MEMORY_CACHE))
#define CHAMPLAIN_MEMORY_CACHE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CHAMPLAIN_TYPE_MEMORY_CACHE, ChamplainMemoryCacheClass))
typedef struct _ChamplainMemoryCachePrivate ChamplainMemoryCachePrivate;
typedef struct _ChamplainMemoryCache ChamplainMemoryCache;
typedef struct _ChamplainMemoryCacheClass ChamplainMemoryCacheClass;
struct _ChamplainMemoryCache
{
ChamplainTileCache parent_instance;
ChamplainMemoryCachePrivate *priv;
};
struct _ChamplainMemoryCacheClass
{
ChamplainTileCacheClass parent_class;
};
GType champlain_memory_cache_get_type (void);
ChamplainMemoryCache *champlain_memory_cache_new (void);
ChamplainMemoryCache *champlain_memory_cache_new_full (guint size_limit);
guint champlain_memory_cache_get_size_limit (ChamplainMemoryCache *memory_cache);
void champlain_memory_cache_set_size_limit (ChamplainMemoryCache *memory_cache,
guint size_limit);
void champlain_memory_cache_clean (ChamplainMemoryCache *memory_cache);
G_END_DECLS
#endif /* _CHAMPLAIN_MEMORY_CACHE_H_ */
......@@ -353,7 +353,7 @@ tile_rendered_cb (ChamplainTile *tile,
champlain_map_source_fill_tile (next_source, tile);
g_object_unref (map_source);
g_signal_handlers_disconnect_by_func (tile, tile_rendered_cb, data);
g_signal_handlers_disconnect_by_func (tile, tile_rendered_cb, map_source);
}
static void
......
......@@ -548,7 +548,7 @@ tile_rendered_cb (ChamplainTile *tile, ChamplainRenderCallbackData *data, TileRe
g_object_unref (map_source);
g_free (user_data);
g_signal_handlers_disconnect_by_func (tile, tile_rendered_cb, data);
g_signal_handlers_disconnect_by_func (tile, tile_rendered_cb, user_data);
}
......
......@@ -104,7 +104,7 @@ tile_rendered_cb (ChamplainTile *tile,
champlain_map_source_fill_tile (next_source, tile);
g_object_unref (map_source);
g_signal_handlers_disconnect_by_func (tile, tile_rendered_cb, data);
g_signal_handlers_disconnect_by_func (tile, tile_rendered_cb, map_source);
}
......
......@@ -31,16 +31,6 @@ G_DEFINE_TYPE (ChamplainTileCache, champlain_tile_cache, CHAMPLAIN_TYPE_MAP_SOUR
#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), CHAMPLAIN_TYPE_TILE_CACHE, ChamplainTileCachePrivate))
enum
{
PROP_0,
PROP_PERSISTENT_CACHE
};
struct _ChamplainTileCachePrivate
{
gboolean persistent;
};
static const gchar *get_id (ChamplainMapSource *map_source);
static const gchar *get_name (ChamplainMapSource *map_source);
......@@ -50,43 +40,7 @@ static guint get_min_zoom_level (ChamplainMapSource *map_source);
static guint get_max_zoom_level (ChamplainMapSource *map_source);
static guint get_tile_size (ChamplainMapSource *map_source);
static ChamplainMapProjection get_projection (ChamplainMapSource *map_source);
static void reload_tiles_cb (ChamplainTileCache *tile_cache, G_GNUC_UNUSED gpointer data);
static void
champlain_tile_cache_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
ChamplainTileCache *tile_cache = CHAMPLAIN_TILE_CACHE (object);
switch (property_id)
{
case PROP_PERSISTENT_CACHE:
g_value_set_boolean (value, champlain_tile_cache_get_persistent (tile_cache));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
champlain_tile_cache_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
ChamplainTileCachePrivate *priv = CHAMPLAIN_TILE_CACHE (object)->priv;
switch (property_id)
{
case PROP_PERSISTENT_CACHE:
priv->persistent = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
champlain_tile_cache_dispose (GObject *object)
......@@ -112,14 +66,9 @@ champlain_tile_cache_class_init (ChamplainTileCacheClass *klass)
GObjectClass* object_class = G_OBJECT_CLASS (klass);
ChamplainMapSourceClass *map_source_class = CHAMPLAIN_MAP_SOURCE_CLASS (klass);
ChamplainTileCacheClass *tile_cache_class = CHAMPLAIN_TILE_CACHE_CLASS (klass);
GParamSpec *pspec;
g_type_class_add_private (klass, sizeof (ChamplainTileCachePrivate));
object_class->finalize = champlain_tile_cache_finalize;
object_class->dispose = champlain_tile_cache_dispose;
object_class->get_property = champlain_tile_cache_get_property;
object_class->set_property = champlain_tile_cache_set_property;
object_class->constructed = champlain_tile_cache_constructed;
map_source_class->get_id = get_id;
......@@ -136,62 +85,13 @@ champlain_tile_cache_class_init (ChamplainTileCacheClass *klass)
tile_cache_class->refresh_tile_time = NULL;
tile_cache_class->on_tile_filled = NULL;
tile_cache_class->store_tile = NULL;
tile_cache_class->clean = NULL;
/**
* ChamplainTileCache:persistent-cache
*
* Determines whether the cache is persistent or temporary (cleaned upon
* destruction)
*
* Since: 0.6
*/
pspec = g_param_spec_boolean ("persistent-cache",
"Persistent Cache",
"Specifies whether the cache is persistent",
TRUE,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_PERSISTENT_CACHE, pspec);
}
static void
champlain_tile_cache_init (ChamplainTileCache *tile_cache)
{
ChamplainTileCachePrivate *priv = GET_PRIVATE (tile_cache);
tile_cache->priv = priv;
priv->persistent = TRUE;
g_signal_connect (tile_cache, "reload-tiles",
G_CALLBACK (reload_tiles_cb), NULL);
}
static
void reload_tiles_cb (ChamplainTileCache *tile_cache, G_GNUC_UNUSED gpointer data)
{
g_return_if_fail (CHAMPLAIN_IS_TILE_CACHE (tile_cache));
if (!champlain_tile_cache_get_persistent (tile_cache))
champlain_tile_cache_clean (tile_cache);
}
/**
* champlain_tile_cache_get_persistent:
* @tile_cache: a #ChamplainTileCache
*
* Gets cache persistency information.
*
* Returns: TRUE when the cache is persistent; FALSE otherwise.
*
* Since: 0.6
*/
gboolean
champlain_tile_cache_get_persistent (ChamplainTileCache *tile_cache)
{
g_return_val_if_fail (CHAMPLAIN_IS_TILE_CACHE (tile_cache), FALSE);
return tile_cache->priv->persistent;
}
/**
* champlain_tile_cache_store_tile:
......@@ -257,23 +157,6 @@ champlain_tile_cache_on_tile_filled (ChamplainTileCache *tile_cache,
CHAMPLAIN_TILE_CACHE_GET_CLASS (tile_cache)->on_tile_filled (tile_cache, tile);
}
/**
* champlain_tile_cache_clean:
* @tile_cache: a #ChamplainTileCache
*
* Erases the contents of the cache. This function will fail when the cache is
* not temporary.
*
* Since: 0.6
*/
void
champlain_tile_cache_clean (ChamplainTileCache *tile_cache)
{
g_return_if_fail (CHAMPLAIN_IS_TILE_CACHE (tile_cache));
CHAMPLAIN_TILE_CACHE_GET_CLASS (tile_cache)->clean (tile_cache);
}
static const gchar *
get_id (ChamplainMapSource *map_source)
{
......
......@@ -59,13 +59,10 @@ struct _ChamplainTileCacheClass
ChamplainTile *tile);
void (*on_tile_filled) (ChamplainTileCache *tile_cache,
ChamplainTile *tile);
void (*clean) (ChamplainTileCache *tile_cache);
};
GType champlain_tile_cache_get_type (void);
gboolean champlain_tile_cache_get_persistent (ChamplainTileCache *tile_cache);
void champlain_tile_cache_store_tile (ChamplainTileCache *tile_cache,
ChamplainTile *tile,
const gchar *contents,
......@@ -74,7 +71,6 @@ void champlain_tile_cache_refresh_tile_time (ChamplainTileCache *tile_cache,
ChamplainTile *tile);
void champlain_tile_cache_on_tile_filled (ChamplainTileCache *tile_cache,
ChamplainTile *tile);
void champlain_tile_cache_clean (ChamplainTileCache *tile_cache);
G_END_DECLS
......
......@@ -37,6 +37,7 @@
#include "champlain/champlain-map-source-chain.h"
#include "champlain/champlain-tile-source.h"
#include "champlain/champlain-tile-cache.h"
#include "champlain/champlain-memory-cache.h"
#include "champlain/champlain-network-tile-source.h"
#include "champlain/champlain-file-cache.h"
#include "champlain/champlain-null-tile-source.h"
......
......@@ -444,7 +444,8 @@ map_source_changed (GtkWidget *widget, ChamplainView *view)
champlain_map_source_chain_push (source_chain, src);
champlain_map_source_chain_push (source_chain, tile_source);
src = CHAMPLAIN_MAP_SOURCE(champlain_file_cache_new_full (100000000, NULL, FALSE));
src = CHAMPLAIN_MAP_SOURCE(champlain_memory_cache_new_full (100));
champlain_map_source_set_renderer (src, CHAMPLAIN_RENDERER (champlain_image_renderer_new ()));
champlain_map_source_chain_push (source_chain, src);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment