From: rtrimana Date: Sat, 26 Nov 2016 00:53:25 +0000 (-0800) Subject: Reverting type resolution in C++ to Java types, e.g. byte and char instead of just... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iot2.git;a=commitdiff_plain;h=4951f81458fa28e4db26f568df9f30e7afdecf0c Reverting type resolution in C++ to Java types, e.g. byte and char instead of just char --- diff --git a/config/iotpolicy/testclasspolicy.pol b/config/iotpolicy/testclasspolicy.pol index 21eb09e..24be14c 100644 --- a/config/iotpolicy/testclasspolicy.pol +++ b/config/iotpolicy/testclasspolicy.pol @@ -1,5 +1,13 @@ public interface TestClassInterface { + public byte getByte(byte in); + public short getShort(short in); + public long getLong(long in); + public float getFloat(float in); + public double getDouble(double in); + public boolean getBoolean(boolean in); + public char getChar(char in); + public int getA(); public void setA(int _int); public void setB(float _float); public void setC(String _string); @@ -9,6 +17,14 @@ public interface TestClassInterface { capability Setters { description = "All the set methods"; + method = "getByte(byte in)"; + method = "getShort(short in)"; + method = "getLong(long in)"; + method = "getFloat(float in)"; + method = "getDouble(double in)"; + method = "getBoolean(boolean in)"; + method = "getChar(char in)"; + method = "getA()"; method = "setA(int _int)"; method = "setB(float _float)"; method = "setC(String _string)"; diff --git a/iotjava/Makefile b/iotjava/Makefile index ce06bed..ab069c4 100644 --- a/iotjava/Makefile +++ b/iotjava/Makefile @@ -70,7 +70,7 @@ clean: PHONY += rmi rmi: mkdir -p $(BIN_DIR) -# $(JAVAC) -cp .:../$(BIN_DIR) -d $(BIN_DIR) iotrmi/Java/*.java + $(JAVAC) -cp .:../$(BIN_DIR) -d $(BIN_DIR) iotrmi/Java/*.java # $(JAVAC) -cp .:../$(BIN_DIR) -d $(BIN_DIR) iotrmi/Java/sample/*.java # mkdir -p $(BIN_DIR)/iotrmi/C++ #$(G++) iotrmi/C++/IoTSocketServer.cpp -o $(BIN_DIR)/iotrmi/C++/IoTSocketServer.out @@ -86,7 +86,7 @@ rmi: # $(G++) iotrmi/C++/sample/CallBack_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_Skeleton.out --std=c++11 #$(G++) iotrmi/C++/sample/TestClass.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass.out --std=c++11 # $(G++) iotrmi/C++/sample/TestClass_Stub.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Stub.out --std=c++11 -pthread -pg - $(G++) iotrmi/C++/sample/TestClass_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Skeleton.out --std=c++11 -pthread -pg +# $(G++) iotrmi/C++/sample/TestClass_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Skeleton.out --std=c++11 -pthread -pg #$(G++) iotrmi/C++/sample/Test.cpp -o ../bin/iotrmi/C++/sample/Test.out --std=c++11 -lpthread #$(G++) iotrmi/C++/sample/Test2.cpp -o ../bin/iotrmi/C++/sample/Test2.out --std=c++11 -pthread -pg # $(G++) iotrmi/C++/sample/StructC.cpp -o ../bin/iotrmi/C++/sample/StructC.out --std=c++11 diff --git a/iotjava/iotpolicy/IoTCompiler.java b/iotjava/iotpolicy/IoTCompiler.java index 028373b..ee3d287 100644 --- a/iotjava/iotpolicy/IoTCompiler.java +++ b/iotjava/iotpolicy/IoTCompiler.java @@ -2560,8 +2560,9 @@ public class IoTCompiler { println("int numParam = " + methParams.size() + ";"); println("int methodId = " + intDecl.getMethodNumId(method) + ";"); String retType = intDecl.getMethodType(method); - String retTypeC = checkAndGetCplusType(retType); - println("string retType = \"" + checkAndGetCplusArrayType(retTypeC) + "\";"); + //String retTypeC = checkAndGetCplusType(retType); + //println("string retType = \"" + checkAndGetCplusArrayType(retTypeC) + "\";"); + println("string retType = \"" + retType + "\";"); // Generate array of parameter types print("string paramCls[] = { "); for (int i = 0; i < methParams.size(); i++) { @@ -2569,8 +2570,10 @@ public class IoTCompiler { if (checkCallbackType(paramType, callbackType)) { // Check if this has callback object print("\"int\""); } else { // Generate normal classes if it's not a callback object - String paramTypeC = checkAndGetCplusType(methPrmTypes.get(i)); - String prmType = checkAndGetCplusArrayType(paramTypeC, methParams.get(i)); + //String paramTypeC = checkAndGetCplusType(methPrmTypes.get(i)); + //String prmType = checkAndGetCplusArrayType(paramTypeC, methParams.get(i)); + String paramTypeC = checkAndGetArray(methPrmTypes.get(i), methParams.get(i)); + String prmType = getSimpleType(getEnumType(paramTypeC)); print("\"" + prmType + "\""); } if (i != methParams.size() - 1) // Check if this is the last element @@ -2891,8 +2894,9 @@ public class IoTCompiler { checkAndWriteStructSetupCplusStub(methParams, methPrmTypes, intDecl, method); println("int methodId = " + intDecl.getMethodNumId(method) + ";"); String retType = intDecl.getMethodType(method); - String retTypeC = checkAndGetCplusType(retType); - println("string retType = \"" + checkAndGetCplusArrayType(getStructType(getEnumType(retTypeC))) + "\";"); + //String retTypeC = checkAndGetCplusType(retType); + //println("string retType = \"" + checkAndGetCplusArrayType(getStructType(getEnumType(retTypeC))) + "\";"); + println("string retType = \"" + retType + "\";"); // Generate array of parameter types if (isStructPresent(methParams, methPrmTypes)) { writeStructParamClassCplusStub(methParams, methPrmTypes); @@ -2900,9 +2904,12 @@ public class IoTCompiler { println("int numParam = " + methParams.size() + ";"); print("string paramCls[] = { "); for (int i = 0; i < methParams.size(); i++) { - String paramTypeC = checkAndGetCplusType(methPrmTypes.get(i)); - String paramType = checkAndGetCplusArrayType(paramTypeC, methParams.get(i)); - print("\"" + getEnumType(paramType) + "\""); + //String paramTypeC = checkAndGetCplusType(methPrmTypes.get(i)); + //String paramType = checkAndGetCplusArrayType(paramTypeC, methParams.get(i)); + //print("\"" + getEnumType(paramType) + "\""); + String paramTypeC = checkAndGetArray(methPrmTypes.get(i), methParams.get(i)); + String prmType = getSimpleType(getEnumType(paramTypeC)); + print("\"" + prmType + "\""); // Check if this is the last element (don't print a comma) if (i != methParams.size() - 1) { print(", "); @@ -3596,7 +3603,8 @@ public class IoTCompiler { if (isStructClass(getSimpleArrayType(getSimpleType(retType)))) // Struct type println("rmiObj->sendReturnObj(retObj, retCls, numRetObj);"); else - println("rmiObj->sendReturnObj(retObj, \"" + getEnumType(checkAndGetCplusArrayType(retTypeC)) + "\");"); + //println("rmiObj->sendReturnObj(retObj, \"" + getEnumType(checkAndGetCplusArrayType(retTypeC)) + "\");"); + println("rmiObj->sendReturnObj(retObj, \"" + getEnumType(retType) + "\");"); } } @@ -3618,9 +3626,12 @@ public class IoTCompiler { callbackType = paramType; print("\"int\""); } else { // Generate normal classes if it's not a callback object - String paramTypeC = checkAndGetCplusType(methPrmTypes.get(i)); - String prmType = checkAndGetCplusArrayType(paramTypeC, methParams.get(i)); - print("\"" + getEnumType(prmType) + "\""); + //String paramTypeC = checkAndGetCplusType(methPrmTypes.get(i)); + //String prmType = checkAndGetCplusArrayType(paramTypeC, methParams.get(i)); + //print("\"" + getEnumType(prmType) + "\""); + String paramTypeC = checkAndGetArray(methPrmTypes.get(i), methParams.get(i)); + String prmType = getSimpleType(getEnumType(paramTypeC)); + print("\"" + prmType + "\""); } if (i != methParams.size() - 1) { print(", "); diff --git a/iotjava/iotpolicy/tree/CapabilityDecl.java b/iotjava/iotpolicy/tree/CapabilityDecl.java index 7b2f923..a12cf13 100644 --- a/iotjava/iotpolicy/tree/CapabilityDecl.java +++ b/iotjava/iotpolicy/tree/CapabilityDecl.java @@ -110,6 +110,13 @@ public class CapabilityDecl extends Declaration { public List getMethods(String cap) { int index = listCapabs.indexOf(cap); + // If index=-1, it means that it's not found. + // There is perhaps a discrepancy in the policy file + // between the list of capabilities and requires + // sections + if (index == -1) + throw new Error("CapabilityDecl: Capability " + cap + + " does not exist in this interface! Please check your (requires) policy file..."); return listMethods.get(index); } } diff --git a/iotjava/iotrmi/C++/IoTRMICall.hpp b/iotjava/iotrmi/C++/IoTRMICall.hpp index 2ac2509..a630798 100644 --- a/iotjava/iotrmi/C++/IoTRMICall.hpp +++ b/iotjava/iotrmi/C++/IoTRMICall.hpp @@ -145,7 +145,6 @@ int IoTRMICall::methodLength(string paramCls[], void* paramObj[], int numParam) // Calculate methodLen methodLen = methodLen + paramLen; } - return methodLen; } diff --git a/iotjava/iotrmi/C++/IoTRMIUtil.hpp b/iotjava/iotrmi/C++/IoTRMIUtil.hpp index f42241e..db43722 100644 --- a/iotjava/iotrmi/C++/IoTRMIUtil.hpp +++ b/iotjava/iotrmi/C++/IoTRMIUtil.hpp @@ -185,10 +185,10 @@ int IoTRMIUtil::getTypeSize(string type) { int IoTRMIUtil::getVarTypeSize(string type, void* paramObj) { int paramLen = 0; - if (type.compare("string") == 0) { + if (type.compare("String") == 0) { // Get the length of the string through void* casting to string* paramLen = (*(string*)paramObj).length(); - } else if (type.compare("string[]") == 0) { + } else if (type.compare("String[]") == 0) { paramLen = IoTRMIUtil::getByteStringLength(*(vector*) paramObj); } else if (type.compare("byte[]") == 0) { int dataSize = getTypeSize("byte"); @@ -209,7 +209,7 @@ int IoTRMIUtil::getVarTypeSize(string type, void* paramObj) { int dataSize = getTypeSize("double"); paramLen = (*(vector*) paramObj).size() * dataSize; } else if (type.compare("bool[]") == 0) { - int dataSize = getTypeSize("bool"); + int dataSize = getTypeSize("boolean"); paramLen = (*(vector*) paramObj).size() * dataSize; } else if (type.compare("char[]") == 0) { int dataSize = getTypeSize("char"); @@ -266,13 +266,13 @@ void* IoTRMIUtil::getParamObject(void* retObj, const char* type, char* paramByte strcmp(type, "double") == 0) { retObj = (void*) byteArrayToDouble((double*) retObj, paramBytes); } else if ( strcmp(type, "b") == 0 || - strcmp(type, "bool") == 0) { + strcmp(type, "boolean") == 0) { retObj = (void*) byteArrayToBoolean((bool*) retObj, paramBytes); } else if ( strcmp(type, "c") == 0 || strcmp(type, "char") == 0) { retObj = (void*) byteArrayToChar((char*) retObj, paramBytes); } else if ( strcmp(type, "Ss") == 0 || - strcmp(type, "string") == 0) { + strcmp(type, "String") == 0) { retObj = (void*) byteArrayToString((string*) retObj, paramBytes, len); } else if ( string(type).find("[]") != string::npos) { // This is an array type, i.e. vector @@ -305,7 +305,7 @@ void* IoTRMIUtil::getArrayParamObject(void* retObj, const char* type, char* para retObj = byteArrayToBooleanArray((vector*) retObj, paramBytes, len); } else if (strcmp(type, "char[]") == 0) { retObj = byteArrayToCharArray((vector*) retObj, paramBytes, len); - } else if (strcmp(type, "string[]") == 0) { + } else if (strcmp(type, "String[]") == 0) { retObj = byteArrayToStringArray((vector*) retObj, paramBytes, len); } else { string error = "IoTRMIUtil: Unrecognizable type: " + string(type); @@ -338,12 +338,13 @@ char* IoTRMIUtil::getObjectBytes(char* retObjBytes, void* obj, const char* type) strcmp(type, "double") == 0) { retObjBytes = doubleToByteArray(*((double*) obj), retObjBytes); } else if ( strcmp(type, "b") == 0 || - strcmp(type, "bool") == 0) { + strcmp(type, "boolean") == 0) { retObjBytes = booleanToByteArray(*((bool*) obj), retObjBytes); } else if ( strcmp(type, "c") == 0 || strcmp(type, "char") == 0) { retObjBytes = charToByteArray(*((char*) obj), retObjBytes); } else if ( strcmp(type, "Ss") == 0 || + strcmp(type, "String") == 0 || strcmp(type, "string") == 0) { retObjBytes = stringToByteArray(*((string*) obj), retObjBytes); } else if ( string(type).find("[]") != string::npos) { @@ -377,7 +378,7 @@ char* IoTRMIUtil::getArrayObjectBytes(char* retObjBytes, void* obj, const char* retObjBytes = arrBooleanToByteArray(*((vector*) obj), retObjBytes); } else if (strcmp(type, "char[]") == 0) { retObjBytes = arrCharToByteArray(*((vector*) obj), retObjBytes); - } else if (strcmp(type, "string[]") == 0) { + } else if (strcmp(type, "String[]") == 0) { retObjBytes = arrStringToByteArray(*((vector*) obj), retObjBytes); } else { string error = "IoTRMIUtil: Unrecognizable type: " + string(type); diff --git a/iotjava/iotrmi/C++/basics/TestClass.hpp b/iotjava/iotrmi/C++/basics/TestClass.hpp index 91f7e5c..d39960b 100644 --- a/iotjava/iotrmi/C++/basics/TestClass.hpp +++ b/iotjava/iotrmi/C++/basics/TestClass.hpp @@ -13,6 +13,14 @@ class TestClass : public TestClassInterface { TestClass(); TestClass(int _int, float _float, string _string); + char getByte(char in); + short getShort(short in); + int64_t getLong(int64_t in); + float getFloat(float in); + double getDouble(double in); + bool getBoolean(bool in); + char getChar(char in); + int getA(); void setA(int _int); void setB(float _float); void setC(string _string); @@ -45,6 +53,54 @@ TestClass::TestClass(int _int, float _float, string _string) { } +char TestClass::getByte(char in) { + + return in; +} + + +short TestClass::getShort(short in) { + + return in; +} + + +int64_t TestClass::getLong(int64_t in) { + + return in; +} + + +float TestClass::getFloat(float in) { + + return in; +} + + +double TestClass::getDouble(double in) { + + return in; +} + + +bool TestClass::getBoolean(bool in) { + + return in; +} + + +char TestClass::getChar(char in) { + + return in; +} + + +int TestClass::getA() { + + return intA; +} + + void TestClass::setA(int _int) { intA = _int; diff --git a/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp b/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp index 20defbb..c4a692d 100644 --- a/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp +++ b/iotjava/iotrmi/C++/basics/TestClass_Stub.cpp @@ -9,12 +9,22 @@ int main(int argc, char *argv[]) int port = 5010; const char* address = "localhost"; + //const char* address = "128.195.136.170"; // dc-9.calit2.uci.edu int rev = 0; bool bResult = false; vector ports; ports.push_back(12345); TestClassComplete *tcStub = new TestClassComplete_Stub(port, address, rev, &bResult, ports); + cout << "Return value: " << tcStub->getByte(68) << endl; + cout << "Return value: " << tcStub->getShort(1234) << endl; + //cout << "Return value: " << tcStub->getLong(12345678) << endl; + cout << "Return value: " << tcStub->getFloat(12.345) << endl; + cout << "Return value: " << tcStub->getDouble(12345.678) << endl; + cout << "Return value: " << tcStub->getBoolean(true) << endl; + cout << "Return value: " << tcStub->getChar('c') << endl; + + cout << "Return value: " << tcStub->getA() << endl; cout << "Return value: " << tcStub->setAndGetA(123) << endl; cout << "Return value: " << tcStub->setACAndGetA("string", 123) << endl; vector input; diff --git a/iotjava/iotrmi/Java/IoTRMIObject.java b/iotjava/iotrmi/Java/IoTRMIObject.java index 6f52228..54ffa6e 100644 --- a/iotjava/iotrmi/Java/IoTRMIObject.java +++ b/iotjava/iotrmi/Java/IoTRMIObject.java @@ -55,7 +55,7 @@ public class IoTRMIObject { // Receive method info methodBytes = rmiServer.receiveBytes(methodBytes); - System.out.println("Method: " + Arrays.toString(methodBytes)); + //System.out.println("Method: " + Arrays.toString(methodBytes)); return methodBytes; } diff --git a/iotjava/iotrmi/Java/IoTRMIUtil.java b/iotjava/iotrmi/Java/IoTRMIUtil.java index e238755..23385ba 100644 --- a/iotjava/iotrmi/Java/IoTRMIUtil.java +++ b/iotjava/iotrmi/Java/IoTRMIUtil.java @@ -211,7 +211,6 @@ public class IoTRMIUtil { public static Object getParamObjectArray(Class type, byte[] paramBytes) { Object retObj = null; - System.out.println("Got here!!!"); if ((type == byte[].class) || (type == byte.class)) { retObj = (Object) paramBytes; @@ -284,7 +283,7 @@ public class IoTRMIUtil { byte[] retObjBytes = null; if (obj instanceof Byte) { - retObjBytes = (byte[]) obj; + retObjBytes = new byte[] { (byte) obj }; } else if (obj instanceof Short) { retObjBytes = shortToByteArray((short) obj); } else if (obj instanceof Integer) { diff --git a/iotjava/iotrmi/Java/basics/TestClass.java b/iotjava/iotrmi/Java/basics/TestClass.java index 128e0ad..19b99de 100644 --- a/iotjava/iotrmi/Java/basics/TestClass.java +++ b/iotjava/iotrmi/Java/basics/TestClass.java @@ -30,6 +30,54 @@ public class TestClass implements TestClassInterface { } + public byte getByte(byte in) { + + return in; + } + + + public short getShort(short in) { + + return in; + } + + + public long getLong(long in) { + + return in; + } + + + public float getFloat(float in) { + + return in; + } + + + public double getDouble(double in) { + + return in; + } + + + public boolean getBoolean(boolean in) { + + return in; + } + + + public char getChar(char in) { + + return in; + } + + + public int getA() { + + return intA; + } + + public void setA(int _int) { intA = _int; diff --git a/iotjava/iotrmi/Java/basics/TestClass_Stub.java b/iotjava/iotrmi/Java/basics/TestClass_Stub.java index 0a39b76..d94a09d 100644 --- a/iotjava/iotrmi/Java/basics/TestClass_Stub.java +++ b/iotjava/iotrmi/Java/basics/TestClass_Stub.java @@ -11,11 +11,21 @@ public class TestClass_Stub { int port = 5010; String address = "localhost"; + //String address = "128.195.136.170"; // dc-9.calit2.uci.edu 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.getByte((byte)68)); + System.out.println("Return value: " + tcstub.getShort((short)1234)); + System.out.println("Return value: " + tcstub.getLong(12345678l)); + System.out.println("Return value: " + tcstub.getFloat(12.345f)); + System.out.println("Return value: " + tcstub.getDouble(12345.678)); + System.out.println("Return value: " + tcstub.getBoolean(true)); + System.out.println("Return value: " + tcstub.getChar('c')); + + System.out.println("Return value: " + tcstub.getA()); 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" }));