From 6f2dc73bb6bd5ff48cb4a2e77e9e7b6a93828902 Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期二, 07 一月 2020 19:21:39 +0800
Subject: [PATCH] 修改进程间接口,统一为foo(int, string)

---
 lib/src/main/cpp/native-lib.cpp |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/lib/src/main/cpp/native-lib.cpp b/lib/src/main/cpp/native-lib.cpp
index db4f1e8..211125f 100644
--- a/lib/src/main/cpp/native-lib.cpp
+++ b/lib/src/main/cpp/native-lib.cpp
@@ -13,6 +13,7 @@
 #include "rtk_module/rtk.h"
 #include "mcu/mcu_if.h"
 #include "driver_test.h"
+#include "master/comm_if.h"
 
 static JavaVM *sg_jvm = NULL;
 static jobject sg_obj = NULL;
@@ -407,6 +408,36 @@
     }
 }
 
+void SendMsgToMainProc(int cmd, const char *value)
+{
+    JNIEnv *env;
+    bool ready_in_java_env = false;
+
+    if (sg_jvm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) {
+        // Attach涓荤嚎绋�
+        if (sg_jvm->AttachCurrentThread(&env, NULL) != JNI_OK) {
+            LOGE("%s: AttachCurrentThread() failed", __FUNCTION__);
+            return;
+        }
+    } else {
+        ready_in_java_env = true;
+    }
+
+    jclass cls = env->GetObjectClass(sg_obj);
+    jmethodID fun = env->GetMethodID(cls, "SendMsgToMainProc", "(ILjava/lang/String;)V");
+
+    env->CallVoidMethod(sg_obj, fun, cmd, value != NULL ? env->NewStringUTF(value) : NULL);
+
+    env->DeleteLocalRef(cls);
+
+    if (!ready_in_java_env) {
+        //Detach涓荤嚎绋�
+        if (sg_jvm->DetachCurrentThread() != JNI_OK) {
+            LOGE("%s: DetachCurrentThread() failed", __FUNCTION__);
+        }
+    }
+}
+
 void DisplayText(const char *string)
 {
     DEBUG("DisplayText: %s", string);
@@ -422,11 +453,25 @@
     // 涓嶈兘鐩存帴璧嬪��(g_obj = ojb)
     sg_obj = env->NewGlobalRef(thiz);
 
+    MA_NdkStart();
     AppTimer_Init();
-
     ConfigMCU();
     DriverTestInit();
     ConfigRTKModule();
 
     InitPlatform(phone, RTK_PLATFORM_IP, RTK_PLATFORM_PORT);
-}
\ No newline at end of file
+}
+
+extern "C"
+JNIEXPORT void JNICALL
+Java_com_anyun_exam_lib_RemoteService_MainProcMsgEntry(JNIEnv *env, jobject thiz, jint cmd,
+                                                       jstring value) {
+    // TODO: implement MainProcMsgEntry()
+    if (value != NULL) {
+        const char *str = env->GetStringUTFChars(value, 0);
+        MA_MainProcMsgEntry(cmd, str);
+        env->ReleaseStringUTFChars(value, str);
+    } else {
+        MA_MainProcMsgEntry(cmd, NULL);
+    }
+}

--
Gitblit v1.8.0