Adjusting back into the original lengthy version of IrrigationController; for testing...
[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 java.util.Map;
8 import java.util.HashMap;
9 import java.util.concurrent.atomic.AtomicBoolean;
10 import iotrmi.Java.IoTRMIComm;
11 import iotrmi.Java.IoTRMICommClient;
12 import iotrmi.Java.IoTRMICommServer;
13 import iotrmi.Java.IoTRMIUtil;
14
15 import iotcode.interfaces.*;
16
17 public class GPSGatewaySmart_Stub implements GPSGatewaySmart {
18
19         private int objectId = 3;
20         private IoTRMIComm rmiComm;
21         // Synchronization variables
22         private AtomicBoolean retValueReceived3 = new AtomicBoolean(false);
23         private AtomicBoolean retValueReceived4 = new AtomicBoolean(false);
24         
25
26         public GPSGatewaySmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception {
27                 if (_localPortSend != 0 && _localPortRecv != 0) {
28                         rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev);
29                 } else
30                 {
31                         rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev);
32                 }
33                 rmiComm.registerStub(objectId, 3, retValueReceived3);
34                 rmiComm.registerStub(objectId, 4, retValueReceived4);
35                 IoTRMIUtil.mapStub.put(objectId, this);
36         }
37
38         public GPSGatewaySmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception {
39                 rmiComm = _rmiComm;
40                 objectId = _objectId;
41                 rmiComm.registerStub(objectId, 3, retValueReceived3);
42                 rmiComm.registerStub(objectId, 4, retValueReceived4);
43         }
44
45         public void setNewRoomIDAvailable(boolean bValue) {
46                 int methodId = 5;
47                 Class<?> retType = void.class;
48                 Class<?>[] paramCls = new Class<?>[] { boolean.class };
49                 Object[] paramObj = new Object[] { bValue };
50                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
51         }
52
53         public void setNewRingStatusAvailable(boolean bValue) {
54                 int methodId = 6;
55                 Class<?> retType = void.class;
56                 Class<?>[] paramCls = new Class<?>[] { boolean.class };
57                 Object[] paramObj = new Object[] { bValue };
58                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
59         }
60
61         public void stop() {
62                 int methodId = 2;
63                 Class<?> retType = void.class;
64                 Class<?>[] paramCls = new Class<?>[] {  };
65                 Object[] paramObj = new Object[] {  };
66                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
67         }
68
69         public void start() {
70                 int methodId = 1;
71                 Class<?> retType = void.class;
72                 Class<?>[] paramCls = new Class<?>[] {  };
73                 Object[] paramObj = new Object[] {  };
74                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
75         }
76
77         public void init() {
78                 int methodId = 0;
79                 Class<?> retType = void.class;
80                 Class<?>[] paramCls = new Class<?>[] {  };
81                 Object[] paramObj = new Object[] {  };
82                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
83         }
84
85         public int getRoomID() {
86                 int methodId = 3;
87                 Class<?> retType = int.class;
88                 Class<?>[] paramCls = new Class<?>[] {  };
89                 Object[] paramObj = new Object[] {  };
90                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
91                 // Waiting for return value
92                 while (!retValueReceived3.get());
93                 Object retObj = rmiComm.getReturnValue(retType, null);
94                 retValueReceived3.set(false);
95                 rmiComm.setGetReturnBytes();
96
97                 return (int)retObj;
98         }
99
100         public void registerCallback(GPSGatewayCallback _callbackTo) {
101                 int[] objIdSent0 = new int[1];
102                 try {
103                         if (!IoTRMIUtil.mapSkel.containsKey(_callbackTo)) {
104                                 int newObjIdSent = rmiComm.getObjectIdCounter();
105                                 objIdSent0[0] = newObjIdSent;
106                                 rmiComm.decrementObjectIdCounter();
107                                 GPSGatewayCallback_Skeleton skel0 = new GPSGatewayCallback_Skeleton(_callbackTo, rmiComm, newObjIdSent);
108                                 IoTRMIUtil.mapSkel.put(_callbackTo, skel0);
109                                 IoTRMIUtil.mapSkelId.put(_callbackTo, newObjIdSent);
110                                 Thread thread = new Thread() {
111                                         public void run() {
112                                                 try {
113                                                         skel0.___waitRequestInvokeMethod();
114                                                         } catch (Exception ex) {
115                                                         ex.printStackTrace();
116                                                         throw new Error("Exception when trying to run ___waitRequestInvokeMethod() for GPSGatewayCallback_Skeleton!");
117                                                 }
118                                         }
119                                 };
120                                 thread.start();
121                                 while(!skel0.didAlreadyInitWaitInvoke());
122                         }
123                         else
124                         {
125                                 int newObjIdSent = IoTRMIUtil.mapSkelId.get(_callbackTo);
126                                 objIdSent0[0] = newObjIdSent;
127                         }
128                 } catch (Exception ex) {
129                         ex.printStackTrace();
130                         throw new Error("Exception when generating skeleton objects!");
131                 }
132
133                 int methodId = 7;
134                 Class<?> retType = void.class;
135                 Class<?>[] paramCls = new Class<?>[] { int[].class };
136                 Object[] paramObj = new Object[] { objIdSent0 };
137                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
138         }
139
140         public boolean getRingStatus() {
141                 int methodId = 4;
142                 Class<?> retType = boolean.class;
143                 Class<?>[] paramCls = new Class<?>[] {  };
144                 Object[] paramObj = new Object[] {  };
145                 rmiComm.remoteCall(objectId, methodId, paramCls, paramObj);
146                 // Waiting for return value
147                 while (!retValueReceived4.get());
148                 Object retObj = rmiComm.getReturnValue(retType, null);
149                 retValueReceived4.set(false);
150                 rmiComm.setGetReturnBytes();
151
152                 return (boolean)retObj;
153         }
154
155 }