Adding new policy, Java, and Cpp files for testing/debugging
authorrtrimana <rtrimana@uci.edu>
Fri, 25 Nov 2016 22:06:36 +0000 (14:06 -0800)
committerrtrimana <rtrimana@uci.edu>
Fri, 25 Nov 2016 22:06:36 +0000 (14:06 -0800)
config/iotpolicy/testclasspolicy.pol [new file with mode: 0644]
config/iotpolicy/testclassrequires.pol [new file with mode: 0644]
iotjava/Makefile
iotjava/iotpolicy/IoTCompiler.java
iotjava/iotrmi/C++/basics/TestClass.hpp [new file with mode: 0644]
iotjava/iotrmi/C++/basics/TestClass_Skeleton.cpp [new file with mode: 0644]
iotjava/iotrmi/C++/basics/TestClass_Stub.cpp [new file with mode: 0644]
iotjava/iotrmi/Java/basics/TestClass.java [new file with mode: 0644]
iotjava/iotrmi/Java/basics/TestClass_Skeleton.java [new file with mode: 0644]
iotjava/iotrmi/Java/basics/TestClass_Stub.java [new file with mode: 0644]

diff --git a/config/iotpolicy/testclasspolicy.pol b/config/iotpolicy/testclasspolicy.pol
new file mode 100644 (file)
index 0000000..21eb09e
--- /dev/null
@@ -0,0 +1,32 @@
+public interface TestClassInterface {
+
+       public void setA(int _int);
+       public void setB(float _float);
+       public void setC(String _string);
+       public String sumArray(String newA[]);
+       public int setAndGetA(int newA);
+       public int setACAndGetA(String newC, int newA);
+
+       capability Setters {
+               description = "All the set methods";
+               method = "setA(int _int)";
+               method = "setB(float _float)";
+               method = "setC(String _string)";
+       }
+
+       capability SetAndGets {
+               description = "All the set-and-get methods";
+               method = "sumArray(String newA[])";
+               method = "setAndGetA(int newA)";
+               method = "setACAndGetA(String newC, int newA)";
+       }
+
+       struct StructJ {
+
+               string  name;
+               float   value;
+               int     year;
+       } 
+}
+
+
diff --git a/config/iotpolicy/testclassrequires.pol b/config/iotpolicy/testclassrequires.pol
new file mode 100644 (file)
index 0000000..713fb4e
--- /dev/null
@@ -0,0 +1,3 @@
+
+requires TestClassInterface with Setters, SetAndGets as interface TestClassComplete;
+
index d7f6a9d7fcf625920113a94e2285e6222b071676..ce06bedb31c24f10fe57587d801e408e4e7edeee 100644 (file)
@@ -20,7 +20,8 @@ compiler:
 
 PHONY += run-compiler
 run-compiler:
-       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler camerapolicy.pol camerarequires.pol lightbulbpolicy.pol lightbulbrequires.pol -cplus Cplus -java Java
+       #cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler camerapolicy.pol camerarequires.pol lightbulbpolicy.pol lightbulbrequires.pol -cplus Cplus -java Java
+       cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler testclasspolicy.pol testclassrequires.pol -cplus Cplus -java Java
 
 # Runtime system compilation
 PHONY += runtime
@@ -30,11 +31,34 @@ runtime:
 # TODO: Can remove this later - just to test-compile the resulted files from the compiler
 PHONY += compile
 compile:
