2023-09-02 17:30:21 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2023-09-08 22:12:42 -06:00
|
|
|
#include "ALooperEventLoopImplementation.h"
|
2023-09-13 23:22:44 -06:00
|
|
|
#include <AK/Format.h>
|
2023-09-08 22:12:42 -06:00
|
|
|
#include <AK/OwnPtr.h>
|
2023-09-02 17:30:21 +02:00
|
|
|
#include <Ladybird/Utilities.h>
|
2023-09-08 22:12:42 -06:00
|
|
|
#include <LibCore/EventLoop.h>
|
|
|
|
|
#include <LibCore/Timer.h>
|
2023-09-02 17:30:21 +02:00
|
|
|
#include <jni.h>
|
|
|
|
|
|
2023-09-08 22:12:42 -06:00
|
|
|
OwnPtr<Core::EventLoop> s_main_event_loop;
|
|
|
|
|
|
2023-09-02 17:30:21 +02:00
|
|
|
extern "C" JNIEXPORT void JNICALL
|
2023-09-13 23:22:44 -06:00
|
|
|
Java_org_serenityos_ladybird_LadybirdActivity_initNativeCode(JNIEnv* env, jobject /* thiz */, jstring resource_dir, jstring tag_name, jobject timer_service)
|
2023-09-02 17:30:21 +02:00
|
|
|
{
|
|
|
|
|
char const* raw_resource_dir = env->GetStringUTFChars(resource_dir, nullptr);
|
|
|
|
|
s_serenity_resource_root = raw_resource_dir;
|
|
|
|
|
env->ReleaseStringUTFChars(resource_dir, raw_resource_dir);
|
2023-09-08 22:12:42 -06:00
|
|
|
|
2023-09-13 23:22:44 -06:00
|
|
|
char const* raw_tag_name = env->GetStringUTFChars(tag_name, nullptr);
|
|
|
|
|
AK::set_log_tag_name(raw_tag_name);
|
|
|
|
|
env->ReleaseStringUTFChars(tag_name, raw_tag_name);
|
|
|
|
|
|
|
|
|
|
dbgln("Set resource dir to {}", s_serenity_resource_root);
|
|
|
|
|
|
2023-09-08 22:12:42 -06:00
|
|
|
jobject timer_service_ref = env->NewGlobalRef(timer_service);
|
|
|
|
|
JavaVM* vm = nullptr;
|
|
|
|
|
jint ret = env->GetJavaVM(&vm);
|
|
|
|
|
VERIFY(ret == 0);
|
|
|
|
|
Core::EventLoopManager::install(*new Ladybird::ALooperEventLoopManager(vm, timer_service_ref));
|
|
|
|
|
s_main_event_loop = make<Core::EventLoop>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL
|
|
|
|
|
Java_org_serenityos_ladybird_LadybirdActivity_execMainEventLoop(JNIEnv*, jobject /* thiz */)
|
|
|
|
|
{
|
|
|
|
|
s_main_event_loop->pump(Core::EventLoop::WaitMode::PollForEvents);
|
2023-09-02 17:30:21 +02:00
|
|
|
}
|