Remove jni dependencies from Bridge.h/cpp
Reviewed By: astreet Differential Revision: D2905191 fb-gh-sync-id: 7510ef1d1b87ff50f35195d5ca8c0dd98f81526f shipit-source-id: 7510ef1d1b87ff50f35195d5ca8c0dd98f81526f
This commit is contained in:
parent
1d561fd604
commit
229c8c35c9
|
@ -19,7 +19,7 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
|
||||||
LOCAL_CFLAGS := \
|
LOCAL_CFLAGS := \
|
||||||
-DLOG_TAG=\"ReactNative\"
|
-DLOG_TAG=\"ReactNative\"
|
||||||
|
|
||||||
LOCAL_CFLAGS += -Wall -Werror -fexceptions
|
LOCAL_CFLAGS += -Wall -Werror -fexceptions -frtti
|
||||||
CXX11_FLAGS := -std=c++11
|
CXX11_FLAGS := -std=c++11
|
||||||
LOCAL_CFLAGS += $(CXX11_FLAGS)
|
LOCAL_CFLAGS += $(CXX11_FLAGS)
|
||||||
LOCAL_EXPORT_CPPFLAGS := $(CXX11_FLAGS)
|
LOCAL_EXPORT_CPPFLAGS := $(CXX11_FLAGS)
|
||||||
|
|
|
@ -71,5 +71,6 @@ react_library(
|
||||||
'-std=c++11',
|
'-std=c++11',
|
||||||
'-fexceptions',
|
'-fexceptions',
|
||||||
'-fvisibility=hidden',
|
'-fvisibility=hidden',
|
||||||
|
'-frtti',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
#include "Bridge.h"
|
#include "Bridge.h"
|
||||||
|
|
||||||
#include "Executor.h"
|
|
||||||
#include "MethodCall.h"
|
|
||||||
|
|
||||||
#ifdef WITH_FBSYSTRACE
|
#ifdef WITH_FBSYSTRACE
|
||||||
#include <fbsystrace.h>
|
#include <fbsystrace.h>
|
||||||
using fbsystrace::FbSystraceSection;
|
using fbsystrace::FbSystraceSection;
|
||||||
|
@ -13,7 +10,7 @@ using fbsystrace::FbSystraceSection;
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace react {
|
namespace react {
|
||||||
|
|
||||||
Bridge::Bridge(const RefPtr<CountableJSExecutorFactory>& jsExecutorFactory, Callback callback) :
|
Bridge::Bridge(JSExecutorFactory* jsExecutorFactory, Callback callback) :
|
||||||
m_callback(std::move(callback)),
|
m_callback(std::move(callback)),
|
||||||
m_destroyed(std::shared_ptr<bool>(new bool(false)))
|
m_destroyed(std::shared_ptr<bool>(new bool(false)))
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <jni.h>
|
|
||||||
#include <fb/Countable.h>
|
|
||||||
#include <fb/RefPtr.h>
|
|
||||||
#include "Value.h"
|
#include "Value.h"
|
||||||
#include "Executor.h"
|
#include "Executor.h"
|
||||||
#include "MethodCall.h"
|
#include "MethodCall.h"
|
||||||
|
@ -22,14 +19,11 @@ struct dynamic;
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace react {
|
namespace react {
|
||||||
|
|
||||||
class CountableJSExecutorFactory : public JSExecutorFactory, public Countable {
|
class Bridge {
|
||||||
};
|
|
||||||
|
|
||||||
class Bridge : public Countable {
|
|
||||||
public:
|
public:
|
||||||
typedef std::function<void(std::vector<MethodCall>, bool isEndOfBatch)> Callback;
|
typedef std::function<void(std::vector<MethodCall>, bool isEndOfBatch)> Callback;
|
||||||
|
|
||||||
Bridge(const RefPtr<CountableJSExecutorFactory>& jsExecutorFactory, Callback callback);
|
Bridge(JSExecutorFactory* jsExecutorFactory, Callback callback);
|
||||||
virtual ~Bridge();
|
virtual ~Bridge();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -567,6 +567,10 @@ static jmethodID gCallbackMethod;
|
||||||
static jmethodID gOnBatchCompleteMethod;
|
static jmethodID gOnBatchCompleteMethod;
|
||||||
static jmethodID gLogMarkerMethod;
|
static jmethodID gLogMarkerMethod;
|
||||||
|
|
||||||
|
struct CountableBridge : Bridge, Countable {
|
||||||
|
using Bridge::Bridge;
|
||||||
|
};
|
||||||
|
|
||||||
static void logMarker(const std::string& marker) {
|
static void logMarker(const std::string& marker) {
|
||||||
JNIEnv* env = Environment::current();
|
JNIEnv* env = Environment::current();
|
||||||
jclass markerClass = env->FindClass("com/facebook/react/bridge/ReactMarker");
|
jclass markerClass = env->FindClass("com/facebook/react/bridge/ReactMarker");
|
||||||
|
@ -643,12 +647,12 @@ static void create(JNIEnv* env, jobject obj, jobject executor, jobject callback,
|
||||||
dispatchCallbacksToJava(weakCallback, weakCallbackQueueThread, std::move(calls), isEndOfBatch);
|
dispatchCallbacksToJava(weakCallback, weakCallbackQueueThread, std::move(calls), isEndOfBatch);
|
||||||
};
|
};
|
||||||
auto nativeExecutorFactory = extractRefPtr<CountableJSExecutorFactory>(env, executor);
|
auto nativeExecutorFactory = extractRefPtr<CountableJSExecutorFactory>(env, executor);
|
||||||
auto bridge = createNew<Bridge>(nativeExecutorFactory, bridgeCallback);
|
auto bridge = createNew<CountableBridge>(nativeExecutorFactory.get(), bridgeCallback);
|
||||||
setCountableForJava(env, obj, std::move(bridge));
|
setCountableForJava(env, obj, std::move(bridge));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void executeApplicationScript(
|
static void executeApplicationScript(
|
||||||
const RefPtr<Bridge>& bridge,
|
const RefPtr<CountableBridge>& bridge,
|
||||||
const std::string& script,
|
const std::string& script,
|
||||||
const std::string& sourceUri) {
|
const std::string& sourceUri) {
|
||||||
try {
|
try {
|
||||||
|
@ -661,7 +665,7 @@ static void executeApplicationScript(
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadApplicationUnbundle(
|
static void loadApplicationUnbundle(
|
||||||
const RefPtr<Bridge>& bridge,
|
const RefPtr<CountableBridge>& bridge,
|
||||||
AAssetManager *assetManager,
|
AAssetManager *assetManager,
|
||||||
const std::string& startupCode,
|
const std::string& startupCode,
|
||||||
const std::string& startupFileName) {
|
const std::string& startupFileName) {
|
||||||
|
@ -683,7 +687,7 @@ static void loadScriptFromAssets(JNIEnv* env, jobject obj, jobject assetManager,
|
||||||
jstring assetName) {
|
jstring assetName) {
|
||||||
jclass markerClass = env->FindClass("com/facebook/react/bridge/ReactMarker");
|
jclass markerClass = env->FindClass("com/facebook/react/bridge/ReactMarker");
|
||||||
auto manager = AAssetManager_fromJava(env, assetManager);
|
auto manager = AAssetManager_fromJava(env, assetManager);
|
||||||
auto bridge = extractRefPtr<Bridge>(env, obj);
|
auto bridge = extractRefPtr<CountableBridge>(env, obj);
|
||||||
auto assetNameStr = fromJString(env, assetName);
|
auto assetNameStr = fromJString(env, assetName);
|
||||||
|
|
||||||
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromAssets_start"));
|
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromAssets_start"));
|
||||||
|
@ -709,7 +713,7 @@ static void loadScriptFromAssets(JNIEnv* env, jobject obj, jobject assetManager,
|
||||||
static void loadScriptFromFile(JNIEnv* env, jobject obj, jstring fileName, jstring sourceURL) {
|
static void loadScriptFromFile(JNIEnv* env, jobject obj, jstring fileName, jstring sourceURL) {
|
||||||
jclass markerClass = env->FindClass("com/facebook/react/bridge/ReactMarker");
|
jclass markerClass = env->FindClass("com/facebook/react/bridge/ReactMarker");
|
||||||
|
|
||||||
auto bridge = jni::extractRefPtr<Bridge>(env, obj);
|
auto bridge = jni::extractRefPtr<CountableBridge>(env, obj);
|
||||||
auto fileNameStr = fileName == NULL ? "" : fromJString(env, fileName);
|
auto fileNameStr = fileName == NULL ? "" : fromJString(env, fileName);
|
||||||
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromFile_start"));
|
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromFile_start"));
|
||||||
auto script = fileName == NULL ? "" : react::loadScriptFromFile(fileNameStr);
|
auto script = fileName == NULL ? "" : react::loadScriptFromFile(fileNameStr);
|
||||||
|
@ -729,7 +733,7 @@ static void loadScriptFromFile(JNIEnv* env, jobject obj, jstring fileName, jstri
|
||||||
|
|
||||||
static void callFunction(JNIEnv* env, jobject obj, jint moduleId, jint methodId,
|
static void callFunction(JNIEnv* env, jobject obj, jint moduleId, jint methodId,
|
||||||
NativeArray::jhybridobject args) {
|
NativeArray::jhybridobject args) {
|
||||||
auto bridge = extractRefPtr<Bridge>(env, obj);
|
auto bridge = extractRefPtr<CountableBridge>(env, obj);
|
||||||
auto arguments = cthis(wrap_alias(args));
|
auto arguments = cthis(wrap_alias(args));
|
||||||
try {
|
try {
|
||||||
bridge->callFunction(
|
bridge->callFunction(
|
||||||
|
@ -744,7 +748,7 @@ static void callFunction(JNIEnv* env, jobject obj, jint moduleId, jint methodId,
|
||||||
|
|
||||||
static void invokeCallback(JNIEnv* env, jobject obj, jint callbackId,
|
static void invokeCallback(JNIEnv* env, jobject obj, jint callbackId,
|
||||||
NativeArray::jhybridobject args) {
|
NativeArray::jhybridobject args) {
|
||||||
auto bridge = extractRefPtr<Bridge>(env, obj);
|
auto bridge = extractRefPtr<CountableBridge>(env, obj);
|
||||||
auto arguments = cthis(wrap_alias(args));
|
auto arguments = cthis(wrap_alias(args));
|
||||||
try {
|
try {
|
||||||
bridge->invokeCallback(
|
bridge->invokeCallback(
|
||||||
|
@ -757,32 +761,32 @@ static void invokeCallback(JNIEnv* env, jobject obj, jint callbackId,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setGlobalVariable(JNIEnv* env, jobject obj, jstring propName, jstring jsonValue) {
|
static void setGlobalVariable(JNIEnv* env, jobject obj, jstring propName, jstring jsonValue) {
|
||||||
auto bridge = extractRefPtr<Bridge>(env, obj);
|
auto bridge = extractRefPtr<CountableBridge>(env, obj);
|
||||||
bridge->setGlobalVariable(fromJString(env, propName), fromJString(env, jsonValue));
|
bridge->setGlobalVariable(fromJString(env, propName), fromJString(env, jsonValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
static jboolean supportsProfiling(JNIEnv* env, jobject obj) {
|
static jboolean supportsProfiling(JNIEnv* env, jobject obj) {
|
||||||
auto bridge = extractRefPtr<Bridge>(env, obj);
|
auto bridge = extractRefPtr<CountableBridge>(env, obj);
|
||||||
return bridge->supportsProfiling() ? JNI_TRUE : JNI_FALSE;
|
return bridge->supportsProfiling() ? JNI_TRUE : JNI_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void startProfiler(JNIEnv* env, jobject obj, jstring title) {
|
static void startProfiler(JNIEnv* env, jobject obj, jstring title) {
|
||||||
auto bridge = extractRefPtr<Bridge>(env, obj);
|
auto bridge = extractRefPtr<CountableBridge>(env, obj);
|
||||||
bridge->startProfiler(fromJString(env, title));
|
bridge->startProfiler(fromJString(env, title));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stopProfiler(JNIEnv* env, jobject obj, jstring title, jstring filename) {
|
static void stopProfiler(JNIEnv* env, jobject obj, jstring title, jstring filename) {
|
||||||
auto bridge = extractRefPtr<Bridge>(env, obj);
|
auto bridge = extractRefPtr<CountableBridge>(env, obj);
|
||||||
bridge->stopProfiler(fromJString(env, title), fromJString(env, filename));
|
bridge->stopProfiler(fromJString(env, title), fromJString(env, filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleMemoryPressureModerate(JNIEnv* env, jobject obj) {
|
static void handleMemoryPressureModerate(JNIEnv* env, jobject obj) {
|
||||||
auto bridge = extractRefPtr<Bridge>(env, obj);
|
auto bridge = extractRefPtr<CountableBridge>(env, obj);
|
||||||
bridge->handleMemoryPressureModerate();
|
bridge->handleMemoryPressureModerate();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleMemoryPressureCritical(JNIEnv* env, jobject obj) {
|
static void handleMemoryPressureCritical(JNIEnv* env, jobject obj) {
|
||||||
auto bridge = extractRefPtr<Bridge>(env, obj);
|
auto bridge = extractRefPtr<CountableBridge>(env, obj);
|
||||||
bridge->handleMemoryPressureCritical();
|
bridge->handleMemoryPressureCritical();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,17 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
#include <jni/Countable.h>
|
||||||
|
#include <react/Executor.h>
|
||||||
|
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace react {
|
namespace react {
|
||||||
|
|
||||||
jmethodID getLogMarkerMethod();
|
jmethodID getLogMarkerMethod();
|
||||||
|
|
||||||
|
struct CountableJSExecutorFactory : JSExecutorFactory, Countable {
|
||||||
|
using JSExecutorFactory::JSExecutorFactory;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace react
|
} // namespace react
|
||||||
} // namespace facebook
|
} // namespace facebook
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <react/Bridge.h>
|
|
||||||
#include <react/Executor.h>
|
#include <react/Executor.h>
|
||||||
#include <jni/fbjni.h>
|
#include <jni/fbjni.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <jni/GlobalReference.h>
|
#include <jni/GlobalReference.h>
|
||||||
|
#include "OnLoad.h"
|
||||||
|
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace react {
|
namespace react {
|
||||||
|
|
Loading…
Reference in New Issue