mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-29 14:15:29 +03:00
Introduce JniString
as C++ wrapper over jstring
We used to manually call JNI UTF-8 string allocation and deallocation functions when utilizing a `jstring` but this could be erroneous and is just inconvenient. All of this has now been consolidated into an class `JniString` which is a wrapper around `std::string` and creates a copy of the contents of the `jstring` in its constructor and passes them into the `std::string` constructor.
This commit is contained in:
parent
79ceb2cf23
commit
fb476567ff
@ -76,8 +76,8 @@ extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_executeApplication(
|
|||||||
auto settings{std::make_shared<skyline::Settings>(preferenceFd)};
|
auto settings{std::make_shared<skyline::Settings>(preferenceFd)};
|
||||||
close(preferenceFd);
|
close(preferenceFd);
|
||||||
|
|
||||||
auto appFilesPath{env->GetStringUTFChars(appFilesPathJstring, nullptr)};
|
skyline::JniString appFilesPath(env, appFilesPathJstring);
|
||||||
auto logger{std::make_shared<skyline::Logger>(std::string(appFilesPath) + "skyline.log", settings->logLevel)};
|
auto logger{std::make_shared<skyline::Logger>(appFilesPath + "skyline.log", settings->logLevel)};
|
||||||
|
|
||||||
auto start{std::chrono::steady_clock::now()};
|
auto start{std::chrono::steady_clock::now()};
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_executeApplication(
|
|||||||
jvmManager,
|
jvmManager,
|
||||||
logger,
|
logger,
|
||||||
settings,
|
settings,
|
||||||
std::string(appFilesPath),
|
appFilesPath,
|
||||||
GetTimeZoneName(),
|
GetTimeZoneName(),
|
||||||
static_cast<skyline::language::SystemLanguage>(systemLanguage),
|
static_cast<skyline::language::SystemLanguage>(systemLanguage),
|
||||||
std::make_shared<skyline::vfs::AndroidAssetFileSystem>(AAssetManager_fromJava(env, assetManager))
|
std::make_shared<skyline::vfs::AndroidAssetFileSystem>(AAssetManager_fromJava(env, assetManager))
|
||||||
@ -102,11 +102,8 @@ extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_executeApplication(
|
|||||||
AudioWeak = os->state.audio;
|
AudioWeak = os->state.audio;
|
||||||
InputWeak = os->state.input;
|
InputWeak = os->state.input;
|
||||||
jvmManager->InitializeControllers();
|
jvmManager->InitializeControllers();
|
||||||
env->ReleaseStringUTFChars(appFilesPathJstring, appFilesPath);
|
|
||||||
|
|
||||||
auto romUri{env->GetStringUTFChars(romUriJstring, nullptr)};
|
logger->InfoNoPrefix("Launching ROM {}", skyline::JniString(env, romUriJstring));
|
||||||
logger->InfoNoPrefix("Launching ROM {}", romUri);
|
|
||||||
env->ReleaseStringUTFChars(romUriJstring, romUri);
|
|
||||||
|
|
||||||
os->Execute(romFd, static_cast<skyline::loader::RomFormat>(romType));
|
os->Execute(romFd, static_cast<skyline::loader::RomFormat>(romType));
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
|
@ -14,10 +14,7 @@
|
|||||||
extern "C" JNIEXPORT jint JNICALL Java_emu_skyline_loader_RomFile_populate(JNIEnv *env, jobject thiz, jint jformat, jint fd, jstring appFilesPathJstring, jint systemLanguage) {
|
extern "C" JNIEXPORT jint JNICALL Java_emu_skyline_loader_RomFile_populate(JNIEnv *env, jobject thiz, jint jformat, jint fd, jstring appFilesPathJstring, jint systemLanguage) {
|
||||||
skyline::loader::RomFormat format{static_cast<skyline::loader::RomFormat>(jformat)};
|
skyline::loader::RomFormat format{static_cast<skyline::loader::RomFormat>(jformat)};
|
||||||
|
|
||||||
auto appFilesPath{env->GetStringUTFChars(appFilesPathJstring, nullptr)};
|
auto keyStore{std::make_shared<skyline::crypto::KeyStore>(skyline::JniString(env, appFilesPathJstring))};
|
||||||
auto keyStore{std::make_shared<skyline::crypto::KeyStore>(appFilesPath)};
|
|
||||||
env->ReleaseStringUTFChars(appFilesPathJstring, appFilesPath);
|
|
||||||
|
|
||||||
std::unique_ptr<skyline::loader::Loader> loader;
|
std::unique_ptr<skyline::loader::Loader> loader;
|
||||||
try {
|
try {
|
||||||
auto backing{std::make_shared<skyline::vfs::OsBacking>(fd)};
|
auto backing{std::make_shared<skyline::vfs::OsBacking>(fd)};
|
||||||
|
@ -4,6 +4,13 @@
|
|||||||
#include "jvm.h"
|
#include "jvm.h"
|
||||||
|
|
||||||
namespace skyline {
|
namespace skyline {
|
||||||
|
std::string JniString::GetJString(JNIEnv *env, jstring jString) {
|
||||||
|
auto utf{env->GetStringUTFChars(jString, nullptr)};
|
||||||
|
std::string string{utf};
|
||||||
|
env->ReleaseStringUTFChars(jString, utf);
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief A thread-local wrapper over JNIEnv and JavaVM which automatically handles attaching and detaching threads
|
* @brief A thread-local wrapper over JNIEnv and JavaVM which automatically handles attaching and detaching threads
|
||||||
*/
|
*/
|
||||||
|
@ -7,6 +7,17 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
namespace skyline {
|
namespace skyline {
|
||||||
|
/**
|
||||||
|
* @brief A wrapper over std::string that supports construction using a JNI jstring
|
||||||
|
*/
|
||||||
|
class JniString : public std::string {
|
||||||
|
private:
|
||||||
|
static std::string GetJString(JNIEnv *env, jstring jString);
|
||||||
|
|
||||||
|
public:
|
||||||
|
JniString(JNIEnv *env, jstring jString) : std::string(GetJString(env, jString)) {}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The JvmManager class is used to simplify transactions with the Java component
|
* @brief The JvmManager class is used to simplify transactions with the Java component
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user