Refactoring type size handler; using Java types as standard
[iot2.git] / iotjava / iotrmi / C++ / sample / TestClass_Skeleton.hpp
1 #include <iostream>
2 #include "../IoTRMIObject.hpp"
3 #include "TestClass.hpp"
4
5 using namespace std;
6
7 class TestClass_Skeleton {
8         public:
9                 TestClass_Skeleton(TestClassInterface* _tc, int _port);
10                 ~TestClass_Skeleton();
11
12                 void    waitRequestInvokeMethod();
13
14         private:                
15                 TestClassInterface              *tc;
16                 IoTRMIObject                    *rmiObj;
17                 //CallBackInterface cbstub;
18
19                 const static int size = 8;
20                 string methodSignatures[size] = {
21
22                         "voidsetA(int)",
23                         "voidsetB(float)",
24                         "voidsetC(string)",
25                         //"sumArray(string[])",
26                         "sumArray(int[])",
27                         "intsetAndGetA(int)",
28                         "intsetACAndGetA(string,int)",
29                         "intcallBack()",
30                         "voidregisterCallBack(CallBackInterface)"
31                 };
32 };
33
34
35 TestClass_Skeleton::TestClass_Skeleton(TestClassInterface* _tc, int _port) {
36
37         bool _bResult = false;
38         tc = _tc;
39         rmiObj = new IoTRMIObject(_port, &_bResult, methodSignatures, size);
40 }
41
42
43 TestClass_Skeleton::~TestClass_Skeleton() {
44
45         if (rmiObj != NULL) {
46                 delete rmiObj;
47                 rmiObj = NULL;
48         }
49 }
50
51
52 void TestClass_Skeleton::waitRequestInvokeMethod() {
53
54         // Loop continuously waiting for incoming bytes
55         while (true) {
56
57                 rmiObj->getMethodBytes();
58                 string methodSign = rmiObj->getSignature();
59                 cout << "Method sign: " << methodSign << endl;
60                 
61                 if (methodSign.compare("voidsetA(int)") == 0) {
62                         string paramCls[] = { "int" };
63                         int numParam = 1;
64                         int param1 = 0;
65                         void* paramObj[] = { &param1 };
66                         rmiObj->getMethodParams(paramCls, numParam, paramObj);
67                         tc->setA(param1);
68                 } else if (methodSign.compare("voidsetB(float)") == 0) {
69                         string paramCls[] = { "float" };
70                         int numParam = 1;
71                         float param1 = 0.0;
72                         void* paramObj[] = { &param1 };
73                         rmiObj->getMethodParams(paramCls, numParam, paramObj);
74                         tc->setB(param1);
75                 } else if (methodSign.compare("voidsetC(string)") == 0) {
76                         string paramCls[] = { "string" };
77                         int numParam = 1;
78                         string param1 = "";
79                         void* paramObj[] = { &param1 };
80                         rmiObj->getMethodParams(paramCls, numParam, paramObj);
81                         tc->setC(param1);
82                 /*} else if (methodSign.compare("sumArray(string[])") == 0) {
83                         string paramCls[] = { "string[]" };
84                         int numParam = 1;
85                         vector<string> param1;
86                         void* paramObj[] = { &param1 };
87                         rmiObj->getMethodParams(paramCls, numParam, paramObj);
88                         string retVal = tc->sumArray(param1);
89                         void* retObj = &retVal;
90                         rmiObj->sendReturnObj(retObj, "string");*/
91                 } else if (methodSign.compare("sumArray(int[])") == 0) {
92                         string paramCls[] = { "int[]" };
93                         int numParam = 1;
94                         vector<int> param1;
95                         void* paramObj[] = { &param1 };
96                         rmiObj->getMethodParams(paramCls, numParam, paramObj);
97                         int64_t retVal = tc->sumArray(param1);          
98                         void* retObj = &retVal;
99                         rmiObj->sendReturnObj(retObj, "long");
100                 } else if (methodSign.compare("intsetAndGetA(int)") == 0) {
101                         string paramCls[] = { "int" };
102                         int numParam = 1;
103                         int param1 = 0;
104                         void* paramObj[] = { &param1 };
105                         rmiObj->getMethodParams(paramCls, numParam, paramObj);
106                         int retVal = tc->setAndGetA(param1);
107                         void* retObj = &retVal;
108                         rmiObj->sendReturnObj(retObj, "int");
109                 } else if (methodSign.compare("intsetACAndGetA(string,int)") == 0) {
110                         string paramCls[] = { "string", "int" };
111                         int numParam = 2;
112                         string param1 = "";
113                         int param2 = 0;
114                         void* paramObj[] = { &param1, &param2 };
115                         rmiObj->getMethodParams(paramCls, numParam, paramObj);
116                         int retVal = tc->setACAndGetA(param1, param2);
117                         void* retObj = &retVal;
118                         rmiObj->sendReturnObj(retObj, "int");
119                 /*} else if (methodSign.compare("voidregisterCallBack(CallBackInterface)") == 0) {
120                         //
121                 } else if (methodSign.compare("intcallBack()") == 0) {
122                         //*/
123                 } else {
124                         string error = "Signature unreqcognized: " + string(methodSign);
125                         throw error;
126                 }
127         }
128 }
129
130
131 /*void TestClass_Stub::registerCallback(CallBackInterface _cb) {
132
133         cb = _cb;
134 }
135
136
137 int TestClass_Stub::callBack() {
138
139         return cb.printInt();
140 }*/
141