public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Event-loop on main thread; consistent with other command-line utilities.
@ 2008-02-14 21:41 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-02-14 21:41 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  ea824c83ac5c61c806ad4fff8bd7fc304aab8b3a (commit)
      from  536bdb48547f55541dca484b61a1ba930363e407 (commit)

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

- Log -----------------------------------------------------------------
commit ea824c83ac5c61c806ad4fff8bd7fc304aab8b3a
Author: Andrew Cagney <cagney@redhat.com>
Date:   Thu Feb 14 16:41:13 2008 -0500

    Event-loop on main thread; consistent with other command-line utilities.
    
    frysk-core/frysk/bindir/ChangeLog
    2008-02-14  Andrew Cagney  <cagney@redhat.com>
    
    	* fhpd.java: Run the CLI in a sub-thread and the event-loop on the
    	main thread.

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

Summary of changes:
 frysk-core/frysk/bindir/ChangeLog |    5 ++
 frysk-core/frysk/bindir/fhpd.java |  134 +++++++++++++++++++++---------------
 2 files changed, 83 insertions(+), 56 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog
index 4167d36..1f83ca9 100644
--- a/frysk-core/frysk/bindir/ChangeLog
+++ b/frysk-core/frysk/bindir/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-14  Andrew Cagney  <cagney@redhat.com>
+
+	* fhpd.java: Run the CLI in a sub-thread and the event-loop on the
+	main thread.
+
 2008-02-13  Andrew Cagney  <cagney@redhat.com>
 
 	* fexe.java: Update to match Exe.
diff --git a/frysk-core/frysk/bindir/fhpd.java b/frysk-core/frysk/bindir/fhpd.java
index 11d9d72..b32bfbb 100644
--- a/frysk-core/frysk/bindir/fhpd.java
+++ b/frysk-core/frysk/bindir/fhpd.java
@@ -39,6 +39,7 @@
 
 package frysk.bindir;
 
+import frysk.event.Event;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -51,19 +52,19 @@ import frysk.util.CoreExePair;
 import frysk.proc.Manager;
 import frysk.proc.ProcId;
 import frysk.util.CommandlineParser;
