This is the mail archive of the frysk-cvs@sources.redhat.com mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[SCM] master: gui changes for writer in CLI


The branch, master has been updated
       via  bbf65a2f723cbba04b745ee99ab0adb8ab8f82cb (commit)
       via  6596e0483077d423d3998600d49d2f9f5928ff65 (commit)
      from  e5a45290eaa2d95ae971591d15f2cb79a10b6cc7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit bbf65a2f723cbba04b745ee99ab0adb8ab8f82cb
Author: Tim Moore <timoore@redhat.com>
Date:   Wed Feb 27 11:29:33 2008 +0100

    gui changes for writer in CLI

commit 6596e0483077d423d3998600d49d2f9f5928ff65
Author: Tim Moore <moore@blackbox.bricoworks.com>
Date:   Wed Feb 20 18:37:42 2008 +0100

    FlowControlWriter for buffering asynch output during user input
    
    frysk-core/frysk/bindir/ChangeLog:
    2008-02-20  Tim Moore  <timoore@redhat.com>
    
    	* fhpd.java (TerminalObserver): New class
    	(CommandLine()): Use TerminalObserver and FlowControlWriter.
    
    frysk-core/frysk/hpd/ChangeLog:
    2008-02-20  Tim Moore  <timoore@redhat.com>
    
    	* CLI.java (constructors): Take a Writer argument instead of a
    	PrintStream.
    
    frysk-core/frysk/util/ChangeLog:
    2008-02-20  Tim Moore  <timoore@redhat.com>
    
    	* FlowControlWriter.java: New class.
    	* ObservingTerminal.java: Rename ObservingTerminalObserver to
    	Observable.
    	(afterReadLine, getObse

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/bindir/ChangeLog                  |    5 +
 frysk-core/frysk/bindir/fhpd.java                  |   34 ++++-
 frysk-core/frysk/hpd/CLI.java                      |   14 +-
 frysk-core/frysk/hpd/ChangeLog                     |    5 +
 frysk-core/frysk/util/ChangeLog                    |    7 +
 .../frysk/util/FlowControlWriter.java              |  143 ++++++++++++++------
 frysk-core/frysk/util/ObservingTerminal.java       |   35 ++++--
 frysk-gui/frysk/gui/monitor/ConsoleWidget.java     |    2 +-
 frysk-gui/frysk/vtecli/ConsoleWindow.java          |    2 +-
 9 files changed, 180 insertions(+), 67 deletions(-)
 copy frysk-sys/frysk/testbed/TearDownExpect.java => frysk-core/frysk/util/FlowControlWriter.java (54%)

First 500 lines of diff:
diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog
index f570d19..8a4cbe8 100644
--- a/frysk-core/frysk/bindir/ChangeLog
+++ b/frysk-core/frysk/bindir/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-28  Tim Moore  <timoore@redhat.com>
+
+	* fhpd.java (TerminalObserver): New class
+	(CommandLine()): Use TerminalObserver and FlowControlWriter.
+
 2008-02-27  Sami Wagiaalla  <swagiaal@redhat.com> 
 
 	* fstack.java(stackCore): Use PrintStackOptions instead of boolean
diff --git a/frysk-core/frysk/bindir/fhpd.java b/frysk-core/frysk/bindir/fhpd.java
index 3a5f285..ed2dc6c 100644
--- a/frysk-core/frysk/bindir/fhpd.java
+++ b/frysk-core/frysk/bindir/fhpd.java
@@ -47,9 +47,13 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.List;
+import java.util.Observable;
+import java.util.Observer;
+
 import frysk.hpd.CLI;
 import jline.Completor;
 import jline.ConsoleReader;
+import frysk.util.FlowControlWriter;
 import frysk.proc.Manager;
 import frysk.util.CommandlineParser;
 import frysk.util.ObservingTerminal;
@@ -74,6 +78,21 @@ public class fhpd {
             return cli.complete (buffer, cursor, candidates);
         }
     }
