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 = 0;
21 // Communications and synchronizations
22 private IoTRMIComm rmiComm;
23 private AtomicBoolean didAlreadyInitWaitInvoke;
24 private AtomicBoolean methodReceived;
25 private byte[] methodBytes = null;
27 private final static int object0Id = 0; //CameraSmart
28 private static Integer[] object0Permission = { 8, 7, 9, 6, 2, 1, 4, 3, 0, 10, 5 };
29 private static List<Integer> set0Allowed;
32 public Camera_Skeleton(Camera _mainObj, int _portSend, int _portRecv) throws Exception {
34 rmiComm = new IoTRMICommServer(_portSend, _portRecv);
35 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
36 IoTRMIUtil.mapSkel.put(_mainObj, this);
37 IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
38 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
39 methodReceived = new AtomicBoolean(false);
40 rmiComm.registerSkeleton(objectId, methodReceived);
41 Thread thread1 = new Thread() {
44 ___waitRequestInvokeMethod();
55 public Camera_Skeleton(Camera _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
59 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
60 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
61 methodReceived = new AtomicBoolean(false);
62 rmiComm.registerSkeleton(objectId, methodReceived);
65 public boolean didAlreadyInitWaitInvoke() {
66 return didAlreadyInitWaitInvoke.get();
81 public byte[] getLatestFrame() {
82 return mainObj.getLatestFrame();
85 public long getTimestamp() {
86 return mainObj.getTimestamp();
89 public List<Resolution> getSupportedResolutions() {
90 return mainObj.getSupportedResolutions();
93 public boolean setResolution(Resolution _res) {
94 return mainObj.setResolution(_res);
97 public boolean setFPS(int _fps) {
98 return mainObj.setFPS(_fps);
101 public int getMaxFPS() {
102 return mainObj.getMaxFPS();
105 public int getMinFPS() {
106 return mainObj.getMinFPS();
109 public void registerCallback(CameraSmartCallback _callbackTo) {
110 mainObj.registerCallback(_callbackTo);
113 public void ___init() {
114 byte[] localMethodBytes = methodBytes;
115 rmiComm.setGetMethodBytes();
116 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
120 public void ___start() {
121 byte[] localMethodBytes = methodBytes;
122 rmiComm.setGetMethodBytes();
123 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
127 public void ___stop() {
128 byte[] localMethodBytes = methodBytes;
129 rmiComm.setGetMethodBytes();
130 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
134 public void ___getLatestFrame() throws IOException {
135 byte[] localMethodBytes = methodBytes;
136 rmiComm.setGetMethodBytes();
137 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
138 Object retObj = getLatestFrame();
139 rmiComm.sendReturnObj(retObj, localMethodBytes);
142 public void ___getTimestamp() throws IOException {
143 byte[] localMethodBytes = methodBytes;
144 rmiComm.setGetMethodBytes();
145 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
146 Object retObj = getTimestamp();
147 rmiComm.sendReturnObj(retObj, localMethodBytes);
150 public void ___getSupportedResolutions() throws IOException {
151 byte[] localMethodBytes = methodBytes;
152 rmiComm.setGetMethodBytes();
153 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
154 List<Resolution> retEnum = getSupportedResolutions();
155 int retLen = retEnum.size();
156 int[] retEnumVal = new int[retLen];
157 for (int i = 0; i < retLen; i++) {
158 retEnumVal[i] = retEnum.get(i).ordinal();
160 Object retObj = retEnumVal;
161 rmiComm.sendReturnObj(retObj, localMethodBytes);
164 public void ___setResolution() throws IOException {
165 byte[] localMethodBytes = methodBytes;
166 rmiComm.setGetMethodBytes();
167 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
168 int paramInt0[] = (int[]) paramObj[0];
169 Resolution[] enumVals = Resolution.values();
170 Resolution paramEnum0 = enumVals[paramInt0[0]];
171 Object retObj = setResolution(paramEnum0);
172 rmiComm.sendReturnObj(retObj, localMethodBytes);
175 public void ___setFPS() throws IOException {
176 byte[] localMethodBytes = methodBytes;
177 rmiComm.setGetMethodBytes();
178 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null }, localMethodBytes);
179 Object retObj = setFPS((int) paramObj[0]);
180 rmiComm.sendReturnObj(retObj, localMethodBytes);
183 public void ___getMaxFPS() throws IOException {
184 byte[] localMethodBytes = methodBytes;
185 rmiComm.setGetMethodBytes();
186 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
187 Object retObj = getMaxFPS();
188 rmiComm.sendReturnObj(retObj, localMethodBytes);
191 public void ___getMinFPS() throws IOException {
192 byte[] localMethodBytes = methodBytes;
193 rmiComm.setGetMethodBytes();
194 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
195 Object retObj = getMinFPS();
196 rmiComm.sendReturnObj(retObj, localMethodBytes);
199 public void ___registerCallback() {
200 byte[] localMethodBytes = methodBytes;
201 rmiComm.setGetMethodBytes();
202 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
204 int[] stubIdArray0 = (int[]) paramObj[0];
205 int objIdRecv0 = stubIdArray0[0];
206 CameraSmartCallback newStub0 = null;
207 if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
208 newStub0 = new CameraSmartCallback_Stub(rmiComm, objIdRecv0);
209 IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
210 rmiComm.setObjectIdCounter(objIdRecv0);
211 rmiComm.decrementObjectIdCounter();
214 newStub0 = (CameraSmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
216 CameraSmartCallback stub0 = newStub0;
217 registerCallback(stub0);
218 } catch(Exception ex) {
219 ex.printStackTrace();
220 throw new Error("Exception from callback object instantiation!");
224 public void ___waitRequestInvokeMethod() throws IOException {
225 didAlreadyInitWaitInvoke.compareAndSet(false, true);
227 if (!methodReceived.get()) {
230 methodBytes = rmiComm.getMethodBytes();
231 methodReceived.set(false);
232 int _objectId = IoTRMIComm.getObjectId(methodBytes);
233 int methodId = IoTRMIComm.getMethodId(methodBytes);
234 if (_objectId == objectId) {
235 if (!set0Allowed.contains(methodId)) {
236 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
249 catch (Exception ex) {
250 ex.printStackTrace();
261 catch (Exception ex) {
262 ex.printStackTrace();
273 catch (Exception ex) {
274 ex.printStackTrace();
285 catch (Exception ex) {
286 ex.printStackTrace();
297 catch (Exception ex) {
298 ex.printStackTrace();
307 ___getSupportedResolutions();
309 catch (Exception ex) {
310 ex.printStackTrace();
321 catch (Exception ex) {
322 ex.printStackTrace();
333 catch (Exception ex) {
334 ex.printStackTrace();
345 catch (Exception ex) {
346 ex.printStackTrace();
357 catch (Exception ex) {
358 ex.printStackTrace();
367 ___registerCallback();
369 catch (Exception ex) {
370 ex.printStackTrace();
376 throw new Error("Method Id " + methodId + " not recognized!");