summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/plugin.c52
-rw-r--r--apps/plugin.h14
2 files changed, 58 insertions, 8 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index bfa497479c..0fab448584 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -52,6 +52,17 @@
52#define PREFIX(_x_) _x_ 52#define PREFIX(_x_) _x_
53#endif 53#endif
54 54
55#define PLUGIN_BUFFER_SIZE 0x8000
56
57#ifdef SIMULATOR
58static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE];
59#else
60extern unsigned char pluginbuf[];
61#endif
62
63static bool plugin_loaded = false;
64static int plugin_size = 0;
65
55static int plugin_test(int api_version, int model, int memsize); 66static int plugin_test(int api_version, int model, int memsize);
56 67
57static struct plugin_api rockbox_api = { 68static struct plugin_api rockbox_api = {
@@ -142,7 +153,8 @@ static struct plugin_api rockbox_api = {
142 kbd_input, 153 kbd_input,
143 mpeg_current_track, 154 mpeg_current_track,
144 atoi, 155 atoi,
145 get_time 156 get_time,
157 plugin_get_buffer,
146}; 158};
147 159
148int plugin_load(char* plugin, void* parameter) 160int plugin_load(char* plugin, void* parameter)
@@ -154,7 +166,6 @@ int plugin_load(char* plugin, void* parameter)
154 void* pd; 166 void* pd;
155 char path[256]; 167 char path[256];
156#else 168#else
157 extern unsigned char pluginbuf[];
158 int fd; 169 int fd;
159#endif 170#endif
160 171
@@ -196,22 +207,25 @@ int plugin_load(char* plugin, void* parameter)
196 } 207 }
197 208
198 plugin_start = (void*)&pluginbuf; 209 plugin_start = (void*)&pluginbuf;
199 rc = read(fd, plugin_start, 0x8000); 210 plugin_size = read(fd, plugin_start, PLUGIN_BUFFER_SIZE);
200 close(fd); 211 close(fd);
201 if (rc < 0) { 212 if (plugin_size < 0) {
202 /* read error */ 213 /* read error */
203 snprintf(buf, sizeof buf, str(LANG_READ_FAILED), plugin); 214 snprintf(buf, sizeof buf, str(LANG_READ_FAILED), plugin);
204 splash(HZ*2, 0, true, buf); 215 splash(HZ*2, 0, true, buf);
205 return -1; 216 return -1;
206 } 217 }
207 if (rc == 0) { 218 if (plugin_size == 0) {
208 /* loaded a 0-byte plugin, implying it's not for this model */ 219 /* loaded a 0-byte plugin, implying it's not for this model */
209 splash(HZ*2, 0, true, str(LANG_PLUGIN_WRONG_MODEL)); 220 splash(HZ*2, 0, true, str(LANG_PLUGIN_WRONG_MODEL));
210 return -1; 221 return -1;
211 } 222 }
212#endif 223#endif
213 224
225 plugin_loaded = true;
214 rc = plugin_start(&rockbox_api, parameter); 226 rc = plugin_start(&rockbox_api, parameter);
227 plugin_loaded = false;
228
215 switch (rc) { 229 switch (rc) {
216 case PLUGIN_OK: 230 case PLUGIN_OK:
217 break; 231 break;
@@ -239,9 +253,33 @@ int plugin_load(char* plugin, void* parameter)
239 return PLUGIN_OK; 253 return PLUGIN_OK;
240} 254}
241 255
242int plugin_test(int api_version, int model, int memsize) 256/* Returns a pointer to the portion of the plugin buffer that is not already
257 being used. If no plugin is loaded, returns the entire plugin buffer */
258void* plugin_get_buffer(int* buffer_size)
259{
260 int buffer_pos;
261
262 if (plugin_loaded)
263 {
264 if (plugin_size >= PLUGIN_BUFFER_SIZE)
265 return NULL;
266
267 *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
268 buffer_pos = plugin_size;
269 }
270 else
271 {
272 *buffer_size = PLUGIN_BUFFER_SIZE;
273 buffer_pos = 0;
274 }
275
276 return &pluginbuf[buffer_pos];
277}
278
279static int plugin_test(int api_version, int model, int memsize)
243{ 280{
244 if (api_version != PLUGIN_API_VERSION) 281 if (api_version < PLUGIN_MIN_API_VERSION ||
282 api_version > PLUGIN_API_VERSION)
245 return PLUGIN_WRONG_API_VERSION; 283 return PLUGIN_WRONG_API_VERSION;
246 284
247 if (model != MODEL) 285 if (model != MODEL)
diff --git a/apps/plugin.h b/apps/plugin.h
index 3d6859b0d3..5bebcd701f 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -43,7 +43,11 @@
43#include "mpeg.h" 43#include "mpeg.h"
44 44
45/* increase this every time the api struct changes */ 45/* increase this every time the api struct changes */
46#define PLUGIN_API_VERSION 6 46#define PLUGIN_API_VERSION 7
47
48/* update this to latest version if a change to the api struct breaks
49 backwards compatibility */
50#define PLUGIN_MIN_API_VERSION 6
47 51
48/* plugin return codes */ 52/* plugin return codes */
49enum plugin_status { 53enum plugin_status {
@@ -75,6 +79,12 @@ do { \
75 return _rc_; \ 79 return _rc_; \
76} while(0) 80} while(0)
77 81
82/* NOTE: To support backwards compatibility, only add new functions at
83 the end of the structure. Every time you add a new function,
84 remember to increase PLUGIN_API_VERSION. If you make changes to the
85 existing APIs then also update PLUGIN_MIN_API_VERSION to current
86 version
87 */
78struct plugin_api { 88struct plugin_api {
79 /* these two fields must always be first, to ensure 89 /* these two fields must always be first, to ensure
80 TEST_PLUGIN_API will always work */ 90 TEST_PLUGIN_API will always work */
@@ -170,10 +180,12 @@ struct plugin_api {
170 struct mp3entry* (*mpeg_current_track)(void); 180 struct mp3entry* (*mpeg_current_track)(void);
171 int (*atoi)(const char *str); 181 int (*atoi)(const char *str);
172 struct tm* (*get_time)(void); 182 struct tm* (*get_time)(void);
183 void* (*plugin_get_buffer)(int* buffer_size);
173}; 184};
174 185
175/* defined by the plugin loader (plugin.c) */ 186/* defined by the plugin loader (plugin.c) */
176int plugin_load(char* plugin, void* parameter); 187int plugin_load(char* plugin, void* parameter);
188void* plugin_get_buffer(int *buffer_size);
177 189
178/* defined by the plugin */ 190/* defined by the plugin */
179enum plugin_status plugin_start(struct plugin_api* rockbox, void* parameter) 191enum plugin_status plugin_start(struct plugin_api* rockbox, void* parameter)