[BACK]Return to OXplot.java CVS log [TXT][DIR] Up to [local] / OpenXM / src / OpenMath

Annotation of OpenXM/src/OpenMath/OXplot.java, Revision 1.1

1.1     ! tam         1: /**
        !             2:  * $OpenXM$
        !             3:  */
        !             4:
        !             5: import JP.ac.kobe_u.math.tam.OpenXM.*;
        !             6: import java.util.Stack;
        !             7: //import java.io.*;
        !             8:
        !             9: public class OXplot extends OpenXMserver{
        !            10:   private Stack stack = new Stack();
        !            11:   private Vector plotframe = new Vector();
        !            12:   protected boolean debug = true;
        !            13:   final int version = 200007010;
        !            14:
        !            15:   public OXplot(String hostname,int ControlPort,int DataPort){
        !            16:     super(hostname,ControlPort,DataPort);
        !            17:   }
        !            18:
        !            19:   public void computeProcess(OpenXMconnection stream){
        !            20:     debug("OXplot started.");
        !            21:     try{
        !            22:       while(true){
        !            23:        try{
        !            24:          OXmessage message = stream.receive();
        !            25:          int ox_tag = message.getTag();
        !            26:
        !            27:          switch(ox_tag){
        !            28:          case OXmessage.OX_COMMAND:
        !            29:            StackMachine((SM)message.getBody(),stream);
        !            30:            break;
        !            31:
        !            32:          case OXmessage.OX_DATA:
        !            33:            stack.push(message.getBody());
        !            34:            debug("push: "+ stack.peek());
        !            35:            break;
        !            36:          }
        !            37:        }catch(RuntimeException e){
        !            38:          System.err.println(e.getMessage());
        !            39:          e.printStackTrace();
        !            40:          debug("error occured. stack was cleared.");
        !            41:          stack = new Stack();
        !            42:        }
        !            43:       }
        !            44:     }catch(java.io.IOException e){
        !            45:       System.err.println(e.getMessage());
        !            46:       e.printStackTrace();
        !            47:       System.err.println("error occured, and recovering processes seems to be impossible.");
        !            48:     }catch(Exception e){
        !            49:       System.err.println(e.getMessage());
        !            50:       e.printStackTrace();
        !            51:       System.err.println("error occured, and recovering processes seems to be impossible.");
        !            52:     }finally{
        !            53:       System.out.println("breaking...");
        !            54:     }
        !            55:   }
        !            56:
        !            57:   class plotframe extends java.awt.Frame{
        !            58:     int pixels[][];
        !            59:
        !            60:     plotframe(int width,int height){
        !            61:       super("plotframe");
        !            62:       setSize(width,height);
        !            63:       setResizable(false);
        !            64:
        !            65:       pixels = new int[width][];
        !            66:       for(int i=0;i<pixels.length;i++){
        !            67:        pixels[i] = new int[height];
        !            68:       }
        !            69:     }
        !            70:   }
        !            71:
        !            72:   private void SM_popCMO(OpenXMconnection stream) throws java.io.IOException{
        !            73:     try{
        !            74:       if(stack.empty()){
        !            75:        stream.send(new CMO_NULL());
        !            76:       }else{
        !            77:        debug("sending CMO: "+ stack.peek());
        !            78:        stream.send((CMO)stack.pop());
        !            79:        debug("test");
        !            80:       }
        !            81:     }catch(MathcapViolation e){
        !            82:       try{
        !            83:        stream.send(new CMO_ERROR2(new CMO_STRING("MathcapViolation: "+
        !            84:                                              e.getMessage())));
        !            85:       }catch(MathcapViolation tmp){}
        !            86:     }
        !            87:   }
        !            88:
        !            89:   private void SM_executeFunction() throws java.io.IOException{
        !            90:     String function_name;
        !            91:     CMO[] argv;
        !            92:     int argc;
        !            93:
        !            94:     if(!(stack.peek() instanceof CMO_STRING)){
        !            95:       stack.push(new CMO_ERROR2(new CMO_NULL()));
        !            96:       return;
        !            97:     }
        !            98:     function_name = ((CMO_STRING)stack.pop()).getString();
        !            99:     argc = ((CMO_INT32)stack.pop()).intValue();
        !           100:     argv = new CMO[argc];
        !           101:     for(int i=0;i<argc;i++){
        !           102:       argv[i] = (CMO)stack.pop();
        !           103:     }
        !           104:
        !           105:     if(function_name.equals("CREATE") && argc==2){
        !           106:       stack.push(CREATE(argv));
        !           107:     }else if(function_name.equals("CMO2OMXML") && argc==1){
        !           108:       //stack.push(CMO2OMXML(argv[0]));
        !           109:     }else{
        !           110:       stack.push(new CMO_ERROR2(new CMO_NULL()));
        !           111:     }
        !           112:
        !           113:     return;
        !           114:   }
        !           115:
        !           116:   private void SM_mathcap(OpenXMconnection stream) throws java.io.IOException{
        !           117:     CMO[] mathcap = new CMO[3];
        !           118:
        !           119:     {
        !           120:       CMO[] list = {new CMO_INT32(version),
        !           121:                  new CMO_STRING("Ox_system=OMproxy.class"),
        !           122:                  new CMO_STRING("Version=0."+ version),
        !           123:                  new CMO_STRING("HOSTTYPE=JAVA")};
        !           124:       mathcap[0] = new CMO_LIST(list);
        !           125:     }
        !           126:
        !           127:     {
        !           128:       CMO[] list = {new CMO_INT32(SM.SM_popCMO),
        !           129:                    new CMO_INT32(SM.SM_executeFunction),
        !           130:                    new CMO_INT32(SM.SM_mathcap),
        !           131:                    new CMO_INT32(SM.SM_setMathCap),
        !           132:                    new CMO_INT32(SM.SM_control_kill),
        !           133:                    new CMO_INT32(SM.SM_control_reset_connection)};
        !           134:       mathcap[1] = new CMO_LIST(list);
        !           135:     }
        !           136:
        !           137:     {
        !           138:       CMO[] CMOFormat = {new CMO_INT32(CMO.NULL),
        !           139:                         new CMO_INT32(CMO.INT32),
        !           140:                         new CMO_INT32(CMO.STRING),
        !           141:                         new CMO_INT32(CMO.LIST),
        !           142:                         new CMO_INT32(CMO.MONOMIAL32),
        !           143:                         new CMO_INT32(CMO.ZZ),
        !           144:                         new CMO_INT32(CMO.QQ),
        !           145:                         new CMO_INT32(CMO.ZERO),
        !           146:                         new CMO_INT32(CMO.BIGFLOAT),
        !           147:                         new CMO_INT32(CMO.INDETERMINATE),
        !           148:                         new CMO_INT32(CMO.TREE)};
        !           149:       CMO[] DataFormat1 = {new CMO_INT32(OXmessage.OX_DATA),
        !           150:                           new CMO_LIST(CMOFormat)};
        !           151:       CMO[] list = {new CMO_LIST(DataFormat1)};
        !           152:
        !           153:       mathcap[2] = new CMO_LIST(list);
        !           154:     }
        !           155:
        !           156:     stack = new Stack();
        !           157:     stack.push(new CMO_MATHCAP(new CMO_LIST(mathcap)));
        !           158:     debug("push: "+ stack.peek());
        !           159:   }
        !           160:
        !           161:   private void SM_setMathCap(OpenXMconnection stream)
        !           162:        throws java.io.IOException{
        !           163:     Object mathcap = stack.pop();
        !           164:
        !           165:     if(mathcap instanceof CMO_MATHCAP){
        !           166:       stack.push(new CMO_ERROR2(new CMO_NULL()));
        !           167:     }
        !           168:     stream.setMathCap((CMO_MATHCAP)mathcap);
        !           169:   }
        !           170:
        !           171:   private void StackMachine(SM mesg,OpenXMconnection stream)
        !           172:        throws java.io.IOException{
        !           173:     debug("receive: "+mesg);
        !           174:
        !           175:     switch(mesg.getCode()){
        !           176:     case SM.SM_popCMO:
        !           177:       SM_popCMO(stream);
        !           178:       break;
        !           179:
        !           180:     case SM.SM_executeFunction:
        !           181:       SM_executeFunction();
        !           182:       break;
        !           183:
        !           184:     case SM.SM_mathcap:
        !           185:       SM_mathcap(stream);
        !           186:       break;
        !           187:
        !           188:     case SM.SM_setMathCap:
        !           189:       SM_setMathCap(stream);
        !           190:       break;
        !           191:
        !           192:     default:
        !           193:       System.out.println("received "+ mesg);
        !           194:     }
        !           195:   }
        !           196:
        !           197:   private CREATE(CMO[] argv){
        !           198:     plotframe tmp = new plotframe(argv[0],argv[1]);
        !           199:     int i;
        !           200:
        !           201:     for(i=0;i<plotframe.size();i++){
        !           202:       if(plotframe.elementAt(i) == null){
        !           203:        plotframe.setElementAt(tmp,i);
        !           204:        return i;
        !           205:       }
        !           206:     }
        !           207:
        !           208:     plotframe.addElement(tmp);
        !           209:   }
        !           210:
        !           211:   private void debug(String str){
        !           212:     if(debug){
        !           213:       System.err.println(str);
        !           214:     }
        !           215:   }
        !           216:
        !           217:   private static String usage(){
        !           218:     String ret = "";
        !           219:
        !           220:     ret += "usage\t: java OMproxy [options]\n";
        !           221:     ret += "options\t:\n";
        !           222:     ret += "\t -h \t show this message\n";
        !           223:     ret += "\t -host hostname \t (default localhost)\n";
        !           224:     ret += "\t -data port \t (default 1300)\n";
        !           225:     ret += "\t -control port \t (default 1200)\n";
        !           226:     ret += "\t -insecure \t this version ignore this option\n";
        !           227:     ret += "\t -debug \t display debug messages\n";
        !           228:
        !           229:     return ret;
        !           230:   }
        !           231:
        !           232:   public static void main(String[] argv){
        !           233:     String hostname = "localhost";
        !           234:     int ControlPort = 1200, DataPort = 1300;
        !           235:     OpenXMserver ox;
        !           236:
        !           237:     for(int i=0;i<argv.length;i++){
        !           238:       if(argv[i].equals("-h")){
        !           239:         System.out.println("");
        !           240:         System.exit(0);
        !           241:       }else if(argv[i].equals("-host")){
        !           242:         hostname = argv[++i];
        !           243:       }else if(argv[i].equals("-data")){
        !           244:         DataPort = Integer.valueOf(argv[++i]).intValue();
        !           245:       }else if(argv[i].equals("-control")){
        !           246:         ControlPort = Integer.valueOf(argv[++i]).intValue();
        !           247:       }else{
        !           248:         System.err.println("unknown option :"+ argv[i]);
        !           249:         System.exit(1);
        !           250:       }
        !           251:     }
        !           252:
        !           253:     //ox = new OpenXMserver(hostname,ControlPort,DataPort);
        !           254:     ox = new OMproxy(hostname,ControlPort,DataPort);
        !           255:     /*
        !           256:     try{
        !           257:     }catch(java.net.UnknownHostException e){
        !           258:       System.err.println("host unknown.");
        !           259:       System.err.println(e.getMessage());
        !           260:       return;
        !           261:     }catch(IOException e){
        !           262:       System.err.println("connection failed.");
        !           263:       System.err.println("IOException occuer !!");
        !           264:       System.err.println(e.getMessage());
        !           265:       return;
        !           266:     }
        !           267:     */
        !           268:
        !           269:     ox.start();
        !           270:
        !           271:     System.out.println("breaking...");
        !           272:   }
        !           273: }

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