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