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.LightBulbTest;
17 public class LightBulbTest_Stub implements LightBulbTest {
19 private int objectId = 0;
20 private IoTRMIComm rmiComm;
21 // Synchronization variables
22 private AtomicBoolean retValueReceived6 = new AtomicBoolean(false);
23 private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
24 private AtomicBoolean retValueReceived8 = new AtomicBoolean(false);
25 private AtomicBoolean retValueReceived7 = new AtomicBoolean(false);
26 private AtomicBoolean retValueReceived9 = new AtomicBoolean(false);
29 public LightBulbTest_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
30 if (_localPortSend != 0 && _localPortRecv != 0) {
31 rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
34 rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
36 rmiComm.registerStub(objectId, 6, retValueReceived6);
37 rmiComm.registerStub(objectId, 3, retValueReceived3);
38 rmiComm.registerStub(objectId, 8, retValueReceived8);
39 rmiComm.registerStub(objectId, 7, retValueReceived7);
40 rmiComm.registerStub(objectId, 9, retValueReceived9);
41 IoTRMIUtil.mapStub.put(objectId, this);
44 public LightBulbTest_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
47 rmiComm.registerStub(objectId, 6, retValueReceived6);
48 rmiComm.registerStub(objectId, 3, retValueReceived3);
49 rmiComm.registerStub(objectId, 8, retValueReceived8);
50 rmiComm.registerStub(objectId, 7, retValueReceived7);
51 rmiComm.registerStub(objectId, 9, retValueReceived9);
54 public void turnOn() {
56 Class<?> retType = void.class;
57 Class<?>[] paramCls = new Class<?>[] { };
58 Object[] paramObj = new Object[] { };
59 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
62 public double getBrightness() {
64 Class<?> retType = double.class;
65 Class<?>[] paramCls = new Class<?>[] { };
66 Object[] paramObj = new Object[] { };
67 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
68 // Waiting for return value
69 while (!retValueReceived6.get());
70 Object retObj = rmiComm.getReturnValue(retType, null);
71 retValueReceived6.set(false);
72 rmiComm.setGetReturnBytes();
74 return (double)retObj;
77 public void turnOff() {
79 Class<?> retType = void.class;
80 Class<?>[] paramCls = new Class<?>[] { };
81 Object[] paramObj = new Object[] { };
82 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
85 public boolean getState() {
87 Class<?> retType = boolean.class;
88 Class<?>[] paramCls = new Class<?>[] { };
89 Object[] paramObj = new Object[] { };
90 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
91 // Waiting for return value
92 while (!retValueReceived3.get());
93 Object retObj = rmiComm.getReturnValue(retType, null);
94 retValueReceived3.set(false);
95 rmiComm.setGetReturnBytes();
97 return (boolean)retObj;
100 public void setColor(double _hue, double _saturation, double _brightness) {
102 Class<?> retType = void.class;
103 Class<?>[] paramCls = new Class<?>[] { double.class, double.class, double.class };
104 Object[] paramObj = new Object[] { _hue, _saturation, _brightness };
105 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
108 public double getSaturation() {
110 Class<?> retType = double.class;
111 Class<?>[] paramCls = new Class<?>[] { };
112 Object[] paramObj = new Object[] { };
113 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
114 // Waiting for return value
115 while (!retValueReceived8.get());
116 Object retObj = rmiComm.getReturnValue(retType, null);
117 retValueReceived8.set(false);
118 rmiComm.setGetReturnBytes();
120 return (double)retObj;
125 Class<?> retType = void.class;
126 Class<?>[] paramCls = new Class<?>[] { };
127 Object[] paramObj = new Object[] { };
128 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
131 public void setTemperature(int _temperature) {
133 Class<?> retType = void.class;
134 Class<?>[] paramCls = new Class<?>[] { int.class };
135 Object[] paramObj = new Object[] { _temperature };
136 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
139 public double getHue() {
141 Class<?> retType = double.class;
142 Class<?>[] paramCls = new Class<?>[] { };
143 Object[] paramObj = new Object[] { };
144 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
145 // Waiting for return value
146 while (!retValueReceived7.get());
147 Object retObj = rmiComm.getReturnValue(retType, null);
148 retValueReceived7.set(false);
149 rmiComm.setGetReturnBytes();
151 return (double)retObj;
154 public int getTemperature() {
156 Class<?> retType = int.class;
157 Class<?>[] paramCls = new Class<?>[] { };
158 Object[] paramObj = new Object[] { };
159 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
160 // Waiting for return value
161 while (!retValueReceived9.get());
162 Object retObj = rmiComm.getReturnValue(retType, null);
163 retValueReceived9.set(false);
164 rmiComm.setGetReturnBytes();