+    static class TerminalObserver implements Observer {
+	private FlowControlWriter writer;
+	
+	public TerminalObserver(FlowControlWriter writer) {
+	    this.writer = writer;
+	}
+	public void update(Observable observable, Object arg) {
+	    ObservingTerminal.Observable obs = (ObservingTerminal.Observable)observable;
+	    if (obs.getTerminal().getInputEntered()) {
+		writer.pause();
+	    } else {
+		writer.unpause();
+	    }
+	}
+    }
 
     // Start the command line in its own thread; but from within
     // the event-loop.  This ensures that the event-loop is up and
@@ -84,14 +103,18 @@ public class fhpd {
 	private ConsoleReader reader;
 	CommandLine() {
 	    // Construct the HPD.
-	    cli = new CLI("(fhpd) ", System.out);
-
 	    try {
+                ObservingTerminal terminal = new ObservingTerminal(FileDescriptor.in);
+                PrintWriter printWriter = new PrintWriter(System.out);
+                FlowControlWriter writer = new FlowControlWriter(printWriter);
+                terminal.getObservable()
+                    .addObserver(new TerminalObserver(writer));
+                cli = new CLI("(fhpd) ", writer);
 		reader = new ConsoleReader
-		    (new FileInputStream(java.io.FileDescriptor.in),
-		     new PrintWriter(System.out),
+                    (new FileInputStream(java.io.FileDescriptor.in),
+		     printWriter,
 		     null,
-		     new ObservingTerminal(FileDescriptor.in));
+		     terminal);
 	    } catch (IOException ioe) {
 		System.out.println("ERROR: Could not create a command line");
 		System.out.print(ioe.getMessage());
@@ -164,7 +187,6 @@ public class fhpd {
     
         parser.setHeader("Usage: fhpd <PID> || fhpd <EXEFILE> || fhpd <COREFILE> [<EXEFILE>]");
         parser.parse(args);
-
 	Manager.eventLoop.add(new CommandLine());
 
 	// Run the event loop then exit when it exits (or crashes).
diff --git a/frysk-core/frysk/hpd/CLI.java b/frysk-core/frysk/hpd/CLI.java
index fc770bc..35bc9e5 100644
--- a/frysk-core/frysk/hpd/CLI.java
+++ b/frysk-core/frysk/hpd/CLI.java
@@ -40,8 +40,8 @@
 package frysk.hpd;
 
 import frysk.debuginfo.ObjectDeclarationSearchEngine;
-import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.io.Writer;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -218,12 +218,12 @@ public class CLI {
     /**
      * Constructor
      * @param prompt String initially to be used as the prompt
-     * @param out Stream for output. This really should be a PrintWriter
+     * @param out PrintWriter for output
      * @param steppingEngine existing SteppingEngine
      */
-    public CLI(String prompt, PrintStream out, SteppingEngine steppingEngine) {
+    public CLI(String prompt, Writer outWriter, SteppingEngine steppingEngine) {
         this.prompt = prompt;
-        outWriter = new PrintWriter(out, true);
+        this.outWriter = new PrintWriter(outWriter);
         this.steppingEngine = steppingEngine;
         idManager = ProcTaskIDManager.getSingleton();
 
@@ -254,10 +254,10 @@ public class CLI {
     /**
      * Constructor that creates a new steppingEngine
      * @param prompt String initially to be used as the prompt
-     * @param out Stream for output. This really should be a PrintWriter
+     * @param out PrintWriter for output.
      */
-    public CLI(String prompt, PrintStream out) {
-        this(prompt, out, new SteppingEngine());
+    public CLI(String prompt, Writer outWriter) {
+        this(prompt, outWriter, new SteppingEngine());
     }
    
     public String getPrompt() {
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index 28d1f25..917fd09 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-28  Tim Moore  <timoore@redhat.com>
+
+	* CLI.java (constructors): Take a Writer argument instead of a
+	PrintStream.
+	
 2008-02-27  Rick Moseley  <rmoseley@redhat.com>
 
 	* ViewsetCommand.java: Fix error when duplicate executables are
diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog
index f7a2866..0ec9ce3 100644
--- a/frysk-core/frysk/util/ChangeLog
+++ b/frysk-core/frysk/util/ChangeLog
@@ -1,3 +1,10 @@
+2008-02-28  Tim Moore  <timoore@redhat.com>
+
+	* FlowControlWriter.java: New class.
+	* ObservingTerminal.java: Rename ObservingTerminalObserver to
+	Observable.
+	(afterReadLine, getObservable): New methods.
+	
 2008-02-27  Sami Wagiaalla  <swagiaal@redhat.com>
 
 	* TestStackTraceAction.java: Use PrintStackOptions instead of boolean list.
diff --git a/frysk-sys/frysk/testbed/TearDownExpect.java b/frysk-core/frysk/util/FlowControlWriter.java
similarity index 54%
copy from frysk-sys/frysk/testbed/TearDownExpect.java
copy to frysk-core/frysk/util/FlowControlWriter.java
index 0e50faf..b0b76fd 100644
--- a/frysk-sys/frysk/testbed/TearDownExpect.java
+++ b/frysk-core/frysk/util/FlowControlWriter.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2007, 2008, Red Hat Inc.
+// Copyright 2008 Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -37,60 +37,119 @@
 // version and license this file solely under the GPL without
 // exception.
 
-package frysk.testbed;
+package frysk.util;
 
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Iterator;
-import frysk.expunit.Expect;
-import java.io.File;
-import frysk.rsl.Log;
+import java.io.FilterWriter;
+import java.io.IOException;
+import java.io.Writer;
 
 /**
- * Framework for cleaning up temporary processes created as part of a
- * test run.
+ * Extension of Writer that allows output to be paused.
  */
+public class FlowControlWriter extends FilterWriter {
+    private Writer outStream;
+    private boolean paused = false;
 
-public class TearDownExpect extends Expect {
-    private static final Log fine = Log.fine(TearDownExpect.class);
-    public TearDownExpect(String[] args) {
-	super(args);
-	add(this);
+    /**
+     * @param out
+     */
+    public FlowControlWriter(Writer outStream) {
+	super(outStream);
+	this.outStream = outStream;
     }
-    public TearDownExpect(File program) {
-	super(program);
-	add(this);
+
+    public synchronized boolean isPaused() {
+	return paused;
     }
-    public TearDownExpect(String command) {
-	super(command);
-	add(this);
+    
+    public synchronized void pause() {
+	paused = true;
+    }
+    
+    public synchronized void unpause() {
+	paused = false;
+	notifyAll();
+    }
+    
+    public synchronized void flush () {
+	while (paused) {
+	    try {
+		wait();
+	    }
+	    catch (InterruptedException e) {
+		
+	    }
+	}
+	try {
+	    outStream.flush();
+	}
+	catch (IOException e) {
+	}
     }
 
-    /**
-     * Collection of expect classes.
-     */
-    private static Set expects = new HashSet();
-    /**
-     * Add the Expect class to the collection of things that should be
-     * blown away.
-     */
-    private static void add (Expect expect) {
-	expects.add(expect);
-	fine.log("add", expect);
-	TearDownProcess.add(expect.getPid());
+    public synchronized void close() throws IOException {
+	while (paused) {
+	    try {
+		wait();
+	    }
+	    catch (InterruptedException e) {
+		
+	    }
+	}
+	outStream.close();
+	super.close();
     }
 
-    public static void tearDown () {
-	for (Iterator i = expects.iterator(); i.hasNext(); ) {
-	    Expect e = (Expect)i.next();
+    public synchronized void write(char[] buf, int offset, int len) throws IOException {
+	while (paused) {
 	    try {
-		e.close();
-		fine.log("tearDown", e);
-	    } catch (RuntimeException r) {
-		fine.log("tearDown", e, "failed", r);
-		// Toss; teardown.
+		wait();
 	    }
-	    i.remove();
+	    catch (InterruptedException e) {
+		
+	    }
+	}
+	outStream.write(buf, offset, len);
+	try {
+	    outStream.flush();
+	}
+	catch (IOException e) {
+	}
+    }
+
+    public synchronized void write(int b) throws IOException {
+	while (paused) {
+	    try {
+		wait();
+	    }
+	    catch (InterruptedException e) {
+		
+	    }
+	}
+	outStream.write(b);
+	try {
+	    outStream.flush();
+	}
+	catch (IOException e) {
+	}
+    }
+
+    public synchronized void write(String str, int offset, int len) throws IOException {
+	while (paused) {
+	    try {
+		wait();
+	    }
+	    catch (InterruptedException e) {
+		
+	    }
+	}
+	outStream.write(str, offset, len);
+	try {
+	    outStream.flush();
+	}
+	catch (IOException e) {
+	    
 	}
     }
+    
 }
diff --git a/frysk-core/frysk/util/ObservingTerminal.java b/frysk-core/frysk/util/ObservingTerminal.java
index 3aa67e7..162be63 100644
--- a/frysk-core/frysk/util/ObservingTerminal.java
+++ b/frysk-core/frysk/util/ObservingTerminal.java
@@ -40,8 +40,6 @@
 package frysk.util;
 
 import java.io.*;
-import java.util.Observable;
-
 import jline.ConsoleReader;
 
 import frysk.sys.FileDescriptor;
@@ -49,33 +47,41 @@ import frysk.sys.FileDescriptor;
 
 public class ObservingTerminal
     extends PtyTerminal {
-    public class ObservingTerminalObserver extends Observable {
-        ObservingTerminal terminal;
-        ObservingTerminalObserver(ObservingTerminal terminal) {
+    public class Observable extends java.util.Observable {
+        private final ObservingTerminal terminal;
+        Observable(ObservingTerminal terminal) {
             this.terminal = terminal;
         }
         public void setChanged() {
             super.setChanged();
         }
+        
+        public ObservingTerminal getTerminal() {
+            return terminal;
+        }
     }
 
-    final ObservingTerminalObserver observable;
+    final Observable observable;
     
     boolean inputEntered = false;
     
+    public boolean getInputEntered() {
+	return inputEntered;
+    }
+    
     public ObservingTerminal(FileDescriptor fd) {
         super(fd);
-        observable = new ObservingTerminalObserver(this);
+        observable = new Observable(this);
     }
 
     public ObservingTerminal(File file) {
         super(file);
-        observable = new ObservingTerminalObserver(this);
+        observable = new Observable(this);
     }
 
     public ObservingTerminal(String string) {
         super(string);
-        observable = new ObservingTerminalObserver(this);
+        observable = new Observable(this);
     }
     
     public void beforeReadLine(ConsoleReader reader, String prompt,
@@ -95,7 +101,16 @@ public class ObservingTerminal
         return result;
     }
 
-    public ObservingTerminalObserver getObservable() {
+    
+    public void afterReadLine(ConsoleReader reader, String prompt,
+	    Character mask) {
+	inputEntered = false;
+	observable.setChanged();
+	observable.notifyObservers();
+	super.afterReadLine(reader, prompt, mask);
+    }
+
+    public Observable getObservable() {
         return observable;
     }
                
diff --git a/frysk-gui/frysk/gui/monitor/ConsoleWidget.java b/frysk-gui/frysk/gui/monitor/ConsoleWidget.java
index 38c49af..30ab1a2 100644
--- a/frysk-gui/frysk/gui/monitor/ConsoleWidget.java
+++ b/frysk-gui/frysk/gui/monitor/ConsoleWidget.java
@@ -69,7 +69,7 @@ public class ConsoleWidget extends Bin {
 
 			try
 			{
-			  cli = new CLI("(frysk) ", new PrintStream( new FileOutputStream(new File(fname)) ) );
+			  cli = new CLI("(frysk) ", new PrintWriter( new FileOutputStream(new File(fname)) ) );
 			}
 			catch (IOException ioe)
 			{
diff --git a/frysk-gui/frysk/vtecli/ConsoleWindow.java b/frysk-gui/frysk/vtecli/ConsoleWindow.java
index ae535cf..b2b69a7 100644
--- a/frysk-gui/frysk/vtecli/ConsoleWindow.java
+++ b/frysk-gui/frysk/vtecli/ConsoleWindow.java
@@ -74,7 +74,7 @@ public class ConsoleWindow
       try
         {
           cli = new CLI("(frysk) ", 
-                        new PrintStream(new FileOutputStream(new File(fname))));
+                        new PrintWriter(new FileOutputStream(new File(fname))));
         }
       catch (IOException ioe)
         {


hooks/post-receive
--
frysk system monitor/debugger


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]