diff src/org/tn5250j/framework/tn5250/tnvt.java @ 8:3b760b39962a tn5250

adding tn5250 files
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 15:41:35 -0700
parents 1b9e27659ef7
children e773d0952613
line wrap: on
line diff
--- a/src/org/tn5250j/framework/tn5250/tnvt.java	Thu May 22 13:41:05 2014 -0700
+++ b/src/org/tn5250j/framework/tn5250/tnvt.java	Thu May 22 15:41:35 2014 -0700
@@ -80,6 +80,9 @@
 
 import javax.net.ssl.SSLSocket;
 
+import com.five_ten_sg.connectbot.service.TerminalBridge;
+import com.five_ten_sg.connectbot.service.TerminalManager;
+
 import org.tn5250j.Session5250;
 import org.tn5250j.TN5250jConstants;
 import org.tn5250j.encoding.CharMappings;
@@ -89,8 +92,6 @@
 import org.tn5250j.tools.logging.TN5250jLogger;
 
 public final class tnvt implements Runnable {
-
-
 	// negotiating commands
 	private static final byte IAC = (byte) -1; // 255 FF
 	private static final byte DONT = (byte) -2; //254 FE
@@ -131,7 +132,6 @@
 	private Thread pthread;
 	private int readType;
 	private boolean enhanced = true;
-	private Session5250 controller;
 	private boolean cursorOn = false;
 	private String session = "";
 	private int port = 23;
@@ -160,6 +160,8 @@
 	private boolean firstScreen;
 	private String sslType;
 	private WTDSFParser sfParser;
+    private TerminalBridge bridge;
+    private TerminalManager manager;
 
 	private final TN5250jLogger log = TN5250jLogFactory.getLogger(this.getClass());
 
@@ -169,17 +171,16 @@
 	 * @param type
 	 * @param support132
 	 */
-	public tnvt(Session5250 session, Screen5250 screen52, boolean type, boolean support132) {
-
-		controller = session;
+	public tnvt(Screen5250 screen52, boolean enhanced, boolean support132, TerminalBridge bridge, TerminalManager manager) {
 		if (log.isInfoEnabled()) {
 			log.info(" new session -> " + controller.getSessionName());
 		}
-
-		enhanced = type;
+		this.screen52   = screen52;
 		this.support132 = support132;
+		this.enhanced   = enhanced;
+        this.bridge     = bridge;
+        this.manager    = manager;
 		setCodePage("37");
-		this.screen52 = screen52;
 		dataIncluded = new boolean[24];
 
 		if (System.getProperties().containsKey("SESSION_CONNECT_USER")) {
@@ -295,9 +296,8 @@
 			//         sock = new Socket(s, port);
 			//smk - For SSL compability
 			SocketConnector sc = new SocketConnector();
-			if (sslType != null)
-				sc.setSSLType(sslType);
-			sock = sc.createSocket(s, port);
+			if (sslType != null) sc.setSSLType(sslType);
+			sock = sc.createSocket(s, port, bridge, manager);
 
 			if (sock == null) {
 				log.warn("I did not get a socket");
@@ -384,11 +384,9 @@
 				log.info("Closing socket");
 				sock.close();
 			}
-			if (bin != null)
-				bin.close();
-			if (bout != null)
-				bout.close();
-			connected = false;
+			if (bin != null) bin.close();
+			if (bout != null) bout.close();
+			connected   = false;
 			firstScreen = false;
 
 			// WVL - LDC : TR.000345 : properly disconnect and clear screen
@@ -398,9 +396,6 @@
 			screen52.setCursorActive(false);
 			screen52.clearAll();
 			screen52.restoreScreen();
-
-			controller.fireSessionChanged(TN5250jConstants.STATE_DISCONNECTED);
-
 		} catch (Exception exception) {
 			log.warn(exception.getMessage());
 			connected = false;
@@ -1165,95 +1160,8 @@
 
 	}
 
-	//      private final void execCmd() {
-	//         String name = "";
-	//         String argString = "";
-	//
-	//         StringBuffer sb = new StringBuffer();
-	//         sb.append(screen52.screen[0][3].getChar());
-	//         sb.append(screen52.screen[0][4].getChar());
-	//         sb.append(screen52.screen[0][5].getChar());
-	//         sb.append(screen52.screen[0][6].getChar());
-	//
-	//         System.out.println("command = " + sb);
-	//         int x = 8;
-	//         sb.setLength(0);
-	//         while (screen52.screen[0][x].getChar() > ' ') {
-	//            sb.append(screen52.screen[0][x].getChar());
-	//            x++;
-	//         }
-	//         name = sb.toString();
-	//         System.out.println("name = " + name);
-	//
-	//         sb.setLength(0);
-	//         x++;
-	//         while (screen52.screen[0][x].getChar() >= ' ') {
-	//            sb.append(screen52.screen[0][x].getChar());
-	//            x++;
-	//         }
-	//         argString = sb.toString();
-	//         System.out.println("args = " + argString);
-	//
-	//         sendAidKey(AID_ENTER);
-	//
-	//         try {
-	//
-	//            Class c = Class.forName(name);
-	//            String args1[] = {argString};
-	//            String args2[] = {};
-	//
-	//            Method m = c.getMethod("main",
-	//            new Class[] { args1.getClass() });
-	//            m.setAccessible(true);
-	//            int mods = m.getModifiers();
-	//            if (m.getReturnType() !=
-	//                   void.class || !Modifier.isStatic(mods) ||
-	//                  !Modifier.isPublic(mods)) {
-	//
-	//                     throw new NoSuchMethodException("main");
-	//                  }
-	//            try {
-	//               if (argString.length() > 0)
-	//                  m.invoke(null, new Object[] { args1 });
-	//               else
-	//                  m.invoke(null, new Object[] { args2 });
-	//            }
-	//            catch (IllegalAccessException e) {
-	//                 // This should not happen, as we have
-	//                 // disabled access checks
-	//                  System.out.println("iae " + e.getMessage());
-	//
-	//            }
-	//         }
-	//         catch (ClassNotFoundException cnfe) {
-	//            System.out.println("cnfe " + cnfe.getMessage());
-	//         }
-	//         catch (NoSuchMethodException nsmf) {
-	//            System.out.println("nsmf " + nsmf.getMessage());
-	//         }
-	//         catch (InvocationTargetException ite) {
-	//            System.out.println("ite " + ite.getMessage());
-	//         }
-	//   // catch (IllegalAccessException iae) {
-	//   // System.out.println("iae " + iae.getMessage());
-	//   // }
-	//   // catch (InstantiationException ie) {
-	//   // System.out.println("ie " + ie.getMessage());
-	//   // }
-	//   // try {
-	//   //
-	//   // Runtime rt = Runtime.getRuntime();
-	//   // Process proc = rt.exec("notepad");
-	//   // int exitVal = proc.exitValue();
-	//   // }
-	//   // catch (Throwable t) {
-	//   //
-	//   // t.printStackTrace();
-	//   // }
-	//      }
 
 	private final void readScreen() throws IOException {
-
 		int rows = screen52.getRows();
 		int cols = screen52.getColumns();
 		byte abyte0[] = new byte[rows * cols];
@@ -1263,7 +1171,6 @@
 	}
 
 	private final void fillScreenArray(byte[] sa, int rows, int cols) {
-
 		int la = 32;
 		int sac = 0;
 		int len = rows * cols;
@@ -1980,12 +1887,9 @@
 					break;
 
 				case 21: // WTDSF - Write To Display Structured Field order
-					log
-					.debug("WTDSF - Write To Display Structured Field order");
+					log.debug("WTDSF - Write To Display Structured Field order");
 					byte[] seg = bk.getSegment();
 					error = sfParser.parseWriteToDisplayStructuredField(seg);
-
-					//                  error = writeToDisplayStructuredField();
 					break;
 
 				case 29: // SF - Start of Field
@@ -2002,8 +1906,7 @@
 						// control word
 
 						// check if the first fcw1 is an 0x81 if it is then get
-						// the
-						// next pair for checking
+						// the next pair for checking
 						if (fcw1 == 0x81) {
 							bk.getNextByte();
 							fcw1 = bk.getNextByte() & 0xff; // check for field
@@ -2023,9 +1926,7 @@
 										+ " "
 										+ Integer.toHexString(bk
 												.getNextByte() & 0xff));
-								//                           bk.getNextByte();
-								attr = bk.getNextByte() & 0xff; // attribute
-								// field
+								attr = bk.getNextByte() & 0xff; // attribute field
 							}
 						} else {
 							attr = fcw1; // attribute of field
@@ -2133,10 +2034,8 @@
 			screen52.clearTable();
 
 			// well that is the first time I have seen this. This fixes a
-			// problem
-			// with S/36 command line. Finally got it.
-			if (l <= 3)
-				return false;
+			// problem with S/36 command line. Finally got it.
+			if (l <= 3) return false;
 
 			screen52.setErrorLine(bk.getNextByte()); // error row