1 package IrrigationController;
3 import java.io.IOException;
5 import java.util.ArrayList;
6 import java.util.Arrays;
8 import java.util.HashMap;
9 import java.util.concurrent.atomic.AtomicBoolean;
10 import iotrmi.Java.IoTRMIComm;
11 import iotrmi.Java.IoTRMICommClient;
12 import iotrmi.Java.IoTRMICommServer;
13 import iotrmi.Java.IoTRMIUtil;
15 import iotcode.interfaces.*;
17 public class SprinklerSmart_Stub implements SprinklerSmart {
19 private int objectId = 6;
20 private IoTRMIComm rmiComm;
21 // Synchronization variables
22 private AtomicBoolean retValueReceived4 = new AtomicBoolean(false);
23 private AtomicBoolean retValueReceived2 = new AtomicBoolean(false);
24 private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
27 public SprinklerSmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
28 if (_localPortSend != 0 && _localPortRecv != 0) {
29 rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
32 rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
34 rmiComm.registerStub(objectId, 4, retValueReceived4);
35 rmiComm.registerStub(objectId, 2, retValueReceived2);
36 rmiComm.registerStub(objectId, 3, retValueReceived3);
37 IoTRMIUtil.mapStub.put(objectId, this);
40 public SprinklerSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
43 rmiComm.registerStub(objectId, 4, retValueReceived4);
44 rmiComm.registerStub(objectId, 2, retValueReceived2);
45 rmiComm.registerStub(objectId, 3, retValueReceived3);
48 public boolean doesHaveZoneTimers() {
50 Class<?> retType = boolean.class;
51 Class<?>[] paramCls = new Class<?>[] { };
52 Object[] paramObj = new Object[] { };
53 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
54 // Waiting for return value
55 while (!retValueReceived4.get());
56 Object retObj = rmiComm.getReturnValue(retType, null);
57 retValueReceived4.set(false);
58 rmiComm.setGetReturnBytes();
60 return (boolean)retObj;
63 public List<ZoneState> getZoneStates() {
65 Class<?> retType = int.class;
66 Class<?>[] paramCls = new Class<?>[] { };
67 Object[] paramObj = new Object[] { };
68 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
69 // Waiting for return value
70 while (!retValueReceived2.get());
71 Object retObj = rmiComm.getReturnValue(retType, null);
72 retValueReceived2.set(false);
73 rmiComm.setGetReturnBytes();
75 int retLen = (int) retObj;
76 Class<?>[] retCls = new Class<?>[3*retLen];
77 Class<?>[] retClsVal = new Class<?>[3*retLen];
79 for(int i = 0; i < retLen; i++) {
80 retCls[retPos] = int.class;
81 retClsVal[retPos++] = null;
82 retCls[retPos] = boolean.class;
83 retClsVal[retPos++] = null;
84 retCls[retPos] = int.class;
85 retClsVal[retPos++] = null;
87 // Waiting for return value
88 while (!retValueReceived2.get());
89 Object[] retActualObj = rmiComm.getStructObjects(retCls, retClsVal);
90 retValueReceived2.set(false);
91 rmiComm.setGetReturnBytes();
93 List<ZoneState> structRet = new ArrayList<ZoneState>();
95 for(int i = 0; i < retLen; i++) {
96 ZoneState structRetMem = new ZoneState();
97 structRetMem.zoneNumber = (int) retActualObj[retObjPos++];
98 structRetMem.onOffState = (boolean) retActualObj[retObjPos++];
99 structRetMem.duration = (int) retActualObj[retObjPos++];
100 structRet.add(structRetMem);
107 Class<?> retType = void.class;
108 Class<?>[] paramCls = new Class<?>[] { };
109 Object[] paramObj = new Object[] { };
110 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
113 public void setZone(int _zone, boolean _onOff, int _onDurationSeconds) {
115 Class<?> retType = void.class;
116 Class<?>[] paramCls = new Class<?>[] { int.class, boolean.class, int.class };
117 Object[] paramObj = new Object[] { _zone, _onOff, _onDurationSeconds };
118 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
121 public int getNumberOfZones() {
123 Class<?> retType = int.class;
124 Class<?>[] paramCls = new Class<?>[] { };
125 Object[] paramObj = new Object[] { };
126 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
127 // Waiting for return value
128 while (!retValueReceived3.get());
129 Object retObj = rmiComm.getReturnValue(retType, null);
130 retValueReceived3.set(false);
131 rmiComm.setGetReturnBytes();