Minor fixes in LifxLightBulb driver (not fully tested yet)
[iot2.git] / benchmarks / IrrigationController / WeatherGatewaySmart_Stub.java
1 package IrrigationController;
2
3 import java.io.IOException;
4 import java.util.List;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import iotrmi.Java.IoTRMICall;
8 import iotrmi.Java.IoTRMIObject;
9
10 import iotcode.interfaces.*;
11
12 public class WeatherGatewaySmart_Stub implements WeatherGatewaySmart {
13
14         private IoTRMICall rmiCall;
15         private String callbackAddress;
16         private int[] ports;
17
18         private final static int objectId = 0;
19         // Callback properties
20         private IoTRMIObject rmiObj;
21         List<WeatherGatewayCallback> listCallbackObj;
22         private int objIdCnt = 0;
23         private final static int object0Id = 0; //WeatherGatewaySmartCallback
24         private static Integer[] object0Permission = { 0 };
25         private static List<Integer> set0Allowed;
26         
27
28         public WeatherGatewaySmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception {
29                 callbackAddress = _callbackAddress;
30                 ports = _ports;
31                 rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev);
32                 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
33                 listCallbackObj = new ArrayList<WeatherGatewayCallback>();
34                 set0Allowed.add(-9999);
35                 ___initCallBack();
36         }
37
38         public double getInchesPerWeek() {
39                 int methodId = 3;
40                 Class<?> retType = double.class;
41                 Class<?>[] paramCls = new Class<?>[] {  };
42                 Object[] paramObj = new Object[] {  };
43                 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
44                 return (double)retObj;
45         }
46
47         public double getInchesPerMinute() {
48                 int methodId = 6;
49                 Class<?> retType = double.class;
50                 Class<?>[] paramCls = new Class<?>[] {  };
51                 Object[] paramObj = new Object[] {  };
52                 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
53                 return (double)retObj;
54         }
55
56         public int getDaysToWaterOn() {
57                 int methodId = 5;
58                 Class<?> retType = int.class;
59                 Class<?>[] paramCls = new Class<?>[] {  };
60                 Object[] paramObj = new Object[] {  };
61                 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
62                 return (int)retObj;
63         }
64
65         public void registerCallback(WeatherGatewayCallback _callbackTo) {
66                 try {
67                         WeatherGatewayCallback_CallbackSkeleton skel0 = new WeatherGatewayCallback_CallbackSkeleton(_callbackTo, callbackAddress, objIdCnt++);
68                         listCallbackObj.add(skel0);
69                 } catch (Exception ex) {
70                         ex.printStackTrace();
71                         throw new Error("Exception when generating skeleton objects!");
72                 }
73
74                 int methodId = 7;
75                 Class<?> retType = void.class;
76                 Class<?>[] paramCls = new Class<?>[] { int.class };
77                 Object[] paramObj = new Object[] { new Integer(1) };
78                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
79         }
80
81         public void ___initCallBack() {
82                 Thread thread = new Thread() {
83                         public void run() {
84                                 try {
85                                         rmiObj = new IoTRMIObject(ports[0]);
86                                         while (true) {
87                                                 byte[] method = rmiObj.getMethodBytes();
88                                                 int objId = IoTRMIObject.getObjectId(method);
89                                                 WeatherGatewayCallback_CallbackSkeleton skel = (WeatherGatewayCallback_CallbackSkeleton) listCallbackObj.get(objId);
90                                                 if (skel != null) {
91                                                         int methodId = IoTRMIObject.getMethodId(method);
92                                                         if (!set0Allowed.contains(methodId)) {
93                                                                 throw new Error("Callback object for WeatherGatewayCallback is not allowed to access method: " + methodId);
94                                                         }
95                                                         skel.invokeMethod(rmiObj);
96                                                 } else {
97                                                         throw new Error("WeatherGatewayCallback: Object with Id " + objId + " not found!");
98                                                 }
99                                         }
100                                 } catch (Exception ex) {
101                                         ex.printStackTrace();
102                                         throw new Error("Error instantiating class WeatherGatewayCallback_CallbackSkeleton!");
103                                 }
104                         }
105                 };
106                 thread.start();
107
108                 int methodId = -9998;
109                 Class<?> retType = void.class;
110                 Class<?>[] paramCls = new Class<?>[] { int[].class, String.class, int.class };
111                 Object[] paramObj = new Object[] { ports, callbackAddress, 0 };
112                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
113         }
114
115         public void stop() {
116                 int methodId = 2;
117                 Class<?> retType = void.class;
118                 Class<?>[] paramCls = new Class<?>[] {  };
119                 Object[] paramObj = new Object[] {  };
120                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
121         }
122
123         public void start() {
124                 int methodId = 1;
125                 Class<?> retType = void.class;
126                 Class<?>[] paramCls = new Class<?>[] {  };
127                 Object[] paramObj = new Object[] {  };
128                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
129         }
130
131         public void init() {
132                 int methodId = 0;
133                 Class<?> retType = void.class;
134                 Class<?>[] paramCls = new Class<?>[] {  };
135                 Object[] paramObj = new Object[] {  };
136                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
137         }
138
139         public int getWeatherZipCode() {
140                 int methodId = 4;
141                 Class<?> retType = int.class;
142                 Class<?>[] paramCls = new Class<?>[] {  };
143                 Object[] paramObj = new Object[] {  };
144                 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
145                 return (int)retObj;
146         }
147
148 }