Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/iot2
[iot2.git] / iotjava / iotrmi / Java / basics / TestClassCallbacks_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 TestClassCallbacks_Stub {
7
8         public static void main(String[] args) throws Exception {
9
10                 CommunicationHandler comHan = new CommunicationHandler(true);
11                 int numOfPorts = 2;
12                 //int[] ports = comHan.getCallbackPorts(numOfPorts);
13
14                 int localportsend = 5011;
15                 int localportrecv = 6011;
16                 int portsend = 5000;
17                 int portrecv = 6000;
18                 //String address = "localhost";
19                 //String address = "192.168.2.191";     // RPi2
20                 //String skeletonAddress = "128.195.136.170";   // dc-9.calit2.uci.edu
21                 String skeletonAddress = "128.195.204.132";
22                 String callbackAddress = "128.195.204.132";     // dw-2.eecs.uci.edu (this machine)
23                 //String skeletonAddress = "192.168.2.108";     // RPi1
24                 //String callbackAddress = "192.168.2.191";     // RPi2
25                 int rev = 0;
26
27                 TestClassComplete_Stub tcstub = new TestClassComplete_Stub(localportsend, localportrecv, portsend, portrecv, 
28                         skeletonAddress, rev);
29                 System.out.println("==== CALLBACKS ====");
30                 CallBackInterface cbSingle = new CallBack(2354);
31                 tcstub.registerCallback(cbSingle);
32                 System.out.println("Registered callback!");
33 //              CallBackInterface cbSingle1 = new CallBack(2356);
34 //              tcstub.registerCallback(cbSingle1);
35 //              System.out.println("Registered callback!");
36 //              CallBackInterface cbSingle2 = new CallBack(2360);
37 //              tcstub.registerCallback(cbSingle2);
38 //              System.out.println("Registered callback!");
39                 /*CallBackInterface cb1 = new CallBack(23);
40                 CallBackInterface cb2 = new CallBack(33);
41                 CallBackInterface cb3 = new CallBack(43);
42                 CallBackInterface[] cb = { cb1, cb2, cb3 };
43                 tcstub.registerCallbackArray(cb);
44                 List<CallBackInterface> cblist = new ArrayList<CallBackInterface>();
45                 CallBackInterface cb4 = new CallBack(53); cblist.add(cb4);
46                 CallBackInterface cb5 = new CallBack(63); cblist.add(cb5);
47                 CallBackInterface cb6 = new CallBack(73); cblist.add(cb6);
48                 tcstub.registerCallbackList(cblist);*/
49                 /*Enum[] enArr = { Enum.APPLE, Enum.ORANGE, Enum.APPLE, Enum.GRAPE };
50                 List<Enum> enArr2 = new ArrayList(Arrays.asList(enArr));
51                 List<Enum> resArr2 = tcstub.handleEnumList(enArr2);
52                 System.out.println("Enum members: " + resArr2.toString());*/
53                 Struct str = new Struct();
54                 str.name = "Rahmadi";
55                 str.value = 0.123f;
56                 str.year = 2016;
57                 Struct str2 = new Struct();
58                 str2.name = "Trimananda";
59                 str2.value = 0.124f;
60                 str2.year = 2017;
61                 Struct[] arrStr = { str, str2 };
62                 Struct[] arrRet = tcstub.handleStructArray(arrStr);
63                 for(Struct st : arrRet) {
64                         System.out.println("Name: " + st.name);
65                         System.out.println("Value: " + st.value);
66                         System.out.println("Year: " + st.year);
67                 }
68
69 //              System.out.println("Return value from callback 1: " + tcstub.callBack() + "\n\n");
70 //              System.out.println("\n\nCalling short one more time value: " + tcstub.getShort((short)4576) + "\n\n");
71 //              System.out.println("Return value from callback 2: " + tcstub.callBack() + "\n\n");
72 //              System.out.println("\n\nCalling short one more time value: " + tcstub.getShort((short)1233) + "\n\n");
73 //              System.out.println("\n\nCalling short one more time value: " + tcstub.getShort((short)1321) + "\n\n");
74                 while(true) {}
75         }
76 }