From b73167960d22722779c249041de3e9eb64fe7394 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Tue, 22 Oct 2002 20:28:54 +0000 Subject: [PATCH] New file. --- .../cdt/debug/mi/core/SessionProcess.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/SessionProcess.java diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/SessionProcess.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/SessionProcess.java new file mode 100644 index 00000000000..cfa6966a89e --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/SessionProcess.java @@ -0,0 +1,87 @@ +package org.eclipse.cdt.debug.mi.core; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.eclipse.cdt.debug.mi.core.command.CLICommand; + +/** + */ +public class SessionProcess extends Process { + + MISession session; + OutputStream out; + + public SessionProcess(MISession s) { + session = s; + } + + /** + * @see java.lang.Process#destroy() + */ + public void destroy() { + session.getGDBProcess().destroy(); + } + + /** + * @see java.lang.Process#exitValue() + */ + public int exitValue() { + return session.getGDBProcess().exitValue(); + } + + /** + * @see java.lang.Process#getErrorStream() + */ + public InputStream getErrorStream() { + return session.getMILogStream(); + } + + /** + * @see java.lang.Process#getInputStream() + */ + public InputStream getInputStream() { + return session.getMIConsoleStream(); + } + + /** + * @see java.lang.Process#getOutputStream() + */ + public OutputStream getOutputStream() { + if (out == null) { + out = new OutputStream() { + StringBuffer buf = new StringBuffer(); + public void write(int b) throws IOException { + buf.append((char)b); + if (b == '\n') { + post(); + } + } + + // Encapsulate the string sent to gdb in a fake + // command and post it to the TxThread. + public void post() throws IOException { + // Throw away the newline. + String str = buf.toString().trim(); + CLICommand cmd = new CLICommand(str); + buf.setLength(0); + try { + session.postCommand(cmd); + } catch (MIException e) { + throw new IOException(e.getMessage()); + } + } + }; + } + return out; + } + + /** + * @see java.lang.Process#waitFor() + */ + public int waitFor() throws InterruptedException { + return session.getGDBProcess().waitFor(); + } + +}