summaryrefslogtreecommitdiffstats
path: root/uisimulator/common/io.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-08-26 23:20:02 +0000
committerThomas Martitz <kugel@rockbox.org>2010-08-26 23:20:02 +0000
commit73f057be6fcb849d5379073267e21e9526576ccd (patch)
treeb2b239517ba89f4e9969918642006a3d15faa062 /uisimulator/common/io.c
parent55dc25fe7273bf9aa71cdaea9a68c39fa3a22f50 (diff)
downloadrockbox-73f057be6fcb849d5379073267e21e9526576ccd.tar.gz
rockbox-73f057be6fcb849d5379073267e21e9526576ccd.tar.bz2
rockbox-73f057be6fcb849d5379073267e21e9526576ccd.zip
Introduce a small api for loading code (codecs,plugins) from disk/memory.
It's a used by codec/plugin loading and vastly reduces code duplication. It's also a step forward in getting rid of libuisimulator in the application ports. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27900 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/common/io.c')
-rw-r--r--uisimulator/common/io.c113
1 files changed, 13 insertions, 100 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index 4c0fa33be5..c8d6a8a67d 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -58,6 +58,7 @@
#include "debug.h"
#include "ata.h" /* for IF_MV2 et al. */
#include "rbpaths.h"
+#include "load_code.h"
/* keep this in sync with file.h! */
#undef MAX_PATH /* this avoids problems when building simulator */
@@ -530,116 +531,28 @@ int sim_fsync(int fd)
#include <dlfcn.h>
#endif
-void *sim_codec_load_ram(char* codecptr, int size, void **pd)
-{
- void *hdr;
- char path[MAX_PATH];
- int fd;
- int codec_count;
-#ifdef WIN32
- char buf[MAX_PATH];
-#endif
- *pd = NULL;
-
- /* We have to create the dynamic link library file from ram so we
- can simulate the codec loading. With voice and crossfade,
- multiple codecs may be loaded at the same time, so we need
- to find an unused filename */
- for (codec_count = 0; codec_count < 10; codec_count++)
- {
-#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
- /* we need that path fixed, since get_user_file_path()
- * gives us the folder on the sdcard where we cannot load libraries
- * from (no exec permissions)
- */
- snprintf(path, sizeof(path),
- "/data/data/org.rockbox/app_rockbox/libtemp_codec_%d.so",
- codec_count);
-#else
- char name[MAX_PATH];
- const char *_name = get_user_file_path(ROCKBOX_DIR, 0, name, sizeof(name));
- snprintf(path, sizeof(path), "%s/_temp_codec%d.dll", get_sim_pathname(_name), codec_count);
-#endif
- fd = OPEN(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU);
- if (fd >= 0)
- break; /* Created a file ok */
- }
- if (fd < 0)
- {
- DEBUGF("failed to open for write: %s\n", path);
- return NULL;
- }
-
- if (write(fd, codecptr, size) != size)
- {
- DEBUGF("write failed");
- return NULL;
- }
- close(fd);
+void *lc_open(const char *filename, char *buf, size_t buf_size)
+{
+ const char *sim_path = get_sim_pathname(filename);
+ void *handle = _lc_open((const char*)UTF8_TO_OS(sim_path), buf, buf_size);
- /* Now load the library. */
- *pd = dlopen(path, RTLD_NOW);
- if (*pd == NULL)
+ if (handle == NULL)
{
- DEBUGF("failed to load %s\n", path);
-#ifdef WIN32
- FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
- buf, sizeof buf, NULL);
- DEBUGF("dlopen(%s): %s\n", path, buf);
-#else
- DEBUGF("dlopen(%s): %s\n", path, dlerror());
-#endif
- return NULL;
+ DEBUGF("failed to load %s\n", filename);
+ DEBUGF("lc_open(%s): %s\n", filename, lc_last_error());
}
-
- hdr = dlsym(*pd, "__header");
- if (!hdr)
- hdr = dlsym(*pd, "___header");
-
- return hdr; /* maybe NULL if symbol not present */
-}
-
-void sim_codec_close(void *pd)
-{
- dlclose(pd);
+ return handle;
}
-void *sim_plugin_load(char *plugin, void **pd)
+void *lc_get_header(void *handle)
{
- void *hdr;
- char path[MAX_PATH];
-#ifdef WIN32
- char buf[MAX_PATH];
-#endif
-
- snprintf(path, sizeof(path), "%s", get_sim_pathname(plugin));
-
- *pd = NULL;
-
- *pd = dlopen(path, RTLD_NOW);
- if (*pd == NULL) {
- DEBUGF("failed to load %s\n", plugin);
-#ifdef WIN32
- FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
- buf, sizeof(buf), NULL);
- DEBUGF("dlopen(%s): %s\n", path, buf);
-#else
- DEBUGF("dlopen(%s): %s\n", path, dlerror());
-#endif
- return NULL;
- }
-
- hdr = dlsym(*pd, "__header");
- if (!hdr)
- hdr = dlsym(*pd, "___header");
-
- return hdr; /* maybe NULL if symbol not present */
+ return _lc_get_header(handle);
}
-void sim_plugin_close(void *pd)
+void lc_close(void *handle)
{
- dlclose(pd);
+ _lc_close(handle);
}
#ifdef WIN32