[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.14

1.14    ! takayama    1: /* $OpenXM: OpenXM/src/k097/lib/ox/ox.k,v 1.13 2008/01/28 00:13:45 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:
1.12      takayama    9: def oxGetClientList() {
                     10:   local clist;
                     11:   sm1(" [(oxGetClientList)] extension /clist set ");
                     12:   return( clist );
                     13: }
                     14:
1.3       takayama   15: class OXchannel extends Object {
                     16:   local channel;
                     17:   /* Just add a tag. */
1.5       takayama   18:   def getChannel() {
                     19:     return(channel);
                     20:   }
1.3       takayama   21:   def generate(c) {
                     22:     this = new();
                     23:     if (IsArray(c)) {
                     24:       if (c[0] != "client") {
                     25:          Error("OXchannel.generate(c) : c is not client object.");
                     26:       }
                     27:     }else{
                     28:       Error("OXchannel.generate(c) : c is not client object.");
                     29:     }
                     30:     channel = c;
                     31:     return(this);
                     32:   }
                     33:
                     34:   def pushCMO(ob) {
                     35:     local cc;
                     36:     cc = channel;
                     37:     sm1(" cc ob oxpushcmo ");
                     38:   }
                     39:
                     40:   def pushCMD(ob) {
                     41:     local cc;
                     42:     cc = channel;
                     43:     if (IsInteger(ob)) {
                     44:       ob = IntegerToSm1Integer(ob);
                     45:     }
1.4       takayama   46:     sm1(" [(oxPushCMD) cc ob] extension ");
1.3       takayama   47:   }
1.4       takayama   48:
                     49:   def popCMO() {
                     50:     local cc,r;
                     51:     cc = channel;
                     52:     sm1(" cc oxpopcmo /r set ");
                     53:     return(r);
                     54:   }
                     55:
1.7       takayama   56:   def popString() {
                     57:     local cc,r;
                     58:     cc = channel;
                     59:     sm1(" cc oxpopstring /r set ");
                     60:     return(r);
                     61:   }
                     62:
                     63:
1.3       takayama   64: }
1.1       takayama   65:
1.2       takayama   66: class OXcontrol extends Object {
                     67:   local control;
1.5       takayama   68:   def getControl() {
                     69:     return(control);
                     70:   }
1.11      takayama   71:   def generate(c,useX) {
                     72:      if (Length(Arglist) <= 1) {
                     73:        useX = true;
                     74:      }
1.2       takayama   75:      if (Tag(c) != 0) {
                     76:        control = c;
                     77:        return(this);
                     78:      }else{
1.11      takayama   79:        return(start(useX));
1.2       takayama   80:      }
                     81:   }
1.11      takayama   82:   def start(useX) {
                     83:     local c,e, pass, peer, data, s, stmp, xopt;
                     84:     if (Length(Arglist) == 0) {
                     85:        useX = true;
                     86:     }
                     87:     if (useX) {
                     88:         xopt = " -x ";
                     89:     }else{
                     90:         xopt = "  ";
                     91:     }
1.10      takayama   92:     this = new(Object.new0());
1.1       takayama   93:     sm1(" [(oxGenPass)] extension /pass set ");
                     94:     sm1(" [(oxGetPort1) (localhost)] extension /peer set ");
                     95:     sm1(" /data peer 1 get toString def ");
                     96:     s = AddString(
1.5       takayama   97:       [GetEnv("OpenXM_HOME"),
1.8       takayama   98:        "/bin/oxc",
1.11      takayama   99:        " -c ", pass, " -h "," localhost ", " -p ", data, xopt,
1.1       takayama  100:        " & "]);
1.13      takayama  101:     sm1(" [ (/bin/sh -c \") s (\") ] cat /stmp set ");
1.1       takayama  102:     sm1(" stmp message ");
                    103:     sm1(" stmp system  ");
                    104:     sm1(" [(oxCreateControl_RFC_101) peer 0 pass] extension /c set ");
1.3       takayama  105:     control = OXchannel.generate(c);
1.1       takayama  106:     return(this);
1.2       takayama  107:   }
1.3       takayama  108:   def pushCMO(a) {
                    109:     control.channel.pushCMO(a);
                    110:   }
                    111:   def pushCMD(a) {
                    112:     control.channel.pushCMD(a);
                    113:   }
1.4       takayama  114:   def popCMO() {
                    115:     return(control.channel.popCMO());
                    116:   }
1.7       takayama  117:   def popString() {
                    118:     return(control.channel.popString());
                    119:   }
1.2       takayama  120:
1.1       takayama  121: }
                    122:
1.4       takayama  123: /* How to debug?
                    124:    sm1(" OX { vname } sendmsg /aaa set ");
                    125:    Get the value of vname in the context OX and set it to aaa.
                    126: */
