Fixing bug for return value from callback in C++ (sendReturnObj is called twice)...
authorrtrimana <rtrimana@uci.edu>
Sat, 5 Nov 2016 19:13:34 +0000 (12:13 -0700)
committerrtrimana <rtrimana@uci.edu>
Sat, 5 Nov 2016 19:13:34 +0000 (12:13 -0700)
14 files changed:
iotjava/Makefile
iotjava/iotrmi/C++/IoTRMICall.hpp
iotjava/iotrmi/C++/IoTRMIObject.hpp
iotjava/iotrmi/C++/IoTSocket.hpp
iotjava/iotrmi/C++/sample/CallBack_CBSkeleton.hpp
iotjava/iotrmi/C++/sample/CallBack_Skeleton.hpp
iotjava/iotrmi/C++/sample/TestClass.hpp
iotjava/iotrmi/C++/sample/TestClass_Skeleton.hpp
iotjava/iotrmi/C++/sample/TestClass_Stub.cpp
iotjava/iotrmi/C++/sample/TestClass_Stub.hpp
iotjava/iotrmi/Java/sample/CallBack_CBSkeleton.java
iotjava/iotrmi/Java/sample/CallBack_Skeleton.java
iotjava/iotrmi/Java/sample/TestClass_Skeleton.java
iotjava/iotrmi/Java/sample/TestClass_Stub.java

index 3d7b7f0..70bce37 100644 (file)
@@ -33,23 +33,24 @@ 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
-       mkdir -p $(BIN_DIR)/iotrmi/C++
+#      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++/IoTRMICall.cpp -o $(BIN_DIR)/iotrmi/C++/IoTRMICall.out --std=c++11
 #      $(G++) iotrmi/C++/IoTRMIObject.cpp -o $(BIN_DIR)/iotrmi/C++/IoTRMIObject.out --std=c++11
 #      mkdir -p $(BIN_DIR)/iotrmi/C++/sample
