Adding changes and files for doorlock driver
[iot2.git] / benchmarks / Java / SpeakerController / SpeakerSmart_Stub.java
1 package SpeakerController;
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 SpeakerSmart_Stub implements SpeakerSmart {
18
19         private int objectId = 1;
20         private IoTRMIComm rmiComm;
21         // Synchronization variables
22         private AtomicBoolean retValueReceived6 = new AtomicBoolean(false);
23         private AtomicBoolean retValueReceived2 = new AtomicBoolean(false);
24         private AtomicBoolean retValueReceived1 = new AtomicBoolean(false);
25         private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
26         private AtomicBoolean retValueReceived4 = new AtomicBoolean(false);
27         private AtomicBoolean retValueReceived5 = new AtomicBoolean(false);
28         
29
30         public SpeakerSmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
31                 if (_localPortSend != 0 && _localPortRecv != 0) {
32                         rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
33                 } else
34                 {
35                         rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
36                 }
37                 rmiComm.registerStub(objectId, 6, retValueReceived6);
38                 rmiComm.registerStub(objectId, 2, retValueReceived2);
39                 rmiComm.registerStub(objectId, 1, retValueReceived1);
40                 rmiComm.registerStub(objectId, 3, retValueReceived3);
41                 rmiComm.registerStub(objectId, 4, retValueReceived4);
42                 rmiComm.registerStub(objectId, 5, retValueReceived5);
43                 IoTRMIUtil.mapStub.put(objectId, this);
44         }
45
46         public SpeakerSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
47                 rmiComm = _rmiComm;
48                 objectId = _objectId;
49                 rmiComm.registerStub(objectId, 6, retValueReceived6);
50                 rmiComm.registerStub(objectId, 2, retValueReceived2);
51                 rmiComm.registerStub(objectId, 1, retValueReceived1);
52                 rmiComm.registerStub(objectId, 3, retValueReceived3);
53                 rmiComm.registerStub(objectId, 4, retValueReceived4);
54                 rmiComm.registerStub(objectId, 5, retValueReceived5);
55         }
56
57         public int getPosition() {
58                 int methodId = 6;
59                 Class<?> retType = int.class;
60                 Class<?>[] paramCls = new Class<?>[] {  };
61                 Object[] paramObj = new Object[] {  };
62                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
63                 // Waiting for return value
64                 while (!retValueReceived6.get());
65                 Object retObj = rmiComm.getReturnValue(retType, null);
66                 retValueReceived6.set(false);
67                 rmiComm.setGetReturnBytes();
68
69                 return (int)retObj;
70         }
71
72         public boolean stopPlayback() {
73                 int methodId = 2;
74                 Class<?> retType = boolean.class;
75                 Class<?>[] paramCls = new Class<?>[] {  };
76                 Object[] paramObj = new Object[] {  };
77                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
78                 // Waiting for return value
79                 while (!retValueReceived2.get());
80                 Object retObj = rmiComm.getReturnValue(retType, null);
81                 retValueReceived2.set(false);
82                 rmiComm.setGetReturnBytes();
83
84                 return (boolean)retObj;
85         }
86
87         public void clearData() {
88                 int methodId = 9;
89                 Class<?> retType = void.class;
90                 Class<?>[] paramCls = new Class<?>[] {  };
91                 Object[] paramObj = new Object[] {  };
92                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
93         }
94
95         public boolean startPlayback() {
96                 int methodId = 1;
97                 Class<?> retType = boolean.class;
98                 Class<?>[] paramCls = new Class<?>[] {  };
99                 Object[] paramObj = new Object[] {  };
100                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
101                 // Waiting for return value
102                 while (!retValueReceived1.get());
103                 Object retObj = rmiComm.getReturnValue(retType, null);
104                 retValueReceived1.set(false);
105                 rmiComm.setGetReturnBytes();
106
107                 return (boolean)retObj;
108         }
109
110         public boolean getPlaybackState() {
111                 int methodId = 3;
112                 Class<?> retType = boolean.class;
113                 Class<?>[] paramCls = new Class<?>[] {  };
114                 Object[] paramObj = new Object[] {  };
115                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
116                 // Waiting for return value
117                 while (!retValueReceived3.get());
118                 Object retObj = rmiComm.getReturnValue(retType, null);
119                 retValueReceived3.set(false);
120                 rmiComm.setGetReturnBytes();
121
122                 return (boolean)retObj;
123         }
124
125         public boolean setVolume(float _percent) {
126                 int methodId = 4;
127                 Class<?> retType = boolean.class;
128                 Class<?>[] paramCls = new Class<?>[] { float.class };
129                 Object[] paramObj = new Object[] { _percent };
130                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
131                 // Waiting for return value
132                 while (!retValueReceived4.get());
133                 Object retObj = rmiComm.getReturnValue(retType, null);
134                 retValueReceived4.set(false);
135                 rmiComm.setGetReturnBytes();
136
137                 return (boolean)retObj;
138         }
139
140         public float getVolume() {
141                 int methodId = 5;
142                 Class<?> retType = float.class;
143                 Class<?>[] paramCls = new Class<?>[] {  };
144                 Object[] paramObj = new Object[] {  };
145                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
146                 // Waiting for return value
147                 while (!retValueReceived5.get());
148                 Object retObj = rmiComm.getReturnValue(retType, null);
149                 retValueReceived5.set(false);
150                 rmiComm.setGetReturnBytes();
151
152                 return (float)retObj;
153         }
154
155         public void setPosition(int _mSec) {
156                 int methodId = 7;
157                 Class<?> retType = void.class;
158                 Class<?>[] paramCls = new Class<?>[] { int.class };
159                 Object[] paramObj = new Object[] { _mSec };
160                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
161         }
162
163         public void loadData(short _samples[], int _offs, int _len) {
164                 int methodId = 8;
165                 Class<?> retType = void.class;
166                 Class<?>[] paramCls = new Class<?>[] { short[].class, int.class, int.class };
167                 Object[] paramObj = new Object[] { _samples, _offs, _len };
168                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
169         }
170
171         public void init() {
172                 int methodId = 0;
173                 Class<?> retType = void.class;
174                 Class<?>[] paramCls = new Class<?>[] {  };
175                 Object[] paramObj = new Object[] {  };
176                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
177         }
178
179         public void registerCallback(SpeakerCallback _cb) {
180                 int[] objIdSent0 = new int[1];
181                 try {
182                         if (!IoTRMIUtil.mapSkel.containsKey(_cb)) {
183                                 int newObjIdSent = rmiComm.getObjectIdCounter();
184                                 objIdSent0[0] = newObjIdSent;
185                                 rmiComm.decrementObjectIdCounter();
186                                 SpeakerCallback_Skeleton skel0 = new SpeakerCallback_Skeleton(_cb, rmiComm, newObjIdSent);
187                                 IoTRMIUtil.mapSkel.put(_cb, skel0);
188                                 IoTRMIUtil.mapSkelId.put(_cb, newObjIdSent);
189                                 Thread thread = new Thread() {
190                                         public void run() {
191                                                 try {
192                                                         skel0.___waitRequestInvokeMethod();
193                                                         } catch (Exception ex) {
194                                                         ex.printStackTrace();
195                                                         throw new Error("Exception when trying to run ___waitRequestInvokeMethod() for SpeakerCallback_Skeleton!");
196                                                 }
197                                         }
198                                 };
199                                 thread.start();
200                                 while(!skel0.didAlreadyInitWaitInvoke());
201                         }
202                         else
203                         {
204                                 int newObjIdSent = IoTRMIUtil.mapSkelId.get(_cb);
205                                 objIdSent0[0] = newObjIdSent;
206                         }
207                 } catch (Exception ex) {
208                         ex.printStackTrace();
209                         throw new Error("Exception when generating skeleton objects!");
210                 }
211
212                 int methodId = 10;
213                 Class<?> retType = void.class;
214                 Class<?>[] paramCls = new Class<?>[] { int[].class };
215                 Object[] paramObj = new Object[] { objIdSent0 };
216                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
217         }
218
219 }