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 NativeAndroidAccessible { | |||||
static void runTask(std::function<void()> &&task) { | |||||
kamil: another option might be using `inline` function to shorten code, because this is simply one… | |||||
marcinUnsubmitted Not Done Inline ActionsLet's name a class with a noun - not an adjective. Perhaps NativeAndroidAccessProvider could work, but up to you. marcin: Let's name a class with a noun - not an adjective. Perhaps `NativeAndroidAccessProvider` could… | |||||
tomekUnsubmitted Not Done Inline ActionsRegarding the inline, the docs https://en.cppreference.com/w/cpp/language/inline say
Additionally, for member functions https://isocpp.org/wiki/faq/inline-functions#inline-member-fns-more the inline keyword is implicit. I'm not sure how about struct. tomek: Regarding the `inline`, the docs https://en.cppreference.com/w/cpp/language/inline say
> Since… | |||||
// 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 |
another option might be using inline function to shorten code, because this is simply one-line function, but looks like in codebase this pattern is preferred so sticking to this one