Beispiel #1
0
CAResult_t CAIPJniInit()
{
    OIC_LOG(DEBUG, IP_MONITOR_TAG, "IN");

    OIC_LOG(DEBUG, IP_MONITOR_TAG, "CAIPJniInit");
    g_jvm = CANativeJNIGetJavaVM();

    if (!g_jvm)
    {
        OIC_LOG(ERROR, IP_MONITOR_TAG, "JNI initialize error");
        return CA_STATUS_FAILED;
    }

    OIC_LOG(DEBUG, IP_MONITOR_TAG, "OUT");
    return CA_STATUS_OK;
}
Beispiel #2
0
static CAResult_t CAIPDestroyJniInterface()
{
    OIC_LOG(DEBUG, TAG, "CAIPDestroyJniInterface");

    JavaVM *jvm = CANativeJNIGetJavaVM();
    if (!jvm)
    {
        OIC_LOG(ERROR, TAG, "Could not get JavaVM pointer");
        return CA_STATUS_FAILED;
    }

    bool isAttached = false;
    JNIEnv* env;
    jint res = (*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION_1_6);
    if (JNI_OK != res)
    {
        OIC_LOG(INFO, TAG, "Could not get JNIEnv pointer");
        res = (*jvm)->AttachCurrentThread(jvm, &env, NULL);

        if (JNI_OK != res)
        {
            OIC_LOG(ERROR, TAG, "AttachCurrentThread has failed");
            return CA_STATUS_FAILED;
        }
        isAttached = true;
    }

    jclass jni_IpInterface = (*env)->FindClass(env, "org/iotivity/ca/CaIpInterface");
    if (!jni_IpInterface)
    {
        OIC_LOG(ERROR, TAG, "Could not get CaIpInterface class");
        goto error_exit;
    }

    jmethodID jni_InterfaceDestroyMethod = (*env)->GetStaticMethodID(env, jni_IpInterface,
                                                                     "destroyIpInterface",
                                                                     "()V");
    if (!jni_InterfaceDestroyMethod)
    {
        OIC_LOG(ERROR, TAG, "Could not get CaIpInterface destroy method");
        goto error_exit;
    }

    (*env)->CallStaticVoidMethod(env, jni_IpInterface, jni_InterfaceDestroyMethod);

    if ((*env)->ExceptionCheck(env))
    {
        OIC_LOG(ERROR, TAG, "destroyIpInterface has failed");
        (*env)->ExceptionDescribe(env);
        (*env)->ExceptionClear(env);
        goto error_exit;
    }

    OIC_LOG(DEBUG, TAG, "Destroy instance for CaIpInterface");

    if (isAttached)
    {
        (*jvm)->DetachCurrentThread(jvm);
    }

    return CA_STATUS_OK;

error_exit:

    if (isAttached)
    {
        (*jvm)->DetachCurrentThread(jvm);
    }

    return CA_STATUS_FAILED;
}
Beispiel #3
0
CAResult_t CAIPJniInit()
{
    OIC_LOG(DEBUG, TAG, "CAIPJniInit_IN");

    JavaVM *jvm = CANativeJNIGetJavaVM();
    if (!jvm)
    {
        OIC_LOG(ERROR, TAG, "Could not get JavaVM pointer");
        return CA_STATUS_FAILED;
    }

    jobject context = CANativeJNIGetContext();
    if (!context)
    {
        OIC_LOG(ERROR, TAG, "unable to get application context");
        return CA_STATUS_FAILED;
    }

    JNIEnv* env;
    if ((*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION_1_6) != JNI_OK)
    {
        OIC_LOG(ERROR, TAG, "Could not get JNIEnv pointer");
        return CA_STATUS_FAILED;
    }

    jmethodID mid_getApplicationContext = CAGetJNIMethodID(env, "android/content/Context",
                                                           "getApplicationContext",
                                                           "()Landroid/content/Context;");

    if (!mid_getApplicationContext)
    {
        OIC_LOG(ERROR, TAG, "Could not get getApplicationContext method");
        return CA_STATUS_FAILED;
    }

    jobject jApplicationContext = (*env)->CallObjectMethod(env, context,
                                                           mid_getApplicationContext);
    if (!jApplicationContext)
    {
        OIC_LOG(ERROR, TAG, "Could not get application context");
        return CA_STATUS_FAILED;
    }

    jclass cls_CaIpInterface = (*env)->FindClass(env, "org/iotivity/ca/CaIpInterface");
    if (!cls_CaIpInterface)
    {
        OIC_LOG(ERROR, TAG, "Could not get CaIpInterface class");
        return CA_STATUS_FAILED;
    }

    jmethodID mid_CaIpInterface_ctor = (*env)->GetMethodID(env, cls_CaIpInterface, "<init>",
                                                                   "(Landroid/content/Context;)V");
    if (!mid_CaIpInterface_ctor)
    {
        OIC_LOG(ERROR, TAG, "Could not get CaIpInterface constructor method");
        return CA_STATUS_FAILED;
    }

    (*env)->NewObject(env, cls_CaIpInterface, mid_CaIpInterface_ctor, jApplicationContext);
    OIC_LOG(DEBUG, TAG, "Create CaIpInterface instance, success");

    OIC_LOG(DEBUG, TAG, "CAIPJniInit_OUT");
    return CA_STATUS_OK;
}
Beispiel #4
0
void CAEDRServerJniInit()
{
    OIC_LOG(DEBUG, TAG, "CAEDRServerJniInit");
    g_jvm = CANativeJNIGetJavaVM();
}
Beispiel #5
0
//getting jvm
void CALENetworkMonitorJniInit()
{
    OIC_LOG(DEBUG, TAG, "CALENetworkMonitorJniInit");
    g_jvm = CANativeJNIGetJavaVM();
}
Beispiel #6
0
void CAEDRCoreJniInit()
{
    OIC_LOG(DEBUG, TAG, "CAEdrClientJniInit");
    g_jvm = (JavaVM*) CANativeJNIGetJavaVM();
}
static void CANfcJniInit()
{
    OIC_LOG(DEBUG, TAG, "CANfcJniInit");
    g_jvm = (JavaVM*) CANativeJNIGetJavaVM();
}