[BACK]Return to oxclient.m2 CVS log [TXT][DIR] Up to [local] / OpenXM / src / Macaulay2 / m2

Annotation of OpenXM/src/Macaulay2/m2/oxclient.m2, Revision 1.1

1.1     ! takayama    1: ID=" $OpenXM$ "
        !             2:
        !             3: load "oxcommon.m2"
        !             4:
        !             5: oxSession = method()
        !             6: oxSession(String) := (s) -> (
        !             7:      try (F := oxStartSession(s))
        !             8:      else ( error "Could not start the server " | s);
        !             9:      F
        !            10:      )
        !            11:
        !            12: oxFlush = method()
        !            13: oxFlush(OXSESSION, File, String) := (F, file, str) -> (
        !            14:      if (F.FlushFlag == 0) then file << str << flush
        !            15:      else (
        !            16:          read "Press Return to flush: ";
        !            17:          file << str << flush;
        !            18:          );
        !            19:      )
        !            20:
        !            21: oxToggleFlushFlag = method()
        !            22: oxToggleFlushFlag(OXSESSION, ZZ) := (F, n) -> (
        !            23:      F.FlushFlag = n;
        !            24:      )
        !            25:
        !            26: oxEmptyHashTable = method()
        !            27: oxEmptyHashTable(OXSESSION) := (F) -> (
        !            28:      apply(keys F, i -> remove(F, i));
        !            29:      )
        !            30:
        !            31: oxasir = () -> ( oxStartSession "ox_asir" )
        !            32:
        !            33: -- this method starts the server s.
        !            34: oxStartSession = (s) -> (
        !            35:      MINPORT := 1025;
        !            36:      MAXPORT := 5000;
        !            37:      MAXTRIES := 3; -- number of times to try to open new ports
        !            38:      MAXTRIES = 1000; -- number of times to try to open new ports
        !            39:      PASS := "M2";
        !            40:
        !            41:      F := null;
        !            42:      G := null;
        !            43:      i := 0;
        !            44:      while (i < MAXTRIES and (F === null or G === null)) do (
        !            45:                  if not (F === null) then (close F; F = null);
        !            46:                  if not (F === null) then (close G; G = null);
        !            47:          cPort := random (MAXPORT - MINPORT) + MINPORT;
        !            48:          dPort := random (MAXPORT - MINPORT) + MINPORT;
        !            49:          if (cPort != dPort) then (
        !            50:               try F = openListener(toString "$:"|cPort) else F = null;
        !            51:               try G = openListener(toString "$:"|dPort) else G = null;
        !            52:               );
        !            53:            i = i+1;
        !            54:          );
        !            55:      << "F = " << F << " and " << " G = " << G << endl << flush;
        !            56:      if (F === null or G === null) then
        !            57:          error "Couldn't connect to the ox server" | s;
        !            58:      comm = toString "xterm -geometry 80x25-0-0 -e  ox -ox " | s | " -data " |
        !            59:                       dPort | " -control " | cPort |
        !            60:                      " -reverse -host localhost" | " -pass " | PASS | " &" ;
        !            61:      comm = makeLaunchCommand(true,"localhost","mike","localhost",
        !            62:                              s,dPort,cPort,PASS);
        !            63:      print comm;
        !            64:      if (run (comm) != 0)
        !            65:        then error "Couldn't start the ox server " | s;
        !            66:
        !            67:      F = openInOut F;
        !            68:      G = openInOut G;
        !            69:      F << "\000" << flush ; -- set to network byte order
        !            70:      G << "\000" << flush;
        !            71:
        !            72:      FP = makeOXINPUT F;
        !            73:      S := getBytes(FP,#PASS);
        !            74:      if S != PASS then (
        !            75:          close F;
        !            76:          close G;
        !            77:          error "wrong one time password";
        !            78:          );
        !            79:      GP = makeOXINPUT G;
        !            80:      S = getBytes(GP,#PASS);
        !            81:      if S != PASS then (
        !            82:          close F;
        !            83:          close G;
        !            84:          error "wrong one time password";
        !            85:          );
        !            86:      getBytes(FP,2);
        !            87:      getBytes(GP,2);
        !            88:
        !            89:      -- need to change the following.
        !            90:      new OXSESSION from {
        !            91:          ServerName => s,
        !            92:          ControlPort => F,
        !            93:          DataPort => G,
        !            94:          SerialNumber => 0,
        !            95:          FlushFlag => 0,
        !            96:          DataBuffer => makeOXINPUT G,
        !            97:          Buffer => "",
        !            98:          BufferPointer => 0}
        !            99:      )
        !           100:
        !           101: -- methods to access data fields of the OXSESSION class
        !           102: oxGetDataPort = method()
        !           103: oxGetDataPort(OXSESSION) := (F) -> (F.DataPort)
        !           104: oxGetControlPort = method()
        !           105: oxGetControlPort(OXSESSION) := (F) -> (F.ControlPort)
        !           106: oxGetSerialNumber = method()
        !           107: oxGetSerialNumber(OXSESSION) := (F) -> (F.SerialNumber)
        !           108: oxGetFlushFlag = method()
        !           109: oxGetFlushFlag(OXSESSION) := (F) -> (F.FlushFlag)
        !           110:
        !           111: incrementSerialNumber = method()
        !           112: incrementSerialNumber(OXSESSION) := (F) -> (
        !           113:      F.SerialNumber = F.SerialNumber + 1;)
        !           114:
        !           115: oxPushCMO = (F,s) -> (
        !           116:      incrementSerialNumber(F);
        !           117:      Fport := oxGetDataPort(F);
        !           118:      Fport << OXDATA
        !           119:            << toNetwork(oxGetSerialNumber(F));
        !           120:      CMOSerialize(Fport,s);
        !           121:      oxFlush(F, Fport, "");
        !           122:      )
        !           123:
        !           124: oxData = method()
        !           125: oxData(OXSESSION, String) :=
        !           126: oxData(OXSESSION, ZZ) :=
        !           127: oxData(OXSESSION, INT32) :=
        !           128: oxData(OXSESSION, List) := oxPushCMO
        !           129:
        !           130: -- method to set mathcap of mine to the server.
        !           131: oxSetMathcap = method()
        !           132: oxSetMathcap(OXSESSION) := (F) -> (
        !           133:      incrementSerialNumber(F);
        !           134:      Fport := oxGetDataPort(F);
        !           135:      Fport << OXDATA << toNetwork(oxGetSerialNumber(F))
        !           136:            << toNetwork(CMO'MATHCAP);
        !           137:      CMOSerialize(Fport,MATHCAP'OF'M2);
        !           138:      oxFlush(F, oxGetDataPort(F), "");
        !           139:      oxCommand(F,SM'setMathCap);
        !           140:      )
        !           141:
        !           142: -- method to send a command to the data port
        !           143: oxCommand = method()
        !           144: oxCommand(OXSESSION, ZZ) := (F, TagNumber) -> (
        !           145:      incrementSerialNumber(F);
        !           146:      str := OXCOMMAND | toNetwork(oxGetSerialNumber(F)) | toNetwork(TagNumber);
        !           147:      oxFlush(F, oxGetDataPort(F), str);
        !           148:      )
        !           149:
        !           150: -- method to send a command to the control port
        !           151: oxControl = method()
        !           152: oxControl(OXSESSION, ZZ) := (F, TagNumber) -> (
        !           153:      incrementSerialNumber(F);
        !           154:      str := OXCOMMAND | toNetwork(oxGetSerialNumber(F)) | toNetwork(TagNumber);
        !           155:      oxFlush(F, oxGetControlPort(F), str);
        !           156:      )
        !           157:
        !           158: -- various commands
        !           159: oxExecuteStringByLocalParser = method()
        !           160: oxExecuteStringByLocalParser(OXSESSION) := (F) -> (
        !           161:      oxCommand(F, SM'executeStringByLocalParser);
        !           162:      )
        !           163:
        !           164: oxExecuteFunction = method()
        !           165: oxExecuteFunction(OXSESSION) := (F) -> (
        !           166:      oxCommand(F, SM'executeFunction);
        !           167:      )
        !           168:
        !           169: oxPopCMO = method()
        !           170: oxPopCMO(OXSESSION) := (F) -> (
        !           171:      oxCommand(F, SM'popCMO);
        !           172:      oxTag := get32bits(F.DataBuffer); -- read the OX tag
        !           173:      serTag := get32bits(F.DataBuffer); -- read the Serial tag
        !           174:      CMOfromBinary(F.DataBuffer)
        !           175:      );
        !           176:
        !           177: oxPopString = method()
        !           178: oxPopString(OXSESSION) := (F) -> (
        !           179:      oxCommand(F, SM'popString);
        !           180:      oxTag := get32bits(F.DataBuffer); -- read the OX tag
        !           181:      serTag := get32bits(F.DataBuffer); -- read the Serial tag
        !           182:      CMOfromBinary(F.DataBuffer)
        !           183:      )
        !           184:
        !           185:
        !           186: oxKill = method()
        !           187: oxKill(OXSESSION) := (F) -> (
        !           188:      oxControl(F, SM'control'kill);
        !           189:      oxEmptyHashTable(F);
        !           190:      )
        !           191:
        !           192: oxRestart = method()
        !           193: oxRestart(OXSESSION) := (F) -> (
        !           194:      oxControl(F, SM'control'kill);
        !           195:      tmp := oxStartSession(F.ServerName);
        !           196:      scan(keys tmp, i -> (F#i = tmp#i));
        !           197:      F.DataBuffer = makeOXINPUT (F.DataPort);
        !           198:      F
        !           199:      )
        !           200:
        !           201: oxPopMathcap = method()
        !           202: oxPopMathcap(OXSESSION) := (F) ->(
        !           203:         oxCommand(F,SM'mathcap);
        !           204:         oxPopCMO(F)
        !           205:         )
        !           206:
        !           207: oxPrimDecomp = method()
        !           208: oxPrimDecomp(OXSESSION, Ideal) := (F, I) -> (
        !           209:      -- translate to asir notation
        !           210:      s := toString I;
        !           211:      s = "[" | substring(s,6,#s-7) | "]";
        !           212:      v = toString gens ring I;
        !           213:      v = "[" | substring(v,1,#v-2) | "]";
        !           214:      s = "primadec(" | s | "," | v | ");";
        !           215:      << "sending" << s << endl;
        !           216:      oxData(F, s);
        !           217:      oxExecuteStringByLocalParser(F);
        !           218:      str = oxPopString(F);
        !           219:      toList apply(value str, i -> {ideal(toList(i#0)), ideal(toList(i#1))})
        !           220:      )
        !           221: oxPrimDecomp(OXSESSION, Ideal) := (F, I) -> (
        !           222:      -- translate to asir notation
        !           223:      s := toString I;
        !           224:      s = "[" | substring(s,6,#s-7) | "]";
        !           225:      v = toString gens ring I;
        !           226:      v = "[" | substring(v,1,#v-2) | "]";
        !           227:      s = "primadec(" | s | "," | v | ");";
        !           228:      << "sending" << s << endl;
        !           229:      oxData(F, s);
        !           230:      oxExecuteStringByLocalParser(F);
        !           231:      --str = oxPopString(F);
        !           232:      --toList apply(value str, i -> {ideal(toList(i#0)), ideal(toList(i#1))})
        !           233:      )
        !           234:
        !           235: -- makeLaunchCommand generates an argument of run.
        !           236: -- Replace comm = toString "xterm ...." in oxStartSession (oxcommon.m2) by
        !           237: --  comm = makeLauchCommand with proper arguments.
        !           238: -- I think that the examples below speak itself.
        !           239: -- Some arguments are not necessary when UseSSH is true.
        !           240: -- there may be a neat way to define optional arguments in M2.
        !           241:
        !           242: makeLaunchCommand=(UseSSH,MyHostName,RemoteLoginName,RemoteHostName,OxServerName,dPort,cPort,PASS)->(
        !           243:      commXterm := toString " xterm -geometry 80x25-0-0 " ;
        !           244:      commOX :=toString " -e ox -ox " | OxServerName |
        !           245:                        " -data " | dPort |
        !           246:                       " -control " | cPort |
        !           247:                       " -reverse " |
        !           248:                       " -host " | RemoteHostName |
        !           249:                       " -pass " | PASS   | "  ";
        !           250:      if (UseSSH) then (
        !           251:          comm = toString "ssh -f -l " | RemoteLoginName | " " |
        !           252:                           RemoteHostName |
        !           253:                           " '" | commXterm |
        !           254:                           --uncomment when X11 forwarding is not allowed.
        !           255:                           " -display " | MyHostName | ":0 " |
        !           256:                           commOX | "'  >/dev/null ";
        !           257:          )
        !           258:      else  (
        !           259:          comm = toString commXterm | commOX | " &";
        !           260:          );
        !           261:      comm
        !           262:      )
        !           263:
        !           264: ///
        !           265: print makeLaunchCommand(false,"localhost","grobner","localhost","ox_asir",1300,1200,"M2")
        !           266: print " "
        !           267: print makeLaunchCommand(true,"localhost","grobner","localhost","ox_asir",1300,1200,"M2")
        !           268: print " "
        !           269: print makeLaunchCommand(true,"mymachine.edu","graver","oxservers.com","ox_m2",1300,1200,"M2")
        !           270: print " "
        !           271: print makeLaunchCommand(true,"hogehoge.com","goober","servers.openxm.org","ox_sm1",1300,1200,"M2");
        !           272: print " "
        !           273: ///

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