Adding object ID and tons of minor adjustments for callback support
[iot2.git] / iotjava / iotrmi / C++ / sample / TestClass_Stub.hpp
1 #include <iostream>
2 #include "../IoTRMICall.hpp"
3 #include "../IoTRMIObject.hpp"
4 #include "TestClassInterface.hpp"
5
6 using namespace std;
7
8 class TestClass_Stub : public TestClassInterface {
9         public:
10                 TestClass_Stub();
11                 TestClass_Stub(int _port, const char* _address, int _rev, bool* _bResult, vector<int> _ports);
12                 ~TestClass_Stub();
13
14                 void                            setA(int _int);
15                 void                            setB(float _float);
16                 void                            setC(string _string);
17                 string                          sumArray(vector<string> newA);
18                 //int64_t                               sumArray(vector<int> newA);
19                 int                                     setAndGetA(int newA);
20                 int                                     setACAndGetA(string newC, int newA);
21                 void                            registerCallback(CallBackInterface* _cb);
22                 void                            registerCallback(vector<CallBackInterface*>_cb);
23                 int                                     callBack();
24                 void                            init_CallBack();
25
26                 const static int        size = 9;
27                 const static string methodSignatures[size];
28
29         private:                
30                 int                                                     intA;
31                 float                                           floatB;
32                 string                                          stringC;
33                 //CallBackInterface                     cb;
34                 IoTRMICall                                      *rmiCall;
35                 IoTRMIObject                            *rmiObj;
36                 string                                          address;
37                 vector<int>                                     ports;
38                 map<int,CallBackInterface*> mapCBObj;
39
40                 int             objectId = 0;   // Default value is 0
41 };
42
43
44 const string TestClass_Stub::methodSignatures[TestClass_Stub::size] = {
45         "voidsetA(int)",
46         "voidsetB(float)",
47         "voidsetC(string)",
48         "sumArray(string[])",
49         //"sumArray(int[])",
50         "intsetAndGetA(int)",
51         "intsetACAndGetA(string,int)",
52         "intcallBack()",
53         "voidregisterCallBack(CallBackInterface)",
54         "voidregisterCallBack(CallBackInterface[])"
55 };
56
57
58 TestClass_Stub::TestClass_Stub() {
59
60         address = "";
61         rmiCall = NULL;
62 }
63
64
65 TestClass_Stub::TestClass_Stub(int _port, const char* _address, int _rev, bool* _bResult, vector<int> _ports) {
66
67         address = _address;
68         rmiCall = new IoTRMICall(_port, _address, _rev, _bResult, methodSignatures, size);
69         ports = _ports;
70 }
71
72
73 TestClass_Stub::~TestClass_Stub() {
74
75         if (rmiCall != NULL) {
76                 delete rmiCall;
77                 rmiCall = NULL;
78         }
79 }
80
81
82 // Callback handler thread
83 void TestClass_Stub::init_CallBack() {
84
85         bool bResult = false;
86         rmiObj = new IoTRMIObject(ports[0], &bResult, CallBack_CBSkeleton::methodSignatures, CallBack_CBSkeleton::size);
87         while (true) {
88                 char* method = rmiObj->getMethodBytes();
89                 
90         }
91 }
92
93
94 void TestClass_Stub::setA(int _int) {
95
96         int numParam = 1;
97         string sign = "voidsetA(int)";
98         string retType = "void";
99         string paramCls[] = { "int" };
100         void* paramObj[] = { &_int };
101         void* retObj = NULL;
102         rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
103 }
104
105
106 void TestClass_Stub::setB(float _float) {
107
108         int numParam = 1;
109         string sign = "voidsetB(float)";
110         string retType = "void";
111         string paramCls[] = { "float" };
112         void* paramObj[] = { &_float };
113         void* retObj = NULL;
114         rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
115 }
116
117
118 void TestClass_Stub::setC(string _string) {
119
120         int numParam = 1;
121         string sign = "voidsetC(string)";
122         string retType = "void";
123         string paramCls[] = { "string" };
124         void* paramObj[] = { &_string };
125         void* retObj = NULL;
126         rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
127 }
128
129
130 string TestClass_Stub::sumArray(vector<string> newA) {
131
132         int numParam = 1;
133         string sign = "sumArray(string[])";
134         string retType = "string";
135         string paramCls[] = { "string[]" };
136         void* paramObj[] = { &newA };
137         string retVal = "";
138         void* retObj = &retVal;
139         rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
140         return retVal;
141 }
142
143
144 /*int64_t TestClass_Stub::sumArray(vector<int> newA) {
145
146         int numParam = 1;
147         string sign = "sumArray(int[])";
148         string retType = "long";
149         string paramCls[] = { "int[]" };
150         void* paramObj[] = { &newA };
151         int64_t retVal = 0;
152         void* retObj = &retVal;
153         rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
154         return retVal;
155 }*/
156
157
158
159 int TestClass_Stub::setAndGetA(int newA) {
160
161         int numParam = 1;
162         string sign = "intsetAndGetA(int)";
163         string retType = "int";
164         string paramCls[] = { "int" };
165         void* paramObj[] = { &newA };
166         int retVal = 0;
167         void* retObj = &retVal;
168         rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
169         return retVal;
170 }
171
172
173 int TestClass_Stub::setACAndGetA(string newC, int newA) {
174
175         int numParam = 2;
176         string sign = "intsetACAndGetA(string,int)";
177         string retType = "int";
178         string paramCls[] = { "string", "int" };
179         void* paramObj[] = { &newC, &newA };
180         int retVal = 0;
181         void* retObj = &retVal;
182         rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
183         return retVal;
184 }
185
186
187 void TestClass_Stub::registerCallback(CallBackInterface* _cb) {
188
189         //Should implement the callback here
190 }
191
192
193 void TestClass_Stub::registerCallback(vector<CallBackInterface*> _cb) {
194
195         //Should implement the callback here for multiple callback objects
196 }
197
198
199 int TestClass_Stub::callBack() {
200
201         int numParam = 0;
202         string sign = "intcallBack()";
203         string retType = "int";
204         string paramCls[] = { };
205         void* paramObj[] = { };
206         int retVal = 0;
207         void* retObj = &retVal;
208         rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
209         return retVal;
210 }
211