Adding Java Checker Framework checker option in the makefiles; basically this is...
[iot2.git] / benchmarks / Java / HomeSecurityController / SmartthingsSensorSmart_Stub.java
1 package HomeSecurityController;
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 SmartthingsSensorSmart_Stub implements SmartthingsSensorSmart {
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<SmartthingsSensorCallback> listCallbackObj;
22         private int objIdCnt = 0;
23         private final static int object0Id = 0; //SmartthingsSensorSmartCallback
24         private static Integer[] object0Permission = { 0 };
25         private static List<Integer> set0Allowed;
26         
27
28         public SmartthingsSensorSmart_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<SmartthingsSensorCallback>();
34                 set0Allowed.add(-9999);
35                 ___initCallBack();
36         }
37
38         public long getTimestampOfLastReading() {
39                 int methodId = 3;
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);
44                 return (long)retObj;
45         }
46
47         public boolean isActiveValue() {
48                 int methodId = 2;
49                 Class<?> retType = boolean.class;
50                 Class<?>[] paramCls = new Class<?>[] {  };
51                 Object[] paramObj = new Object[] {  };
52                 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
53                 return (boolean)retObj;
54         }
55
56         public int getId() {
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(SmartthingsSensorCallback _callbackTo) {
66                 try {
67                         SmartthingsSensorCallback_CallbackSkeleton skel0 = new SmartthingsSensorCallback_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 = 6;
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                                                 SmartthingsSensorCallback_CallbackSkeleton skel = (SmartthingsSensorCallback_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 SmartthingsSensorCallback is not allowed to access method: " + methodId);
94                                                         }
95                                                         skel.invokeMethod(rmiObj);
96                                                 } else {
97                                                         throw new Error("SmartthingsSensorCallback: Object with Id " + objId + " not found!");
98                                                 }
99                                         }
100                                 } catch (Exception ex) {
101                                         ex.printStackTrace();
102                                         throw new Error("Error instantiating class SmartthingsSensorCallback_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 int getValue() {
116                 int methodId = 1;
117                 Class<?> retType = int.class;
118                 Class<?>[] paramCls = new Class<?>[] {  };
119                 Object[] paramObj = new Object[] {  };
120                 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
121                 return (int)retObj;
122         }
123
124         public void setId(int id) {
125                 int methodId = 4;
126                 Class<?> retType = void.class;
127                 Class<?>[] paramCls = new Class<?>[] { int.class };
128                 Object[] paramObj = new Object[] { id };
129                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
130         }
131
132         public void init() {
133                 int methodId = 0;
134                 Class<?> retType = void.class;
135                 Class<?>[] paramCls = new Class<?>[] {  };
136                 Object[] paramObj = new Object[] {  };
137                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
138         }
139
140 }