-       $(G++) iotrmi/C++/sample/CallBackInterface.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBackInterface.out --std=c++11
-       $(G++) iotrmi/C++/sample/CallBack.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack.out --std=c++11
-       $(G++) iotrmi/C++/sample/CallBack_CBStub.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_CBStub.out --std=c++11
-       $(G++) iotrmi/C++/sample/CallBack_CBSkeleton.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_CBSkeleton.out --std=c++11
+       #$(G++) iotrmi/C++/sample/CallBackInterface.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBackInterface.out --std=c++11
+       #$(G++) iotrmi/C++/sample/CallBack.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack.out --std=c++11
+       #$(G++) iotrmi/C++/sample/CallBack_CBStub.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_CBStub.out --std=c++11
+       #$(G++) iotrmi/C++/sample/CallBack_CBSkeleton.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_CBSkeleton.out --std=c++11
        $(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
-       $(G++) iotrmi/C++/sample/TestClass_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_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/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/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
 
 
 PHONY += run-rmiserver
index c749b02..3637809 100644 (file)
@@ -88,15 +88,12 @@ void* IoTRMICall::remoteCall(int objectId, string methodSign, string retType, st
        // Send input parameters
        int len = methodLength(paramCls, paramObj, numParam);
        char method[len];
-       cout << "Got in remoteCall!" << endl;
        methodToBytes(objectId, methodSign, paramCls, paramObj, method, numParam);
-       cout << "Executed methodToBytes in remoteCall!" << endl;
-       IoTRMIUtil::printBytes(method, len, false);
+//     IoTRMIUtil::printBytes(method, len, false);
        // Send bytes
        fflush(NULL);
        rmiClient->sendBytes(method, len);
        fflush(NULL);
-       cout << "Got in remoteCall! 2" << endl;
        // Receive return value and return it to caller
        if (retType.compare("void") == 0)
                // Just make it NULL if it's a void return
@@ -105,7 +102,7 @@ void* IoTRMICall::remoteCall(int objectId, string methodSign, string retType, st
                int retLen = 0;
                char* retObjBytes = NULL;
                retObjBytes = rmiClient->receiveBytes(retObjBytes, &retLen);
-               IoTRMIUtil::printBytes(retObjBytes, retLen, false);
+//             IoTRMIUtil::printBytes(retObjBytes, retLen, false);
                retObj = IoTRMIUtil::getParamObject(retObj, retType.c_str(), retObjBytes, retLen);
        }
        
index 084fb7b..830be11 100644 (file)
@@ -106,10 +106,8 @@ void IoTRMIObject::sendReturnObj(void* retObj, string type) {
 char* IoTRMIObject::getMethodBytes() {
 
        // Get method in bytes and update method length
-       cout << "Got into getMethodBytes()" << endl;
        //fflush(NULL);
        methodBytes = rmiServer->receiveBytes(methodBytes, &methodLen);
-       cout << "Got into getMethodBytes() 2" << endl;
        fflush(NULL);
        return methodBytes;
 }
index 54f0234..642882f 100644 (file)
@@ -159,7 +159,6 @@ char* IoTSocket::receiveBytes(char* pVals, int* len)
        if (!receiveAck())
                return NULL;
 #endif
-       cout << "Socket 6!" << endl;
        return pVals;
 }
 
index 7ed5f04..510ed64 100644 (file)
@@ -13,9 +13,12 @@ class CallBack_CBSkeleton : public CallBackInterface {
                CallBack_CBSkeleton(CallBackInterface* _cb, int _objectId);
                ~CallBack_CBSkeleton();
 
-               void*                                   invokeMethod(IoTRMIObject* rmiObj, string *type);
-               int                                             printInt();
-               void                                    setInt(int _i);
+               void                    invokeMethod(IoTRMIObject* rmiObj);
+               int                             printInt();
+               void                    setInt(int _i);
+
+               void                    ___printInt(IoTRMIObject* rmiObj);
+               void                    ___setInt(IoTRMIObject* rmiObj);
 
                const static int                size = 2;
                const static string     methodSignatures[size];
@@ -47,47 +50,21 @@ CallBack_CBSkeleton::~CallBack_CBSkeleton() {
 }
 
 
-void* CallBack_CBSkeleton::invokeMethod(IoTRMIObject* rmiObj, string *type) {
-
-       // Loop continuously waiting for incoming bytes
-       void* retObj = NULL;
-       cout << "Get inside invoke method!" << endl;
-
-       //rmiObj->getMethodBytes();
-       cout << "Get inside invoke 2!" << endl;
-       string methodSign = rmiObj->getSignature();
-       cout << "Get inside invoke 3!" << endl;
-       cout << "Method sign: " << methodSign << endl;
-       
-       if (methodSign.compare("intprintInt()") == 0) {
-               string paramCls[] = { };
-               int numParam = 0;
-               void* paramObj[] = { };
-               rmiObj->getMethodParams(paramCls, numParam, paramObj);
-               int retVal = printInt();
-               retObj = &retVal;
-               *type = "int";
-               rmiObj->sendReturnObj(retObj, "int");
-       } else if (methodSign.compare("voidsetInt(int)") == 0) {
-               string paramCls[] = { "int" };
-               int numParam = 1;
-               int param1 = 1;
-               void* paramObj[] = { &param1 };
-               rmiObj->getMethodParams(paramCls, numParam, paramObj);
-               setInt(param1);
-               *type = "void";
-       } else {
-               string error = "Signature not recognized: " + string(methodSign);
-               throw error;
-       }
+int CallBack_CBSkeleton::printInt() {
 
-       return retObj;
+       return cb->printInt();
 }
 
 
-int CallBack_CBSkeleton::printInt() {
+void CallBack_CBSkeleton::___printInt(IoTRMIObject* rmiObj) {
 
-       return cb->printInt();
+       string paramCls[] = { };
+       int numParam = 0;
+       void* paramObj[] = { };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       int retVal = printInt();
+       void* retObj = &retVal;
+       rmiObj->sendReturnObj(retObj, "int");
 }
 
 
@@ -96,5 +73,32 @@ void CallBack_CBSkeleton::setInt(int _i) {
        cb->setInt(_i);
 }
 
+
+void CallBack_CBSkeleton::___setInt(IoTRMIObject* rmiObj) {
+
+       string paramCls[] = { "int" };
+       int numParam = 1;
+       int param1 = 1;
+       void* paramObj[] = { &param1 };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       setInt(param1);
+}
+
+
+void CallBack_CBSkeleton::invokeMethod(IoTRMIObject* rmiObj) {
+
+       string methodSign = rmiObj->getSignature();
+       
+       if (methodSign.compare("intprintInt()") == 0) {
+               ___printInt(rmiObj);
+       } else if (methodSign.compare("voidsetInt(int)") == 0) {
+               ___setInt(rmiObj);
+       } else {
+               string error = "Signature not recognized: " + string(methodSign);
+               throw error;
+       }
+}
+
+
 #endif
 
index b087046..ff80e02 100644 (file)
@@ -12,10 +12,13 @@ class CallBack_Skeleton : public CallBackInterface {
                CallBack_Skeleton(CallBackInterface* _cb, int _port);
                ~CallBack_Skeleton();
 
-               void                    waitRequestInvokeMethod();
+               void                    ___waitRequestInvokeMethod();
                int                             printInt();
                void                    setInt(int _i);
 
+               void                    ___printInt();
+               void                    ___setInt();
+
                const static int size = 2;
                const static string methodSignatures[size];
 
@@ -38,7 +41,7 @@ CallBack_Skeleton::CallBack_Skeleton(CallBackInterface* _cb, int _port) {
        bool _bResult = false;
        cb = _cb;
        rmiObj = new IoTRMIObject(_port, &_bResult, methodSignatures, size);
-       waitRequestInvokeMethod();
+       ___waitRequestInvokeMethod();
 }
 
 
@@ -51,7 +54,42 @@ CallBack_Skeleton::~CallBack_Skeleton() {
 }
 
 
-void CallBack_Skeleton::waitRequestInvokeMethod() {
+int CallBack_Skeleton::printInt() {
+
+       return cb->printInt();
+}
+
+
+void CallBack_Skeleton::___printInt() {
+
+       string paramCls[] = { };
+       int numParam = 0;
+       void* paramObj[] = { };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       int retVal = printInt();
+       void* retObj = &retVal;
+       rmiObj->sendReturnObj(retObj, "int");
+}
+
+
+void CallBack_Skeleton::setInt(int _i) {
+
+       cb->setInt(_i);
+}
+
+
+void CallBack_Skeleton::___setInt() {
+
+       string paramCls[] = { "int" };
+       int numParam = 1;
+       int param1 = 1;
+       void* paramObj[] = { &param1 };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       setInt(param1);
+}
+
+
+void CallBack_Skeleton::___waitRequestInvokeMethod() {
 
        // Loop continuously waiting for incoming bytes
        while (true) {
@@ -61,20 +99,9 @@ void CallBack_Skeleton::waitRequestInvokeMethod() {
                cout << "Method sign: " << methodSign << endl;
                
                if (methodSign.compare("intprintInt()") == 0) {
-                       string paramCls[] = { };
-                       int numParam = 0;
-                       void* paramObj[] = { };
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       int retVal = printInt();
-                       void* retObj = &retVal;
-                       rmiObj->sendReturnObj(retObj, "int");
+                       ___printInt();
                } else if (methodSign.compare("voidsetInt(int)") == 0) {
-                       string paramCls[] = { "int" };
-                       int numParam = 1;
-                       int param1 = 1;
-                       void* paramObj[] = { &param1 };
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       setInt(param1);
+                       ___setInt();
                } else {
                        string error = "Signature not recognized: " + string(methodSign);
                        throw error;
@@ -83,16 +110,5 @@ void CallBack_Skeleton::waitRequestInvokeMethod() {
 }
 
 
-int CallBack_Skeleton::printInt() {
-
-       return cb->printInt();
-}
-
-
-void CallBack_Skeleton::setInt(int _i) {
-
-       cb->setInt(_i);
-}
-
 #endif
 
index 61dd2e3..0384f22 100644 (file)
@@ -146,8 +146,8 @@ int TestClass::callBack() {
        int sum = 0;
        for (CallBackInterface* cb : cbvec) {
                //cout << "Sum: " << sum << endl;
-               //sum = sum + cb->printInt();
-               cb->setInt(sum++);
+               sum = sum + cb->printInt();
+               //cb->setInt(sum++);
        }
        //CallBackInterface* cb = cbvec[0];
        //sum = cb->printInt();
index b5452c0..dd66cc6 100644 (file)
@@ -14,7 +14,7 @@ class TestClass_Skeleton : public TestClassInterface {
                TestClass_Skeleton(TestClassInterface* _tc, int _port);
                ~TestClass_Skeleton();
 
-               void                    waitRequestInvokeMethod();
+               void                    ___waitRequestInvokeMethod();
                void                    setA(int _int);
                void                    setB(float _float);
                void                    setC(string _string);
@@ -26,6 +26,22 @@ class TestClass_Skeleton : public TestClassInterface {
                void                    registerCallback(vector<CallBackInterface*> _cb);
                int                             callBack();
                void                    handleStruct(vector<data> vecData);
+               
+               void                    ___setA();
+               void                    ___setB();
+               void                    ___setC();
+               void                    ___sumArray();
+               //int64_t               ____sumArray();
+               void                    ___setAndGetA();
+               void                    ___setACAndGetA();
+               void                    ___registerCallback();
+               void                    ____registerCallback();
+               // For array of callbacks
+               void                    ___regCB();
+               void                    ___callBack();
+               // For array of structs
+               int                             ___structSize();
+               void                    ___handleStruct(int structsize1);
 
                const static int        size = 12;
                const static string methodSignatures[size];
@@ -64,10 +80,8 @@ TestClass_Skeleton::TestClass_Skeleton(TestClassInterface* _tc, int _port) {
 
        bool _bResult = false;
        tc = _tc;
-       cout << "Reached here 1!" << endl;
        rmiObj = new IoTRMIObject(_port, &_bResult, methodSignatures, size);
-       cout << "Reached here 2!" << endl;
-       waitRequestInvokeMethod();
+       ___waitRequestInvokeMethod();
 }
 
 
@@ -88,155 +102,20 @@ TestClass_Skeleton::~TestClass_Skeleton() {
 }
 
 
-void TestClass_Skeleton::waitRequestInvokeMethod() {
-
-       int structsize1 = 0;
-       // Loop continuously waiting for incoming bytes
-       while (true) {
+void TestClass_Skeleton::setA(int _int) {
 
-               rmiObj->getMethodBytes();
-               string methodSign = rmiObj->getSignature();
-               cout << "Method sign: " << methodSign << endl;
-               
-               if (methodSign.compare("voidsetA(int)") == 0) {
-                       string paramCls[] = { "int" };
-                       int numParam = 1;
-                       int param1 = 0;
-                       void* paramObj[] = { &param1 };
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       setA(param1);
-               } else if (methodSign.compare("voidsetB(float)") == 0) {
-                       string paramCls[] = { "float" };
-                       int numParam = 1;
-                       float param1 = 0.0;
-                       void* paramObj[] = { &param1 };
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       setB(param1);
-               } else if (methodSign.compare("voidsetC(string)") == 0) {
-                       string paramCls[] = { "string" };
-                       int numParam = 1;
-                       string param1 = "";
-                       void* paramObj[] = { &param1 };
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       setC(param1);
-               } else if (methodSign.compare("sumArray(string[])") == 0) {
-                       string paramCls[] = { "string[]" };
-                       int numParam = 1;
-                       vector<string> param1;
-                       void* paramObj[] = { &param1 };
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       string retVal = sumArray(param1);
-                       void* retObj = &retVal;
-                       rmiObj->sendReturnObj(retObj, "string");
-               /*} else if (methodSign.compare("sumArray(int[])") == 0) {
-                       string paramCls[] = { "int[]" };
-                       int numParam = 1;
-                       vector<int> param1;
-                       void* paramObj[] = { &param1 };
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       int64_t retVal = sumArray(param1);              
-                       void* retObj = &retVal;
-                       rmiObj->sendReturnObj(retObj, "long");*/
-               } else if (methodSign.compare("intsetAndGetA(int)") == 0) {
-                       string paramCls[] = { "int" };
-                       int numParam = 1;
-                       int param1 = 0;
-                       void* paramObj[] = { &param1 };
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       int retVal = setAndGetA(param1);
-                       void* retObj = &retVal;
-                       rmiObj->sendReturnObj(retObj, "int");
-               } else if (methodSign.compare("intsetACAndGetA(string,int)") == 0) {
-                       string paramCls[] = { "string", "int" };
-                       int numParam = 2;
-                       string param1 = "";
-                       int param2 = 0;
-                       void* paramObj[] = { &param1, &param2 };
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       int retVal = setACAndGetA(param1, param2);
-                       void* retObj = &retVal;
-                       rmiObj->sendReturnObj(retObj, "int");
-               /*} else if (methodSign.compare("voidregisterCallBack(CallBackInterface)") == 0) {
-                       //*/
-               } else if (methodSign.compare("voidregisterCallBack(CallBackInterface[])") == 0) {
-                       string paramCls[] = { "int" };
-                       int numParam = 1;
-                       int numStubs = 0;
-                       void* paramObj[] = { &numStubs };
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       vector<CallBackInterface*> stub;
-                       for (int objId = 0; objId < numStubs; objId++) {
-                               CallBackInterface* cb = new CallBack_CBStub(rmiCall, objIdCnt);
-                               stub.push_back(cb);
-                               vecCBObj.push_back(cb);
-                               objIdCnt++;
-                       }
-                       registerCallback(stub);
-               } else if (methodSign.compare("registercallback") == 0) {
-                       string paramCls[] = { "int", "string", "int" };
-                       int numParam = 3;
-                       int param1 = 0;
-                       string param2 = "";
-                       int param3 = 0;
-                       void* paramObj[] = { &param1, &param2, &param3 };
-                       cout << "Get here! Registering callback!" << endl;
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       // Instantiate IoTRMICall object
-                       bool bResult = false;
-                       rmiCall = new IoTRMICall(param1, param2.c_str(), param3, &bResult, 
-                               CallBack_CBStub::methodSignatures, CallBack_CBStub::size);
-               } else if (methodSign.compare("intcallBack()") == 0) {
-                       cout << "Get here inside callback!!!" << endl;
-                       int retVal = callBack();
-                       cout << "Return value in TestClass_Skeleton: " << retVal << endl;
-                       void* retObj = &retVal;
-                       rmiObj->sendReturnObj(retObj, "int");
-               // Handle struct
-               } else if (methodSign.compare("structsize") == 0) {
-                       string paramCls[] = { "int" };
-                       int numParam = 1;
-                       int param1 = 0;
-                       void* paramObj[] = { &param1 };
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       structsize1 = param1;
-                       cout << "Struct size: " << structsize1 << endl;
-               } else if (methodSign.compare("handleStruct(StructJ[])") == 0) {
-                       string paramCls[3*structsize1];
-                       void* paramObj[3*structsize1];
-                       int numParam = 3*structsize1;
-                       // define array of everything
-                       string param1[structsize1];
-                       float param2[structsize1];
-                       int param3[structsize1];
-                       int pos = 0;
-                       for(int i=0; i < structsize1; i++) {
-                               paramCls[pos] = "string";
-                               paramObj[pos++] = &param1[i];
-                               paramCls[pos] = "float";
-                               paramObj[pos++] = &param2[i];
-                               paramCls[pos] = "int";
-                               paramObj[pos++] = &param3[i];
-                       }
-                       rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       vector<data> dat(structsize1);
-                       pos = 0;
-                       for (int i=0; i < structsize1; i++) {
-                               dat[i].name = param1[i];
-                               dat[i].value = param2[i];
-                               dat[i].year = param3[i];
-                       }
-                       handleStruct(dat);
-               } else {
-                       string error = "Signature unrecognized: " + string(methodSign);
-                       throw error;
-               }
-       }
+       tc->setA(_int);
 }
 
 
-void TestClass_Skeleton::setA(int _int) {
+void TestClass_Skeleton::___setA() {
 
-       tc->setA(_int);
+       string paramCls[] = { "int" };
+       int numParam = 1;
+       int param1 = 0;
+       void* paramObj[] = { &param1 };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       setA(param1);
 }
 
 
@@ -246,15 +125,50 @@ void TestClass_Skeleton::setB(float _float) {
 }
 
 
+void TestClass_Skeleton::___setB() {
+
+       string paramCls[] = { "float" };
+       int numParam = 1;
+       float param1 = 0.0;
+       void* paramObj[] = { &param1 };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       setB(param1);
+}
+
+
 void TestClass_Skeleton::setC(string _string) {
 
        tc->setC(_string);
 }
 
 
+void TestClass_Skeleton::___setC() {
+
+       string paramCls[] = { "string" };
+       int numParam = 1;
+       string param1 = "";
+       void* paramObj[] = { &param1 };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       setC(param1);
+}
+
+
 string TestClass_Skeleton::sumArray(vector<string> newA) {
 
-       return tc->sumArray(newA);;
+       return tc->sumArray(newA);
+}
+
+
+void TestClass_Skeleton::___sumArray() {
+
+       string paramCls[] = { "string[]" };
+       int numParam = 1;
+       vector<string> param1;
+       void* paramObj[] = { &param1 };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       string retVal = sumArray(param1);
+       void* retObj = &retVal;
+       rmiObj->sendReturnObj(retObj, "string");
 }
 
 
@@ -264,40 +178,206 @@ string TestClass_Skeleton::sumArray(vector<string> newA) {
 }*/
 
 
+/*int64_t TestClass_Skeleton::____sumArray() {
+
+}*/
+
+
 int TestClass_Skeleton::setAndGetA(int newA) {
 
        return tc->setAndGetA(newA);
 }
 
 
+void TestClass_Skeleton::___setAndGetA() {
+
+       string paramCls[] = { "int" };
+       int numParam = 1;
+       int param1 = 0;
+       void* paramObj[] = { &param1 };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       int retVal = setAndGetA(param1);
+       void* retObj = &retVal;
+       rmiObj->sendReturnObj(retObj, "int");
+}
+
+
 int TestClass_Skeleton::setACAndGetA(string newC, int newA) {
 
        return tc->setACAndGetA(newC, newA);
 }
 
 
+void TestClass_Skeleton::___setACAndGetA() {
+
+       string paramCls[] = { "string", "int" };
+       int numParam = 2;
+       string param1 = "";
+       int param2 = 0;
+       void* paramObj[] = { &param1, &param2 };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       int retVal = setACAndGetA(param1, param2);
+       void* retObj = &retVal;
+       rmiObj->sendReturnObj(retObj, "int");
+}
+
+
 void TestClass_Skeleton::registerCallback(CallBackInterface* _cb) {
 
        tc->registerCallback(_cb);
 }
 
 
+void TestClass_Skeleton::___registerCallback() {
+
+}
+
+
 void TestClass_Skeleton::registerCallback(vector<CallBackInterface*> _cb) {
 
        tc->registerCallback(_cb);
 }
 
 
+void TestClass_Skeleton::___regCB() {
+
+       string paramCls[] = { "int", "string", "int" };
+       int numParam = 3;
+       int param1 = 0;
+       string param2 = "";
+       int param3 = 0;
+       void* paramObj[] = { &param1, &param2, &param3 };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       // Instantiate IoTRMICall object
+       bool bResult = false;
+       rmiCall = new IoTRMICall(param1, param2.c_str(), param3, &bResult, 
+               CallBack_CBStub::methodSignatures, CallBack_CBStub::size);
+}
+
+
+void TestClass_Skeleton::____registerCallback() {
+
+       string paramCls[] = { "int" };
+       int numParam = 1;
+       int numStubs = 0;
+       void* paramObj[] = { &numStubs };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       vector<CallBackInterface*> stub;
+       for (int objId = 0; objId < numStubs; objId++) {
+               CallBackInterface* cb = new CallBack_CBStub(rmiCall, objIdCnt);
+               stub.push_back(cb);
+               vecCBObj.push_back(cb);
+               objIdCnt++;
+       }
+       registerCallback(stub);
+}
+
+
 int TestClass_Skeleton::callBack() {
 
        tc->callBack();
 }
 
 
+void TestClass_Skeleton::___callBack() {
+
+       int retVal = callBack();
+       void* retObj = &retVal;
+       rmiObj->sendReturnObj(retObj, "int");
+}
+
+
+int TestClass_Skeleton::___structSize() {
+
+       string paramCls[] = { "int" };
+       int numParam = 1;
+       int param1 = 0;
+       void* paramObj[] = { &param1 };
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       return param1;
+}
+
+
 void TestClass_Skeleton::handleStruct(vector<data> vecData) {
 
        tc->handleStruct(vecData);
 }
 
+
+void TestClass_Skeleton::___handleStruct(int structsize1) {
+
+       string paramCls[3*structsize1];
+       void* paramObj[3*structsize1];
+       int numParam = 3*structsize1;
+       // define array of everything
+       string param1[structsize1];
+       float param2[structsize1];
+       int param3[structsize1];
+       int pos = 0;
+       for(int i=0; i < structsize1; i++) {
+               paramCls[pos] = "string";
+               paramObj[pos++] = &param1[i];
+               paramCls[pos] = "float";
+               paramObj[pos++] = &param2[i];
+               paramCls[pos] = "int";
+               paramObj[pos++] = &param3[i];
+       }
+       rmiObj->getMethodParams(paramCls, numParam, paramObj);
+       vector<data> dat(structsize1);
+       pos = 0;
+       for (int i=0; i < structsize1; i++) {
+               dat[i].name = param1[i];
+               dat[i].value = param2[i];
+               dat[i].year = param3[i];
+       }
+       handleStruct(dat);
+}
+
+
+void TestClass_Skeleton::___waitRequestInvokeMethod() {
+
+       int structsize1 = 0;
+       // Loop continuously waiting for incoming bytes
+       while (true) {
+
+               rmiObj->getMethodBytes();
+               string methodSign = rmiObj->getSignature();
+               cout << "Method sign: " << methodSign << endl;
+               
+               if (methodSign.compare("voidsetA(int)") == 0) {
+                       ___setA();
+               } else if (methodSign.compare("voidsetB(float)") == 0) {
+                       ___setB();
+               } else if (methodSign.compare("voidsetC(string)") == 0) {
+                       ___setC();
+               } else if (methodSign.compare("sumArray(string[])") == 0) {
+                       ___sumArray();
+               /*} else if (methodSign.compare("sumArray(int[])") == 0) {
+                       ____sumArray();*/
+               } else if (methodSign.compare("intsetAndGetA(int)") == 0) {
+                       ___setAndGetA();
+               } else if (methodSign.compare("intsetACAndGetA(string,int)") == 0) {
+                       ___setACAndGetA();
+               } else if (methodSign.compare("voidregisterCallBack(CallBackInterface)") == 0) {
+                       //
+               } else if (methodSign.compare("voidregisterCallBack(CallBackInterface[])") == 0) {
+                       ____registerCallback();
+               } else if (methodSign.compare("registercallback") == 0) {
+                       ___regCB();
+               } else if (methodSign.compare("intcallBack()") == 0) {
+                       ___callBack();
+               // Handle struct
+               } else if (methodSign.compare("structsize") == 0) {
+                       structsize1 = ___structSize();
+               } else if (methodSign.compare("handleStruct(StructJ[])") == 0) {
+                       ___handleStruct(structsize1);
+               } else {
+                       string error = "Signature unrecognized: " + string(methodSign);
+                       throw error;
+               }
+       }
+}
+
+
 #endif
 
index d56d39d..4067dcb 100644 (file)
@@ -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<CallBackInterface*> cb;
@@ -40,11 +40,6 @@ int main(int argc, char *argv[])
        tcStub->registerCallback(cb);
        cout << "Return value from callback: " << tcStub->callBack() << endl;
 
-       delete tcStub;
-       delete cb1;
-       delete cb2;
-       delete cb3;*/
-
        vector<data> dataset;
 
        data testdata;
@@ -63,5 +58,9 @@ int main(int argc, char *argv[])
        tcStub->handleStruct(dataset);
 
        delete tcStub;
+       delete cb1;
+       delete cb2;
+       delete cb3;
+
        return 0;
 }
index 39ede87..db12b48 100644 (file)
@@ -83,12 +83,10 @@ TestClass_Stub::TestClass_Stub(int _port, const char* _address, int _rev, bool*
        rmiCall = new IoTRMICall(_port, _address, _rev, _bResult, methodSignatures, size);
        ports = _ports;
        // Start thread
-       cout << "Reached here 1!" << endl;
-//     thread th1 (&TestClass_Stub::____init_CallBack, this);
-//     th1.detach();
+       thread th1 (&TestClass_Stub::____init_CallBack, this);
+       th1.detach();
        //th1.join();
-       cout << "Reached here 2!" << endl;
-//     ____registerCallBack();
+       ____registerCallBack();
 }
 
 
@@ -113,27 +111,14 @@ TestClass_Stub::~TestClass_Stub() {
 void TestClass_Stub::____init_CallBack() {
 
        bool bResult = false;
-       cout << "Reach here init!" << endl;
        rmiObj = new IoTRMIObject(ports[0], &bResult, CallBack_CBSkeleton::methodSignatures, CallBack_CBSkeleton::size);
-       cout << "Reach here init 2!" << endl;
        while (true) {
                char* method = rmiObj->getMethodBytes();
-               cout << "Get method bytes here: " << endl;
-               IoTRMIUtil::printBytes(method, rmiObj->getMethodBytesLen(), false);
                int objId = IoTRMIObject::getObjectId(method);
                if (objId < vecCBObj.size()) {  // Check if still within range
                        CallBack_CBSkeleton* skel = 
                                dynamic_cast<CallBack_CBSkeleton*> (vecCBObj.at(objId));
-                       cout << "Dynamic cast done!" << endl;
-                       //rmiObj->setMethodBytes(method);
-                       string type = "";
-                       cout << "About to execute invoke method!" << endl;
-                       void* retObj = skel->invokeMethod(rmiObj, &type);
-                       cout << "Executed invoke method!" << endl;
-                       if (type != "void") {
-                               rmiObj->sendReturnObj(retObj, type);
-                               cout << "Sent return object!" << endl;
-                       }
+                       skel->invokeMethod(rmiObj);
                } else {
                        string error = "TestClass_Stub: Illegal object Id: " + to_string(objId);
                        throw error;
@@ -152,9 +137,7 @@ void TestClass_Stub::____registerCallBack() {
        int rev = 0;
        void* paramObj[] = { &ports[0], &address, &rev };
        void* retObj = NULL;
-       cout << "Get here! 1" << endl;
        rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
-       cout << "Get here! 2" << endl;
 }
 
 
index c038ec7..2c8ece3 100644 (file)
@@ -28,6 +28,28 @@ public class CallBack_CBSkeleton implements CallBackInterface {
                System.out.println("Creating CallBack_Skeleton and waiting!");
        }
 
+       
+       public int printInt() {
+               return cb.printInt();
+       }
+       
+       
+       public int ___printInt() {
+               return printInt();
+       }
+
+
+       public void setInt(int _i) {
+               cb.setInt(_i);
+       }
+       
+       
+       public void ___setInt(IoTRMIObject rmiObj) {
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
+                       new Class<?>[] { null }, new Class<?>[] { null });
+               setInt((int) paramObj[0]);
+       }
+       
 
        public Object invokeMethod(IoTRMIObject rmiObj) throws IOException {
 
@@ -36,11 +58,9 @@ public class CallBack_CBSkeleton implements CallBackInterface {
                Object retObj = null;
 
                if (methodSign.equals("intprintInt()")) {
-                       retObj = printInt();
+                       retObj = ___printInt();
                } else if (methodSign.equals("voidsetInt(int)")) {
-                       paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                               new Class<?>[] { null }, new Class<?>[] { null });
-                       setInt((int) paramObj[0]);
+                       ___setInt(rmiObj);
                } else
                        throw new Error("Signature not recognized!");
                System.out.println("Return object: " + retObj);
@@ -56,21 +76,7 @@ public class CallBack_CBSkeleton implements CallBackInterface {
        }
 
 
-       public int printInt() {
-               return cb.printInt();
-       }
-
-
-       public void setInt(int _i) {
-               cb.setInt(_i);
-       }
-
-
        public static void main(String[] args) throws Exception {
 
-               int port = 5010;
-               CallBack cb = new CallBack(23);
-               CallBack_Skeleton cbSkel = new CallBack_Skeleton(cb, port);
-               cbSkel.waitRequestInvokeMethod();
        }
 }
index 70d8a81..8c587f8 100644 (file)
@@ -27,10 +27,33 @@ public class CallBack_Skeleton implements CallBackInterface {
                cb = _cb;
                System.out.println("Creating CallBack_Skeleton and waiting!");
                rmiObj = new IoTRMIObject(_port, methodSignatures);
+               ___waitRequestInvokeMethod();
        }
 
 
-       public void waitRequestInvokeMethod() throws IOException {
+       public int printInt() {
+               return cb.printInt();
+       }
+       
+       
+       public int ___printInt() {
+               return printInt();
+       }
+
+
+       public void setInt(int _i) {
+               cb.setInt(_i);
+       }
+       
+       
+       public void ___setInt() {
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
+                       new Class<?>[] { null }, new Class<?>[] { null });
+               setInt((int) paramObj[0]);
+       }
+       
+
+       private void ___waitRequestInvokeMethod() throws IOException {
 
                // Loop continuously waiting for incoming bytes
                while (true) {
@@ -46,11 +69,9 @@ public class CallBack_Skeleton implements CallBackInterface {
                                System.out.println("Method sign: " + methodSign);
 
                                if (methodSign.equals("intprintInt()")) {
-                                       retObj = printInt();
+                                       retObj = ___printInt();
                                } else if (methodSign.equals("voidsetInt(int)")) {
-                                       paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                                               new Class<?>[] { null }, new Class<?>[] { null });
-                                       setInt((int) paramObj[0]);
+                                       ___setInt();
                                } else
                                        throw new Error("Signature not recognized!");
                                System.out.println("Return object: " + retObj);
@@ -71,21 +92,11 @@ public class CallBack_Skeleton implements CallBackInterface {
        }
 
 
-       public int printInt() {
-               return cb.printInt();
-       }
-
-
-       public void setInt(int _i) {
-               cb.setInt(_i);
-       }
-
-
        public static void main(String[] args) throws Exception {
 
                int port = 5010;
                CallBack cb = new CallBack(23);
                CallBack_Skeleton cbSkel = new CallBack_Skeleton(cb, port);
-               cbSkel.waitRequestInvokeMethod();
+               //cbSkel.waitRequestInvokeMethod();
        }
 }
index a115615..a164740 100644 (file)
@@ -49,127 +49,9 @@ public class TestClass_Skeleton implements TestClassInterface {
                tc = _tc;
                port = _port;
                rmiObj = new IoTRMIObject(_port, methodSignatures);
-               waitRequestInvokeMethod();
+               ___waitRequestInvokeMethod();
        }
 
-
-       public void waitRequestInvokeMethod() throws IOException {
-
-               // Struct size
-               int structsize1 = 0;
-               // Loop continuously waiting for incoming bytes
-               while (true) {
-
-                       rmiObj.getMethodBytes();
-                       int _objectId = rmiObj.getObjectId();
-                       if (_objectId == objectId) {
-                       // Multiplex based on object Id
-                               String methodSign = rmiObj.getSignature();
-                               Object[] paramObj = null;
-                               Object retObj = null;
-
-                               if (methodSign.equals("voidsetA(int)")) {
-                                       paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                                               new Class<?>[] { null }, new Class<?>[] { null });
-                                       setA((int) paramObj[0]);
-                               } else if (methodSign.equals("voidsetB(float)")) {
-                                       paramObj = rmiObj.getMethodParams(new Class<?>[] { float.class }, 
-                                               new Class<?>[] { null }, new Class<?>[] { null });
-                                       setB((float) paramObj[0]);
-                               } else if (methodSign.equals("voidsetC(string)")) {
-                                       paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class }, 
-                                               new Class<?>[] { null }, new Class<?>[] { null });
-                                       setC((String) paramObj[0]);
-                               } else if (methodSign.equals("sumArray(string[])")) {
-                                       paramObj = rmiObj.getMethodParams(new Class<?>[] { String[].class }, 
-                                               new Class<?>[] { null }, new Class<?>[] { null });
-                                       retObj = sumArray((String[]) paramObj[0]);
-                               } else if (methodSign.equals("intsetAndGetA(int)")) {
-                                       paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                                               new Class<?>[] { null }, new Class<?>[] { null });
-                                       retObj = setAndGetA((int) paramObj[0]);
-                               } else if (methodSign.equals("intsetACAndGetA(string,int)")) {
-                                       paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class, int.class }, 
-                                               new Class<?>[] { null, null }, new Class<?>[] { null, null });
-                                       retObj = setACAndGetA((String) paramObj[0], (int) paramObj[1]);
-                               } else if (methodSign.equals("voidregisterCallBack(CallBackInterface)")) {
-                                       paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class }, 
-                                               new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
-                                       CallBackInterface cbstub = new CallBack_Stub((int) paramObj[0], (String) paramObj[1], (int) paramObj[2]);
-                                       registerCallback((CallBackInterface) cbstub);
-                               } else if (methodSign.equals("voidregisterCallBack(CallBackInterface[])")) {
-                                       paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                                               new Class<?>[] { null }, new Class<?>[] { null });
-                                       //String[] methodSignatures = CallBack_CBStub.getMethodSignatures();
-                                       //IoTRMICall rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], (int) paramObj[2], methodSignatures);
-                                       int numStubs = (int) paramObj[0];
-                                       CallBackInterface[] stub = new CallBackInterface[numStubs];
-                                       for (int objId = 0; objId < numStubs; objId++) {
-                                               stub[objId] = new CallBack_CBStub(rmiCall, objIdCnt);
-                                               objIdCnt++;
-                                       }
-                                       registerCallback(stub);
-                               } else if (methodSign.equals("intcallBack()")) {
-                                       retObj = callBack();
-                               // Special option to register callback
-                               } else if (methodSign.equals("registercallback")) {
-                                       paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class }, 
-                                               new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
-                                       String[] methodSignatures = CallBack_CBStub.getMethodSignatures();
-                                       rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], (int) paramObj[2], methodSignatures);
-                                       System.out.println("Creating a new IoTRMICall object");
-                               // Struct handling (3 is the size of the struct)
-                               } else if (methodSign.equals("structsize")) {
-                                       paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
-                                               new Class<?>[] { null }, new Class<?>[] { null });
-                                       structsize1 = (int) paramObj[0];
-                               } else if (methodSign.equals("handleStruct(StructJ[])")) {
-                                       Class<?>[] paramCls = new Class<?>[3*structsize1];
-                                       Class<?>[] paramClsTyp1 = new Class<?>[3*structsize1];
-                                       Class<?>[] paramClsTyp2 = new Class<?>[3*structsize1];
-                                       int pos = 0;
-                                       for(int i=0; i < structsize1; i++) {
-                                               paramCls[pos] = String.class;
-                                               paramClsTyp1[pos] = null;
-                                               paramClsTyp2[pos++] = null;
-                                               paramCls[pos] = float.class;
-                                               paramClsTyp1[pos] = null;
-                                               paramClsTyp2[pos++] = null;
-                                               paramCls[pos] = int.class;
-                                               paramClsTyp1[pos] = null;
-                                               paramClsTyp2[pos++] = null;
-                                       }
-                                       paramObj = rmiObj.getMethodParams(paramCls, 
-                                               paramClsTyp1, paramClsTyp2);
-                                       StructJ[] data = new StructJ[structsize1];
-                                       for (int i=0; i < structsize1; i++) {
-                                               data[i] = new StructJ();
-                                       }
-                                       pos = 0;
-                                       for(int i=0; i < structsize1; i++) {
-                                               data[i].name = (String) paramObj[pos++];
-                                               data[i].value = (float) paramObj[pos++];
-                                               data[i].year = (int) paramObj[pos++];
-                                       }
-                                       tc.handleStruct(data);
-                               } else
-                                       throw new Error("Signature not recognized!");
-
-                               if (retObj != null) {
-                                       rmiObj.sendReturnObj(retObj);
-                               }
-                               System.out.println("Servicing remote call for object: " + objectId + " - method: " + methodSign);
-                       }
-               }
-       }
-
-
-       // Return method signatures
-       public static String[] getMethodSignatures() {
-
-               return methodSignatures;
-       }
-       
        
        public void setA(int _int) {
                
@@ -177,57 +59,247 @@ public class TestClass_Skeleton implements TestClassInterface {
        }
        
        
+       public void ___setA() {
+
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
+                       new Class<?>[] { null }, new Class<?>[] { null });
+               setA((int) paramObj[0]);
+       }
+       
+       
        public void setB(float _float) {
                
                tc.setB(_float);
        }
        
        
+       public void ___setB() {
+
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { float.class }, 
+                       new Class<?>[] { null }, new Class<?>[] { null });
+               setB((float) paramObj[0]);
+       }
+       
+       
        public void setC(String _string) {
                
                tc.setC(_string);
        }
        
        
+       public void ___setC() {
+               
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class }, 
+                       new Class<?>[] { null }, new Class<?>[] { null });
+               setC((String) paramObj[0]);
+       }
+       
+       
        public String sumArray(String[] newA) {
                
                return tc.sumArray(newA);
        }
        
        
+       public String ___sumArray() {
+               
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { String[].class }, 
+                       new Class<?>[] { null }, new Class<?>[] { null });
+               return sumArray((String[]) paramObj[0]);
+       }
+       
+       
        public int setAndGetA(int newA) {
                
                return tc.setAndGetA(newA);
        }
        
        
+       public int ___setAndGetA() {
+               
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
+                       new Class<?>[] { null }, new Class<?>[] { null });
+               return setAndGetA((int) paramObj[0]);
+       }
+       
+       
        public int setACAndGetA(String newC, int newA) {
                
                return tc.setACAndGetA(newC, newA);
        }
        
        
+       public int ___setACAndGetA() {
+               
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class, int.class }, 
+                       new Class<?>[] { null, null }, new Class<?>[] { null, null });
+               return setACAndGetA((String) paramObj[0], (int) paramObj[1]);
+       }
+       
+       
        public void registerCallback(CallBackInterface _cb) {
                
                tc.registerCallback(_cb);
        }
