Source code for /engineering/autohit-2003/src/autohit/system/tellio/TellServerEngine.javaOriginal file TellServerEngine.java
   1 /**
   2  * AUTOHIT 2003
   3  * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
   4  * 
   5  * This program is free software; you can redistribute it and/or modify 
   6  * it under the terms of the GNU General Public License as published by 
   7  * the Free Software Foundation; either version 2 of the License, or (at
   8  * your option) any later version.
   9  * This program is distributed in the hope that it will be useful, but
  10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12  * more details.
  13  * 
  14  * You should have received a copy of the GNU General Public License along
  15  * with this program; if not, write to the Free Software Foundation, Inc.,
  16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17  *
  18  * Additional license information can be found in the documentation.
  19  * @author Erich P Gatejen
  20  */
  21 package autohit.system.tellio;
  22 
  23 import java.io.BufferedInputStream;
  24 import java.io.EOFException;
  25 import java.io.IOException;
  26 import java.io.Serializable;
  27 //import autohit.common.Constants;
  28 
  29 /**
  30  * TELL IO working engine.
  31  * 
  32  * @author Erich P. Gatejen
  33  * @version 1.0 <i>Version History</i><code>EPG - Initial - 04Jan04<br>
  34  * /code>
  35  */
  36 public class TellServerEngine implements Serializable {
  37 
  38 	final static long serialVersionUID = 1;
  39 	
  40 	/**
  41 	 * TELL tokens
  42 	 */
  43 	public static final int STATE_NEW = 0;
  44 	public static final int STATE_GIVE = 1;
  45 	public static final int STATE_DATA = 2;
  46 	public static final int STATE_ERROR = 99;
  47 
  48 	public int state;
  49 	public int numeric;
  50 	
  51 	/**
  52 	 * Initialize the engine.
  53 	 * 
  54 	 * @return a String containing the dump.
  55 	 */
  56 	public void init() {
  57 		state = STATE_NEW;
  58 		numeric = 1;
  59 	}
  60 
  61 	/**
  62 	 * Initialize the engine.
  63 	 * 
  64 	 * @return a String containing the dump.
  65 	 */
  66 	public void connected(BufferedInputStream bis) {
  67 
  68 		try {
  69 
  70 			int next = bis.read();
  71 			while (next >= 0) {
  72 				
  73 				switch (state) {
  74 				
  75 					case STATE_NEW:
  76 						state_new(next, bis);
  77 						break;
  78 						
  79 					case STATE_GIVE:
  80 						//state_give(next, bis);
  81 						break;
  82 						
  83 					case STATE_DATA:
  84 						//state_data(next, bis);
  85 						break;
  86 						
  87 					default:
  88 						throw new TellException("Tellio.Server.connected base state.  Dropping connection.  state=" + state + " token=" + next,TellException.CODE_SYSTEM_GENERIC_ERROR);
  89 				}
  90 					
  91 				next = bis.read();
  92 			}
  93 			
  94 		} catch (TellException te) {
  95 
  96 		} catch (EOFException eeof) {
  97 
  98 		} catch (IOException iof) {
  99 
 100 		} catch (Exception ee) {
 101 
 102 		}
 103 
 104 	}
 105 
 106 	/**
 107 	 * Accept.  (SERVER)
 108 	 * 
 109 	 * @return a String containing the dump.
 110 	 */
 111 	public int state_new(int token, BufferedInputStream bis) throws TellException {
 112 
 113 		Tell current = null;
 114 		
 115 		switch (token) {
 116 			case Tell.TELL_ASK :
 117 				//current 
 118 				break;
 119 				
 120 			case Tell.TELL_FETCH :
 121 				break;
 122 
 123 			case Tell.TELL_GIVE :
 124 			case Tell.TELL_DATA :
 125 			case Tell.TELL_DONE :
 126 			case Tell.TELL_INVALID :
 127 			case Tell.TELL_BAD :
 128 			case Tell.TELL_TELL :
 129 			case Tell.TELL_STOP :	
 130 			default :
 131 				throw new TellException("Server.accept broken protocol.  Dropping connection.  Token=" + token,TellException.CODE_SYSTEM_TELLIO_BROKEN_PROTOCOL);
 132 		}
 133 		return token;
 134 	}
 135 
 136 }