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/sample/*.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++/IoTSocketClient.cpp -o $(BIN_DIR)/iotrmi/C++/IoTSocketClient.out
# $(G++) iotrmi/C++/sample/CallBack_Stub.cpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_Stub.out --std=c++11
# $(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
-# $(G++) iotrmi/C++/sample/TestClass_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Skeleton.out --std=c++11 -pthread
+ $(G++) iotrmi/C++/sample/TestClass_Stub.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Stub.out --std=c++11 -pthread
+ $(G++) iotrmi/C++/sample/TestClass_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Skeleton.out --std=c++11 -pthread
#$(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
void registerCallback(vector<CallBackInterface*> _cb);
int callBack();
void handleStruct(vector<data> vecData);
- void handleEnum(vector<EnumC> vecEn);
+ vector<EnumC> handleEnum(vector<EnumC> vecEn);
private:
int intA;
}
-void TestClass::handleEnum(vector<EnumC> vecEn) {
+vector<EnumC> TestClass::handleEnum(vector<EnumC> vecEn) {
for (EnumC en : vecEn) {
cout << "Enum: " << en << endl;
}
+
+ return vecEn;
}
virtual void registerCallback(vector<CallBackInterface*> _cb) = 0;
virtual int callBack() = 0;
virtual void handleStruct(vector<data> vecData) = 0;
- virtual void handleEnum(vector<EnumC> vecEn) = 0;
+ virtual vector<EnumC> handleEnum(vector<EnumC> vecEn) = 0;
};
#endif
void registerCallback(vector<CallBackInterface*> _cb);
int callBack();
void handleStruct(vector<data> vecData);
- void handleEnum(vector<EnumC> vecEn);
+ vector<EnumC> handleEnum(vector<EnumC> vecEn);
void ___setA();
void ___setB();
}
-void TestClass_Skeleton::handleEnum(vector<EnumC> vecEn) {
+vector<EnumC> TestClass_Skeleton::handleEnum(vector<EnumC> vecEn) {
- tc->handleEnum(vecEn);
+ return tc->handleEnum(vecEn);
}
for (int i=0; i < enumsize1; i++) {
en[i] = (EnumC) param1[i];
}
- handleEnum(en);
+ //handleEnum(en);
+ // if void, just "handleEnum(en)"
+ // this is when we have return value vector<EnumC>
+ vector<EnumC> retEnum = handleEnum(en);
+ // Get length first
+ int enumSize2 = retEnum.size();
+ // Now send the array of integers
+ vector<int> retEnumInt(enumSize2);
+ for (int i=0; i < enumSize2; i++) {
+ retEnumInt[i] = (int) retEnum[i];
+ }
+ void* retObj = &retEnumInt;
+ rmiObj->sendReturnObj(retObj, "int[]");
}
vecEn.push_back(ORANGE);
vecEn.push_back(APPLE);
vecEn.push_back(GRAPE);
- tcStub->handleEnum(vecEn);
+ vector<EnumC> vecRes = tcStub->handleEnum(vecEn);
+ for (EnumC en : vecRes) {
+ cout << "EnumC: " << en << endl;
+ }
return 0;
}
void registerCallback(vector<CallBackInterface*>_cb);
int callBack();
void handleStruct(vector<data> vecData);
- void handleEnum(vector<EnumC> vecEn);
+ vector<EnumC> handleEnum(vector<EnumC> vecEn);
void ____init_CallBack(); // thread
void ____registerCallBack(); // tell the other side that we are ready
}
-void TestClass_Stub::handleEnum(vector<EnumC> vecEn) {
+vector<EnumC> TestClass_Stub::handleEnum(vector<EnumC> vecEn) {
int numParam = 1;
int methodId = 13;
int numParam2 = vecEn.size();
int methodId2 = 12;
- string retType2 = "void";
+ string retType2 = "int[]";
string paramCls2[numParam2];
// Need to define this container for integer version of enum
int paramEnum[numParam2];
void* paramObj2[numParam2];
- for(int i = 0; i < vecEn.size(); i++) {
+ for(int i = 0; i < numParam2; i++) {
paramCls2[i] = "int";
paramEnum[i] = (int) vecEn[i]; // cast enum to integer
paramObj2[i] = ¶mEnum[i];
}
- void* retObj2 = NULL;
+ vector<int> retEnumInt(numParam2);
+ // if no return value just
+ // void* retObj2 = NULL;
+ // This is with return value:
+ void* retObj2 = &retEnumInt;
rmiCall->remoteCall(objectId, methodId2, retType2, paramCls2, paramObj2, numParam2, retObj2);
+ int enumsize1 = retEnumInt.size();
+ vector<EnumC> retVal(enumsize1);
+ for (int i=0; i < enumsize1; i++) {
+ retVal[i] = (EnumC) retEnumInt[i];
+ }
+ return retVal;
}
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;
} else if ( (type == String[].class) ||
(type == String.class)) {
retObj = (Object) byteArrayToStringArray(paramBytes);
- } else if (type.isArray()) {
+ //} else if (type.isArray()) {
// This is an array but it's more than 1 dimension, e.g. 2-dimensional,
// 3-dimensional, etc.
// for loop to check inner array perhaps using object
}
- public void handleEnum(EnumJ[] en) {
+ public EnumJ[] handleEnum(EnumJ[] en) {
for (EnumJ e : en) {
System.out.println("Enum: " + e);
}
+
+ return en;
}
public void registerCallback(CallBackInterface[] _cb);
public int callBack();
public void handleStruct(StructJ[] data);
- public void handleEnum(EnumJ[] en);
+ public EnumJ[] handleEnum(EnumJ[] en);
}
}
- public void handleEnum(EnumJ[] en) {
+ public EnumJ[] handleEnum(EnumJ[] en) {
- tc.handleEnum(en);
+ return tc.handleEnum(en);
}
}
- public void ___handleEnum(int enumSize1) {
+ public void ___handleEnum(int enumSize1) throws IOException {
Class<?>[] paramCls = new Class<?>[enumSize1];
Class<?>[] paramClsVal = new Class<?>[enumSize1];
for (int i=0; i < enumSize1; i++) {
data[i] = enumJ[(int) paramObj[i]];
}
- tc.handleEnum(data);
+ // if void, just "handleEnum(data)"
+ // this is when we have return value EnumJ[]
+ EnumJ[] retEnum = handleEnum(data);
+ // Get length first
+ int enumSize2 = retEnum.length;
+ // Now send the array of integers
+ int[] retEnumInt = new int[enumSize2];
+ for (int i=0; i < enumSize2; i++) {
+ retEnumInt[i] = retEnum[i].ordinal();
+ }
+ Object retObj = retEnumInt;
+ rmiObj.sendReturnObj(retObj);
}
}
- public void handleEnum(EnumJ[] en) {
+ public EnumJ[] handleEnum(EnumJ[] en) {
// Send length info first
int methodId = 13;
rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj);
int methodId2 = 12;
- Class<?> retType2 = void.class;
+ Class<?> retType2 = int[].class;
// Calculate the size of the array
Class<?>[] paramCls2 = new Class<?>[en.length];
Object[] paramObj2 = new Object[en.length];
paramCls2[i] = int.class;
paramObj2[i] = en[i].ordinal();
}
- System.out.println(Arrays.toString(paramObj2));
- rmiCall.remoteCall(objectId, methodId2, retType2, null, paramCls2, paramObj2);
+ // if no return value just
+ // rmiCall.remoteCall(objectId, methodId2, retType2, null, paramCls2, paramObj2);
+ // This is with return value:
+ Object retObj =
+ rmiCall.remoteCall(objectId, methodId2, retType2, null, paramCls2, paramObj2);
+ int[] retEnumInt = (int[]) retObj;
+ int enumsize1 = retEnumInt.length;
+ // Encoder/decoder
+ EnumJ[] enumJ = EnumJ.values();
+ EnumJ[] enRetVal = new EnumJ[enumsize1];
+ for(int i = 0; i < enumsize1; i++) {
+ enRetVal[i] = enumJ[retEnumInt[i]];
+ }
+ return enRetVal;
}
System.out.println("Return value: " + tcstub.setACAndGetA("string", 123));
System.out.println("Return value: " + tcstub.sumArray(new String[] { "123", "456", "987" }));
- CallBackInterface cb1 = new CallBack(23);
+ /*CallBackInterface cb1 = new CallBack(23);
CallBackInterface cb2 = new CallBack(33);
CallBackInterface cb3 = new CallBack(43);
CallBackInterface[] cb = { cb1, cb2, cb3 };
System.out.println("Value: " + str.value);
System.out.println("Year: " + str.year);
}
- tcstub.handleStruct(data);
+ tcstub.handleStruct(data);*/
EnumJ[] en = { EnumJ.APPLE, EnumJ.ORANGE, EnumJ.APPLE, EnumJ.GRAPE };
- tcstub.handleEnum(en);
-
+ EnumJ[] res = tcstub.handleEnum(en);
+ System.out.println("Enum members: " + Arrays.toString(res));
}
}