1.1       takayama  127:
1.3       takayama  128: class OX extends OXcontrol {
1.5       takayama  129:   local engine, engineIDs;
                    130:   def getEngine() {
                    131:      return(engine);
                    132:   }
                    133:   def getEngineIDs() {
                    134:      return(engineIDs);
                    135:   }
                    136:   /* OX.generate("ox_sm1"); or OX.generate("ox_sm1",null) */
1.11      takayama  137:   def generate(name,control,useX) {
                    138:     local c,e, pass, peer, data, s, stmp, engineID,nn;
                    139:     nn = Length(Arglist);
                    140:     if (nn == 0) {
                    141:       name = "ox_sm1";  control = null; useX = true;
                    142:     }
                    143:     if (nn == 1) {
                    144:       control = null; useX = true;
1.5       takayama  145:     }
1.11      takayama  146:     if (nn == 2) {
                    147:       useX = true;
1.5       takayama  148:     }
1.11      takayama  149:     this = new(OXcontrol.generate(control,useX));
1.10      takayama  150:     control = this.getControl();
1.2       takayama  151:     sm1(" [(oxGetPort1) (localhost)] extension /peer set ");
                    152:     sm1(" /data peer 1 get def ");
1.6       takayama  153:     /* BUG: control.pushCMO(data) does not work.
                    154:             Use control = super.getControl(); */
                    155:     control.pushCMO([[data],name]);
1.2       takayama  156:     control.pushCMD(SM_control_spawn_server);
                    157:     engineID = control.popCMO();
1.4       takayama  158:     print("engineID=");Println(engineID);
1.5       takayama  159:     if (Tag(engineID) == 257 ) {  /* error object */
                    160:        Error("Server could be found.");
                    161:     }
                    162:     engineIDs = [engineID];
1.2       takayama  163:     sm1(" [(oxCreateEngine_RFC_101) peer 0 (Empty) engineID] extension /c set ");
1.3       takayama  164:     engine = OXchannel.generate(c);
1.2       takayama  165:     return(this);
1.3       takayama  166:   }
1.5       takayama  167:   def pushCMO(a) {
                    168:     engine.channel.pushCMO(a);
                    169:   }
                    170:   def pushCMD(a) {
                    171:     engine.channel.pushCMD(a);
                    172:   }
                    173:   def popCMO() {
                    174:     return(engine.channel.popCMO());
                    175:   }
1.7       takayama  176:   def popString() {
                    177:     return(engine.channel.popString());
                    178:   }
1.2       takayama  179:
1.9       takayama  180:   def rpc_submit(func,ar) {
1.5       takayama  181:      local n,i,one,comm;
                    182:      if (! IsString(func)) {
                    183:        Error("The first argument of rpc must be a string.");
                    184:      }
                    185:      if (! IsArray(ar)) {
                    186:        Error("The second argument of rpc must be a list.");
                    187:      }
                    188:      one = IntegerToSm1Integer(1);
                    189:      sm1(" getVlist2 toString /comm set ");
                    190:      comm = AddString(["OxVlist=",comm,";"]);
                    191:      this.pushCMO(comm);
                    192:      this.pushCMD(SM_executeStringByLocalParser);
                    193:
                    194:      this.pushCMO("print(OxVlist);");
                    195:      this.pushCMD(SM_executeStringByLocalParser);
                    196:
                    197:      n = Length(ar);
                    198:      for (i=n-1; i>=0; i--) {
                    199:        this.pushCMO(ar[i]);
                    200:        this.pushCMO(one);
                    201:        this.pushCMO("ox_dtop");
                    202:        this.pushCMD(SM_executeFunction);
                    203:      }
                    204:      this.pushCMO(IntegerToSm1Integer(n));
                    205:      this.pushCMO(func);
                    206:      this.pushCMD(SM_executeFunction);
                    207:
1.9       takayama  208:   }
                    209:
                    210:   def rpc(func,ar) {
                    211:      local one;
                    212:      sm1(" /one 1 def ");
                    213:      rpc_submit(func,ar);
1.5       takayama  214:      this.pushCMO(one);
                    215:      this.pushCMO("ox_ptod");
                    216:      this.pushCMD(SM_executeFunction);
                    217:      return(this.popCMO());
1.7       takayama  218:   }
1.9       takayama  219:
                    220:   def rpc_str(func,ar) {
                    221:      rpc_submit(func,ar);
                    222:      return(this.popString());
                    223:   }
1.7       takayama  224:   def executeString(s) {
                    225:      this.pushCMO(s);
                    226:      this.pushCMD(SM_executeStringByLocalParser);
1.5       takayama  227:   }
                    228: }
                    229:
                    230: /*
                    231:   Example:
                    232:      a = startAsir();
                    233:      f = a.rpc("fctr",[x^10-1]);
                    234:      Println(f);
                    235: */
                    236: def startAsir() {
1.11      takayama  237:   return(Asir.generate());
1.2       takayama  238: }
1.1       takayama  239:
1.10      takayama  240: class Asir extends OX {
                    241:   local ;
1.11      takayama  242:   def generate(useX) {
1.10      takayama  243:     local asirpeer,a;
1.11      takayama  244:     if (Length(Arglist) == 0) { useX = true; }
                    245:     this = new(OX.generate("ox_asir",null,useX));
1.10      takayama  246:     a = this;
                    247:     asirpeer = (a.getEngine()).getChannel();
                    248:     Println(asirpeer);
                    249:     sm1(" [asirpeer oxasirpath.asirlib] loadAsirFile ");
                    250:     return(this);
1.11      takayama  251:   }
                    252:   def OnTimer() {
                    253:     local a;
                    254:     a = this;
                    255:     a.executeString("K0_timer=time();");
                    256:     a.popString();
                    257:     a.executeString("K0_timer_CPU=K0_timer[0];");
                    258:     a.popString();
                    259:     a.executeString("K0_timer_GC=K0_timer[1];");
                    260:     a.popString();
                    261:   }
                    262:   def OffTimer() {
                    263:     local a;
                    264:     a = this;
1.14    ! takayama  265:     a.executeString("map(rtostr,[time()[0]-K0_timer_CPU,time()[1]-K0_timer_GC]);");
1.11      takayama  266:     return(a.popCMO());
1.10      takayama  267:   }
                    268: }

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