Verified Commit 9a90caea authored by James Westman's avatar James Westman
Browse files

file-cache: Remove as a map source

This commit makes two BREAKING CHANGES to the file cache format!
- There is now an integer `modtime` column in the SQLite database. This
  is easier than using the filesystem modification time since we already
  need to query the database for the ETag.
- There is no longer a .png extension on cached files. There's no reason
  to assume the file is a PNG image, so it was unnecessary.

Makes ShumateFileCache its own class, rather than a subclass of
ShumateTileCache. It is curretly unused, but in the near future it will
be directly used by ShumateNetworkTileSource to cache tiles.

As part of this change, ShumateFileCache no longer fills tiles; it has
asynchronous methods to store and retrieve tile data, but it treats this data
as opaque. It is up to the user of the file cache to decode tile data.

Part of #15.
parent 9a4ea412
This diff is collapsed.
......@@ -26,12 +26,22 @@
#define _SHUMATE_FILE_CACHE_H_
#include <glib-object.h>
#include <shumate/shumate-tile-cache.h>
#include "shumate-tile.h"
G_BEGIN_DECLS
#define SHUMATE_TYPE_FILE_CACHE shumate_file_cache_get_type ()
G_DECLARE_DERIVABLE_TYPE (ShumateFileCache, shumate_file_cache, SHUMATE, FILE_CACHE, ShumateTileCache)
G_DECLARE_DERIVABLE_TYPE (ShumateFileCache, shumate_file_cache, SHUMATE, FILE_CACHE, GObject)
GQuark shumate_file_cache_error_quark (void);
#define SHUMATE_FILE_CACHE_ERROR shumate_file_cache_error_quark ()
typedef enum {
SHUMATE_FILE_CACHE_ERROR_DATABASE,
} ShumateFileCacheError;
/**
* ShumateFileCache:
......@@ -42,7 +52,7 @@ G_DECLARE_DERIVABLE_TYPE (ShumateFileCache, shumate_file_cache, SHUMATE, FILE_CA
struct _ShumateFileCacheClass
{
ShumateTileCacheClass parent_class;
GObjectClass parent_class;
};
ShumateFileCache *shumate_file_cache_new_full (guint size_limit,
......@@ -53,6 +63,31 @@ void shumate_file_cache_set_size_limit (ShumateFileCache *file_cache,
guint size_limit);
const char *shumate_file_cache_get_cache_dir (ShumateFileCache *file_cache);
const char *shumate_file_cache_get_cache_key (ShumateFileCache *file_cache);
void shumate_file_cache_retrieve_file_async (ShumateFileCache *self,
ShumateTile *tile,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GBytes *shumate_file_cache_retrieve_file_finish (ShumateFileCache *self,
GAsyncResult *result,
GError **error);
void shumate_file_cache_store_tile_async (ShumateFileCache *self,
ShumateTile *tile,
GBytes *data,
const char *etag,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean shumate_file_cache_store_tile_finish (ShumateFileCache *self,
GAsyncResult *result,
GError **error);
gboolean shumate_file_cache_check_validity (ShumateFileCache *self,
ShumateTile *tile,
char **etag_out);
void shumate_file_cache_purge (ShumateFileCache *file_cache);
void shumate_file_cache_purge_on_idle (ShumateFileCache *file_cache);
......
......@@ -41,7 +41,6 @@
#include "shumate-debug.h"
#include "shumate.h"
#include "shumate-file-cache.h"
#include "shumate-enum-types.h"
#include "shumate-map-source.h"
#include "shumate-marshal.h"
......@@ -299,7 +298,7 @@ shumate_map_source_factory_create (ShumateMapSourceFactory *factory,
* Creates a cached map source.
*
* Returns: (transfer none): a ready to use #ShumateMapSourceChain consisting of
* #ShumateFileCache, #ShumateMapSource matching the given name, and
* a #ShumateMapSource matching the given name and
* an error tile source created with shumate_map_source_factory_create_error_source ().
* Returns NULL if the source with the given name doesn't exist.
*/
......@@ -310,7 +309,6 @@ shumate_map_source_factory_create_cached_source (ShumateMapSourceFactory *factor
ShumateMapSourceChain *source_chain;
ShumateMapSource *tile_source;
ShumateMapSource *error_source;
ShumateMapSource *file_cache;
guint tile_size;
g_return_val_if_fail (SHUMATE_IS_MAP_SOURCE_FACTORY (factory), NULL);
......@@ -322,12 +320,9 @@ shumate_map_source_factory_create_cached_source (ShumateMapSourceFactory *factor
tile_size = shumate_map_source_get_tile_size (tile_source);
error_source = shumate_map_source_factory_create_error_source (factory, tile_size);
file_cache = SHUMATE_MAP_SOURCE (shumate_file_cache_new_full (100000000, NULL));
source_chain = shumate_map_source_chain_new ();
shumate_map_source_chain_push (source_chain, error_source);
shumate_map_source_chain_push (source_chain, tile_source);
shumate_map_source_chain_push (source_chain, file_cache);
return SHUMATE_MAP_SOURCE (source_chain);
}
......
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