diff options
author | Thomas Martitz <kugel@rockbox.org> | 2010-08-26 23:20:02 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2010-08-26 23:20:02 +0000 |
commit | 73f057be6fcb849d5379073267e21e9526576ccd (patch) | |
tree | b2b239517ba89f4e9969918642006a3d15faa062 /uisimulator/common | |
parent | 55dc25fe7273bf9aa71cdaea9a68c39fa3a22f50 (diff) | |
download | rockbox-73f057be6fcb849d5379073267e21e9526576ccd.tar.gz 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')
-rw-r--r-- | uisimulator/common/io.c | 113 |
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 @@ | |||
58 | #include "debug.h" | 58 | #include "debug.h" |
59 | #include "ata.h" /* for IF_MV2 et al. */ | 59 | #include "ata.h" /* for IF_MV2 et al. */ |
60 | #include "rbpaths.h" | 60 | #include "rbpaths.h" |
61 | #include "load_code.h" | ||
61 | 62 | ||
62 | /* keep this in sync with file.h! */ | 63 | /* keep this in sync with file.h! */ |
63 | #undef MAX_PATH /* this avoids problems when building simulator */ | 64 | #undef MAX_PATH /* this avoids problems when building simulator */ |
@@ -530,116 +531,28 @@ int sim_fsync(int fd) | |||
530 | #include <dlfcn.h> | 531 | #include <dlfcn.h> |
531 | #endif | 532 | #endif |
532 | 533 | ||
533 | void *sim_codec_load_ram(char* codecptr, int size, void **pd) | ||
534 | { | ||
535 | void *hdr; | ||
536 | char path[MAX_PATH]; | ||
537 | int fd; | ||
538 | int codec_count; | ||
539 | #ifdef WIN32 | ||
540 | char buf[MAX_PATH]; | ||
541 | #endif | ||
542 | 534 | ||
543 | *pd = NULL; | 535 | void *lc_open(const char *filename, char *buf, size_t buf_size) |
544 | 536 | { | |
545 | /* We have to create the dynamic link library file from ram so we | 537 | const char *sim_path = get_sim_pathname(filename); |
546 | can simulate the codec loading. With voice and crossfade, | 538 | void *handle = _lc_open((const char*)UTF8_TO_OS(sim_path), buf, buf_size); |
547 | multiple codecs may be loaded at the same time, so we need | ||
548 | to find an unused filename */ | ||
549 | for (codec_count = 0; codec_count < 10; codec_count++) | ||
550 | { | ||
551 | #if (CONFIG_PLATFORM & PLATFORM_ANDROID) | ||
552 | /* we need that path fixed, since get_user_file_path() | ||
553 | * gives us the folder on the sdcard where we cannot load libraries | ||
554 | * from (no exec permissions) | ||
555 | */ | ||
556 | snprintf(path, sizeof(path), | ||
557 | "/data/data/org.rockbox/app_rockbox/libtemp_codec_%d.so", | ||
558 | codec_count); | ||
559 | #else | ||
560 | char name[MAX_PATH]; | ||
561 | const char *_name = get_user_file_path(ROCKBOX_DIR, 0, name, sizeof(name)); | ||
562 | snprintf(path, sizeof(path), "%s/_temp_codec%d.dll", get_sim_pathname(_name), codec_count); | ||
563 | #endif | ||
564 | fd = OPEN(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU); | ||
565 | if (fd >= 0) | ||
566 | break; /* Created a file ok */ | ||
567 | } | ||
568 | if (fd < 0) | ||
569 | { | ||
570 | DEBUGF("failed to open for write: %s\n", path); | ||
571 | return NULL; | ||
572 | } | ||
573 | |||
574 | if (write(fd, codecptr, size) != size) | ||
575 | { | ||
576 | DEBUGF("write failed"); | ||
577 | return NULL; | ||
578 | } | ||
579 | close(fd); | ||
580 | 539 | ||
581 | /* Now load the library. */ | 540 | if (handle == NULL) |
582 | *pd = dlopen(path, RTLD_NOW); | ||
583 | if (*pd == NULL) | ||
584 | { | 541 | { |
585 | DEBUGF("failed to load %s\n", path); | 542 | DEBUGF("failed to load %s\n", filename); |
586 | #ifdef WIN32 | 543 | DEBUGF("lc_open(%s): %s\n", filename, lc_last_error()); |
587 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, | ||
588 | buf, sizeof buf, NULL); | ||
589 | DEBUGF("dlopen(%s): %s\n", path, buf); | ||
590 | #else | ||
591 | DEBUGF("dlopen(%s): %s\n", path, dlerror()); | ||
592 | #endif | ||
593 | return NULL; | ||
594 | } | 544 | } |
595 | 545 | return handle; | |
596 | hdr = dlsym(*pd, "__header"); | ||
597 | if (!hdr) | ||
598 | hdr = dlsym(*pd, "___header"); | ||
599 | |||
600 | return hdr; /* maybe NULL if symbol not present */ | ||
601 | } | ||
602 | |||
603 | void sim_codec_close(void *pd) | ||
604 | { | ||
605 | dlclose(pd); | ||
606 | } | 546 | } |
607 | 547 | ||
608 | void *sim_plugin_load(char *plugin, void **pd) | 548 | void *lc_get_header(void *handle) |
609 | { | 549 | { |
610 | void *hdr; | 550 | return _lc_get_header(handle); |
611 | char path[MAX_PATH]; | ||
612 | #ifdef WIN32 | ||
613 | char buf[MAX_PATH]; | ||
614 | #endif | ||
615 | |||
616 | snprintf(path, sizeof(path), "%s", get_sim_pathname(plugin)); | ||
617 | |||
618 | *pd = NULL; | ||
619 | |||
620 | *pd = dlopen(path, RTLD_NOW); | ||
621 | if (*pd == NULL) { | ||
622 | DEBUGF("failed to load %s\n", plugin); | ||
623 | #ifdef WIN32 | ||
624 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, | ||
625 | buf, sizeof(buf), NULL); | ||
626 | DEBUGF("dlopen(%s): %s\n", path, buf); | ||
627 | #else | ||
628 | DEBUGF("dlopen(%s): %s\n", path, dlerror()); | ||
629 | #endif | ||
630 | return NULL; | ||
631 | } | ||
632 | |||
633 | hdr = dlsym(*pd, "__header"); | ||
634 | if (!hdr) | ||
635 | hdr = dlsym(*pd, "___header"); | ||
636 | |||
637 | return hdr; /* maybe NULL if symbol not present */ | ||
638 | } | 551 | } |
639 | 552 | ||
640 | void sim_plugin_close(void *pd) | 553 | void lc_close(void *handle) |
641 | { | 554 | { |
642 | dlclose(pd); | 555 | _lc_close(handle); |
643 | } | 556 | } |
644 | 557 | ||
645 | #ifdef WIN32 | 558 | #ifdef WIN32 |