X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iot2.git;a=blobdiff_plain;f=benchmarks%2FJava%2FSpeakerController%2FSpeakerSmart_Stub.java;fp=benchmarks%2FJava%2FSpeakerController%2FSpeakerSmart_Stub.java;h=71147e695d44408e2a510e0a9b9d69622ef99255;hp=0000000000000000000000000000000000000000;hb=7a119d4b8c8f39801afb6a2de46682715cedf289;hpb=9056ba9d1b09be0fe455e7a68e9bf6a9ce5cf88d diff --git a/benchmarks/Java/SpeakerController/SpeakerSmart_Stub.java b/benchmarks/Java/SpeakerController/SpeakerSmart_Stub.java new file mode 100644 index 0000000..71147e6 --- /dev/null +++ b/benchmarks/Java/SpeakerController/SpeakerSmart_Stub.java @@ -0,0 +1,174 @@ +package SpeakerController; + +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 SpeakerSmart_Stub implements SpeakerSmart { + + private IoTRMICall rmiCall; + private String callbackAddress; + private int[] ports; + + private final static int objectId = 0; + // Callback properties + private IoTRMIObject rmiObj; + List listCallbackObj; + private int objIdCnt = 0; + private final static int object0Id = 0; //SpeakerSmartCallback + private static Integer[] object0Permission = { 0 }; + private static List set0Allowed; + + + public SpeakerSmart_Stub(int _port, String _skeletonAddress, String _callbackAddress, int _rev, int[] _ports) throws Exception { + callbackAddress = _callbackAddress; + ports = _ports; + rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev); + set0Allowed = new ArrayList(Arrays.asList(object0Permission)); + listCallbackObj = new ArrayList(); + set0Allowed.add(-9999); + ___initCallBack(); + } + + public int getPosition() { + int methodId = 6; + Class retType = int.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); + return (int)retObj; + } + + public boolean stopPlayback() { + int methodId = 2; + Class retType = boolean.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); + return (boolean)retObj; + } + + public void clearData() { + int methodId = 9; + Class retType = void.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); + } + + public boolean startPlayback() { + int methodId = 1; + Class retType = boolean.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); + return (boolean)retObj; + } + + public boolean getPlaybackState() { + int methodId = 3; + Class retType = boolean.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); + return (boolean)retObj; + } + + public boolean setVolume(float _percent) { + int methodId = 4; + Class retType = boolean.class; + Class[] paramCls = new Class[] { float.class }; + Object[] paramObj = new Object[] { _percent }; + Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); + return (boolean)retObj; + } + + public float getVolume() { + int methodId = 5; + Class retType = float.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + Object retObj = rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); + return (float)retObj; + } + + public void setPosition(int _mSec) { + int methodId = 7; + Class retType = void.class; + Class[] paramCls = new Class[] { int.class }; + Object[] paramObj = new Object[] { _mSec }; + rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); + } + + public void loadData(short _samples[], int _offs, int _len) { + int methodId = 8; + Class retType = void.class; + Class[] paramCls = new Class[] { short[].class, int.class, int.class }; + Object[] paramObj = new Object[] { _samples, _offs, _len }; + rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); + } + + public void init() { + int methodId = 0; + Class retType = void.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); + } + + public void registerCallback(SpeakerCallback _cb) { + try { + SpeakerCallback_CallbackSkeleton skel0 = new SpeakerCallback_CallbackSkeleton(_cb, callbackAddress, objIdCnt++); + listCallbackObj.add(skel0); + } catch (Exception ex) { + ex.printStackTrace(); + throw new Error("Exception when generating skeleton objects!"); + } + + int methodId = 10; + Class retType = void.class; + Class[] paramCls = new Class[] { int.class }; + Object[] paramObj = new Object[] { new Integer(1) }; + rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); + } + + public void ___initCallBack() { + Thread thread = new Thread() { + public void run() { + try { + rmiObj = new IoTRMIObject(ports[0]); + while (true) { + byte[] method = rmiObj.getMethodBytes(); + int objId = IoTRMIObject.getObjectId(method); + SpeakerCallback_CallbackSkeleton skel = (SpeakerCallback_CallbackSkeleton) listCallbackObj.get(objId); + if (skel != null) { + int methodId = IoTRMIObject.getMethodId(method); + if (!set0Allowed.contains(methodId)) { + throw new Error("Callback object for SpeakerCallback is not allowed to access method: " + methodId); + } + skel.invokeMethod(rmiObj); + } else { + throw new Error("SpeakerCallback: Object with Id " + objId + " not found!"); + } + } + } catch (Exception ex) { + ex.printStackTrace(); + throw new Error("Error instantiating class SpeakerCallback_CallbackSkeleton!"); + } + } + }; + thread.start(); + + int methodId = -9998; + Class retType = void.class; + Class[] paramCls = new Class[] { int[].class, String.class, int.class }; + Object[] paramObj = new Object[] { ports, callbackAddress, 0 }; + rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); + } + +}