当前位置: 首页>>代码示例>>C++>>正文


C++ JavaVM::DetachCurrentThread方法代码示例

本文整理汇总了C++中JavaVM::DetachCurrentThread方法的典型用法代码示例。如果您正苦于以下问题:C++ JavaVM::DetachCurrentThread方法的具体用法?C++ JavaVM::DetachCurrentThread怎么用?C++ JavaVM::DetachCurrentThread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JavaVM的用法示例。


在下文中一共展示了JavaVM::DetachCurrentThread方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: frameworkMessage

void JNIExecutor::frameworkMessage(ExecutorDriver* driver, const string& data)
{
  jvm->AttachCurrentThread((void**) &env, NULL);

  jclass clazz = env->GetObjectClass(jdriver);

  jfieldID exec = env->GetFieldID(clazz, "exec", "Lorg/apache/mesos/Executor;");
  jobject jexec = env->GetObjectField(jdriver, exec);

  clazz = env->GetObjectClass(jexec);

  // exec.frameworkMessage(driver, data);
  jmethodID frameworkMessage =
    env->GetMethodID(clazz, "frameworkMessage",
		     "(Lorg/apache/mesos/ExecutorDriver;"
		     "[B)V");

  // byte[] data = ..;
  jbyteArray jdata = env->NewByteArray(data.size());
  env->SetByteArrayRegion(jdata, 0, data.size(), (jbyte*) data.data());

  env->ExceptionClear();

  env->CallVoidMethod(jexec, frameworkMessage, jdriver, jdata);

  if (env->ExceptionOccurred()) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    jvm->DetachCurrentThread();
    driver->stop();
    this->error(driver, -1, "Java exception caught");
    return;
  }

  jvm->DetachCurrentThread();
}
开发者ID:viirya,项目名称:mesos,代码行数:36,代码来源:org_apache_mesos_MesosExecutorDriver.cpp

示例2: DetachFromJVM

void Thread::DetachFromJVM()
{
    if (true == IsMainThread())
        return;

    DAVA::CorePlatformAndroid *core = (DAVA::CorePlatformAndroid *)DAVA::Core::Instance();
    DAVA::AndroidSystemDelegate* delegate = core->GetAndroidSystemDelegate();
    JavaVM *vm = delegate->GetVM();
    JNIEnv *env;

    if (JNI_OK == vm->GetEnv((void**)&env, JNI_VERSION_1_6))
    {
        if (0 != vm->DetachCurrentThread())
            Logger::Error("runtime_error(Could not detach current thread from JNI)");
    }
}
开发者ID:galek,项目名称:dava.framework,代码行数:16,代码来源:ThreadAndroid.cpp

示例3: callVoidJavaMethod

void callVoidJavaMethod(const char* javaMethodName, string param){
	ANativeActivity* activity = NULL; JavaVM* jvm = NULL; JNIEnv* env = NULL;	
	if(prepareForCallJavaMethod(&activity, &jvm, &env)){
		jclass clazz = env->GetObjectClass(activity->clazz);
		jmethodID methodID = env->GetMethodID(clazz, javaMethodName, "(Ljava/lang/String;)V");
		jstring jStringParam = env->NewStringUTF( param.c_str() );
		if( !jStringParam )
		{ 
			__android_log_print(ANDROID_LOG_ERROR, "MainNativeActivity#callJavaMethod", "Fallo al pasar string de ndk a java");
			return;
		}
		env->CallVoidMethod(activity->clazz, methodID, jStringParam);
		env->DeleteLocalRef( jStringParam );
		jvm->DetachCurrentThread();
	}
}
开发者ID:MarcoLotto,项目名称:ScaenaFramework,代码行数:16,代码来源:NativeActivityJavaConnector.cpp

示例4:

    ~msandroid_sound_write_data() {
        ms_bufferizer_flush(bufferizer);
        ms_bufferizer_destroy(bufferizer);
        ms_cond_destroy(&cond);
        if (audio_track_class!=0) {
            //JNIEnv *env = ms_get_jni_env();

            JNIEnv *env = NULL;
            JavaVM *jvm = ms_get_jvm();
            if (jvm->AttachCurrentThread(&env, NULL)!=0) {
                ms_fatal("AttachCurrentThread() failed !");
            }
            env->DeleteGlobalRef(audio_track_class);
            jvm->DetachCurrentThread();
        }
    }
开发者ID:fremaks,项目名称:linphone_sdk,代码行数:16,代码来源:androidsound_depr.cpp

示例5: dx_uio_read

/**
 * Used for user supplied input/output functions.  See initDxClass();
 */
int dx_uio_read (int fd, char* ptr, unsigned cnt) {
	JavaVM *vm = jvr_getVM();
	JNIEnv *e;
	int detach = 0;
	if (vm->GetEnv((void **)&e, JNI_VERSION_1_2) != JNI_OK) {
		vm->AttachCurrentThread((void**)&e,&attachArgs);
		detach = 1;
	}
	if (e->ExceptionOccurred()) {
		e->ExceptionDescribe();
		e->ExceptionClear();
		return -1;
	}

  jcharArray charArray = (jcharArray) e->CallStaticObjectMethod(dx_class, dx_uio_read_method, (jint) fd, (jint) cnt);
	if (e->ExceptionOccurred()) {
		e->ExceptionDescribe();
		e->ExceptionClear();
		if (detach) { vm->DetachCurrentThread(); }
		return -1;
	}
	if (charArray == NULL) {
		// EOF
		if (detach) { vm->DetachCurrentThread(); }
		return -1;
	}

	int buflen = e->GetArrayLength(charArray);
	if (e->ExceptionOccurred()) {
		e->ExceptionDescribe();
		e->ExceptionClear();
		if (detach) { vm->DetachCurrentThread(); }
		return -1;
	}
	if (buflen == 0) {
		// EOF aka no data
		if (detach) { vm->DetachCurrentThread(); }
		return -1;
	}

	jchar* bufp = (jchar*) e->GetCharArrayElements(charArray,0);
	if (e->ExceptionOccurred()) {
		e->ExceptionDescribe();
		e->ExceptionClear();
		if (detach) { vm->DetachCurrentThread(); }
		return -1;
	}

	memcpy(ptr,bufp,buflen);
	e->ReleaseCharArrayElements(charArray, bufp, JNI_ABORT);
	e->DeleteLocalRef(charArray);
	if (detach) { vm->DetachCurrentThread(); }
	return buflen;
}
开发者ID:kevinodotnet,项目名称:jvr,代码行数:57,代码来源:dx.cpp

示例6: report_exception

static void report_exception(JNIEnv* env, jthrowable excep, const char* msg)
{
    env->ExceptionClear();

    jstring tagstr = env->NewStringUTF(LOG_TAG);
    jstring msgstr = env->NewStringUTF(msg);

    if ((tagstr == NULL) || (msgstr == NULL)) {
        env->ExceptionClear();      /* assume exception (OOM?) was thrown */
        ALOGE("Unable to call Log.e()\n");
        ALOGE("%s", msg);
        goto bail;
    }

    env->CallStaticIntMethod(
        gLogOffsets.mClass, gLogOffsets.mLogE, tagstr, msgstr, excep);
    if (env->ExceptionCheck()) {
        /* attempting to log the failure has failed */
        ALOGW("Failed trying to log exception, msg='%s'\n", msg);
        env->ExceptionClear();
    }

    if (env->IsInstanceOf(excep, gErrorOffsets.mClass)) {
        /*
         * It's an Error: Reraise the exception, detach this thread, and
         * wait for the fireworks. Die even more blatantly after a minute
         * if the gentler attempt doesn't do the trick.
         *
         * The GetJavaVM function isn't on the "approved" list of JNI calls
         * that can be made while an exception is pending, so we want to
         * get the VM ptr, throw the exception, and then detach the thread.
         */
        JavaVM* vm = jnienv_to_javavm(env);
        env->Throw(excep);
        vm->DetachCurrentThread();
        sleep(60);
        ALOGE("Forcefully exiting");
        exit(1);
        *((int *) 1) = 1;
    }

bail:
    /* discard local refs created for us by VM */
    env->DeleteLocalRef(tagstr);
    env->DeleteLocalRef(msgstr);
}
开发者ID:Blakez,项目名称:android_frameworks_base,代码行数:46,代码来源:android_util_Binder.cpp

示例7: hal_notify_callback

// Called by the HAL to notify us of fingerprint events
static void hal_notify_callback(fingerprint_msg_t msg) {
    uint32_t arg1 = 0;
    uint32_t arg2 = 0;
    uint32_t arg3 = 0; // TODO
    switch (msg.type) {
        case FINGERPRINT_ERROR:
            arg1 = msg.data.error;
            break;
        case FINGERPRINT_ACQUIRED:
            arg1 = msg.data.acquired.acquired_info;
            break;
        case FINGERPRINT_PROCESSED:
            arg1 = msg.data.processed.id;
            break;
        case FINGERPRINT_TEMPLATE_ENROLLING:
            arg1 = msg.data.enroll.id;
            arg2 = msg.data.enroll.samples_remaining;
            arg3 = msg.data.enroll.data_collected_bmp;
            break;
        case FINGERPRINT_TEMPLATE_REMOVED:
            arg1 = msg.data.removed.id;
            break;
        default:
            ALOGE("fingerprint: invalid msg: %d", msg.type);
            return;
    }
    //ALOG(LOG_VERBOSE, LOG_TAG, "hal_notify(msg=%d, arg1=%d, arg2=%d)\n", msg.type, arg1, arg2);

	// TODO: fix gross hack to attach JNI to calling thread
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JavaVM* vm = NULL;
    if (env == NULL) {
        JavaVMAttachArgs args = {JNI_VERSION_1_4, NULL, NULL};
        vm = AndroidRuntime::getJavaVM();
        int result = vm->AttachCurrentThread(&env, (void*) &args);
        if (result != JNI_OK) {
            ALOGE("Can't call JNI method: attach failed: %#x", result);
            return;
        }
    }
    env->CallVoidMethod(gFingerprintServiceClassInfo.callbackObject,
            gFingerprintServiceClassInfo.notify, msg.type, arg1, arg2);
    if (vm != NULL) {
        vm->DetachCurrentThread();
    }
}
开发者ID:thuutin,项目名称:android_frameworks_base,代码行数:47,代码来源:android_server_FingerprintManager.cpp

示例8: performCallback

int32_t SpiReadAutoReceiveBufferCallbackStore::performCallback(
    const char* name, uint32_t* buffer, int32_t numToRead) {
  JNIEnv* env;
  JavaVM* vm = sim::GetJVM();
  bool didAttachThread = false;
  int tryGetEnv = vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
  if (tryGetEnv == JNI_EDETACHED) {
    // Thread not attached
    didAttachThread = true;
    if (vm->AttachCurrentThread(reinterpret_cast<void**>(&env), nullptr) != 0) {
      // Failed to attach, log and return
      wpi::outs() << "Failed to attach\n";
      wpi::outs().flush();
      return -1;
    }
  } else if (tryGetEnv == JNI_EVERSION) {
    wpi::outs() << "Invalid JVM Version requested\n";
    wpi::outs().flush();
  }

  auto toCallbackArr = MakeJIntArray(
      env, wpi::ArrayRef<uint32_t>{buffer, static_cast<size_t>(numToRead)});

  jint ret = env->CallIntMethod(m_call, sim::GetBufferCallback(),
                                MakeJString(env, name), toCallbackArr,
                                (jint)numToRead);

  jint* fromCallbackArr = reinterpret_cast<jint*>(
      env->GetPrimitiveArrayCritical(toCallbackArr, nullptr));

  for (int i = 0; i < ret; i++) {
    buffer[i] = fromCallbackArr[i];
  }

  env->ReleasePrimitiveArrayCritical(toCallbackArr, fromCallbackArr, JNI_ABORT);

  if (env->ExceptionCheck()) {
    env->ExceptionDescribe();
  }

  if (didAttachThread) {
    vm->DetachCurrentThread();
  }
  return ret;
}
开发者ID:AustinShalit,项目名称:allwpilib,代码行数:45,代码来源:SpiReadAutoReceiveBufferCallbackStore.cpp

示例9: callback_thread_event

static void callback_thread_event(bt_cb_thread_evt event) {
    JavaVM* vm = AndroidRuntime::getJavaVM();
    if (event  == ASSOCIATE_JVM) {
        JavaVMAttachArgs args;
        char name[] = "BT Service Callback Thread";
        args.version = JNI_VERSION_1_6;
        args.name = name;
        args.group = NULL;
        vm->AttachCurrentThread(&callbackEnv, &args);
        ALOGV("Callback thread attached: %p", callbackEnv);
    } else if (event == DISASSOCIATE_JVM) {
        if (!checkCallbackThread()) {
            ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);
            return;
        }
        vm->DetachCurrentThread();
    }
}
开发者ID:denisigo,项目名称:fireprime_packages_apps_Bluetooth,代码行数:18,代码来源:com_android_bluetooth_btservice_AdapterService.cpp

示例10: callStringJavaMethod

string callStringJavaMethod(const char* javaMethodName, string param){
	ANativeActivity* activity = NULL; JavaVM* jvm = NULL; JNIEnv* env = NULL;	
	string result;
	if(prepareForCallJavaMethod(&activity, &jvm, &env)){
		jclass clazz = env->GetObjectClass(activity->clazz);
		jmethodID methodID = env->GetMethodID(clazz, javaMethodName, "(Ljava/lang/String;)Ljava/lang/String;");
		jstring jStringParam = env->NewStringUTF( param.c_str() );
		if( !jStringParam )
		{ 
			__android_log_print(ANDROID_LOG_ERROR, "NativeActivityConnector#callStringJavaMethod", "Fallo al pasar string de ndk a java");
			return result;
		}
		jstring jresult = (jstring) env->CallObjectMethod(activity->clazz, methodID, jStringParam);
		result = jstringToString(jresult, env);
		env->DeleteLocalRef( jStringParam );
		jvm->DetachCurrentThread();
	}
	return result;
}
开发者ID:MarcoLotto,项目名称:ScaenaFramework,代码行数:19,代码来源:NativeActivityJavaConnector.cpp

示例11: dx_uio_seek

/**
 * Used for user supplied input/output functions.  See initDxClass();
 */
long dx_uio_seek (int fd, long offset, int whence) {

	JavaVM *vm = jvr_getVM();
	JNIEnv *e;
	int detach = 0;
	if (vm->GetEnv((void **)&e, JNI_VERSION_1_2) != JNI_OK) {
		vm->AttachCurrentThread((void**)&e,&attachArgs);
		detach = 1;
	}
	if (e->ExceptionOccurred()) {
		e->ExceptionDescribe();
		e->ExceptionClear();
		return -1;
	}
	long ret = e->CallStaticLongMethod(dx_class,dx_uio_seek_method,(jint) fd,(jlong) offset,(jint) whence);
	if (detach) { vm->DetachCurrentThread(); }
	return ret;

}
开发者ID:kevinodotnet,项目名称:jvr,代码行数:22,代码来源:dx.cpp

示例12: backupStatus

/****************************************************************************
Desc:
****************************************************************************/
RCODE JNIBackupStatus::backupStatus(
	FLMUINT64		ui64BytesToDo,
	FLMUINT64		ui64BytesDone)
{
	RCODE				rc = NE_XFLM_OK;
	JNIEnv *			pEnv;
	jclass			Cls;
	jmethodID		MId;
	FLMBOOL			bMustDetach = FALSE;
	
	if (m_pJvm->GetEnv( (void **)&pEnv, JNI_VERSION_1_2) != JNI_OK)
	{
		if (m_pJvm->AttachCurrentThread( (void **)&pEnv, NULL) != 0)
		{
			rc = RC_SET(NE_XFLM_FAILURE);	
			goto Exit;
		}
		
		bMustDetach = TRUE;
	}

	Cls = pEnv->GetObjectClass( m_jStatus);
	MId = pEnv->GetMethodID( Cls, "backupStatus", "(JJ)I");
	flmAssert( MId);
		
	rc = (RCODE)pEnv->CallIntMethod( m_jStatus, MId, (jlong)ui64BytesToDo,
									 (jlong)ui64BytesDone);
									  
Exit:

	if (bMustDetach)
	{
		if (m_pJvm->DetachCurrentThread() != 0)
		{
			flmAssert( 0);
			rc = RC_SET( NE_XFLM_FAILURE);
		}
	}

	return( rc);
}
开发者ID:Tyrion-Lannister-274AL,项目名称:flaim,代码行数:44,代码来源:jbackup.cpp

示例13:

JniCallbackHelper::~JniCallbackHelper() {

	if (mMethodId != 0) {
		if (mEnv->ExceptionCheck()) {
			JNI_HELPER_LOGE(
					"There was an exception thrown from the Java method!!");
			mEnv->ExceptionClear();
		}
	}
	for (std::vector<jobject>::iterator it = mNewJavaObjects.begin();
			it != mNewJavaObjects.end(); ++it) {
		mEnv->DeleteLocalRef(*it);
	}

	mEnv->DeleteGlobalRef(mJObject);

	if (JNI_EDETACHED == mGetEnvResult) {
		JavaVM * vm;
		mEnv->GetJavaVM(&vm);
		vm->DetachCurrentThread();
	}
}
开发者ID:menny,项目名称:JniUtils,代码行数:22,代码来源:JniCallbackHelper.cpp

示例14: onLeaveInternalPeriodicCaptureThread

void OpenSLMediaPlayerHQVisualizerJNIBinder::onLeaveInternalPeriodicCaptureThread(
    OpenSLMediaPlayerHQVisualizer *visualizer) noexcept
{
    LOGD("onLeaveInternalPeriodicCaptureThread()");

    JavaVM *vm = jvm_;

    if (jvm_attached_) {
        // release global references
        for (auto &t : jwaveform_data_) {
            t.release(env_);
        }
        for (auto &t : jfft_data_) {
            t.release(env_);
        }

        // detach
        (void)vm->DetachCurrentThread();
        jvm_attached_ = false;
    }
    env_ = nullptr;
}
开发者ID:HKingz,项目名称:android-openslmediaplayer,代码行数:22,代码来源:OpenSLMediaPlayerHQVisualizerJNIBinder.cpp

示例15: closeKeyboardIME

int closeKeyboardIME()
{
    ANativeActivity *activity = sf::getNativeActivity();
    JavaVM* vm = activity->vm;
    JNIEnv* env = activity->env;
    JavaVMAttachArgs attachargs;
    attachargs.version = JNI_VERSION_1_6;
    attachargs.name = "NativeThread";
    attachargs.group = NULL;
    jint res = vm->AttachCurrentThread(&env, &attachargs);
    if (res == JNI_ERR)
        return EXIT_FAILURE;

    jclass natact = env->FindClass("android/app/NativeActivity");
    jclass context = env->FindClass("android/content/Context");

    jfieldID fid = env->GetStaticFieldID(context, "INPUT_METHOD_SERVICE", "Ljava/lang/String;");
    jobject svcstr = env->GetStaticObjectField(context, fid);


    jmethodID getss = env->GetMethodID(natact, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
    jobject imm_obj = env->CallObjectMethod(activity->clazz, getss, svcstr);

    jclass imm_cls = env->GetObjectClass(imm_obj);
    jmethodID toggleSoftInput = env->GetMethodID(imm_cls, "toggleSoftInput", "(II)V");

    env->CallVoidMethod(imm_obj, toggleSoftInput, 1, 0);

    env->DeleteLocalRef(imm_obj);
    env->DeleteLocalRef(imm_cls);
    env->DeleteLocalRef(svcstr);
    env->DeleteLocalRef(context);
    env->DeleteLocalRef(natact);

    vm->DetachCurrentThread();

    return EXIT_SUCCESS;
}
开发者ID:eliasdaler,项目名称:imgui-sfml,代码行数:38,代码来源:imgui-SFML.cpp


注:本文中的JavaVM::DetachCurrentThread方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。