From 117609a31aadb0eca91a6080447ba3819177b7a0 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Wed, 16 Nov 2016 09:17:09 -0800 Subject: [PATCH] Fixing minor bugs for callback-in-callback placeholders --- iotjava/iotpolicy/IoTCompiler.java | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java index 9c6a16a..7681ff5 100644 --- a/iotjava/iotpolicy/IoTCompiler.java +++ b/iotjava/iotpolicy/IoTCompiler.java @@ -674,6 +674,8 @@ public class IoTCompiler { private void writePropertiesJavaCallbackStub(String intface, String newIntface, boolean callbackExist, Set callbackClasses) { println("private IoTRMICall rmiCall;"); + println("private String address;"); + println("private int[] ports;\n"); // Get the object Id println("private static int objectId = 0;"); if (callbackExist) { @@ -694,6 +696,7 @@ public class IoTCompiler { */ private void writeConstructorJavaCallbackStub(String intface, boolean callbackExist, Set callbackClasses) { + // TODO: If we want callback in callback, then we need to add address and port initializations println("public " + intface + "(IoTRMICall _rmiCall, int _objectId) throws Exception {"); println("objectId = _objectId;"); println("rmiCall = _rmiCall;"); @@ -702,6 +705,7 @@ public class IoTCompiler { String callbackType = (String) it.next(); println("listCallbackObj = new ArrayList<" + callbackType + ">();"); println("___initCallBack();"); + println("// TODO: Add address and port initialization here if we want callback in callback!"); } println("}\n"); } @@ -819,9 +823,13 @@ public class IoTCompiler { /** * HELPER: writeInitCallbackJavaSkeleton() writes the init callback method for skeleton class */ - private void writeInitCallbackJavaSkeleton() { + private void writeInitCallbackJavaSkeleton(boolean callbackSkeleton) { - println("public void ___regCB() throws IOException {"); + // This is a callback skeleton generation + if (callbackSkeleton) + println("public void ___regCB(IoTRMIObject rmiObj) throws IOException {"); + else + println("public void ___regCB() throws IOException {"); println("Object[] paramObj = rmiObj.getMethodParams(new Class[] { int.class, String.class, int.class },"); println("\tnew Class[] { null, null, null });"); println("rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], (int) paramObj[2]);"); @@ -832,7 +840,8 @@ public class IoTCompiler { /** * HELPER: writeMethodJavaSkeleton() writes the method of the skeleton class */ - private void writeMethodJavaSkeleton(Collection methods, InterfaceDecl intDecl, Set callbackClasses) { + private void writeMethodJavaSkeleton(Collection methods, InterfaceDecl intDecl, Set callbackClasses, + boolean callbackSkeleton) { for (String method : methods) { @@ -863,7 +872,7 @@ public class IoTCompiler { writeStdMethodBodyJavaSkeleton(methParams, methodId, intDecl.getMethodType(method)); println("}\n"); if (isCallbackMethod) - writeInitCallbackJavaSkeleton(); + writeInitCallbackJavaSkeleton(callbackSkeleton); } } @@ -1093,7 +1102,7 @@ public class IoTCompiler { // Write constructor writeConstructorJavaSkeleton(newSkelClass, intface); // Write methods - writeMethodJavaSkeleton(methods, intDecl, callbackClasses); + writeMethodJavaSkeleton(methods, intDecl, callbackClasses, false); // Write method helper writeMethodHelperJavaSkeleton(methods, intDecl, callbackClasses); // Write waitRequestInvokeMethod() - main loop @@ -1193,7 +1202,7 @@ public class IoTCompiler { // Print case -9999 (callback handler) if callback exists if (callbackExist) { int methodId = intDecl.getHelperMethodNumId(method); - println("case " + methodId + ": ___regCB(); break;"); + println("case " + methodId + ": ___regCB(rmiObj); break;"); } println("default: "); println("throw new Error(\"Method Id \" + methodId + \" not recognized!\");"); @@ -1233,7 +1242,7 @@ public class IoTCompiler { // Write constructor writeConstructorJavaCallbackSkeleton(newSkelClass, intface); // Write methods - writeMethodJavaSkeleton(methods, intDecl, callbackClasses); + writeMethodJavaSkeleton(methods, intDecl, callbackClasses, true); // Write method helper writeMethodHelperJavaCallbackSkeleton(methods, intDecl, callbackClasses); // Write waitRequestInvokeMethod() - main loop -- 2.34.1