Making sure that sample stub and skeleton classes inherit from a common interface
authorrtrimana <rtrimana@uci.edu>
Fri, 28 Oct 2016 16:01:50 +0000 (09:01 -0700)
committerrtrimana <rtrimana@uci.edu>
Fri, 28 Oct 2016 16:01:50 +0000 (09:01 -0700)
iotjava/iotrmi/C++/sample/TestClass.cpp
iotjava/iotrmi/C++/sample/TestClass.hpp
iotjava/iotrmi/C++/sample/TestClassInterface.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/TestClass_Skeleton.java
iotjava/iotrmi/Java/sample/TestClass_Stub.java

index d9229ab..cbaeeba 100644 (file)
@@ -10,14 +10,14 @@ int main(int argc, char *argv[])
        TestClassInterface *tc = new TestClass();
        cout << "Return value: " << tc->setAndGetA(123) << endl;
        cout << "Return value: " << tc->setACAndGetA("string", 123) << endl;
-       /*vector<string> input;
+       vector<string> input;
        input.push_back("123");
        input.push_back("456");
-       input.push_back("987");*/
-       vector<int> input;
+       input.push_back("987");
+       /*vector<int> input;
        input.push_back(123);
        input.push_back(456);
-       input.push_back(987);
+       input.push_back(987);*/
 
        cout << "Return value: " << tc->sumArray(input) << endl;
 
