Preparing second and third benchmarks; backing up MySQL database
[iot2.git] / benchmarks / SmartLightsController / Camera_CallbackSkeleton.java
1 package SmartLightsController;
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 Camera_CallbackSkeleton implements Camera {
13
14         private Camera mainObj;
15         private int objectId = 0;
16         private String callbackAddress;
17         private static int objIdCnt = 0;
18         private IoTRMICall rmiCall;
19         private int[] ports;
20
21         
22
23         public Camera_CallbackSkeleton(Camera _mainObj, String _callbackAddress, int _objectId) throws Exception {
24                 callbackAddress = _callbackAddress;
25                 mainObj = _mainObj;
26                 objectId = _objectId;
27         }
28
29         public void init() {
30                 mainObj.init();
31         }
32
33         public void start() {
34                 mainObj.start();
35         }
36
37         public void stop() {
38                 mainObj.stop();
39         }
40
41         public byte[] getLatestFrame() {
42                 return mainObj.getLatestFrame();
43         }
44
45         public long getTimestamp() {
46                 return mainObj.getTimestamp();
47         }
48
49         public List<Resolution> getSupportedResolutions() {
50                 return mainObj.getSupportedResolutions();
51         }
52
53         public boolean setResolution(Resolution _res) {
54                 return mainObj.setResolution(_res);
55         }
56
57         public boolean setFPS(int _fps) {
58                 return mainObj.setFPS(_fps);
59         }
60
61         public int getMaxFPS() {
62                 return mainObj.getMaxFPS();
63         }
64
65         public int getMinFPS() {
66                 return mainObj.getMinFPS();
67         }
68
69         public void registerCallback(CameraSmartCallback _callbackTo) {
70                 mainObj.registerCallback(_callbackTo);
71         }
72
73         public void ___regCB(IoTRMIObject rmiObj) throws IOException {
74                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class, String.class, int.class },new Class<?>[] { null, null, null });
75                 ports = (int[]) paramObj[0];
76                 rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], ports[1]);
77         }
78
79         public void ___init(IoTRMIObject rmiObj) {
80                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
81                 new Class<?>[] {  });
82                 init();
83         }
84
85         public void ___start(IoTRMIObject rmiObj) {
86                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
87                 new Class<?>[] {  });
88                 start();
89         }
90
91         public void ___stop(IoTRMIObject rmiObj) {
92                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
93                 new Class<?>[] {  });
94                 stop();
95         }
96
97         public void ___getLatestFrame(IoTRMIObject rmiObj) throws IOException {
98                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
99                 new Class<?>[] {  });
100                 Object retObj = getLatestFrame();
101                 rmiObj.sendReturnObj(retObj);
102         }
103
104         public void ___getTimestamp(IoTRMIObject rmiObj) throws IOException {
105                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
106                 new Class<?>[] {  });
107                 Object retObj = getTimestamp();
108                 rmiObj.sendReturnObj(retObj);
109         }
110
111         public void ___getSupportedResolutions(IoTRMIObject rmiObj) throws IOException {
112                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
113                 new Class<?>[] {  });
114                 List<Resolution> retEnum = getSupportedResolutions();
115                 int retLen = retEnum.size();
116                 int[] retEnumVal = new int[retLen];
117                 for (int i = 0; i < retLen; i++) {
118                         retEnumVal[i] = retEnum.get(i).ordinal();
119                 }
120                 Object retObj = retEnumVal;
121                 rmiObj.sendReturnObj(retObj);
122         }
123
124         public void ___setResolution(IoTRMIObject rmiObj) throws IOException {
125                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class }, 
126                 new Class<?>[] { null });
127                 int paramInt0[] = (int[]) paramObj[0];
128                 Resolution[] enumVals = Resolution.values();
129                 Resolution paramEnum0 = enumVals[paramInt0[0]];
130                 Object retObj = setResolution(paramEnum0);
131                 rmiObj.sendReturnObj(retObj);
132         }
133
134         public void ___setFPS(IoTRMIObject rmiObj) throws IOException {
135                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
136                 new Class<?>[] { null });
137                 Object retObj = setFPS((int) paramObj[0]);
138                 rmiObj.sendReturnObj(retObj);
139         }
140
141         public void ___getMaxFPS(IoTRMIObject rmiObj) throws IOException {
142                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
143                 new Class<?>[] {  });
144                 Object retObj = getMaxFPS();
145                 rmiObj.sendReturnObj(retObj);
146         }
147
148         public void ___getMinFPS(IoTRMIObject rmiObj) throws IOException {
149                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] {  }, 
150                 new Class<?>[] {  });
151                 Object retObj = getMinFPS();
152                 rmiObj.sendReturnObj(retObj);
153         }
154
155         public void ___registerCallback(IoTRMIObject rmiObj) {
156                 Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
157                 new Class<?>[] { null });
158                 try {
159                         CameraSmartCallback stub0 = new CameraSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
160                         objIdCnt++;
161                         registerCallback(stub0);
162                 } catch(Exception ex) {
163                         ex.printStackTrace();
164                         throw new Error("Exception from callback object instantiation!");
165                 }
166         }
167
168         public void invokeMethod(IoTRMIObject rmiObj) throws IOException {
169                 int methodId = rmiObj.getMethodId();
170                 switch (methodId) {
171                         case 0: ___init(rmiObj); break;
172                         case 1: ___start(rmiObj); break;
173                         case 2: ___stop(rmiObj); break;
174                         case 3: ___getLatestFrame(rmiObj); break;
175                         case 4: ___getTimestamp(rmiObj); break;
176                         case 5: ___getSupportedResolutions(rmiObj); break;
177                         case 6: ___setResolution(rmiObj); break;
178                         case 7: ___setFPS(rmiObj); break;
179                         case 8: ___getMaxFPS(rmiObj); break;
180                         case 9: ___getMinFPS(rmiObj); break;
181                         case 10: ___registerCallback(rmiObj); break;
182                         case -9998: ___regCB(rmiObj); break;
183                         default: 
184                         throw new Error("Method Id " + methodId + " not recognized!");
185                 }
186         }
187
188 }