+       
+       
+       public void ___registerCallback() throws IOException {
+               
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class }, 
+                       new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
+               CallBackInterface cbstub = new CallBack_Stub((int) paramObj[0], (String) paramObj[1], (int) paramObj[2]);
+               registerCallback((CallBackInterface) cbstub);
+       }
+       
 
        public void registerCallback(CallBackInterface[] _cb) {
                
                tc.registerCallback(_cb);
        }
        
+       
+       // Use 4 underscores because this is a second instance of registerCallback
+       public void ____registerCallback() throws IOException {
+               
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
+                       new Class<?>[] { null }, new Class<?>[] { null });
+               int numStubs = (int) paramObj[0];
+               CallBackInterface[] stub = new CallBackInterface[numStubs];
+               for (int objId = 0; objId < numStubs; objId++) {
+                       stub[objId] = new CallBack_CBStub(rmiCall, objIdCnt);
+                       objIdCnt++;
+               }
+               registerCallback(stub);
+       }
+       
+       
+       public void ___regCB() throws IOException {
+               
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class }, 
+                       new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
+               String[] methodSignatures = CallBack_CBStub.getMethodSignatures();
+               rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], (int) paramObj[2], methodSignatures);
+               System.out.println("Creating a new IoTRMICall object");
+       }
+       
+       
        public int callBack() {
                
                return tc.callBack();
        }
