Ejemplo n.º 1
0
VALUE getallPhonebookRecords(void* pb) {
#if defined (_WIN32_WCE)//&& !defined( OS_PLATFORM_MOTCE )
	if (RHO_IS_WMDEVICE && pb) {
		CNativeAddressBook* phonebook = (CNativeAddressBook*)pb;
        VALUE valGc = rho_ruby_disable_gc();
        CHoldRubyValue hash(rho_ruby_createHash());
		
		std::vector<CABRecord*> records;
		phonebook->getAllRecords(records);
		while(records.size() > 0) {
			CABRecord* record = records.back();
			const char* rid = record->getValue("id").c_str();
			if (rid) {
				LOGC(TRACE,"Phonebook") + "Adding record " + rid;
				addHashToHash(hash,rid,_getRecord(record));
			}
			delete record;
			records.pop_back();
		}

        rho_ruby_enable_gc(valGc);
		return hash;
	}	
#endif
	return rho_ruby_get_NIL();	
}
Ejemplo 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);
#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)
    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 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

    }
}
Ejemplo n.º 3
0
bool CHttpServer::run()
{
    if (verbose) LOG(INFO) + "Start HTTP server";

    if (!init())
    {
        return false;
    }

    m_active = true;

    if (!m_started_as_separated_simple_server)
        RHODESAPP().notifyLocalServerStarted();

    for(;;) 
    {
        if (verbose) RAWTRACE("Waiting for connections...");
#ifndef RHO_NO_RUBY_API
        if (rho_ruby_is_started() && (!m_started_as_separated_simple_server))
            rho_ruby_start_threadidle();
#endif
        fd_set readfds;
        FD_ZERO(&readfds);
        FD_SET(m_listener, &readfds);

        timeval tv = {0,0};
        unsigned long nTimeout = RHODESAPP().getTimer().getNextTimeout();
        tv.tv_sec = nTimeout/1000;
        tv.tv_usec = (nTimeout - tv.tv_sec*1000)*1000;
        
        
        int ret = select(m_listener+1, &readfds, NULL, NULL, (tv.tv_sec == 0 && tv.tv_usec == 0 ? 0 : &tv) );
        
        //int errsv = errno;
        
#ifndef RHO_NO_RUBY_API
        if (rho_ruby_is_started() && (!m_started_as_separated_simple_server))
            rho_ruby_stop_threadidle();
#endif
        bool bProcessed = false;
        if (ret > 0) 
        {
            if (FD_ISSET(m_listener, &readfds))
            {
                //RAWTRACE("Before accept...");
                SOCKET conn = accept(m_listener, NULL, NULL);
                //RAWTRACE("After accept...");
                if (!m_active) {
                    if (verbose) RAWTRACE("Stop HTTP server");
                    return true;
                }
                if (conn == INVALID_SOCKET) {
        #if !defined(WINDOWS_PLATFORM)
                    if (RHO_NET_ERROR_CODE == EINTR)
                        continue;
        #endif
                    if (verbose) RAWLOG_ERROR1("Can not accept connection: %d", RHO_NET_ERROR_CODE);
                    return false;
                }

                if (verbose) RAWTRACE("Connection accepted, process it...");
                VALUE val;
#ifndef RHO_NO_RUBY_API                
                if (rho_ruby_is_started() && (!m_started_as_separated_simple_server))
                {
                    if ( !RHOCONF().getBool("enable_gc_while_request") )                
                        val = rho_ruby_disable_gc();
                }
#endif
                m_sock = conn;
                bProcessed = process(m_sock);
#ifndef RHO_NO_RUBY_API
                if (rho_ruby_is_started() && (!m_started_as_separated_simple_server))
                {
                    if ( !RHOCONF().getBool("enable_gc_while_request") )
                        rho_ruby_enable_gc(val);
                }
#endif
                if (verbose) RAWTRACE("Close connected socket");
                closesocket(m_sock);
                m_sock = INVALID_SOCKET;
            }
        }
        else if ( ret == 0 ) //timeout
        {
            bProcessed = RHODESAPP().getTimer().checkTimers();
        }
        else
        {
            if (verbose) RAWLOG_ERROR1("HTTP Server select error: %d", ret);
            continue;
            //return false;
        }
#ifndef RHO_NO_RUBY_API
        if (rho_ruby_is_started() && (!m_started_as_separated_simple_server))
        {
            if ( bProcessed )
            {
                if (verbose) {
                    LOG(INFO) + "GC Start.";
                }
                rb_gc();
                if (verbose) {
                    LOG(INFO) + "GC End.";
                }
            }
        }
#endif
    }
}
Ejemplo n.º 4
0
bool CDirectHttpRequestQueue::run( )
{
  m_server.m_pQueue = this;
  m_server.m_active = true;
  RHODESAPP().notifyLocalServerStarted();
  
  do
  {
      
      if (rho_ruby_is_started() ) {
          rho_ruby_start_threadidle();
      }
      
     m_thread.wait(-1);

      
      if (rho_ruby_is_started() ) {
          rho_ruby_stop_threadidle();
      }
      
    m_response = "";
    
    if ( m_request != 0 )
    {
      CHttpServer::ResponseWriter respWriter;
      m_server.m_localResponseWriter = &respWriter;
      
#ifndef RHO_NO_RUBY_API
      VALUE val;
      if (rho_ruby_is_started())
      {
        if ( !RHOCONF().getBool("enable_gc_while_request") )
        {
          val = rho_ruby_disable_gc();
        }
      }
#endif
      
      bool bProcessed = m_server.decide(
                                        m_request->method,
                                        m_request->uri,
                                        m_request->query,
                                        m_request->headers,
                                        m_request->body
                                        );
      
#ifndef RHO_NO_RUBY_API
      if (rho_ruby_is_started())
      {
        if ( !RHOCONF().getBool("enable_gc_while_request") )
        {
          rho_ruby_enable_gc(val);
        }
        
        if ( bProcessed )
        {
          LOG(INFO) + "GC Start.";
          rb_gc();
          LOG(INFO) + "GC End.";
        }
      }
#endif
      
      m_server.m_localResponseWriter = 0;
      
      m_response = respWriter.getResponse();
      
      pthread_cond_t* signal = m_request->signal;
      pthread_mutex_t* mutex = m_request->mutex;
      
      m_request->clear();
      m_request = 0;

      if ( (signal != 0) && (mutex!=0) )
      {
        pthread_mutex_lock(mutex);
        pthread_cond_signal(signal);
        pthread_mutex_unlock(mutex);
      }
    }
  }while (m_server.m_active);
  
  return true;
}
Ejemplo n.º 5
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

    }
}
Ejemplo n.º 6
0
RHO_GLOBAL VALUE getallPhonebookRecords(void* pb)
{
    if (logging_enable) RAWLOG_INFO("getallPhonebookRecords() START");
    jobject phonebookObj = (jobject)pb;

    JNIEnv *env = jnienv();

    jclass phonebookCls = getJNIClass(RHODES_JAVA_CLASS_PHONEBOOK);
    if (!phonebookCls) return Qnil;
    jclass contactCls = getJNIClass(RHODES_JAVA_CLASS_CONTACT);
    if (!contactCls) return Qnil;

    jmethodID phonebookPrepareFullListMID = getJNIClassMethod(env, phonebookCls, "prepareFullList", "()V");
    if (!phonebookPrepareFullListMID) return Qnil;

    jmethodID phonebookMoveToBeginMID = getJNIClassMethod(env, phonebookCls, "moveToBegin", "()V");
    if (!phonebookMoveToBeginMID) return Qnil;
    jmethodID hasNextMID = getJNIClassMethod(env, phonebookCls, "hasNext", "()Z");
    if (!hasNextMID) return Qnil;
    jmethodID nextMID = getJNIClassMethod(env, phonebookCls, "next", "()Ljava/lang/Object;");
    if (!nextMID) return Qnil;
    jmethodID contactIdMID = getJNIClassMethod(env, contactCls, "id", "()Ljava/lang/String;");
    if (!contactIdMID) return Qnil;

	jmethodID contactGetFieldMID = getJNIClassMethod(env, contactCls, "getField", "(I)Ljava/lang/String;");
	if (!contactGetFieldMID) return Qnil;


    env->CallVoidMethod(phonebookObj, phonebookPrepareFullListMID);

    // pb.moveToBegin();
    env->CallVoidMethod(phonebookObj, phonebookMoveToBeginMID);


    VALUE valGc = rho_ruby_disable_gc();
    CHoldRubyValue hash(rho_ruby_createHash());
    // while(pb.hasNext())
    while(env->CallBooleanMethod(phonebookObj, hasNextMID))
    {
        // Contact contact = (Contact)pb.next();
        jobject contactObj = env->CallObjectMethod(phonebookObj, nextMID);
        if (!contactObj) return Qnil;
        // String id = contact.id();
        jstring idObj = (jstring)env->CallObjectMethod(contactObj, contactIdMID);
        if (!idObj) return Qnil;

        //addHashToHash(hash, rho_cast<std::string>(idObj).c_str(), createHashFromContact(contactObj));
		CHoldRubyValue contactHash(rho_ruby_createHash());
		// contact.moveToBegin();

		int i;
		for (i = 0; i < PB_FIELDS_COUNT; i++) {
			jstring value = (jstring)env->CallObjectMethod(contactObj, contactGetFieldMID, i);
			if (value != NULL) {
				addStrToHash(contactHash, field_names[i], rho_cast<std::string>(value).c_str());
				env->DeleteLocalRef(value);
			}
		}

		addHashToHash(hash, rho_cast<std::string>(idObj).c_str(), contactHash);

        env->DeleteLocalRef(idObj);
        env->DeleteLocalRef(contactObj);
    }

    rho_ruby_enable_gc(valGc);
    if (logging_enable) RAWLOG_INFO("getallPhonebookRecords() FINISH");
    return hash;
}