platform/shared/rubyJVM/src/com/rho/RhoRuby.java in rhodes-1.5.5 vs platform/shared/rubyJVM/src/com/rho/RhoRuby.java in rhodes-2.0.0.beta1
- old
+ new
@@ -12,11 +12,13 @@
import com.rho.sync.SyncThread;
import com.rho.net.AsyncHttp;
import com.rho.Properties;
//import net.rim.device.api.system.CodeModuleManager;
import java.util.Hashtable;
+import java.util.Vector;
import com.rho.rjson.RJSONTokener;
+import com.rho.net.NetResponse;
public class RhoRuby {
private static final RhoLogger LOG = RhoLogger.RHO_STRIP_LOG ? new RhoEmptyLogger() :
new RhoLogger("RhoRuby");
@@ -26,10 +28,11 @@
public static final RubyID serveID = RubyID.intern("serve_hash");
public static final RubyID serveIndexID = RubyID.intern("serve_index_hash");
public static final RubyID raiseRhoError = RubyID.intern("raise_rhoerror");
public static final RubyID initApp = RubyID.intern("init_app");
public static final RubyID activateApp = RubyID.intern("activate_app");
+ public static final RubyID loadServerSources_mid = RubyID.intern("load_server_sources");
// public static final RubyID getStartPath = RubyID.intern("get_start_path");
// public static final RubyID getOptionsPath = RubyID.intern("get_options_path");
static RubyValue receiver;
@@ -58,22 +61,33 @@
{
if ( exc instanceof IOException )
{
String strMsg = exc.getMessage();
- return strMsg != null && (strMsg.indexOf("timed out") >= 0 || strMsg.indexOf("Timed out") >= 0)
- ? RhoRuby.ERR_NOSERVERRESPONSE : RhoRuby.ERR_NETWORK;
+ return strMsg != null && (strMsg.indexOf("timed out") >= 0 || strMsg.indexOf("Timed out") >= 0)
+ ? RhoRuby.ERR_NOSERVERRESPONSE : RhoRuby.ERR_NETWORK;
}
return ERR_NONE;
}
public static int getErrorCode(Exception exc)
{
return ERR_RUNTIME;
}
+ public static int getErrorFromResponse(NetResponse resp)
+ {
+ if ( resp.isUnathorized() )
+ return RhoRuby.ERR_UNATHORIZED;
+
+ if ( !resp.isOK() )
+ return RhoRuby.ERR_REMOTESERVER;
+
+ return RhoRuby.ERR_NONE;
+ }
+
public static String getErrorText(int nError)
{
if ( nError == ERR_NONE )
return "";
@@ -124,23 +138,24 @@
helper.initRubyExtensions();
//TODO: implement recursive dir creation
RhoClassFactory.createFile().getDirPath("apps");
RhoClassFactory.createFile().getDirPath("apps/public");
- RhoClassFactory.createFile().getDirPath("apps/public/db-files");
+ RhoClassFactory.createFile().getDirPath("db");
+ RhoClassFactory.createFile().getDirPath("db/db-files");
//Class mainRuby = Class.forName("xruby.ServeME.main");
- DBAdapter.getInstance().startTransaction();
+ //DBAdapter.startAllDBTransaction();
try{
mainObj = helper.createMainObject();//new xruby.ServeME.main();//(RubyProgram)mainRuby.newInstance();
receiver = mainObj.invoke();
if ( !rho_ruby_isValid() )
throw new RuntimeException("Initialize Rho framework failed.");
}finally
{
- DBAdapter.getInstance().commit();
+ //DBAdapter.commitAllDBTransaction();
}
// RubyModule modRhom = (RubyModule)RubyRuntime.ObjectClass.getConstant("Rhom");
}
@@ -150,14 +165,23 @@
public static void rho_ruby_activateApp(){
RubyAPI.callPublicNoArgMethod(receiver, null, activateApp);
}
+ public static void loadserversources(String strData){
+ RubyAPI.callPublicOneArgMethod(receiver, ObjectFactory.createString(strData), null, loadServerSources_mid);
+ }
+
public static boolean rho_ruby_isValid(){
return receiver!= null && receiver != RubyConstant.QNIL;
}
+ public static boolean isMainRubyThread()
+ {
+ return RubyThread.isMainThread();
+ }
+
public static void RhoRubyStop(){
receiver = null;
mainObj = null;
@@ -253,9 +277,23 @@
}
public static void add_to_array(RubyValue ar, RubyValue val)
{
((RubyArray)ar).add(val);
+ }
+
+ public static Vector makeVectorStringFromArray(RubyValue v)
+ {
+ Vector res = new Vector();
+
+ if ( v == RubyConstant.QNIL )
+ return res;
+
+ RubyArray ar = (RubyArray)v;
+ for ( int i = 0; i < ar.size(); i++ )
+ res.addElement(ar.get(i).toStr());
+
+ return res;
}
public static RubyValue addTimeToHash(RubyHash hash, String key, long val) {
return hash.add( ObjectFactory.createString(key), ObjectFactory.createTime(val) );
}