[BACK]Return to ox.k CVS log [TXT][DIR] Up to [local] / OpenXM / src / k097 / lib / ox

Annotation of OpenXM/src/k097/lib/ox/ox.k, Revision 1.5

1.5     ! takayama    1: /* $OpenXM: OpenXM/src/k097/lib/ox/ox.k,v 1.4 2000/12/11 13:53:28 takayama Exp $  */
1.3       takayama    2:
1.5     ! takayama    3: /* Load_sm1(["ox.sm1",AddString([GetEnv("OpenXM_HOME"),"/lib/sm1/ox.sm1"])],
        !             4:          "ox.sm1.loaded"); */
        !             5: Load_sm1(["oxasir.sm1",AddString([GetEnv("OpenXM_HOME"),
        !             6:           "/lib/sm1/oxasir.sm1"])],
        !             7:          "oxasir.sm1.loaded");
1.3       takayama    8:
                      9: class OXchannel extends Object {
                     10:   local channel;
                     11:   /* Just add a tag. */
1.5     ! takayama   12:   def getChannel() {
        !            13:     return(channel);
        !            14:   }
1.3       takayama   15:   def generate(c) {
                     16:     this = new();
                     17:     if (IsArray(c)) {
                     18:       if (c[0] != "client") {
                     19:          Error("OXchannel.generate(c) : c is not client object.");
                     20:       }
                     21:     }else{
                     22:       Error("OXchannel.generate(c) : c is not client object.");
                     23:     }
                     24:     channel = c;
                     25:     return(this);
                     26:   }
                     27:
                     28:   def pushCMO(ob) {
                     29:     local cc;
                     30:     cc = channel;
                     31:     sm1(" cc ob oxpushcmo ");
                     32:   }
                     33:
                     34:   def pushCMD(ob) {
                     35:     local cc;
                     36:     cc = channel;
                     37:     if (IsInteger(ob)) {
                     38:       ob = IntegerToSm1Integer(ob);
                     39:     }
1.4       takayama   40:     sm1(" [(oxPushCMD) cc ob] extension ");
1.3       takayama   41:   }
1.4       takayama   42:
                     43:   def popCMO() {
                     44:     local cc,r;
                     45:     cc = channel;
                     46:     sm1(" cc oxpopcmo /r set ");
                     47:     return(r);
                     48:   }
                     49:
1.3       takayama   50: }
1.1       takayama   51:
1.2       takayama   52: class OXcontrol extends Object {
                     53:   local control;
1.5     ! takayama   54:   def getControl() {
        !            55:     return(control);
        !            56:   }
1.3       takayama   57:   def generate(c) {
1.2       takayama   58:      if (Tag(c) != 0) {
                     59:        control = c;
                     60:        return(this);
                     61:      }else{
                     62:        return(start());
                     63:      }
                     64:   }
                     65:   def start() {
1.1       takayama   66:     local c,e, pass, peer, data, s, stmp;
                     67:     this = new(super.new0());
                     68:     sm1(" [(oxGenPass)] extension /pass set ");
                     69:     sm1(" [(oxGetPort1) (localhost)] extension /peer set ");
                     70:     sm1(" /data peer 1 get toString def ");
                     71:     s = AddString(
1.5     ! takayama   72:       [GetEnv("OpenXM_HOME"),
        !            73:        "/src/oxc/oxc",
1.1       takayama   74:        " -c ", pass, " -h "," localhost ", " -p ", data, " -x ",
                     75:        " & "]);
                     76:     sm1(" [ (/bin/csh -c \") s (\") ] cat /stmp set ");
                     77:     sm1(" stmp message ");
                     78:     sm1(" stmp system  ");
                     79:     sm1(" [(oxCreateControl_RFC_101) peer 0 pass] extension /c set ");
1.3       takayama   80:     control = OXchannel.generate(c);
1.1       takayama   81:     return(this);
1.2       takayama   82:   }
1.3       takayama   83:   def pushCMO(a) {
                     84:     control.channel.pushCMO(a);
                     85:   }
                     86:   def pushCMD(a) {
                     87:     control.channel.pushCMD(a);
                     88:   }
1.4       takayama   89:   def popCMO() {
                     90:     return(control.channel.popCMO());
                     91:   }
1.2       takayama   92:
1.1       takayama   93: }
                     94:
1.4       takayama   95: /* How to debug?
                     96:    sm1(" OX { vname } sendmsg /aaa set ");
                     97:    Get the value of vname in the context OX and set it to aaa.
                     98: */