-//import frysk.util.PtyTerminal;
 import frysk.util.ObservingTerminal;
 import gnu.classpath.tools.getopt.Option;
 import gnu.classpath.tools.getopt.OptionException;
 import frysk.sys.FileDescriptor;
 
 public class fhpd {
-    static int pid;
-    static File execFile;
-    static File core;
-    static File exeFile;
-    static boolean noExe = false;
-    static String sysroot;
+    private static int pid;
+    private static File execFile;
+    private static File core;
+    private static File exeFile;
+    private static boolean noExe = false;
+    private static String sysroot;
+    private static int exitStatus;
 
     final static class FhpdCompletor implements Completor {
         CLI cli;
@@ -75,10 +76,74 @@ public class fhpd {
         }
     }
 
+    // Start the command line in its own thread; but from within
+    // the event-loop.  This ensures that the event-loop is up and
+    // running before the CLI.
+    static class CommandLine extends Thread implements Event {
+	private String line = "";
+	private CLI cli;
+	private ConsoleReader reader;
+	CommandLine() {
+	    // Construct a command to pass in as initialization
+	    try {
+		if (pid > 0)
+		    line = "attach " + pid;
+		else if (execFile != null)
+		    line = "load " + execFile.getCanonicalPath();
+		else if (core != null) {
+		    line = "core " + core.getCanonicalPath();      
+		    if (exeFile != null)
+			line += " " + exeFile.getCanonicalPath();
+		    else if (noExe)
+			line +=" -noexe";
+		}
+		if (sysroot != null)
+		    line = line + " -sysroot " + sysroot;
+	    } catch (IOException e) {
+		System.err.println("Error: " + e);
+		System.exit(1);
+		return;
+	    }
+	    // Construct the HPD.
+	    cli = new CLI("(fhpd) ", System.out);
+	    try {
+		reader = new ConsoleReader
+		    (new FileInputStream(java.io.FileDescriptor.in),
+		     new PrintWriter(System.out),
+		     null,
+		     new ObservingTerminal(FileDescriptor.in));
+	    } catch (IOException ioe) {
+		System.out.println("ERROR: Could not create a command line");
+		System.out.print(ioe.getMessage());
+		System.exit(1);
+		return;
+	    }
+	    Completor fhpdCompletor = new FhpdCompletor(cli);
+	    reader.addCompletor(fhpdCompletor);
+	}
+	public void execute() {
+	    start();
+	}
+	public void run() {
+	    try {
+		cli.execCommand(line);
+		while (line != null && ! (line.equals("quit")
+					  || line.equals("q")
+					  || line.equals("exit"))) {
+		    line = reader.readLine(cli.getPrompt());
+		    cli.execCommand(line);
+		}
+	    } catch (IOException ioe) {
+		System.out.println("ERROR: Could not read from command line");
+		System.out.print(ioe.getMessage());
+		exitStatus = 1;
+	    }
+	    Manager.eventLoop.requestStop();
+	}
+    }
+    
     public static void main (String[] args) {
-        CLI cli;
         CommandlineParser parser = new CommandlineParser ("fhpd") {
-
                 //@Override
                 public void parseCommand (String[] command) {
                     execFile = new File (command[0]);
@@ -88,7 +153,6 @@ public class fhpd {
                                                    + command[0]);
                     }
                 }
-
                 //@Override
                 public void parsePids (ProcId[] pids) {
                     pid = pids[0].id;
@@ -126,53 +190,11 @@ public class fhpd {
     
         parser.setHeader("Usage: fhpd <PID> || fhpd <EXEFILE> || fhpd <COREFILE> [<EXEFILE>]");
         parser.parse(args);
-        Manager.eventLoop.start();
-        String line = "";
-    
-        try {
-            if (pid > 0)
-                line = "attach " + pid;
-            else if (execFile != null)
-                line = "load " + execFile.getCanonicalPath();
-            else if (core != null) {
-                line = "core " + core.getCanonicalPath();      
-                if (exeFile != null)
-                    line += " " + exeFile.getCanonicalPath();
-                else if (noExe)
-                    line +=" -noexe";
-            }
-            if (sysroot != null)
-                line = line + " -sysroot " + sysroot;
-        }
-        catch (IOException ignore) {}
-    
-        cli = new CLI("(fhpd) ", System.out);
-        ConsoleReader reader = null; // the jline reader
 
-        try {
-            reader = new ConsoleReader(new FileInputStream(java.io.FileDescriptor.in),
-                                       new PrintWriter(System.out),
-                                       null,
-                                       new ObservingTerminal(FileDescriptor.in));
-        }
-        catch (IOException ioe) {
-            System.out.println("ERROR: Could not create a command line");
-            System.out.print(ioe.getMessage());
-        }
+	Manager.eventLoop.add(new CommandLine());
 
-        Completor fhpdCompletor = new FhpdCompletor(cli);
-        reader.addCompletor(fhpdCompletor);
-        try {
-            cli.execCommand(line);
-            while (line != null && ! (line.equals("quit") || line.equals("q")
-                                      || line.equals("exit"))) {
-                    line = reader.readLine(cli.getPrompt());
-                    cli.execCommand(line);
-                }
-        }
-        catch (IOException ioe) {
-            System.out.println("ERROR: Could not read from command line");
-            System.out.print(ioe.getMessage());
-        }
+	// Run the event loop then exit when it exits (or crashes).
+	Manager.eventLoop.run();
+	System.exit(exitStatus);
     }
 }


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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-02-14 21:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-14 21:41 [SCM] master: Event-loop on main thread; consistent with other command-line utilities cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).