Replacing default BUFFSIZE value with new buffer size value when a resize needs to...
[iot2.git] / benchmarks / drivers / MotionSensor / SmartthingsSensor_Skeleton.java
1 package iotcode.MotionSensor;
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 SmartthingsSensor_Skeleton implements SmartthingsSensor {
13
14         private SmartthingsSensor mainObj;
15         private IoTRMIObject rmiObj;
16
17         private String callbackAddress;
18         private int objIdCnt = 0;
19         private IoTRMICall rmiCall;
20         private int[] ports;
21
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;
25         
26
27         public SmartthingsSensor_Skeleton(SmartthingsSensor _mainObj, String _callbackAddress, int _port) throws Exception {
28                 mainObj = _mainObj;
29                 callbackAddress = _callbackAddress;
30                 rmiObj = new IoTRMIObject(_port);
31                 set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
32                 set0Allowed.add(-9998);
33                 ___waitRequestInvokeMethod();
34         }
35
36         public void init() {
37                 mainObj.init();
38         }
39
40         public int getValue() {
41                 return mainObj.getValue();
42         }
43
44         public boolean isActiveValue() {
45                 return mainObj.isActiveValue();
46         }
47
48         public long getTimestampOfLastReading() {
49                 return mainObj.getTimestampOfLastReading();
50         }
51
52         public void setId(int id) {
53                 mainObj.setId(id);
54         }
55
56         public int getId() {
57                 return mainObj.getId();
58         }
59
60         public void registerCallback(SmartthingsSensorSmartCallback _callbackTo) {
61                 mainObj.registerCallback(_callbackTo);
62         }
63
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]);
68         }
69
70         public void ___init() {
71                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
72                 new Class<?>[] {  });
73                 init();
74         }
75
76         public void ___getValue() throws IOException {
77                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
78                 new Class<?>[] {  });
79                 Object retObj = getValue();
80                 rmiObj.sendReturnObj(retObj);
81         }
82
83         public void ___isActiveValue() throws IOException {
84                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
85                 new Class<?>[] {  });
86                 Object retObj = isActiveValue();
87                 rmiObj.sendReturnObj(retObj);
88         }
89
90         public void ___getTimestampOfLastReading() throws IOException {
91                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
92                 new Class<?>[] {  });
93                 Object retObj = getTimestampOfLastReading();
94                 rmiObj.sendReturnObj(retObj);
95         }
96
97         public void ___setId() {
98                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
99                 new Class<?>[] { null });
100                 setId((int) paramObj[0]);
101         }
102
103         public void ___getId() throws IOException {
104                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
105                 new Class<?>[] {  });
106                 Object retObj = getId();
107                 rmiObj.sendReturnObj(retObj);
108         }
109
110         public void ___registerCallback() {
111                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
112                 new Class<?>[] { null });
113                 try {
114                         SmartthingsSensorSmartCallback stub0 = new SmartthingsSensorSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
115                         objIdCnt++;
116                         registerCallback(stub0);
117                 } catch(Exception ex) {
118                         ex.printStackTrace();
119                         throw new Error("Exception from callback object instantiation!");
120                 }
121         }
122
123         private void ___waitRequestInvokeMethod() throws IOException {
124                 while (true) {
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);
131                                 }
132                         }
133                         else {
134                                 throw new Error("Object Id: " + _objectId + " not recognized!");
135                         }
136                         switch (methodId) {
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;
145                                 default: 
146                                 throw new Error("Method Id " + methodId + " not recognized!");
147                         }
148                 }
149         }
150
151 }