fnc12 / Mitsoko

10 stars 1 forks source link

Usage discussion #2

Closed DonaldTrump88 closed 7 years ago

DonaldTrump88 commented 7 years ago

I added this issue for people who want to discssion about the library. https://github.com/fnc12/embeddedRest/issues/4

fnc12 commented 7 years ago

Thanks. But it'd be better to discuss it here cause people will not understand why mitsoko is being discussed in embeddedRest repo

DonaldTrump88 commented 7 years ago

I felt so. So I opened this issue. For for background of following discussion, you may refer https://github.com/fnc12/embeddedRest/issues/4

  1. There is no release of created string in AndroidUtil\java\lang\String.cpp. Is it because of usage of std::move(create(p)) AndroidUtil\java\io\File.cpp ?
  2. Where is connection with HttpURLConnection?
  3. Does Mitsoko library have any dependency?
DonaldTrump88 commented 7 years ago

What do you mean release of created string? Dalvik garbage collector releases all local variables once it decides to do so.

If it goes to Dalvik then its garbage cleaner will delete it. But it depends on usage of create. I am not sure, how it is used. What about GetStringUTFChars string? Shouldn't it be released? https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#GetStringUTFChars

fnc12 commented 7 years ago

Yes, GetStringUTFChars gotta be released probably but I don't do it. We gotta add release of them. Also it would be great to add auto release of local variables cause local variables pool is limited to 512. Once Mitsoko/JNI creates 513th one app crashes. Local variables can be released explicitly but it is optional. Also it is good to create global reference class to keep global vars in JNI. Now the only way to create global ref is to call JNI env directly using java::lang::JNI::Env()->NewGlobalRef(...);. BTW java::lang::JNI::Env() returns JNIEnv pointer used for pure JNI functions. So you can use it. JNIEnv pointers are stored in a static map one per thread. The map is guarded by mutex cause it's very important and can be accesses in different threads (I met data races - it's hard to debug it on android).

DonaldTrump88 commented 7 years ago

Yes, you are correct.

  1. I found that mitsoko-template/proj.android/app/src/main/jni/Android.mk has LOCAL_LDLIBS += -llog -ldl -landroid.
fnc12 commented 7 years ago

Oh I forgot one thing about dependencies - you also gotta include mitsoko-template/proj.android/app/src/main/jni/ dir with its contents cause this is a folder with C++ compilation scripts and NI.cpp source that has java native functions implementation.

And what about LOCAL_LDLIBS += -llog -ldl -landroid?

DonaldTrump88 commented 7 years ago

Good morning, I think, you need log lib due to __android_log_write in AndroidUtil.hpp. I did not find its usage in the library itself. Is it possible to add preprocessor directive to make it enableable it, e.g ENABLE_ANDROID_LOG or atleast DISABLE_ANDROID_LOG?

fnc12 commented 7 years ago

you can log with LOGI macro like LOGI("name = %s", name.c_str());. Also cout is redirected to android log so just << data to cout to see it in logcat.

DonaldTrump88 commented 7 years ago

Thanks, there is also libandroid.so used for linking. But there no header include in Mitsoko from https://developer.android.com/ndk/guides/stable_apis.html . May I know why Mitsoko does need libandroid.so?

fnc12 commented 7 years ago

libandroid.so is required for CrystaX NDK https://www.crystax.net

DonaldTrump88 commented 7 years ago

Interesting. What do you do with it? I saw that you have used APP_STL := gnustl_static also.

fnc12 commented 7 years ago

CrystaX has better implementation of std lib. E.g. google ndk hasn't std::to_string implementation but CrystaX ndk has. APP_STL doesn't matter. I used all of options and it compiles well.

DonaldTrump88 commented 7 years ago

Good, so can I stay with Android NDK instead of CrystaX? I think, it should work.

fnc12 commented 7 years ago

You can try. But I cannot guarantee it will work. Anyway it's easy to switch NDK - just download it and set path in the project in properties.local file

DonaldTrump88 commented 7 years ago

I read its features from https://www.crystax.net/en/android/ndk. Unfortunatelly, they does not offer me any additional value over standard NDK.

DonaldTrump88 commented 7 years ago
  1. Where is connection with HttpURLConnection?
fnc12 commented 7 years ago

https://github.com/fnc12/Mitsoko/blob/master/Url/Request.cpp Mitsoko::Url::Request::performAsync<std::vector<char>> function

DonaldTrump88 commented 7 years ago

Closing the issue.