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");
  }
}
Beispiel #2
0
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;
}
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;
}
Beispiel #4
0
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
}
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();
}
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();
    }
}
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;
    }
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();
}
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();
}
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();
}
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();
}
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();
}
/****************************************************************************
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);
}
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");
  }
}
Beispiel #15
0
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);    
}
void JNIExecutor::init(ExecutorDriver* driver, const ExecutorArgs& args)
{
  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.init(driver);
  jmethodID init =
    env->GetMethodID(clazz, "init",
		     "(Lorg/apache/mesos/ExecutorDriver;"
		     "Lorg/apache/mesos/Protos$ExecutorArgs;)V");

  jobject jargs = convert<ExecutorArgs>(env, args);

  env->ExceptionClear();

  env->CallVoidMethod(jexec, init, jdriver, jargs);

  if (env->ExceptionCheck()) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    jvm->DetachCurrentThread();
    driver->abort();
    return;
  }

  jvm->DetachCurrentThread();
}
Beispiel #17
0
    std::string Database::create(std::string name, jint mode) {
        std::string filename;
        JNIEnv* env;
        JavaVM* vm = engine->app->activity->vm;
        
        vm->AttachCurrentThread(&env, NULL);

        jclass clazz = env->GetObjectClass(engine->app->activity->clazz);
        jmethodID methodj = env->GetMethodID(clazz, "openOrCreateDatabase", "(Ljava/lang/String;ILandroid/database/sqlite/SQLiteDatabase$CursorFactory;)Landroid/database/sqlite/SQLiteDatabase;");
        jobject jdb = env->CallObjectMethod(engine->app->activity->clazz, methodj,  env->NewStringUTF(name.c_str()), mode, NULL);
        if (jdb != NULL) {
            clazz = env->GetObjectClass(jdb);
            methodj = env->GetMethodID(clazz, "getPath", "()Ljava/lang/String;");
            jstring jstr = (jstring)env->CallObjectMethod(jdb, methodj);
            if (jstr != NULL) {
                const char* str = env->GetStringUTFChars(jstr, NULL);
                filename = str;
                env->ReleaseStringUTFChars(jstr, str);
            }
            methodj = env->GetMethodID(clazz, "close", "()V");
            env->CallVoidMethod(jdb, methodj);
        }
        vm->DetachCurrentThread();

        return filename;
    }
void JNIExecutor::launchTask(ExecutorDriver* driver, const TaskDescription& desc)
{
  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.launchTask(driver, desc);
  jmethodID launchTask =
    env->GetMethodID(clazz, "launchTask",
		     "(Lorg/apache/mesos/ExecutorDriver;"
		     "Lorg/apache/mesos/Protos$TaskDescription;)V");

  jobject jdesc = convert<TaskDescription>(env, desc);

  env->ExceptionClear();

  env->CallVoidMethod(jexec, launchTask, jdriver, jdesc);

  if (env->ExceptionCheck()) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    jvm->DetachCurrentThread();
    driver->abort();
    return;
  }

  jvm->DetachCurrentThread();
}
    msandroid_sound_write_data() :audio_track_class(0),audio_track(0),write_chunk_size(0),writtenBytes(0),last_sample_date(0) {
        bufferizer = ms_bufferizer_new();
        ms_cond_init(&cond,0);
        JNIEnv *jni_env = NULL;
        JavaVM *jvm = ms_get_jvm();
        if (jvm->AttachCurrentThread(&jni_env, NULL)!=0) {
            ms_fatal("AttachCurrentThread() failed !");
            return;
        }

        //JNIEnv *jni_env = ms_get_jni_env();
        jclass temp_class = 0;
        temp_class = jni_env->FindClass("android/media/AudioTrack");
        audio_track_class = (jclass)jni_env->NewGlobalRef(temp_class);
        if (audio_track_class == 0) {
            ms_error("cannot find  android/media/AudioTrack\n");
            return;
        }
        jmethodID hwrate_id = jni_env->GetStaticMethodID(audio_track_class,"getNativeOutputSampleRate", "(I)I");
        if (hwrate_id == 0) {
            ms_error("cannot find  int AudioRecord.getNativeOutputSampleRate(int streamType)");
            return;
        }
        rate = jni_env->CallStaticIntMethod(audio_track_class,hwrate_id,0 /*STREAM_VOICE_CALL*/);
        ms_message("Hardware sample rate is %i",rate);
        jvm->DetachCurrentThread();
    };
