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:
Chris Hopman 2016-02-09 12:59:33 -08:00 committed by facebook-github-bot-5
parent 1d561fd604
commit 229c8c35c9
7 changed files with 29 additions and 27 deletions

View File

@ -19,7 +19,7 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
LOCAL_CFLAGS := \
-DLOG_TAG=\"ReactNative\"
LOCAL_CFLAGS += -Wall -Werror -fexceptions
LOCAL_CFLAGS += -Wall -Werror -fexceptions -frtti
CXX11_FLAGS := -std=c++11
LOCAL_CFLAGS += $(CXX11_FLAGS)
LOCAL_EXPORT_CPPFLAGS := $(CXX11_FLAGS)

View File

@ -71,5 +71,6 @@ react_library(
'-std=c++11',
'-fexceptions',
'-fvisibility=hidden',
'-frtti',
],
)

View File

@ -2,9 +2,6 @@
#include "Bridge.h"
#include "Executor.h"
#include "MethodCall.h"
#ifdef WITH_FBSYSTRACE
#include <fbsystrace.h>
using fbsystrace::FbSystraceSection;
@ -13,7 +10,7 @@ using fbsystrace::FbSystraceSection;
namespace facebook {
namespace react {
Bridge::Bridge(const RefPtr<CountableJSExecutorFactory>& jsExecutorFactory, Callback callback) :
Bridge::Bridge(JSExecutorFactory* jsExecutorFactory, Callback callback) :
m_callback(std::move(callback)),
m_destroyed(std::shared_ptr<bool>(new bool(false)))
{

View File

@ -5,9 +5,6 @@
#include <functional>
#include <map>
#include <vector>
#include <jni.h>
#include <fb/Countable.h>
#include <fb/RefPtr.h>
#include "Value.h"
#include "Executor.h"
#include "MethodCall.h"
@ -22,14 +19,11 @@ struct dynamic;
namespace facebook {
namespace react {
class CountableJSExecutorFactory : public JSExecutorFactory, public Countable {
};
class Bridge : public Countable {
class Bridge {
public:
typedef std::function<void(std::vector<MethodCall>, bool isEndOfBatch)> Callback;
Bridge(const RefPtr<CountableJSExecutorFactory>& jsExecutorFactory, Callback callback);
Bridge(JSExecutorFactory* jsExecutorFactory, Callback callback);
virtual ~Bridge();
/**

View File

@ -567,6 +567,10 @@ static jmethodID gCallbackMethod;
static jmethodID gOnBatchCompleteMethod;
static jmethodID gLogMarkerMethod;
struct CountableBridge : Bridge, Countable {
using Bridge::Bridge;
};
static void logMarker(const std::string& marker) {
JNIEnv* env = Environment::current();
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);
};
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));
}
static void executeApplicationScript(
const RefPtr<Bridge>& bridge,
const RefPtr<CountableBridge>& bridge,
const std::string& script,
const std::string& sourceUri) {
try {
@ -661,7 +665,7 @@ static void executeApplicationScript(
}
static void loadApplicationUnbundle(
const RefPtr<Bridge>& bridge,
const RefPtr<CountableBridge>& bridge,
AAssetManager *assetManager,
const std::string& startupCode,
const std::string& startupFileName) {
@ -683,7 +687,7 @@ static void loadScriptFromAssets(JNIEnv* env, jobject obj, jobject assetManager,
jstring assetName) {
jclass markerClass = env->FindClass("com/facebook/react/bridge/ReactMarker");
auto manager = AAssetManager_fromJava(env, assetManager);
auto bridge = extractRefPtr<Bridge>(env, obj);
auto bridge = extractRefPtr<CountableBridge>(env, obj);
auto assetNameStr = fromJString(env, assetName);
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) {
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);
env->CallStaticVoidMethod(markerClass, gLogMarkerMethod, env->NewStringUTF("loadScriptFromFile_start"));
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,
NativeArray::jhybridobject args) {
auto bridge = extractRefPtr<Bridge>(env, obj);
auto bridge = extractRefPtr<CountableBridge>(env, obj);
auto arguments = cthis(wrap_alias(args));
try {
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,
NativeArray::jhybridobject args) {
auto bridge = extractRefPtr<Bridge>(env, obj);
auto bridge = extractRefPtr<CountableBridge>(env, obj);
auto arguments = cthis(wrap_alias(args));
try {
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) {
auto bridge = extractRefPtr<Bridge>(env, obj);
auto bridge = extractRefPtr<CountableBridge>(env, obj);
bridge->setGlobalVariable(fromJString(env, propName), fromJString(env, jsonValue));
}
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;
}
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));
}
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));
}
static void handleMemoryPressureModerate(JNIEnv* env, jobject obj) {
auto bridge = extractRefPtr<Bridge>(env, obj);
auto bridge = extractRefPtr<CountableBridge>(env, obj);
bridge->handleMemoryPressureModerate();
}
static void handleMemoryPressureCritical(JNIEnv* env, jobject obj) {
auto bridge = extractRefPtr<Bridge>(env, obj);
auto bridge = extractRefPtr<CountableBridge>(env, obj);
bridge->handleMemoryPressureCritical();
}

View File

@ -3,11 +3,17 @@
#pragma once
#include <jni.h>
#include <jni/Countable.h>
#include <react/Executor.h>
namespace facebook {
namespace react {
jmethodID getLogMarkerMethod();
struct CountableJSExecutorFactory : JSExecutorFactory, Countable {
using JSExecutorFactory::JSExecutorFactory;
};
} // namespace react
} // namespace facebook

View File

@ -2,11 +2,11 @@
#pragma once
#include <react/Bridge.h>
#include <react/Executor.h>
#include <jni/fbjni.h>
#include <jni.h>
#include <jni/GlobalReference.h>
#include "OnLoad.h"
namespace facebook {
namespace react {