tn5250j/src/org/tn5250j tnvt.java,1.40,1.41

"Kenneth J. Pouncey" <[email protected]> Sat, 26 Jun 2004 05:37:02 +0000
Newsgroups gmane.comp.java.tn5250j.cvs
Message-ID <[email protected]>
Update of /cvsroot/tn5250j/tn5250j/src/org/tn5250j
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12214

Modified Files:
	tnvt.java 
Log Message:
Add call back scanning functionality Luc - LDC

Index: tnvt.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/tnvt.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** tnvt.java	14 Apr 2004 12:15:53 -0000	1.40
--- tnvt.java	26 Jun 2004 05:37:00 -0000	1.41
***************
*** 69,72 ****
--- 69,77 ----
     private String devName;
     private String devNameUsed;
+ 
+    // WVL - LDC : TR.000300 : Callback scenario from 5250
+    private boolean scan; // = false;
+    private static int STRSCAN = 1;
+ 
     private String user;
     private String password;
***************
*** 88,94 ****
     private String sslType;
     WTDSFParser sfParser;
! 	
     private Logger log = Logger.getLogger(this.getClass());
!    
     tnvt (Screen5250 screen52) {
  
--- 93,99 ----
     private String sslType;
     WTDSFParser sfParser;
! 
     private Logger log = Logger.getLogger(this.getClass());
! 
     tnvt (Screen5250 screen52) {
  
***************
*** 298,301 ****
--- 303,310 ----
     public final boolean disconnect() {
  
+       // Added by LUC - LDC to fix a null pointer exception.
+       if (!connected)
+          return false;
+ 
        if (me != null && me.isAlive()) {
           me.interrupt();
***************
*** 319,322 ****
--- 328,340 ----
           connected = false;
           firstScreen = false;
+ 
+          // WVL - LDC : TR.000345 : properly disconnect and clear screen
+          // Is this the right place to set screen realestate on disconnect?
+          //controller.getScreen().clearAll();
+          screen52.goto_XY(0);
+          screen52.setCursorActive(false);
+          screen52.clearAll();
+          screen52.restoreScreen();
+ 
           controller.fireSessionChanged(TN5250jConstants.STATE_DISCONNECTED);
  
***************
*** 856,859 ****
--- 874,976 ----
     }
  
+    // WVL - LDC : TR.000300 : Callback scenario from 5250
+    /**
+     * Activate or deactivate the command scanning behaviour.
+     *
+     * @param scan if true, scanning is enabled; disabled otherwise.
+     *
+     * @see scan4Cmd()
+     */
+    public void setScanningEnabled(boolean scan)
+    {
+      this.scan = scan;
+    }
+ 
+    // WVL - LDC : TR.000300 : Callback scenario from 5250
+    /**
+     * Checks whether command scanning is enabled.
+     *
+     * @return true is command scanning is enabled; false otherwise.
+     */
+    public boolean isScanningEnabled()
+    {
+      return this.scan;
+    }
+ 
+    // WVL - LDC : TR.000300 : Callback scenario from 5250
+    /**
+     * When command scanning is activated, the terminal reads the first and
+     * second character in the datastream (the zero position allows to
+     * devisualize the scan stream). If the sequence <code>#!</code> is
+     * encountered and if this sequence is <strong>not</strong> followed by a
+     * blank character, the {@link parseCommand(ScreenChar[])} is called.
+     */
+    private void scan()
+    {
+ //     System.out.println("Checking command : " + screen52.screen[1].getChar() + screen52.screen[2].getChar());
+      ScreenChar[] screen = screen52.screen;
+      if (  (screen[STRSCAN].getChar() == '#')
+         && (screen[STRSCAN+1].getChar() == '!')
+         && (screen[STRSCAN+2].getChar() != ' ')
+         )
+       {
+         try
+         {
+           parseCommand();
+         }
+         catch (Throwable t)
+         {
+           System.out.println("Exec cmd: " + t.getMessage());
+           t.printStackTrace();
+         }
+       }
+    }
+ 
+    // WVL - LDC : TR.000300 : Callback scenario from 5250
+    /**
+     * The screen is parsed starting from second position until a white space
+     * is encountered. When found the {@link Session#execCommand(String, int)}
+     * is called with the parsed string. The position immediately following the
+     * encountered white space, separating the command from the rest of the
+     * screen, is passed as starting index.
+     *
+     * Note that the character at the starting position can potentially
+     * be a white space itself. The starting position in <code>execCommand</code>
+     * provided to make the scanning sequence more flexible.
+     * We'd like for example to embed also a <code>+</code> or <code>-</code>
+     * sign to indicate whether the tnvt should trigger a repaint or not.
+     * This would allow the flashing of command sequences without them becoming
+     * visible.
+     *
+     * <ul>
+     * <li><strong>PRE</strong> The screen character at position
+     * <code>STRSCAN + 2</code> is not a white space.
+     * </li>
+     * </ul>
+     */
+   private void parseCommand()
+   {
+     // Search for the command i.e. the first token in the stream
+     // after the #! sequence separated by a space from the rest
+     // of the screen.
+     char[] screen = screen52.getScreenAsAllChars();
+     for (int  s = STRSCAN + 2, i = s; i < screen.length; i++)
+     {
+       if (screen[i] == ' ')
+       {
+         String command   = new String(screen, s, i-s);
+ 
+         // Skip all white spaces between the command and the rest of
+         // the screen.
+         //for (; (i < screen.length) && (screen[i] == ' '); i++);
+ 
+         String remainder = new String(screen, i+1, screen.length - (i+1));
+ //        System.out.println("Sensing action command in the input! = " + command);
+         controller.scanned(command, remainder);
+         break;
+       }
+     }
+   }
+ 
     public void run () {
  
***************
*** 970,973 ****
--- 1087,1091 ----
              screen52.drawFields();
  
+ 
  //      if (screen52.screen[0][1].getChar() == '#' &&
  //         screen52.screen[0][2].getChar() == '!')
***************
*** 1015,1019 ****
  
     public void dumpStuff() {
! 	  
  	  if(log.isDebugEnabled()) {
  	      log.debug(" Pending unlock " + pendingUnlock);
--- 1133,1137 ----
  
     public void dumpStuff() {
! 
  	  if(log.isDebugEnabled()) {
  	      log.debug(" Pending unlock " + pendingUnlock);
***************
*** 1386,1389 ****
--- 1504,1513 ----
                 case CMD_WRITE_TO_DISPLAY:    // 0x11 17 write to display
                    error = writeToDisplay(true);
+                   // WVL - LDC : TR.000300 : Callback scenario from 5250
+                   // Only scan when WRITE_TO_DISPLAY operation (i.e. refill screen buffer)
+                   // has been issued!
+                   if (scan)
+                     scan();
+ 
                    break;
                 case CMD_RESTORE_SCREEN:   // 0x12 18 Restore Screen



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com