Advertisement
you_are_adopted

xxxx_jni.cpp

Feb 23rd, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1.  
  2. #include <string.h>
  3. #include <jni.h>
  4. #include <boost/thread.hpp>
  5. #include "XXXProtocol.h"
  6.  
  7. #include <metaioSDK/IMetaioSDK.h>
  8. #include <metaioSDK/IGeometry.h>
  9.  
  10. #include <XXXXLib/MetaioSDK-Extensions/JavaMethodLib.h>
  11.  
  12. #include <XXXXLib/MetaioSDK-Extensions/MetaioSDKExtensions.h>
  13.  
  14. JNIEnv* javaEnv = 0;
  15. jobject javaThiz = 0;
  16.  
  17. JavaVM* jvm;
  18. jint jVersion;
  19. JNIEnv* jEnv;
  20. jobject jObj;
  21.  
  22. jobject globalObj;
  23.  
  24. // Convert a std string to a jstring
  25. void GetJStringContent(JNIEnv *AEnv, jstring AStr, std::string &ARes) {
  26.   if (!AStr) {
  27.     ARes.clear();
  28.     return;
  29.   }
  30.  
  31.   const char *s = AEnv->GetStringUTFChars(AStr,NULL);
  32.   ARes=s;
  33.   AEnv->ReleaseStringUTFChars(AStr,s);
  34. }
  35.  
  36. extern "C" {
  37. JNIEXPORT void JNICALL Java_yy_zzz_XXXX_ndkcode_XXXProtocol_startXXXX(
  38.     JNIEnv* env, jobject thiz , jstring ip, jint port, jstring assetPath);
  39.  
  40. JNIEXPORT void JNICALL Java_yy_zzz_XXXX_ndkcode_XXXProtocol_stopXXXX(
  41.     JNIEnv* env, jobject thiz);
  42.    
  43. JNIEXPORT void JNICALL Java_yy_zzz_XXXX_ndkcode_XXXProtocol_sendJsonViaXXXX(
  44.     JNIEnv* env, jobject thiz, jstring jsonString);
  45. }
  46.  
  47.  
  48.  
  49. JNIEXPORT void JNICALL Java_yy_zzz_XXXX_ndkcode_XXXProtocol_startXXXX(
  50.     JNIEnv* env, jobject thiz, jstring ip, jint port, jstring assetPath)
  51. {
  52.     std::string ipStr;
  53.     GetJStringContent(env, ip, ipStr);
  54.  
  55.     std::string pathStr;
  56.     GetJStringContent(env, assetPath, pathStr);
  57.  
  58.     // thread preparation
  59.     JavaVM* javaVM;
  60.     env->GetJavaVM(&javaVM);
  61.  
  62.     jvm = javaVM;
  63.  
  64.     jVersion = env->GetVersion();
  65.  
  66.     toaster(env, thiz, "XXXX started!");
  67.  
  68.     // make it global, so the garbage collector does not mess it up
  69.     globalObj = env->NewGlobalRef(thiz);
  70.  
  71.     XXXX_init(ipStr, (uint16_t)port, pathStr, env, globalObj);
  72. }
  73.  
  74. JNIEXPORT void JNICALL Java_yy_zzz_XXXX_ndkcode_XXXProtocol_stopXXXX(
  75.     JNIEnv* env, jobject thiz){
  76.  
  77.     stopUpdateThread();
  78.  
  79. }
  80.  
  81. JNIEXPORT void JNICALL Java_yy_zzz_XXXX_ndkcode_XXXProtocol_sendJsonViaXXXX(
  82.     JNIEnv* env, jobject thiz, jstring jsonString) {
  83.     std::string nativeJsonString;
  84.     GetJStringContent(env, jsonString, nativeJsonString);
  85.    
  86.     sendJson(nativeJsonString);
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement