本文整理汇总了C++中JavaVM::AttachCurrentThread方法的典型用法代码示例。如果您正苦于以下问题:C++ JavaVM::AttachCurrentThread方法的具体用法?C++ JavaVM::AttachCurrentThread怎么用?C++ JavaVM::AttachCurrentThread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JavaVM
的用法示例。
在下文中一共展示了JavaVM::AttachCurrentThread方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
void JNIExecutor::init(ExecutorDriver* driver, const ExecutorArgs& args)
{
jvm->AttachCurrentThread((void **) &env, NULL);
jclass clazz = env->GetObjectClass(jdriver);
jfieldID exec = env->GetFieldID(clazz, "exec", "Lmesos/Executor;");
jobject jexec = env->GetObjectField(jdriver, exec);
clazz = env->GetObjectClass(jexec);
// exec.init(driver);
jmethodID init =
env->GetMethodID(clazz, "init", "(Lmesos/ExecutorDriver;Lmesos/ExecutorArgs;)V");
jobject jargs = convert<ExecutorArgs>(env, args);
env->ExceptionClear();
env->CallVoidMethod(jexec, init, jdriver, jargs);
if (!env->ExceptionOccurred()) {
jvm->DetachCurrentThread();
} else {
env->ExceptionDescribe();
env->ExceptionClear();
jvm->DetachCurrentThread();
driver->stop();
this->error(driver, -1, "Java exception caught");
}
}
示例2: Create
INT CLcxSndJni::Create(LC_HANDLE p1, LC_HANDLE p2, LC_HANDLE p3, LC_HANDLE p4)
{
char* name = (char*)p1;
int fd = -1;
#if defined(__ANDROID__)
JNIEnv* pEnv = NULL;
JavaVM* pJvm = LCSYS::g_pJavaVM;
jclass clzz = LCSYS::g_JniClzz;
if(NULL == pJvm || 0 > pJvm->AttachCurrentThread(&pEnv, NULL))
{
LOGE("SndJni::Create::Err::AttachCurrentThread::Create\n");
return LC_EFAIL;
}
fd = pEnv->CallStaticIntMethod(clzz, Jni_SndCreate, pEnv->NewStringUTF(name));
#endif
if(0>fd)
return LC_EFAIL;
strcpy(m_name, name);
m_fd = fd;
return LC_OK;
}
示例3: set_wake_alarm_callout
static bool set_wake_alarm_callout(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data) {
JNIEnv *env;
JavaVM *vm = AndroidRuntime::getJavaVM();
jint status = vm->GetEnv((void **)&env, JNI_VERSION_1_6);
if (status != JNI_OK && status != JNI_EDETACHED) {
ALOGE("%s unable to get environment for JNI call", __func__);
return false;
}
if (status == JNI_EDETACHED && vm->AttachCurrentThread(&env, &sAttachArgs) != 0) {
ALOGE("%s unable to attach thread to VM", __func__);
return false;
}
sAlarmCallback = cb;
sAlarmCallbackData = data;
jboolean jshould_wake = should_wake ? JNI_TRUE : JNI_FALSE;
jboolean ret = env->CallBooleanMethod(sJniAdapterServiceObj, method_setWakeAlarm, (jlong)delay_millis, jshould_wake);
if (!ret) {
sAlarmCallback = NULL;
sAlarmCallbackData = NULL;
}
if (status == JNI_EDETACHED) {
vm->DetachCurrentThread();
}
return !!ret;
}
开发者ID:denisigo,项目名称:fireprime_packages_apps_Bluetooth,代码行数:31,代码来源:com_android_bluetooth_btservice_AdapterService.cpp
示例4: initAndroid
void initAndroid()
{
porting::jnienv = NULL;
JavaVM *jvm = app_global->activity->vm;
JavaVMAttachArgs lJavaVMAttachArgs;
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
lJavaVMAttachArgs.name = "MinetestNativeThread";
lJavaVMAttachArgs.group = NULL;
#ifdef NDEBUG
// This is a ugly hack as arm v7a non debuggable builds crash without this
// printf ... if someone finds out why please fix it!
infostream << "Attaching native thread. " << std::endl;
#endif
if ( jvm->AttachCurrentThread(&porting::jnienv, &lJavaVMAttachArgs) == JNI_ERR) {
errorstream << "Failed to attach native thread to jvm" << std::endl;
exit(-1);
}
nativeActivity = findClass("net/minetest/minetest/MtNativeActivity");
if (nativeActivity == 0) {
errorstream <<
"porting::initAndroid unable to find java native activity class" <<
std::endl;
}
#ifdef GPROF
/* in the start-up code */
__android_log_print(ANDROID_LOG_ERROR, PROJECT_NAME,
"Initializing GPROF profiler");
monstartup("libminetest.so");
#endif
}
示例5: disconnected
void JNIScheduler::disconnected(SchedulerDriver* driver)
{
jvm->AttachCurrentThread(JNIENV_CAST(&env), NULL);
jclass clazz = env->GetObjectClass(jdriver);
jfieldID scheduler = env->GetFieldID(clazz, "scheduler", "Lorg/apache/mesos/Scheduler;");
jobject jscheduler = env->GetObjectField(jdriver, scheduler);
clazz = env->GetObjectClass(jscheduler);
// scheduler.disconnected(driver);
jmethodID disconnected =
env->GetMethodID(clazz, "disconnected",
"(Lorg/apache/mesos/SchedulerDriver;)V");
env->ExceptionClear();
env->CallVoidMethod(jscheduler, disconnected, jdriver);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
jvm->DetachCurrentThread();
driver->abort();
return;
}
jvm->DetachCurrentThread();
}
示例6: sound_read_preprocess
static void sound_read_preprocess(MSFilter *f) {
msandroid_sound_read_data *d=(msandroid_sound_read_data*)f->data;
ms_debug("andsnd_read_preprocess");
if (!d->started)
sound_read_setup(f);
ms_ticker_set_time_func(f->ticker,(uint64_t (*)(void*))ms_ticker_synchronizer_get_corrected_time, d->ticker_synchronizer);
if (d->builtin_aec && d->audio_record) {
//JNIEnv *env=ms_get_jni_env();
JNIEnv *env = NULL;
JavaVM *jvm = ms_get_jvm();
if (jvm->AttachCurrentThread(&env, NULL)!=0) {
ms_fatal("AttachCurrentThread() failed !");
return;
}
jmethodID getsession_id=0;
int sessionId=-1;
getsession_id = env->GetMethodID(d->audio_record_class,"getAudioSessionId", "()I");
if(getsession_id==0) {
ms_error("cannot find AudioRecord.getAudioSessionId() method");
jvm->DetachCurrentThread();
return;
}
sessionId = env->CallIntMethod(d->audio_record,getsession_id);
ms_message("AudioRecord.getAudioSessionId() returned %i", sessionId);
if (sessionId==-1) {
jvm->DetachCurrentThread();
return;
}
d->aec = enable_hardware_echo_canceller(env, sessionId);
jvm->DetachCurrentThread();
}
}
示例7: msandroid_sound_write_preprocess
void msandroid_sound_write_preprocess(MSFilter *f) {
ms_debug("andsnd_write_preprocess");
msandroid_sound_write_data *d=(msandroid_sound_write_data*)f->data;
jmethodID constructor_id=0;
int rc;
jmethodID min_buff_size_id;
//JNIEnv *jni_env = ms_get_jni_env();
JNIEnv *jni_env = NULL;
JavaVM *jvm = ms_get_jvm();
if (jvm->AttachCurrentThread(&jni_env, NULL)!=0) {
ms_fatal("AttachCurrentThread() failed !");
return;
}
if (d->audio_track_class == 0) {
jvm->DetachCurrentThread();
return;
}
constructor_id = jni_env->GetMethodID(d->audio_track_class,"<init>", "(IIIIII)V");
if (constructor_id == 0) {
ms_error("cannot find AudioTrack(int streamType, int sampleRateInHz, \
int channelConfig, int audioFormat, int bufferSizeInBytes, int mode)");
jvm->DetachCurrentThread();
return;
}
示例8: shutdown
void JNIExecutor::shutdown(ExecutorDriver* driver)
{
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.shutdown(driver);
jmethodID shutdown =
env->GetMethodID(clazz, "shutdown",
"(Lorg/apache/mesos/ExecutorDriver;)V");
env->ExceptionClear();
env->CallVoidMethod(jexec, shutdown, jdriver);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
jvm->DetachCurrentThread();
driver->abort();
return;
}
jvm->DetachCurrentThread();
}
示例9: error
void JNIExecutor::error(ExecutorDriver* driver, int code, const string& message)
{
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.error(driver, code, message);
jmethodID error =
env->GetMethodID(clazz, "error",
"(Lorg/apache/mesos/ExecutorDriver;"
"I"
"Ljava/lang/String;)V");
jint jcode = code;
jobject jmessage = convert<string>(env, message);
env->ExceptionClear();
env->CallVoidMethod(jexec, error, jdriver, jcode, jmessage);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
jvm->DetachCurrentThread();
driver->abort();
return;
}
jvm->DetachCurrentThread();
}
示例10: killTask
void JNIExecutor::killTask(ExecutorDriver* driver, const TaskID& taskId)
{
jvm->AttachCurrentThread(JNIENV_CAST(&env), NULL);
jclass clazz = env->GetObjectClass(jdriver);
jfieldID executor = env->GetFieldID(clazz, "executor", "Lorg/apache/mesos/Executor;");
jobject jexecutor = env->GetObjectField(jdriver, executor);
clazz = env->GetObjectClass(jexecutor);
// executor.killTask(driver, taskId);
jmethodID killTask =
env->GetMethodID(clazz, "killTask",
"(Lorg/apache/mesos/ExecutorDriver;"
"Lorg/apache/mesos/Protos$TaskID;)V");
jobject jtaskId = convert<TaskID>(env, taskId);
env->ExceptionClear();
env->CallVoidMethod(jexecutor, killTask, jdriver, jtaskId);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
jvm->DetachCurrentThread();
driver->abort();
return;
}
jvm->DetachCurrentThread();
}
示例11: 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->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
jvm->DetachCurrentThread();
driver->abort();
return;
}
jvm->DetachCurrentThread();
}
示例12: reregistered
void JNIExecutor::reregistered(ExecutorDriver* driver,
const SlaveInfo& slaveInfo)
{
jvm->AttachCurrentThread(JNIENV_CAST(&env), NULL);
jclass clazz = env->GetObjectClass(jdriver);
jfieldID executor = env->GetFieldID(clazz, "executor", "Lorg/apache/mesos/Executor;");
jobject jexecutor = env->GetObjectField(jdriver, executor);
clazz = env->GetObjectClass(jexecutor);
// executor.reregistered(driver, slaveInfo);
jmethodID reregistered =
env->GetMethodID(clazz, "reregistered",
"(Lorg/apache/mesos/ExecutorDriver;"
"Lorg/apache/mesos/Protos$SlaveInfo;)V");
jobject jslaveInfo = convert<SlaveInfo>(env, slaveInfo);
env->ExceptionClear();
env->CallVoidMethod(jexecutor, reregistered, jdriver, jslaveInfo);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
jvm->DetachCurrentThread();
driver->abort();
return;
}
jvm->DetachCurrentThread();
}
示例13: WriteData
/****************************************************************************
Desc:
****************************************************************************/
RCODE JNIBackupClient::WriteData(
const void * pvBuffer,
FLMUINT uiBytesToWrite)
{
RCODE rc = NE_XFLM_OK;
JNIEnv * pEnv;
jclass Cls;
jmethodID MId;
jbyteArray jBuff = NULL;
void * pvBuff;
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_jClient);
MId = pEnv->GetMethodID( Cls, "WriteData", "([B)I");
flmAssert( MId);
if ((jBuff = pEnv->NewByteArray( (jsize)uiBytesToWrite)) == NULL)
{
rc = RC_SET( NE_XFLM_MEM);
goto Exit;
}
pvBuff = pEnv->GetPrimitiveArrayCritical(jBuff, NULL);
f_memcpy(pvBuff, pvBuffer, uiBytesToWrite);
pEnv->ReleasePrimitiveArrayCritical( jBuff, pvBuff, 0);
if( RC_BAD( rc = (RCODE)pEnv->CallIntMethod( m_jClient, MId, jBuff)))
{
goto Exit;
}
Exit:
if (jBuff)
{
pEnv->DeleteLocalRef( jBuff);
}
if (bMustDetach)
{
if (m_pJvm->DetachCurrentThread() != 0)
{
flmAssert( 0);
rc = RC_SET( NE_XFLM_FAILURE);
}
}
return( rc);
}
示例14: launchTask
void JNIExecutor::launchTask(ExecutorDriver* driver, const TaskDescription& desc)
{
jvm->AttachCurrentThread((void **) &env, NULL);
jclass clazz = env->GetObjectClass(jdriver);
jfieldID exec = env->GetFieldID(clazz, "exec", "Lmesos/Executor;");
jobject jexec = env->GetObjectField(jdriver, exec);
clazz = env->GetObjectClass(jexec);
// exec.launchTask(driver, desc);
jmethodID launchTask = env->GetMethodID(clazz, "launchTask",
"(Lmesos/ExecutorDriver;Lmesos/TaskDescription;)V");
jobject jdesc = convert<TaskDescription>(env, desc);
env->ExceptionClear();
env->CallVoidMethod(jexec, launchTask, jdriver, jdesc);
if (!env->ExceptionOccurred()) {
jvm->DetachCurrentThread();
} else {
env->ExceptionDescribe();
env->ExceptionClear();
jvm->DetachCurrentThread();
driver->stop();
this->error(driver, -1, "Java exception caught");
}
}
示例15: cacheEnv
void cacheEnv()
{
JNIEnv* env = nullptr;
JavaVM *jvm = JniHelpers::get()->getJavaVM();
jint ret = jvm->GetEnv((void**)&env, JNI_VERSION_1_4);
switch (ret)
{
case JNI_OK :
break;
case JNI_EDETACHED :
if (jvm->AttachCurrentThread(&env, NULL) < 0)
{
LOGE("Failed to get the environment using AttachCurrentThread()");
return;
}
else
{
break;
}
case JNI_EVERSION :
LOGE("JNI interface version 1.4 not supported");
default:
LOGE("Failed to get the environment using GetEnv()");
return;
}
JniHelpers::get()->setEnv(env);
}