Fixing minor bugs for callback-in-callback placeholders
authorrtrimana <rtrimana@uci.edu>
Wed, 16 Nov 2016 17:17:09 +0000 (09:17 -0800)
committerrtrimana <rtrimana@uci.edu>
Wed, 16 Nov 2016 17:17:09 +0000 (09:17 -0800)
iotjava/iotpolicy/IoTCompiler.java

index 9c6a16aad378302e185fecc20240f6fa0d3d8039..7681ff53d68f8683369e1e35798a8b7e0ff2f87d 100644 (file)
@@ -674,6 +674,8 @@ public class IoTCompiler {
        private void writePropertiesJavaCallbackStub(String intface, String newIntface, boolean callbackExist, Set<String> 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<String> 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<String> methods, InterfaceDecl intDecl, Set<String> callbackClasses) {
+       private void writeMethodJavaSkeleton(Collection<String> methods, InterfaceDecl intDecl, Set<String> 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