Skip to content

Commit

Permalink
Remove jni dependencies from Bridge.h/cpp
Browse files Browse the repository at this point in the history
Reviewed By: astreet

Differential Revision: D2905191

fb-gh-sync-id: 7510ef1d1b87ff50f35195d5ca8c0dd98f81526f
shipit-source-id: 7510ef1d1b87ff50f35195d5ca8c0dd98f81526f
  • Loading branch information
cjhopman authored and facebook-github-bot-5 committed Feb 9, 2016
1 parent 1d561fd commit 229c8c3
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion ReactAndroid/src/main/jni/react/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ReactAndroid/src/main/jni/react/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ react_library(
'-std=c++11',
'-fexceptions',
'-fvisibility=hidden',
'-frtti',
],
)
5 changes: 1 addition & 4 deletions ReactAndroid/src/main/jni/react/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

#include "Bridge.h"

#include "Executor.h"
#include "MethodCall.h"

#ifdef WITH_FBSYSTRACE
#include <fbsystrace.h>
using fbsystrace::FbSystraceSection;
Expand All @@ -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)))
{
Expand Down
10 changes: 2 additions & 8 deletions ReactAndroid/src/main/jni/react/Bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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();

/**
Expand Down
30 changes: 17 additions & 13 deletions ReactAndroid/src/main/jni/react/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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"));
Expand All @@ -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);
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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();
}

Expand Down
6 changes: 6 additions & 0 deletions ReactAndroid/src/main/jni/react/jni/OnLoad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ReactAndroid/src/main/jni/react/jni/ProxyExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 229c8c3

Please sign in to comment.