+       
+       
+       public int ___callBack() {
+               
+               return callBack();
+       }
+       
 
        public void handleStruct(StructJ[] data) {
 
                tc.handleStruct(data);
        }
+       
+       
+       public int ___structSize() {
+               
+               Object[] paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
+                       new Class<?>[] { null }, new Class<?>[] { null });
+               return (int) paramObj[0];               
+       }
+       
+       
+       public void ___handleStruct(int structsize1) {
+
+               Class<?>[] paramCls = new Class<?>[3*structsize1];
+               Class<?>[] paramClsTyp1 = new Class<?>[3*structsize1];
+               Class<?>[] paramClsTyp2 = new Class<?>[3*structsize1];
+               int pos = 0;
+               for(int i=0; i < structsize1; i++) {
+                       paramCls[pos] = String.class;
+                       paramClsTyp1[pos] = null;
+                       paramClsTyp2[pos++] = null;
+                       paramCls[pos] = float.class;
+                       paramClsTyp1[pos] = null;
+                       paramClsTyp2[pos++] = null;
+                       paramCls[pos] = int.class;
+                       paramClsTyp1[pos] = null;
+                       paramClsTyp2[pos++] = null;
+               }
+               Object[] paramObj = rmiObj.getMethodParams(paramCls, 
+                       paramClsTyp1, paramClsTyp2);
+               StructJ[] data = new StructJ[structsize1];
+               for (int i=0; i < structsize1; i++) {
+                       data[i] = new StructJ();
+               }
+               pos = 0;
+               for(int i=0; i < structsize1; i++) {
+                       data[i].name = (String) paramObj[pos++];
+                       data[i].value = (float) paramObj[pos++];
+                       data[i].year = (int) paramObj[pos++];
+               }
+               tc.handleStruct(data);
+       }
+       
 
