1 package iotcode.EspSprinkler;
3 import java.io.IOException;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import iotrmi.Java.IoTRMICall;
8 import iotrmi.Java.IoTRMIObject;
10 import iotcode.interfaces.*;
12 public class Sprinkler_Skeleton implements Sprinkler {
14 private Sprinkler mainObj;
15 private IoTRMIObject rmiObj;
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;
23 public Sprinkler_Skeleton(Sprinkler _mainObj, String _callbackAddress, int _port) throws Exception {
25 callbackAddress = _callbackAddress;
26 rmiObj = new IoTRMIObject(_port);
27 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
28 ___waitRequestInvokeMethod();
35 public void setZone(int _zone, boolean _onOff, int _onDurationSeconds) {
36 mainObj.setZone(_zone, _onOff, _onDurationSeconds);
39 public List<ZoneState> getZoneStates() {
40 return mainObj.getZoneStates();
43 public int getNumberOfZones() {
44 return mainObj.getNumberOfZones();
47 public boolean doesHaveZoneTimers() {
48 return mainObj.doesHaveZoneTimers();
51 public void ___init() {
52 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
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]);
63 public void ___getZoneStates() throws IOException {
64 Object[] paramObj = rmiObj.getMethodParams(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];
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;
81 rmiObj.sendReturnObj(retCls, retObj);
84 public void ___getNumberOfZones() throws IOException {
85 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
87 Object retObj = getNumberOfZones();
88 rmiObj.sendReturnObj(retObj);
91 public void ___doesHaveZoneTimers() throws IOException {
92 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
94 Object retObj = doesHaveZoneTimers();
95 rmiObj.sendReturnObj(retObj);
98 private void ___waitRequestInvokeMethod() throws IOException {
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);
109 throw new Error("Object Id: " + _objectId + " not recognized!");
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;
118 throw new Error("Method Id " + methodId + " not recognized!");