Fixing bug for return value from callback in C++ (sendReturnObj is called twice)...
[iot2.git] / iotjava / iotrmi / C++ / sample / CallBack_CBSkeleton.hpp
index 7ed5f04f3f251fb13b40cfc64dd04917adebcafa..510ed646e02ec063de5ed64ea3ed8cdbe3d6e434 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