Fixing a bug in IoTMaster (wrong variable for language flag check); adding LANGUAGE...
[iot2.git] / benchmarks / Java / SpeakerController / GPSGatewaySmart_Stub.java
1 package SpeakerController;
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 GPSGatewaySmart_Stub implements GPSGatewaySmart {
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<GPSGatewayCallback> listCallbackObj;
22         private int objIdCnt = 0;
23         private final static int object0Id = 0; //GPSGatewaySmartCallback
24         private static Integer[] object0Permission = { 0, 1 };
25         private static List<Integer> set0Allowed;
26         
27
28         public GPSGatewaySmart_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<GPSGatewayCallback>();
34                 set0Allowed.add(-9999);
35                 ___initCallBack();
36         }
37
38         public void setNewRoomIDAvailable(boolean bValue) {
39                 int methodId = 5;
40                 Class<?> retType = void.class;
41                 Class<?>[] paramCls = new Class<?>[] { boolean.class };
42                 Object[] paramObj = new Object[] { bValue };
43                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
44         }
45
46         public void setNewRingStatusAvailable(boolean bValue) {
47                 int methodId = 6;
48                 Class<?> retType = void.class;
49                 Class<?>[] paramCls = new Class<?>[] { boolean.class };
50                 Object[] paramObj = new Object[] { bValue };
51                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
52         }
53
54         public void stop() {
55                 int methodId = 2;
56                 Class<?> retType = void.class;
57                 Class<?>[] paramCls = new Class<?>[] {  };
58                 Object[] paramObj = new Object[] {  };
59                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
60         }
61
62         public void start() {
63                 int methodId = 1;
64                 Class<?> retType = void.class;
65                 Class<?>[] paramCls = new Class<?>[] {  };
66                 Object[] paramObj = new Object[] {  };
67                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
68         }
69
70         public void init() {
71                 int methodId = 0;
72                 Class<?> retType = void.class;
73                 Class<?>[] paramCls = new Class<?>[] {  };
74                 Object[] paramObj = new Object[] {  };
75                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
76         }
77
78         public int getRoomID() {
79                 int methodId = 3;
80                 Class<?> retType = int.class;
81                 Class<?>[] paramCls = new Class<?>[] {  };
82                 Object[] paramObj = new Object[] {  };
83                 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
84                 return (int)retObj;
85         }
86
87         public void registerCallback(GPSGatewayCallback _callbackTo) {
88                 try {
89                         GPSGatewayCallback_CallbackSkeleton skel0 = new GPSGatewayCallback_CallbackSkeleton(_callbackTo, callbackAddress, objIdCnt++);
90                         listCallbackObj.add(skel0);
91                 } catch (Exception ex) {
92                         ex.printStackTrace();
93                         throw new Error("Exception when generating skeleton objects!");
94                 }
95
96                 int methodId = 7;
97                 Class<?> retType = void.class;
98                 Class<?>[] paramCls = new Class<?>[] { int.class };
99                 Object[] paramObj = new Object[] { new Integer(1) };
100                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
101         }
102
103         public void ___initCallBack() {
104                 Thread thread = new Thread() {
105                         public void run() {
106                                 try {
107                                         rmiObj = new IoTRMIObject(ports[0]);
108                                         while (true) {
109                                                 byte[] method = rmiObj.getMethodBytes();
110                                                 int objId = IoTRMIObject.getObjectId(method);
111                                                 GPSGatewayCallback_CallbackSkeleton skel = (GPSGatewayCallback_CallbackSkeleton) listCallbackObj.get(objId);
112                                                 if (skel != null) {
113                                                         int methodId = IoTRMIObject.getMethodId(method);
114                                                         if (!set0Allowed.contains(methodId)) {
115                                                                 throw new Error("Callback object for GPSGatewayCallback is not allowed to access method: " + methodId);
116                                                         }
117                                                         skel.invokeMethod(rmiObj);
118                                                 } else {
119                                                         throw new Error("GPSGatewayCallback: Object with Id " + objId + " not found!");
120                                                 }
121                                         }
122                                 } catch (Exception ex) {
123                                         ex.printStackTrace();
124                                         throw new Error("Error instantiating class GPSGatewayCallback_CallbackSkeleton!");
125                                 }
126                         }
127                 };
128                 thread.start();
129
130                 int methodId = -9998;
131                 Class<?> retType = void.class;
132                 Class<?>[] paramCls = new Class<?>[] { int[].class, String.class, int.class };
133                 Object[] paramObj = new Object[] { ports, callbackAddress, 0 };
134                 rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
135         }
136
137         public boolean getRingStatus() {
138                 int methodId = 4;
139                 Class<?> retType = boolean.class;
140                 Class<?>[] paramCls = new Class<?>[] {  };
141                 Object[] paramObj = new Object[] {  };
142                 Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
143                 return (boolean)retObj;
144         }
145
146 }