diff options
author | Thomas Martitz <kugel@rockbox.org> | 2010-08-27 00:29:50 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2010-08-27 00:29:50 +0000 |
commit | 194174a371b16dfc24960d1e33371c0a7ef1c2c2 (patch) | |
tree | b924bf74a96bb7dedcaebb45319569c003d81e8b /uisimulator/common/io.c | |
parent | 97d2a6ec5ca8ace8daed29c8c69aab9595147b3a (diff) | |
download | rockbox-194174a371b16dfc24960d1e33371c0a7ef1c2c2.tar.gz rockbox-194174a371b16dfc24960d1e33371c0a7ef1c2c2.zip |
2nd try: 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.
Apparently sh needs linker symbols prefixed with _ even if they're referenced without from C code.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27902 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/common/io.c')
-rw-r--r-- | uisimulator/common/io.c | 116 |
1 files changed, 16 insertions, 100 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index 4c0fa33be5..9862b4a7a2 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 */ |
@@ -520,6 +521,8 @@ int sim_fsync(int fd) | |||
520 | #endif | 521 | #endif |
521 | } | 522 | } |
522 | 523 | ||
524 | |||
525 | #ifndef __PCTOOL__ | ||
523 | #ifdef WIN32 | 526 | #ifdef WIN32 |
524 | /* sim-win32 */ | 527 | /* sim-win32 */ |
525 | #define dlopen(_x_, _y_) LoadLibraryW(UTF8_TO_OS(_x_)) | 528 | #define dlopen(_x_, _y_) LoadLibraryW(UTF8_TO_OS(_x_)) |
@@ -530,118 +533,31 @@ int sim_fsync(int fd) | |||
530 | #include <dlfcn.h> | 533 | #include <dlfcn.h> |
531 | #endif | 534 | #endif |
532 | 535 | ||
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 | |||
543 | *pd = NULL; | ||
544 | 536 | ||
545 | /* We have to create the dynamic link library file from ram so we | 537 | void *lc_open(const char *filename, char *buf, size_t buf_size) |
546 | can simulate the codec loading. With voice and crossfade, | 538 | { |
547 | multiple codecs may be loaded at the same time, so we need | 539 | const char *sim_path = get_sim_pathname(filename); |
548 | to find an unused filename */ | 540 | void *handle = _lc_open((const char*)UTF8_TO_OS(sim_path), buf, buf_size); |
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 | 541 | ||
581 | /* Now load the library. */ | 542 | if (handle == NULL) |
582 | *pd = dlopen(path, RTLD_NOW); | ||
583 | if (*pd == NULL) | ||
584 | { | 543 | { |
585 | DEBUGF("failed to load %s\n", path); | 544 | DEBUGF("failed to load %s\n", filename); |
586 | #ifdef WIN32 | 545 | 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 | } | 546 | } |
595 | 547 | 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 | } | 548 | } |
602 | 549 | ||
603 | void sim_codec_close(void *pd) | 550 | void *lc_get_header(void *handle) |
604 | { | 551 | { |
605 | dlclose(pd); | 552 | return _lc_get_header(handle); |
606 | } | ||
607 | |||
608 | void *sim_plugin_load(char *plugin, void **pd) | ||
609 | { | ||
610 | void *hdr; | ||
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 | } | 553 | } |
639 | 554 | ||
640 | void sim_plugin_close(void *pd) | 555 | void lc_close(void *handle) |
641 | { | 556 | { |
642 | dlclose(pd); | 557 | _lc_close(handle); |
643 | } | 558 | } |
644 | 559 | ||
560 | #endif /* __PCTOOL__ */ | ||
645 | #ifdef WIN32 | 561 | #ifdef WIN32 |
646 | static unsigned old_cp; | 562 | static unsigned old_cp; |
647 | 563 | ||