RHO_GLOBAL int rho_sysimpl_get_property(char* szPropName, VALUE* resValue) { JNIEnv *env = jnienv(); jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES); if (!cls) return 0; jmethodID mid = getJNIClassStaticMethod(env, cls, "getProperty", "(Ljava/lang/String;)Ljava/lang/Object;"); if (!mid) return 0; jobject result = env->CallStaticObjectMethod(cls, mid, rho_cast<jstring>(szPropName)); if (!result) return 0; jclass clsBoolean = getJNIClass(RHODES_JAVA_CLASS_BOOLEAN); jclass clsInteger = getJNIClass(RHODES_JAVA_CLASS_INTEGER); jclass clsFloat = getJNIClass(RHODES_JAVA_CLASS_FLOAT); jclass clsDouble = getJNIClass(RHODES_JAVA_CLASS_DOUBLE); jclass clsString = getJNIClass(RHODES_JAVA_CLASS_STRING); if (env->IsInstanceOf(result, clsBoolean)) { jmethodID midValue = getJNIClassMethod(env, clsBoolean, "booleanValue", "()Z"); *resValue = rho_ruby_create_boolean((int)env->CallBooleanMethod(result, midValue)); return 1; } else if (env->IsInstanceOf(result, clsInteger)) { jmethodID midValue = getJNIClassMethod(env, clsInteger, "intValue", "()I"); *resValue = rho_ruby_create_integer((int)env->CallIntMethod(result, midValue)); return 1; } else if (env->IsInstanceOf(result, clsFloat)) { jmethodID midValue = getJNIClassMethod(env, clsFloat, "floatValue", "()F"); *resValue = rho_ruby_create_double((double)env->CallFloatMethod(result, midValue)); return 1; } else if (env->IsInstanceOf(result, clsDouble)) { jmethodID midValue = getJNIClassMethod(env, clsDouble, "doubleValue", "()D"); *resValue = rho_ruby_create_double((double)env->CallDoubleMethod(result, midValue)); return 1; } else if (env->IsInstanceOf(result, clsString)) { jstring resStrObj = (jstring)result; *resValue = rho_ruby_create_string(rho_cast<std::string>(resStrObj).c_str()); return 1; } return 0; }
VALUE rho_cast_helper<VALUE, jint>::operator ()(JNIEnv *env, jint jValue) { return rho_ruby_create_integer(static_cast<int>(jValue)); }
VALUE rho_cast_helper<VALUE, jobject>::getInteger(jobject jInteger) { jint jRes = m_env->CallIntMethod(jInteger, midIntValue); return rho_ruby_create_integer(jRes); }
VALUE rho_sys_get_property(char* szPropName) { if (!szPropName || !*szPropName) return rho_ruby_get_NIL(); VALUE res; #ifdef RHODES_EMULATOR if (rho_simimpl_get_property(szPropName, &res)) return res; #endif if (rho_sysimpl_get_property(szPropName, &res)) return res; if (strcasecmp("platform",szPropName) == 0) return rho_ruby_create_string(rho_rhodesapp_getplatform()); if (strcasecmp("has_network",szPropName) == 0) return rho_sys_has_network(); if (strcasecmp("locale",szPropName) == 0) return rho_sys_get_locale(); if (strcasecmp("screen_width",szPropName) == 0) return rho_ruby_create_integer(rho_sys_get_screen_width()); if (strcasecmp("screen_height",szPropName) == 0) return rho_ruby_create_integer(rho_sys_get_screen_height()); if (strcasecmp("real_screen_width",szPropName) == 0) return rho_ruby_create_integer(rho_sys_get_screen_width()); if (strcasecmp("real_screen_height",szPropName) == 0) return rho_ruby_create_integer(rho_sys_get_screen_height()); if (strcasecmp("device_id",szPropName) == 0) { rho::String strDeviceID = ""; if ( rho::sync::CClientRegister::getInstance() ) strDeviceID = rho::sync::CClientRegister::getInstance()->getDevicePin(); return rho_ruby_create_string(strDeviceID.c_str()); } if (strcasecmp("phone_id", szPropName) == 0) return rho_ruby_create_string(""); if (strcasecmp("full_browser",szPropName) == 0) return rho_ruby_create_boolean(1); if (strcasecmp("rhodes_port",szPropName) == 0) return rho_ruby_create_integer(atoi(RHODESAPP().getFreeListeningPort())); if (strcasecmp("is_emulator",szPropName) == 0) return rho_ruby_create_boolean(0); if (strcasecmp("has_touchscreen",szPropName) == 0) return rho_ruby_create_boolean(1); if (strcasecmp("has_sqlite",szPropName) == 0) return rho_ruby_create_boolean(1); RAWLOG_ERROR1("Unknown Rho::System property : %s", szPropName); return rho_ruby_get_NIL(); }
VALUE rho_sys_get_property(char* szPropName) { if (!szPropName || !*szPropName) return rho_ruby_get_NIL(); VALUE res; #ifdef RHODES_EMULATOR if (rho_simimpl_get_property(szPropName, &res)) return res; #endif if (rho_sysimpl_get_property(szPropName, &res)) return res; if (strcasecmp("platform",szPropName) == 0) return rho_ruby_create_string(rho_rhodesapp_getplatform()); if (strcasecmp("has_network",szPropName) == 0) return rho_sys_has_network(); if (strcasecmp("locale",szPropName) == 0) return rho_sys_get_locale(); if (strcasecmp("screen_width",szPropName) == 0) return rho_ruby_create_integer(rho_sys_get_screen_width()); if (strcasecmp("screen_height",szPropName) == 0) return rho_ruby_create_integer(rho_sys_get_screen_height()); if (strcasecmp("real_screen_width",szPropName) == 0) return rho_ruby_create_integer(rho_sys_get_screen_width()); if (strcasecmp("real_screen_height",szPropName) == 0) return rho_ruby_create_integer(rho_sys_get_screen_height()); if (strcasecmp("device_id",szPropName) == 0) { rho::String strDeviceID = ""; if ( rho::sync::CClientRegister::getInstance() ) strDeviceID = rho::sync::CClientRegister::getInstance()->getDevicePin(); return rho_ruby_create_string(strDeviceID.c_str()); } if (strcasecmp("phone_id", szPropName) == 0) return rho_ruby_create_string(""); if (strcasecmp("full_browser",szPropName) == 0) return rho_ruby_create_boolean(1); if (strcasecmp("rhodes_port",szPropName) == 0) return rho_ruby_create_integer(atoi(RHODESAPP().getFreeListeningPort())); if (strcasecmp("free_server_port",szPropName) == 0) return rho_ruby_create_integer(RHODESAPP().determineFreeListeningPort()); if (strcasecmp("is_emulator",szPropName) == 0) return rho_ruby_create_boolean(0); if (strcasecmp("has_touchscreen",szPropName) == 0) return rho_ruby_create_boolean(1); if (strcasecmp("has_sqlite",szPropName) == 0) return rho_ruby_create_boolean(1); if (strcasecmp("security_token_not_passed",szPropName) == 0) { int passed = 0; if ((RHODESAPP().isSecurityTokenNotPassed())) { passed = 1; } return rho_ruby_create_boolean(passed); } if (strcasecmp("is_moto_device",szPropName) == 0) #ifdef APP_BUILD_CAPABILITY_MOTOROLA return rho_ruby_create_boolean(1); #else return rho_ruby_create_boolean(0); #endif RAWLOG_ERROR1("Unknown Rho::System property : %s", szPropName); return rho_ruby_get_NIL(); }
VALUE MethodResultJni::toRuby() { RAWTRACE("toRuby"); VALUE res = Qnil; JNIEnv *env = jniInit(); if (!env) { RAWLOG_FATAL("JNI initialization failed"); rb_raise(rb_eRuntimeError,"JNI initialization failed"); return Qnil; } int type = getResultType(env); switch(type) { case typeNone: break; case typeBoolean: { bool booleanResult = static_cast<bool>(getBooleanResult(env)); res = booleanResult ? Qtrue : Qfalse; } break; case typeInteger: { int intResult = static_cast<int>(getIntegerResult(env)); res = rho_ruby_create_integer(intResult); } break; case typeDouble: { double doubleResult = static_cast<double>(getDoubleResult(env)); res = rho_ruby_create_double(doubleResult); } break; case typeString: { jhstring jhStrResult = getStringResult(env); res = rho_cast<VALUE>(env, jhStrResult); } break; case typeList: { jhobject jhListResult = getListResult(env); res = rho_cast<VALUE>(env, jhListResult); } break; case typeMap: { jhobject jhMapResult = getMapResult(env); res = rho_cast<VALUE>(env, jhMapResult); } break; case typeArgError: rho_ruby_raise_argerror(getErrorMessage(env).c_str()); break; case typeError: rb_raise(rb_eRuntimeError, getErrorMessage(env).c_str()); break; default: RAWLOG_FATAL("Unknown runtime error in MethodResultJni class"); rb_raise(rb_eRuntimeError,"Unknown runtime error in MethodResultJni class"); } reset(env); return res; }