1 package SmartLightsController;
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 CameraCallback_Skeleton implements CameraCallback {
19 private CameraCallback 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; //CameraSmartCallback
28 private static Integer[] object0Permission = { 0 };
29 private static List<Integer> set0Allowed;
32 public CameraCallback_Skeleton(CameraCallback _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 CameraCallback_Skeleton(CameraCallback _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();
69 public void newCameraFrameAvailable(CameraSmart _camera) {
70 mainObj.newCameraFrameAvailable(_camera);
73 public void ___newCameraFrameAvailable() {
74 byte[] localMethodBytes = methodBytes;
75 rmiComm.setGetMethodBytes();
76 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int[].class }, new Class<?>[] { null }, localMethodBytes);
78 int[] stubIdArray0 = (int[]) paramObj[0];
79 int objIdRecv0 = stubIdArray0[0];
80 CameraSmart newStub0 = null;
81 if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) {
82 newStub0 = new CameraSmart_Stub(rmiComm, objIdRecv0);
83 IoTRMIUtil.mapStub.put(objIdRecv0, newStub0);
84 rmiComm.setObjectIdCounter(objIdRecv0);
85 rmiComm.decrementObjectIdCounter();
88 newStub0 = (CameraSmart_Stub) IoTRMIUtil.mapStub.get(objIdRecv0);
90 CameraSmart stub0 = newStub0;
91 newCameraFrameAvailable(stub0);
92 } catch(Exception ex) {
94 throw new Error("Exception from callback object instantiation!");
98 public void ___waitRequestInvokeMethod() throws IOException {
99 didAlreadyInitWaitInvoke.compareAndSet(false, true);
101 if (!methodReceived.get()) {
104 methodBytes = rmiComm.getMethodBytes();
105 methodReceived.set(false);
106 int _objectId = IoTRMIComm.getObjectId(methodBytes);
107 int methodId = IoTRMIComm.getMethodId(methodBytes);
108 if (_objectId == objectId) {
109 if (!set0Allowed.contains(methodId)) {
110 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
121 ___newCameraFrameAvailable();
123 catch (Exception ex) {
124 ex.printStackTrace();
126 //System.out.println("Thread done!");
131 throw new Error("Method Id " + methodId + " not recognized!");