import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
-import iotrmi.Java.IoTRMICall;
-import iotrmi.Java.IoTRMIObject;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import iotrmi.Java.IoTRMIComm;
+import iotrmi.Java.IoTRMICommClient;
+import iotrmi.Java.IoTRMICommServer;
+import iotrmi.Java.IoTRMIUtil;
import iotcode.interfaces.LightBulb;
public class LightBulb_Skeleton implements LightBulb {
private LightBulb mainObj;
- private IoTRMIObject rmiObj;
-
- private String callbackAddress;
+ private int objectId = 0;
+ // Communications and synchronizations
+ private IoTRMIComm rmiComm;
+ private AtomicBoolean didAlreadyInitWaitInvoke;
+ private AtomicBoolean methodReceived;
+ private byte[] methodBytes = null;
+ // Permissions
private final static int object0Id = 0; //LightBulbSmart
private static Integer[] object0Permission = { 2, 10, 1, 3, 11, 8, 12, 7, 13, 9, 6, 16, 17, 4, 0, 14, 15, 5 };
private static List<Integer> set0Allowed;
- public LightBulb_Skeleton(LightBulb _mainObj, String _callbackAddress, int _port) throws Exception {
+ public LightBulb_Skeleton(LightBulb _mainObj, int _portSend, int _portRecv) throws Exception {
mainObj = _mainObj;
- callbackAddress = _callbackAddress;
- rmiObj = new IoTRMIObject(_port);
+ rmiComm = new IoTRMICommServer(_portSend, _portRecv);
set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
- ___waitRequestInvokeMethod();
+ IoTRMIUtil.mapSkel.put(_mainObj, this);
+ IoTRMIUtil.mapSkelId.put(_mainObj, objectId);
+ didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+ methodReceived = new AtomicBoolean(false);
+ rmiComm.registerSkeleton(objectId, methodReceived);
+ Thread thread1 = new Thread() {
+ public void run() {
+ try {
+ ___waitRequestInvokeMethod();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ };
+ thread1.start();
+ }
+
+ public LightBulb_Skeleton(LightBulb _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception {
+ mainObj = _mainObj;
+ rmiComm = _rmiComm;
+ objectId = _objectId;
+ set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+ didAlreadyInitWaitInvoke = new AtomicBoolean(false);
+ methodReceived = new AtomicBoolean(false);
+ rmiComm.registerSkeleton(objectId, methodReceived);
+ }
+
+ public boolean didAlreadyInitWaitInvoke() {
+ return didAlreadyInitWaitInvoke.get();
}
public void init() {
}
public void ___init() {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
init();
}
public void ___turnOff() {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
turnOff();
}
public void ___turnOn() {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
turnOn();
}
public void ___getState() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getState();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___setColor() {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { double.class, double.class, double.class },
- new Class<?>[] { null, null, null });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { double.class, double.class, double.class }, new Class<?>[] { null, null, null }, localMethodBytes);
setColor((double) paramObj[0], (double) paramObj[1], (double) paramObj[2]);
}
public void ___setTemperature() {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
- new Class<?>[] { null });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { int.class }, new Class<?>[] { null }, localMethodBytes);
setTemperature((int) paramObj[0]);
}
public void ___getBrightness() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getBrightness();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getHue() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getHue();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getSaturation() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getSaturation();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getTemperature() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getTemperature();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getBrightnessRangeLowerBound() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getBrightnessRangeLowerBound();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getBrightnessRangeUpperBound() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getBrightnessRangeUpperBound();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getHueRangeLowerBound() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getHueRangeLowerBound();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getHueRangeUpperBound() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getHueRangeUpperBound();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getSaturationRangeLowerBound() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getSaturationRangeLowerBound();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getSaturationRangeUpperBound() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getSaturationRangeUpperBound();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getTemperatureRangeLowerBound() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getTemperatureRangeLowerBound();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
public void ___getTemperatureRangeUpperBound() throws IOException {
- Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
- new Class<?>[] { });
+ byte[] localMethodBytes = methodBytes;
+ rmiComm.setGetMethodBytes();
+ Object[] paramObj = rmiComm.getMethodParams(new Class<?>[] { }, new Class<?>[] { }, localMethodBytes);
Object retObj = getTemperatureRangeUpperBound();
- rmiObj.sendReturnObj(retObj);
+ rmiComm.sendReturnObj(retObj, localMethodBytes);
}
- private void ___waitRequestInvokeMethod() throws IOException {
+ public void ___waitRequestInvokeMethod() throws IOException {
+ didAlreadyInitWaitInvoke.compareAndSet(false, true);
while (true) {
- rmiObj.getMethodBytes();
- int _objectId = rmiObj.getObjectId();
- int methodId = rmiObj.getMethodId();
- if (_objectId == object0Id) {
+ if (!methodReceived.get()) {
+ continue;
+ }
+ methodBytes = rmiComm.getMethodBytes();
+ methodReceived.set(false);
+ int _objectId = IoTRMIComm.getObjectId(methodBytes);
+ int methodId = IoTRMIComm.getMethodId(methodBytes);
+ if (_objectId == objectId) {
if (!set0Allowed.contains(methodId)) {
throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId);
}
}
else {
- throw new Error("Object Id: " + _objectId + " not recognized!");
+ continue;
}
switch (methodId) {
- case 0: ___init(); break;
- case 1: ___turnOff(); break;
- case 2: ___turnOn(); break;
- case 3: ___getState(); break;
- case 4: ___setColor(); break;
- case 5: ___setTemperature(); break;
- case 6: ___getBrightness(); break;
- case 7: ___getHue(); break;
- case 8: ___getSaturation(); break;
- case 9: ___getTemperature(); break;
- case 10: ___getBrightnessRangeLowerBound(); break;
- case 11: ___getBrightnessRangeUpperBound(); break;
- case 12: ___getHueRangeLowerBound(); break;
- case 13: ___getHueRangeUpperBound(); break;
- case 14: ___getSaturationRangeLowerBound(); break;
- case 15: ___getSaturationRangeUpperBound(); break;
- case 16: ___getTemperatureRangeLowerBound(); break;
- case 17: ___getTemperatureRangeUpperBound(); break;
+ case 0:
+ new Thread() {
+ public void run() {
+ try {
+ ___init();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 1:
+ new Thread() {
+ public void run() {
+ try {
+ ___turnOff();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 2:
+ new Thread() {
+ public void run() {
+ try {
+ ___turnOn();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 3:
+ new Thread() {
+ public void run() {
+ try {
+ ___getState();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 4:
+ new Thread() {
+ public void run() {
+ try {
+ ___setColor();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 5:
+ new Thread() {
+ public void run() {
+ try {
+ ___setTemperature();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 6:
+ new Thread() {
+ public void run() {
+ try {
+ ___getBrightness();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 7:
+ new Thread() {
+ public void run() {
+ try {
+ ___getHue();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 8:
+ new Thread() {
+ public void run() {
+ try {
+ ___getSaturation();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 9:
+ new Thread() {
+ public void run() {
+ try {
+ ___getTemperature();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 10:
+ new Thread() {
+ public void run() {
+ try {
+ ___getBrightnessRangeLowerBound();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 11:
+ new Thread() {
+ public void run() {
+ try {
+ ___getBrightnessRangeUpperBound();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 12:
+ new Thread() {
+ public void run() {
+ try {
+ ___getHueRangeLowerBound();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 13:
+ new Thread() {
+ public void run() {
+ try {
+ ___getHueRangeUpperBound();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 14:
+ new Thread() {
+ public void run() {
+ try {
+ ___getSaturationRangeLowerBound();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 15:
+ new Thread() {
+ public void run() {
+ try {
+ ___getSaturationRangeUpperBound();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 16:
+ new Thread() {
+ public void run() {
+ try {
+ ___getTemperatureRangeLowerBound();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
+ case 17:
+ new Thread() {
+ public void run() {
+ try {
+ ___getTemperatureRangeUpperBound();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }.start();
+ break;
default:
throw new Error("Method Id " + methodId + " not recognized!");
}