From 229c8c35c940318102daaa6d1a654f773ecffd2f Mon Sep 17 00:00:00 2001 From: Chris Hopman Date: Tue, 9 Feb 2016 12:59:33 -0800 Subject: [PATCH] Remove jni dependencies from Bridge.h/cpp Reviewed By: astreet Differential Revision: D2905191 fb-gh-sync-id: 7510ef1d1b87ff50f35195d5ca8c0dd98f81526f shipit-source-id: 7510ef1d1b87ff50f35195d5ca8c0dd98f81526f --- ReactAndroid/src/main/jni/react/Android.mk | 2 +- ReactAndroid/src/main/jni/react/BUCK | 1 + ReactAndroid/src/main/jni/react/Bridge.cpp | 5 +--- ReactAndroid/src/main/jni/react/Bridge.h | 10 ++----- .../src/main/jni/react/jni/OnLoad.cpp | 30 +++++++++++-------- ReactAndroid/src/main/jni/react/jni/OnLoad.h | 6 ++++ .../src/main/jni/react/jni/ProxyExecutor.h | 2 +- 7 files changed, 29 insertions(+), 27 deletions(-) diff --git a/ReactAndroid/src/main/jni/react/Android.mk b/ReactAndroid/src/main/jni/react/Android.mk index 3e3fbe247..073d09157 100644 --- a/ReactAndroid/src/main/jni/react/Android.mk +++ b/ReactAndroid/src/main/jni/react/Android.mk @@ -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) diff --git a/ReactAndroid/src/main/jni/react/BUCK b/ReactAndroid/src/main/jni/react/BUCK index 2835903f4..8bafe44d2 100644 --- a/ReactAndroid/src/main/jni/react/BUCK +++ b/ReactAndroid/src/main/jni/react/BUCK @@ -71,5 +71,6 @@ react_library( '-std=c++11', '-fexceptions', '-fvisibility=hidden', + '-frtti', ], ) diff --git a/ReactAndroid/src/main/jni/react/Bridge.cpp b/ReactAndroid/src/main/jni/react/Bridge.cpp index 93ba78e5a..a4bb6887e 100644 --- a/ReactAndroid/src/main/jni/react/Bridge.cpp +++ b/ReactAndroid/src/main/jni/react/Bridge.cpp @@ -2,9 +2,6 @@ #include "Bridge.h" -#include "Executor.h" -#include "MethodCall.h" - #ifdef WITH_FBSYSTRACE #include using fbsystrace::FbSystraceSection; @@ -13,7 +10,7 @@ using fbsystrace::FbSystraceSection; namespace facebook { namespace react { -Bridge::Bridge(const RefPtr& jsExecutorFactory, Callback callback) : +Bridge::Bridge(JSExecutorFactory* jsExecutorFactory, Callback callback) : m_callback(std::move(callback)), m_destroyed(std::shared_ptr(new bool(false))) { diff --git a/ReactAndroid/src/main/jni/react/Bridge.h b/ReactAndroid/src/main/jni/react/Bridge.h index cbc6c7a98..26b1aa8ef 100644 --- a/ReactAndroid/src/main/jni/react/Bridge.h +++ b/ReactAndroid/src/main/jni/react/Bridge.h @@ -5,9 +5,6 @@ #include #include #include -#include -#include -#include #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, bool isEndOfBatch)> Callback; - Bridge(const RefPtr& jsExecutorFactory, Callback callback); + Bridge(JSExecutorFactory* jsExecutorFactory, Callback callback); virtual ~Bridge(); /** diff --git a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp index 2492fe858..128ef8338 100644 --- a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp @@ -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(env, executor); - auto bridge = createNew(nativeExecutorFactory, bridgeCallback); + auto bridge = createNew(nativeExecutorFactory.get(), bridgeCallback); setCountableForJava(env, obj, std::move(bridge)); } static void executeApplicationScript( - const RefPtr& bridge, + const RefPtr& bridge, const std::string& script, const std::string& sourceUri) { try { @@ -661,7 +665,7 @@ static void executeApplicationScript( } static void loadApplicationUnbundle( - const RefPtr& bridge, + const RefPtr& 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(env, obj); + auto bridge = extractRefPtr(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(env, obj); + auto bridge = jni::extractRefPtr(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(env, obj); + auto bridge = extractRefPtr(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(env, obj); + auto bridge = extractRefPtr(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(env, obj); + auto bridge = extractRefPtr(env, obj); bridge->setGlobalVariable(fromJString(env, propName), fromJString(env, jsonValue)); } static jboolean supportsProfiling(JNIEnv* env, jobject obj) { - auto bridge = extractRefPtr(env, obj); + auto bridge = extractRefPtr(env, obj); return bridge->supportsProfiling() ? JNI_TRUE : JNI_FALSE; } static void startProfiler(JNIEnv* env, jobject obj, jstring title) { - auto bridge = extractRefPtr(env, obj); + auto bridge = extractRefPtr(env, obj); bridge->startProfiler(fromJString(env, title)); } static void stopProfiler(JNIEnv* env, jobject obj, jstring title, jstring filename) { - auto bridge = extractRefPtr(env, obj); + auto bridge = extractRefPtr(env, obj); bridge->stopProfiler(fromJString(env, title), fromJString(env, filename)); } static void handleMemoryPressureModerate(JNIEnv* env, jobject obj) { - auto bridge = extractRefPtr(env, obj); + auto bridge = extractRefPtr(env, obj); bridge->handleMemoryPressureModerate(); } static void handleMemoryPressureCritical(JNIEnv* env, jobject obj) { - auto bridge = extractRefPtr(env, obj); + auto bridge = extractRefPtr(env, obj); bridge->handleMemoryPressureCritical(); } diff --git a/ReactAndroid/src/main/jni/react/jni/OnLoad.h b/ReactAndroid/src/main/jni/react/jni/OnLoad.h index 9da83c447..e7a7d04a4 100644 --- a/ReactAndroid/src/main/jni/react/jni/OnLoad.h +++ b/ReactAndroid/src/main/jni/react/jni/OnLoad.h @@ -3,11 +3,17 @@ #pragma once #include +#include +#include namespace facebook { namespace react { jmethodID getLogMarkerMethod(); +struct CountableJSExecutorFactory : JSExecutorFactory, Countable { + using JSExecutorFactory::JSExecutorFactory; +}; + } // namespace react } // namespace facebook diff --git a/ReactAndroid/src/main/jni/react/jni/ProxyExecutor.h b/ReactAndroid/src/main/jni/react/jni/ProxyExecutor.h index 5b2842592..09e7778b0 100644 --- a/ReactAndroid/src/main/jni/react/jni/ProxyExecutor.h +++ b/ReactAndroid/src/main/jni/react/jni/ProxyExecutor.h @@ -2,11 +2,11 @@ #pragma once -#include #include #include #include #include +#include "OnLoad.h" namespace facebook { namespace react {