@@ -17,6 +17,7 @@ public class PipedProcess {
17
17
private BufferedReader reader = null ;
18
18
private BufferedWriter writer = null ;
19
19
private Process process ;
20
+ private String nextAnalyzeCommand ;
20
21
21
22
/** Start process. */
22
23
public final void initialize (EngineConfig engineConfig ) {
@@ -31,6 +32,27 @@ public EngineConfig getEngineConfig() {
31
32
return engineConfig ;
32
33
}
33
34
35
+ private void writeAnalyzeCommands (String cmd ) {
36
+ writeLineToProcess ("stop" );
37
+ writeLineToProcess ("isready" );
38
+ writeLineToProcess (cmd );
39
+ writeLineToProcess ("go infinite" );
40
+ }
41
+
42
+ public synchronized void analyzeNext () {
43
+ if (this .nextAnalyzeCommand != null ) {
44
+ writeAnalyzeCommands (nextAnalyzeCommand );
45
+ this .nextAnalyzeCommand = null ;
46
+ }
47
+ }
48
+
49
+ /**
50
+ * TODO: use a delayed queue instead (e.g. DelayQueue) or FutureTask?
51
+ */
52
+ public synchronized void setNextAnalyzeCommand (String nextAnalyzeCommand ) {
53
+ this .nextAnalyzeCommand = nextAnalyzeCommand ;
54
+ }
55
+
34
56
public boolean isAlive () {
35
57
return processAlive && !isTerminated ();
36
58
}
@@ -83,9 +105,9 @@ public final synchronized String readLineFromProcess() {
83
105
} catch (IOException e ) {
84
106
Log .e (TAG , "Error reading from process" );
85
107
}
86
- // if (ret != null && ret.length() > 0) {
87
- // Log.d("SCID", "Engine -> GUI: " + ret);
88
- // }
108
+ // if (ret != null && ret.length() > 0) {
109
+ // Log.d("SCID", "Engine -> GUI: " + ret);
110
+ // }
89
111
return ret ;
90
112
}
91
113
@@ -95,7 +117,7 @@ public final synchronized String readLineFromProcess() {
95
117
* @throws IOException
96
118
*/
97
119
public final synchronized void writeLineToProcess (String data ) {
98
- // Log.d("SCID", "GUI -> Engine: " + data);
120
+ // Log.d("SCID", "GUI -> Engine: " + data);
99
121
try {
100
122
writeToProcess (data + "\n " );
101
123
} catch (IOException e ) {
@@ -106,7 +128,8 @@ public final synchronized void writeLineToProcess(String data) {
106
128
107
129
/** Start the child process. */
108
130
private final void startProcess (EngineConfig engineConfig ) {
109
- ProcessBuilder builder = new ProcessBuilder (engineConfig .getExecutablePath ());
131
+ ProcessBuilder builder = new ProcessBuilder (
132
+ engineConfig .getExecutablePath ());
110
133
builder .redirectErrorStream (true );
111
134
try {
112
135
Log .d (TAG , "starting process" );
0 commit comments