+       cp ./iotrmi/Java/basics/* $(BIN_DIR)/iotpolicy/output_files/Java
+       cp ./iotrmi/C++/basics/* $(BIN_DIR)/iotpolicy/output_files/Cplus
        cd $(BIN_DIR)/iotpolicy/output_files; cp *.java ./Java
        cd $(BIN_DIR)/iotpolicy/output_files; cp *.hpp ./Cplus
-#      cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) *.java
+       cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) *.java
 #      cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./*.hpp --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
-       cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./Camera_Skeleton.hpp --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
+       cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./TestClass_Skeleton.cpp -o ./TestClass_Skeleton.out --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
+       cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./TestClass_Stub.cpp -o ./TestClass_Stub.out --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
+
+PHONY += run-java-skeleton
+run-java-skeleton:
+       cd ../bin/iotpolicy/output_files/Java; $(JAVA) -cp .:../../../$(BIN_DIR) TestClass_Skeleton
+
+PHONY += run-java-stub
+run-java-stub:
+       cd ../bin/iotpolicy/output_files/Java; $(JAVA) -cp .:../../../$(BIN_DIR) TestClass_Stub
+
+PHONY += run-cplus-skeleton
+run-cplus-skeleton:
+       ../bin/iotpolicy/output_files/Cplus/TestClass_Skeleton.out
+
+PHONY += run-cplus-stub
+run-cplus-stub:
+       ../bin/iotpolicy/output_files/Cplus/TestClass_Stub.out
+
+PHONY += folderclean
+folderclean:
+       rm -rf $(BIN_DIR)/iotpolicy/output_files
 
 PHONY += clean
 clean:
index 674c98c7559857708fe45212a7850b67a35e4e98..028373b77b8883a43f9b70ee16089ec01bfa7fd1 100644 (file)
@@ -1589,7 +1589,8 @@ public class IoTCompiler {
         * HELPER: writeMethodHelperReturnJavaSkeleton() writes return statement part in skeleton
         */
        private void writeMethodHelperReturnJavaSkeleton(InterfaceDecl intDecl, List<String> methParams,
-                       List<String> methPrmTypes, String method, boolean isCallbackMethod, String callbackType) {
+                       List<String> methPrmTypes, String method, boolean isCallbackMethod, String callbackType,
+                       boolean isStructMethod) {
 
                checkAndWriteEnumTypeJavaSkeleton(methParams, methPrmTypes);
                Map<Integer,String> mapStubParam = null;
@@ -1616,7 +1617,10 @@ public class IoTCompiler {
                                print("paramStruct" + i);
                        } else {
                                String prmType = checkAndGetArray(methPrmTypes.get(i), methParams.get(i));
-                               print("(" + prmType + ") paramObj[offset" + i + "]");
+                               if (isStructMethod)
+                                       print("(" + prmType + ") paramObj[offset" + i + "]");
+                               else
+                                       print("(" + prmType + ") paramObj[" + i + "]");
                        }
                        if (i != methParams.size() - 1)
                                print(", ");
@@ -1684,7 +1688,7 @@ public class IoTCompiler {
                println("Object[] paramObj = rmiObj.getMethodParams(paramCls, paramClsGen);");
                writeStructMembersInitJavaSkeleton(intDecl, methParams, methPrmTypes, method);
                // Write the return value part
-               writeMethodHelperReturnJavaSkeleton(intDecl, methParams, methPrmTypes, method, isCallbackMethod, callbackType);
+               writeMethodHelperReturnJavaSkeleton(intDecl, methParams, methPrmTypes, method, isCallbackMethod, callbackType, true);
        }
 
 
@@ -1726,7 +1730,7 @@ public class IoTCompiler {
                }
                println(" });");
                // Write the return value part
-               writeMethodHelperReturnJavaSkeleton(intDecl, methParams, methPrmTypes, method, isCallbackMethod, callbackType);
+               writeMethodHelperReturnJavaSkeleton(intDecl, methParams, methPrmTypes, method, isCallbackMethod, callbackType, false);
        }
 
 
@@ -1980,10 +1984,10 @@ public class IoTCompiler {
                        println("if (!set" + newObjectId + "Allowed.contains(methodId)) {");
                        println("throw new Error(\"Object with object Id: \" + _objectId + \"  is not allowed to access method: \" + methodId);");
                        println("}");
+                       println("}");
                        println("else {");
                        println("throw new Error(\"Object Id: \" + _objectId + \" not recognized!\");");
                        println("}");
-                       println("}");
                }
        }
 
