Private
Public Access
2
0

peripheralman: implement gpio interrupt

Add gpio interrupt support for peripheral manager based on the
existing implementation in gpio.c.
Rewrite steps by using a global reference to lookup java isr
routine using JNI methods and add exception check after every call.
Free local reference class since it's not garbage collected and will
lead to a memory leak.

Signed-off-by: Sanrio Alvares <sanrio.alvares@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Sanrio Alvares
2017-06-26 15:18:19 -07:00
committed by Brendan Le Foll
parent 5bbea8010e
commit 3d77c86634
2 changed files with 123 additions and 4 deletions

View File

@@ -29,7 +29,7 @@ static pthread_key_t env_key;
static pthread_once_t env_key_init = PTHREAD_ONCE_INIT;
static jmethodID runGlobal;
static JavaVM* globVM = NULL;
static jclass jcObject;
void
mraa_java_set_jvm(JavaVM* vm)
@@ -44,8 +44,24 @@ mraa_java_make_env_key(void)
JNIEnv* jenv;
(*globVM)->GetEnv(globVM, (void**) &jenv, JNI_REQUIRED_VERSION);
jclass rcls = (*jenv)->FindClass(jenv, "java/lang/Runnable");
jmethodID runm = (*jenv)->GetMethodID(jenv, rcls, "run", "()V");
runGlobal = (jmethodID)(*jenv)->NewGlobalRef(jenv, (jobject) runm);
if ((*jenv)->ExceptionOccurred(jenv)) {
(*jenv)->ExceptionClear(jenv);
return;
}
jcObject = (jclass) (*jenv)->NewGlobalRef(jenv, rcls);
if ((*jenv)->ExceptionOccurred(jenv)) {
(*jenv)->ExceptionClear(jenv);
return;
}
(*jenv)->DeleteLocalRef(jenv, rcls);
runGlobal = (*jenv)->GetMethodID(jenv, jcObject, "run", "()V");
if ((*jenv)->ExceptionOccurred(jenv)) {
(*jenv)->ExceptionClear(jenv);
return;
}
pthread_key_create(&env_key, NULL);
}
}