Files
yoga/lib/fb/src/main/cpp/include/fbjni/NativeRunnable.h

43 lines
907 B
C
Raw Normal View History

/**
* Copyright (c) Facebook, Inc. and its affiliates.
2016-08-31 16:15:15 +01: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
#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