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.*;
17 public class Speaker_Skeleton implements Speaker {
19 private Speaker mainObj;
20 private int objectId = 1;
21 // Communications and synchronizations
22 private IoTRMIComm rmiComm;
23 private AtomicBoolean didAlreadyInitWaitInvoke;
24 private AtomicBoolean methodReceived;
25 private byte[] methodBytes = null;
27 private static Integer[] object1Permission = { 6, 2, 9, 1, 3, 4, 5, 7, 8, 0, 10 };
28 private static List<Integer> set1Allowed;
31 public Speaker_Skeleton(Speaker _mainObj, int _portSend, int _portRecv) throws Exception {
33 rmiComm = new IoTRMICommServer(_portSend, _portRecv);
34 set1Allowed = new ArrayList<Integer>(Arrays.asList(object1Permission));
35 IoTRMIUtil.mapSkel.put(_mainObj, this);
36 IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
37 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
38 methodReceived = new AtomicBoolean(false);
39 rmiComm.registerSkeleton(objectId, methodReceived);
40 Thread thread1 = new Thread() {
43 ___waitRequestInvokeMethod();
54 public Speaker_Skeleton(Speaker _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
58 set1Allowed = new ArrayList<Integer>(Arrays.asList(object1Permission));
59 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
60 methodReceived = new AtomicBoolean(false);
61 rmiComm.registerSkeleton(objectId, methodReceived);
64 public boolean didAlreadyInitWaitInvoke() {
65 return didAlreadyInitWaitInvoke.get();
72 public boolean startPlayback() {
73 return mainObj.startPlayback();
76 public boolean stopPlayback() {
77 return mainObj.stopPlayback();
80 public boolean getPlaybackState() {
81 return mainObj.getPlaybackState();
84 public boolean setVolume(float _percent) {
85 return mainObj.setVolume(_percent);
88 public float getVolume() {
89 return mainObj.getVolume();
92 public int getPosition() {
93 return mainObj.getPosition();
96 public void setPosition(int _mSec) {
97 mainObj.setPosition(_mSec);
100 public void loadData(short _samples[], int _offs, int _len) {
101 mainObj.loadData(_samples, _offs, _len);
104 public void clearData() {
108 public void registerCallback(SpeakerSmartCallback _cb) {
109 mainObj.registerCallback(_cb);
112 public void ___init() {
113 byte[] localMethodBytes = methodBytes;
114 rmiComm.setGetMethodBytes();
115 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
119 public void ___startPlayback() throws IOException {
120 byte[] localMethodBytes = methodBytes;
121 rmiComm.setGetMethodBytes();
122 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
123 Object retObj = startPlayback();
124 rmiComm.sendReturnObj(retObj, localMethodBytes);
127 public void ___stopPlayback() throws IOException {
128 byte[] localMethodBytes = methodBytes;
129 rmiComm.setGetMethodBytes();
130 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
131 Object retObj = stopPlayback();
132 rmiComm.sendReturnObj(retObj, localMethodBytes);
135 public void ___getPlaybackState() throws IOException {
136 byte[] localMethodBytes = methodBytes;
137 rmiComm.setGetMethodBytes();
138 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
139 Object retObj = getPlaybackState();
140 rmiComm.sendReturnObj(retObj, localMethodBytes);
143 public void ___setVolume() throws IOException {
144 byte[] localMethodBytes = methodBytes;
145 rmiComm.setGetMethodBytes();
146 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { float.class }, new Class<?>[] { null }, localMethodBytes);
147 Object retObj = setVolume((float) paramObj[0]);
148 rmiComm.sendReturnObj(retObj, localMethodBytes);
151 public void ___getVolume() throws IOException {
152 byte[] localMethodBytes = methodBytes;
153 rmiComm.setGetMethodBytes();
154 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
155 Object retObj = getVolume();
156 rmiComm.sendReturnObj(retObj, localMethodBytes);
159 public void ___getPosition() throws IOException {
160 byte[] localMethodBytes = methodBytes;
161 rmiComm.setGetMethodBytes();
162 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
163 Object retObj = getPosition();
164 rmiComm.sendReturnObj(retObj, localMethodBytes);
167 public void ___setPosition() {
168 byte[] localMethodBytes = methodBytes;
169 rmiComm.setGetMethodBytes();
170 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null }, localMethodBytes);
171 setPosition((int) paramObj[0]);
174 public void ___loadData() {
175 byte[] localMethodBytes = methodBytes;
176 rmiComm.setGetMethodBytes();
177 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { short[].class, int.class, int.class }, new Class<?>[] { null, null, null }, localMethodBytes);
178 loadData((short[]) paramObj[0], (int) paramObj[1], (int) paramObj[2]);
181 public void ___clearData() {
182 byte[] localMethodBytes = methodBytes;
183 rmiComm.setGetMethodBytes();
184 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
188 public void ___registerCallback() {
189 byte[] localMethodBytes = methodBytes;
190 rmiComm.setGetMethodBytes();
191 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
193 int[] stubIdArray0 = (int[]) paramObj[0];
194 int objIdRecv0 = stubIdArray0[0];
195 SpeakerSmartCallback newStub0 = null;
196 if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
197 newStub0 = new SpeakerSmartCallback_Stub(rmiComm, objIdRecv0);
198 IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
199 rmiComm.setObjectIdCounter(objIdRecv0);
200 rmiComm.decrementObjectIdCounter();
203 newStub0 = (SpeakerSmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
205 SpeakerSmartCallback stub0 = newStub0;
206 registerCallback(stub0);
207 } catch(Exception ex) {
208 ex.printStackTrace();
209 throw new Error("Exception from callback object instantiation!");
213 public void ___waitRequestInvokeMethod() throws IOException {
214 didAlreadyInitWaitInvoke.compareAndSet(false, true);
216 if (!methodReceived.get()) {
219 methodBytes = rmiComm.getMethodBytes();
220 methodReceived.set(false);
221 int _objectId = IoTRMIComm.getObjectId(methodBytes);
222 int methodId = IoTRMIComm.getMethodId(methodBytes);
223 if (_objectId == objectId) {
224 if (!set1Allowed.contains(methodId)) {
225 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
238 catch (Exception ex) {
239 ex.printStackTrace();
250 catch (Exception ex) {
251 ex.printStackTrace();
262 catch (Exception ex) {
263 ex.printStackTrace();
272 ___getPlaybackState();
274 catch (Exception ex) {
275 ex.printStackTrace();
286 catch (Exception ex) {
287 ex.printStackTrace();
298 catch (Exception ex) {
299 ex.printStackTrace();
310 catch (Exception ex) {
311 ex.printStackTrace();
322 catch (Exception ex) {
323 ex.printStackTrace();
334 catch (Exception ex) {
335 ex.printStackTrace();
346 catch (Exception ex) {
347 ex.printStackTrace();
356 ___registerCallback();
358 catch (Exception ex) {
359 ex.printStackTrace();
365 throw new Error("Method Id " + methodId + " not recognized!");