Adding changes and files for doorlock driver
[iot2.git] / benchmarks / Java / HomeSecurityController / SmartthingsSensorSmart_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 SmartthingsSensorSmart_Stub implements SmartthingsSensorSmart {
18
19         private int objectId = 3;
20         private IoTRMIComm rmiComm;
21         // Synchronization variables
22         private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
23         private AtomicBoolean retValueReceived2 = new AtomicBoolean(false);
24         private AtomicBoolean retValueReceived5 = new AtomicBoolean(false);
25         private AtomicBoolean retValueReceived1 = new AtomicBoolean(false);
26         
27
28         public SmartthingsSensorSmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
29                 if (_localPortSend != 0 && _localPortRecv != 0) {
30                         rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
31                 } else
32                 {
33                         rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
34                 }
35                 rmiComm.registerStub(objectId, 3, retValueReceived3);
36                 rmiComm.registerStub(objectId, 2, retValueReceived2);
37                 rmiComm.registerStub(objectId, 5, retValueReceived5);
38                 rmiComm.registerStub(objectId, 1, retValueReceived1);
39                 IoTRMIUtil.mapStub.put(objectId, this);
40         }
41
42         public SmartthingsSensorSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
43                 rmiComm = _rmiComm;
44                 objectId = _objectId;
45                 rmiComm.registerStub(objectId, 3, retValueReceived3);
46                 rmiComm.registerStub(objectId, 2, retValueReceived2);
47                 rmiComm.registerStub(objectId, 5, retValueReceived5);
48                 rmiComm.registerStub(objectId, 1, retValueReceived1);
49         }
50
51         public long getTimestampOfLastReading() {
52                 int methodId = 3;
53                 Class<?> retType = long.class;
54                 Class<?>[] paramCls = new Class<?>[] {  };
55                 Object[] paramObj = new Object[] {  };
56                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
57                 // Waiting for return value
58                 while (!retValueReceived3.get());
59                 Object retObj = rmiComm.getReturnValue(retType, null);
60                 retValueReceived3.set(false);
61                 rmiComm.setGetReturnBytes();
62
63                 return (long)retObj;
64         }
65
66         public boolean isActiveValue() {
67                 int methodId = 2;
68                 Class<?> retType = boolean.class;
69                 Class<?>[] paramCls = new Class<?>[] {  };
70                 Object[] paramObj = new Object[] {  };
71                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
72                 // Waiting for return value
73                 while (!retValueReceived2.get());
74                 Object retObj = rmiComm.getReturnValue(retType, null);
75                 retValueReceived2.set(false);
76                 rmiComm.setGetReturnBytes();
77
78                 return (boolean)retObj;
79         }
80
81         public int getId() {
82                 int methodId = 5;
83                 Class<?> retType = int.class;
84                 Class<?>[] paramCls = new Class<?>[] {  };
85                 Object[] paramObj = new Object[] {  };
86                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
87                 // Waiting for return value
88                 while (!retValueReceived5.get());
89                 Object retObj = rmiComm.getReturnValue(retType, null);
90                 retValueReceived5.set(false);
91                 rmiComm.setGetReturnBytes();
92
93                 return (int)retObj;
94         }
95
96         public void registerCallback(SmartthingsSensorCallback _callbackTo) {
97                 int[] objIdSent0 = new int[1];
98                 try {
99                         if (!IoTRMIUtil.mapSkel.containsKey(_callbackTo)) {
100                                 int newObjIdSent = rmiComm.getObjectIdCounter();
101                                 objIdSent0[0] = newObjIdSent;
102                                 rmiComm.decrementObjectIdCounter();
103                                 SmartthingsSensorCallback_Skeleton skel0 = new SmartthingsSensorCallback_Skeleton(_callbackTo, rmiComm, newObjIdSent);
104                                 IoTRMIUtil.mapSkel.put(_callbackTo, skel0);
105                                 IoTRMIUtil.mapSkelId.put(_callbackTo, newObjIdSent);
106                                 Thread thread = new Thread() {
107                                         public void run() {
108                                                 try {
109                                                         skel0.___waitRequestInvokeMethod();
110                                                         } catch (Exception ex) {
111                                                         ex.printStackTrace();
112                                                         throw new Error("Exception when trying to run ___waitRequestInvokeMethod() for SmartthingsSensorCallback_Skeleton!");
113                                                 }
114                                         }
115                                 };
116                                 thread.start();
117                                 while(!skel0.didAlreadyInitWaitInvoke());
118                         }
119                         else
120                         {
121                                 int newObjIdSent = IoTRMIUtil.mapSkelId.get(_callbackTo);
122                                 objIdSent0[0] = newObjIdSent;
123                         }
124                 } catch (Exception ex) {
125                         ex.printStackTrace();
126                         throw new Error("Exception when generating skeleton objects!");
127                 }
128
129                 int methodId = 6;
130                 Class<?> retType = void.class;
131                 Class<?>[] paramCls = new Class<?>[] { int[].class };
132                 Object[] paramObj = new Object[] { objIdSent0 };
133                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
134         }
135
136         public int getValue() {
137                 int methodId = 1;
138                 Class<?> retType = int.class;
139                 Class<?>[] paramCls = new Class<?>[] {  };
140                 Object[] paramObj = new Object[] {  };
141                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
142                 // Waiting for return value
143                 while (!retValueReceived1.get());
144                 Object retObj = rmiComm.getReturnValue(retType, null);
145                 retValueReceived1.set(false);
146                 rmiComm.setGetReturnBytes();
147
148                 return (int)retObj;
149         }
150
151         public void setId(int id) {
152                 int methodId = 4;
153                 Class<?> retType = void.class;
154                 Class<?>[] paramCls = new Class<?>[] { int.class };
155                 Object[] paramObj = new Object[] { id };
156                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
157         }
158
159         public void init() {
160                 int methodId = 0;
161                 Class<?> retType = void.class;
162                 Class<?>[] paramCls = new Class<?>[] {  };
163                 Object[] paramObj = new Object[] {  };
164                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
165         }
166
167 }