2018-11-29 11:35:34 -08:00
|
|
|
/**
|
2018-09-11 15:27:47 -07:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-08-31 16:15:15 +01:00
|
|
|
*
|
2018-11-29 11:35:34 -08:00
|
|
|
* This source code is licensed under the MIT license found in the LICENSE
|
|
|
|
* file in the root directory of this source tree.
|
2016-08-31 16:15:15 +01:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-07-17 06:52:55 -07:00
|
|
|
#include <fbjni/fbjni.h>
|
2016-08-31 16:15:15 +01:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace jni {
|
|
|
|
|
|
|
|
struct JRunnable : public JavaClass<JRunnable> {
|
|
|
|
static auto constexpr kJavaDescriptor = "Ljava/lang/Runnable;";
|
|
|
|
};
|
|
|
|
|
|
|
|
struct JNativeRunnable : public HybridClass<JNativeRunnable, JRunnable> {
|
|
|
|
public:
|
|
|
|
static auto constexpr kJavaDescriptor = "Lcom/facebook/jni/NativeRunnable;";
|
|
|
|
|
|
|
|
JNativeRunnable(std::function<void()>&& runnable) : runnable_(std::move(runnable)) {}
|
|
|
|
|
|
|
|
static void OnLoad() {
|
|
|
|
registerHybrid({
|
|
|
|
makeNativeMethod("run", JNativeRunnable::run),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void run() {
|
|
|
|
runnable_();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::function<void()> runnable_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace jni
|
|
|
|
} // namespace facebook
|