blob: b83d213393e96330ce34f65807f60d77197ad646 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.mi.core.command;
import org.eclipse.cdt.debug.mi.core.MIException;
import org.eclipse.cdt.debug.mi.core.output.MIInfo;
import org.eclipse.cdt.debug.mi.core.output.MILogStreamOutput;
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.MIStreamRecord;
/**
* A base class for all mi requests.
*/
public abstract class Command
{
private static int globalCounter;
int token = 0;
MIOutput output;
/**
* A global counter for all command, the token
* will be use to identify uniquely a command.
* Unless the value wraps around which is unlikely.
*/
private static synchronized int getUniqToken() {
int count = ++globalCounter;
// If we ever wrap around.
if (count <= 0) {
count = globalCounter = 1;
}
return count;
}
/**
* Returns the identifier of this request.
*
* @return the identifier of this request
*/
public int getToken() {
if (token == 0) {
token = getUniqToken();
}
return token;
}
// public void setToken(int token) {
// this.token = token;
// }
public MIOutput getMIOutput() {
return output;
}
public void setMIOutput(MIOutput mi) {
output = mi;
}
/**
* Parse the MIOutput generate after posting the command.
*/
public MIInfo getMIInfo () throws MIException {
MIInfo info = null;
MIOutput out = getMIOutput();
if (out != null) {
info = new MIInfo(out);
if (info.isError()) {
String mesg = info.getErrorMsg();
StringBuffer sb = new StringBuffer();
MIOOBRecord[] oobs = out.getMIOOBRecords();
for (int i = 0; i < oobs.length; i++) {
if (oobs[i] instanceof MILogStreamOutput) {
MIStreamRecord o = (MIStreamRecord) oobs[i];
sb.append(o.getString());
}
}
throw new MIException(mesg, sb.toString());
}
}
return info;
}
}
|