--- /dev/null
+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;
+ }
+}
+
+
--- /dev/null
+
+requires TestClassInterface with Setters, SetAndGets as interface TestClassComplete;
+
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
# 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:
* 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;
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(", ");
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);
}
}
println(" });");
// Write the return value part
- writeMethodHelperReturnJavaSkeleton(intDecl, methParams, methPrmTypes, method, isCallbackMethod, callbackType);
+ writeMethodHelperReturnJavaSkeleton(intDecl, methParams, methPrmTypes, method, isCallbackMethod, callbackType, false);
}
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("}");
}
}
println("vector<int> paramEnumInt" + i + ";");
} else {
String methParamComplete = checkAndGetCplusArray(methPrmType, methParams.get(i));
- println(methParamComplete + ";");
+ //println(methParamComplete + " = " + generateCplusInitializer(methPrmType) + ";");
+ println(methParamComplete + ";");
}
}
}
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("}");
}
}
--- /dev/null
+#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
+
--- /dev/null
+#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;
+}
--- /dev/null
+#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;
+}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+
+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);
+
+ }
+}
--- /dev/null
+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" }));
+ }
+}