Example #1
0
static int _open_uri(const String& p_uri) {

	JNIEnv *env = ThreadAndroid::get_env();
	jstring jStr = env->NewStringUTF(p_uri.utf8().get_data());
	return env->CallIntMethod(godot_io,_openURI,jStr)	;
}
Example #2
0
static String _get_data_dir() {

	JNIEnv *env = ThreadAndroid::get_env();
	jstring s =(jstring)env->CallObjectMethod(godot_io,_getDataDir);
	return String(env->GetStringUTFChars( s, NULL ));
}
Example #3
0
		//--------------------------------------------------------
		/// Create Native Interface
		//--------------------------------------------------------
		void IJavaInterface::CreateNativeInterface(const std::string& instrInterfaceName)
		{
			if (mpJavaObject == nullptr)
			{
				JNIEnv* pEnv = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr();

				//get the class type
				jclass jClassType = JavaVirtualMachine::Get()->FindClass(instrInterfaceName);
				if (jClassType == nullptr)
				{
					jthrowable exception = pEnv->ExceptionOccurred();
					if (exception != nullptr)
					{
						pEnv->ExceptionDescribe();
						pEnv->ExceptionClear();
					}

					CS_LOG_FATAL("Cannot find native interface class '" + instrInterfaceName + "'");
				}

				//get the class instance
				jmethodID jConstructor = pEnv->GetMethodID(jClassType, "<init>", "()V");
				jobject jClassInstance = pEnv->NewObject(jClassType, jConstructor);
				if (jClassInstance == nullptr)
				{
					jthrowable exception = pEnv->ExceptionOccurred();
					if (exception != nullptr)
					{
						pEnv->ExceptionDescribe();
						pEnv->ExceptionClear();
					}

					CS_LOG_FATAL("Cannot create native interface instance '" + instrInterfaceName + "'");
				}

				//create a global reference to the instance
				mpJavaObject = pEnv->NewGlobalRef(jClassInstance);

				//delete all the local references
				pEnv->DeleteLocalRef(jClassType);
				pEnv->DeleteLocalRef(jClassInstance);
			}
			else
			{
				CS_LOG_FATAL("Cannot create native interface " + instrInterfaceName + ", as it has already been created!");
			}
		}
Example #4
0
	virtual Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error) {

		//print_line("attempt to call "+String(p_method));
		ERR_FAIL_COND_V(!instance,Variant());

		r_error.error=Variant::CallError::CALL_OK;

		Map<StringName,MethodData >::Element *E=method_map.find(p_method);
		if (!E) {

			print_line("no exists");
			r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
			return Variant();
		}


		int ac = E->get().argtypes.size();
		if (ac<p_argcount) {

			print_line("fewargs");
			r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
			r_error.argument=ac;
			return Variant();
		}

		if (ac>p_argcount) {

			print_line("manyargs");
			r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
			r_error.argument=ac;
			return Variant();
		}



		for(int i=0;i<p_argcount;i++) {

			if (!Variant::can_convert(p_args[i]->get_type(),E->get().argtypes[i])) {

				r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
				r_error.argument=i;
				r_error.expected=E->get().argtypes[i];
			}
		}


		jvalue *v=NULL;

		if (p_argcount) {

			v=(jvalue*)alloca( sizeof(jvalue)*p_argcount );
		}

		JNIEnv *env = ThreadAndroid::get_env();

		//print_line("argcount "+String::num(p_argcount));
		for(int i=0;i<p_argcount;i++) {

			v[i] = _variant_to_jvalue(env, E->get().argtypes[i], p_args[i]);
		}

		//print_line("calling method!!");

		Variant ret;

		switch(E->get().ret_type) {

			case Variant::NIL: {


				//print_line("call void");
				env->CallVoidMethodA(instance,E->get().method,v);
			} break;
			case Variant::BOOL: {

				ret = env->CallBooleanMethodA(instance,E->get().method,v);
				//print_line("call bool");
			} break;
			case Variant::INT: {

				ret = env->CallIntMethodA(instance,E->get().method,v);
				//print_line("call int");
			} break;
			case Variant::REAL: {

				ret = env->CallFloatMethodA(instance,E->get().method,v);
			} break;
			case Variant::STRING: {

				jobject o = env->CallObjectMethodA(instance,E->get().method,v);
				String str = env->GetStringUTFChars((jstring)o, NULL );
				ret=str;
			} break;
			case Variant::STRING_ARRAY: {

				jobjectArray arr = (jobjectArray)env->CallObjectMethodA(instance,E->get().method,v);

				ret = _jobject_to_variant(env, arr);

			} break;
			case Variant::INT_ARRAY: {

				jintArray arr = (jintArray)env->CallObjectMethodA(instance,E->get().method,v);

				int fCount = env->GetArrayLength(arr);
				DVector<int> sarr;
				sarr.resize(fCount);

				DVector<int>::Write w = sarr.write();
				env->GetIntArrayRegion(arr,0,fCount,w.ptr());
				w = DVector<int>::Write();
				ret=sarr;
			} break;
			case Variant::REAL_ARRAY: {

				jfloatArray arr = (jfloatArray)env->CallObjectMethodA(instance,E->get().method,v);

				int fCount = env->GetArrayLength(arr);
				DVector<float> sarr;
				sarr.resize(fCount);

				DVector<float>::Write w = sarr.write();
				env->GetFloatArrayRegion(arr,0,fCount,w.ptr());
				w = DVector<float>::Write();
				ret=sarr;
			} break;

			case Variant::DICTIONARY: {

				//print_line("call dictionary");
				jobject obj = env->CallObjectMethodA(instance, E->get().method, v);
				ret = _jobject_to_variant(env, obj);

			} break;
			default: {


				print_line("failure..");
				ERR_FAIL_V(Variant());
			} break;
		}

		//print_line("success");

		return ret;
	}
