1 package SpeakerController;
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 SpeakerSmart_Stub implements SpeakerSmart {
14 private IoTRMICall rmiCall;
15 private String callbackAddress;
18 private final static int objectId = 0;
19 // Callback properties
20 private IoTRMIObject rmiObj;
21 List<SpeakerCallback> listCallbackObj;
22 private int objIdCnt = 0;
23 private final static int object0Id = 0; //SpeakerSmartCallback
24 private static Integer[] object0Permission = { 0 };
25 private static List<Integer> set0Allowed;
28 public SpeakerSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
29 callbackAddress = _callbackAddress;
31 rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
32 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
33 listCallbackObj = new ArrayList<SpeakerCallback>();
34 set0Allowed.add(-9999);
38 public int getPosition() {
40 Class<?> retType = int.class;
41 Class<?>[] paramCls = new Class<?>[] { };
42 Object[] paramObj = new Object[] { };
43 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
47 public boolean stopPlayback() {
49 Class<?> retType = boolean.class;
50 Class<?>[] paramCls = new Class<?>[] { };
51 Object[] paramObj = new Object[] { };
52 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
53 return (boolean)retObj;
56 public void clearData() {
58 Class<?> retType = void.class;
59 Class<?>[] paramCls = new Class<?>[] { };
60 Object[] paramObj = new Object[] { };
61 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
64 public boolean startPlayback() {
66 Class<?> retType = boolean.class;
67 Class<?>[] paramCls = new Class<?>[] { };
68 Object[] paramObj = new Object[] { };
69 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
70 return (boolean)retObj;
73 public boolean getPlaybackState() {
75 Class<?> retType = boolean.class;
76 Class<?>[] paramCls = new Class<?>[] { };
77 Object[] paramObj = new Object[] { };
78 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
79 return (boolean)retObj;
82 public boolean setVolume(float _percent) {
84 Class<?> retType = boolean.class;
85 Class<?>[] paramCls = new Class<?>[] { float.class };
86 Object[] paramObj = new Object[] { _percent };
87 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
88 return (boolean)retObj;
91 public float getVolume() {
93 Class<?> retType = float.class;
94 Class<?>[] paramCls = new Class<?>[] { };
95 Object[] paramObj = new Object[] { };
96 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
100 public void setPosition(int _mSec) {
102 Class<?> retType = void.class;
103 Class<?>[] paramCls = new Class<?>[] { int.class };
104 Object[] paramObj = new Object[] { _mSec };
105 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
108 public void loadData(short _samples[], int _offs, int _len) {
110 Class<?> retType = void.class;
111 Class<?>[] paramCls = new Class<?>[] { short[].class, int.class, int.class };
112 Object[] paramObj = new Object[] { _samples, _offs, _len };
113 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
118 Class<?> retType = void.class;
119 Class<?>[] paramCls = new Class<?>[] { };
120 Object[] paramObj = new Object[] { };
121 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
124 public void registerCallback(SpeakerCallback _cb) {
126 SpeakerCallback_CallbackSkeleton skel0 = new SpeakerCallback_CallbackSkeleton(_cb, callbackAddress, objIdCnt++);
127 listCallbackObj.add(skel0);
128 } catch (Exception ex) {
129 ex.printStackTrace();
130 throw new Error("Exception when generating skeleton objects!");
134 Class<?> retType = void.class;
135 Class<?>[] paramCls = new Class<?>[] { int.class };
136 Object[] paramObj = new Object[] { new Integer(1) };
137 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
140 public void ___initCallBack() {
141 Thread thread = new Thread() {
144 rmiObj = new IoTRMIObject(ports[0]);
146 byte[] method = rmiObj.getMethodBytes();
147 int objId = IoTRMIObject.getObjectId(method);
148 SpeakerCallback_CallbackSkeleton skel = (SpeakerCallback_CallbackSkeleton) listCallbackObj.get(objId);
150 int methodId = IoTRMIObject.getMethodId(method);
151 if (!set0Allowed.contains(methodId)) {
152 throw new Error("Callback object for SpeakerCallback is not allowed to access method: " + methodId);
154 skel.invokeMethod(rmiObj);
156 throw new Error("SpeakerCallback: Object with Id " + objId + " not found!");
159 } catch (Exception ex) {
160 ex.printStackTrace();
161 throw new Error("Error instantiating class SpeakerCallback_CallbackSkeleton!");
167 int methodId = -9998;
168 Class<?> retType = void.class;
169 Class<?>[] paramCls = new Class<?>[] { int[].class, String.class, int.class };
170 Object[] paramObj = new Object[] { ports, callbackAddress, 0 };
171 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);