-package SmartLightsController;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Arrays;
-import iotrmi.Java.IoTRMICall;
-import iotrmi.Java.IoTRMIObject;
-
-import iotcode.interfaces.*;
-
-public class CameraSmart_CallbackStub implements CameraSmart {
-
- private IoTRMICall rmiCall;
- private String callbackAddress;
- private int[] ports;
-
- private int objectId = 0;
- // Callback properties
- private IoTRMIObject rmiObj;
- List<CameraCallback> listCallbackObj;
- private static int objIdCnt = 0;
- private final static int object0Id = 0; //CameraSmartCallback
- private static Integer[] object0Permission = { 0 };
- private static List<Integer> set0Allowed;
-
-
- public CameraSmart_CallbackStub(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {
- callbackAddress = _callbackAddress;
- objectId = _objectId;
- rmiCall = _rmiCall;
- ports = _ports;
- set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- listCallbackObj = new ArrayList<CameraCallback>();
- ___initCallBack();
- }
-
- public int getMaxFPS() {
- int methodId = 8;
- Class<?> retType = int.class;
- Class<?>[] paramCls = new Class<?>[] { };
- Object[] paramObj = new Object[] { };
- Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- return (int)retObj;
- }
-
- public boolean setFPS(int _fps) {
- int methodId = 7;
- Class<?> retType = boolean.class;
- Class<?>[] paramCls = new Class<?>[] { int.class };
- Object[] paramObj = new Object[] { _fps };
- Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- return (boolean)retObj;
- }
-
- public int getMinFPS() {
- int methodId = 9;
- Class<?> retType = int.class;
- Class<?>[] paramCls = new Class<?>[] { };
- Object[] paramObj = new Object[] { };
- Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- return (int)retObj;
- }
-
- public boolean setResolution(Resolution _res) {
- int methodId = 6;
- Class<?> retType = boolean.class;
- int paramEnum0[] = new int[1];
- paramEnum0[0] = _res.ordinal();
- Class<?>[] paramCls = new Class<?>[] { int[].class };
- Object[] paramObj = new Object[] { paramEnum0 };
- Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- return (boolean)retObj;
- }
-
- public void stop() {
- int methodId = 2;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { };
- Object[] paramObj = new Object[] { };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
- public void start() {
- int methodId = 1;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { };
- Object[] paramObj = new Object[] { };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
- public long getTimestamp() {
- int methodId = 4;
- Class<?> retType = long.class;
- Class<?>[] paramCls = new Class<?>[] { };
- Object[] paramObj = new Object[] { };
- Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- return (long)retObj;
- }
-
- public byte[] getLatestFrame() {
- int methodId = 3;
- Class<?> retType = byte[].class;
- Class<?>[] paramCls = new Class<?>[] { };
- Object[] paramObj = new Object[] { };
- Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- return (byte[])retObj;
- }
-
- public void init() {
- int methodId = 0;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { };
- Object[] paramObj = new Object[] { };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
- public void registerCallback(CameraCallback _callbackTo) {
- try {
- CameraCallback_CallbackSkeleton skel0 = new CameraCallback_CallbackSkeleton(_callbackTo, callbackAddress, objIdCnt++);
- listCallbackObj.add(skel0);
- } catch (Exception ex) {
- ex.printStackTrace();
- throw new Error("Exception when generating skeleton objects!");
- }
-
- int methodId = 10;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { int.class };
- Object[] paramObj = new Object[] { new Integer(1) };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
- public void ___initCallBack() {
- Thread thread = new Thread() {
- public void run() {
- try {
- rmiObj = new IoTRMIObject(ports[1]);
- while (true) {
- byte[] method = rmiObj.getMethodBytes();
- int methodId = IoTRMIObject.getMethodId(method);
- if (!set0Allowed.contains(methodId)) {
- throw new Error("Callback object for CameraCallback is not allowed to access method: " + methodId);
- }
- int objId = IoTRMIObject.getObjectId(method);
- CameraCallback_CallbackSkeleton skel = (CameraCallback_CallbackSkeleton) listCallbackObj.get(objId);
- if (skel != null) {
- skel.invokeMethod(rmiObj);
- } else {
- throw new Error("CameraCallback: Object with Id " + objId + " not found!");
- }
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- throw new Error("Error instantiating class CameraCallback_CallbackSkeleton!");
- }
- }
- };
- thread.start();
-
- int methodId = -9998;
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { int[].class, String.class, int.class };
- Object[] paramObj = new Object[] { ports, callbackAddress, 0 };
- rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- }
-
- public List<Resolution> getSupportedResolutions() {
- int methodId = 5;
- Class<?> retType = int[].class;
- Class<?>[] paramCls = new Class<?>[] { };
- Object[] paramObj = new Object[] { };
- Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
- int[] retEnum = (int[]) retObj;
- Resolution[] enumVals = Resolution.values();
- int retLen = retEnum.length;
- List<Resolution> enumRetVal = new ArrayList<Resolution>();
- for (int i = 0; i < retLen; i++) {
- enumRetVal.add(enumVals[retEnum[i]]);
- }
- return enumRetVal;
- }
-
-}