Replacing default BUFFSIZE value with new buffer size value when a resize needs to...
[iot2.git] / benchmarks / drivers / IHome / Speaker_Skeleton.java
1 package iotcode.IHome;
2
3 import java.io.IOException;
4 import java.util.List;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import iotrmi.Java.IoTRMICall;
8 import iotrmi.Java.IoTRMIObject;
9
10 import iotcode.interfaces.*;
11
12 public class Speaker_Skeleton implements Speaker {
13
14         private Speaker mainObj;
15         private IoTRMIObject rmiObj;
16
17         private String callbackAddress;
18         private int objIdCnt = 0;
19         private IoTRMICall rmiCall;
20         private int[] ports;
21
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;
25         
26
27         public Speaker_Skeleton(Speaker _mainObj, String _callbackAddress, int _port) throws Exception {
28                 mainObj = _mainObj;
29                 callbackAddress = _callbackAddress;
30                 rmiObj = new IoTRMIObject(_port);
31                 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
32                 set0Allowed.add(-9998);
33                 ___waitRequestInvokeMethod();
34         }
35
36         public void init() {
37                 mainObj.init();
38         }
39
40         public boolean startPlayback() {
41                 return mainObj.startPlayback();
42         }
43
44         public boolean stopPlayback() {
45                 return mainObj.stopPlayback();
46         }
47
48         public boolean getPlaybackState() {
49                 return mainObj.getPlaybackState();
50         }
51
52         public boolean setVolume(float _percent) {
53                 return mainObj.setVolume(_percent);
54         }
55
56         public float getVolume() {
57                 return mainObj.getVolume();
58         }
59
60         public int getPosition() {
61                 return mainObj.getPosition();
62         }
63
64         public void setPosition(int _mSec) {
65                 mainObj.setPosition(_mSec);
66         }
67
68         public void loadData(short _samples[], int _offs, int _len) {
69                 mainObj.loadData(_samples, _offs, _len);
70         }
71
72         public void clearData() {
73                 mainObj.clearData();
74         }
75
76         public void registerCallback(SpeakerSmartCallback _cb) {
77                 mainObj.registerCallback(_cb);
78         }
79
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]);
84         }
85
86         public void ___init() {
87                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
88                 new Class<?>[] {  });
89                 init();
90         }
91
92         public void ___startPlayback() throws IOException {
93                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
94                 new Class<?>[] {  });
95                 Object retObj = startPlayback();
96                 rmiObj.sendReturnObj(retObj);
97         }
98
99         public void ___stopPlayback() throws IOException {
100                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
101                 new Class<?>[] {  });
102                 Object retObj = stopPlayback();
103                 rmiObj.sendReturnObj(retObj);
104         }
105
106         public void ___getPlaybackState() throws IOException {
107                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
108                 new Class<?>[] {  });
109                 Object retObj = getPlaybackState();
110                 rmiObj.sendReturnObj(retObj);
111         }
112
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);
118         }
119
120         public void ___getVolume() throws IOException {
121                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
122                 new Class<?>[] {  });
123                 Object retObj = getVolume();
124                 rmiObj.sendReturnObj(retObj);
125         }
126
127         public void ___getPosition() throws IOException {
128                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
129                 new Class<?>[] {  });
130                 Object retObj = getPosition();
131                 rmiObj.sendReturnObj(retObj);
132         }
133
134         public void ___setPosition() {
135                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
136                 new Class<?>[] { null });
137                 setPosition((int) paramObj[0]);
138         }
139
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]);
144         }
145
146         public void ___clearData() {
147                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
148                 new Class<?>[] {  });
149                 clearData();
150         }
151
152         public void ___registerCallback() {
153                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
154                 new Class<?>[] { null });
155                 try {
156                         SpeakerSmartCallback stub0 = new SpeakerSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
157                         objIdCnt++;
158                         registerCallback(stub0);
159                 } catch(Exception ex) {
160                         ex.printStackTrace();
161                         throw new Error("Exception from callback object instantiation!");
162                 }
163         }
164
165         private void ___waitRequestInvokeMethod() throws IOException {
166                 while (true) {
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);
173                                 }
174                         }
175                         else {
176                                 throw new Error("Object Id: " + _objectId + " not recognized!");
177                         }
178                         switch (methodId) {
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;
191                                 default: 
192                                 throw new Error("Method Id " + methodId + " not recognized!");
193                         }
194                 }
195         }
196
197 }