1.1       takayama   99:
1.3       takayama  100: class OX extends OXcontrol {
1.5     ! takayama  101:   local engine, engineIDs;
        !           102:   def getEngine() {
        !           103:      return(engine);
        !           104:   }
        !           105:   def getEngineIDs() {
        !           106:      return(engineIDs);
        !           107:   }
        !           108:   /* OX.generate("ox_sm1"); or OX.generate("ox_sm1",null) */
        !           109:   def generate(name,control) {
1.2       takayama  110:     local c,e, pass, peer, data, s, stmp, engineID;
1.5     ! takayama  111:     if (Length(Arglist) == 0) {
        !           112:       name = "ox_sm1";  control = null;
        !           113:     }
        !           114:     if (Length(Arglist) == 1) {
        !           115:       control = null;
        !           116:     }
1.3       takayama  117:     this = new(super.generate(control));
1.5     ! takayama  118:     control = super.getControl();
1.2       takayama  119:     sm1(" [(oxGetPort1) (localhost)] extension /peer set ");
                    120:     sm1(" /data peer 1 get def ");
1.5     ! takayama  121:     control.pushCMO(data); /* BUG: control.pushCMO(data) does not work.
        !           122:                               Use control = super.getControl(); */
1.2       takayama  123:     control.pushCMO(name);
                    124:     control.pushCMD(SM_control_spawn_server);
                    125:     engineID = control.popCMO();
1.4       takayama  126:     print("engineID=");Println(engineID);
1.5     ! takayama  127:     if (Tag(engineID) == 257 ) {  /* error object */
        !           128:        Error("Server could be found.");
        !           129:     }
        !           130:     engineIDs = [engineID];
1.2       takayama  131:     sm1(" [(oxCreateEngine_RFC_101) peer 0 (Empty) engineID] extension /c set ");
1.3       takayama  132:     engine = OXchannel.generate(c);
1.2       takayama  133:     return(this);
1.3       takayama  134:   }
1.5     ! takayama  135:   def pushCMO(a) {
        !           136:     engine.channel.pushCMO(a);
        !           137:   }
        !           138:   def pushCMD(a) {
        !           139:     engine.channel.pushCMD(a);
        !           140:   }
        !           141:   def popCMO() {
        !           142:     return(engine.channel.popCMO());
        !           143:   }
1.2       takayama  144:
1.5     ! takayama  145:   def rpc(func,ar) {
        !           146:      local n,i,one,comm;
        !           147:      if (! IsString(func)) {
        !           148:        Error("The first argument of rpc must be a string.");
        !           149:      }
        !           150:      if (! IsArray(ar)) {
        !           151:        Error("The second argument of rpc must be a list.");
        !           152:      }
        !           153:      one = IntegerToSm1Integer(1);
        !           154:      sm1(" getVlist2 toString /comm set ");
        !           155:      comm = AddString(["OxVlist=",comm,";"]);
        !           156:      this.pushCMO(comm);
        !           157:      this.pushCMD(SM_executeStringByLocalParser);
        !           158:
        !           159:      this.pushCMO("print(OxVlist);");
        !           160:      this.pushCMD(SM_executeStringByLocalParser);
        !           161:
        !           162:      n = Length(ar);
        !           163:      for (i=n-1; i>=0; i--) {
        !           164:        this.pushCMO(ar[i]);
        !           165:        this.pushCMO(one);
        !           166:        this.pushCMO("ox_dtop");
        !           167:        this.pushCMD(SM_executeFunction);
        !           168:      }
        !           169:      this.pushCMO(IntegerToSm1Integer(n));
        !           170:      this.pushCMO(func);
        !           171:      this.pushCMD(SM_executeFunction);
        !           172:
        !           173:      this.pushCMO(one);
        !           174:      this.pushCMO("ox_ptod");
        !           175:      this.pushCMD(SM_executeFunction);
        !           176:      return(this.popCMO());
        !           177:   }
        !           178:
        !           179: }
        !           180:
        !           181: /*
        !           182:   Example:
        !           183:      a = startAsir();
        !           184:      f = a.rpc("fctr",[x^10-1]);
        !           185:      Println(f);
        !           186: */
        !           187: def startAsir() {
        !           188:   local a,asirpeer;
        !           189:   a = OX.generate("ox_asir");
        !           190:   asirpeer = (a.getEngine()).getChannel();
        !           191:   Println(asirpeer);
        !           192:   sm1(" [asirpeer oxasirpath.asirlib] loadAsirFile ");
        !           193:   return(a);
1.2       takayama  194: }
1.1       takayama  195:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>