1 package iotcode.SpruceSensor;
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 MoistureSensor_Skeleton implements MoistureSensor {
14 private MoistureSensor mainObj;
15 private IoTRMIObject rmiObj;
17 private String callbackAddress;
18 private int objIdCnt = 0;
19 private IoTRMICall rmiCall;
22 private final static int object0Id = 0; //MoistureSensorSmart
23 private static Integer[] object0Permission = { 2, 4, 5, 1, 3, 0 };
24 private static List<Integer> set0Allowed;
27 public MoistureSensor_Skeleton(MoistureSensor _mainObj, String _callbackAddress, int _port) throws Exception {
29 callbackAddress = _callbackAddress;
30 rmiObj = new IoTRMIObject(_port);
31 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
32 set0Allowed.add(-9998);
33 ___waitRequestInvokeMethod();
40 public float getMoisture() {
41 return mainObj.getMoisture();
44 public long getTimestampOfLastReading() {
45 return mainObj.getTimestampOfLastReading();
48 public void setId(int id) {
53 return mainObj.getId();
56 public void registerCallback(MoistureSensorSmartCallback _callbackTo) {
57 mainObj.registerCallback(_callbackTo);
60 public void ___regCB() throws IOException {
61 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class, String.class, int.class },new Class<?>[] { null, null, null });
62 ports = (int[]) paramObj[0];
63 rmiCall = new IoTRMICall(ports[0], (String) paramObj[1], (int) paramObj[2]);
66 public void ___init() {
67 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
72 public void ___getMoisture() throws IOException {
73 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
75 Object retObj = getMoisture();
76 rmiObj.sendReturnObj(retObj);
79 public void ___getTimestampOfLastReading() throws IOException {
80 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
82 Object retObj = getTimestampOfLastReading();
83 rmiObj.sendReturnObj(retObj);
86 public void ___setId() {
87 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
88 new Class<?>[] { null });
89 setId((int) paramObj[0]);
92 public void ___getId() throws IOException {
93 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
95 Object retObj = getId();
96 rmiObj.sendReturnObj(retObj);
99 public void ___registerCallback() {
100 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
101 new Class<?>[] { null });
103 MoistureSensorSmartCallback stub0 = new MoistureSensorSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
105 registerCallback(stub0);
106 } catch(Exception ex) {
107 ex.printStackTrace();
108 throw new Error("Exception from callback object instantiation!");
112 private void ___waitRequestInvokeMethod() throws IOException {
114 rmiObj.getMethodBytes();
115 int _objectId = rmiObj.getObjectId();
116 int methodId = rmiObj.getMethodId();
117 if (_objectId == object0Id) {
118 if (!set0Allowed.contains(methodId)) {
119 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
123 throw new Error("Object Id: " + _objectId + " not recognized!");
126 case 0: ___init(); break;
127 case 1: ___getMoisture(); break;
128 case 2: ___getTimestampOfLastReading(); break;
129 case 3: ___setId(); break;
130 case 4: ___getId(); break;
131 case 5: ___registerCallback(); break;
132 case -9998: ___regCB(); break;
134 throw new Error("Method Id " + methodId + " not recognized!");