From 9588f4768de10645d7b0d8a2214d5c63fc92fde8 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Mon, 7 Nov 2016 09:54:06 -0800 Subject: [PATCH] Sending int[] instead of a bunch of int for enum type transport; cleaning up method signatures on C++ side --- .../iotrmi/C++/sample/CallBack_CBSkeleton.hpp | 10 ---- iotjava/iotrmi/C++/sample/CallBack_CBStub.hpp | 10 ---- .../iotrmi/C++/sample/CallBack_Skeleton.hpp | 10 ---- iotjava/iotrmi/C++/sample/CallBack_Stub.hpp | 10 ---- .../iotrmi/C++/sample/TestClass_Skeleton.hpp | 42 ++++----------- iotjava/iotrmi/C++/sample/TestClass_Stub.cpp | 20 ++++--- iotjava/iotrmi/C++/sample/TestClass_Stub.hpp | 52 ++++--------------- .../Java/sample/TestClass_Skeleton.java | 27 +++------- .../iotrmi/Java/sample/TestClass_Stub.java | 26 ++++------ 9 files changed, 51 insertions(+), 156 deletions(-) diff --git a/iotjava/iotrmi/C++/sample/CallBack_CBSkeleton.hpp b/iotjava/iotrmi/C++/sample/CallBack_CBSkeleton.hpp index ffd6c42..90c63a1 100644 --- a/iotjava/iotrmi/C++/sample/CallBack_CBSkeleton.hpp +++ b/iotjava/iotrmi/C++/sample/CallBack_CBSkeleton.hpp @@ -20,22 +20,12 @@ class CallBack_CBSkeleton : public CallBackInterface { void ___printInt(IoTRMIObject* rmiObj); void ___setInt(IoTRMIObject* rmiObj); - const static int size = 2; - const static string methodSignatures[size]; - private: CallBackInterface *cb; int objectId = 0; }; -const string CallBack_CBSkeleton::methodSignatures[CallBack_CBSkeleton::size] = { - - "intprintInt()", - "voidsetInt(int)" -}; - - // Constructor CallBack_CBSkeleton::CallBack_CBSkeleton(CallBackInterface* _cb, int _objectId) { diff --git a/iotjava/iotrmi/C++/sample/CallBack_CBStub.hpp b/iotjava/iotrmi/C++/sample/CallBack_CBStub.hpp index 0ab69b5..b674efa 100644 --- a/iotjava/iotrmi/C++/sample/CallBack_CBStub.hpp +++ b/iotjava/iotrmi/C++/sample/CallBack_CBStub.hpp @@ -16,9 +16,6 @@ class CallBack_CBStub : public CallBackInterface { int printInt(); void setInt(int _i); - const static int size = 2; - const static string methodSignatures[size]; - private: IoTRMICall *rmiCall; @@ -26,13 +23,6 @@ class CallBack_CBStub : public CallBackInterface { }; -const string CallBack_CBStub::methodSignatures[CallBack_CBStub::size] = { - - "intprintInt()", - "voidsetInt(int)" -}; - - // Constructor CallBack_CBStub::CallBack_CBStub() { diff --git a/iotjava/iotrmi/C++/sample/CallBack_Skeleton.hpp b/iotjava/iotrmi/C++/sample/CallBack_Skeleton.hpp index 9ab5c03..bde7e42 100644 --- a/iotjava/iotrmi/C++/sample/CallBack_Skeleton.hpp +++ b/iotjava/iotrmi/C++/sample/CallBack_Skeleton.hpp @@ -19,22 +19,12 @@ class CallBack_Skeleton : public CallBackInterface { void ___printInt(); void ___setInt(); - const static int size = 2; - const static string methodSignatures[size]; - private: CallBackInterface *cb; IoTRMIObject *rmiObj; }; -const string CallBack_Skeleton::methodSignatures[CallBack_Skeleton::size] = { - - "intprintInt()", - "voidsetInt(int)" -}; - - // Constructor CallBack_Skeleton::CallBack_Skeleton(CallBackInterface* _cb, int _port) { diff --git a/iotjava/iotrmi/C++/sample/CallBack_Stub.hpp b/iotjava/iotrmi/C++/sample/CallBack_Stub.hpp index 9bdcef4..e7db446 100644 --- a/iotjava/iotrmi/C++/sample/CallBack_Stub.hpp +++ b/iotjava/iotrmi/C++/sample/CallBack_Stub.hpp @@ -16,9 +16,6 @@ class CallBack_Stub : public CallBackInterface { int printInt(); void setInt(int _i); - const static int size = 2; - const static string methodSignatures[size]; - private: IoTRMICall *rmiCall; @@ -27,13 +24,6 @@ class CallBack_Stub : public CallBackInterface { }; -const string CallBack_Stub::methodSignatures[CallBack_Stub::size] = { - - "intprintInt()", - "voidsetInt(int)" -}; - - // Constructor CallBack_Stub::CallBack_Stub() { diff --git a/iotjava/iotrmi/C++/sample/TestClass_Skeleton.hpp b/iotjava/iotrmi/C++/sample/TestClass_Skeleton.hpp index 015cda4..6f715fc 100644 --- a/iotjava/iotrmi/C++/sample/TestClass_Skeleton.hpp +++ b/iotjava/iotrmi/C++/sample/TestClass_Skeleton.hpp @@ -46,9 +46,6 @@ class TestClass_Skeleton : public TestClassInterface { int ___enumSize(); void ___handleEnum(int enumsize1); - const static int size = 12; - const static string methodSignatures[size]; - private: TestClassInterface *tc; IoTRMIObject *rmiObj; @@ -59,23 +56,6 @@ class TestClass_Skeleton : public TestClassInterface { }; -const string TestClass_Skeleton::methodSignatures[TestClass_Skeleton::size] = { - "voidsetA(int)", // 0 - "voidsetB(float)", // 1 - "voidsetC(string)", // 2 - "sumArray(string[])", // 3 - //"sumArray(int[])", - "intsetAndGetA(int)", // 4 - "intsetACAndGetA(string,int)", // 5 - "intcallBack()", // 6 - "voidregisterCallBack(CallBackInterface)", // 7 - "voidregisterCallBack(CallBackInterface[])", // 8 - "registercallback", // 9 - "handleStruct(StructJ[])", // 10 - "structsize" // 11 -}; - - int TestClass_Skeleton::objIdCnt = 0; @@ -355,19 +335,16 @@ int TestClass_Skeleton::___enumSize() { void TestClass_Skeleton::___handleEnum(int enumsize1) { - string paramCls[enumsize1]; - void* paramObj[enumsize1]; - int numParam = enumsize1; - // define array of everything - int param1[enumsize1]; - for(int i=0; i < enumsize1; i++) { - paramCls[i] = "int"; - paramObj[i] = ¶m1[i]; - } + int numParam = 1; + string paramCls[] = { "int[]" }; + vector paramInt; + void* paramObj[] = { ¶mInt }; + // Receive the array of integers rmiObj->getMethodParams(paramCls, numParam, paramObj); - vector en(enumsize1); - for (int i=0; i < enumsize1; i++) { - en[i] = (EnumC) param1[i]; + int enumSize1 = paramInt.size(); + vector en(enumSize1); + for (int i=0; i < enumSize1; i++) { + en[i] = (EnumC) paramInt[i]; } //handleEnum(en); // if void, just "handleEnum(en)" @@ -411,7 +388,6 @@ void TestClass_Skeleton::___waitRequestInvokeMethod() { case 10: ___handleStruct(structsize1); break; case 11: structsize1 = ___structSize(); break; case 12: ___handleEnum(enumsize1); break; - case 13: enumsize1 = ___enumSize(); break; default: string error = "Method Id not recognized!"; throw error; diff --git a/iotjava/iotrmi/C++/sample/TestClass_Stub.cpp b/iotjava/iotrmi/C++/sample/TestClass_Stub.cpp index 201f8c0..95197c5 100644 --- a/iotjava/iotrmi/C++/sample/TestClass_Stub.cpp +++ b/iotjava/iotrmi/C++/sample/TestClass_Stub.cpp @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) cout << "Return value: " << tcStub->sumArray(input) << endl; - /*CallBackInterface *cb1 = new CallBack(23); + CallBackInterface *cb1 = new CallBack(23); CallBackInterface *cb2 = new CallBack(33); CallBackInterface *cb3 = new CallBack(43); vector cb; @@ -38,6 +38,14 @@ int main(int argc, char *argv[]) cb.push_back(cb2); cb.push_back(cb3); tcStub->registerCallback(cb); + /*CallBackInterface *cb4 = new CallBack(53); + CallBackInterface *cb5 = new CallBack(63); + CallBackInterface *cb6 = new CallBack(73); + vector cbsec; + cb.push_back(cb4); + cb.push_back(cb5); + cb.push_back(cb6); + tcStub->registerCallback(cbsec);*/ cout << "Return value from callback: " << tcStub->callBack() << endl; vector dataset; @@ -57,11 +65,6 @@ int main(int argc, char *argv[]) tcStub->handleStruct(dataset); - delete tcStub; - delete cb1; - delete cb2; - delete cb3;*/ - vector vecEn; vecEn.push_back(APPLE); vecEn.push_back(ORANGE); @@ -72,5 +75,10 @@ int main(int argc, char *argv[]) cout << "EnumC: " << en << endl; } + delete tcStub; + delete cb1; + delete cb2; + delete cb3; + return 0; } diff --git a/iotjava/iotrmi/C++/sample/TestClass_Stub.hpp b/iotjava/iotrmi/C++/sample/TestClass_Stub.hpp index 8e470ef..b8cce21 100644 --- a/iotjava/iotrmi/C++/sample/TestClass_Stub.hpp +++ b/iotjava/iotrmi/C++/sample/TestClass_Stub.hpp @@ -32,9 +32,6 @@ class TestClass_Stub : public TestClassInterface { void ____init_CallBack(); // thread void ____registerCallBack(); // tell the other side that we are ready - const static int size = 12; - const static string methodSignatures[size]; - private: int intA; float floatB; @@ -54,23 +51,6 @@ class TestClass_Stub : public TestClassInterface { int TestClass_Stub::objIdCnt = 0; -const string TestClass_Stub::methodSignatures[TestClass_Stub::size] = { - "voidsetA(int)", // 0 - "voidsetB(float)", // 1 - "voidsetC(string)", // 2 - "sumArray(string[])", // 3 - //"sumArray(int[])", - "intsetAndGetA(int)", // 4 - "intsetACAndGetA(string,int)", // 5 - "intcallBack()", // 6 - "voidregisterCallBack(CallBackInterface)", // 7 - "voidregisterCallBack(CallBackInterface[])", // 8 - "registercallback", // 9 - "handleStruct(StructJ[])", // 10 - "structsize" // 11 -}; - - TestClass_Stub::TestClass_Stub() { address = ""; @@ -306,32 +286,22 @@ void TestClass_Stub::handleStruct(vector vecData) { vector TestClass_Stub::handleEnum(vector vecEn) { int numParam = 1; - int methodId = 13; - string retType = "void"; - string paramCls[] = { "int" }; - int enumsize = vecEn.size(); - void* paramObj[] = { &enumsize }; - void* retObj = NULL; - rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj); - - int numParam2 = vecEn.size(); - int methodId2 = 12; - string retType2 = "int[]"; - string paramCls2[numParam2]; + int numEl = vecEn.size(); + int methodId = 12; + string retType = "int[]"; + string paramCls[] = { "int[]" }; // Need to define this container for integer version of enum - int paramEnum[numParam2]; - void* paramObj2[numParam2]; - for(int i = 0; i < numParam2; i++) { - paramCls2[i] = "int"; - paramEnum[i] = (int) vecEn[i]; // cast enum to integer - paramObj2[i] = ¶mEnum[i]; + vector paramInt(numEl); + for(int i = 0; i < numEl; i++) { + paramInt[i] = (int) vecEn[i]; // cast enum to integer } - vector retEnumInt(numParam2); + void* paramObj[] = { ¶mInt }; // 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); + vector retEnumInt; + void* retObj = &retEnumInt; + rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj); int enumsize1 = retEnumInt.size(); vector retVal(enumsize1); for (int i=0; i < enumsize1; i++) { diff --git a/iotjava/iotrmi/Java/sample/TestClass_Skeleton.java b/iotjava/iotrmi/Java/sample/TestClass_Skeleton.java index 73580a2..753e238 100644 --- a/iotjava/iotrmi/Java/sample/TestClass_Skeleton.java +++ b/iotjava/iotrmi/Java/sample/TestClass_Skeleton.java @@ -232,29 +232,17 @@ public class TestClass_Skeleton implements TestClassInterface { } - public int ___enumSize() { - - Object[] paramObj = rmiObj.getMethodParams(new Class[] { int.class }, - new Class[] { null }); - return (int) paramObj[0]; - } + public void ___handleEnum() throws IOException { - - public void ___handleEnum(int enumSize1) throws IOException { - - Class[] paramCls = new Class[enumSize1]; - Class[] paramClsVal = new Class[enumSize1]; - for(int i=0; i < enumSize1; i++) { - paramCls[i] = int.class; - paramClsVal[i] = null; - } - Object[] paramObj = rmiObj.getMethodParams(paramCls, - paramClsVal); + Object[] paramObj = rmiObj.getMethodParams(new Class[] { int[].class }, + new Class[] { null }); // Encoder/decoder + int paramInt[] = (int[]) paramObj[0]; + int enumSize1 = paramInt.length; EnumJ[] enumJ = EnumJ.values(); EnumJ[] data = new EnumJ[enumSize1]; for (int i=0; i < enumSize1; i++) { - data[i] = enumJ[(int) paramObj[i]]; + data[i] = enumJ[paramInt[i]]; } // if void, just "handleEnum(data)" // this is when we have return value EnumJ[] @@ -300,8 +288,7 @@ public class TestClass_Skeleton implements TestClassInterface { // Struct handling (3 is the size of the struct) case 10: ___handleStruct(structSize1); break; case 11: structSize1 = ___structSize(); break; - case 12: ___handleEnum(enumSize1); break; - case 13: enumSize1 = ___enumSize(); break; + case 12: ___handleEnum(); break; default: throw new Error("Method Id not recognized!"); } diff --git a/iotjava/iotrmi/Java/sample/TestClass_Stub.java b/iotjava/iotrmi/Java/sample/TestClass_Stub.java index 2e64275..4a3f323 100644 --- a/iotjava/iotrmi/Java/sample/TestClass_Stub.java +++ b/iotjava/iotrmi/Java/sample/TestClass_Stub.java @@ -243,28 +243,22 @@ public class TestClass_Stub implements TestClassInterface { public EnumJ[] handleEnum(EnumJ[] en) { - // Send length info first - int methodId = 13; - Class retType = void.class; - Class[] paramCls = new Class[] { int.class }; - Object[] paramObj = new Object[] { en.length }; - rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); - - int methodId2 = 12; - Class retType2 = int[].class; - // Calculate the size of the array - Class[] paramCls2 = new Class[en.length]; - Object[] paramObj2 = new Object[en.length]; + int methodId = 12; + Class retType = int[].class; // Handle with for loop + int paramInt[] = new int[en.length]; for(int i = 0; i < en.length; i++) { - paramCls2[i] = int.class; - paramObj2[i] = en[i].ordinal(); + paramInt[i] = en[i].ordinal(); } + + Class[] paramCls = new Class[] { int[].class }; + Object[] paramObj = new Object[] { paramInt }; + // if no return value just - // rmiCall.remoteCall(objectId, methodId2, retType2, null, paramCls2, paramObj2); + // rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); // This is with return value: Object retObj = - rmiCall.remoteCall(objectId, methodId2, retType2, null, paramCls2, paramObj2); + rmiCall.remoteCall(objectId, methodId, retType, null, paramCls, paramObj); int[] retEnumInt = (int[]) retObj; int enumsize1 = retEnumInt.length; // Encoder/decoder -- 2.34.1