@@ -3635,7 +3639,8 @@ public class IoTCompiler {
                                        println("vector<int> paramEnumInt" + i + ";");
                                } else {
                                        String methParamComplete = checkAndGetCplusArray(methPrmType, methParams.get(i));
-                                       println(methParamComplete + ";");
+                                       //println(methParamComplete + " = " + generateCplusInitializer(methPrmType) + ";");
+                    println(methParamComplete + ";");
                                }
                        }
                }
@@ -3991,11 +3996,11 @@ public class IoTCompiler {
                        println("cerr << \"Object with object Id: \" << _objectId << \"  is not allowed to access method: \" << methodId << endl;");
                        println("exit(-1);");
                        println("}");
+                       println("}");
                        println("else {");
                        println("cerr << \"Object Id: \" << _objectId << \" not recognized!\" << endl;");
                        println("exit(-1);");
                        println("}");
-                       println("}");
                }
        }
 
diff --git a/iotjava/iotrmi/C++/basics/TestClass.hpp b/iotjava/iotrmi/C++/basics/TestClass.hpp
new file mode 100644 (file)
index 0000000..91f7e5c
--- /dev/null
@@ -0,0 +1,92 @@
+#ifndef _TESTCLASS_HPP__
+#define _TESTCLASS_HPP__
+
+#include <iostream>
+#include <thread>
+#include <chrono>
+#include "TestClassInterface.hpp"
+
+using namespace std;
+
+class TestClass : public TestClassInterface {
+       public:
+               TestClass();
+               TestClass(int _int, float _float, string _string);
+
+               void                            setA(int _int);
+               void                            setB(float _float);
+               void                            setC(string _string);
+               string                          sumArray(vector<string> newA);
+               int                                     setAndGetA(int newA);
+               int                                     setACAndGetA(string newC, int newA);
+
+       private:                
+               int                                                     intA;
+               float                                           floatB;
+               string                                          stringC;
+};
+
+
+TestClass::TestClass() {
+
+       intA = 1;
+       floatB = 2;
+       stringC = "345";
+       // cbvec doesn't need to be initialized again
+}
+
+
+TestClass::TestClass(int _int, float _float, string _string) {
+
+       intA = _int;
+       floatB = _float;
+       stringC = _string;
+       // cbvec doesn't need to be initialized again
+}
+
+
+void TestClass::setA(int _int) {
+
+       intA = _int;
+}
+
+
+void TestClass::setB(float _float) {
+
+       floatB = _float;
+}
+
+
+void TestClass::setC(string _string) {
+
+       stringC = _string;
+}
+
+
+string TestClass::sumArray(vector<string> newA) {
+
+       string sum = "";
+       int len = newA.size();
+       for(int c = 0; c < len; c++) {
+               sum = sum + newA[c];
+       }
+       return sum;
+}
+
+
+int TestClass::setAndGetA(int newA) {
+
+       intA = newA;
+       return intA;
+}
+
+
+int TestClass::setACAndGetA(string newC, int newA) {
+
+       stringC = newC;
+       intA = newA;
+       return intA;
+}
+
+#endif
+
diff --git a/iotjava/iotrmi/C++/basics/TestClass_Skeleton.cpp b/iotjava/iotrmi/C++/basics/TestClass_Skeleton.cpp
new file mode 100644 (file)
index 0000000..cea5030
--- /dev/null
@@ -0,0 +1,20 @@
+#include <iostream>
+#include <string>
+#include "TestClassInterface_Skeleton.hpp"
+#include "TestClass.hpp"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+       TestClassInterface *tc;
+       TestClassInterface_Skeleton *tcSkel;
+
+       int port = 5010;
+       tc = new TestClass(3, 5.0, "7911");
+       tcSkel = new TestClassInterface_Skeleton(tc, port);
+
+       delete tc;
+       delete tcSkel;
+       return 0;
+}
diff --git a/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp b/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp
new file mode 100644 (file)
index 0000000..20defbb
--- /dev/null
@@ -0,0 +1,28 @@
+#include <iostream>
+#include <string>
+#include "TestClassComplete_Stub.hpp"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+
+       int port = 5010;
+       const char* address = "localhost";
+       int rev = 0;
+       bool bResult = false;
+       vector<int> ports;
+       ports.push_back(12345);
+
+       TestClassComplete *tcStub = new TestClassComplete_Stub(port, address, rev, &bResult, ports);
+       cout << "Return value: " << tcStub->setAndGetA(123) << endl;
+       cout << "Return value: " << tcStub->setACAndGetA("string", 123) << endl;
+       vector<string> input;
+       input.push_back("123");
+       input.push_back("456");
+       input.push_back("987");
+
+       cout << "Return value: " << tcStub->sumArray(input) << endl;
+       
+       return 0;
+}
diff --git a/iotjava/iotrmi/Java/basics/TestClass.java b/iotjava/iotrmi/Java/basics/TestClass.java
new file mode 100644 (file)
index 0000000..128e0ad
--- /dev/null
@@ -0,0 +1,74 @@
+import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
+
+public class TestClass implements TestClassInterface {
+
+       /**
+        * Class Properties
+        */
+       private int intA;
+       private float floatB;
+       private String stringC;
+
+       /**
+        * Constructors
+        */
+       public TestClass() {
+
+               intA = 1;
+               floatB = 2;
+               stringC = "345";
+       }
+
+
+       public TestClass(int _int, float _float, String _string) {
+
+               intA = _int;
+               floatB = _float;
+               stringC = _string;
+       }
+
+
+       public void setA(int _int) {
+
+               intA = _int;
+       }
+
+
+       public void setB(float _float) {
+
+               floatB = _float;
+       }
+
+
+       public void setC(String _string) {
+
+               stringC = _string;
+       }
+
+
+       // Getters
+       public String sumArray(String[] newA) {
+
+               String sum = "";
+               for (String i : newA) 
+                       sum = sum + i;
+               return sum;
+       }
+
+
+       public int setAndGetA(int newA) {
+
+               intA = newA;
+               return intA;
+       }
+
+
+       public int setACAndGetA(String newC, int newA) {
+
+               stringC = newC;
+               intA = newA;
+               return intA;
+       }
+}
diff --git a/iotjava/iotrmi/Java/basics/TestClass_Skeleton.java b/iotjava/iotrmi/Java/basics/TestClass_Skeleton.java
new file mode 100644 (file)
index 0000000..a5b7360
--- /dev/null
@@ -0,0 +1,11 @@
+
+public class TestClass_Skeleton {
+
+       public static void main(String[] args) throws Exception {
+
+               int port = 5010;
+               TestClass tc = new TestClass(3, 5f, "7911");
+               TestClassInterface_Skeleton tcSkel = new TestClassInterface_Skeleton(tc, port);
+
+       }
+}
diff --git a/iotjava/iotrmi/Java/basics/TestClass_Stub.java b/iotjava/iotrmi/Java/basics/TestClass_Stub.java
new file mode 100644 (file)
index 0000000..0a39b76
--- /dev/null
@@ -0,0 +1,23 @@
+import java.util.Arrays;
+import iotruntime.master.CommunicationHandler;
+
+public class TestClass_Stub {
+
+       public static void main(String[] args) throws Exception {
+
+               CommunicationHandler comHan = new CommunicationHandler(true);
+               int numOfPorts = 1;
+               int[] ports = comHan.getCallbackPorts(numOfPorts);
+
+               int port = 5010;
+               String address = "localhost";
+               int rev = 0;
+
+               System.out.println("Allocated ports: " + Arrays.toString(ports));
+
+               TestClassComplete_Stub tcstub = new TestClassComplete_Stub(port, address, rev, ports);
+               System.out.println("Return value: " + tcstub.setAndGetA(123));
+               System.out.println("Return value: " + tcstub.setACAndGetA("string", 123));
+               System.out.println("Return value: " + tcstub.sumArray(new String[] { "123", "456", "987" }));
+       }
+}