Skip to content

Commit b369ed5

Browse files
committed
DBus : fix return value in method with callbacks
1 parent 25d0eec commit b369ed5

3 files changed

Lines changed: 46 additions & 5 deletions

File tree

src/javaforce/ipc/DBus.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,14 +1064,15 @@ private void method_call() throws Exception {
10641064
//to avoid deadlock this must be done on a new thread : TODO : create a thread pool
10651065
String _member = member;
10661066
String _sender = sender;
1067+
int _msg_serial = msg_serial; //field value may change with next inbound msg
10671068
new Thread() {
10681069
public void run() {
10691070
try {
10701071
Object ret = ep.dispatch(_member, args);
1071-
write_msg(MSG_RETURN, _sender, nextSerial(), msg_serial, _member, new Object[] {ret});
1072+
write_msg(MSG_RETURN, _sender, nextSerial(), _msg_serial, _member, new Object[] {ret});
10721073
} catch (Exception e) {
10731074
if (debug) JFLog.log(e);
1074-
write_msg(MSG_ERROR, _sender, nextSerial(), msg_serial, _member, new Object[] {e.toString()});
1075+
write_msg(MSG_ERROR, _sender, nextSerial(), _msg_serial, _member, new Object[] {e.toString()});
10751076
}
10761077
}
10771078
}.start();

src/javaforce/ipc/IPC.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public interface IPC {
1212
/** Disconnect from IPC service. */
1313
public boolean disconnect();
1414

15+
/** Return name on message bus. */
16+
public String getBusName();
17+
1518
/** Invoke RPC on specified end point. */
1619
public Object invoke(String dest, String method, Object... args) throws Exception;
1720

src/javaforce/tests/TestIPC.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
public class TestIPC {
1616

1717
private static boolean debug = false;
18+
private static boolean debug_callback = true;
1819

1920
private static boolean use_tcp = false;
2021
private static int tcp_port = 8001;
@@ -39,7 +40,9 @@ private static void server() {
3940
} else {
4041
transport = DBus.createTransport();
4142
}
42-
IPC ipc = new DBus(new TestEndPoint("javaforce.TestIPC.Server"), transport);
43+
TestEndPoint ep = new TestEndPoint("javaforce.TestIPC.Server");
44+
IPC ipc = new DBus(ep, transport);
45+
ep.setIPC(ipc);
4346
if (!ipc.connect()) {
4447
JFLog.log("IPC.connect() failed");
4548
return;
@@ -90,15 +93,18 @@ public void run() {
9093
} else {
9194
transport = DBus.createTransport();
9295
}
93-
ipc = new DBus(new TestEndPoint(null), transport);
96+
TestEndPoint ep = new TestEndPoint(null);
97+
ipc = new DBus(ep, transport);
9498
if (!ipc.connect()) {
9599
JFLog.log("IPC.connect() failed");
96100
return;
97101
}
102+
ep.setIPC(ipc);
98103
while (true) {
99104
try {
100105
ping();
101106
modify();
107+
callback();
102108
} catch (Exception e) {
103109
JFLog.log(e);
104110
}
@@ -135,6 +141,16 @@ public void modify() throws Exception {
135141
success++;
136142
}
137143
}
144+
public void callback() throws Exception {
145+
Object result = ipc.invoke("javaforce.TestIPC.Server", "process", ipc.getBusName(), 3);
146+
if (result == null) {
147+
if (debug) JFLog.log("result == null");
148+
error++;
149+
} else {
150+
if (debug) JFLog.log("result = " + result);
151+
success++;
152+
}
153+
}
138154
}
139155

140156
public static class TestEndPoint implements EndPoint {
@@ -145,6 +161,7 @@ public TestEndPoint(String name) {
145161

146162
private String name;
147163
private Dispatcher dispatcher;
164+
private IPC ipc;
148165

149166
public String getEndPointName() {
150167
return name;
@@ -154,7 +171,11 @@ public Object dispatch(String method, Object[] args) throws Exception {
154171
return dispatcher.dispatch(method, args);
155172
}
156173

157-
public static class Methods {
174+
public void setIPC(IPC ipc) {
175+
this.ipc = ipc;
176+
}
177+
178+
public class Methods {
158179
public boolean ping(int value) {
159180
if (debug) JFLog.log(String.format("ping(0x%x)", value));
160181
return true;
@@ -166,6 +187,22 @@ public byte[] modify(byte[] data) {
166187
data[2] = 0x66;
167188
return data;
168189
}
190+
public boolean process(String name, int cnt) {
191+
if (ipc != null) {
192+
for(int a=0;a<cnt;a++) {
193+
try {
194+
ipc.invoke(name, "callback", "count=" + a);
195+
} catch (Exception e) {
196+
JFLog.log(e);
197+
}
198+
}
199+
}
200+
return true;
201+
}
202+
public boolean callback(String value) {
203+
if (debug_callback) JFLog.log("callback:" + value);
204+
return true;
205+
}
169206
}
170207
}
171208
}

0 commit comments

Comments
 (0)