Beispiel #20
0
// 多线程中调用java端方法时, 需要进行线程绑定
// 线程函数
void* thread_func(void* args) {
    // 刷新画面
    JavaVM *vm = JniHelper::getJavaVM();
    if(NULL == vm){
        LOGD_D("Failed to get jni enviroment!");
        pthread_exit((void*)2);
    }

    // 直接attach 当前线程到vm中
    JNIEnv* env = NULL;
    int status = -1;
    status = vm->AttachCurrentThread(&env, NULL);
    if (0 > status) {
        LOGD_D("Failed to attach to current thread, give up operator!");
        status = -1;
        pthread_exit((void*)3);
    } else {
        status = 0;
    }

    // 调用java端接口
    env->CallStaticVoidMethod(g_nativeMgr._jnativeMgr, g_nativeMgr._jtestvoidfunc, 100.11, 2013.44);

    // 解除线程引用
    vm->DetachCurrentThread();
    pthread_exit((void*)0);
}
Beispiel #21
0
JSObjectRef Function::ConstructorCallback(JSContextRef ctx, JSObjectRef constructor,
		size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
	JNIEnv *env;
	jvm->AttachCurrentThread(&env, NULL);
	jclass cls = env->GetObjectClass(thiz);
	jmethodID mid;
	do {
		mid = env->GetMethodID(cls,"constructorCallback","(JJ[JJ)J");
		if (!env->ExceptionCheck()) break;
		env->ExceptionClear();
		cls = env->GetSuperclass(env->GetObjectClass(thiz));
		if (cls == NULL || env->ExceptionCheck()) {
			return NULL;
		}
	} while (true);
	jlongArray argsArr = env->NewLongArray(argumentCount);
	jlong* args = new jlong[argumentCount];
	for (int i=0; i<argumentCount; i++) {
		args[i] = (long) arguments[i];
	}
	env->SetLongArrayRegion(argsArr,0,argumentCount,args);

	long objret = env->CallLongMethod(thiz, mid, (jlong)ctx, (jlong)constructor,
			argsArr, (jlong)exception);

	delete args;
	return (JSObjectRef)objret;
}
void* start_routine(void *args)
{
	ALOGI(">>>>>>>>>>>>>I am in, I am a bad boy!!!!<<<<<<<<<<<<<<");

	JNIEnv *jnienv = NULL;
	JavaVM *javavm = NULL;
	bool should_detach = false;
	char *apk_path = NULL;

	javavm = AndroidRuntime::getJavaVM();
	if(javavm != NULL){

		javavm->GetEnv((void **)&jnienv, JNI_VERSION_1_4);

		if(jnienv == NULL){
			should_detach = true;
			javavm->AttachCurrentThread(&jnienv, NULL);
		}

		if(jnienv != NULL){

			apk_path = find_apk_path();
			if(!apk_path){
				ALOGE("Could found't apk_path");
				goto bails;
			}

			const char *dexout_dir = "/data/data/com.tencent.mm/dexout";

			int state = 0;

			if (access(dexout_dir, R_OK | W_OK | X_OK) != 0) {
				int state = mkdir(dexout_dir, S_IRWXU);
				if (state) {
					ALOGE("Could create dexout dir");
					goto bails;
				}
			}

			state = load_dex(jnienv, apk_path, dexout_dir, "com.android.testplugin.Entry", "invoke");
			if(state != 0){
				ALOGE("Load dex error!!");
				goto bails;
			}
		}
	}

bails:
	if(apk_path){
		free(apk_path);
		apk_path = NULL;
	}

	if(javavm && jnienv && should_detach){
		javavm->DetachCurrentThread();
		jnienv = NULL;
		javavm = NULL;
	}
	return NULL;
}
void JNIScheduler::reregistered(SchedulerDriver* driver,
                                const MasterInfo& masterInfo)
{
    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.reregistered(driver, masterInfo);
    jmethodID reregistered =
        env->GetMethodID(clazz, "reregistered",
                         "(Lorg/apache/mesos/SchedulerDriver;"
                         "Lorg/apache/mesos/Protos$MasterInfo;)V");

    jobject jmasterInfo = convert<MasterInfo>(env, masterInfo);

    env->ExceptionClear();

    env->CallVoidMethod(jscheduler, reregistered, jdriver, jmasterInfo);

    if (env->ExceptionCheck()) {
        env->ExceptionDescribe();
        env->ExceptionClear();
        jvm->DetachCurrentThread();
        driver->abort();
        return;
    }

    jvm->DetachCurrentThread();
}
ExecutorInfo JNIScheduler::getExecutorInfo(SchedulerDriver* driver)
{
  jvm->AttachCurrentThread((void**) &env, NULL);

  jclass clazz = env->GetObjectClass(jdriver);

  jfieldID sched = env->GetFieldID(clazz, "sched", "Lorg/apache/mesos/Scheduler;");
  jobject jsched = env->GetObjectField(jdriver, sched);

  clazz = env->GetObjectClass(jsched);

  // ExecutorInfo executor = sched.getExecutorInfo(driver);
  jmethodID getExecutorInfo =
    env->GetMethodID(clazz, "getExecutorInfo",
		     "(Lorg/apache/mesos/SchedulerDriver;)"
		     "Lorg/apache/mesos/Protos$ExecutorInfo;");

  env->ExceptionClear();

  jobject jexecutor = env->CallObjectMethod(jsched, getExecutorInfo, jdriver);

  if (env->ExceptionCheck()) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    jvm->DetachCurrentThread();
    driver->abort();
    return ExecutorInfo();
  }

  ExecutorInfo executor = construct<ExecutorInfo>(env, jexecutor);

  jvm->DetachCurrentThread();

  return executor;
}
void JNIScheduler::resourceOffers(SchedulerDriver* driver,
                                  const vector<Offer>& offers)
{
    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.resourceOffers(driver, offers);
    jmethodID resourceOffers =
        env->GetMethodID(clazz, "resourceOffers",
                         "(Lorg/apache/mesos/SchedulerDriver;"
                         "Ljava/util/List;)V");

    // List offers = new ArrayList();
    clazz = env->FindClass("java/util/ArrayList");

    jmethodID _init_ = env->GetMethodID(clazz, "<init>", "()V");
    jobject joffers = env->NewObject(clazz, _init_);

    jmethodID add = env->GetMethodID(clazz, "add", "(Ljava/lang/Object;)Z");

    // Loop through C++ vector and add each offer to the Java list.
    foreach (const Offer& offer, offers) {
        jobject joffer = convert<Offer>(env, offer);
        env->CallBooleanMethod(joffers, add, joffer);
    }
void JNIScheduler::registered(SchedulerDriver* driver,
                              const FrameworkID& frameworkId)
{
  jvm->AttachCurrentThread((void**) &env, NULL);

  jclass clazz = env->GetObjectClass(jdriver);

  jfieldID sched = env->GetFieldID(clazz, "sched", "Lorg/apache/mesos/Scheduler;");
  jobject jsched = env->GetObjectField(jdriver, sched);

  clazz = env->GetObjectClass(jsched);

  // sched.registered(driver, frameworkId);
  jmethodID registered =
    env->GetMethodID(clazz, "registered",
		     "(Lorg/apache/mesos/SchedulerDriver;"
		     "Lorg/apache/mesos/Protos$FrameworkID;)V");

  jobject jframeworkId = convert<FrameworkID>(env, frameworkId);

  env->ExceptionClear();

  env->CallVoidMethod(jsched, registered, jdriver, jframeworkId);

  if (env->ExceptionCheck()) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    jvm->DetachCurrentThread();
    driver->abort();
    return;
  }

  jvm->DetachCurrentThread();
}
Beispiel #27
0
INT CLcxSndJni::Pause()
{
	GetStatus();

	if(LCX_AV_PLAY != m_state)
		return LC_OK;

	m_state = LCX_AV_PAUSE;

#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::Pause::Err::AttachCurrentThread::\n");
		return LC_EFAIL;
	}

	pEnv->CallStaticIntMethod(clzz, Jni_SndPause, (jint)m_fd);

