1 package iotcode.AmcrestCamera;
3 import java.io.IOException;
5 import java.util.ArrayList;
6 import java.util.Arrays;
8 import java.util.HashMap;
9 import java.util.concurrent.atomic.AtomicBoolean;
10 import iotrmi.Java.IoTRMIComm;
11 import iotrmi.Java.IoTRMICommClient;
12 import iotrmi.Java.IoTRMICommServer;
13 import iotrmi.Java.IoTRMIUtil;
15 import iotcode.interfaces.*;
17 public class Camera_Skeleton implements Camera {
19 private Camera mainObj;
20 private int objectId = 2;
21 // Communications and synchronizations
22 private IoTRMIComm rmiComm;
23 private AtomicBoolean didAlreadyInitWaitInvoke;
24 private AtomicBoolean methodReceived;
25 private byte[] methodBytes = null;
27 private static Integer[] object2Permission = { 8, 7, 9, 6, 2, 1, 4, 3, 0, 10, 5 };
28 private static List<Integer> set2Allowed;
31 public Camera_Skeleton(Camera _mainObj, int _portSend, int _portRecv) throws Exception {
33 rmiComm = new IoTRMICommServer(_portSend, _portRecv);
34 set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
35 IoTRMIUtil.mapSkel.put(_mainObj, this);
36 IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
37 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
38 methodReceived = new AtomicBoolean(false);
39 rmiComm.registerSkeleton(objectId, methodReceived);
40 Thread thread1 = new Thread() {
43 ___waitRequestInvokeMethod();
54 public Camera_Skeleton(Camera _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
58 set2Allowed = new ArrayList<Integer>(Arrays.asList(object2Permission));
59 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
60 methodReceived = new AtomicBoolean(false);
61 rmiComm.registerSkeleton(objectId, methodReceived);
64 public boolean didAlreadyInitWaitInvoke() {
65 return didAlreadyInitWaitInvoke.get();
80 public byte[] getLatestFrame() {
81 return mainObj.getLatestFrame();
84 public long getTimestamp() {
85 return mainObj.getTimestamp();
88 public List<Resolution> getSupportedResolutions() {
89 return mainObj.getSupportedResolutions();
92 public boolean setResolution(Resolution _res) {
93 return mainObj.setResolution(_res);
96 public boolean setFPS(int _fps) {
97 return mainObj.setFPS(_fps);
100 public int getMaxFPS() {
101 return mainObj.getMaxFPS();
104 public int getMinFPS() {
105 return mainObj.getMinFPS();
108 public void registerCallback(CameraSmartCallback _callbackTo) {
109 mainObj.registerCallback(_callbackTo);
112 public void ___init() {
113 byte[] localMethodBytes = methodBytes;
114 rmiComm.setGetMethodBytes();
115 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
119 public void ___start() {
120 byte[] localMethodBytes = methodBytes;
121 rmiComm.setGetMethodBytes();
122 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
126 public void ___stop() {
127 byte[] localMethodBytes = methodBytes;
128 rmiComm.setGetMethodBytes();
129 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
133 public void ___getLatestFrame() throws IOException {
134 byte[] localMethodBytes = methodBytes;
135 rmiComm.setGetMethodBytes();
136 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
137 Object retObj = getLatestFrame();
138 rmiComm.sendReturnObj(retObj, localMethodBytes);
141 public void ___getTimestamp() throws IOException {
142 byte[] localMethodBytes = methodBytes;
143 rmiComm.setGetMethodBytes();
144 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
145 Object retObj = getTimestamp();
146 rmiComm.sendReturnObj(retObj, localMethodBytes);
149 public void ___getSupportedResolutions() throws IOException {
150 byte[] localMethodBytes = methodBytes;
151 rmiComm.setGetMethodBytes();
152 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
153 List<Resolution> retEnum = getSupportedResolutions();
154 int retLen = retEnum.size();
155 int[] retEnumVal = new int[retLen];
156 for (int i = 0; i < retLen; i++) {
157 retEnumVal[i] = retEnum.get(i).ordinal();
159 Object retObj = retEnumVal;
160 rmiComm.sendReturnObj(retObj, localMethodBytes);
163 public void ___setResolution() throws IOException {
164 byte[] localMethodBytes = methodBytes;
165 rmiComm.setGetMethodBytes();
166 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
167 int paramInt0[] = (int[]) paramObj[0];
168 Resolution[] enumVals = Resolution.values();
169 Resolution paramEnum0 = enumVals[paramInt0[0]];
170 Object retObj = setResolution(paramEnum0);
171 rmiComm.sendReturnObj(retObj, localMethodBytes);
174 public void ___setFPS() throws IOException {
175 byte[] localMethodBytes = methodBytes;
176 rmiComm.setGetMethodBytes();
177 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null }, localMethodBytes);
178 Object retObj = setFPS((int) paramObj[0]);
179 rmiComm.sendReturnObj(retObj, localMethodBytes);
182 public void ___getMaxFPS() throws IOException {
183 byte[] localMethodBytes = methodBytes;
184 rmiComm.setGetMethodBytes();
185 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
186 Object retObj = getMaxFPS();
187 rmiComm.sendReturnObj(retObj, localMethodBytes);
190 public void ___getMinFPS() throws IOException {
191 byte[] localMethodBytes = methodBytes;
192 rmiComm.setGetMethodBytes();
193 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
194 Object retObj = getMinFPS();
195 rmiComm.sendReturnObj(retObj, localMethodBytes);
198 public void ___registerCallback() {
199 byte[] localMethodBytes = methodBytes;
200 rmiComm.setGetMethodBytes();
201 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
203 int[] stubIdArray0 = (int[]) paramObj[0];
204 int objIdRecv0 = stubIdArray0[0];
205 CameraSmartCallback newStub0 = null;
206 if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
207 newStub0 = new CameraSmartCallback_Stub(rmiComm, objIdRecv0);
208 IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
209 rmiComm.setObjectIdCounter(objIdRecv0);
210 rmiComm.decrementObjectIdCounter();
213 newStub0 = (CameraSmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
215 CameraSmartCallback stub0 = newStub0;
216 registerCallback(stub0);
217 } catch(Exception ex) {
218 ex.printStackTrace();
219 throw new Error("Exception from callback object instantiation!");
223 public void ___waitRequestInvokeMethod() throws IOException {
224 didAlreadyInitWaitInvoke.compareAndSet(false, true);
226 if (!methodReceived.get()) {
229 methodBytes = rmiComm.getMethodBytes();
230 methodReceived.set(false);
231 int _objectId = IoTRMIComm.getObjectId(methodBytes);
232 int methodId = IoTRMIComm.getMethodId(methodBytes);
233 if (_objectId == objectId) {
234 if (!set2Allowed.contains(methodId)) {
235 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
248 catch (Exception ex) {
249 ex.printStackTrace();
260 catch (Exception ex) {
261 ex.printStackTrace();
272 catch (Exception ex) {
273 ex.printStackTrace();
284 catch (Exception ex) {
285 ex.printStackTrace();
296 catch (Exception ex) {
297 ex.printStackTrace();
306 ___getSupportedResolutions();
308 catch (Exception ex) {
309 ex.printStackTrace();
320 catch (Exception ex) {
321 ex.printStackTrace();
332 catch (Exception ex) {
333 ex.printStackTrace();
344 catch (Exception ex) {
345 ex.printStackTrace();
356 catch (Exception ex) {
357 ex.printStackTrace();
366 ___registerCallback();
368 catch (Exception ex) {
369 ex.printStackTrace();
375 throw new Error("Method Id " + methodId + " not recognized!");