From 570607fa861ab3553b9c000d2a6ff0bcab0e7b26 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Wed, 13 Jan 2016 11:07:54 -0800 Subject: [PATCH] instantiate and make calls to rpc server --- .../com_reacttests_RealmReactAndroid.cpp | 21 ++++++++++++++----- .../com_reacttests_RealmReactAndroid.h | 2 +- tests/react-test-app/run-android.sh | 2 ++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/android/com_reacttests_RealmReactAndroid.cpp b/src/android/com_reacttests_RealmReactAndroid.cpp index 3b8a1a6f..19a6f01d 100644 --- a/src/android/com_reacttests_RealmReactAndroid.cpp +++ b/src/android/com_reacttests_RealmReactAndroid.cpp @@ -8,6 +8,7 @@ #include "com_reacttests_RealmReactAndroid.h" #include "JSCExecutor.h" #include "js_init.h" +#include "rpc.hpp" #include "platform.hpp" #include #include @@ -28,11 +29,10 @@ JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsCon // Getting the internal storage path for the application const char* strFileDir = env->GetStringUTFChars(fileDir , NULL); - std::string absoluteAppPath(strFileDir); + realm::set_default_realm_file_directory(strFileDir); env->ReleaseStringUTFChars(fileDir , strFileDir); - realm::set_default_realm_file_directory(absoluteAppPath); - __android_log_print(ANDROID_LOG_ERROR, "JSRealm", "Absolute path %s", realm::default_realm_file_directory().c_str()); + __android_log_print(ANDROID_LOG_ERROR, "JSRealm", "Absolute path %s", realm::default_realm_file_directory().c_str()); // load the symbol typedef std::unordered_map (*get_jsc_context_t)(); @@ -57,11 +57,16 @@ JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsCon * Class: com_reacttests_RealmReactAndroid * Method: setupChromeDebugModeRealmJsContext */ + static realm_js::RPCServer *s_rpc_server; JNIEXPORT jlong JNICALL Java_com_reacttests_RealmReactAndroid_setupChromeDebugModeRealmJsContext (JNIEnv *, jclass) { __android_log_print(ANDROID_LOG_ERROR, "JSRealm", "Java_com_reacttests_RealmReactAndroid_setupChromeDebugModeRealmJsContext"); - return 0; + if (s_rpc_server) { + delete s_rpc_server; + } + s_rpc_server = new realm_js::RPCServer(); + return (jlong)s_rpc_server; } /* @@ -70,9 +75,15 @@ JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsCon */ JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_processChromeDebugCommand - (JNIEnv *env, jclass, jlong rpc_server_ptr, jstring chrome_cmd) + (JNIEnv *env, jclass, jlong rpc_server_ptr, jstring chrome_cmd, jstring chrome_args) { __android_log_print(ANDROID_LOG_ERROR, "JSRealm", "Java_com_reacttests_RealmReactAndroid_processChromeDebugCommand"); + const char* cmd = env->GetStringUTFChars(chrome_cmd, NULL); + const char* args = env->GetStringUTFChars(chrome_args, NULL); + realm_js::json json = realm_js::json::parse(args); + s_rpc_server->perform_request(cmd, json); + env->ReleaseStringUTFChars(chrome_cmd, cmd); + env->ReleaseStringUTFChars(chrome_args, args); return env->NewStringUTF("Echo"); } diff --git a/src/android/com_reacttests_RealmReactAndroid.h b/src/android/com_reacttests_RealmReactAndroid.h index 7d13b454..86f41736 100644 --- a/src/android/com_reacttests_RealmReactAndroid.h +++ b/src/android/com_reacttests_RealmReactAndroid.h @@ -27,7 +27,7 @@ JNIEXPORT jlong JNICALL Java_com_reacttests_RealmReactAndroid_setupChromeDebugMo * Method: processsetupChromeDebugCommand */ JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_processChromeDebugCommand - (JNIEnv *, jclass, jlong, jstring); + (JNIEnv *, jclass, jlong, jstring, jstring); #ifdef __cplusplus diff --git a/tests/react-test-app/run-android.sh b/tests/react-test-app/run-android.sh index bdd9fe43..2bfcc423 100755 --- a/tests/react-test-app/run-android.sh +++ b/tests/react-test-app/run-android.sh @@ -3,4 +3,6 @@ cp ../../react-native/android/app/build/outputs/aar/app-debug.aar android/app/li rm -rf node_modules/realm node_modules/realm-tests npm install realm realm-tests cp ../../src/object-store/parser/queryTests.json node_modules/realm-tests/ +adb forward tcp:8082 tcp:8082 +adb reverse tcp:8081 tcp:8081 react-native run-android