Replacing default BUFFSIZE value with new buffer size value when a resize needs to...
[iot2.git] / benchmarks / drivers / WeatherPhoneGateway / WeatherGateway_Skeleton.java
1 package iotcode.WeatherPhoneGateway;
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 WeatherGateway_Skeleton implements WeatherGateway {
13
14         private WeatherGateway 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; //WeatherGatewaySmart
23         private static Integer[] object0Permission = { 3, 6, 5, 7, 2, 1, 0, 4 };
24         private static List<Integer> set0Allowed;
25         
26
27         public WeatherGateway_Skeleton(WeatherGateway _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 double getInchesPerWeek() {
49                 return mainObj.getInchesPerWeek();
50         }
51
52         public int getWeatherZipCode() {
53                 return mainObj.getWeatherZipCode();
54         }
55
56         public int getDaysToWaterOn() {
57                 return mainObj.getDaysToWaterOn();
58         }
59
60         public double getInchesPerMinute() {
61                 return mainObj.getInchesPerMinute();
62         }
63
64         public void registerCallback(WeatherGatewaySmartCallback _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 ___getInchesPerWeek() throws IOException {
93                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
94                 new Class<?>[] {  });
95                 Object retObj = getInchesPerWeek();
96                 rmiObj.sendReturnObj(retObj);
97         }
98
99         public void ___getWeatherZipCode() throws IOException {
100                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
101                 new Class<?>[] {  });
102                 Object retObj = getWeatherZipCode();
103                 rmiObj.sendReturnObj(retObj);
104         }
105
106         public void ___getDaysToWaterOn() throws IOException {
107                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
108                 new Class<?>[] {  });
109                 Object retObj = getDaysToWaterOn();
110                 rmiObj.sendReturnObj(retObj);
111         }
112
113         public void ___getInchesPerMinute() throws IOException {
114                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
115                 new Class<?>[] {  });
116                 Object retObj = getInchesPerMinute();
117                 rmiObj.sendReturnObj(retObj);
118         }
119
120         public void ___registerCallback() {
121                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
122                 new Class<?>[] { null });
123                 try {
124                         WeatherGatewaySmartCallback stub0 = new WeatherGatewaySmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
125                         objIdCnt++;
126                         registerCallback(stub0);
127                 } catch(Exception ex) {
128                         ex.printStackTrace();
129                         throw new Error("Exception from callback object instantiation!");
130                 }
131         }
132
133         private void ___waitRequestInvokeMethod() throws IOException {
134                 while (true) {
135                         rmiObj.getMethodBytes();
136                         int _objectId = rmiObj.getObjectId();
137                         int methodId = rmiObj.getMethodId();
138                         if (_objectId == object0Id) {
139                                 if (!set0Allowed.contains(methodId)) {
140                                         throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
141                                 }
142                         }
143                         else {
144                                 throw new Error("Object Id: " + _objectId + " not recognized!");
145                         }
146                         switch (methodId) {
147                                 case 0: ___init(); break;
148                                 case 1: ___start(); break;
149                                 case 2: ___stop(); break;
150                                 case 3: ___getInchesPerWeek(); break;
151                                 case 4: ___getWeatherZipCode(); break;
152                                 case 5: ___getDaysToWaterOn(); break;
153                                 case 6: ___getInchesPerMinute(); break;
154                                 case 7: ___registerCallback(); break;
155                                 case -9998: ___regCB(); break;
156                                 default: 
157                                 throw new Error("Method Id " + methodId + " not recognized!");
158                         }
159                 }
160         }
161
162 }