Esempio n. 1
0
VALUE __rhoGetCurrentDir(void)
{
    return rb_str_new2(rho_native_rhopath());
}
Esempio n. 2
0
void RhoRubyStart()
{
    const char* szRoot = rho_native_rhopath();
    //VALUE moduleRhom;
#ifdef HAVE_LOCALE_H
    setlocale(LC_CTYPE, "");
#endif
    {
#ifdef ENABLE_RUBY_VM_STAT
        g_collect_stat = 1;
#endif

        RUBY_INIT_STACK;
        ruby_init();
#if defined(WIN32)
        rb_w32_sysinit(NULL,NULL);
#endif

#if defined(DEBUG)
        //enable_gc_profile();
#endif
        //rb_funcall(rb_mGC, rb_intern("stress="), 1, Qtrue);

        ruby_init_loadpath(szRoot);
#ifdef RHODES_EMULATOR
        {
            VALUE load_path = GET_VM()->load_path;
            char* app_path = malloc(strlen(szRoot)+100);

            rb_ary_clear(load_path);

            strcpy(app_path, szRoot);
            strcat(app_path, "app");

            rb_ary_push(load_path, rb_str_new2(app_path) );

            strcpy(app_path, rho_simconf_getRhodesPath());
            strcat(app_path, "/lib/framework");
            rb_ary_push(load_path, rb_str_new2(app_path) );
        }

#endif

        Init_strscan();
        Init_sqlite3_api();
        Init_GeoLocation();
        Init_SyncEngine();
        Init_AsyncHttp();
        Init_System();
        Init_Phonebook();
        Init_WebView();
        Init_RhoConf();
        Init_Alert();
        Init_SignatureCapture();
        Init_RhoBluetooth();
        Init_RhodesNativeViewManager();
        Init_Camera();
        Init_stringio();
        Init_DateTimePicker();
        Init_NativeBar();
        Init_RhoSupport();
        Init_MapView();
        Init_RingtoneManager();
        Init_socket();
        Init_NavBar();
        Init_RhoEvent();
        Init_Calendar();
//TODO: RhoSimulator  - load extensions dll dynamically
#if !defined(RHODES_EMULATOR) && !defined(RHO_SYMBIAN)
        Init_Extensions();
#endif //RHODES_EMULATOR

#ifdef ENABLE_RUBY_VM_STAT
        struct timeval  start;
        struct timeval  end;

        gettimeofday (&start, NULL);
#endif

#ifdef RHODES_EMULATOR
        rb_const_set(rb_cObject, rb_intern("RHODES_EMULATOR"), Qtrue);
        require_compiled(rb_str_new2("rhoframework"), &framework );
        framework = rb_const_get(rb_cObject,rb_intern("RHO_FRAMEWORK"));
#else
        {
            VALUE res = rho_ruby_disable_gc();
            require_compiled(rb_str_new2("rhoframework"), &framework );
            rho_ruby_enable_gc(res);
        }
#endif //RHODES_EMULATOR

        if ( framework == 0 || framework == Qnil )
        {
            RAWLOG_FATAL("RHO framework creating failed. Application will exit.");
        }

#ifdef ENABLE_RUBY_VM_STAT
        gettimeofday (&end, NULL);

        if ( end.tv_sec > 0 )
            g_require_compiled_msec += (end.tv_sec  - start.tv_sec) * 1000;
        else
            g_require_compiled_msec += (end.tv_usec - start.tv_usec)/1000;

#endif

        rb_gc_register_mark_object(framework);

        CONST_ID(framework_mid, "serve");
        CONST_ID(framework_mid2, "serve_index");
        CONST_ID(initApp_mid, "init_app");
        CONST_ID(onConfigConflicts_mid, "on_config_conflicts");
        CONST_ID(activateApp_mid, "activate_app");
        CONST_ID(deactivateApp_mid, "deactivate_app");
        CONST_ID(uiCreated_mid, "ui_created");
        CONST_ID(uiDestroyed_mid, "ui_destroyed");
        CONST_ID(loadServerSources_mid,"load_server_sources");
        CONST_ID(loadAllSyncSources_mid,"load_all_sync_sources");
        CONST_ID(resetDBOnSyncUserChanged_mid, "reset_db_on_sync_user_changed");

        //moduleRhom = rb_const_get(rb_cObject, rb_intern("Rhom"));

#ifdef ENABLE_RUBY_VM_STAT
        g_collect_stat = 0;
#endif

    }
}
Esempio n. 3
0
VALUE require_compiled(VALUE fname, VALUE* result, int bLoad)
{
    VALUE path;
    char* szName1 = 0;
    VALUE retval = Qtrue;
    
    if (TYPE(fname) != T_STRING)
        rb_raise(rb_eLoadError, "can not load non-string");

    szName1 = RSTRING_PTR(fname);

    if ( String_endsWith(szName1,".rb") ) 
    {
        rb_str_chop_bang(fname); rb_str_chop_bang(fname); rb_str_chop_bang(fname);
    }
    //rb_funcall(fname, rb_intern("sub!"), 2, rb_str_new2(".rb"), rb_str_new2("") );
    szName1 = RSTRING_PTR(fname);

    if ( strcmp("strscan",szName1)==0 || strcmp("enumerator",szName1)==0 ||
        strcmp("stringio",szName1)==0 || strcmp("socket",szName1)==0 )
        return Qtrue;

    RHO_LOCK(require_lock);

    if ( !bLoad && isAlreadyLoaded(fname) == Qtrue )
        goto RCompExit;

    path = find_file(fname);

    if ( path != 0 )
    {
        VALUE seq;

        RAWLOG_INFO1("require_compiled: %s", szName1);

        //optimize require
        //rb_ary_push(GET_VM()->loaded_features, path);
        rb_ary_push(GET_VM()->loaded_features, fname);

#ifdef RHODES_EMULATOR
        if ( strstr( RSTRING_PTR(path), ".rb") == 0 )
            rb_str_cat(path,".rb",3);

        GET_VM()->src_encoding_index = rb_utf8_encindex();
        rb_load(path, 0);

        if( rho_simconf_getBool("reload_app_changes") )
        {
            if ( strncmp( RSTRING_PTR(path), rho_native_rhopath(), strlen(rho_native_rhopath()) ) == 0 )
                rb_ary_delete(GET_VM()->loaded_features, fname);
        }
#else
        //rb_gc_disable();
        seq = loadISeqFromFile(path);
        

        //*result = rb_funcall(seq, rb_intern("eval"), 0 );
        *result = rb_iseq_eval(seq);
        
        //rb_gc_enable();
#endif
        goto RCompExit;
    }

    RAWLOG_ERROR1("require_compiled: error: can not find %s", RSTRING_PTR(fname));
    retval = Qnil;

RCompExit:
    RHO_UNLOCK(require_lock);
    return retval;
}
Esempio n. 4
0
static VALUE find_file(VALUE fname)
{
    VALUE res = 0;
    int nOK = 0;

    //RAWLOG_INFO1("find_file: fname: %s", RSTRING_PTR(fname));
#ifdef RHODES_EMULATOR
    if ( strncmp(RSTRING_PTR(fname), rho_simconf_getRhodesPath(), strlen(rho_simconf_getRhodesPath())) == 0 )
        res = fname;
    else
#endif

    if ( strncmp(RSTRING_PTR(fname), rho_native_rhopath(), strlen(rho_native_rhopath())) == 0 ){
        res = rb_str_dup(fname);
        rb_str_cat(res,RHO_RB_EXT,strlen(RHO_RB_EXT));
        //RAWLOG_INFO1("find_file: res: %s", RSTRING_PTR(res));
    } else if ( strncmp(RSTRING_PTR(fname), rho_native_reruntimepath(), strlen(rho_native_reruntimepath())) == 0 ){
        res = rb_str_dup(fname);
        rb_str_cat(res,RHO_RB_EXT,strlen(RHO_RB_EXT));
        //RAWLOG_INFO1("find_file: res: %s", RSTRING_PTR(res));
    }else{
        int i = 0;
        VALUE load_path = GET_VM()->load_path;
        //VALUE dir;
        VALUE fname1 = checkRhoBundleInPath(fname);
        //RAWLOG_INFO1("find_file: fname after checkRhoBundleInPath: %s", RSTRING_PTR(fname));

        //TODO: support document relative require in case of multiple apps
        if (RARRAY_LEN(load_path)>1){
            for( ; i < RARRAY_LEN(load_path); i++ ){
                VALUE dir = RARRAY_PTR(load_path)[i];

#ifdef RHODES_EMULATOR
                res = check_app_file_exist(dir, fname1, rho_simconf_getString("platform"));
#endif
                if ( !res )
                    res = check_app_file_exist(dir, fname1, 0 );

                if (res)
                {
                    nOK = 1;
                    break;
                }
            }
            if ( !nOK )
            {
#ifdef RHODES_EMULATOR
                //check for extensions
/*                res = rb_str_new2(rho_simconf_getRhodesPath() );
                rb_str_cat2(res,"/lib/extensions/");

                res = check_extension(res, fname, 1);
                if ( !res )
                {
                    res = rb_str_new2(rho_native_rhopath() );
                    rb_str_cat2(res,"/extensions/");

                    res = check_extension(res, fname,1);
                }

                if ( !res )
                {
                    res = rb_str_new2( rho_simconf_getString("ext_path") );
                    res = check_extension(res, fname, 0);
                }
*/
                const char* szPaths = rho_simconf_getString("ext_path");
                const char* szPath = szPaths;
                const char* szSep = strchr(szPath, ';');
                res = 0;
                for( ; szSep; szSep = strchr(szPath, ';') )
                {
                    res = rb_str_new( szPath, szSep-szPath);
                    rb_str_cat2(res,"/");
                    rb_str_append(res,fname);
                    rb_str_cat2(res,RHO_RB_EXT);

                    if ( eaccess(RSTRING_PTR(res), R_OK) == 0 )
                        break;

                    res = rb_str_new( szPath, szSep-szPath);
                    rb_str_cat2(res,"/app/");
                    rb_str_append(res,fname);
                    rb_str_cat2(res,RHO_RB_EXT);

                    if ( eaccess(RSTRING_PTR(res), R_OK) == 0 )
                        break;

                    res = 0;
                    szPath = szSep+1;
                }

                if( res )
                    nOK = 1;
                else
                    return 0;
#else
                return 0;
#endif
                
            }
        } /*else {
            dir = RARRAY_PTR(load_path)[RARRAY_LEN(load_path)-1];

            res = rb_str_dup(dir);
            rb_str_cat(res,"/",1);
            rb_str_cat(res,RSTRING_PTR(fname),RSTRING_LEN(fname));
            rb_str_cat(res,RHO_RB_EXT,strlen(RHO_RB_EXT));

            if ( g_curAppPath != 0 && eaccess(RSTRING_PTR(res), R_OK) != 0 ){
                res = rb_str_new2(g_curAppPath);
                rb_str_cat(res,"/",1);
                rb_str_cat(res,RSTRING_PTR(fname),RSTRING_LEN(fname));
                rb_str_cat(res,RHO_RB_EXT,strlen(RHO_RB_EXT));
            }
        } */
    }

    //RAWLOG_INFO1("find_file: RhoPreparePath: %s", RSTRING_PTR(res));
    res = RhoPreparePath(res);
    if ( !nOK )
        nOK = 1;//eaccess(RSTRING_PTR(res), R_OK) == 0 ? 1 : 0;

    return nOK ? res : 0;
}
Esempio n. 5
0
RHO_GLOBAL void JNICALL Java_com_rhomobile_rhodes_RhodesApplication_createRhodesApp
  (JNIEnv *env, jclass)
{
    // Start Rhodes application
    rho_rhodesapp_create(rho_native_rhopath());
}
Esempio n. 6
0
void RhoRubyStart()
{
    const char* szRoot = rho_native_rhopath();
    //VALUE moduleRhom;
#ifdef HAVE_LOCALE_H
    setlocale(LC_CTYPE, "");
#endif
    {
#ifdef ENABLE_RUBY_VM_STAT
        g_collect_stat = 1;
#endif

        RUBY_INIT_STACK;
        ruby_init();
#if defined(WIN32)
        rb_w32_sysinit(NULL,NULL);
#endif

#if defined(DEBUG)
        //enable_gc_profile();
#endif
        //rb_funcall(rb_mGC, rb_intern("stress="), 1, Qtrue);

        ruby_init_loadpath(szRoot);
#if defined(RHODES_EMULATOR) || defined(APP_BUILD_CAPABILITY_MOTOROLA) || defined(OS_WP8)
        {
            VALUE load_path = GET_VM()->load_path;
            char* app_path = malloc(strlen(szRoot)+100);

            rb_ary_clear(load_path);

            strcpy(app_path, szRoot);
#if defined(RHODES_EMULATOR)
            strcat(app_path, "app");
#elif defined(OS_WP8)
            strcat(app_path, "/apps/app");
#else
            strcat(app_path, "apps/app");
#endif
            rb_ary_push(load_path, rb_str_new2(app_path) );

#if defined(APP_BUILD_CAPABILITY_MOTOROLA)
            strcpy(app_path, rho_native_reruntimepath());
            strcat(app_path, "lib");
#elif defined(OS_WP8)
            strcpy(app_path, szRoot);
            strcat(app_path, "/lib");
#else
            strcpy(app_path, rho_simconf_getRhodesPath());
            strcat(app_path, "/lib/framework");
#endif
            rb_ary_push(load_path, rb_str_new2(app_path) );
        }

#endif

//DO not use it! Keeps for backward compatibility with ruby extensions. Use Rho::System.isRhoSimulator
#ifdef RHODES_EMULATOR
        rb_const_set(rb_cObject, rb_intern("RHODES_EMULATOR"), Qtrue);
#endif

#if !defined(OS_WP8)

        Init_strscan(); //+
        Init_GeoLocation(); //+

        Init_Phonebook();
#if !defined(OS_MACOSX) && !defined( OS_WINDOWS_DESKTOP ) && !defined(OS_WINCE) && !defined(OS_ANDROID)
        Init_WebView(); //+
#endif

#if !defined(RHO_NO_RUBY)
        Init_RhoConf(); //+
#endif

//#if !defined(OS_WINDOWS_DESKTOP) || defined(RHODES_EMULATOR)
//    Init_Alert();
//#endif

#if defined(WINDOWS_PLATFORM) && !defined(RHODES_EMULATOR) && !defined(RHODES_QT_PLATFORM)
        init_rhoext_Signature();
#else
        //Init_SignatureCapture();
#endif
        Init_RhoBluetooth();
        Init_RhodesNativeViewManager();
#if !defined(OS_MACOSX)
        Init_Camera();
#endif
        Init_stringio(); //+
        Init_DateTimePicker();
//#if !defined(WINDOWS_PLATFORM) && !defined(RHODES_EMULATOR) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
//    Init_NativeBar();
//#endif
        Init_RhoSupport(); //+
        Init_MapView();
        Init_RingtoneManager();
        Init_socket(); //+
//#if !defined(WINDOWS_PLATFORM) && !defined(RHODES_EMULATOR) && !defined(OS_MACOSX)
//    Init_NavBar();
//#endif
        Init_RhoEvent();
        Init_Calendar();
//#if !defined(OS_WINDOWS_DESKTOP) && !defined(RHODES_EMULATOR) && ! defined(OS_WINCE)
//    Init_Alert();
//#endif

#if defined(OS_MACOSX)
#ifndef RHO_DISABLE_OLD_CAMERA_SIGNATURE_API
        Init_Camera();
        Init_SignatureCapture();
#endif
#endif

#if defined(OS_ANDROID)
#ifndef RHO_DISABLE_OLD_CAMERA_SIGNATURE_API
        Init_SignatureCapture();
#endif
#endif

//TODO: RhoSimulator  - load extensions dll dynamically
#if !defined(RHO_SYMBIAN)
        Init_Extensions();
#endif //RHO_SYMBIAN

#else // OS_WP8 is set
        Init_strscan();
        Init_GeoLocation();
        Init_NavBar();
        Init_RhoSupport();
        Init_RhoConf();
        Init_Alert();

        Init_socket();
        Init_stringio();

        Init_Extensions();
#endif //OS_WP8

        extensions_loaded = 1;

        if ( rho_rcclient_have_rhoconnect_client() ) {
            rb_const_set(rb_cObject, rb_intern("RHOCONNECT_CLIENT_PRESENT"), Qtrue);
        }

        if (rho_is_remote_debug())
        {
            rb_const_set(rb_cObject, rb_intern("RHOSTUDIO_REMOTE_DEBUG"), Qtrue);
            rb_const_set(rb_cObject, rb_intern("RHOSTUDIO_REMOTE_HOST"), rho_ruby_create_string(rho_get_remote_debug_host()));
            rb_const_set(rb_cObject, rb_intern("RHOSTUDIO_REMOTE_APPPATH"), rho_ruby_create_string(rho_native_rhopath()));
        }
        else
        {
            rb_const_set(rb_cObject, rb_intern("RHOSTUDIO_REMOTE_DEBUG"), Qfalse);
        }

#if defined(APP_BUILD_CAPABILITY_MOTOROLA)
        rb_require("rhomotoapi");
#endif //APP_BUILD_CAPABILITY_MOTOROLA

#ifdef ENABLE_RUBY_VM_STAT
        struct timeval  start;
        struct timeval  end;

        gettimeofday (&start, NULL);
#endif

#ifdef RHODES_EMULATOR
        require_compiled(rb_str_new2("rhoframework"), &framework );
        framework = rb_const_get(rb_cObject,rb_intern("RHO_FRAMEWORK"));
#else
        {
            VALUE res = rho_ruby_disable_gc();

            require_compiled(rb_str_new2("rhoframework"), &framework );
            rho_ruby_enable_gc(res);
        }
#endif //RHODES_EMULATOR

        if ( framework == 0 || framework == Qnil )
        {
            RAWLOG_FATAL("RHO framework creating failed. Application will exit.");
        }

#ifdef ENABLE_RUBY_VM_STAT
        gettimeofday (&end, NULL);

        if ( end.tv_sec > 0 )
            g_require_compiled_msec += (end.tv_sec  - start.tv_sec) * 1000;
        else
            g_require_compiled_msec += (end.tv_usec - start.tv_usec)/1000;

#endif

        rb_gc_register_mark_object(framework);

        CONST_ID(framework_mid, "serve");
        CONST_ID(framework_mid2, "serve_index");
        CONST_ID(initApp_mid, "init_app");
        CONST_ID(onConfigConflicts_mid, "on_config_conflicts");
        CONST_ID(activateApp_mid, "activate_app");
        CONST_ID(deactivateApp_mid, "deactivate_app");
        CONST_ID(uiCreated_mid, "ui_created");
        CONST_ID(uiDestroyed_mid, "ui_destroyed");
        CONST_ID(loadServerSources_mid,"load_server_sources");
        CONST_ID(loadAllSyncSources_mid,"load_all_sync_sources");
        CONST_ID(resetDBOnSyncUserChanged_mid, "reset_db_on_sync_user_changed");

        //moduleRhom = rb_const_get(rb_cObject, rb_intern("Rhom"));

#ifdef ENABLE_RUBY_VM_STAT
        g_collect_stat = 0;
#endif

    }
}
Esempio n. 7
0
void RhoRubyStart()
{
    //VALUE moduleRhom;
#ifdef HAVE_LOCALE_H
    setlocale(LC_CTYPE, "");
#endif
    {
#ifdef ENABLE_RUBY_VM_STAT
        g_collect_stat = 1;
#endif

        RUBY_INIT_STACK;
        ruby_init();
#if defined(WIN32)
        rb_w32_sysinit(NULL,NULL);
#endif

#if defined(DEBUG)
        //enable_gc_profile();
#endif
        //rb_funcall(rb_mGC, rb_intern("stress="), 1, Qtrue);

        ruby_init_loadpath(rho_native_rhopath());
        Init_strscan();
        Init_sqlite3_api();
        Init_GeoLocation();
        Init_SyncEngine();
        Init_AsyncHttp();
        Init_System();
        Init_Phonebook();
        Init_WebView();
        Init_RhoConf();
        Init_Alert();
        Init_SignatureTool();
        Init_Camera();
        Init_stringio();
        Init_DateTimePicker();
        Init_NativeBar();
        Init_RhoSupport();
        Init_MapView();
        Init_RingtoneManager();
        Init_socket();
        Init_NavBar();
        Init_Extensions();

#ifdef ENABLE_RUBY_VM_STAT
        struct timeval  start;
        struct timeval  end;

        gettimeofday (&start, NULL);
#endif

        require_compiled(rb_str_new2("rhoframework"), &framework );

#ifdef ENABLE_RUBY_VM_STAT
        gettimeofday (&end, NULL);

        if ( end.tv_sec > 0 )
            g_require_compiled_msec += (end.tv_sec  - start.tv_sec) * 1000;
        else
            g_require_compiled_msec += (end.tv_usec - start.tv_usec)/1000;

#endif

        rb_gc_register_mark_object(framework);

        CONST_ID(framework_mid, "serve");
        CONST_ID(framework_mid2, "serve_index");
        CONST_ID(initApp_mid, "init_app");
        CONST_ID(activateApp_mid, "activate_app");
        CONST_ID(deactivateApp_mid, "deactivate_app");
        CONST_ID(loadServerSources_mid,"load_server_sources");

        //moduleRhom = rb_const_get(rb_cObject, rb_intern("Rhom"));

#ifdef ENABLE_RUBY_VM_STAT
        g_collect_stat = 0;
#endif

    }
}