index 891e44e..272f1c8 100644 (file)
@@ -12,8 +12,8 @@ class TestClass : public TestClassInterface {
                void                            setA(int _int);
                void                            setB(float _float);
                void                            setC(string _string);
-               //string                                sumArray(vector<string> newA);
-               int64_t                         sumArray(vector<int> newA);
+               string                          sumArray(vector<string> newA);
+               //int64_t                               sumArray(vector<int> newA);
                int                                     setAndGetA(int newA);
                int                                     setACAndGetA(string newC, int newA);
                //void                          registerCallback(CallBackInterface _cb);
@@ -64,7 +64,7 @@ void TestClass::setC(string _string) {
 }
 
 
-/*string TestClass::sumArray(vector<string> newA) {
+string TestClass::sumArray(vector<string> newA) {
 
        string sum = "";
        int len = newA.size();
@@ -72,10 +72,10 @@ void TestClass::setC(string _string) {
                sum = sum + newA[c];
        }
        return sum;
-}*/
+}
 
 
-int64_t TestClass::sumArray(vector<int> newA) {
+/*int64_t TestClass::sumArray(vector<int> newA) {
 
        int64_t sum = 0;
        int len = newA.size();
@@ -83,7 +83,7 @@ int64_t TestClass::sumArray(vector<int> newA) {
                sum = sum + newA[c];
        }
        return sum;
-}
+}*/
 
 
 int TestClass::setAndGetA(int newA) {
index 5ad53a8..9dc3e00 100644 (file)
@@ -8,8 +8,8 @@ class TestClassInterface {
                virtual void    setA(int _int) = 0;
                virtual void    setB(float _float) = 0;
                virtual void    setC(string _string) = 0;
-               //virtual string        sumArray(vector<string> newA) = 0;
-               virtual int64_t sumArray(vector<int> newA) = 0;
+               virtual string  sumArray(vector<string> newA) = 0;
+               //virtual int64_t       sumArray(vector<int> newA) = 0;
                virtual int             setAndGetA(int newA) = 0;
                virtual int             setACAndGetA(string newC, int newA) = 0;
                //virtual void  registerCallback(CallBackInterface _cb);
index 0527378..d5be54b 100644 (file)
@@ -4,12 +4,21 @@
 
 using namespace std;
 
-class TestClass_Skeleton {
+class TestClass_Skeleton : public TestClassInterface {
        public:
                TestClass_Skeleton(TestClassInterface* _tc, int _port);
                ~TestClass_Skeleton();
 
                void    waitRequestInvokeMethod();
+               void    setA(int _int);
+               void    setB(float _float);
+               void    setC(string _string);
+               string  sumArray(vector<string> newA);
+               //int64_t       sumArray(vector<int> newA);
+               int             setAndGetA(int newA);
+               int             setACAndGetA(string newC, int newA);
+               //void  registerCallback(CallBackInterface _cb);
+               //int   callBack();
 
        private:                
                TestClassInterface              *tc;
@@ -22,8 +31,8 @@ class TestClass_Skeleton {
                        "voidsetA(int)",
                        "voidsetB(float)",
                        "voidsetC(string)",
-                       //"sumArray(string[])",
-                       "sumArray(int[])",
+                       "sumArray(string[])",
+                       //"sumArray(int[])",
                        "intsetAndGetA(int)",
                        "intsetACAndGetA(string,int)",
                        "intcallBack()",
@@ -64,46 +73,46 @@ void TestClass_Skeleton::waitRequestInvokeMethod() {
                        int param1 = 0;
                        void* paramObj[] = { &param1 };
                        rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       tc->setA(param1);
+                       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);
-                       tc->setB(param1);
+                       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);
-                       tc->setC(param1);
-               /*} else if (methodSign.compare("sumArray(string[])") == 0) {
+                       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 = tc->sumArray(param1);
+                       string retVal = sumArray(param1);
                        void* retObj = &retVal;
-                       rmiObj->sendReturnObj(retObj, "string");*/
-               } else if (methodSign.compare("sumArray(int[])") == 0) {
+                       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 = tc->sumArray(param1);          
+                       int64_t retVal = sumArray(param1);              
                        void* retObj = &retVal;
-                       rmiObj->sendReturnObj(retObj, "long");
+                       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 = tc->setAndGetA(param1);
+                       int retVal = setAndGetA(param1);
                        void* retObj = &retVal;
                        rmiObj->sendReturnObj(retObj, "int");
                } else if (methodSign.compare("intsetACAndGetA(string,int)") == 0) {
@@ -113,7 +122,7 @@ void TestClass_Skeleton::waitRequestInvokeMethod() {
                        int param2 = 0;
                        void* paramObj[] = { &param1, &param2 };
                        rmiObj->getMethodParams(paramCls, numParam, paramObj);
-                       int retVal = tc->setACAndGetA(param1, param2);
+                       int retVal = setACAndGetA(param1, param2);
                        void* retObj = &retVal;
                        rmiObj->sendReturnObj(retObj, "int");
                /*} else if (methodSign.compare("voidregisterCallBack(CallBackInterface)") == 0) {
@@ -128,14 +137,56 @@ void TestClass_Skeleton::waitRequestInvokeMethod() {
 }
 
 
-/*void TestClass_Stub::registerCallback(CallBackInterface _cb) {
+void TestClass_Skeleton::setA(int _int) {
 
-       cb = _cb;
+       tc->setA(_int);
 }
 
 
-int TestClass_Stub::callBack() {
+void TestClass_Skeleton::setB(float _float) {
 
-       return cb.printInt();
+       tc->setB(_float);
+}
+
+
+void TestClass_Skeleton::setC(string _string) {
+
+       tc->setC(_string);
+}
+
+
+string TestClass_Skeleton::sumArray(vector<string> newA) {
+
+       return tc->sumArray(newA);;
+}
+
+
+/*int64_t TestClass_Skeleton::sumArray(vector<int> newA) {
+
+       return tc->sumArray(newA);
+}*/
+
+
+int TestClass_Skeleton::setAndGetA(int newA) {
+
+       return tc->setAndGetA(newA);
+}
+
+
+int TestClass_Skeleton::setACAndGetA(string newC, int newA) {
+
+       return tc->setACAndGetA(newC, newA);
+}
+
+
+/*void TestClass_Skeleton::registerCallback(CallBackInterface _cb) {
+
+       tc->registerCallback(_cb);
+}
+
+
+int TestClass_Skeleton::callBack() {
+
+       return tc->callBack();
 }*/
 
index 7870578..cfb7aa7 100644 (file)
@@ -15,14 +15,14 @@ int main(int argc, char *argv[])
        TestClassInterface *tcStub = new TestClass_Stub(port, address, rev, &bResult);
        cout << "Return value: " << tcStub->setAndGetA(123) << endl;
        cout << "Return value: " << tcStub->setACAndGetA("string", 123) << endl;
-       /*vector<string> input;
+       vector<string> input;
        input.push_back("123");
        input.push_back("456");
-       input.push_back("987");*/
-       vector<int> input;
+       input.push_back("987");
+       /*vector<int> input;
        input.push_back(123);
        input.push_back(456);
-       input.push_back(987);
+       input.push_back(987);*/
 
        cout << "Return value: " << tcStub->sumArray(input) << endl;
 
index 1d73cbe..97d3db5 100644 (file)
@@ -13,8 +13,8 @@ class TestClass_Stub : public TestClassInterface {
                void                            setA(int _int);
                void                            setB(float _float);
                void                            setC(string _string);
-               //string                                sumArray(vector<string> newA);
-               int64_t                         sumArray(vector<int> newA);
+               string                          sumArray(vector<string> newA);
+               //int64_t                               sumArray(vector<int> newA);
                int                                     setAndGetA(int newA);
                int                                     setACAndGetA(string newC, int newA);
                //void                          registerCallback(CallBackInterface _cb);
@@ -90,7 +90,7 @@ void TestClass_Stub::setC(string _string) {
 }
 
 
-/*string TestClass_Stub::sumArray(vector<string> newA) {
+string TestClass_Stub::sumArray(vector<string> newA) {
 
        int numParam = 1;
        string sign = "sumArray(string[])";
@@ -101,10 +101,10 @@ void TestClass_Stub::setC(string _string) {
        void* retObj = &retVal;
        rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
        return retVal;
-}*/
+}
 
 
-int64_t TestClass_Stub::sumArray(vector<int> newA) {
+/*int64_t TestClass_Stub::sumArray(vector<int> newA) {
 
        int numParam = 1;
        string sign = "sumArray(int[])";
@@ -115,7 +115,7 @@ int64_t TestClass_Stub::sumArray(vector<int> newA) {
        void* retObj = &retVal;
        rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
        return retVal;
-}
+}*/
 
 
 
index 07dbda8..7856cdf 100644 (file)
@@ -6,7 +6,7 @@ import iotrmi.Java.IoTRMIObject;
 
 import java.util.Arrays;
 
-public class TestClass_Skeleton {
+public class TestClass_Skeleton implements TestClassInterface {
 
        private String[] methodSignatures = {
 
@@ -53,34 +53,34 @@ public class TestClass_Skeleton {
                        if (methodSign.equals("voidsetA(int)")) {
                                paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class }, 
                                        new Class<?>[] { null }, new Class<?>[] { null });
-                               tc.setA((int) paramObj[0]);
+                               setA((int) paramObj[0]);
                        } else if (methodSign.equals("voidsetB(float)")) {
                                paramObj = rmiObj.getMethodParams(new Class<?>[] { float.class }, 
                                        new Class<?>[] { null }, new Class<?>[] { null });
-                               tc.setB((float) paramObj[0]);
+                               setB((float) paramObj[0]);
                        } else if (methodSign.equals("voidsetC(string)")) {
                                paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class }, 
                                        new Class<?>[] { null }, new Class<?>[] { null });
-                               tc.setC((String) paramObj[0]);
+                               setC((String) paramObj[0]);
                        } else if (methodSign.equals("sumArray(string[])")) {
                                paramObj = rmiObj.getMethodParams(new Class<?>[] { String[].class }, 
                                        new Class<?>[] { null }, new Class<?>[] { null });
-                               retObj = tc.sumArray((String[]) paramObj[0]);
+                               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 = tc.setAndGetA((int) paramObj[0]);
+                               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 = tc.setACAndGetA((String) paramObj[0], (int) paramObj[1]);
+                               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]);
-                               tc.registerCallback((CallBackInterface) cbstub);
+                               registerCallback((CallBackInterface) cbstub);
                        } else if (methodSign.equals("intcallBack()")) {
-                               retObj = tc.callBack();
+                               retObj = callBack();
                        } else
                                throw new Error("Signature un-recognized!");
 
@@ -90,6 +90,54 @@ public class TestClass_Skeleton {
                        System.out.println("Servicing remote call for method: " + methodSign);
                }
        }
+       
+       
+       public void setA(int _int) {
+               
+               tc.setA(_int);
+       }
+       
+       
+       public void setB(float _float) {
+               
+               tc.setB(_float);
+       }
+       
+       
+       public void setC(String _string) {
+               
+               tc.setC(_string);
+       }
+       
+       
+       public String sumArray(String[] newA) {
+               
+               return tc.sumArray(newA);
+       }
+       
+       
+       public int setAndGetA(int newA) {
+               
+               return tc.setAndGetA(newA);
+       }
+       
+       
+       public int setACAndGetA(String newC, int newA) {
+               
+               return tc.setACAndGetA(newC, newA);
+       }
+       
+       
+       public void registerCallback(CallBackInterface _cb) {
+               
+               tc.registerCallback(_cb);
+       }
+       
+       
+       public int callBack() {
+               
+               return tc.callBack();
+       }
 
 
        public static void main(String[] args) throws Exception {
index 39411a7..31d20a2 100644 (file)
@@ -159,9 +159,9 @@ public class TestClass_Stub implements TestClassInterface {
                System.out.println("Return value: " + tcstub.setACAndGetA("string", 123));
                System.out.println("Return value: " + tcstub.sumArray(new String[] { "123", "456", "987" }));
 
-               CallBack cb = new CallBack(23);
+               /*CallBack cb = new CallBack(23);
                tcstub.registerCallback(cb);
-               System.out.println("Return value from callback: " + tcstub.callBack());
+               System.out.println("Return value from callback: " + tcstub.callBack());*/
                //System.out.println("Return value: " + tcstub.setAndGetA(1234));
        }
 }