Reverting type resolution in C++ to Java types, e.g. byte and char instead of just...
authorrtrimana <rtrimana@uci.edu>
Sat, 26 Nov 2016 00:53:25 +0000 (16:53 -0800)
committerrtrimana <rtrimana@uci.edu>
Sat, 26 Nov 2016 00:53:25 +0000 (16:53 -0800)
12 files changed:
config/iotpolicy/testclasspolicy.pol
iotjava/Makefile
iotjava/iotpolicy/IoTCompiler.java
iotjava/iotpolicy/tree/CapabilityDecl.java
iotjava/iotrmi/C++/IoTRMICall.hpp
iotjava/iotrmi/C++/IoTRMIUtil.hpp
iotjava/iotrmi/C++/basics/TestClass.hpp
iotjava/iotrmi/C++/basics/TestClass_Stub.cpp
iotjava/iotrmi/Java/IoTRMIObject.java
iotjava/iotrmi/Java/IoTRMIUtil.java
iotjava/iotrmi/Java/basics/TestClass.java
iotjava/iotrmi/Java/basics/TestClass_Stub.java

index 21eb09e7ad27f88407d6fc61df1fad12e7393cb5..24be14c5e1891c97baf1ab7b80bc314c6e9fd672 100644 (file)
@@ -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)";
index ce06bedb31c24f10fe57587d801e408e4e7edeee..ab069c48b94eec2448c9e20eac9f19aa09398afc 100644 (file)
@@ -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
index 028373b77b8883a43f9b70ee16089ec01bfa7fd1..ee3d287ee396d2b898ad0e45afa8ef77fab8a79d 100644 (file)
@@ -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(", ");
index 7b2f923a823f162403d4cf34e5e14f1795541c4b..a12cf13e54d70eccc1acd284487ec265ff5c0c70 100644 (file)
@@ -110,6 +110,13 @@ public class CapabilityDecl extends Declaration {
        public List<String> 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);
        }
 }
index 2ac2509f39c54b84c938632a20a401f9d6127f10..a63079846b4c7797bc9a37adebfe676b227dd3d9 100644 (file)
@@ -145,7 +145,6 @@ int IoTRMICall::methodLength(string paramCls[], void* paramObj[], int numParam)
                // Calculate methodLen
                methodLen = methodLen + paramLen;
        }
-
        return methodLen;
 }
 
index f42241edd94c79a65c6a8ae701b701d359e26d1a..db437228bb0891215f2e8435f312d4efea0e0055 100644 (file)
@@ -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<string>*) 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<double>*) paramObj).size() * dataSize;
        } else if (type.compare("bool[]") == 0) {
-               int dataSize = getTypeSize("bool");
+               int dataSize = getTypeSize("boolean");
                paramLen = (*(vector<bool>*) 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<bool>*) retObj, paramBytes, len);
        } else if (strcmp(type, "char[]") == 0) {
                retObj = byteArrayToCharArray((vector<char>*) retObj, paramBytes, len);
-       } else if (strcmp(type, "string[]") == 0) {
+       } else if (strcmp(type, "String[]") == 0) {
                retObj = byteArrayToStringArray((vector<string>*) 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<bool>*) obj), retObjBytes);
        } else if (strcmp(type, "char[]") == 0) {
                retObjBytes = arrCharToByteArray(*((vector<char>*) obj), retObjBytes);
-       } else if (strcmp(type, "string[]") == 0) {
+       } else if (strcmp(type, "String[]") == 0) {
                retObjBytes = arrStringToByteArray(*((vector<string>*) obj), retObjBytes);
        } else {
                string error = "IoTRMIUtil: Unrecognizable type: " + string(type);
index 91f7e5c66c301de1a4f02558197f8a21bc580375..d39960b651b3dbda67a52e6a35232ced9c262f2c 100644 (file)
@@ -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;
index 20defbb69d15a778fca95aa83efe4ae19c15e215..c4a692d38477c13732c986c14ca65b9cd9d2b697 100644 (file)
@@ -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<int> 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<string> input;
index 6f52228bb0d021b72c02a69582e03997b65f0e07..54ffa6e385eb61f9c5e4ff8ff8d891121ebf578d 100644 (file)
@@ -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;
        }
 
index e2387557673986ba42c44ce169a70744cc1cc49a..23385ba5199947039f7d68d398cb95fc4c02b063 100644 (file)
@@ -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) {
index 128e0ad4303b16ca19e987bb14552f95419c553d..19b99de69fb5d8f599252dd13ae02322593dc564 100644 (file)
@@ -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;
index 0a39b762fa07d8804a87e39f30a2347648387afa..d94a09d7e473d1af54d566a51c93cb9a62d9dea5 100644 (file)
@@ -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" }));