1515public 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