--- /dev/null
+package iotcode.GPSPhoneGateway;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+import iotrmi.Java.IoTRMICall;
+import iotrmi.Java.IoTRMIObject;
+
+import iotcode.interfaces.*;
+
+public class GPSGatewaySmartCallback_CallbackStub implements GPSGatewaySmartCallback {
+
+ private IoTRMICall rmiCall;
+ private String callbackAddress;
+ private int[] ports;
+
+ private int objectId = 0;
+
+
+ public GPSGatewaySmartCallback_CallbackStub(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {
+ callbackAddress = _callbackAddress;
+ objectId = _objectId;
+ rmiCall = _rmiCall;
+ ports = _ports;
+ }
+
+ public void newRoomIDRetrieved(int _roomIdentifier) {
+ int methodId = 0;
+ Class<?> retType = void.class;
+ Class<?>[] paramCls = new Class<?>[] { int.class };
+ Object[] paramObj = new Object[] { _roomIdentifier };
+ rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+ }
+
+ public void newRingStatusRetrieved(boolean _ringStatus) {
+ int methodId = 1;
+ Class<?> retType = void.class;
+ Class<?>[] paramCls = new Class<?>[] { boolean.class };
+ Object[] paramObj = new Object[] { _ringStatus };
+ rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+ }
+
+}
--- /dev/null
+package iotcode.GPSPhoneGateway;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+import iotrmi.Java.IoTRMICall;
+import iotrmi.Java.IoTRMIObject;
+
+import iotcode.interfaces.*;
+
+public class GPSGateway_Skeleton implements GPSGateway {
+
+ private GPSGateway mainObj;
+ private IoTRMIObject rmiObj;
+
+ private String callbackAddress;
+ private int objIdCnt = 0;
+ private IoTRMICall rmiCall;
+ private int[] ports;
+
+ private final static int object0Id = 0; //GPSGatewaySmart
+ private static Integer[] object0Permission = { 5, 6, 2, 1, 0, 3, 7, 4 };
+ private static List<Integer> set0Allowed;
+
+
+ public GPSGateway_Skeleton(GPSGateway _mainObj, String _callbackAddress, int _port) throws Exception {
+ mainObj = _mainObj;
+ callbackAddress = _callbackAddress;
+ rmiObj = new IoTRMIObject(_port);
+ set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+ set0Allowed.add(-9998);
+ ___waitRequestInvokeMethod();
+ }
+
+ public void init() {
+ mainObj.init();
+ }
+
+ public void start() {
+ mainObj.start();
+ }
+
+ public void stop() {
+ mainObj.stop();
+ }
+
+ public int getRoomID() {
+ return mainObj.getRoomID();
+ }
+
+ public boolean getRingStatus() {
+ return mainObj.getRingStatus();
+ }
+
+ public void setNewRoomIDAvailable(boolean bValue) {
+ mainObj.setNewRoomIDAvailable(bValue);
+ }
+
+ public void setNewRingStatusAvailable(boolean bValue) {
+ mainObj.setNewRingStatusAvailable(bValue);
+ }
+
+ public void registerCallback(GPSGatewaySmartCallback _callbackTo) {
+ mainObj.registerCallback(_callbackTo);
+ }
+
+ public void ___regCB() throws IOException {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class, String.class, int.class },new Class<?>[] { null, null, null });
+ ports = (int[]) paramObj[0];
+ rmiCall = new IoTRMICall(ports[0], (String) paramObj[1], (int) paramObj[2]);
+ }
+
+ public void ___init() {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
+ new Class<?>[] { });
+ init();
+ }
+
+ public void ___start() {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
+ new Class<?>[] { });
+ start();
+ }
+
+ public void ___stop() {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
+ new Class<?>[] { });
+ stop();
+ }
+
+ public void ___getRoomID() throws IOException {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
+ new Class<?>[] { });
+ Object retObj = getRoomID();
+ rmiObj.sendReturnObj(retObj);
+ }
+
+ public void ___getRingStatus() throws IOException {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
+ new Class<?>[] { });
+ Object retObj = getRingStatus();
+ rmiObj.sendReturnObj(retObj);
+ }
+
+ public void ___setNewRoomIDAvailable() {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { boolean.class },
+ new Class<?>[] { null });
+ setNewRoomIDAvailable((boolean) paramObj[0]);
+ }
+
+ public void ___setNewRingStatusAvailable() {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { boolean.class },
+ new Class<?>[] { null });
+ setNewRingStatusAvailable((boolean) paramObj[0]);
+ }
+
+ public void ___registerCallback() {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
+ new Class<?>[] { null });
+ try {
+ GPSGatewaySmartCallback stub0 = new GPSGatewaySmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
+ objIdCnt++;
+ registerCallback(stub0);
+ } catch(Exception ex) {
+ ex.printStackTrace();
+ throw new Error("Exception from callback object instantiation!");
+ }
+ }
+
+ private void ___waitRequestInvokeMethod() throws IOException {
+ while (true) {
+ rmiObj.getMethodBytes();
+ int _objectId = rmiObj.getObjectId();
+ int methodId = rmiObj.getMethodId();
+ if (_objectId == object0Id) {
+ 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!");
+ }
+ switch (methodId) {
+ case 0: ___init(); break;
+ case 1: ___start(); break;
+ case 2: ___stop(); break;
+ case 3: ___getRoomID(); break;
+ case 4: ___getRingStatus(); break;
+ case 5: ___setNewRoomIDAvailable(); break;
+ case 6: ___setNewRingStatusAvailable(); break;
+ case 7: ___registerCallback(); break;
+ case -9998: ___regCB(); break;
+ default:
+ throw new Error("Method Id " + methodId + " not recognized!");
+ }
+ }
+ }
+
+}
--- /dev/null
+package iotcode.IHome;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+import iotrmi.Java.IoTRMICall;
+import iotrmi.Java.IoTRMIObject;
+
+import iotcode.interfaces.*;
+
+public class SpeakerSmartCallback_CallbackStub implements SpeakerSmartCallback {
+
+ private IoTRMICall rmiCall;
+ private String callbackAddress;
+ private int[] ports;
+
+ private int objectId = 0;
+
+
+ public SpeakerSmartCallback_CallbackStub(IoTRMICall _rmiCall, String _callbackAddress, int _objectId, int[] _ports) throws Exception {
+ callbackAddress = _callbackAddress;
+ objectId = _objectId;
+ rmiCall = _rmiCall;
+ ports = _ports;
+ }
+
+ public void speakerDone() {
+ int methodId = 0;
+ Class<?> retType = void.class;
+ Class<?>[] paramCls = new Class<?>[] { };
+ Object[] paramObj = new Object[] { };
+ rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
+ }
+
+}
--- /dev/null
+package iotcode.IHome;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+import iotrmi.Java.IoTRMICall;
+import iotrmi.Java.IoTRMIObject;
+
+import iotcode.interfaces.*;
+
+public class Speaker_Skeleton implements Speaker {
+
+ private Speaker mainObj;
+ private IoTRMIObject rmiObj;
+
+ private String callbackAddress;
+ private int objIdCnt = 0;
+ private IoTRMICall rmiCall;
+ private int[] ports;
+
+ private final static int object0Id = 0; //SpeakerSmart
+ private static Integer[] object0Permission = { 6, 2, 9, 1, 3, 4, 5, 7, 8, 0, 10 };
+ private static List<Integer> set0Allowed;
+
+
+ public Speaker_Skeleton(Speaker _mainObj, String _callbackAddress, int _port) throws Exception {
+ mainObj = _mainObj;
+ callbackAddress = _callbackAddress;
+ rmiObj = new IoTRMIObject(_port);
+ set0Allowed = new ArrayList<Integer>(Arrays.asList(object0Permission));
+ set0Allowed.add(-9998);
+ ___waitRequestInvokeMethod();
+ }
+
+ public void init() {
+ mainObj.init();
+ }
+
+ public boolean startPlayback() {
+ return mainObj.startPlayback();
+ }
+
+ public boolean stopPlayback() {
+ return mainObj.stopPlayback();
+ }
+
+ public boolean getPlaybackState() {
+ return mainObj.getPlaybackState();
+ }
+
+ public boolean setVolume(float _percent) {
+ return mainObj.setVolume(_percent);
+ }
+
+ public float getVolume() {
+ return mainObj.getVolume();
+ }
+
+ public int getPosition() {
+ return mainObj.getPosition();
+ }
+
+ public void setPosition(int _mSec) {
+ mainObj.setPosition(_mSec);
+ }
+
+ public void loadData(short _samples[], int _offs, int _len) {
+ mainObj.loadData(_samples, _offs, _len);
+ }
+
+ public void clearData() {
+ mainObj.clearData();
+ }
+
+ public void registerCallback(SpeakerSmartCallback _cb) {
+ mainObj.registerCallback(_cb);
+ }
+
+ public void ___regCB() throws IOException {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int[].class, String.class, int.class },new Class<?>[] { null, null, null });
+ ports = (int[]) paramObj[0];
+ rmiCall = new IoTRMICall(ports[0], (String) paramObj[1], (int) paramObj[2]);
+ }
+
+ public void ___init() {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
+ new Class<?>[] { });
+ init();
+ }
+
+ public void ___startPlayback() throws IOException {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
+ new Class<?>[] { });
+ Object retObj = startPlayback();
+ rmiObj.sendReturnObj(retObj);
+ }
+
+ public void ___stopPlayback() throws IOException {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
+ new Class<?>[] { });
+ Object retObj = stopPlayback();
+ rmiObj.sendReturnObj(retObj);
+ }
+
+ public void ___getPlaybackState() throws IOException {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
+ new Class<?>[] { });
+ Object retObj = getPlaybackState();
+ rmiObj.sendReturnObj(retObj);
+ }
+
+ public void ___setVolume() throws IOException {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { float.class },
+ new Class<?>[] { null });
+ Object retObj = setVolume((float) paramObj[0]);
+ rmiObj.sendReturnObj(retObj);
+ }
+
+ public void ___getVolume() throws IOException {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
+ new Class<?>[] { });
+ Object retObj = getVolume();
+ rmiObj.sendReturnObj(retObj);
+ }
+
+ public void ___getPosition() throws IOException {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
+ new Class<?>[] { });
+ Object retObj = getPosition();
+ rmiObj.sendReturnObj(retObj);
+ }
+
+ public void ___setPosition() {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
+ new Class<?>[] { null });
+ setPosition((int) paramObj[0]);
+ }
+
+ public void ___loadData() {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { short[].class, int.class, int.class },
+ new Class<?>[] { null, null, null });
+ loadData((short[]) paramObj[0], (int) paramObj[1], (int) paramObj[2]);
+ }
+
+ public void ___clearData() {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { },
+ new Class<?>[] { });
+ clearData();
+ }
+
+ public void ___registerCallback() {
+ Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
+ new Class<?>[] { null });
+ try {
+ SpeakerSmartCallback stub0 = new SpeakerSmartCallback_CallbackStub(rmiCall, callbackAddress, objIdCnt, ports);
+ objIdCnt++;
+ registerCallback(stub0);
+ } catch(Exception ex) {
+ ex.printStackTrace();
+ throw new Error("Exception from callback object instantiation!");
+ }
+ }
+
+ private void ___waitRequestInvokeMethod() throws IOException {
+ while (true) {
+ rmiObj.getMethodBytes();
+ int _objectId = rmiObj.getObjectId();
+ int methodId = rmiObj.getMethodId();
+ if (_objectId == object0Id) {
+ 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!");
+ }
+ switch (methodId) {
+ case 0: ___init(); break;
+ case 1: ___startPlayback(); break;
+ case 2: ___stopPlayback(); break;
+ case 3: ___getPlaybackState(); break;
+ case 4: ___setVolume(); break;
+ case 5: ___getVolume(); break;
+ case 6: ___getPosition(); break;
+ case 7: ___setPosition(); break;
+ case 8: ___loadData(); break;
+ case 9: ___clearData(); break;
+ case 10: ___registerCallback(); break;
+ case -9998: ___regCB(); break;
+ default:
+ throw new Error("Method Id " + methodId + " not recognized!");
+ }
+ }
+ }
+
+}
/**
* Class Constant
*/
- protected static int BUFFSIZE = 128000; // how many bytes our incoming buffer can hold
+ //protected static int BUFFSIZE = 128000; // how many bytes our incoming buffer can hold (original)
+ protected static int BUFFSIZE = 8388608; // 8388608 = 2^23 bytes of memory (8MB) - this is required by our IHome speaker driver
protected static int MSG_LEN_SIZE = 4; // send length in the size of integer (4 bytes)
/**
input.read(lenBytes, 0, MSG_LEN_SIZE);
int maxlen = ByteBuffer.wrap(lenBytes).getInt();
// Receive until maxlen
- if (maxlen>BUFFSIZE)
- System.out.println("IoTSocketClient/Server: Sending more bytes then will fit in buffer!");
+ if (maxlen>BUFFSIZE) {
+ System.out.println("IoTSocketClient/Server: Sending more bytes then will fit in buffer! Number of bytes: " + maxlen);
+ }
val = new byte[maxlen];
while (totalbytes < maxlen)
{