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

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

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