}
- public void handleStruct(StructJ[] data) {
+ public StructJ[] handleStruct(StructJ[] data) {
- tc.handleStruct(data);
+ return tc.handleStruct(data);
}
}
- public void ___handleStruct(int structsize1) {
+ public void ___handleStruct(int structsize1) throws IOException {
Class<?>[] paramCls = new Class<?>[3*structsize1];
Class<?>[] paramClsVal = new Class<?>[3*structsize1];
data[i].value = (float) paramObj[pos++];
data[i].year = (int) paramObj[pos++];
}
- tc.handleStruct(data);
+ // Just the following if there is no returned value
+ //tc.handleStruct(data);
+ StructJ[] retStruct = tc.handleStruct(data);
+ // Return length first
+ int structsize2 = retStruct.length;
+ Object retObj = structsize2;
+ rmiObj.sendReturnObj(retObj);
+ // Send the actual struct members
+ // Calculate the size of the array
+ Class<?>[] retCls = new Class<?>[3*structsize2];
+ Object[] retObj2 = new Object[3*structsize2];
+ // Handle with for loop
+ pos = 0;
+ for(int i = 0; i < structsize2; i++) {
+ retCls[pos] = String.class;
+ retObj2[pos++] = data[i].name;
+ retCls[pos] = float.class;
+ retObj2[pos++] = data[i].value;
+ retCls[pos] = int.class;
+ retObj2[pos++] = data[i].year;
+ }
+ rmiObj.sendReturnObj(retCls, retObj2);
}
TestClass tc = new TestClass(3, 5f, "7911");
TestClass_Skeleton tcSkel = new TestClass_Skeleton(tc, port);
-/* String[] methodSignatures = TestClass_CBSkeleton.getMethodSignatures();
- IoTRMIObject rmiObj = new IoTRMIObject(port, methodSignatures);
- Map<Integer,TestClassInterface> mapCBObject = new HashMap<Integer,TestClassInterface>();
-
- // Can replace for-loop with while-loop if necessary
- for (int i = 1; i < 3; i++) {
- TestClassInterface tcSkel = new TestClass_CBSkeleton(tc, i);
- mapCBObject.put(i, tcSkel);
- }
-
- Object retObj = null;
- while (true) {
- byte[] method = rmiObj.getMethodBytes();
- int objId = IoTRMIObject.getObjectId(method);
- TestClass_CBSkeleton tcSkel = (TestClass_CBSkeleton) mapCBObject.get(objId);
- if (tcSkel != null) {
- rmiObj.setMethodBytes(method);
- retObj = tcSkel.invokeMethod(rmiObj);
- }
- if (retObj != null) {
- rmiObj.sendReturnObj(retObj);
- }
- }
-*/
- //int objectId = 1;
- //System.out.println("Creating 0 object");
- //TestClass_Skeleton tcSkel1 = new TestClass_Skeleton(tc, rmiObj, objectId);
- //System.out.println("Creating 1 object");
- //objectId = 2;
- //TestClass_Skeleton tcSkel2 = new TestClass_Skeleton(tc, rmiObj, objectId);
- //System.out.println("Creating 2 object");
-
- /*for (int i = 1; i < 3; i++) {
- final int objectId = i;
- Thread thread = new Thread() {
- public void run() {
- try{
- TestClass_Skeleton tcSkel = new TestClass_Skeleton(tc, rmiObj, objectId);
- } catch (Exception ex){
- ex.printStackTrace();
- throw new Error("Error instantiating class CallBack_Skeleton!");
- }
- }
- };
- thread.start();
- }*/
}
}