Source code for /engineering/autohit-2003/src/autohit/system/tellio/Tell.javaOriginal file Tell.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.Serializable;
  25 import autohit.common.Utils;
  26 //import autohit.common.Constants;
  27 
  28 /**
  29  * TELL IO primitive interface.  WIP WIP WIP
  30  * 
  31  * @author Erich P. Gatejen
  32  * @version 1.0 <i>Version History</i><code>EPG - Initial - 04Jan04<br>
  33  * /code>
  34  */
  35 public class Tell implements Serializable {
  36 
  37 	final static long serialVersionUID = 1;
  38 	
  39 	public static final int MAX_DATA_SIZE = (65535 * 8) - 12;
  40 
  41 	/**
  42 	 * TELL tokens
  43 	 */
  44 	public static final int TELL_INVALID = 0;
  45 	public static final int TELL_ASK = 'A';
  46 	public static final int TELL_BAD = 'B';
  47 	public static final int TELL_TELL = 'T';
  48 	public static final int TELL_FETCH = 'F';
  49 	public static final int TELL_GIVE = 'G';
  50 	public static final int TELL_DATA = 'D';
  51 	public static final int TELL_DONE = 'O';
  52 	public static final int TELL_STOP = 'S';
  53 
  54 	/**
  55 	 * Instruction
  56 	 * 
  57 	 * @serial
  58 	 */
  59 	public int tell;
  60 
  61 	/**
  62 	 * Numeric
  63 	 * 
  64 	 * @serial
  65 	 */
  66 	public int numeric;
  67 
  68 	/**
  69 	 * Size
  70 	 * 
  71 	 * @serial
  72 	 */
  73 	public int size;
  74 
  75 	/**
  76 	 * Data
  77 	 * 
  78 	 * @serial
  79 	 */
  80 	public byte[] data;
  81 
  82 	/**
  83 	 * Dump this Instruction. Mostly for debugging.
  84 	 * 
  85 	 * @return a String containing the dump.
  86 	 */
  87 	public String toString() {
  88 		return tell + ".";
  89 	}
  90 
  91 	/**
  92 	 * Build.
  93 	 * 
  94 	 * @return a String containing the dump.
  95 	 */
  96 	public boolean read(BufferedInputStream bis) throws TellException {
  97 
  98 		boolean result = false;
  99 		byte[] buf = new byte[4];
 100 		try {
 101 
 102 			int temp = 0;
 103 
 104 			// read numeric
 105 			buf[1] = (byte) bis.read();
 106 			buf[2] = (byte) bis.read();
 107 			buf[3] = (byte) bis.read();
 108 			buf[4] = (byte) bis.read();
 109 			numeric = Utils.packInteger(buf);
 110 
 111 			// read size
 112 			buf[1] = (byte) bis.read();
 113 			buf[2] = (byte) bis.read();
 114 			buf[3] = (byte) bis.read();
 115 			buf[4] = (byte) bis.read();
 116 			size = Utils.packInteger(buf);
 117 			if (size > MAX_DATA_SIZE) {
 118 				throw new TellException(
 119 						"Tell.read broken protocol.  Data over MAX_SIZE(" + MAX_DATA_SIZE + ")  actual size=" + size,
 120 						TellException.CODE_SYSTEM_TELLIO_BROKEN_PROTOCOL);
 121 			}
 122 
 123 			// read data
 124 			data = new byte[size];
 125 			int cursor = 0;
 126 			int run = bis.read(data,0,size);
 127 			while (run >=0) {
 128 				
 129 				
 130 			}
 131 			
 132 
 133 
 134 		
 135 		} catch (TellException tee) {
 136 			throw tee;
 137 		} catch (Exception ee) {
 138 
 139 		}
 140 		return result;
 141 	}
 142 
 143 	/**
 144 	 * Accept.
 145 	 * 
 146 	 * @return a String containing the dump.
 147 	 */
 148 	public int client_accept(int token) throws TellException {
 149 		switch (token) {
 150 
 151 			case TELL_ASK :
 152 			case TELL_BAD :
 153 			case TELL_TELL :
 154 			case TELL_FETCH :
 155 			case TELL_GIVE :
 156 			case TELL_DATA :
 157 			case TELL_DONE :
 158 			case TELL_STOP :
 159 
 160 			default :
 161 			case TELL_INVALID :
 162 
 163 				}
 164 		tell = token;
 165 		return token;
 166 	}
 167 
 168 }