forked from len0rd/rockbox
Open Plugin cache plugin entry when possible
leave plugin entries in ram and try not to save them unless necessary doesn't use more space just a bit of careful ordering with the buffer Change-Id: I1973e9ad4655c2544f596b37cee35601a0cffa94
This commit is contained in:
parent
10b873c407
commit
29fa47d43d
4 changed files with 104 additions and 49 deletions
|
@ -65,6 +65,7 @@
|
||||||
#include "viewport.h"
|
#include "viewport.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "fixedpoint.h"
|
#include "fixedpoint.h"
|
||||||
|
#include "open_plugin.h"
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
@ -279,6 +280,7 @@ static void system_flush(void)
|
||||||
{
|
{
|
||||||
playlist_shutdown();
|
playlist_shutdown();
|
||||||
tree_flush();
|
tree_flush();
|
||||||
|
open_plugin_cache_flush();
|
||||||
call_storage_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
|
call_storage_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,25 +32,82 @@
|
||||||
#define OP_EXT "opx"
|
#define OP_EXT "opx"
|
||||||
#define OP_LEN 4
|
#define OP_LEN 4
|
||||||
|
|
||||||
struct open_plugin_entry_t open_plugin_entry;
|
struct open_plugin_entry_t open_plugin_entry = {0};
|
||||||
|
|
||||||
static const int op_entry_sz = sizeof(struct open_plugin_entry_t);
|
static const int op_entry_sz = sizeof(struct open_plugin_entry_t);
|
||||||
|
|
||||||
|
static int open_plugin_hash_get_entry(uint32_t hash,
|
||||||
|
struct open_plugin_entry_t *entry,
|
||||||
|
const char* dat_file);
|
||||||
|
|
||||||
|
static inline void op_clear_entry(struct open_plugin_entry_t *entry)
|
||||||
|
{
|
||||||
|
if (entry)
|
||||||
|
{
|
||||||
|
memset(entry, 0, op_entry_sz);
|
||||||
|
entry->lang_id = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int op_update_dat(struct open_plugin_entry_t *entry)
|
||||||
|
{
|
||||||
|
int fd, fd1;
|
||||||
|
uint32_t hash;
|
||||||
|
|
||||||
|
if (!entry || entry->hash == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
hash = entry->hash;
|
||||||
|
|
||||||
|
fd = open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||||
|
if (!fd)
|
||||||
|
return -1;
|
||||||
|
write(fd, entry, op_entry_sz);
|
||||||
|
|
||||||
|
fd1 = open(OPEN_PLUGIN_DAT, O_RDONLY);
|
||||||
|
if (fd1)
|
||||||
|
{
|
||||||
|
while (read(fd1, &open_plugin_entry, op_entry_sz) == op_entry_sz)
|
||||||
|
{
|
||||||
|
if (open_plugin_entry.hash != hash)
|
||||||
|
write(fd, &open_plugin_entry, op_entry_sz);
|
||||||
|
}
|
||||||
|
close(fd1);
|
||||||
|
remove(OPEN_PLUGIN_DAT);
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
rename(OPEN_PLUGIN_DAT ".tmp", OPEN_PLUGIN_DAT);
|
||||||
|
|
||||||
|
op_clear_entry(&open_plugin_entry);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter)
|
uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
bool is_valid = false;
|
bool is_valid = false;
|
||||||
uint32_t hash;
|
uint32_t hash;
|
||||||
char *pos;
|
int32_t lang_id;
|
||||||
int fd = 0;
|
char *pos = "\0";
|
||||||
int fd1 = 0;
|
|
||||||
|
|
||||||
/*strlcpy(plug_entry.key, key, sizeof(plug_entry.key));*/
|
if(!key)
|
||||||
open_plugin_entry.lang_id = P2ID((unsigned char*)key);
|
{
|
||||||
|
op_clear_entry(&open_plugin_entry);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lang_id = P2ID((unsigned char*)key);
|
||||||
key = P2STR((unsigned char *)key);
|
key = P2STR((unsigned char *)key);
|
||||||
|
|
||||||
open_plugin_get_hash(key, &hash);
|
open_plugin_get_hash(key, &hash);
|
||||||
open_plugin_entry.hash = hash;
|
|
||||||
|
|
||||||
|
if(open_plugin_entry.hash != hash)
|
||||||
|
{
|
||||||
|
/* the entry in ram needs saved */
|
||||||
|
op_update_dat(&open_plugin_entry);
|
||||||
|
}
|
||||||
|
|
||||||
if (plugin)
|
if (plugin)
|
||||||
{
|
{
|
||||||
|
@ -74,49 +131,22 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p
|
||||||
else if (len > OP_LEN && strcasecmp(&(pos[len-OP_LEN]), "." OP_EXT) == 0)
|
else if (len > OP_LEN && strcasecmp(&(pos[len-OP_LEN]), "." OP_EXT) == 0)
|
||||||
{
|
{
|
||||||
is_valid = true;
|
is_valid = true;
|
||||||
/* path */
|
open_plugin_hash_get_entry(0, &open_plugin_entry, plugin);
|
||||||
strlcpy(open_plugin_entry.path,
|
|
||||||
VIEWERS_DATA_DIR "/open_plugins." ROCK_EXT, OPEN_PLUGIN_BUFSZ);
|
|
||||||
/* parameter */
|
|
||||||
strlcpy(open_plugin_entry.param, plugin, OPEN_PLUGIN_BUFSZ);
|
|
||||||
|
|
||||||
write(fd, &open_plugin_entry, op_entry_sz);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_valid)
|
|
||||||
{
|
|
||||||
fd = open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
|
||||||
if (!fd)
|
|
||||||
return 0;
|
|
||||||
write(fd, &open_plugin_entry, op_entry_sz);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (open_plugin_entry.lang_id != LANG_SHORTCUTS)
|
|
||||||
splashf(HZ / 2, str(LANG_OPEN_PLUGIN_NOT_A_PLUGIN), pos);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fd1 = open(OPEN_PLUGIN_DAT, O_RDONLY);
|
if (!is_valid)
|
||||||
if (fd1)
|
|
||||||
{
|
{
|
||||||
while (read(fd1, &open_plugin_entry, op_entry_sz) == op_entry_sz)
|
if (open_plugin_entry.lang_id != LANG_SHORTCUTS)
|
||||||
{
|
splashf(HZ / 2, str(LANG_OPEN_PLUGIN_NOT_A_PLUGIN), pos);
|
||||||
if (open_plugin_entry.hash != hash)
|
op_clear_entry(&open_plugin_entry);
|
||||||
write(fd, &open_plugin_entry, op_entry_sz);
|
hash = 0;
|
||||||
}
|
|
||||||
close(fd1);
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if(fd1)
|
|
||||||
{
|
|
||||||
remove(OPEN_PLUGIN_DAT);
|
|
||||||
rename(OPEN_PLUGIN_DAT ".tmp", OPEN_PLUGIN_DAT);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
hash = 0;
|
{
|
||||||
|
open_plugin_entry.hash = hash;
|
||||||
|
open_plugin_entry.lang_id = lang_id;
|
||||||
|
}
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
@ -140,20 +170,31 @@ void open_plugin_browse(const char *key)
|
||||||
open_plugin_add_path(key, tmp_buf, NULL);
|
open_plugin_add_path(key, tmp_buf, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_plugin_hash_get_entry(uint32_t hash, struct open_plugin_entry_t *entry)
|
static int open_plugin_hash_get_entry(uint32_t hash,
|
||||||
|
struct open_plugin_entry_t *entry,
|
||||||
|
const char* dat_file)
|
||||||
{
|
{
|
||||||
int ret = -1, record = -1;
|
int ret = -1, record = -1;
|
||||||
|
|
||||||
if (entry)
|
if (entry)
|
||||||
{
|
{
|
||||||
int fd = open(OPEN_PLUGIN_DAT, O_RDONLY);
|
|
||||||
|
if (hash != 0)
|
||||||
|
{
|
||||||
|
if(entry->hash == hash) /* hasn't been flushed yet? */
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
op_update_dat(&open_plugin_entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
int fd = open(dat_file, O_RDONLY);
|
||||||
|
|
||||||
if (fd)
|
if (fd)
|
||||||
{
|
{
|
||||||
while (read(fd, entry, op_entry_sz) == op_entry_sz)
|
while (read(fd, entry, op_entry_sz) == op_entry_sz)
|
||||||
{
|
{
|
||||||
record++;
|
record++;
|
||||||
if (entry->hash == hash)
|
if (hash == 0 || entry->hash == hash)
|
||||||
{
|
{
|
||||||
ret = record;
|
ret = record;
|
||||||
break;
|
break;
|
||||||
|
@ -176,8 +217,8 @@ int open_plugin_get_entry(const char *key, struct open_plugin_entry_t *entry)
|
||||||
uint32_t hash;
|
uint32_t hash;
|
||||||
key = P2STR((unsigned char *)key);
|
key = P2STR((unsigned char *)key);
|
||||||
|
|
||||||
open_plugin_get_hash(key, &hash);
|
open_plugin_get_hash(key, &hash); /* in open_plugin.h */
|
||||||
return open_plugin_hash_get_entry(hash, entry);
|
return open_plugin_hash_get_entry(hash, entry, OPEN_PLUGIN_DAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int open_plugin_run(const char *key)
|
int open_plugin_run(const char *key)
|
||||||
|
@ -196,7 +237,15 @@ int open_plugin_run(const char *key)
|
||||||
if (path)
|
if (path)
|
||||||
ret = plugin_load(path, param);
|
ret = plugin_load(path, param);
|
||||||
|
|
||||||
|
if (ret != GO_TO_PLUGIN)
|
||||||
|
op_clear_entry(&open_plugin_entry);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void open_plugin_cache_flush(void)
|
||||||
|
{
|
||||||
|
op_update_dat(&open_plugin_entry);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* ndef __PCTOOL__ */
|
#endif /* ndef __PCTOOL__ */
|
||||||
|
|
|
@ -59,6 +59,7 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p
|
||||||
int open_plugin_get_entry(const char *key, struct open_plugin_entry_t *entry);
|
int open_plugin_get_entry(const char *key, struct open_plugin_entry_t *entry);
|
||||||
void open_plugin_browse(const char *key);
|
void open_plugin_browse(const char *key);
|
||||||
int open_plugin_run(const char *key);
|
int open_plugin_run(const char *key);
|
||||||
|
void open_plugin_cache_flush(void); /* flush to disk */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*ndef __PCTOOL__ */
|
#endif /*ndef __PCTOOL__ */
|
||||||
|
|
|
@ -856,6 +856,9 @@ void root_menu(void)
|
||||||
|
|
||||||
next_screen = load_plugin_screen(path, param);
|
next_screen = load_plugin_screen(path, param);
|
||||||
|
|
||||||
|
if (next_screen != GO_TO_PLUGIN)
|
||||||
|
open_plugin_add_path(NULL, NULL, NULL);
|
||||||
|
|
||||||
/* shortcuts may take several trips through the GO_TO_PLUGIN case
|
/* shortcuts may take several trips through the GO_TO_PLUGIN case
|
||||||
make sure we preserve and restore the origin */
|
make sure we preserve and restore the origin */
|
||||||
if (next_screen == GO_TO_PREVIOUS && shortcut_origin != GO_TO_ROOT)
|
if (next_screen == GO_TO_PREVIOUS && shortcut_origin != GO_TO_ROOT)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue