3 import java.io.IOException;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import iotrmi.Java.IoTRMICall;
8 import iotrmi.Java.IoTRMIObject;
10 import iotcode.interfaces.*;
12 public class Speaker_Skeleton implements Speaker {
14 private Speaker mainObj;
15 private IoTRMIObject rmiObj;
17 private String callbackAddress;
18 private int objIdCnt = 0;
19 private IoTRMICall rmiCall;
22 private final static int object0Id = 0; //SpeakerSmart
23 private static Integer[] object0Permission = { 6, 2, 9, 1, 3, 4, 5, 7, 8, 0, 10 };
24 private static List<Integer> set0Allowed;
27 public Speaker_Skeleton(Speaker _mainObj, String _callbackAddress, int _port) throws Exception {
29 callbackAddress = _callbackAddress;
30 rmiObj = new IoTRMIObject(_port);
31 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
32 set0Allowed.add(-9998);
33 ___waitRequestInvokeMethod();
40 public boolean startPlayback() {
41 return mainObj.startPlayback();
44 public boolean stopPlayback() {
45 return mainObj.stopPlayback();
48 public boolean getPlaybackState() {
49 return mainObj.getPlaybackState();
52 public boolean setVolume(float _percent) {
53 return mainObj.setVolume(_percent);
56 public float getVolume() {
57 return mainObj.getVolume();
60 public int getPosition() {
61 return mainObj.getPosition();
64 public void setPosition(int _mSec) {
65 mainObj.setPosition(_mSec);
68 public void loadData(short _samples[], int _offs, int _len) {
69 mainObj.loadData(_samples, _offs, _len);
72 public void clearData() {
76 public void registerCallback(SpeakerSmartCallback _cb) {
77 mainObj.registerCallback(_cb);
80 public void ___regCB() throws IOException {
81 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class, String.class, int.class },new Class<?>[] { null, null, null });
82 ports = (int[]) paramObj[0];
83 rmiCall = new IoTRMICall(ports[0], (String) paramObj[1], (int) paramObj[2]);
86 public void ___init() {
87 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
92 public void ___startPlayback() throws IOException {
93 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
95 Object retObj = startPlayback();
96 rmiObj.sendReturnObj(retObj);
99 public void ___stopPlayback() throws IOException {
100 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
102 Object retObj = stopPlayback();
103 rmiObj.sendReturnObj(retObj);
106 public void ___getPlaybackState() throws IOException {
107 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
109 Object retObj = getPlaybackState();
110 rmiObj.sendReturnObj(retObj);
113 public void ___setVolume() throws IOException {
114 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { float.class },
115 new Class<?>[] { null });
116 Object retObj = setVolume((float) paramObj[0]);
117 rmiObj.sendReturnObj(retObj);
120 public void ___getVolume() throws IOException {
121 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
123 Object retObj = getVolume();
124 rmiObj.sendReturnObj(retObj);
127 public void ___getPosition() throws IOException {
128 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
130 Object retObj = getPosition();
131 rmiObj.sendReturnObj(retObj);
134 public void ___setPosition() {
135 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
136 new Class<?>[] { null });
137 setPosition((int) paramObj[0]);
140 public void ___loadData() {
141 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { short[].class, int.class, int.class },
142 new Class<?>[] { null, null, null });
143 loadData((short[]) paramObj[0], (int) paramObj[1], (int) paramObj[2]);
146 public void ___clearData() {
147 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
152 public void ___registerCallback() {
153 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
154 new Class<?>[] { null });
156 SpeakerSmartCallback stub0 = new SpeakerSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
158 registerCallback(stub0);
159 } catch(Exception ex) {
160 ex.printStackTrace();
161 throw new Error("Exception from callback object instantiation!");
165 private void ___waitRequestInvokeMethod() throws IOException {
167 rmiObj.getMethodBytes();
168 int _objectId = rmiObj.getObjectId();
169 int methodId = rmiObj.getMethodId();
170 if (_objectId == object0Id) {
171 if (!set0Allowed.contains(methodId)) {
172 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
176 throw new Error("Object Id: " + _objectId + " not recognized!");
179 case 0: ___init(); break;
180 case 1: ___startPlayback(); break;
181 case 2: ___stopPlayback(); break;
182 case 3: ___getPlaybackState(); break;
183 case 4: ___setVolume(); break;
184 case 5: ___getVolume(); break;
185 case 6: ___getPosition(); break;
186 case 7: ___setPosition(); break;
187 case 8: ___loadData(); break;
188 case 9: ___clearData(); break;
189 case 10: ___registerCallback(); break;
190 case -9998: ___regCB(); break;
192 throw new Error("Method Id " + methodId + " not recognized!");