jnienv

JNI thread model?

我只是一个虾纸丫 提交于 2021-02-17 21:47:10
问题 When I call a C/C++ from Java, is a new thread created by JavaVM or JNI to run the C/C++ code while my Java thread is waiting? I ask this because my C/C++ code runs something on the GPU and I need to check a specific buffer to get the result back. Once I have the result, I need to call my Java function again. So I was thinking of creating a thread on the C++ side that continuously checks the buffer and once there is some data available, makes a call back to the Java side. 回答1: The JNI does

Casting a borrowed reference with a lifetime to a raw pointer in Rust

不打扰是莪最后的温柔 提交于 2021-01-28 11:51:24
问题 I am new to rust and am trying to wrap my head around lifetimes. Please consider the following code: use jni::JNIEnv; pub struct CameraAppEngine<'a> { _env: &'a JNIEnv<'a>, _width: i32, _height: i32 } impl<'a> CameraAppEngine<'a> { pub fn new(_env: &'a JNIEnv<'a>, _width: i32, _height: i32) -> CameraAppEngine { CameraAppEngine { _env, _width, _height } } pub fn env(&'a self) -> JNIEnv<'a> { JNIEnv::from_raw(self._env).unwrap() // error! } } The JNIEnv::from_raw method has a type signature of

Converting jni::sys::JNIEnv to JNINativeInterface defined in ffi

眉间皱痕 提交于 2020-02-25 04:06:30
问题 I am following up on Casting a borrowed reference with a lifetime to a raw pointer in Rust, which solved the wrong problem. Please consider the following code: extern crate jni; extern crate ffi; use jni::JNIEnv; use jni::objects::JClass; use jni::sys::{jint, jlong, jobject}; struct CameraAppEngine { _env: *mut jni::sys::JNIEnv, _width: i32, _height: i32 } impl CameraAppEngine { pub fn new(_env: *mut jni::sys::JNIEnv, _width: i32, _height: i32) -> CameraAppEngine { CameraAppEngine { _env,

JNI_CreateJavaVM() terminates with exit code 1

亡梦爱人 提交于 2019-12-29 08:38:05
问题 I'm trying to call a Java method from C++ using JNI. To do that I've installed jdk1.7.0_51 , linking against jdk1.7.0_51\lib\jvm.lib , including jdk1.7.0_51\include and jdk1.7.0_51\include\win32 . using the following code in Visual Studio 2012 I tried to create a Java vm object - but the function always terminates my application with exit code 1 (the function doesn't return 1: my program terminates completly and sends the exit code 1). #include <iostream> #include "jni.h" int main(int argc,

Keeping a global reference to the JNIEnv environment

那年仲夏 提交于 2019-12-28 02:31:07
问题 I am storing off JNIEnv in a global so I can call static java methods later. But is it nessasary to store off a global pointer to the JNIEnv , they way one would with any other java object, or is it a special case that does not require this. JNIEnv* globalEnvPointer; [JNICALL etc] void init(JNIENv* env, [etc]) { //required? globalEnvPointer = (JNIENv*) (env*)->GetGlobalRef(env, env); //or is this OK? globalEnvPointer = env; } Edit I'm bing a bit dumb here, all the methods that will use

call java methods with argumenrs in JNI

天大地大妈咪最大 提交于 2019-12-25 02:52:24
问题 I am working on JNI program and I am not able to call a java method from my C++ program. The code snippet of java method is here public static void getTables(Connection conn) throws Exception { String TABLE_NAME = "TABLE_NAME"; String TABLE_SCHEMA = "TABLE_SCHEM"; String[] TABLE_TYPES = {"TABLE"}; DatabaseMetaData dbmd = conn.getMetaData(); ResultSet tables = dbmd.getTables(null, null, null, TABLE_TYPES); while (tables.next()) { System.out.println(tables.getString(TABLE_NAME)); System.out

call java methods with argumenrs in JNI

北慕城南 提交于 2019-12-25 02:52:13
问题 I am working on JNI program and I am not able to call a java method from my C++ program. The code snippet of java method is here public static void getTables(Connection conn) throws Exception { String TABLE_NAME = "TABLE_NAME"; String TABLE_SCHEMA = "TABLE_SCHEM"; String[] TABLE_TYPES = {"TABLE"}; DatabaseMetaData dbmd = conn.getMetaData(); ResultSet tables = dbmd.getTables(null, null, null, TABLE_TYPES); while (tables.next()) { System.out.println(tables.getString(TABLE_NAME)); System.out

Qt JNI : Invalid indirect reference 0x61382e48 in decodeIndirectRef

做~自己de王妃 提交于 2019-12-24 03:05:08
问题 I am trying the Qt project that captures audio data from mic on android. I refereed this article : Android AudioRecord example, and wrote it to Qt code. int recorderSampleRate = 44100; int recorderChannels = QAndroidJniObject::getStaticField<jint>("android/media/AudioFormat", "CHANNEL_IN_MONO"); int recorderAudioEncoding = QAndroidJniObject::getStaticField<jint>("android/media/AudioFormat", "ENCODING_PCM_16BIT"); int sourceType = QAndroidJniObject::getStaticField<jint>("android/media

Android Jni : crash in global and local ref variables

大城市里の小女人 提交于 2019-12-22 14:47:26
问题 I have jni c++ code that calls java objects methods, example : jclass JIOManager = CJavaEnv::getInstance()->env()->FindClass(ioManagerName); ..... some code CJavaEnv::getInstance()->env()->DeleteLocalRef(JIOManager); this works really fine when executes in main thread, but when I try to execute this in another thread it crash because it says that it is created in another thread :O !! but after I read in google android developer website, they say accessing Global Ref from any thread is fine,

What is the best way to save JNIEnv*

柔情痞子 提交于 2019-12-17 04:36:08
问题 I have an Android project with JNI. In the CPP file which implements a listener class, there is a callback x() . When x() function is called, I want to call another function in a java class. However, in order to invoke that java function, I need to access JNIEnv*. I know that in the same cpp file of the callback, there is a function: static jboolean init (JNIEnv* env, jobject obj) {...} Should I save in the cpp file JNIEnv* as member variable when init(..) is called? and use it later when the