mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-22 08:25:25 +02:00
more framework.
This commit is contained in:
parent
53696af5f6
commit
1706881c03
18 changed files with 196 additions and 147 deletions
|
@ -19,14 +19,14 @@ public class Queue {
|
|||
list = Collections.synchronizedList(new LinkedList());
|
||||
}
|
||||
|
||||
public Command removeCommand(String id) {
|
||||
public Command removeCommand(int id) {
|
||||
//print("in removeCommand(" + id + ") - entering");
|
||||
synchronized (list) {
|
||||
int size = list.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Command cmd = (Command)list.get(i);
|
||||
String token = cmd.getToken();
|
||||
if (token.equals(id)) {
|
||||
int token = cmd.getToken();
|
||||
if (token == id) {
|
||||
list.remove(cmd);
|
||||
return cmd;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
|||
import java.io.InputStreamReader;
|
||||
|
||||
import org.eclipse.cdt.debug.mi.core.command.Command;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIAsyncRecord;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIOOBRecord;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIOutput;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIResultRecord;
|
||||
|
@ -31,7 +32,8 @@ public class RxThread extends Thread {
|
|||
* search for the corresponding token in rxQueue.
|
||||
*/
|
||||
public void run () {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(session.getInputStream()));
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(session.getInputStream()));
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
try {
|
||||
while (true) {
|
||||
|
@ -52,20 +54,36 @@ public class RxThread extends Thread {
|
|||
void processMIOutput(String buffer) {
|
||||
MIOutput response = session.parse(buffer);
|
||||
if (response != null) {
|
||||
String id = response.getToken();
|
||||
Queue rxQueue = session.getRxQueue();
|
||||
Command cmd = rxQueue.removeCommand(id);
|
||||
if (cmd != null) {
|
||||
cmd.setMIOutput(response);
|
||||
cmd.notifyAll();
|
||||
|
||||
// Notify any command waiting for a ResultRecord.
|
||||
MIResultRecord rr = response.getMIResultRecord();
|
||||
if (rr != null) {
|
||||
int id = rr.geToken();
|
||||
Command cmd = rxQueue.removeCommand(id);
|
||||
if (cmd != null) {
|
||||
cmd.setMIOutput(response);
|
||||
cmd.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
// A command may wait on a specific oob, like breakpointhit
|
||||
MIOOBRecord[] oobs = response.getMIOOBRecords();
|
||||
if (oobs != null && oobs.length > 0) {
|
||||
processMIOOBRecords(oobs);
|
||||
for (int i = 0; i < oobs.length; i++) {
|
||||
if (oobs[i] instanceof MIAsyncRecord) {
|
||||
int id = ((MIAsyncRecord)oobs[i]).getToken();
|
||||
Command cmd = rxQueue.removeCommand(id);
|
||||
if (cmd != null) {
|
||||
cmd.setMIOutput(response);
|
||||
cmd.notifyAll();
|
||||
}
|
||||
}
|
||||
processMIOOBRecord(oobs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void processMIOOBRecords(MIOOBRecord[] oobs) {
|
||||
void processMIOOBRecord(MIOOBRecord oob) {
|
||||
// Dispatch a thread to deal with the listeners.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public class TxThread extends Thread {
|
|||
// - Move to the RxQueue
|
||||
if (cmd != null) {
|
||||
OutputStream out = session.getOutputStream();
|
||||
cmd.setToken(Integer.toString(token));
|
||||
cmd.setToken(token);
|
||||
//System.out.println("Tx " + cmd.toString());
|
||||
try {
|
||||
out.write(cmd.toString().getBytes());
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.eclipse.cdt.debug.mi.core.output.MIOutput;
|
|||
*/
|
||||
public class CLICommand extends Command
|
||||
{
|
||||
String token = "";
|
||||
int token = -1;
|
||||
MIOutput miOutput = null;
|
||||
|
||||
/**
|
||||
|
@ -26,11 +26,11 @@ public class CLICommand extends Command
|
|||
*
|
||||
* @return the text representation of this command
|
||||
*/
|
||||
public String getToken() {
|
||||
public int getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String t) {
|
||||
public void setToken(int t) {
|
||||
token = t;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@ public abstract class Command
|
|||
*
|
||||
* @return the identifier of this request
|
||||
*/
|
||||
public abstract String getToken();
|
||||
public abstract int getToken();
|
||||
|
||||
public abstract void setToken(String token);
|
||||
public abstract void setToken(int token);
|
||||
|
||||
public abstract String toString();
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public class MICommand extends Command
|
|||
String[] options = empty;
|
||||
String[] parameters = empty;
|
||||
String operation = "";
|
||||
String token = "";
|
||||
int token = -1;
|
||||
MIOutput miOutput = null;
|
||||
|
||||
public MICommand(String oper) {
|
||||
|
@ -95,11 +95,11 @@ public class MICommand extends Command
|
|||
return command + "\n";
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
public int getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String t) {
|
||||
public void setToken(int t) {
|
||||
token = t;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,53 @@
|
|||
package org.eclipse.cdt.debug.mi.core.output;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class MIAsyncRecord extends MIOOBRecord {
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.mi.core.MIOutput#interpret()
|
||||
*/
|
||||
public boolean interpret() {
|
||||
return super.interpret();
|
||||
public final static int EXEC_ASYNC = 0;
|
||||
public final static int STATUS_ASYNC = 1;
|
||||
public final static int NOTIFY_ASYNC = 2;
|
||||
|
||||
final static MIResult[] nullResults = new MIResult[0];
|
||||
|
||||
MIResult[] results = null;
|
||||
String asynClass = "";
|
||||
int token = -1;
|
||||
int type = 0;
|
||||
|
||||
public int getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(int t) {
|
||||
token = t;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int t) {
|
||||
type = t;
|
||||
}
|
||||
|
||||
|
||||
public String getAsyncClass() {
|
||||
return asynClass;
|
||||
}
|
||||
|
||||
public void setAsyncClass(String a) {
|
||||
asynClass = a;
|
||||
}
|
||||
|
||||
public MIResult[] getResults() {
|
||||
if (results == null) {
|
||||
return nullResults;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public void setResults(MIResult[] res) {
|
||||
results = res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,7 @@
|
|||
package org.eclipse.cdt.debug.mi.core.output;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class MIConsoleStreamOutput extends MIStreamRecord {
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.mi.core.MIOutput#interpret()
|
||||
*/
|
||||
public boolean interpret() {
|
||||
return super.interpret();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +1,6 @@
|
|||
package org.eclipse.cdt.debug.mi.core.output;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class MIExecAsyncOutput extends MIAsyncRecord {
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.mi.core.MIOutput#interpret()
|
||||
*/
|
||||
public boolean interpret() {
|
||||
return super.interpret();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +1,7 @@
|
|||
package org.eclipse.cdt.debug.mi.core.output;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class MILogStreamOutput extends MIStreamRecord {
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.mi.core.MIOutput#interpret()
|
||||
*/
|
||||
public boolean interpret() {
|
||||
return super.interpret();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,12 +4,4 @@ package org.eclipse.cdt.debug.mi.core.output;
|
|||
*
|
||||
*/
|
||||
public class MINotifyAsyncOutput extends MIAsyncRecord {
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.mi.core.MIOutput#interpret()
|
||||
*/
|
||||
public boolean interpret() {
|
||||
return super.interpret();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,22 +3,5 @@ package org.eclipse.cdt.debug.mi.core.output;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public class MIOOBRecord {
|
||||
|
||||
public final int ASYNC_STOPPED = 0;
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.mi.core.MIOutput#interpret()
|
||||
*/
|
||||
public boolean interpret() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getAsyncType() {
|
||||
return ASYNC_STOPPED;
|
||||
}
|
||||
|
||||
public MIResult[] getResults() {
|
||||
return null;
|
||||
}
|
||||
public abstract class MIOOBRecord {
|
||||
}
|
||||
|
|
|
@ -5,17 +5,26 @@ package org.eclipse.cdt.debug.mi.core.output;
|
|||
public class MIOutput {
|
||||
|
||||
public static final String terminator = "(gdb)\n";
|
||||
String token = "";
|
||||
public static final MIOOBRecord[] nullOOBRecord = new MIOOBRecord[0];
|
||||
MIResultRecord rr = null;
|
||||
MIOOBRecord[] oobs = null;
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public MIResultRecord getMIResultRecord() {
|
||||
return null;
|
||||
return rr;
|
||||
}
|
||||
|
||||
public void setMIResultRecord(MIResultRecord res) {
|
||||
rr = res ;
|
||||
}
|
||||
|
||||
public MIOOBRecord[] getMIOOBRecords() {
|
||||
return null;
|
||||
if (oobs == null)
|
||||
return nullOOBRecord;
|
||||
return oobs;
|
||||
}
|
||||
|
||||
public void setMIOOBRecords(MIOOBRecord [] bands) {
|
||||
oobs = bands;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,84 @@
|
|||
package org.eclipse.cdt.debug.mi.core.output;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public class MIParser {
|
||||
|
||||
public MIOutput parse(String buffer) {
|
||||
return new MIOutput();
|
||||
MIOutput mi = new MIOutput();
|
||||
MIResultRecord rr = null;
|
||||
List oobs = new ArrayList(1);
|
||||
int id = -1;
|
||||
|
||||
StringTokenizer st = new StringTokenizer(buffer, "\n");
|
||||
while (st.hasMoreTokens()) {
|
||||
String token = st.nextToken();
|
||||
|
||||
// Fetch the Token/Id
|
||||
if (Character.isDigit(token.charAt(0))) {
|
||||
int i = 1;
|
||||
while (Character.isDigit(token.charAt(i)) && i < token.length()) {
|
||||
i++;
|
||||
}
|
||||
String numbers = token.substring(i);
|
||||
try {
|
||||
id = Integer.parseInt(numbers);
|
||||
} catch(NumberFormatException e) {
|
||||
}
|
||||
token = token.substring(i);
|
||||
}
|
||||
|
||||
if (token.charAt(0) == '^') {
|
||||
rr = processMIResultRecord(token.substring(1), id);
|
||||
} else {
|
||||
MIOOBRecord br = processMIOOBRecord(token.substring(1), id);
|
||||
if (br != null) {
|
||||
oobs.add(br);
|
||||
}
|
||||
}
|
||||
}
|
||||
MIOOBRecord[] bands = (MIOOBRecord[])oobs.toArray(new MIOOBRecord[oobs.size()]);
|
||||
mi.setMIOOBRecords(bands);
|
||||
mi.setMIResultRecord(rr);
|
||||
return mi;
|
||||
}
|
||||
|
||||
MIResultRecord processMIResultRecord(String buffer, int id) {
|
||||
MIResultRecord rr = new MIResultRecord();
|
||||
rr.setToken(id);
|
||||
if (buffer.startsWith("done")) {
|
||||
rr.setResultClass("done");
|
||||
} else if (buffer.startsWith("error")) {
|
||||
rr.setResultClass("error");
|
||||
} else if (buffer.startsWith("exit")) {
|
||||
rr.setResultClass("exit");
|
||||
} else if (buffer.startsWith("running")) {
|
||||
rr.setResultClass("running");
|
||||
} else if (buffer.startsWith("connected")) {
|
||||
rr.setResultClass("connected");
|
||||
} else {
|
||||
// FIXME:
|
||||
// Error throw an exception?
|
||||
}
|
||||
int i = buffer.indexOf( ',' );
|
||||
if (i != -1) {
|
||||
String s = buffer.substring(i + 1);
|
||||
MIResult[] res = processMIResults(s);
|
||||
rr.setResults(res);
|
||||
}
|
||||
return rr;
|
||||
}
|
||||
|
||||
MIOOBRecord processMIOOBRecord(String buffer, int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MIResult[] processMIResults(String buffer) {
|
||||
return new MIResult[0];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,18 @@ package org.eclipse.cdt.debug.mi.core.output;
|
|||
*/
|
||||
public class MIResultRecord {
|
||||
|
||||
public static final MIResult[] nullResults = new MIResult[0];
|
||||
MIResult[] results = null;
|
||||
String resultClass = "";
|
||||
int token = -1;
|
||||
|
||||
public int geToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(int t) {
|
||||
token = t;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -12,7 +23,18 @@ public class MIResultRecord {
|
|||
return resultClass;
|
||||
}
|
||||
|
||||
public void setResultClass(String type) {
|
||||
resultClass = type;
|
||||
}
|
||||
|
||||
public MIResult[] getResults() {
|
||||
return null;
|
||||
if (results == null) {
|
||||
return nullResults;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public void setResults(MIResult[] res) {
|
||||
results = res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,7 @@
|
|||
package org.eclipse.cdt.debug.mi.core.output;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class MIStatusAsyncOutput extends MIAsyncRecord {
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.mi.core.MIOutput#interpret()
|
||||
*/
|
||||
public boolean interpret() {
|
||||
return super.interpret();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +1,6 @@
|
|||
package org.eclipse.cdt.debug.mi.core.output;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class MIStreamRecord extends MIOOBRecord {
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.mi.core.MIOutput#interpret()
|
||||
*/
|
||||
public boolean interpret() {
|
||||
return super.interpret();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +1,6 @@
|
|||
package org.eclipse.cdt.debug.mi.core.output;
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
public class MITargetStreamOutput extends MIStreamRecord {
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.debug.mi.core.MIOutput#interpret()
|
||||
*/
|
||||
public boolean interpret() {
|
||||
return super.interpret();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue