mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
Feat: load config in libagent to prepare for modules
- Make runtime_dir optional in JuiceAgent.init (tolerate null jstring) - Load config.toml into Agent and expose getConfig/setConfig - Warn instead of failing when runtime directory or config is missing
This commit is contained in:
1 parent
51bcfbd549
commit
2ab1c134ed
3 files changed
+30
-7
No files matched your search
@@ -3,18 +3,25 @@
|
||||
// This function is called by Java to initialize the agent.
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_init
|
||||
(JNIEnv *env, jclass , jstring j_runtime_dir) {
|
||||
|
||||
Logger::init("libagent.log");
|
||||
|
||||
spdlog::info("Initializing JuiceAgent...");
|
||||
|
||||
// Get runtime directory
|
||||
const char* c_runtime_dir = env->GetStringUTFChars(j_runtime_dir, nullptr);
|
||||
std::string runtime_dir(c_runtime_dir);
|
||||
env->ReleaseStringUTFChars(j_runtime_dir, c_runtime_dir);
|
||||
std::string runtime_dir;
|
||||
|
||||
if (j_runtime_dir != nullptr) {
|
||||
const char* c_runtime_dir = env->GetStringUTFChars(j_runtime_dir, nullptr);
|
||||
|
||||
if (c_runtime_dir != nullptr) {
|
||||
runtime_dir = c_runtime_dir;
|
||||
env->ReleaseStringUTFChars(j_runtime_dir, c_runtime_dir);
|
||||
}
|
||||
}
|
||||
|
||||
if (runtime_dir.empty()) {
|
||||
spdlog::error("Failed to get runtime directory from argument, runtime_dir is empty");
|
||||
return JNI_FALSE;
|
||||
spdlog::warn("Runtime directory is empty");
|
||||
}
|
||||
spdlog::info("JuiceAgent got runtime directory: {}", runtime_dir);
|
||||
|
||||
@@ -41,4 +48,4 @@ JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_init
|
||||
agent.init();
|
||||
|
||||
return JNI_TRUE;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user