Fixing bug for return value from callback in C++ (sendReturnObj is called twice)...
[iot2.git] / iotjava / iotrmi / Java / sample / CallBack_CBSkeleton.java
1 package iotrmi.Java.sample;
2
3 import java.io.IOException;
4 import java.util.Set;
5 import java.util.Arrays;
6 import iotrmi.Java.IoTRMIObject;
7
8 public class CallBack_CBSkeleton implements CallBackInterface {
9
10         private int objectId = 0;       // Default value is 0
11         private final static String[] methodSignatures = {
12
13                 "intprintInt()",
14                 "voidsetInt(int)"
15         };
16         private CallBackInterface cb;
17
18
19         /**
20          * Constructors
21          */
22         public CallBack_CBSkeleton(CallBackInterface _cb, int _objectId) throws
23                 ClassNotFoundException, InstantiationException,
24                         IllegalAccessException, IOException {
25
26                 cb = _cb;
27                 objectId = _objectId;
28                 System.out.println("Creating CallBack_Skeleton and waiting!");
29         }
30
31         
32         public int printInt() {
33                 return cb.printInt();
34         }
35         
36         
37         public int ___printInt() {
38                 return printInt();
39         }
40
41
42         public void setInt(int _i) {
43                 cb.setInt(_i);
44         }
45         
46         
47         public void ___setInt(IoTRMIObject rmiObj) {
48                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
49                         new Class<?>[] { null }, new Class<?>[] { null });
50                 setInt((int) paramObj[0]);
51         }
52         
53
54         public Object invokeMethod(IoTRMIObject rmiObj) throws IOException {
55
56                 String methodSign = rmiObj.getSignature();
57                 Object[] paramObj = null;
58                 Object retObj = null;
59
60                 if (methodSign.equals("intprintInt()")) {
61                         retObj = ___printInt();
62                 } else if (methodSign.equals("voidsetInt(int)")) {
63                         ___setInt(rmiObj);
64                 } else
65                         throw new Error("Signature not recognized!");
66                 System.out.println("Return object: " + retObj);
67
68                 return retObj;
69         }
70
71
72         // Return method signatures
73         public static String[] getMethodSignatures() {
74
75                 return methodSignatures;
76         }
77
78
79         public static void main(String[] args) throws Exception {
80
81         }
82 }