void SFBool::setJavaIDs() { if (!mInit) { JNIEnv *jniEnv = getJniEnv(); if (jniEnv == NULL) return; // Class IDs mFieldClassID = jniEnv->FindClass("vrml/field/SFBool"); mConstFieldClassID = jniEnv->FindClass("vrml/field/ConstSFBool"); assert(mFieldClassID && mConstFieldClassID); // MethodIDs jclass classid = getFieldID(); mInitMethodID = jniEnv->GetMethodID(classid, "<init>", "(Z)V"); mGetValueMethodID = jniEnv->GetMethodID(classid, "getValue", "()Z"); mSetValueMethodID = jniEnv->GetMethodID(classid, "setValue", "(Z)V"); mSetNameMethodID = jniEnv->GetMethodID(classid, "setName", "(Ljava/lang/String;)V"); assert(mInitMethodID && mGetValueMethodID && mSetValueMethodID && mSetNameMethodID); // MethodIDs classid = getConstFieldID(); mConstInitMethodID = jniEnv->GetMethodID(classid, "<init>", "(Z)V"); mConstGetValueMethodID = jniEnv->GetMethodID(classid, "getValue", "()Z"); mConstSetValueMethodID = jniEnv->GetMethodID(classid, "setValue", "(Z)V"); mConstSetNameMethodID = jniEnv->GetMethodID(classid, "setName", "(Ljava/lang/String;)V"); assert(mConstInitMethodID && mConstGetValueMethodID && mConstSetValueMethodID && mConstSetNameMethodID); mInit = 1; } }
void NativeCommunicator::unableToConnectZmq() { JNIEnv *env = getJniEnv(); LOG("ZMQ_EVENT_NATIVE_COMMUNICATOR_UNABLE_TO_CONNECT_ZMQ"); jobject obj; if (env) { LOG("-ZNC2"); obj = getCallbackInterface(env); } bool send = true; if (obj) { /* Find the callBack method ID */ jclass interfaceClass = env->GetObjectClass(obj); jmethodID method = env->GetMethodID(interfaceClass, "unableToConnect", "()V"); if (!method) { LOG("callback_handler: failed to get method ID (unableToConnect)"); gJavaVM->DetachCurrentThread(); send = false; } if (send) { env->CallVoidMethod(obj, method); } gJavaVM->DetachCurrentThread(); } LOG("------------ SENT UNABLE TO CONNECT MESSAGE----------------"); }
/* callback function to be called when the notification for Open NFC Extension Manager's reply is received */ void openNfcExtNotifCallback (tMessageOpenNFC* pMessage) { LogInformation("openNfcExtNotifCallback: ENTER"); JNIEnv* e = getJniEnv(); jmethodID method; JNIEnv env = *e; jbyteArray outData = env->NewByteArray(e, pMessage->header.length); if (pMessage->header.length > 0) { env->SetByteArrayRegion(e, outData, 0, pMessage->header.length, (jbyte *) pMessage->pData); } method = env->GetStaticMethodID(e, classManager, "replyCallback", "(II[B)V"); if (method == 0) { LogError("openNfcExtNotifCallback(): can't call replyCallback()"); return; } env->CallStaticVoidMethod(e, classManager, method, pMessage->header.reqId, pMessage->header.errStatus, outData); env->DeleteLocalRef(e, outData); freeJniEnv(); }
void NativeCommunicator::invalidToken() { JNIEnv *env = getJniEnv(); LOG("ZMQ_EVENT_NATIVE_COMMUNICATOR_INVALID_TOKEN"); jobject obj; if (env) { LOG("-UMSC2"); obj = getCallbackInterface(env); } bool send = true; if (obj) { /* Find the callBack method ID */ jclass interfaceClass = env->GetObjectClass(obj); jmethodID method = env->GetMethodID(interfaceClass, "invalidToken", "()V"); if (!method) { LOG("callback_handler: failed to get method ID (invalidToken)"); gJavaVM->DetachCurrentThread(); send = false; } if (send) { env->CallVoidMethod(obj, method); } gJavaVM->DetachCurrentThread(); } LOG("------------ Messages Sent----------------"); }
jobject MFVec3f::toJavaObject(int bConstField) { JNIEnv *jniEnv = getJniEnv(); jclass classid = bConstField ? getConstFieldID() : getFieldID(); jmethodID initMethod = bConstField ? getConstInitMethodID() : getInitMethodID(); jobject fieldObject = jniEnv->NewObject(classid, initMethod); jmethodID setNameMethod = bConstField ? getConstSetNameMethodID() : getSetNameMethodID(); jmethodID addValueMethod = bConstField ? getConstAddValueMethodID() : getAddValueMethodID(); char *fieldName = getName(); jstring jfieldName = NULL; if (fieldName && strlen(fieldName)) jfieldName = jniEnv->NewStringUTF(getName()); jniEnv->CallVoidMethod(fieldObject, setNameMethod, jfieldName); if (jfieldName) jniEnv->DeleteLocalRef(jfieldName); int size = getSize(); for (int n=0; n<size; n++) { float value[3]; get1Value(n, value); jfloat x = value[0]; jfloat y = value[1]; jfloat z = value[2]; jniEnv->CallVoidMethod(fieldObject, addValueMethod, x, y, z); } return fieldObject; }
void NativeCallListener::loadAudio(){ //init(); load(); sendLog(getJniEnv()->NewStringUTF("load complete!")); }
void NativeCommunicator::unableToInitalizeCamera() { JNIEnv *env = getJniEnv(); LOG("ZMQ_EVENT_NATIVE_UABLE_TO_INITIALIZE_CAMERA"); jobject obj; if (env) { obj = getCallbackInterface(env); } bool send = true; if (obj) { /* Find the callBack method ID */ jclass interfaceClass = env->GetObjectClass(obj); jmethodID method = env->GetMethodID(interfaceClass, "unableToInitalizeCamera", "()V"); if (!method) { LOG("callback_handler: failed to get method ID (unableToInitalizeCamera"); gJavaVM->DetachCurrentThread(); send = false; } if (send) { env->CallVoidMethod(obj, method); } gJavaVM->DetachCurrentThread(); } LOG("------------ Messages Sent (unableToInitalizeCamera)----------------"); }
void NativeCommunicator::zmqConnectionDropped() { JNIEnv *env = getJniEnv(); LOG("ZMQ_EVENT_NATIVE_COMMUNICATOR_CONNECTION_DROPPED"); jobject obj; if (env) { LOG("-ZNCD2"); obj = getCallbackInterface(env); } bool send = true; if (obj) { LOG("---ABOUT-TO-CALL-JAVA-METHOD"); /* Find the callBack method ID */ jclass interfaceClass = env->GetObjectClass(obj); jmethodID method = env->GetMethodID(interfaceClass, "connectionDropped", "()V"); if (!method) { LOG("callback_handler: failed to get method ID (connectionDropped)"); gJavaVM->DetachCurrentThread(); send = false; } if (send) { env->CallVoidMethod(obj, method); } gJavaVM->DetachCurrentThread(); } LOG("------------ CONNECTION DROPPED----------------"); }
void NativeCommunicator::updateMessageSent(long messageSent) { JNIEnv *env = getJniEnv(); LOG("ZMQ_EVENT_NATIVE_COMMUNICATOR_UPDATE_MESSAGE_SENT"); jobject obj; if (env) { LOG("-UMSC2"); obj = getCallbackInterface(env); } bool send = true; if (obj) { /* Find the callBack method ID */ jclass interfaceClass = env->GetObjectClass(obj); jmethodID method = env->GetMethodID(interfaceClass, "updateMessagesSent", "(J)V"); if (!method) { LOG("callback_handler: failed to get method ID (updateMessagesSent)"); gJavaVM->DetachCurrentThread(); send = false; } if (send) { env->CallVoidMethod(obj, method); } gJavaVM->DetachCurrentThread(); } LOG("------------ Messages Sent----------------"); }
void NativeCommunicator::updateStreamToken(std::string streamToken) { JNIEnv *env = getJniEnv(); LOG("ZMQ_EVENT_NATIVE_COMMUNICATOR_UPDATE_STREAM_TOKEN"); jobject obj; if (env) { LOG("-UMSC2"); obj = getCallbackInterface(env); } bool send = true; if (obj) { /* Find the callBack method ID */ jstring jstr = env->NewStringUTF(streamToken.c_str()); jclass interfaceClass = env->GetObjectClass(obj); jmethodID method = env->GetMethodID(interfaceClass, "updateStreamToken", "(Ljava/lang/String;)V"); if (!method) { LOG("callback_handler: failed to get method ID (updateStreamToken)"); gJavaVM->DetachCurrentThread(); send = false; } if (send) { env->CallVoidMethod(obj, method,jstr); } gJavaVM->DetachCurrentThread(); } LOG("------------ Messages Sent----------------"); }
JNIEXPORT void JNICALL Java_org_apache_hadoop_mapred_JniTest_nativeMethod(JNIEnv *env, jobject obj) { printf("In C++ native method\n"); env->CallVoidMethod(obj, MID_JniTest_callback); printf("++++>>>>> In C++: calling Java static callback method, using Jni's GentEnv and cached class/method\n"); getJniEnv()->CallStaticVoidMethod((jclass)javaClass, MID_JniTest_staticCallback); }
void SFBool::getValue(jobject field, int bConstField) { assert(field); JNIEnv *jniEnv = getJniEnv(); jclass classid = bConstField ? getConstFieldID() : getFieldID(); jmethodID setValueMethod = bConstField ? getConstSetValueMethodID() : getSetValueMethodID(); assert(classid && setValueMethod); jboolean value = getValue(); jniEnv->CallVoidMethod(field, setValueMethod, value); }
void SFBool::setValue(jobject field, int bConstField) { assert(field); JNIEnv *jniEnv = getJniEnv(); jclass classid = bConstField ? getConstFieldID() : getFieldID(); jmethodID getValueMethod = bConstField ? getConstGetValueMethodID() : getGetValueMethodID(); assert(classid && getValueMethod); jboolean value = jniEnv->CallBooleanMethod(field, getValueMethod); setValue(value ? true : false); }
void SFVec3f::getValue(jobject field, int bConstField) { assert(field); JNIEnv *jniEnv = getJniEnv(); jclass classid = bConstField ? getConstFieldID() : getFieldID(); jmethodID setValueMethod = bConstField ? getConstSetValueMethodID() : getSetValueMethodID(); assert(classid && setValueMethod); jfloat x = getX(); jfloat y = getY(); jfloat z = getZ(); jniEnv->CallVoidMethod(field, setValueMethod, x, y, z); }
void sendMsgToJava(JNIEnv *env, char* msg) { if (env == NULL) { JNIEnv *envc = getJniEnv(); jstring str = (*envc)->NewStringUTF(envc, msg); (*envc)->CallVoidMethod(envc, mJavaFront, MethodOnMassage, str); (*envc)->DeleteLocalRef(envc, str); } else { jstring str = (*env)->NewStringUTF(env, msg); (*env)->CallVoidMethod(env, mJavaFront, MethodOnMassage, str); (*env)->DeleteLocalRef(env, str); } }
void SFVec3f::setValue(jobject field, int bConstField) { assert(field); JNIEnv *jniEnv = getJniEnv(); jclass classid = bConstField ? getConstFieldID() : getFieldID(); jmethodID getXMethod = bConstField ? getConstGetXMethodID() : getGetXMethodID(); jmethodID getYMethod = bConstField ? getConstGetYMethodID() : getGetYMethodID(); jmethodID getZMethod = bConstField ? getConstGetZMethodID() : getGetZMethodID(); assert(classid && getXMethod && getYMethod && getZMethod); jfloat x = jniEnv->CallFloatMethod(field, getXMethod); jfloat y = jniEnv->CallFloatMethod(field, getYMethod); jfloat z = jniEnv->CallFloatMethod(field, getZMethod); setValue(x, y, z); }
jobject SFBool::toJavaObject(int bConstField) { JNIEnv *jniEnv = getJniEnv(); jclass classid = bConstField ? getConstFieldID() : getFieldID(); jmethodID initMethod = bConstField ? getConstInitMethodID() : getInitMethodID(); jboolean value = getValue(); jobject eventField = jniEnv->NewObject(classid, initMethod, value); jmethodID setNameMethod = bConstField ? getConstSetNameMethodID() : getSetNameMethodID(); char *fieldName = getName(); jstring jfieldName = NULL; if (fieldName && strlen(fieldName)) jfieldName = jniEnv->NewStringUTF(getName()); jniEnv->CallVoidMethod(eventField, setNameMethod, jfieldName); if (jfieldName) jniEnv->DeleteLocalRef(jfieldName); return eventField; }
void MFInt32::setValue(jobject field, int bConstField) { assert(field); JNIEnv *jniEnv = getJniEnv(); jclass classid = bConstField ? getConstFieldID() : getFieldID(); jmethodID getSizeMethod = bConstField ? getConstGetSizeMethodID() : getGetSizeMethodID(); jmethodID getValueMethod = bConstField ? getConstGet1ValueMethodID() : getGet1ValueMethodID(); assert(classid && getValueMethod); jint jsize = jniEnv->CallIntMethod(field, getSizeMethod); int size = getSize(); for (int n=0; n<jsize; n++) { jint value = jniEnv->CallIntMethod(field, getValueMethod, n); if (n < size) set1Value(0, value); else addValue(value); } }
jobject SFVec3f::toJavaObject(int bConstField) { JNIEnv *jniEnv = getJniEnv(); jclass classid = bConstField ? getConstFieldID() : getFieldID(); jmethodID initMethod = bConstField ? getConstInitMethodID() : getInitMethodID(); jfloat x = getX(); jfloat y = getY(); jfloat z = getZ(); jobject eventField = jniEnv->NewObject(classid, initMethod, x, y, z); jmethodID setNameMethod = bConstField ? getConstSetNameMethodID() : getSetNameMethodID(); char *fieldName = getName(); jstring jfieldName = NULL; if (fieldName && strlen(fieldName)) jfieldName = jniEnv->NewStringUTF(getName()); jniEnv->CallVoidMethod(eventField, setNameMethod, jfieldName); if (jfieldName) jniEnv->DeleteLocalRef(jfieldName); return eventField; }
void sendByteArrayToJava(JNIEnv *env, void* msg) { if (env == NULL) { JNIEnv *envc = getJniEnv(); jcharArray bytearrayBuffer = (*envc)->NewCharArray(envc, 640 * 480); // construct a new byte array (*env)->SetCharArrayRegion(env, bytearrayBuffer, 0, 640 * 480, (jchar*) msg); // copies the region of length nBytes starting from 0 from the char array to the new byte array (*envc)->CallVoidMethod(envc, mJavaFront, MethodOnMassageByte, bytearrayBuffer); (*envc)->DeleteLocalRef(envc, bytearrayBuffer); } else { jcharArray bytearrayBuffer = (*env)->NewCharArray(env, 640 * 480); // construct a new byte array (*env)->SetCharArrayRegion(env, bytearrayBuffer, 0, 640 * 480, (jchar*) msg); // copies the region of length nBytes starting from 0 from the char array to the new byte array (*env)->CallVoidMethod(env, mJavaFront, MethodOnMassageByte, bytearrayBuffer); (*env)->DeleteLocalRef(env, bytearrayBuffer); } }
void NativeCallListener::sendTime(int time) { JNIEnv* jniEnv = getJniEnv(); jniEnv->CallIntMethod(mObjectRef, sendTimeID, time); }
void NativeCallListener::sendLog(jobject log) { JNIEnv* jniEnv = getJniEnv(); jniEnv->CallIntMethod(mObjectRef, sendLogID, log); }
void MFInt32::setJavaIDs() { if (!mInit) { JNIEnv *jniEnv = getJniEnv(); if (jniEnv == NULL) return; // Class IDs mFieldClassID = jniEnv->FindClass("vrml/field/MFInt32"); mConstFieldClassID = jniEnv->FindClass("vrml/field/ConstMFInt32"); assert(mFieldClassID && mConstFieldClassID); // MethodIDs jclass classid = getFieldID(); mInitMethodID = jniEnv->GetMethodID(classid, "<init>", "()V"); mGetSizeMethodID = jniEnv->GetMethodID(classid, "getSize", "()I"); mClearMethodID = jniEnv->GetMethodID(classid, "clear", "()V"); mDeleteMethodID = jniEnv->GetMethodID(classid, "delete", "(I)V"); mAddValueMethodID = jniEnv->GetMethodID(classid, "addValue", "(I)V"); mInsertValueMethodID = jniEnv->GetMethodID(classid, "insertValue", "(II)V"); mSet1ValueMethodID = jniEnv->GetMethodID(classid, "set1Value", "(II)V"); mGet1ValueMethodID = jniEnv->GetMethodID(classid, "get1Value", "(I)I"); mSetNameMethodID = jniEnv->GetMethodID(classid, "setName", "(Ljava/lang/String;)V"); assert(mInitMethodID); assert(mGetSizeMethodID); assert(mClearMethodID); assert(mDeleteMethodID); assert(mAddValueMethodID); assert(mInsertValueMethodID); assert(mSet1ValueMethodID); assert(mGet1ValueMethodID); assert(mSetNameMethodID); // Const MethodIDs classid = getConstFieldID(); mConstInitMethodID = jniEnv->GetMethodID(classid, "<init>", "()V"); mConstGetSizeMethodID = jniEnv->GetMethodID(classid, "getSize", "()I"); mConstClearMethodID = jniEnv->GetMethodID(classid, "clear", "()V"); mConstDeleteMethodID = jniEnv->GetMethodID(classid, "delete", "(I)V"); mConstAddValueMethodID = jniEnv->GetMethodID(classid, "addValue", "(I)V"); mConstInsertValueMethodID = jniEnv->GetMethodID(classid, "insertValue", "(II)V"); mConstSet1ValueMethodID = jniEnv->GetMethodID(classid, "set1Value", "(II)V"); mConstGet1ValueMethodID = jniEnv->GetMethodID(classid, "get1Value", "(I)I"); mConstSetNameMethodID = jniEnv->GetMethodID(classid, "setName", "(Ljava/lang/String;)V"); assert(mConstInitMethodID); assert(mConstGetSizeMethodID); assert(mConstClearMethodID); assert(mConstDeleteMethodID); assert(mConstAddValueMethodID); assert(mConstInsertValueMethodID); assert(mConstSet1ValueMethodID); assert(mConstGet1ValueMethodID); assert(mConstSetNameMethodID); assert(mConstInitMethodID && mConstSetNameMethodID); mInit = 1; } }