예제 #1
0
RHO_GLOBAL VALUE get_camera_info(const char* camera_type) {
    
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_CAMERA);
    if (!cls) return rho_ruby_get_NIL();
    jmethodID mid_w = getJNIClassStaticMethod(env, cls, "getMaxCameraWidth", "(Ljava/lang/String;)I");
    jmethodID mid_h = getJNIClassStaticMethod(env, cls, "getMaxCameraHeight", "(Ljava/lang/String;)I");
    if ((!mid_w) || (!mid_h)) return rho_ruby_get_NIL();
    int w = env->CallStaticIntMethod(cls, mid_w, rho_cast<jhstring>(camera_type).get());
    int h = env->CallStaticIntMethod(cls, mid_h, rho_cast<jhstring>(camera_type).get());
    
    if ((w <= 0) || (h <= 0)) {
        return rho_ruby_get_NIL();
    }

    VALUE hash = rho_ruby_createHash();
    
    VALUE hash_max_resolution = rho_ruby_createHash();
    
    rho_ruby_add_to_hash(hash_max_resolution, rho_ruby_create_string("width"), rho_ruby_create_integer(w));
    rho_ruby_add_to_hash(hash_max_resolution, rho_ruby_create_string("height"), rho_ruby_create_integer(h));

    rho_ruby_add_to_hash(hash, rho_ruby_create_string("max_resolution"), hash_max_resolution);
    
    return hash;
}
예제 #2
0
파일: fileapi.cpp 프로젝트: croteb/rhodes
RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_file_RhoFileApi_nativeInit
  (JNIEnv *env, jclass)
{
    clsFileApi = getJNIClass(RHODES_JAVA_CLASS_RHOFILEAPI);
    if (!clsFileApi) return;
    midCopy = getJNIClassStaticMethod(env, clsFileApi, "copy", "(Ljava/lang/String;)Z");
    if (!midCopy) return;
    midOpen = getJNIClassStaticMethod(env, clsFileApi, "openInPackage", "(Ljava/lang/String;)Ljava/io/InputStream;");
    if (!midOpen) return;
    midClose = getJNIClassStaticMethod(env, clsFileApi, "close", "(Ljava/io/InputStream;)V");
    if (!midClose) return;
    midRead = getJNIClassStaticMethod(env, clsFileApi, "read", "(Ljava/io/InputStream;[B)I");
    if (!midRead) return;
    midSeek = getJNIClassStaticMethod(env, clsFileApi, "seek", "(Ljava/io/InputStream;I)V");
    if (!midSeek) return;

    const char *libc = "/system/lib/libc.so";
    void *pc = dlopen(libc, RTLD_LAZY);
    __sflags = (func_sflags_t)dlsym(pc, "__sflags");
    __sfp = (func_sfp_t)dlsym(pc, "__sfp");
    real_access = (func_access_t)dlsym(pc, "access");
    real_close = (func_close_t)dlsym(pc, "close");
    real_dup = (func_dup_t)dlsym(pc, "dup");
    real_dup2 = (func_dup2_t)dlsym(pc, "dup2");
    real_fchdir = (func_fchdir_t)dlsym(pc, "fchdir");
    real_fcntl = (func_fcntl_t)dlsym(pc, "fcntl");
    real_fdatasync = (func_fdatasync_t)dlsym(pc, "fdatasync");
    real_flock = (func_flock_t)dlsym(pc, "flock");
    real_fstat = (func_fstat_t)dlsym(pc, "fstat");
    real_fsync = (func_fsync_t)dlsym(pc, "fsync");
    real_ftruncate = (func_ftruncate_t)dlsym(pc, "ftruncate");
    real_lseek = (func_lseek_t)dlsym(pc, "lseek");
    real_lseek64 = (func_lseek64_t)dlsym(pc, "lseek64");
    real_lstat = (func_lstat_t)dlsym(pc, "lstat");
    real_open = (func_open_t)dlsym(pc, "open");
    real_read = (func_read_t)dlsym(pc, "read");
    real_select = (func_select_t)dlsym(pc, "select");
    real_stat = (func_stat_t)dlsym(pc, "stat");
    real_unlink = (func_unlink_t)dlsym(pc, "unlink");
    real_write = (func_write_t)dlsym(pc, "write");
    dlclose(pc);

    // This is just to get typical stat of file
    std::string librhodes = rho_root_path() + "../lib/librhodes.so";
    real_stat(librhodes.c_str(), &librhodes_st);
    librhodes_st.st_mode = S_IFREG|S_IRWXU;
    librhodes_st.st_nlink = 1;
    librhodes_st.st_uid = getuid();
    librhodes_st.st_gid = getgid();
}
예제 #3
0
RHO_GLOBAL VALUE rho_bluetooth_session_read_data(const char* connected_device_name) {
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHOBLUETOOTHMANAGER);
    if (!cls) return 0;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "session_read_data", "(Ljava/lang/String;[BI)I");
    if (!mid) return 0;
    jhstring objStr1 = rho_cast<jstring>(env, connected_device_name);

    int buf_size = env->CallStaticIntMethod(cls, mid, objStr1.get(), 0, 0);

    if (buf_size == 0) {
        // nothing for receive
        return rho_ruby_get_NIL();
    }

    jholder<jbyteArray> buf_j = jholder<jbyteArray>(env->NewByteArray(buf_size));
    int real_readed = env->CallStaticIntMethod(cls, mid, objStr1.get(), buf_j.get(), buf_size);

    jbyte* buf_p = env->GetByteArrayElements(buf_j.get(), 0);
 
    VALUE val = rho_ruby_create_byte_array((unsigned char*)buf_p, real_readed);

    env->ReleaseByteArrayElements(buf_j.get(), buf_p, 0); 

    return val;
}
예제 #4
0
RHO_GLOBAL void rho_bluetooth_session_write_data(const char* connected_device_name, VALUE data) {
    int size = rho_ruby_unpack_byte_array(data, 0, 0);
    if (size <= 0) {
	return;
    }

    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHOBLUETOOTHMANAGER);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "session_write_data", "(Ljava/lang/String;[BI)V");
    if (!mid) return;
    jhstring objStr1 = rho_cast<jstring>(env, connected_device_name);

    jbyteArray buf_j = env->NewByteArray(size);
    jbyte* buf_p = env->GetByteArrayElements(buf_j, 0);

    size = rho_ruby_unpack_byte_array(data, (unsigned char*)buf_p, size);

    env->ReleaseByteArrayElements(buf_j, buf_p, 0);

    env->CallStaticVoidMethod(cls, mid, objStr1.get(), buf_j, size);

    env->DeleteLocalRef(buf_j);

}
예제 #5
0
void MethodResultJni::callJSBack(jint jTabIndex)
{
    RAWTRACE(__FUNCTION__);

    jhstring jhStrCallbackID = getStrCallback(m_env);
    String strCallbackID = rho_cast<String>(m_env, jhStrCallbackID.get());

    jhstring jhCallbackData = getStrCallbackData(m_env);
    String strCallbackData = rho_cast<String>(m_env, jhCallbackData.get());

    String strRes(CMethodResultConvertor().toJSON(*this));

    String strCallback("Rho.callbackHandler( \"");
    strCallback += strCallbackID;
    strCallback += "\", {";
    strCallback += strRes;
    strCallback += "},\"";
    strCallback += strCallbackData;
    strCallback += "\")";

    jclass cls = getJNIClass(RHODES_JAVA_CLASS_WEB_VIEW);
    if (!cls) return;
    static jmethodID mid = getJNIClassStaticMethod(m_env, cls, "executeJs", "(Ljava/lang/String;I)V");
    if (!mid) return;

    jhstring jhCallback = rho_cast<jstring>(m_env, strCallback);
    m_env->CallStaticVoidMethod(cls, mid, jhCallback.get(), jTabIndex);
}
예제 #6
0
파일: event.cpp 프로젝트: JerryFLane/rhodes
RHO_GLOBAL VALUE event_fetch_by_id(const char *id)
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_EVENT_STORE);
    if (!cls) return Qnil;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "fetch", "(Ljava/lang/String;)Ljava/lang/Object;");
    if (!mid) return Qnil;
    jclass clsString = getJNIClass(RHODES_JAVA_CLASS_STRING);
    if (!clsString) return Qnil;

    RHO_TRACE("event_fetch_by_id (1)");
    jhstring jId = rho_cast<jhstring>(env, id);
    RHO_TRACE("event_fetch_by_id (2)");
    jhobject jRet = jhobject(env->CallStaticObjectMethod(cls, mid, jId.get()));
    RHO_TRACE("event_fetch_by_id (3)");
    if (env->IsInstanceOf(jRet.get(), clsString))
    {
        RHO_TRACE("event_fetch_by_id (3.1)");
        std::string error = rho_cast<std::string>(env, (jstring)jRet.get());
        RHO_TRACE("event_fetch_by_id (3.2)");
        rb_raise(rb_eRuntimeError, "Can't fetch event with id %s: %s", id, error.c_str());
        return Qnil;
    }
    VALUE rEvent = event_cast<VALUE>(jRet.get());
    RHO_TRACE("event_fetch_by_id (4)");
    return rEvent;
}
예제 #7
0
RHO_GLOBAL void rho_signature_take(char* callback_url, rho_param* p)
{

    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_SIGNATURE);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "takeSignature", "(Ljava/lang/String;Ljava/lang/Object;)V");
    if (!mid) return;
    jhstring objCallback = rho_cast<jhstring>(callback_url);

    /*
    char* image_format = 0;
    if (p)
    {
        rho_param* pFF = rho_param_hash_get(p, "imageFormat");
        if ( pFF )
            image_format = pFF->v.string;
    }
    if (!image_format)
        image_format = "";

    jhstring objFormat = rho_cast<jhstring>(image_format);
    env->CallStaticVoidMethod(cls, mid, objCallback.get(), objFormat.get());
     */
    
    jobject paramsObj = RhoValueConverter(env).createObject(p);
    env->CallStaticVoidMethod(cls, mid, objCallback.get(), paramsObj);
    env->DeleteLocalRef(paramsObj);
    
    
    
}
예제 #8
0
RHO_GLOBAL void take_picture(char* callback_url, rho_param *options_hash )
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_CAMERA);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "takePicture", "(Ljava/lang/String;Ljava/lang/Object;)V");
    if (!mid) return;

    if ((options_hash != NULL) && (options_hash->type != RHO_PARAM_HASH)) {
        RAWLOG_ERROR("Unexpected parameter type, should be Hash");
        return;
    }

    jobject paramsObj = NULL;
    if (options_hash != NULL) { 
         paramsObj = RhoValueConverter(env).createObject(options_hash);
    }
    
    env->CallStaticVoidMethod(cls, mid, rho_cast<jhstring>(callback_url).get(), paramsObj);

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

}
예제 #9
0
파일: event.cpp 프로젝트: JerryFLane/rhodes
RHO_GLOBAL const char* event_save(VALUE rEvent)
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_EVENT_STORE);
    if (!cls) return NULL;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "save", "(Lcom/rhomobile/rhodes/event/Event;)Ljava/lang/String;");
    if (!mid) return NULL;

    jobject jEvent = event_cast<jobject>(rEvent);
    jstring new_id = (jstring)env->CallStaticObjectMethod(cls, mid, jEvent);
    env->DeleteLocalRef(jEvent);

    //if (jError)
    //{
    //    std::string error = rho_cast<std::string>(env, jError);
    //   env->DeleteLocalRef(jError);
    //    rb_raise(rb_eRuntimeError, "Event save failed: %s", error.c_str());
    //}
    if (new_id) {
        return_string = rho_cast<std::string>(env, new_id);
        env->DeleteLocalRef(new_id);
        return return_string.c_str();
    }
    return NULL;
}
예제 #10
0
RHO_GLOBAL void ringtone_manager_stop()
{
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RINGTONE_MANAGER);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(cls, "stop", "()V");
    if (!mid) return;
    jnienv()->CallStaticVoidMethod(cls, mid);
}
예제 #11
0
RHO_GLOBAL int rho_sys_set_sleeping(int sleeping) {
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES_SERVICE);
    if (!cls) return 0;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "rho_sys_set_sleeping", "(I)I");
    if (!mid) return 0;
    return env->CallStaticIntMethod(cls, mid, sleeping);
}
예제 #12
0
RHO_GLOBAL int rho_bluetooth_is_bluetooth_available() {
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHOBLUETOOTHMANAGER);
    if (!cls) return 0;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "is_bluetooth_available", "()I");
    if (!mid) return 0;
    return env->CallStaticIntMethod(cls, mid);
}
예제 #13
0
RHO_GLOBAL void rho_bluetooth_off_bluetooth() {
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHOBLUETOOTHMANAGER);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "off_bluetooth", "()V");
    if (!mid) return;
    env->CallStaticVoidMethod(cls, mid);
}
예제 #14
0
파일: callbacks.cpp 프로젝트: sumitk/rhodes
RHO_GLOBAL void rho_sys_app_exit()
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "exit", "()V");
    if (!mid) return;
    env->CallStaticVoidMethod(cls, mid);
}
예제 #15
0
RHO_GLOBAL void alert_hide_popup()
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_ALERT);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "hidePopup", "()V");
    if (!mid) return;
    env->CallStaticVoidMethod(cls, mid);
}
예제 #16
0
RHO_GLOBAL int rho_bluetooth_session_get_status(const char* connected_device_name) {
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHOBLUETOOTHMANAGER);
    if (!cls) return 0;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "session_get_status", "(Ljava/lang/String;)I");
    if (!mid) return 0;
    jhstring objStr1 = rho_cast<jstring>(env, connected_device_name);
    return env->CallStaticIntMethod(cls, mid, objStr1.get());
}
예제 #17
0
RHO_GLOBAL void choose_picture(char* callback_url, rho_param *options_hash)
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_CAMERA);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "choosePicture", "(Ljava/lang/String;)V");
    if (!mid) return;
    env->CallStaticVoidMethod(cls, mid, rho_cast<jhstring>(callback_url).get());
}
예제 #18
0
RHO_GLOBAL void rho_bluetooth_set_device_name(const char* device_name) {
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHOBLUETOOTHMANAGER);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "set_device_name", "(Ljava/lang/String;)V");
    if (!mid) return;
    jhstring objDeviceName = rho_cast<jstring>(env, device_name);
    env->CallStaticVoidMethod(cls, mid, objDeviceName.get());
}
예제 #19
0
RHO_GLOBAL void rho_webview_refresh(int index)
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_WEB_VIEW);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "refresh", "(I)V");
    if (!mid) return;
    env->CallStaticVoidMethod(cls, mid, index);
}
예제 #20
0
RHO_GLOBAL void rho_sys_app_uninstall(const char *appname)
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES_SERVICE);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "uninstallApplication", "(Ljava/lang/String;)V");
    if (!mid) return;
    env->CallStaticVoidMethod(cls, mid, rho_cast<jhstring>(appname).get());
}
예제 #21
0
RHO_GLOBAL int rho_sys_is_app_installed(const char *appname)
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES_SERVICE);
    if (!cls) return 0;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "isAppInstalled", "(Ljava/lang/String;)Z");
    if (!mid) return 0;
    return (int)env->CallStaticBooleanMethod(cls, mid, rho_cast<jhstring>(appname).get());
}
예제 #22
0
RHO_GLOBAL void rho_sys_open_url(const char *url)
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES_SERVICE);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "openExternalUrl", "(Ljava/lang/String;)V");
    if (!mid) return;
    env->CallStaticVoidMethod(cls, mid, rho_cast<jhstring>(url).get());
}
예제 #23
0
RHO_GLOBAL void rho_sys_bring_to_front()
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES_SERVICE);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "bringToFront", "()V");
    if (!mid) return;
    env->CallStaticVoidMethod(cls, mid);
}
예제 #24
0
RHO_GLOBAL const char* rho_bluetooth_stop_current_connection_process() {
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHOBLUETOOTHMANAGER);
    if (!cls) return 0;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "stop_current_connection_process", "()V");
    if (!mid) return 0;
    env->CallStaticObjectMethod(cls, mid);
    return "OK";
}
예제 #25
0
RHO_GLOBAL void rho_webview_navigate_back()
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_WEB_VIEW);
    if (!cls) return;
    jmethodID mid =getJNIClassStaticMethod(env, cls, "navigateBack", "()V");
    if (!mid) return;
    env->CallStaticVoidMethod(cls, mid);
}
예제 #26
0
파일: callbacks.cpp 프로젝트: sumitk/rhodes
RHO_GLOBAL VALUE rho_sys_has_network()
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES);
    if (!cls) return rho_ruby_create_boolean(0);
    jmethodID mid = getJNIClassStaticMethod(env, cls, "hasNetwork", "()Z");
    if (!mid) return rho_ruby_create_boolean(0);
    return rho_ruby_create_boolean(env->CallStaticBooleanMethod(cls, mid));
}
예제 #27
0
RHO_GLOBAL int rho_net_ping_network(const char* szHost)
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES_SERVICE);
    if (!cls) return 0;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "pingHost", "(Ljava/lang/String;)Z");
    if (!mid) return 0;
	return (int)env->CallStaticBooleanMethod(cls, mid, rho_cast<jhstring>(szHost).get());
}
예제 #28
0
RHO_GLOBAL void rho_sys_report_app_started()
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES_SERVICE);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "handleAppStarted", "()V");
    if (!mid) return;
    env->CallStaticVoidMethod(cls, mid);
}
예제 #29
0
RHO_GLOBAL void rho_webview_full_screen_mode(int enable)
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES_SERVICE);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "setFullscreen", "(Z)V");
    if (!mid) return;
    env->CallStaticVoidMethod(cls, mid, enable);
}
예제 #30
0
RHO_GLOBAL void rho_conf_show_log()
{
    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_RHODES_SERVICE);
    if (!cls) return;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "showLogView", "()V");
    if (!mid) return;

    env->CallStaticVoidMethod(cls, mid);
}