Preparing files, stubs, and skeletons for 2nd benchmark
[iot2.git] / benchmarks / drivers / EspSprinkler / Sprinkler_Skeleton.java
1 package iotcode.EspSprinkler;
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 Sprinkler_Skeleton implements Sprinkler {
13
14         private Sprinkler mainObj;
15         private IoTRMIObject rmiObj;
16
17         private String callbackAddress;
18         private final static int object0Id = 0; //SprinklerSmart
19         private static Integer[] object0Permission = { 4, 2, 0, 1, 3 };
20         private static List<Integer> set0Allowed;
21         
22
23         public Sprinkler_Skeleton(Sprinkler _mainObj, String _callbackAddress, int _port) throws Exception {
24                 mainObj = _mainObj;
25                 callbackAddress = _callbackAddress;
26                 rmiObj = new IoTRMIObject(_port);
27                 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
28                 ___waitRequestInvokeMethod();
29         }
30
31         public void init() {
32                 mainObj.init();
33         }
34
35         public void setZone(int _zone, boolean _onOff, int _onDurationSeconds) {
36                 mainObj.setZone(_zone, _onOff, _onDurationSeconds);
37         }
38
39         public List<ZoneState> getZoneStates() {
40                 return mainObj.getZoneStates();
41         }
42
43         public int getNumberOfZones() {
44                 return mainObj.getNumberOfZones();
45         }
46
47         public boolean doesHaveZoneTimers() {
48                 return mainObj.doesHaveZoneTimers();
49         }
50
51         public void ___init() {
52                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
53                 new Class<?>[] {  });
54                 init();
55         }
56
57         public void ___setZone() {
58                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, boolean.class, int.class }, 
59                 new Class<?>[] { null, null, null });
60                 setZone((int) paramObj[0], (boolean) paramObj[1], (int) paramObj[2]);
61         }
62
63         public void ___getZoneStates() throws IOException {
64                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
65                 new Class<?>[] {  });
66                 List<ZoneState> retStruct = getZoneStates();
67                 int retLen = retStruct.size();
68                 Object retLenObj = retLen;
69                 rmiObj.sendReturnObj(retLenObj);
70                 Class<?>[] retCls = new Class<?>[3*retLen];
71                 Object[] retObj = new Object[3*retLen];
72                 int retPos = 0;
73                 for(int i = 0; i < retLen; i++) {
74                         retCls[retPos] = int.class;
75                         retObj[retPos++] = retStruct.get(i).zoneNumber;
76                         retCls[retPos] = boolean.class;
77                         retObj[retPos++] = retStruct.get(i).onOffState;
78                         retCls[retPos] = int.class;
79                         retObj[retPos++] = retStruct.get(i).duration;
80                 }
81                 rmiObj.sendReturnObj(retCls, retObj);
82         }
83
84         public void ___getNumberOfZones() throws IOException {
85                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
86                 new Class<?>[] {  });
87                 Object retObj = getNumberOfZones();
88                 rmiObj.sendReturnObj(retObj);
89         }
90
91         public void ___doesHaveZoneTimers() throws IOException {
92                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
93                 new Class<?>[] {  });
94                 Object retObj = doesHaveZoneTimers();
95                 rmiObj.sendReturnObj(retObj);
96         }
97
98         private void ___waitRequestInvokeMethod() throws IOException {
99                 while (true) {
100                         rmiObj.getMethodBytes();
101                         int _objectId = rmiObj.getObjectId();
102                         int methodId = rmiObj.getMethodId();
103                         if (_objectId == object0Id) {
104                                 if (!set0Allowed.contains(methodId)) {
105                                         throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
106                                 }
107                         }
108                         else {
109                                 throw new Error("Object Id: " + _objectId + " not recognized!");
110                         }
111                         switch (methodId) {
112                                 case 0: ___init(); break;
113                                 case 1: ___setZone(); break;
114                                 case 2: ___getZoneStates(); break;
115                                 case 3: ___getNumberOfZones(); break;
116                                 case 4: ___doesHaveZoneTimers(); break;
117                                 default: 
118                                 throw new Error("Method Id " + methodId + " not recognized!");
119                         }
120                 }
121         }
122
123 }