Changeset View
Changeset View
Standalone View
Standalone View
native/android/app/src/cpp/jniHelpers.h
Show All 22 Lines | struct Runnable : public jni::JavaClass<Runnable> { | ||||
static constexpr auto kJavaDescriptor = "Ljava/lang/Runnable;"; | static constexpr auto kJavaDescriptor = "Ljava/lang/Runnable;"; | ||||
void run() { | void run() { | ||||
static const auto method = | static const auto method = | ||||
jni::findClassStatic("java/lang/Runnable")->getMethod<void()>("run"); | jni::findClassStatic("java/lang/Runnable")->getMethod<void()>("run"); | ||||
method(this->self()); | method(this->self()); | ||||
} | } | ||||
}; | }; | ||||
struct NativeAndroidAccessProvider { | |||||
static void runTask(std::function<void()> &&task) { | |||||
// Some methods are meant to be executed on auxiliary threads. In case they | |||||
// require access to native Java API we need to temporarily attach the | |||||
// thread to JVM This function attaches thread to JVM for the time lambda | |||||
// passed to this function will be executing. | |||||
jni::ThreadScope::WithClassLoader(std::move(task)); | |||||
} | |||||
}; | |||||
} // namespace comm | } // namespace comm |