7a6b2776087704629b415b9ea1f8ba28669bf237
[iot2.git] / iotjava / iotrmi / Java / basics / TestClass_Stub.java
1 import java.util.Arrays;
2 import java.util.List;
3 import java.util.ArrayList;
4 import iotruntime.master.CommunicationHandler;
5
6 public class TestClass_Stub {
7
8         public static void main(String[] args) throws Exception {
9
10                 CommunicationHandler comHan = new CommunicationHandler(true);
11                 int numOfPorts = 1;
12                 int[] ports = comHan.getCallbackPorts(numOfPorts);
13
14                 int port = 5010;
15                 String address = "localhost";
16                 //String address = "128.195.136.170";   // dc-9.calit2.uci.edu
17                 int rev = 0;
18
19                 System.out.println("Allocated ports: " + Arrays.toString(ports));
20
21                 TestClassComplete_Stub tcstub = new TestClassComplete_Stub(port, address, rev, ports);
22                 System.out.println("==== SINGLE ====");
23                 System.out.println("Return value: " + tcstub.getByte((byte)68));
24                 System.out.println("Return value: " + tcstub.getShort((short)1234));
25                 System.out.println("Return value: " + tcstub.getLong(12345678l));
26                 System.out.println("Return value: " + tcstub.getFloat(12.345f));
27                 System.out.println("Return value: " + tcstub.getDouble(12345.678));
28                 System.out.println("Return value: " + tcstub.getBoolean(true));
29                 System.out.println("Return value: " + tcstub.getChar('c'));
30
31 /*              System.out.println("==== ARRAY ====");
32                 byte[] in1 = { 68, 69 };
33                 System.out.println("Return value: " + Arrays.toString(tcstub.getByteArray(in1)));
34                 short[] in2 = { (short)1234, (short)1235 };
35                 System.out.println("Return value: " + Arrays.toString(tcstub.getShortArray(in2)));
36                 long[] in3 = { 12345678l, 12356782l };
37                 System.out.println("Return value: " + Arrays.toString(tcstub.getLongArray(in3)));
38                 float[] in4 = { 12.345f, 12.346f };
39                 System.out.println("Return value: " + Arrays.toString(tcstub.getFloatArray(in4)));
40                 double[] in5 = { 12345.678, 12345.543 };
41                 System.out.println("Return value: " + Arrays.toString(tcstub.getDoubleArray(in5)));
42                 boolean[] in6 = { true, false };
43                 System.out.println("Return value: " + Arrays.toString(tcstub.getBooleanArray(in6)));
44                 char[] in7 = { 'c', 'e' };
45                 System.out.println("Return value: " + Arrays.toString(tcstub.getCharArray(in7)));
46
47                 System.out.println("==== LIST ====");
48                 List<Byte> inl1 = Arrays.asList(new Byte[] { 68, 69 });
49                 System.out.println("Return value: " + tcstub.getByteList(inl1));
50                 List<Short> inl2 = Arrays.asList(new Short[] { (short)1234, (short)1235 });
51                 System.out.println("Return value: " + tcstub.getShortList(inl2));
52                 List<Long> inl3 = Arrays.asList(new Long[] { 12345678l, 12356782l });
53                 System.out.println("Return value: " + tcstub.getLongList(inl3));
54                 List<Float> inl4 = Arrays.asList(new Float[] { 12.345f, 12.346f });
55                 System.out.println("Return value: " + tcstub.getFloatList(inl4));
56                 List<Double> inl5 = Arrays.asList(new Double[] { 12345.678, 12345.543 });
57                 System.out.println("Return value: " + tcstub.getDoubleList(inl5));
58                 List<Boolean> inl6 = Arrays.asList(new Boolean[] { true, false });
59                 System.out.println("Return value: " + tcstub.getBooleanList(inl6));
60                 List<Character> inl7 = Arrays.asList(new Character[] { 'c', 'e' });
61                 System.out.println("Return value: " + tcstub.getCharList(inl7));
62
63                 System.out.println("==== ENUM ====");
64                 Enum en = Enum.APPLE;
65                 Enum res = tcstub.handleEnum(en);
66                 System.out.println("Enum member: " + res);
67                 Enum[] enArr = { Enum.APPLE, Enum.ORANGE, Enum.APPLE, Enum.GRAPE };
68                 Enum[] resArr = tcstub.handleEnumArray(enArr);
69                 System.out.println("Enum members: " + Arrays.toString(resArr));
70                 List<Enum> enArr2 = new ArrayList(Arrays.asList(enArr));
71                 List<Enum> resArr2 = tcstub.handleEnumList(enArr2);
72                 System.out.println("Enum members: " + resArr2.toString());
73
74                 System.out.println("==== STRUCT ====");
75                 Struct str = new Struct();
76                 str.name = "Rahmadi";
77                 str.value = 0.123f;
78                 str.year = 2016;
79                 Struct strRes = tcstub.handleStruct(str);
80                 System.out.println("Name: " + strRes.name);
81                 System.out.println("Value: " + strRes.value);
82                 System.out.println("Year: " + strRes.year);
83                 Struct str2 = new Struct();
84                 str2.name = "Trimananda";
85                 str2.value = 0.124f;
86                 str2.year = 2017;
87                 Struct[] arrStr = { str, str2 };
88                 Struct[] arrRet = tcstub.handleStructArray(arrStr);
89                 for(Struct st : arrRet) {
90                         System.out.println("Name: " + st.name);
91                         System.out.println("Value: " + st.value);
92                         System.out.println("Year: " + st.year);
93                 }
94                 List<Struct> stList = new ArrayList(Arrays.asList(arrStr));
95                 List<Struct> stRetList = tcstub.handleStructList(stList);
96                 for(Struct st : stRetList) {
97                         System.out.println("Name: " + st.name);
98                         System.out.println("Value: " + st.value);
99                         System.out.println("Year: " + st.year);
100                 }
101 */
102                 System.out.println("==== CALLBACKS ====");
103                 CallBackInterface cbSingle = new CallBack(2354);
104                 tcstub.registerCallback(cbSingle);
105                 System.out.println("Return value from callback: " + tcstub.callBack());
106                 //CallBackInterface cbSingle2 = new CallBack(2355);
107                 //tcstub.registerCallback(cbSingle2);
108                 //System.out.println("Return value from callback: " + tcstub.callBack());
109                 CallBackInterface cb1 = new CallBack(23);
110                 CallBackInterface cb2 = new CallBack(33);
111                 CallBackInterface cb3 = new CallBack(43);
112                 CallBackInterface[] cb = { cb1, cb2, cb3 };
113                 tcstub.registerCallbackArray(cb);
114                 System.out.println("Return value from callback: " + tcstub.callBack());
115                 List<CallBackInterface> cblist = new ArrayList<CallBackInterface>();
116                 CallBackInterface cb4 = new CallBack(53); cblist.add(cb4);
117                 CallBackInterface cb5 = new CallBack(63); cblist.add(cb5);
118                 CallBackInterface cb6 = new CallBack(73); cblist.add(cb6);
119                 tcstub.registerCallbackList(cblist);
120                 System.out.println("Return value from callback: " + tcstub.callBack());
121
122                 System.out.println("==== OTHERS ====");
123                 System.out.println("Return value: " + tcstub.getA());
124                 System.out.println("Return value: " + tcstub.setAndGetA(123));
125                 System.out.println("Return value: " + tcstub.setACAndGetA("string", 123));
126                 System.out.println("Return value: " + tcstub.sumArray(new String[] { "123", "456", "987" }));
127
128
129         }
130 }