+       private void ___waitRequestInvokeMethod() throws IOException {
 
+               // Struct size
+               int structsize1 = 0;
+               // Loop continuously waiting for incoming bytes
+               while (true) {
+
+                       rmiObj.getMethodBytes();
+                       int _objectId = rmiObj.getObjectId();
+                       if (_objectId == objectId) {
+                       // Multiplex based on object Id
+                               String methodSign = rmiObj.getSignature();
+                               Object retObj = null;
+                               if (methodSign.equals("voidsetA(int)")) {
+                                       ___setA();
+                               } else if (methodSign.equals("voidsetB(float)")) {
+                                       ___setB();
+                               } else if (methodSign.equals("voidsetC(string)")) {
+                                       ___setC();
+                               } else if (methodSign.equals("sumArray(string[])")) {
+                                       retObj = ___sumArray();
+                               } else if (methodSign.equals("intsetAndGetA(int)")) {
+                                       retObj = ___setAndGetA();
+                               } else if (methodSign.equals("intsetACAndGetA(string,int)")) {
+                                       retObj = ___setACAndGetA();
+                               } else if (methodSign.equals("voidregisterCallBack(CallBackInterface)")) {
+                                       ___registerCallback();
+                               } else if (methodSign.equals("voidregisterCallBack(CallBackInterface[])")) {
+                                       ____registerCallback();
+                               } else if (methodSign.equals("intcallBack()")) {
+                                       retObj = ___callBack();
+                               // Special option to register callback
+                               } else if (methodSign.equals("registercallback")) {
+                                       ___regCB();
+                               // Struct handling (3 is the size of the struct)
+                               } else if (methodSign.equals("structsize")) {
+                                       structsize1 = ___structSize();
+                               } else if (methodSign.equals("handleStruct(StructJ[])")) {
+                                       ___handleStruct(structsize1);
+                               } else
+                                       throw new Error("Signature not recognized!");
+
+                               if (retObj != null) {
+                                       rmiObj.sendReturnObj(retObj);
+                               }
+                               System.out.println("Servicing remote call for object: " + objectId + " - method: " + methodSign);
+                       }
+               }
+       }
+
+
+       // Return method signatures
+       public static String[] getMethodSignatures() {
+
+               return methodSignatures;
+       }
+       
+       
        public static void main(String[] args) throws Exception {
 
                int port = 5010;
index 43fcaf0..adad218 100644 (file)
@@ -52,7 +52,7 @@ public class TestClass_Stub implements TestClassInterface {
                ports = _ports;
                rmiCall = new IoTRMICall(_port, _address, _rev, methodSignatures);
                listCBObj = new ArrayList<CallBackInterface>();
-               init_CallBack();
+               ___initCallBack();
        }
 
 
@@ -73,7 +73,7 @@ public class TestClass_Stub implements TestClassInterface {
 
 
        // Initialize callback
-       public void init_CallBack() {
+       public void ___initCallBack() {
 
                Thread thread = new Thread() {
                        public void run() {
@@ -117,7 +117,6 @@ public class TestClass_Stub implements TestClassInterface {
                        public void run() {
                    try{
                                        CallBack_Skeleton cbskel = new CallBack_Skeleton(_cb, ports[0]);
-                                       cbskel.waitRequestInvokeMethod();
                                } catch (Exception ex){
                                        ex.printStackTrace();
                                        throw new Error("Error instantiating class CallBack_Skeleton!");