1 package iotcode.AmcrestCamera;
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.*;
11 import SmartLightsController.CameraSmartCallback_CallbackStub;
13 public class Camera_Skeleton implements Camera {
15 private Camera mainObj;
16 private IoTRMIObject rmiObj;
18 private String callbackAddress;
19 private static int objIdCnt = 0;
20 private IoTRMICall rmiCall;
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;
28 public Camera_Skeleton(Camera _mainObj, String _callbackAddress, int _port) throws Exception {
30 callbackAddress = _callbackAddress;
31 rmiObj = new IoTRMIObject(_port);
32 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
33 set0Allowed.add(-9998);
34 ___waitRequestInvokeMethod();
49 public byte[] getLatestFrame() {
50 return mainObj.getLatestFrame();
53 public long getTimestamp() {
54 return mainObj.getTimestamp();
57 public List<Resolution> getSupportedResolutions() {
58 return mainObj.getSupportedResolutions();
61 public boolean setResolution(Resolution _res) {
62 return mainObj.setResolution(_res);
65 public boolean setFPS(int _fps) {
66 return mainObj.setFPS(_fps);
69 public int getMaxFPS() {
70 return mainObj.getMaxFPS();
73 public int getMinFPS() {
74 return mainObj.getMinFPS();
77 public void registerCallback(CameraSmartCallback _callbackTo) {
78 mainObj.registerCallback(_callbackTo);
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]);
87 public void ___init() {
88 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
93 public void ___start() {
94 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
99 public void ___stop() {
100 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
105 public void ___getLatestFrame() throws IOException {
106 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
108 Object retObj = getLatestFrame();
109 rmiObj.sendReturnObj(retObj);
112 public void ___getTimestamp() throws IOException {
113 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
115 Object retObj = getTimestamp();
116 rmiObj.sendReturnObj(retObj);
119 public void ___getSupportedResolutions() throws IOException {
120 Object[] paramObj = rmiObj.getMethodParams(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();
128 Object retObj = retEnumVal;
129 rmiObj.sendReturnObj(retObj);
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);
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);
149 public void ___getMaxFPS() throws IOException {
150 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
152 Object retObj = getMaxFPS();
153 rmiObj.sendReturnObj(retObj);
156 public void ___getMinFPS() throws IOException {
157 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
159 Object retObj = getMinFPS();
160 rmiObj.sendReturnObj(retObj);
163 public void ___registerCallback() {
164 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
165 new Class<?>[] { null });
167 CameraSmartCallback stub0 = new CameraSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
169 registerCallback(stub0);
170 } catch(Exception ex) {
171 ex.printStackTrace();
172 throw new Error("Exception from callback object instantiation!");
176 private void ___waitRequestInvokeMethod() throws IOException {
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);
187 throw new Error("Object Id: " + _objectId + " not recognized!");
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;
203 throw new Error("Method Id " + methodId + " not recognized!");