diff options
author | Hardeep Sidhu <dyp@pobox.com> | 2003-07-25 23:04:59 +0000 |
---|---|---|
committer | Hardeep Sidhu <dyp@pobox.com> | 2003-07-25 23:04:59 +0000 |
commit | 48c2d0f929528cdd871e761b40662f8b616422f1 (patch) | |
tree | 9943480478e9de90bc258a325b0bdf3a50970926 /apps/plugin.c | |
parent | 7d889c87df474e683ad69d063375c3c9286e36ec (diff) | |
download | rockbox-48c2d0f929528cdd871e761b40662f8b616422f1.tar.gz rockbox-48c2d0f929528cdd871e761b40662f8b616422f1.zip |
Allow older versions of plugins to run so long as plugin api struct changes don't break backwards compatibility. Also added call to retrieve the portion of plugin buffer that is not being used by plugin.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3888 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugin.c')
-rw-r--r-- | apps/plugin.c | 52 |
1 files changed, 45 insertions, 7 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 | ||
58 | static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE]; | ||
59 | #else | ||
60 | extern unsigned char pluginbuf[]; | ||
61 | #endif | ||
62 | |||
63 | static bool plugin_loaded = false; | ||
64 | static int plugin_size = 0; | ||
65 | |||
55 | static int plugin_test(int api_version, int model, int memsize); | 66 | static int plugin_test(int api_version, int model, int memsize); |
56 | 67 | ||
57 | static struct plugin_api rockbox_api = { | 68 | static 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 | ||
148 | int plugin_load(char* plugin, void* parameter) | 160 | int 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 | ||
242 | int 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 */ | ||
258 | void* 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 | |||
279 | static 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) |