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

1.8     ! takayama    1: /* $OpenXM: OpenXM/src/k097/lib/ox/ox.k,v 1.7 2000/12/14 10:04: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.3       takayama   65:   def generate(c) {
1.2       takayama   66:      if (Tag(c) != 0) {
                     67:        control = c;
                     68:        return(this);
                     69:      }else{
                     70:        return(start());
                     71:      }
                     72:   }
                     73:   def start() {
1.1       takayama   74:     local c,e, pass, peer, data, s, stmp;
                     75:     this = new(super.new0());
                     76:     sm1(" [(oxGenPass)] extension /pass set ");
                     77:     sm1(" [(oxGetPort1) (localhost)] extension /peer set ");
                     78:     sm1(" /data peer 1 get toString def ");
                     79:     s = AddString(
1.5       takayama   80:       [GetEnv("OpenXM_HOME"),
1.8     ! takayama   81:        "/bin/oxc",
1.1       takayama   82:        " -c ", pass, " -h "," localhost ", " -p ", data, " -x ",
                     83:        " & "]);
                     84:     sm1(" [ (/bin/csh -c \") s (\") ] cat /stmp set ");
                     85:     sm1(" stmp message ");
                     86:     sm1(" stmp system  ");
                     87:     sm1(" [(oxCreateControl_RFC_101) peer 0 pass] extension /c set ");
1.3       takayama   88:     control = OXchannel.generate(c);
1.1       takayama   89:     return(this);
1.2       takayama   90:   }
1.3       takayama   91:   def pushCMO(a) {
                     92:     control.channel.pushCMO(a);
                     93:   }
                     94:   def pushCMD(a) {
                     95:     control.channel.pushCMD(a);
                     96:   }
1.4       takayama   97:   def popCMO() {
                     98:     return(control.channel.popCMO());
                     99:   }
1.7       takayama  100:   def popString() {
                    101:     return(control.channel.popString());
                    102:   }
1.2       takayama  103:
1.1       takayama  104: }
                    105:
1.4       takayama  106: /* How to debug?
                    107:    sm1(" OX { vname } sendmsg /aaa set ");
                    108:    Get the value of vname in the context OX and set it to aaa.
                    109: */
1.1       takayama  110:
1.3       takayama  111: class OX extends OXcontrol {
1.5       takayama  112:   local engine, engineIDs;
                    113:   def getEngine() {
                    114:      return(engine);
                    115:   }
                    116:   def getEngineIDs() {
                    117:      return(engineIDs);
                    118:   }
                    119:   /* OX.generate("ox_sm1"); or OX.generate("ox_sm1",null) */
                    120:   def generate(name,control) {
1.2       takayama  121:     local c,e, pass, peer, data, s, stmp, engineID;
1.5       takayama  122:     if (Length(Arglist) == 0) {
                    123:       name = "ox_sm1";  control = null;
                    124:     }
                    125:     if (Length(Arglist) == 1) {
                    126:       control = null;
                    127:     }
1.3       takayama  128:     this = new(super.generate(control));
1.5       takayama  129:     control = super.getControl();
1.2       takayama  130:     sm1(" [(oxGetPort1) (localhost)] extension /peer set ");
                    131:     sm1(" /data peer 1 get def ");
1.6       takayama  132:     /* BUG: control.pushCMO(data) does not work.
                    133:             Use control = super.getControl(); */
                    134:     control.pushCMO([[data],name]);
1.2       takayama  135:     control.pushCMD(SM_control_spawn_server);
                    136:     engineID = control.popCMO();
1.4       takayama  137:     print("engineID=");Println(engineID);
1.5       takayama  138:     if (Tag(engineID) == 257 ) {  /* error object */
                    139:        Error("Server could be found.");
                    140:     }
                    141:     engineIDs = [engineID];
1.2       takayama  142:     sm1(" [(oxCreateEngine_RFC_101) peer 0 (Empty) engineID] extension /c set ");
1.3       takayama  143:     engine = OXchannel.generate(c);
1.2       takayama  144:     return(this);
1.3       takayama  145:   }
1.5       takayama  146:   def pushCMO(a) {
                    147:     engine.channel.pushCMO(a);
                    148:   }
                    149:   def pushCMD(a) {
                    150:     engine.channel.pushCMD(a);
                    151:   }
                    152:   def popCMO() {
                    153:     return(engine.channel.popCMO());
                    154:   }
1.7       takayama  155:   def popString() {
                    156:     return(engine.channel.popString());
                    157:   }
1.2       takayama  158:
1.5       takayama  159:   def rpc(func,ar) {
                    160:      local n,i,one,comm;
                    161:      if (! IsString(func)) {
                    162:        Error("The first argument of rpc must be a string.");
                    163:      }
                    164:      if (! IsArray(ar)) {
                    165:        Error("The second argument of rpc must be a list.");
                    166:      }
                    167:      one = IntegerToSm1Integer(1);
                    168:      sm1(" getVlist2 toString /comm set ");
                    169:      comm = AddString(["OxVlist=",comm,";"]);
                    170:      this.pushCMO(comm);
                    171:      this.pushCMD(SM_executeStringByLocalParser);
                    172:
                    173:      this.pushCMO("print(OxVlist);");
                    174:      this.pushCMD(SM_executeStringByLocalParser);
                    175:
                    176:      n = Length(ar);
                    177:      for (i=n-1; i>=0; i--) {
                    178:        this.pushCMO(ar[i]);
                    179:        this.pushCMO(one);
                    180:        this.pushCMO("ox_dtop");
                    181:        this.pushCMD(SM_executeFunction);
                    182:      }
                    183:      this.pushCMO(IntegerToSm1Integer(n));
                    184:      this.pushCMO(func);
                    185:      this.pushCMD(SM_executeFunction);
                    186:
                    187:      this.pushCMO(one);
                    188:      this.pushCMO("ox_ptod");
                    189:      this.pushCMD(SM_executeFunction);
                    190:      return(this.popCMO());
1.7       takayama  191:   }
                    192:
                    193:   def executeString(s) {
                    194:      this.pushCMO(s);
                    195:      this.pushCMD(SM_executeStringByLocalParser);
1.5       takayama  196:   }
                    197:
                    198: }
                    199:
                    200: /*
                    201:   Example:
                    202:      a = startAsir();
                    203:      f = a.rpc("fctr",[x^10-1]);
                    204:      Println(f);
                    205: */
                    206: def startAsir() {
                    207:   local a,asirpeer;
                    208:   a = OX.generate("ox_asir");
                    209:   asirpeer = (a.getEngine()).getChannel();
                    210:   Println(asirpeer);
                    211:   sm1(" [asirpeer oxasirpath.asirlib] loadAsirFile ");
                    212:   return(a);
1.2       takayama  213: }
1.1       takayama  214:

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