Exchanging cameras between benchmarks; updating database
[iot2.git] / benchmarks / Java / HomeSecurityController / AlarmSmart_Stub.java
1 package HomeSecurityController;
2
3 import java.io.IOException;
4 import java.util.List;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import java.util.Map;
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;
14
15 import iotcode.interfaces.*;
16
17 public class AlarmSmart_Stub implements AlarmSmart {
18
19         private int objectId = 1;
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);
25         
26
27         public AlarmSmart_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);
30                 } else
31                 {
32                         rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
33                 }
34                 rmiComm.registerStub(objectId, 4, retValueReceived4);
35                 rmiComm.registerStub(objectId, 2, retValueReceived2);
36                 rmiComm.registerStub(objectId, 3, retValueReceived3);
37                 IoTRMIUtil.mapStub.put(objectId, this);
38         }
39
40         public AlarmSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
41                 rmiComm = _rmiComm;
42                 objectId = _objectId;
43                 rmiComm.registerStub(objectId, 4, retValueReceived4);
44                 rmiComm.registerStub(objectId, 2, retValueReceived2);
45                 rmiComm.registerStub(objectId, 3, retValueReceived3);
46         }
47
48         public boolean doesHaveZoneTimers() {
49                 int methodId = 4;
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();
59
60                 return (boolean)retObj;
61         }
62
63         public List<ZoneState> getZoneStates() {
64                 int methodId = 2;
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();
74
75                 int retLen = (int) retObj;
76                 Class<?>[] retCls = new Class<?>[3*retLen];
77                 Class<?>[] retClsVal = new Class<?>[3*retLen];
78                 int retPos = 0;
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;
86                 }
87                 // Waiting for return value
88                 while (!retValueReceived2.get());
89                 Object[] retActualObj = rmiComm.getStructObjects(retCls, retClsVal);
90                 retValueReceived2.set(false);
91                 rmiComm.setGetReturnBytes();
92
93                 List<ZoneState> structRet = new ArrayList<ZoneState>();
94                 int retObjPos = 0;
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);
101                 }
102                 return structRet;
103         }
104
105         public void init() {
106                 int methodId = 0;
107                 Class<?> retType = void.class;
108                 Class<?>[] paramCls = new Class<?>[] {  };
109                 Object[] paramObj = new Object[] {  };
110                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
111         }
112
113         public void setZone(int _zone, boolean _onOff, int _onDurationSeconds) {
114                 int methodId = 1;
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);
119         }
120
121         public int getNumberOfZones() {
122                 int methodId = 3;
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();
132
133                 return (int)retObj;
134         }
135
136 }