diff options
author | William Wilgus <wilgus.william@gmail.com> | 2021-03-10 19:07:06 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2021-03-18 02:39:30 +0000 |
commit | 29fa47d43d0a9a0fc98fddfa315145ecc7727044 (patch) | |
tree | 14a1954eeff2b720920ee13cb3a184f08fae63b4 /apps | |
parent | 10b873c407b4fc1448e302b4c023dae9d7e43e3c (diff) | |
download | rockbox-29fa47d43d0a9a0fc98fddfa315145ecc7727044.tar.gz rockbox-29fa47d43d0a9a0fc98fddfa315145ecc7727044.zip |
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
Diffstat (limited to 'apps')
-rw-r--r-- | apps/misc.c | 2 | ||||
-rw-r--r-- | apps/open_plugin.c | 145 | ||||
-rw-r--r-- | apps/open_plugin.h | 1 | ||||
-rw-r--r-- | apps/root_menu.c | 3 |
4 files changed, 103 insertions, 48 deletions
diff --git a/apps/misc.c b/apps/misc.c index 3a8798fec0..96ad534c68 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -65,6 +65,7 @@ | |||
65 | #include "viewport.h" | 65 | #include "viewport.h" |
66 | #include "list.h" | 66 | #include "list.h" |
67 | #include "fixedpoint.h" | 67 | #include "fixedpoint.h" |
68 | #include "open_plugin.h" | ||
68 | 69 | ||
69 | #include "debug.h" | 70 | #include "debug.h" |
70 | 71 | ||
@@ -279,6 +280,7 @@ static void system_flush(void) | |||
279 | { | 280 | { |
280 | playlist_shutdown(); | 281 | playlist_shutdown(); |
281 | tree_flush(); | 282 | tree_flush(); |
283 | open_plugin_cache_flush(); | ||
282 | call_storage_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */ | 284 | call_storage_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */ |
283 | } | 285 | } |
284 | 286 | ||
diff --git a/apps/open_plugin.c b/apps/open_plugin.c index 7448018ed9..2e9975adea 100644 --- a/apps/open_plugin.c +++ b/apps/open_plugin.c | |||
@@ -32,25 +32,82 @@ | |||
32 | #define OP_EXT "opx" | 32 | #define OP_EXT "opx" |
33 | #define OP_LEN 4 | 33 | #define OP_LEN 4 |
34 | 34 | ||
35 | struct open_plugin_entry_t open_plugin_entry; | 35 | struct open_plugin_entry_t open_plugin_entry = {0}; |
36 | 36 | ||
37 | static const int op_entry_sz = sizeof(struct open_plugin_entry_t); | 37 | static const int op_entry_sz = sizeof(struct open_plugin_entry_t); |
38 | 38 | ||
39 | static int open_plugin_hash_get_entry(uint32_t hash, | ||
40 | struct open_plugin_entry_t *entry, | ||
41 | const char* dat_file); | ||
42 | |||
43 | static inline void op_clear_entry(struct open_plugin_entry_t *entry) | ||
44 | { | ||
45 | if (entry) | ||
46 | { | ||
47 | memset(entry, 0, op_entry_sz); | ||
48 | entry->lang_id = -1; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | static int op_update_dat(struct open_plugin_entry_t *entry) | ||
53 | { | ||
54 | int fd, fd1; | ||
55 | uint32_t hash; | ||
56 | |||
57 | if (!entry || entry->hash == 0) | ||
58 | return -1; | ||
59 | |||
60 | hash = entry->hash; | ||
61 | |||
62 | fd = open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666); | ||
63 | if (!fd) | ||
64 | return -1; | ||
65 | write(fd, entry, op_entry_sz); | ||
66 | |||
67 | fd1 = open(OPEN_PLUGIN_DAT, O_RDONLY); | ||
68 | if (fd1) | ||
69 | { | ||
70 | while (read(fd1, &open_plugin_entry, op_entry_sz) == op_entry_sz) | ||
71 | { | ||
72 | if (open_plugin_entry.hash != hash) | ||
73 | write(fd, &open_plugin_entry, op_entry_sz); | ||
74 | } | ||
75 | close(fd1); | ||
76 | remove(OPEN_PLUGIN_DAT); | ||
77 | } | ||
78 | close(fd); | ||
79 | |||
80 | rename(OPEN_PLUGIN_DAT ".tmp", OPEN_PLUGIN_DAT); | ||
81 | |||
82 | op_clear_entry(&open_plugin_entry); | ||
83 | return 0; | ||
84 | } | ||
85 | |||
39 | uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter) | 86 | uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter) |
40 | { | 87 | { |
41 | int len; | 88 | int len; |
42 | bool is_valid = false; | 89 | bool is_valid = false; |
43 | uint32_t hash; | 90 | uint32_t hash; |
44 | char *pos; | 91 | int32_t lang_id; |
45 | int fd = 0; | 92 | char *pos = "\0"; |
46 | int fd1 = 0; | 93 | |
94 | if(!key) | ||
95 | { | ||
96 | op_clear_entry(&open_plugin_entry); | ||
97 | return 0; | ||
98 | } | ||
47 | 99 | ||
48 | /*strlcpy(plug_entry.key, key, sizeof(plug_entry.key));*/ | 100 | lang_id = P2ID((unsigned char*)key); |
49 | open_plugin_entry.lang_id = P2ID((unsigned char*)key); | ||
50 | key = P2STR((unsigned char *)key); | 101 | key = P2STR((unsigned char *)key); |
51 | 102 | ||
52 | open_plugin_get_hash(key, &hash); | 103 | open_plugin_get_hash(key, &hash); |
53 | open_plugin_entry.hash = hash; | 104 | |
105 | |||
106 | if(open_plugin_entry.hash != hash) | ||
107 | { | ||
108 | /* the entry in ram needs saved */ | ||
109 | op_update_dat(&open_plugin_entry); | ||
110 | } | ||
54 | 111 | ||
55 | if (plugin) | 112 | if (plugin) |
56 | { | 113 | { |
@@ -74,49 +131,22 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p | |||
74 | else if (len > OP_LEN && strcasecmp(&(pos[len-OP_LEN]), "." OP_EXT) == 0) | 131 | else if (len > OP_LEN && strcasecmp(&(pos[len-OP_LEN]), "." OP_EXT) == 0) |
75 | { | 132 | { |
76 | is_valid = true; | 133 | is_valid = true; |
77 | /* path */ | 134 | open_plugin_hash_get_entry(0, &open_plugin_entry, plugin); |
78 | strlcpy(open_plugin_entry.path, | ||
79 | VIEWERS_DATA_DIR "/open_plugins." ROCK_EXT, OPEN_PLUGIN_BUFSZ); | ||
80 | /* parameter */ | ||
81 | strlcpy(open_plugin_entry.param, plugin, OPEN_PLUGIN_BUFSZ); | ||
82 | |||
83 | write(fd, &open_plugin_entry, op_entry_sz); | ||
84 | } | ||
85 | |||
86 | if (is_valid) | ||
87 | { | ||
88 | fd = open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666); | ||
89 | if (!fd) | ||
90 | return 0; | ||
91 | write(fd, &open_plugin_entry, op_entry_sz); | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | if (open_plugin_entry.lang_id != LANG_SHORTCUTS) | ||
96 | splashf(HZ / 2, str(LANG_OPEN_PLUGIN_NOT_A_PLUGIN), pos); | ||
97 | return 0; | ||
98 | } | 135 | } |
99 | } | 136 | } |
100 | 137 | ||
101 | fd1 = open(OPEN_PLUGIN_DAT, O_RDONLY); | 138 | if (!is_valid) |
102 | if (fd1) | ||
103 | { | 139 | { |
104 | while (read(fd1, &open_plugin_entry, op_entry_sz) == op_entry_sz) | 140 | if (open_plugin_entry.lang_id != LANG_SHORTCUTS) |
105 | { | 141 | splashf(HZ / 2, str(LANG_OPEN_PLUGIN_NOT_A_PLUGIN), pos); |
106 | if (open_plugin_entry.hash != hash) | 142 | op_clear_entry(&open_plugin_entry); |
107 | write(fd, &open_plugin_entry, op_entry_sz); | 143 | hash = 0; |
108 | } | ||
109 | close(fd1); | ||
110 | } | 144 | } |
111 | close(fd); | 145 | else |
112 | |||
113 | if(fd1) | ||
114 | { | 146 | { |
115 | remove(OPEN_PLUGIN_DAT); | 147 | open_plugin_entry.hash = hash; |
116 | rename(OPEN_PLUGIN_DAT ".tmp", OPEN_PLUGIN_DAT); | 148 | open_plugin_entry.lang_id = lang_id; |
117 | } | 149 | } |
118 | else | ||
119 | hash = 0; | ||
120 | 150 | ||
121 | return hash; | 151 | return hash; |
122 | } | 152 | } |
@@ -140,20 +170,31 @@ void open_plugin_browse(const char *key) | |||
140 | open_plugin_add_path(key, tmp_buf, NULL); | 170 | open_plugin_add_path(key, tmp_buf, NULL); |
141 | } | 171 | } |
142 | 172 | ||
143 | static int open_plugin_hash_get_entry(uint32_t hash, struct open_plugin_entry_t *entry) | 173 | static int open_plugin_hash_get_entry(uint32_t hash, |
174 | struct open_plugin_entry_t *entry, | ||
175 | const char* dat_file) | ||
144 | { | 176 | { |
145 | int ret = -1, record = -1; | 177 | int ret = -1, record = -1; |
146 | 178 | ||
147 | if (entry) | 179 | if (entry) |
148 | { | 180 | { |
149 | int fd = open(OPEN_PLUGIN_DAT, O_RDONLY); | 181 | |
182 | if (hash != 0) | ||
183 | { | ||
184 | if(entry->hash == hash) /* hasn't been flushed yet? */ | ||
185 | return 0; | ||
186 | else | ||
187 | op_update_dat(&open_plugin_entry); | ||
188 | } | ||
189 | |||
190 | int fd = open(dat_file, O_RDONLY); | ||
150 | 191 | ||
151 | if (fd) | 192 | if (fd) |
152 | { | 193 | { |
153 | while (read(fd, entry, op_entry_sz) == op_entry_sz) | 194 | while (read(fd, entry, op_entry_sz) == op_entry_sz) |
154 | { | 195 | { |
155 | record++; | 196 | record++; |
156 | if (entry->hash == hash) | 197 | if (hash == 0 || entry->hash == hash) |
157 | { | 198 | { |
158 | ret = record; | 199 | ret = record; |
159 | break; | 200 | break; |
@@ -176,8 +217,8 @@ int open_plugin_get_entry(const char *key, struct open_plugin_entry_t *entry) | |||
176 | uint32_t hash; | 217 | uint32_t hash; |
177 | key = P2STR((unsigned char *)key); | 218 | key = P2STR((unsigned char *)key); |
178 | 219 | ||
179 | open_plugin_get_hash(key, &hash); | 220 | open_plugin_get_hash(key, &hash); /* in open_plugin.h */ |
180 | return open_plugin_hash_get_entry(hash, entry); | 221 | return open_plugin_hash_get_entry(hash, entry, OPEN_PLUGIN_DAT); |
181 | } | 222 | } |
182 | 223 | ||
183 | int open_plugin_run(const char *key) | 224 | int open_plugin_run(const char *key) |
@@ -196,7 +237,15 @@ int open_plugin_run(const char *key) | |||
196 | if (path) | 237 | if (path) |
197 | ret = plugin_load(path, param); | 238 | ret = plugin_load(path, param); |
198 | 239 | ||
240 | if (ret != GO_TO_PLUGIN) | ||
241 | op_clear_entry(&open_plugin_entry); | ||
242 | |||
199 | return ret; | 243 | return ret; |
200 | } | 244 | } |
201 | 245 | ||
246 | void open_plugin_cache_flush(void) | ||
247 | { | ||
248 | op_update_dat(&open_plugin_entry); | ||
249 | } | ||
250 | |||
202 | #endif /* ndef __PCTOOL__ */ | 251 | #endif /* ndef __PCTOOL__ */ |
diff --git a/apps/open_plugin.h b/apps/open_plugin.h index 9f20d7ffda..8c09c4ac58 100644 --- a/apps/open_plugin.h +++ b/apps/open_plugin.h | |||
@@ -59,6 +59,7 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p | |||
59 | int open_plugin_get_entry(const char *key, struct open_plugin_entry_t *entry); | 59 | int open_plugin_get_entry(const char *key, struct open_plugin_entry_t *entry); |
60 | void open_plugin_browse(const char *key); | 60 | void open_plugin_browse(const char *key); |
61 | int open_plugin_run(const char *key); | 61 | int open_plugin_run(const char *key); |
62 | void open_plugin_cache_flush(void); /* flush to disk */ | ||
62 | #endif | 63 | #endif |
63 | 64 | ||
64 | #endif /*ndef __PCTOOL__ */ | 65 | #endif /*ndef __PCTOOL__ */ |
diff --git a/apps/root_menu.c b/apps/root_menu.c index 8df9f87d44..f4f984b823 100644 --- a/apps/root_menu.c +++ b/apps/root_menu.c | |||
@@ -856,6 +856,9 @@ void root_menu(void) | |||
856 | 856 | ||
857 | next_screen = load_plugin_screen(path, param); | 857 | next_screen = load_plugin_screen(path, param); |
858 | 858 | ||
859 | if (next_screen != GO_TO_PLUGIN) | ||
860 | open_plugin_add_path(NULL, NULL, NULL); | ||
861 | |||
859 | /* shortcuts may take several trips through the GO_TO_PLUGIN case | 862 | /* shortcuts may take several trips through the GO_TO_PLUGIN case |
860 | make sure we preserve and restore the origin */ | 863 | make sure we preserve and restore the origin */ |
861 | if (next_screen == GO_TO_PREVIOUS && shortcut_origin != GO_TO_ROOT) | 864 | if (next_screen == GO_TO_PREVIOUS && shortcut_origin != GO_TO_ROOT) |