typedef struct _ChamplainCachePrivate ChamplainCachePrivate;
+static ChamplainCache *instance = NULL;
+
struct _ChamplainCachePrivate {
guint size_limit;
G_OBJECT_CLASS (champlain_cache_parent_class)->finalize (object);
}
+static GObject *
+champlain_cache_constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ GObject *retval;
+
+ if (instance == NULL)
+ {
+ retval = G_OBJECT_CLASS (champlain_cache_parent_class)->constructor
+ (type, n_construct_params, construct_params);
+
+ instance = CHAMPLAIN_CACHE (retval);
+ g_object_add_weak_pointer (retval, (gpointer) &instance);
+ }
+ else
+ {
+ retval = g_object_ref (instance);
+ }
+
+ return retval;
+}
+
static void
champlain_cache_class_init (ChamplainCacheClass *klass)
{
g_type_class_add_private (klass, sizeof (ChamplainCachePrivate));
+ object_class->constructor = champlain_cache_constructor;
object_class->get_property = champlain_cache_get_property;
object_class->set_property = champlain_cache_set_property;
object_class->dispose = champlain_cache_dispose;
* Since: 0.4
*/
ChamplainCache*
-champlain_cache_get_default (void)
+champlain_cache_dup_default (void)
{
- static ChamplainCache * instance = NULL;
-
- if (G_UNLIKELY (instance == NULL))
- {
- instance = g_object_new (CHAMPLAIN_TYPE_CACHE, NULL);
- return instance;
- }
-
- return g_object_ref (instance);
+ return g_object_new (CHAMPLAIN_TYPE_CACHE, NULL);
}
/**
g_strdup (filename));
if (priv->popularity_id == 0)
+ {
+ g_object_ref (self);
priv->popularity_id = g_idle_add (inc_popularity, self);
+ }
cleanup:
sqlite3_reset (priv->stmt_select);
if (priv->popularity_queue == NULL)
{
+ g_object_unref (cache);
priv->popularity_id = 0;
return FALSE;
}
GFile *file;
GFileInfo *info;
guint filesize = 0;
- ChamplainCache *cache = champlain_cache_get_default ();
+ ChamplainCache *cache = champlain_cache_dup_default ();
filename = champlain_tile_get_filename (tile);
cleanup:
g_object_unref (loader);
+ g_object_unref (cache);
g_free (path);
finish:
champlain_tile_set_state (tile, CHAMPLAIN_STATE_DONE);
ChamplainNetworkMapSource *source = CHAMPLAIN_NETWORK_MAP_SOURCE (map_source);
ChamplainNetworkMapSourcePrivate *priv = source->priv;
- ChamplainCache *cache = champlain_cache_get_default ();
+ ChamplainCache *cache = champlain_cache_dup_default ();
/* Try the cached version first */
filename = get_filename (source, tile);
/* If a tile is neither in cache or can be fetched, do nothing, it'll show up
* as empty
*/
+ g_object_unref (cache);
}