#endif

	return LC_OK;
}
string JNIScheduler::getFrameworkName(SchedulerDriver* driver)
{
  jvm->AttachCurrentThread((void**) &env, NULL);

  jclass clazz = env->GetObjectClass(jdriver);

  jfieldID sched = env->GetFieldID(clazz, "sched", "Lorg/apache/mesos/Scheduler;");
  jobject jsched = env->GetObjectField(jdriver, sched);

  clazz = env->GetObjectClass(jsched);

  // String name = sched.getFrameworkName(driver);
  jmethodID getFrameworkName =
    env->GetMethodID(clazz, "getFrameworkName",
		     "(Lorg/apache/mesos/SchedulerDriver;)"
		     "Ljava/lang/String;");

  env->ExceptionClear();

  jobject jname = env->CallObjectMethod(jsched, getFrameworkName, jdriver);

  if (env->ExceptionCheck()) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    jvm->DetachCurrentThread();
    driver->abort();
    return "";
  }

  string name = construct<string>(env, (jstring) jname);

  jvm->DetachCurrentThread();

  return name;
}
static int release_wake_lock_callout(const char *lock_name) {
    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 BT_STATUS_FAIL;
    }

    if (status == JNI_EDETACHED && vm->AttachCurrentThread(&env, &sAttachArgs) != 0) {
        ALOGE("%s unable to attach thread to VM", __func__);
        return BT_STATUS_FAIL;
    }

    jboolean ret = JNI_FALSE;
    jstring lock_name_jni = env->NewStringUTF(lock_name);
    if (lock_name_jni) {
        ret = env->CallBooleanMethod(sJniAdapterServiceObj, method_releaseWakeLock, lock_name_jni);
        env->DeleteLocalRef(lock_name_jni);
    } else {
        ALOGE("%s unable to allocate string: %s", __func__, lock_name);
    }

    if (status == JNI_EDETACHED) {
        vm->DetachCurrentThread();
    }

    return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
}
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", "Lmesos/Executor;");
  jobject jexec = env->GetObjectField(jdriver, exec);

  clazz = env->GetObjectClass(jexec);

  // exec.error(driver, code, message);
  jmethodID error = env->GetMethodID(clazz, "error",
    "(Lmesos/ExecutorDriver;ILjava/lang/String;)V");

  jint jcode = code;
  jobject jmessage = convert<string>(env, message);

  env->ExceptionClear();

  env->CallVoidMethod(jexec, error, jdriver, jcode, jmessage);

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