Updating stub and skeleton for Lifxtest
[iot2.git] / benchmarks / Java / Lifxtest / LightBulbTest_Stub.java
1 package Lifxtest;
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.LightBulbTest;
16
17 public class LightBulbTest_Stub implements LightBulbTest {
18
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);
27         
28
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);
32                 } else
33                 {
34                         rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
35                 }
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);
42         }
43
44         public LightBulbTest_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
45                 rmiComm = _rmiComm;
46                 objectId = _objectId;
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);
52         }
53
54         public void turnOn() {
55                 int methodId = 2;
56                 Class<?> retType = void.class;
57                 Class<?>[] paramCls = new Class<?>[] {  };
58                 Object[] paramObj = new Object[] {  };
59                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
60         }
61
62         public double getBrightness() {
63                 int methodId = 6;
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();
73
74                 return (double)retObj;
75         }
76
77         public void turnOff() {
78                 int methodId = 1;
79                 Class<?> retType = void.class;
80                 Class<?>[] paramCls = new Class<?>[] {  };
81                 Object[] paramObj = new Object[] {  };
82                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
83         }
84
85         public boolean getState() {
86                 int methodId = 3;
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();
96
97                 return (boolean)retObj;
98         }
99
100         public void setColor(double _hue, double _saturation, double _brightness) {
101                 int methodId = 4;
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);
106         }
107
108         public double getSaturation() {
109                 int methodId = 8;
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();
119
120                 return (double)retObj;
121         }
122
123         public void init() {
124                 int methodId = 0;
125                 Class<?> retType = void.class;
126                 Class<?>[] paramCls = new Class<?>[] {  };
127                 Object[] paramObj = new Object[] {  };
128                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
129         }
130
131         public void setTemperature(int _temperature) {
132                 int methodId = 5;
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);
137         }
138
139         public double getHue() {
140                 int methodId = 7;
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();
150
151                 return (double)retObj;
152         }
153
154         public int getTemperature() {
155                 int methodId = 9;
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();
165
166                 return (int)retObj;
167         }
168
169 }