void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions,
    const OCRepresentation& ocRepresentation, const int& eCode, const int& sequenceNumber)
{
    jint envRet;
    JNIEnv *env = GetJNIEnv(envRet);
    if (NULL == env) return;

    jobject jListener = env->NewLocalRef(m_jwListener);
    if (!jListener)
    {
        checkExAndRemoveListener(env);
        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
        return;
    }
    jclass clsL = env->GetObjectClass(jListener);
    if (!clsL)
    {
        checkExAndRemoveListener(env);
        if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
        return;
    }

    if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode && OC_STACK_RESOURCE_DELETED != eCode)
    {
        jobject ex = GetOcException(eCode, "stack error in onObserveCallback");
        if (!ex)
        {
            checkExAndRemoveListener(env);
            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
            return;
        }
        jmethodID midL = env->GetMethodID(clsL, "onObserveFailed", "(Ljava/lang/Throwable;)V");
        if (!midL)
        {
            checkExAndRemoveListener(env);
            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
            return;
        }
        env->CallVoidMethod(jListener, midL, ex);
    }
    else
    {
        jobject jHeaderOptionList = JniUtils::convertHeaderOptionsVectorToJavaList(env, headerOptions);
        if (!jHeaderOptionList)
        {
            checkExAndRemoveListener(env);
            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
            return;
        }

        OCRepresentation * rep = new OCRepresentation(ocRepresentation);
        jlong handle = reinterpret_cast<jlong>(rep);
        jobject jRepresentation = env->NewObject(g_cls_OcRepresentation,
            g_mid_OcRepresentation_N_ctor_bool, handle, true);
        if (!jRepresentation)
        {
            delete rep;
            checkExAndRemoveListener(env);
            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
            return;
        }

        jmethodID midL = env->GetMethodID(clsL, "onObserveCompleted",
            "(Ljava/util/List;Lorg/iotivity/base/OcRepresentation;I)V");
        if (!midL)
        {
            checkExAndRemoveListener(env);
            if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
            return;
        }

        env->CallVoidMethod(jListener, midL, jHeaderOptionList, jRepresentation,
            static_cast<jint>(sequenceNumber));
        if (env->ExceptionCheck())
        {
            LOGE("Java exception is thrown");
            delete rep;
            jthrowable ex = env->ExceptionOccurred();
            env->ExceptionClear();
            m_ownerResource->removeOnObserveListener(env, m_jwListener);
            env->Throw((jthrowable)ex);
        }
    }

    if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
}
void onGetMyProfile(long requestId, bool success, ProfileItem item, string errnum, string errmsg) {
	FileLog("httprequest", "Profile.Native::onGetMyProfile( success : %s )", success?"true":"false");

	/* turn object to java object here */
	JNIEnv* env;
	jint iRet = JNI_ERR;
	gJavaVM->GetEnv((void**)&env, JNI_VERSION_1_4);
	if( env == NULL ) {
		iRet = gJavaVM->AttachCurrentThread((JNIEnv **)&env, NULL);
	}

	jobject jItem = NULL;
	JavaItemMap::iterator itr = gJavaItemMap.find(PROFILE_ITEM_CLASS);
	if( itr != gJavaItemMap.end() ) {
		jclass cls = env->GetObjectClass(itr->second);
		if( cls != NULL) {
			jmethodID init = env->GetMethodID(cls, "<init>", "("
					"Ljava/lang/String;"
					"I"
					"Ljava/lang/String;"
					"Ljava/lang/String;"
					"Ljava/lang/String;"
					"Ljava/lang/String;"

					"I"
					"I"
					"I"
					"I"
					"I"
					"I"
					"I"
					"I"
					"I"
					"I"
					"I"
					"I"
					"I"
					"I"

					"Ljava/lang/String;"
					"Ljava/lang/String;"
					"I"

					"Ljava/lang/String;"
					"Ljava/lang/String;"
					"Ljava/lang/String;"
					"Ljava/lang/String;"
					"Ljava/lang/String;"
					"Ljava/lang/String;"
					"Ljava/lang/String;"
					"Ljava/lang/String;"
					"Ljava/lang/String;"

					"I"
					"I"
					"Ljava/lang/String;"
					"I"

					"Ljava/lang/String;"
					"I"
					"I"

					"Ljava/lang/String;"
					"I"
					"Ljava/lang/String;"
					"I"

					"Ljava/util/ArrayList;"
					")V"
					);

			FileLog("httprequest", "Profile.Native::onGetMyProfile( GetMethodID <init> : %p )", init);

			if( init != NULL ) {
				jstring manid = env->NewStringUTF(item.manid.c_str());
				jstring birthday = env->NewStringUTF(item.birthday.c_str());
				jstring firstname = env->NewStringUTF(item.firstname.c_str());
				jstring lastname = env->NewStringUTF(item.lastname.c_str());
				jstring email = env->NewStringUTF(item.email.c_str());

				jstring resume = env->NewStringUTF(item.resume.c_str());
				jstring resume_content = env->NewStringUTF(item.resume_content.c_str());

				jstring address1 = env->NewStringUTF(item.address1.c_str());
				jstring address2 = env->NewStringUTF(item.address2.c_str());
				jstring city = env->NewStringUTF(item.city.c_str());
				jstring province = env->NewStringUTF(item.province.c_str());
				jstring zipcode = env->NewStringUTF(item.zipcode.c_str());
				jstring telephone = env->NewStringUTF(item.telephone.c_str());
				jstring fax = env->NewStringUTF(item.fax.c_str());
				jstring alternate_email = env->NewStringUTF(item.alternate_email.c_str());
				jstring money = env->NewStringUTF(item.money.c_str());

				jstring photoURL = env->NewStringUTF(item.photoURL.c_str());
				jstring mobile = env->NewStringUTF(item.mobile.c_str());
				jstring landline = env->NewStringUTF(item.landline.c_str());
				jstring landline_ac = env->NewStringUTF(item.landline_ac.c_str());

				jclass jArrayList = env->FindClass("java/util/ArrayList");
				jmethodID jArrayListInit = env->GetMethodID(jArrayList, "<init>", "()V");
				jmethodID jArrayListAdd = env->GetMethodID(jArrayList, "add", "(Ljava/lang/Object;)Z");
				FileLog("httprequest", "Profile.Native::onGetMyProfile( "
										"jArrayList : %p, "
										"jArrayListInit : %p, "
										"jArrayListAdd : %p "
										")",
										jArrayList,
										jArrayListInit,
										jArrayListAdd
										);

				FileLog("httprequest", "Profile.Native::onGetMyProfile( "
						"item.interests.size() : %d "
						")",
						item.interests.size()
						);

				int i = 0;
				jobject jInterestList = NULL;
				jInterestList = env->NewObject(jArrayList, jArrayListInit);
				if( item.interests.size() > 0 ) {
					i = 0;
					for(list<string>::iterator itr = item.interests.begin(); itr != item.interests.end(); itr++, i++) {
						jstring value = env->NewStringUTF((*itr).c_str());
						env->CallBooleanMethod(jInterestList, jArrayListAdd, value);
						env->DeleteLocalRef(value);
					}
				}

				jItem = env->NewObject(cls, init,
						manid,
						item.age,
						birthday,
						firstname,
						lastname,
						email,

						item.gender,
						item.country,
						item.marry,
						item.height,
						item.weight,
						item.smoke,
						item.drink,
						item.language,
						item.religion,
						item.education,
						item.profession,
						item.ethnicity,
						item.income,
						item.children,

						resume,
						resume_content,
						item.resume_status,

						address1,
						address2,
						city,
						province,
						zipcode,
						telephone,
						fax,
						alternate_email,
						money,

						item.v_id,
						item.photo,
						photoURL,
						item.integral,

						mobile,
						item.mobile_cc,
						item.mobile_status,

						landline,
						item.landline_cc,
						landline_ac,
						item.landline_status,

						jInterestList
						);

				FileLog("httprequest", "Profile.Native::onGetMyProfile( NewObject : %p )", jItem);

				env->DeleteLocalRef(manid);
				env->DeleteLocalRef(birthday);
				env->DeleteLocalRef(firstname);
				env->DeleteLocalRef(lastname);
				env->DeleteLocalRef(email);
				env->DeleteLocalRef(resume);
				env->DeleteLocalRef(resume_content);
				env->DeleteLocalRef(address1);
				env->DeleteLocalRef(address2);
				env->DeleteLocalRef(city);
				env->DeleteLocalRef(province);
				env->DeleteLocalRef(zipcode);
				env->DeleteLocalRef(telephone);
				env->DeleteLocalRef(fax);
				env->DeleteLocalRef(alternate_email);
				env->DeleteLocalRef(money);
				env->DeleteLocalRef(photoURL);
				env->DeleteLocalRef(mobile);
				env->DeleteLocalRef(landline);
				env->DeleteLocalRef(landline_ac);

				if( jInterestList != NULL ) {
					env->DeleteLocalRef(jInterestList);
				}
			}
		}
	}

	/* real callback java */
	jobject callbackObj = gCallbackMap.Erase(requestId);
	jclass callbackCls = env->GetObjectClass(callbackObj);

	string signure = "(ZLjava/lang/String;Ljava/lang/String;";
	signure += "L";
	signure += PROFILE_ITEM_CLASS;
	signure += ";";
	signure += ")V";
	jmethodID callback = env->GetMethodID(callbackCls, "OnGetMyProfile", signure.c_str());
	FileLog("httprequest", "onGetMyProfile( callbackCls : %p, callback : %p, signure : %s )",
			callbackCls, callback, signure.c_str());

	if( callbackObj != NULL && callback != NULL ) {
		jstring jerrno = env->NewStringUTF(errnum.c_str());
		jstring jerrmsg = env->NewStringUTF(errmsg.c_str());

		FileLog("httprequest", "Profile.Native::onGetMyProfile( CallObjectMethod "
				"jItem : %p )", jItem);

		env->CallVoidMethod(callbackObj, callback, success, jerrno, jerrmsg, jItem);

		env->DeleteGlobalRef(callbackObj);

		env->DeleteLocalRef(jerrno);
		env->DeleteLocalRef(jerrmsg);
	}

	if( jItem != NULL ) {
		env->DeleteLocalRef(jItem);
	}

	if( iRet == JNI_OK ) {
		gJavaVM->DetachCurrentThread();
	}
}
Example #7
0
void ScilabVariables::sendData (JavaVM * jvm_, char const* varName, int const* indexes, int indexesSize, unsigned short type, int handlerId){

JNIEnv * curEnv = NULL;
jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
jclass cls = curEnv->FindClass( className().c_str() );

jmethodID voidsendDatajstringjava_lang_StringjintArray_intintjcharcharjintintID = curEnv->GetStaticMethodID(cls, "sendData", "(Ljava/lang/String;[ICI)V" ) ;
if (voidsendDatajstringjava_lang_StringjintArray_intintjcharcharjintintID == NULL) {
throw GiwsException::JniMethodNotFoundException(curEnv, "sendData");
}

jstring varName_ = curEnv->NewStringUTF( varName );
if (varName != NULL && varName_ == NULL)
{
throw GiwsException::JniBadAllocException(curEnv);
}


jintArray indexes_ = curEnv->NewIntArray( indexesSize ) ;

if (indexes_ == NULL)
{
// check that allocation succeed
throw GiwsException::JniBadAllocException(curEnv);
}

curEnv->SetIntArrayRegion( indexes_, 0, indexesSize, (jint*)(indexes) ) ;


                         curEnv->CallStaticVoidMethod(cls, voidsendDatajstringjava_lang_StringjintArray_intintjcharcharjintintID ,varName_, indexes_, type, handlerId);
                        curEnv->DeleteLocalRef(varName_);
curEnv->DeleteLocalRef(indexes_);
curEnv->DeleteLocalRef(cls);
if (curEnv->ExceptionCheck()) {
throw GiwsException::JniCallMethodException(curEnv);
}
}
Example #8
0
static const TCHAR *
detect_language()
{
#ifdef ANDROID

  JNIEnv *env = Java::GetEnv();

  Java::Class cls(env, "java/util/Locale");

  // Call static function Locale.getDefault() that
  // returns the user's default Locale object

  jmethodID cid = env->GetStaticMethodID(cls, "getDefault",
                                         "()Ljava/util/Locale;");
  assert(cid != NULL);

  jobject _obj = env->CallStaticObjectMethod(cls, cid);
  if (_obj == NULL)
    return NULL;

  Java::LocalObject obj(env, _obj);

  // Call function Locale.getLanguage() that
  // returns a two-letter language string

  cid = env->GetMethodID(cls, "getLanguage", "()Ljava/lang/String;");
  assert(cid != NULL);

  jstring language = (jstring)env->CallObjectMethod(obj, cid);
  if (language == NULL)
    return NULL;

  // Convert the jstring to a char string
  const char *language2 = env->GetStringUTFChars(language, NULL);
  if (language2 == NULL) {
    env->DeleteLocalRef(language);
    return NULL;
  }

  /* generate the resource name */

  const char *language3 = language2;
  if (strcmp(language3, "pt") == 0)
    /* hack */
    language3 = "pt_BR";

  // Attach .mo to the language identifier
  static char language_buffer[16];
  snprintf(language_buffer, sizeof(language_buffer), "%s.mo", language3);

  // Clean up the memory
  env->ReleaseStringUTFChars(language, language2);
  env->DeleteLocalRef(language);

  // Return e.g. "de.mo"
  return language_buffer;

#else /* !ANDROID */

#if defined(_WIN32_WCE)
  /* the GetUserDefaultUILanguage() prototype is missing on
     mingw32ce, we have to look it up dynamically */
  DynamicLibrary coreloc_dll(_T("coredll"));
  if (!coreloc_dll.IsDefined()) {
    LogStartUp(_T("Language: coredll.dll not found"));
    return NULL;
  }

  typedef LANGID WINAPI (*GetUserDefaultUILanguage_t)();
  GetUserDefaultUILanguage_t GetUserDefaultUILanguage =
    (GetUserDefaultUILanguage_t)
    coreloc_dll.Lookup(_T("GetUserDefaultUILanguage"));
  if (GetUserDefaultUILanguage == NULL) {
    LogStartUp(_T("Language: GetUserDefaultUILanguage() not available"));
    return NULL;
  }
#endif

  // Retrieve the default user language identifier from the OS
  LANGID lang_id = GetUserDefaultUILanguage();
  LogStartUp(_T("Language: GetUserDefaultUILanguage()=0x%x"), (int)lang_id);
  if (lang_id == 0)
    return NULL;

  // Try to convert the primary language part of the language identifier
  // to a MO file name in the language table
  return find_language(PRIMARYLANGID(lang_id));

#endif /* !ANDROID */
}
Example #9
0
void ScilabVariables::sendData (JavaVM * jvm_, char const* varName, int const* indexes, int indexesSize, bool const* const* data, int dataSize, int dataSizeCol, bool swaped, int handlerId){

JNIEnv * curEnv = NULL;
jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
jclass cls = curEnv->FindClass( className().c_str() );

jmethodID voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__booleanbooleanjbooleanbooleanjintintID = curEnv->GetStaticMethodID(cls, "sendData", "(Ljava/lang/String;[I[[ZZI)V" ) ;
if (voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__booleanbooleanjbooleanbooleanjintintID == NULL) {
throw GiwsException::JniMethodNotFoundException(curEnv, "sendData");
}

jstring varName_ = curEnv->NewStringUTF( varName );
if (varName != NULL && varName_ == NULL)
{
throw GiwsException::JniBadAllocException(curEnv);
}


jintArray indexes_ = curEnv->NewIntArray( indexesSize ) ;

if (indexes_ == NULL)
{
// check that allocation succeed
throw GiwsException::JniBadAllocException(curEnv);
}

curEnv->SetIntArrayRegion( indexes_, 0, indexesSize, (jint*)(indexes) ) ;


jobjectArray data_ = curEnv->NewObjectArray(dataSize, curEnv->FindClass("[Z"),NULL);
for (int i=0; i<dataSize; i++){
                        jbooleanArray dataLocal = curEnv->NewBooleanArray( dataSizeCol ) ;
                        curEnv->SetBooleanArrayRegion( dataLocal, 0, dataSizeCol, (jboolean*)(data[i]) ) ;
                        curEnv->SetObjectArrayElement(data_, i, dataLocal);
                        curEnv->DeleteLocalRef(dataLocal);
                        }

jboolean swaped_ = (static_cast<bool>(swaped) ? JNI_TRUE : JNI_FALSE);

                         curEnv->CallStaticVoidMethod(cls, voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__booleanbooleanjbooleanbooleanjintintID ,varName_, indexes_, data_, swaped_, handlerId);
                        curEnv->DeleteLocalRef(varName_);
curEnv->DeleteLocalRef(indexes_);
curEnv->DeleteLocalRef(data_);
curEnv->DeleteLocalRef(cls);
if (curEnv->ExceptionCheck()) {
throw GiwsException::JniCallMethodException(curEnv);
}
}
Example #10
0
void ScilabVariables::sendData (JavaVM * jvm_, char const* varName, int const* indexes, int indexesSize, char const* const* const* data, int dataSize, int dataSizeCol, bool swaped, int handlerId){

JNIEnv * curEnv = NULL;
jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
jclass cls = curEnv->FindClass( className().c_str() );

jmethodID voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__java_lang_Stringjava_lang_StringjbooleanbooleanjintintID = curEnv->GetStaticMethodID(cls, "sendData", "(Ljava/lang/String;[I[[Ljava/lang/String;ZI)V" ) ;
if (voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__java_lang_Stringjava_lang_StringjbooleanbooleanjintintID == NULL) {
throw GiwsException::JniMethodNotFoundException(curEnv, "sendData");
}

jstring varName_ = curEnv->NewStringUTF( varName );
if (varName != NULL && varName_ == NULL)
{
throw GiwsException::JniBadAllocException(curEnv);
}


jintArray indexes_ = curEnv->NewIntArray( indexesSize ) ;

if (indexes_ == NULL)
{
// check that allocation succeed
throw GiwsException::JniBadAllocException(curEnv);
}

curEnv->SetIntArrayRegion( indexes_, 0, indexesSize, (jint*)(indexes) ) ;

jclass stringArrayClass = curEnv->FindClass("java/lang/String");
// create java array of array of strings.
jobjectArray data_ = curEnv->NewObjectArray( dataSize, curEnv->FindClass("[Ljava/lang/String;"), NULL);
if (data_ == NULL)
{
throw GiwsException::JniBadAllocException(curEnv);
}

for ( int i = 0; i < dataSize; i++)
{
jobjectArray dataLocal = curEnv->NewObjectArray( dataSizeCol, stringArrayClass, NULL);
// convert each char * to java strings and fill the java array.
for ( int j = 0; j < dataSizeCol; j++) {
jstring TempString = curEnv->NewStringUTF( data[i][j] );

if (TempString == NULL)
{
throw GiwsException::JniBadAllocException(curEnv);
}

curEnv->SetObjectArrayElement( dataLocal, j, TempString);

// avoid keeping reference on to many strings
curEnv->DeleteLocalRef(TempString);
}
curEnv->SetObjectArrayElement(data_, i, dataLocal);
curEnv->DeleteLocalRef(dataLocal);

}
jboolean swaped_ = (static_cast<bool>(swaped) ? JNI_TRUE : JNI_FALSE);

                         curEnv->CallStaticVoidMethod(cls, voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__java_lang_Stringjava_lang_StringjbooleanbooleanjintintID ,varName_, indexes_, data_, swaped_, handlerId);
                        curEnv->DeleteLocalRef(stringArrayClass);
curEnv->DeleteLocalRef(varName_);
curEnv->DeleteLocalRef(indexes_);
curEnv->DeleteLocalRef(data_);
curEnv->DeleteLocalRef(cls);
if (curEnv->ExceptionCheck()) {
throw GiwsException::JniCallMethodException(curEnv);
}
}
Example #11
0
// Constructors
ScilabVariables::ScilabVariables(JavaVM * jvm_) {
jmethodID constructObject = NULL ;
jobject localInstance ;
jclass localClass ;

const std::string construct="<init>";
const std::string param="()V";
jvm=jvm_;

JNIEnv * curEnv = getCurrentEnv();

localClass = curEnv->FindClass( this->className().c_str() ) ;
if (localClass == NULL) {
  throw GiwsException::JniClassNotFoundException(curEnv, this->className());
}

this->instanceClass = static_cast<jclass>(curEnv->NewGlobalRef(localClass));

/* localClass is not needed anymore */
curEnv->DeleteLocalRef(localClass);

if (this->instanceClass == NULL) {
throw GiwsException::JniObjectCreationException(curEnv, this->className());
}


constructObject = curEnv->GetMethodID( this->instanceClass, construct.c_str() , param.c_str() ) ;
if(constructObject == NULL){
throw GiwsException::JniObjectCreationException(curEnv, this->className());
}

localInstance = curEnv->NewObject( this->instanceClass, constructObject ) ;
if(localInstance == NULL){
throw GiwsException::JniObjectCreationException(curEnv, this->className());
}
 
this->instance = curEnv->NewGlobalRef(localInstance) ;
if(this->instance == NULL){
throw GiwsException::JniObjectCreationException(curEnv, this->className());
}
/* localInstance not needed anymore */
curEnv->DeleteLocalRef(localInstance);

                /* Methods ID set to NULL */
jobjectArray_getAllListenedVariablesID=NULL;
voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__doubledoublejbooleanbooleanjintintID=NULL;
voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__doubledoublejobjectArray__doubledoublejbooleanbooleanjintintID=NULL;
voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__bytebytejbooleanbooleanjintintID=NULL;
voidsendUnsignedDatajstringjava_lang_StringjintArray_intintjobjectArray__bytebytejbooleanbooleanjintintID=NULL;
voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__shortshortjbooleanbooleanjintintID=NULL;
voidsendUnsignedDatajstringjava_lang_StringjintArray_intintjobjectArray__shortshortjbooleanbooleanjintintID=NULL;
voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__intintjbooleanbooleanjintintID=NULL;
voidsendUnsignedDatajstringjava_lang_StringjintArray_intintjobjectArray__intintjbooleanbooleanjintintID=NULL;
voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__longlongjbooleanbooleanjintintID=NULL;
voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__booleanbooleanjbooleanbooleanjintintID=NULL;
voidsendDatajstringjava_lang_StringjintArray_intintjobjectArray__java_lang_Stringjava_lang_StringjbooleanbooleanjintintID=NULL;
voidsendDatajstringjava_lang_StringjintArray_intintjcharcharjintintID=NULL;
voidcloseListjintArray_intintjintintID=NULL;
voidsendDatajstringjava_lang_StringjintArray_intintjintintjintintjintintjintArray_intintjintArray_intintjdoubleArray_doubledoublejintintID=NULL;
voidsendDatajstringjava_lang_StringjintArray_intintjintintjintintjintintjintArray_intintjintArray_intintjdoubleArray_doubledoublejdoubleArray_doubledoublejintintID=NULL;
voidsendDatajstringjava_lang_StringjintArray_intintjintintjintintjintintjintArray_intintjintArray_intintjintintID=NULL;


}
Example #12
0
void ScilabVariables::sendData (JavaVM * jvm_, char const* varName, int const* indexes, int indexesSize, int row, int col, int nbItem, int const* nbItemRow, int nbItemRowSize, int const* colPos, int colPosSize, double const* real, int realSize, double const* imag, int imagSize, int handlerId){

JNIEnv * curEnv = NULL;
jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
jclass cls = curEnv->FindClass( className().c_str() );

jmethodID voidsendDatajstringjava_lang_StringjintArray_intintjintintjintintjintintjintArray_intintjintArray_intintjdoubleArray_doubledoublejdoubleArray_doubledoublejintintID = curEnv->GetStaticMethodID(cls, "sendData", "(Ljava/lang/String;[IIII[I[I[D[DI)V" ) ;
if (voidsendDatajstringjava_lang_StringjintArray_intintjintintjintintjintintjintArray_intintjintArray_intintjdoubleArray_doubledoublejdoubleArray_doubledoublejintintID == NULL) {
throw GiwsException::JniMethodNotFoundException(curEnv, "sendData");
}

jstring varName_ = curEnv->NewStringUTF( varName );
if (varName != NULL && varName_ == NULL)
{
throw GiwsException::JniBadAllocException(curEnv);
}


jintArray indexes_ = curEnv->NewIntArray( indexesSize ) ;

if (indexes_ == NULL)
{
// check that allocation succeed
throw GiwsException::JniBadAllocException(curEnv);
}

curEnv->SetIntArrayRegion( indexes_, 0, indexesSize, (jint*)(indexes) ) ;


jintArray nbItemRow_ = curEnv->NewIntArray( nbItemRowSize ) ;

if (nbItemRow_ == NULL)
{
// check that allocation succeed
throw GiwsException::JniBadAllocException(curEnv);
}

curEnv->SetIntArrayRegion( nbItemRow_, 0, nbItemRowSize, (jint*)(nbItemRow) ) ;


jintArray colPos_ = curEnv->NewIntArray( colPosSize ) ;

if (colPos_ == NULL)
{
// check that allocation succeed
throw GiwsException::JniBadAllocException(curEnv);
}

curEnv->SetIntArrayRegion( colPos_, 0, colPosSize, (jint*)(colPos) ) ;


jdoubleArray real_ = curEnv->NewDoubleArray( realSize ) ;

if (real_ == NULL)
{
// check that allocation succeed
throw GiwsException::JniBadAllocException(curEnv);
}

curEnv->SetDoubleArrayRegion( real_, 0, realSize, (jdouble*)(real) ) ;


jdoubleArray imag_ = curEnv->NewDoubleArray( imagSize ) ;

if (imag_ == NULL)
{
// check that allocation succeed
throw GiwsException::JniBadAllocException(curEnv);
}

curEnv->SetDoubleArrayRegion( imag_, 0, imagSize, (jdouble*)(imag) ) ;


                         curEnv->CallStaticVoidMethod(cls, voidsendDatajstringjava_lang_StringjintArray_intintjintintjintintjintintjintArray_intintjintArray_intintjdoubleArray_doubledoublejdoubleArray_doubledoublejintintID ,varName_, indexes_, row, col, nbItem, nbItemRow_, colPos_, real_, imag_, handlerId);
                        curEnv->DeleteLocalRef(varName_);
curEnv->DeleteLocalRef(indexes_);
curEnv->DeleteLocalRef(nbItemRow_);
curEnv->DeleteLocalRef(colPos_);
curEnv->DeleteLocalRef(real_);
curEnv->DeleteLocalRef(imag_);
curEnv->DeleteLocalRef(cls);
if (curEnv->ExceptionCheck()) {
throw GiwsException::JniCallMethodException(curEnv);
}
}
		//-------------------------------------------
		//-------------------------------------------
        void TextEntryJavaInterface::SetCapitalisationMethod(CSInput::TextEntry::Capitalisation ineKeyboardCapitalisation)
        {
        	JNIEnv* pEnv = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr();
        	s32 dwKeyboardCapitalisation = KeyboardCapitalisationToInteger(ineKeyboardCapitalisation);
        	pEnv->CallVoidMethod(GetJavaObject(), GetMethodID("setCapitalisationMethod"), dwKeyboardCapitalisation);
        }
		//-------------------------------------------
		//-------------------------------------------
        void TextEntryJavaInterface::SetKeyboardType(CSInput::TextEntry::Type ineKeyboardType)
        {
        	JNIEnv* pEnv = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr();
        	s32 dwKeyboardType = KeyboardTypeToInteger(ineKeyboardType);
        	pEnv->CallVoidMethod(GetJavaObject(), GetMethodID("setKeyboardType"), dwKeyboardType);
        }
		//-----------------------------------------------
		//-----------------------------------------------
		void TextEntryJavaInterface::Deactivate()
		{
			JNIEnv* pEnv = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr();
			pEnv->CallVoidMethod(GetJavaObject(), GetMethodID("deactivate"));
		}