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