Replacing default BUFFSIZE value with new buffer size value when a resize needs to...
[iot2.git] / benchmarks / drivers / AmcrestCamera / Camera_Skeleton.java
1 package iotcode.AmcrestCamera;
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 Camera_Skeleton implements Camera {
13
14         private Camera mainObj;
15         private IoTRMIObject rmiObj;
16
17         private String callbackAddress;
18         private static int objIdCnt = 0;
19         private IoTRMICall rmiCall;
20         private int[] ports;
21
22         private final static int object0Id = 0; //CameraSmart
23         private static Integer[] object0Permission = { 8, 7, 9, 6, 2, 1, 4, 3, 0, 10, 5 };
24         private static List<Integer> set0Allowed;
25         
26
27         public Camera_Skeleton(Camera _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 void start() {
41                 mainObj.start();
42         }
43
44         public void stop() {
45                 mainObj.stop();
46         }
47
48         public byte[] getLatestFrame() {
49                 return mainObj.getLatestFrame();
50         }
51
52         public long getTimestamp() {
53                 return mainObj.getTimestamp();
54         }
55
56         public List<Resolution> getSupportedResolutions() {
57                 return mainObj.getSupportedResolutions();
58         }
59
60         public boolean setResolution(Resolution _res) {
61                 return mainObj.setResolution(_res);
62         }
63
64         public boolean setFPS(int _fps) {
65                 return mainObj.setFPS(_fps);
66         }
67
68         public int getMaxFPS() {
69                 return mainObj.getMaxFPS();
70         }
71
72         public int getMinFPS() {
73                 return mainObj.getMinFPS();
74         }
75
76         public void registerCallback(CameraSmartCallback _callbackTo) {
77                 mainObj.registerCallback(_callbackTo);
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 ___start() {
93                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
94                 new Class<?>[] {  });
95                 start();
96         }
97
98         public void ___stop() {
99                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
100                 new Class<?>[] {  });
101                 stop();
102         }
103
104         public void ___getLatestFrame() throws IOException {
105                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
106                 new Class<?>[] {  });
107                 Object retObj = getLatestFrame();
108                 rmiObj.sendReturnObj(retObj);
109         }
110
111         public void ___getTimestamp() throws IOException {
112                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
113                 new Class<?>[] {  });
114                 Object retObj = getTimestamp();
115                 rmiObj.sendReturnObj(retObj);
116         }
117
118         public void ___getSupportedResolutions() throws IOException {
119                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
120                 new Class<?>[] {  });
121                 List<Resolution> retEnum = getSupportedResolutions();
122                 int retLen = retEnum.size();
123                 int[] retEnumVal = new int[retLen];
124                 for (int i = 0; i < retLen; i++) {
125                         retEnumVal[i] = retEnum.get(i).ordinal();
126                 }
127                 Object retObj = retEnumVal;
128                 rmiObj.sendReturnObj(retObj);
129         }
130
131         public void ___setResolution() throws IOException {
132                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class }, 
133                 new Class<?>[] { null });
134                 int paramInt0[] = (int[]) paramObj[0];
135                 Resolution[] enumVals = Resolution.values();
136                 Resolution paramEnum0 = enumVals[paramInt0[0]];
137                 Object retObj = setResolution(paramEnum0);
138                 rmiObj.sendReturnObj(retObj);
139         }
140
141         public void ___setFPS() throws IOException {
142                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
143                 new Class<?>[] { null });
144                 Object retObj = setFPS((int) paramObj[0]);
145                 rmiObj.sendReturnObj(retObj);
146         }
147
148         public void ___getMaxFPS() throws IOException {
149                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
150                 new Class<?>[] {  });
151                 Object retObj = getMaxFPS();
152                 rmiObj.sendReturnObj(retObj);
153         }
154
155         public void ___getMinFPS() throws IOException {
156                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
157                 new Class<?>[] {  });
158                 Object retObj = getMinFPS();
159                 rmiObj.sendReturnObj(retObj);
160         }
161
162         public void ___registerCallback() {
163                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
164                 new Class<?>[] { null });
165                 try {
166                         CameraSmartCallback stub0 = new CameraSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
167                         objIdCnt++;
168                         registerCallback(stub0);
169                 } catch(Exception ex) {
170                         ex.printStackTrace();
171                         throw new Error("Exception from callback object instantiation!");
172                 }
173         }
174
175         private void ___waitRequestInvokeMethod() throws IOException {
176                 while (true) {
177                         rmiObj.getMethodBytes();
178                         int _objectId = rmiObj.getObjectId();
179                         int methodId = rmiObj.getMethodId();
180                         if (_objectId == object0Id) {
181                                 if (!set0Allowed.contains(methodId)) {
182                                         throw new Error("Object with object Id: " + _objectId + "  is not allowed to access method: " + methodId);
183                                 }
184                         }
185                         else {
186                                 throw new Error("Object Id: " + _objectId + " not recognized!");
187                         }
188                         switch (methodId) {
189                                 case 0: ___init(); break;
190                                 case 1: ___start(); break;
191                                 case 2: ___stop(); break;
192                                 case 3: ___getLatestFrame(); break;
193                                 case 4: ___getTimestamp(); break;
194                                 case 5: ___getSupportedResolutions(); break;
195                                 case 6: ___setResolution(); break;
196                                 case 7: ___setFPS(); break;
197                                 case 8: ___getMaxFPS(); break;
198                                 case 9: ___getMinFPS(); break;
199                                 case 10: ___registerCallback(); break;
200                                 case -9998: ___regCB(); break;
201                                 default: 
202                                 throw new Error("Method Id " + methodId + " not recognized!");
203                         }
204                 }
205         }
206
207 }