1 package IrrigationController;
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.*;
12 public class MoistureSensorSmart_Stub implements MoistureSensorSmart {
14 private IoTRMICall rmiCall;
15 private String callbackAddress;
18 private final static int objectId = 0;
19 // Callback properties
20 private IoTRMIObject rmiObj;
21 List<MoistureSensorCallback> listCallbackObj;
22 private int objIdCnt = 0;
23 private final static int object0Id = 0; //MoistureSensorSmartCallback
24 private static Integer[] object0Permission = { 0 };
25 private static List<Integer> set0Allowed;
28 public MoistureSensorSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
29 callbackAddress = _callbackAddress;
31 rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
32 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
33 listCallbackObj = new ArrayList<MoistureSensorCallback>();
34 set0Allowed.add(-9999);
38 public long getTimestampOfLastReading() {
40 Class<?> retType = long.class;
41 Class<?>[] paramCls = new Class<?>[] { };
42 Object[] paramObj = new Object[] { };
43 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
49 Class<?> retType = int.class;
50 Class<?>[] paramCls = new Class<?>[] { };
51 Object[] paramObj = new Object[] { };
52 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
56 public void registerCallback(MoistureSensorCallback _callbackTo) {
58 MoistureSensorCallback_CallbackSkeleton skel0 = new MoistureSensorCallback_CallbackSkeleton(_callbackTo, callbackAddress, objIdCnt++);
59 listCallbackObj.add(skel0);
60 } catch (Exception ex) {
62 throw new Error("Exception when generating skeleton objects!");
66 Class<?> retType = void.class;
67 Class<?>[] paramCls = new Class<?>[] { int.class };
68 Object[] paramObj = new Object[] { new Integer(1) };
69 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
72 public void ___initCallBack() {
73 Thread thread = new Thread() {
76 rmiObj = new IoTRMIObject(ports[0]);
78 byte[] method = rmiObj.getMethodBytes();
79 int objId = IoTRMIObject.getObjectId(method);
80 MoistureSensorCallback_CallbackSkeleton skel = (MoistureSensorCallback_CallbackSkeleton) listCallbackObj.get(objId);
82 int methodId = IoTRMIObject.getMethodId(method);
83 if (!set0Allowed.contains(methodId)) {
84 throw new Error("Callback object for MoistureSensorCallback is not allowed to access method: " + methodId);
86 skel.invokeMethod(rmiObj);
88 throw new Error("MoistureSensorCallback: Object with Id " + objId + " not found!");
91 } catch (Exception ex) {
93 throw new Error("Error instantiating class MoistureSensorCallback_CallbackSkeleton!");
100 Class<?> retType = void.class;
101 Class<?>[] paramCls = new Class<?>[] { int[].class, String.class, int.class };
102 Object[] paramObj = new Object[] { ports, callbackAddress, 0 };
103 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
106 public float getMoisture() {
108 Class<?> retType = float.class;
109 Class<?>[] paramCls = new Class<?>[] { };
110 Object[] paramObj = new Object[] { };
111 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
112 return (float)retObj;
115 public void setId(int id) {
117 Class<?> retType = void.class;
118 Class<?>[] paramCls = new Class<?>[] { int.class };
119 Object[] paramObj = new Object[] { id };
120 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
125 Class<?> retType = void.class;
126 Class<?>[] paramCls = new Class<?>[] { };
127 Object[] paramObj = new Object[] { };
128 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);