low level source data cache backing store interface.

This commit is contained in:
Vincent Sanders 2014-03-08 14:40:09 +00:00
parent ccc9ad969b
commit 657abbd245
5 changed files with 220 additions and 4 deletions

View File

@ -1,6 +1,6 @@
# Content sources
S_CONTENT := content.c content_factory.c dirlist.c fetch.c hlcache.c \
llcache.c mimesniff.c urldb.c
llcache.c mimesniff.c urldb.c no_backing_store.c
S_CONTENT := $(addprefix content/,$(S_CONTENT))
S_CONTENT := $(addprefix content/,$(S_CONTENT))

100
content/backing_store.h Normal file
View File

@ -0,0 +1,100 @@
/*
* Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* Low-level source data cache backing store interface
*/
#ifndef NETSURF_CONTENT_LLCACHE_PRIVATE_H_
#define NETSURF_CONTENT_LLCACHE_PRIVATE_H_
#include "content/llcache.h"
/** storage control flags */
enum backing_store_flags {
BACKING_STORE_NONE = 0, /**< no special processing */
BACKING_STORE_META = 1, /**< data is metadata */
BACKING_STORE_MMAP = 2, /**< when data is retrived this indicates the
* returned buffer may be memory mapped,
* flag must be cleared if the storage is
* allocated and is not memory mapped.
*/
};
/** low level cache backing store operation table
*
* The low level cache (source objects) has the capability to make
* objects and their metadata (headers etc) persistant by writing to a
* backing store using these operations.
*/
struct gui_llcache_table {
/**
* Initialise the backing store.
*
* @param parameters to configure backing store.
* @return NSERROR_OK on success or error code on faliure.
*/
nserror (*initialise)(const struct llcache_store_parameters *parameters);
/**
* Finalise the backing store.
*
* @return NSERROR_OK on success or error code on faliure.
*/
nserror (*finalise)(void);
/**
* Place an object in the backing store.
*
* @param url The url is used as the unique primary key for the data.
* @param flags The flags to control how the obejct is stored.
* @param data The objects data.
* @param datalen The length of the \a data.
* @return NSERROR_OK on success or error code on faliure.
*/
nserror (*store)(struct nsurl *url, enum backing_store_flags flags,
const uint8_t *data, const size_t datalen);
/**
* Retrive an object from the backing store.
*
* @param url The url is used as the unique primary key for the data.
* @param flags The flags to control how the object is retrived.
* @param data The objects data.
* @param datalen The length of the \a data retrieved.
* @return NSERROR_OK on success or error code on faliure.
*/
nserror (*fetch)(struct nsurl *url, enum backing_store_flags *flags,
uint8_t **data, size_t *datalen);
/**
* Invalidate a source object from the backing store.
*
* The entry (if present in the backing store) must no longer
* be returned as a result to the fetch or meta operations.
*
* @param url The url is used as the unique primary key to invalidate.
* @return NSERROR_OK on success or error code on faliure.
*/
nserror (*invalidate)(struct nsurl *url);
};
extern struct gui_llcache_table* null_llcache_table;
extern struct gui_llcache_table* filesystem_llcache_table;
#endif

View File

@ -0,0 +1,68 @@
/*
* Copyright 2014 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* Low-level resource cache null persistant storage implementation.
*/
#include "utils/nsurl.h"
#include "content/backing_store.h"
/* default to disabled backing store */
static nserror initialise(const struct llcache_store_parameters *parameters)
{
return NSERROR_OK;
}
static nserror finalise(void)
{
return NSERROR_OK;
}
static nserror store(nsurl *url,
enum backing_store_flags flags,
const uint8_t *data,
const size_t datalen)
{
return NSERROR_SAVE_FAILED;
}
static nserror fetch(nsurl *url,
enum backing_store_flags *flags,
uint8_t **data_out,
size_t *datalen_out)
{
return NSERROR_NOT_FOUND;
}
static nserror invalidate(nsurl *url)
{
return NSERROR_NOT_FOUND;
}
static struct gui_llcache_table llcache_table = {
.initialise = initialise,
.finalise = finalise,
.store = store,
.fetch = fetch,
.invalidate = invalidate,
};
struct gui_llcache_table *null_llcache_table = &llcache_table;

View File

@ -69,6 +69,7 @@ struct hlcache_handle;
struct download_context;
struct nsurl;
struct gui_file_table;
struct gui_llcache_table;
typedef struct nsnsclipboard_styles {
size_t start; /**< Start of run */
@ -520,7 +521,6 @@ struct gui_browser_table {
};
/**
* NetSurf operation function table
*
@ -572,6 +572,15 @@ struct netsurf_table {
* Provides routines for the interactive text search on a page.
*/
struct gui_search_table *search;
/**
* Low level cache table.
*
* Used by the low level cache to push objects to persistant
* storage. The table is optional and may be NULL which
* uses the default implementation.
*/
struct gui_llcache_table *llcache;
};

View File

@ -17,6 +17,8 @@
*/
#include "content/hlcache.h"
#include "content/backing_store.h"
#include "desktop/download.h"
#include "desktop/gui_factory.h"
#include "utils/file.h"
@ -25,7 +27,6 @@
struct netsurf_table *guit = NULL;
static void gui_default_window_set_title(struct gui_window *g, const char *title)
{
}
@ -400,6 +401,34 @@ static nserror verify_search_register(struct gui_search_table *gst)
return NSERROR_OK;
}
/** verify low level cache persistant backing store table is valid */
static nserror verify_llcache_register(struct gui_llcache_table *glt)
{
/* check table is present */
if (glt == NULL) {
return NSERROR_BAD_PARAMETER;
}
/* mandantory operations */
if (glt->store == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (glt->fetch == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (glt->invalidate == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (glt->initialise == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (glt->finalise == NULL) {
return NSERROR_BAD_PARAMETER;
}
return NSERROR_OK;
}
static nsurl *gui_default_get_resource_url(const char *path)
{
return NULL;
@ -622,6 +651,16 @@ nserror gui_factory_register(struct netsurf_table *gt)
return err;
}
/* llcache table */
if (gt->llcache == NULL) {
/* set default backing store table */
gt->llcache = null_llcache_table;
}
err = verify_llcache_register(gt->llcache);
if (err != NSERROR_OK) {
return err;
}
guit = gt;
return NSERROR_OK;