Replacing default BUFFSIZE value with new buffer size value when a resize needs to...
[iot2.git] / benchmarks / drivers / GPSPhoneGateway / GPSGateway_Skeleton.java
1 package iotcode.GPSPhoneGateway;
2
3 import java.io.IOException;
4 import java.util.List;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import iotrmi.Java.IoTRMICall;
8 import iotrmi.Java.IoTRMIObject;
9
10 import iotcode.interfaces.*;
11
12 public class GPSGateway_Skeleton implements GPSGateway {
13
14         private GPSGateway mainObj;
15         private IoTRMIObject rmiObj;
16
17         private String callbackAddress;
18         private int objIdCnt = 0;
19         private IoTRMICall rmiCall;
20         private int[] ports;
21
22         private final static int object0Id = 0; //GPSGatewaySmart
23         private static Integer[] object0Permission = { 5, 6, 2, 1, 0, 3, 7, 4 };
24         private static List<Integer> set0Allowed;
25         
26
27         public GPSGateway_Skeleton(GPSGateway _mainObj, String _callbackAddress, int _port) throws Exception {
28                 mainObj = _mainObj;
29                 callbackAddress = _callbackAddress;
30                 rmiObj = new IoTRMIObject(_port);
31                 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
32                 set0Allowed.add(-9998);
33                 ___waitRequestInvokeMethod();
34         }
35
36         public void init() {
37                 mainObj.init();
38         }
39
40         public void start() {
41                 mainObj.start();
42         }
43
44         public void stop() {
45                 mainObj.stop();
46         }
47
48         public int getRoomID() {
49                 return mainObj.getRoomID();
50         }
51
52         public boolean getRingStatus() {
53                 return mainObj.getRingStatus();
54         }
55
56         public void setNewRoomIDAvailable(boolean bValue) {
57                 mainObj.setNewRoomIDAvailable(bValue);
58         }
59
60         public void setNewRingStatusAvailable(boolean bValue) {
61                 mainObj.setNewRingStatusAvailable(bValue);
62         }
63
64         public void registerCallback(GPSGatewaySmartCallback _callbackTo) {
65                 mainObj.registerCallback(_callbackTo);
66         }
67
68         public void ___regCB() throws IOException {
69                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class, String.class, int.class },new Class<?>[] { null, null, null });
70                 ports = (int[]) paramObj[0];
71                 rmiCall = new IoTRMICall(ports[0], (String) paramObj[1], (int) paramObj[2]);
72         }
73
74         public void ___init() {
75                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
76                 new Class<?>[] {  });
77                 init();
78         }
79
80         public void ___start() {
81                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
82                 new Class<?>[] {  });
83                 start();
84         }
85
86         public void ___stop() {
87                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
88                 new Class<?>[] {  });
89                 stop();
90         }
91
92         public void ___getRoomID() throws IOException {
93                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
94                 new Class<?>[] {  });
95                 Object retObj = getRoomID();
96                 rmiObj.sendReturnObj(retObj);
97         }
98
99         public void ___getRingStatus() throws IOException {
100                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
101                 new Class<?>[] {  });
102                 Object retObj = getRingStatus();
103                 rmiObj.sendReturnObj(retObj);
104         }
105
106         public void ___setNewRoomIDAvailable() {
107                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { boolean.class }, 
108                 new Class<?>[] { null });
109                 setNewRoomIDAvailable((boolean) paramObj[0]);
110         }
111
112         public void ___setNewRingStatusAvailable() {
113                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { boolean.class }, 
114                 new Class<?>[] { null });
115                 setNewRingStatusAvailable((boolean) paramObj[0]);
116         }
117
118         public void ___registerCallback() {
119                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
120                 new Class<?>[] { null });
121                 try {
122                         GPSGatewaySmartCallback stub0 = new GPSGatewaySmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
123                         objIdCnt++;
124                         registerCallback(stub0);
125                 } catch(Exception ex) {
126                         ex.printStackTrace();
127                         throw new Error("Exception from callback object instantiation!");
128                 }
129         }
130
131         private void ___waitRequestInvokeMethod() throws IOException {
132                 while (true) {
133                         rmiObj.getMethodBytes();
134                         int _objectId = rmiObj.getObjectId();
135                         int methodId = rmiObj.getMethodId();
136                         if (_objectId == object0Id) {
137                                 if (!set0Allowed.contains(methodId)) {
138                                         throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
139                                 }
140                         }
141                         else {
142                                 throw new Error("Object Id: " + _objectId + " not recognized!");
143                         }
144                         switch (methodId) {
145                                 case 0: ___init(); break;
146                                 case 1: ___start(); break;
147                                 case 2: ___stop(); break;
148                                 case 3: ___getRoomID(); break;
149                                 case 4: ___getRingStatus(); break;
150                                 case 5: ___setNewRoomIDAvailable(); break;
151                                 case 6: ___setNewRingStatusAvailable(); break;
152                                 case 7: ___registerCallback(); break;
153                                 case -9998: ___regCB(); break;
154                                 default: 
155                                 throw new Error("Method Id " + methodId + " not recognized!");
156                         }
157                 }
158         }
159
160 }