BDJAVA* bdj_open(const char *path, struct bluray *bd, const char *bdj_disc_id, BDJ_STORAGE *storage) { BD_DEBUG(DBG_BDJ, "bdj_open()\n"); const char *jar_file = _find_libbluray_jar(storage); if (!jar_file) { BD_DEBUG(DBG_BDJ | DBG_CRIT, "BD-J start failed: " BDJ_JARFILE " not found.\n"); return NULL; } #if defined(__APPLE__) && !defined(HAVE_BDJ_J2ME) /* On macOS we need to load libjli to workaround a bug where the wrong * version would be used: https://bugs.openjdk.java.net/browse/JDK-7131356 */ void* jli_lib = _load_jli_macos(); if (!jli_lib) { BD_DEBUG(DBG_BDJ, "Wasn't able to load JLI\n"); } #endif // first load the jvm using dlopen const char *java_home = NULL; void* jvm_lib = _load_jvm(&java_home); if (!jvm_lib) { BD_DEBUG(DBG_BDJ | DBG_CRIT, "Wasn't able to load JVM\n"); return 0; } BDJAVA* bdjava = calloc(1, sizeof(BDJAVA)); if (!bdjava) { dl_dlclose(jvm_lib); return NULL; } JNIEnv* env = NULL; JavaVM *jvm = NULL; if (!_find_jvm(jvm_lib, &env, &jvm) && !_create_jvm(jvm_lib, java_home, jar_file, &env, &jvm)) { X_FREE(bdjava); dl_dlclose(jvm_lib); return NULL; } #if defined(__APPLE__) && !defined(HAVE_BDJ_J2ME) bdjava->h_libjli = jli_lib; #endif bdjava->h_libjvm = jvm_lib; bdjava->jvm = jvm; if (debug_mask & DBG_JNI) { int version = (int)(*env)->GetVersion(env); BD_DEBUG(DBG_BDJ, "Java version: %d.%d\n", version >> 16, version & 0xffff); }
BDJAVA* bdj_open(const char *path, struct bluray *bd, const char *bdj_disc_id, BDJ_STORAGE *storage) { BD_DEBUG(DBG_BDJ, "bdj_open()\n"); const char *jar_file = _find_libbluray_jar(storage); if (!jar_file) { BD_DEBUG(DBG_BDJ | DBG_CRIT, "BD-J start failed: " BDJ_JARFILE " not found.\n"); return NULL; } // first load the jvm using dlopen const char *java_home = NULL; void* jvm_lib = _load_jvm(&java_home); if (!jvm_lib) { BD_DEBUG(DBG_BDJ | DBG_CRIT, "Wasn't able to load JVM\n"); return 0; } JNIEnv* env = NULL; JavaVM *jvm = NULL; if (!_find_jvm(jvm_lib, &env, &jvm) && !_create_jvm(jvm_lib, java_home, jar_file, &env, &jvm)) { dl_dlclose(jvm_lib); return NULL; } BDJAVA* bdjava = calloc(1, sizeof(BDJAVA)); bdjava->h_libjvm = jvm_lib; bdjava->jvm = jvm; if (debug_mask & DBG_JNI) { int version = (int)(*env)->GetVersion(env); BD_DEBUG(DBG_BDJ, "Java version: %d.%d\n", version >> 16, version & 0xffff); }
int main(int argc, char* argv[]) { /* initialize ylisp */ { /* just scope */ ylsys_t sys; sys.print = &_print; sys.log = &_log; sys.assert_ = &_assert_; sys.malloc = &malloc; sys.free = &free; sys.mode = YLMode_repl; sys.mpsz = 1024*1024; /* memory pool size */ sys.gctp = 80; if (YLOk != ylinit(&sys)) { printf("Error: Fail to initialize ylisp\n"); return 0; } #ifdef CONFIG_STATIC_CNF ylcnf_load_ylbase (NULL); ylcnf_load_ylext (NULL); #endif /* CONFIG_STATIC_CNF */ } /* This should be called after ylinit() */ yldynbstr_init(&_dynb, _INIT_OUTBUFSZ); /* run initial scripts if required */ if (argc > 1) { unsigned char* strm; unsigned int strmsz; int i; for (i=1; i<argc; i++) { strm = ylutfile_read(&strmsz, argv[i], 0); if (!strm) { printf("Fail to read given script..\n" " -> %s\n", argv[i]); return 0; } if (YLOk != ylinterpret(strm, strmsz)) { printf("Fail to interpret given script..\n" " -> %s\n", argv[i]); return 0; } free(strm); } } /* start java */ { /* just scope */ JNIEnv* jenv; JavaVM* jvm; jenv = _create_jvm(&jvm); if (!jenv) { printf("Error: Fail to create JavaVM\n"); return 0; } if (0 > _register_natives(jenv)) { printf("Error: Fail to register natives\n"); return 0; } if (0 > _start_java(jvm, jenv, 0, NULL)) { printf("Error : Start java\n"); return 0; } (*jvm)->DestroyJavaVM(jvm); } return 0; }