summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorHardeep Sidhu <dyp@pobox.com>2003-07-25 23:04:59 +0000
committerHardeep Sidhu <dyp@pobox.com>2003-07-25 23:04:59 +0000
commit48c2d0f929528cdd871e761b40662f8b616422f1 (patch)
tree9943480478e9de90bc258a325b0bdf3a50970926 /apps
parent7d889c87df474e683ad69d063375c3c9286e36ec (diff)
downloadrockbox-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')
-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 @@
#define PREFIX(_x_) _x_
#endif
+#define PLUGIN_BUFFER_SIZE 0x8000
+
+#ifdef SIMULATOR
+static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE];
+#else
+extern unsigned char pluginbuf[];
+#endif
+
+static bool plugin_loaded = false;
+static int plugin_size = 0;
+
static int plugin_test(int api_version, int model, int memsize);
static struct plugin_api rockbox_api = {
@@ -142,7 +153,8 @@ static struct plugin_api rockbox_api = {
kbd_input,
mpeg_current_track,
atoi,
- get_time
+ get_time,
+ plugin_get_buffer,
};
int plugin_load(char* plugin, void* parameter)
@@ -154,7 +166,6 @@ int plugin_load(char* plugin, void* parameter)
void* pd;
char path[256];
#else
- extern unsigned char pluginbuf[];
int fd;
#endif
@@ -196,22 +207,25 @@ int plugin_load(char* plugin, void* parameter)
}
plugin_start = (void*)&pluginbuf;
- rc = read(fd, plugin_start, 0x8000);
+ plugin_size = read(fd, plugin_start, PLUGIN_BUFFER_SIZE);
close(fd);
- if (rc < 0) {
+ if (plugin_size < 0) {
/* read error */
snprintf(buf, sizeof buf, str(LANG_READ_FAILED), plugin);
splash(HZ*2, 0, true, buf);
return -1;
}
- if (rc == 0) {
+ if (plugin_size == 0) {
/* loaded a 0-byte plugin, implying it's not for this model */
splash(HZ*2, 0, true, str(LANG_PLUGIN_WRONG_MODEL));
return -1;
}
#endif
+ plugin_loaded = true;
rc = plugin_start(&rockbox_api, parameter);
+ plugin_loaded = false;
+
switch (rc) {
case PLUGIN_OK:
break;
@@ -239,9 +253,33 @@ int plugin_load(char* plugin, void* parameter)
return PLUGIN_OK;
}
-int plugin_test(int api_version, int model, int memsize)
+/* Returns a pointer to the portion of the plugin buffer that is not already
+ being used. If no plugin is loaded, returns the entire plugin buffer */
+void* plugin_get_buffer(int* buffer_size)
+{
+ int buffer_pos;
+
+ if (plugin_loaded)
+ {
+ if (plugin_size >= PLUGIN_BUFFER_SIZE)
+ return NULL;
+
+ *buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
+ buffer_pos = plugin_size;
+ }
+ else
+ {
+ *buffer_size = PLUGIN_BUFFER_SIZE;
+ buffer_pos = 0;
+ }
+
+ return &pluginbuf[buffer_pos];
+}
+
+static int plugin_test(int api_version, int model, int memsize)
{
- if (api_version != PLUGIN_API_VERSION)
+ if (api_version < PLUGIN_MIN_API_VERSION ||
+ api_version > PLUGIN_API_VERSION)
return PLUGIN_WRONG_API_VERSION;
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 @@
#include "mpeg.h"
/* increase this every time the api struct changes */
-#define PLUGIN_API_VERSION 6
+#define PLUGIN_API_VERSION 7
+
+/* update this to latest version if a change to the api struct breaks
+ backwards compatibility */
+#define PLUGIN_MIN_API_VERSION 6
/* plugin return codes */
enum plugin_status {
@@ -75,6 +79,12 @@ do { \
return _rc_; \
} while(0)
+/* NOTE: To support backwards compatibility, only add new functions at
+ the end of the structure. Every time you add a new function,
+ remember to increase PLUGIN_API_VERSION. If you make changes to the
+ existing APIs then also update PLUGIN_MIN_API_VERSION to current
+ version
+ */
struct plugin_api {
/* these two fields must always be first, to ensure
TEST_PLUGIN_API will always work */
@@ -170,10 +180,12 @@ struct plugin_api {
struct mp3entry* (*mpeg_current_track)(void);
int (*atoi)(const char *str);
struct tm* (*get_time)(void);
+ void* (*plugin_get_buffer)(int* buffer_size);
};
/* defined by the plugin loader (plugin.c) */
int plugin_load(char* plugin, void* parameter);
+void* plugin_get_buffer(int *buffer_size);
/* defined by the plugin */
enum plugin_status plugin_start(struct plugin_api* rockbox, void* parameter)