示例#1
0
/* Execute a callback to the associated Java peer. */
void
AwtObject::DoCallback(const char* methodName, const char* methodSig, ...)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

    /* don't callback during the create & initialization process */
    if (m_peerObject != NULL && m_callbacksEnabled) {
        va_list args;
        va_start(args, methodSig);
#ifdef DEBUG
        if (reportEvents) {
            jstring targetStr =
                (jstring)JNU_CallMethodByName(env, NULL, GetTarget(env),
                                              "getName",
                                              "()Ljava/lang/String;").l;
            DASSERT(!safe_ExceptionOccurred(env));
            printf("Posting %s%s method to %S\n", methodName, methodSig,
                   TO_WSTRING(targetStr));
        }
#endif
        /* caching would do much good here */
        JNU_CallMethodByNameV(env, NULL, GetPeer(env),
                              methodName, methodSig, args);
        {
            jthrowable exc = safe_ExceptionOccurred(env);
            if (exc) {
                env->DeleteLocalRef(exc);
                env->ExceptionDescribe();
                env->ExceptionClear();
            }
        }
        DASSERT(!safe_ExceptionOccurred(env));
        va_end(args);
    }
}
示例#2
0
JNIEXPORT jvalue JNICALL
JNU_CallMethodByName(JNIEnv *env,
                     jboolean *hasException,
                     jobject obj,
                     const char *name,
                     const char *signature,
                     ...)
{
    jvalue result;
    va_list args;

    va_start(args, signature);
    result = JNU_CallMethodByNameV(env, hasException, obj, name, signature,
                                   args);
    va_end(args);

    return result;
}