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);
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)";
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
# $(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
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++) {
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
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);
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(", ");
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) + "\");");
}
}
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(", ");
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);
}
}
// Calculate methodLen
methodLen = methodLen + paramLen;
}
-
return methodLen;
}
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");
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");
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
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);
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) {
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);
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);
}
+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;
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;
// Receive method info
methodBytes = rmiServer.receiveBytes(methodBytes);
- System.out.println("Method: " + Arrays.toString(methodBytes));
+ //System.out.println("Method: " + Arrays.toString(methodBytes));
return methodBytes;
}
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;
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) {
}
+ 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;
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" }));