1 package IrrigationController;
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 WeatherGatewayCallback_Skeleton implements WeatherGatewayCallback {
19 private WeatherGatewayCallback mainObj;
20 private int objectId = 4;
21 // Communications and synchronizations
22 private IoTRMIComm rmiComm;
23 private AtomicBoolean didAlreadyInitWaitInvoke;
24 private AtomicBoolean methodReceived;
25 private byte[] methodBytes = null;
27 private static Integer[] object4Permission = { 0 };
28 private static List<Integer> set4Allowed;
31 public WeatherGatewayCallback_Skeleton(WeatherGatewayCallback _mainObj, int _portSend, int _portRecv) throws Exception {
33 rmiComm = new IoTRMICommServer(_portSend, _portRecv);
34 set4Allowed = new ArrayList<Integer>(Arrays.asList(object4Permission));
35 IoTRMIUtil.mapSkel.put(_mainObj, this);
36 IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
37 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
38 methodReceived = new AtomicBoolean(false);
39 rmiComm.registerSkeleton(objectId, methodReceived);
40 Thread thread1 = new Thread() {
43 ___waitRequestInvokeMethod();
54 public WeatherGatewayCallback_Skeleton(WeatherGatewayCallback _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
58 set4Allowed = new ArrayList<Integer>(Arrays.asList(object4Permission));
59 didAlreadyInitWaitInvoke = new AtomicBoolean(false);
60 methodReceived = new AtomicBoolean(false);
61 rmiComm.registerSkeleton(objectId, methodReceived);
64 public boolean didAlreadyInitWaitInvoke() {
65 return didAlreadyInitWaitInvoke.get();
68 public void informationRetrieved(double _inchesPerWeek, int _weatherZipCode, int _daysToWaterOn, double _inchesPerMinute) {
69 mainObj.informationRetrieved(_inchesPerWeek, _weatherZipCode, _daysToWaterOn, _inchesPerMinute);
72 public void ___informationRetrieved() {
73 byte[] localMethodBytes = methodBytes;
74 rmiComm.setGetMethodBytes();
75 Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { double.class, int.class, int.class, double.class }, new Class<?>[] { null, null, null, null }, localMethodBytes);
76 informationRetrieved((double) paramObj[0], (int) paramObj[1], (int) paramObj[2], (double) paramObj[3]);
79 public void ___waitRequestInvokeMethod() throws IOException {
80 didAlreadyInitWaitInvoke.compareAndSet(false, true);
82 if (!methodReceived.get()) {
85 methodBytes = rmiComm.getMethodBytes();
86 methodReceived.set(false);
87 int _objectId = IoTRMIComm.getObjectId(methodBytes);
88 int methodId = IoTRMIComm.getMethodId(methodBytes);
89 if (_objectId == objectId) {
90 if (!set4Allowed.contains(methodId)) {
91 throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
102 ___informationRetrieved();
104 catch (Exception ex) {
105 ex.printStackTrace();
111 throw new Error("Method Id " + methodId + " not recognized!");