1 package iotcode.WaterLeakSensor;
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 SmartthingsSensor_Skeleton implements SmartthingsSensor {
14 private SmartthingsSensor 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; //SmartthingsSensorSmart
23 private static Integer[] object0Permission = { 3, 2, 5, 6, 1, 4, 0 };
24 private static List<Integer> set0Allowed;
27 public SmartthingsSensor_Skeleton(SmartthingsSensor _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 int getValue() {
41 return mainObj.getValue();
44 public boolean isActiveValue() {
45 return mainObj.isActiveValue();
48 public long getTimestampOfLastReading() {
49 return mainObj.getTimestampOfLastReading();
52 public void setId(int id) {
57 return mainObj.getId();
60 public void registerCallback(SmartthingsSensorSmartCallback _callbackTo) {
61 mainObj.registerCallback(_callbackTo);
64 public void ___regCB() throws IOException {
65 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class, String.class, int.class },new Class<?>[] { null, null, null });
66 ports = (int[]) paramObj[0];
67 rmiCall = new IoTRMICall(ports[0], (String) paramObj[1], (int) paramObj[2]);
70 public void ___init() {
71 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
76 public void ___getValue() throws IOException {
77 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
79 Object retObj = getValue();
80 rmiObj.sendReturnObj(retObj);
83 public void ___isActiveValue() throws IOException {
84 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
86 Object retObj = isActiveValue();
87 rmiObj.sendReturnObj(retObj);
90 public void ___getTimestampOfLastReading() throws IOException {
91 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
93 Object retObj = getTimestampOfLastReading();
94 rmiObj.sendReturnObj(retObj);
97 public void ___setId() {
98 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
99 new Class<?>[] { null });
100 setId((int) paramObj[0]);
103 public void ___getId() throws IOException {
104 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
106 Object retObj = getId();
107 rmiObj.sendReturnObj(retObj);
110 public void ___registerCallback() {
111 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
112 new Class<?>[] { null });
114 SmartthingsSensorSmartCallback stub0 = new SmartthingsSensorSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
116 registerCallback(stub0);
117 } catch(Exception ex) {
118 ex.printStackTrace();
119 throw new Error("Exception from callback object instantiation!");
123 private void ___waitRequestInvokeMethod() throws IOException {
125 rmiObj.getMethodBytes();
126 int _objectId = rmiObj.getObjectId();
127 int methodId = rmiObj.getMethodId();
128 if (_objectId == object0Id) {
129 if (!set0Allowed.contains(methodId)) {
130 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
134 throw new Error("Object Id: " + _objectId + " not recognized!");
137 case 0: ___init(); break;
138 case 1: ___getValue(); break;
139 case 2: ___isActiveValue(); break;
140 case 3: ___getTimestampOfLastReading(); break;
141 case 4: ___setId(); break;
142 case 5: ___getId(); break;
143 case 6: ___registerCallback(); break;
144 case -9998: ___regCB(); break;
146 throw new Error("Method Id " + methodId + " not recognized!");