1 #ifndef _TESTCLASS_SKELETON_HPP__
2 #define _TESTCLASS_SKELETON_HPP__
5 #include "../IoTRMIObject.hpp"
6 #include "../IoTRMICall.hpp"
7 #include "CallBack_CBStub.hpp"
8 #include "TestClassInterface.hpp"
12 class TestClass_Skeleton : public TestClassInterface {
14 TestClass_Skeleton(TestClassInterface* _tc, int _port);
15 ~TestClass_Skeleton();
17 void ___waitRequestInvokeMethod();
19 void setB(float _float);
20 void setC(string _string);
21 string sumArray(vector<string> newA);
22 //int64_t sumArray(vector<int> newA);
23 int setAndGetA(int newA);
24 int setACAndGetA(string newC, int newA);
25 void registerCallback(CallBackInterface* _cb);
26 void registerCallback(vector<CallBackInterface*> _cb);
28 void handleStruct(vector<data> vecData);
34 //int64_t ____sumArray();
36 void ___setACAndGetA();
37 void ___registerCallback();
38 void ____registerCallback();
39 // For array of callbacks
42 // For array of structs
44 void ___handleStruct(int structsize1);
46 const static int size = 12;
47 const static string methodSignatures[size];
50 TestClassInterface *tc;
54 vector<CallBackInterface*> vecCBObj;
55 //CallBackInterface cbstub;
59 const string TestClass_Skeleton::methodSignatures[TestClass_Skeleton::size] = {
66 "intsetACAndGetA(string,int)",
68 "voidregisterCallBack(CallBackInterface)",
69 "voidregisterCallBack(CallBackInterface[])",
71 "handleStruct(StructJ[])",
76 int TestClass_Skeleton::objIdCnt = 0;
79 TestClass_Skeleton::TestClass_Skeleton(TestClassInterface* _tc, int _port) {
81 bool _bResult = false;
83 rmiObj = new IoTRMIObject(_port, &_bResult, methodSignatures, size);
84 ___waitRequestInvokeMethod();
88 TestClass_Skeleton::~TestClass_Skeleton() {
94 if (rmiCall != NULL) {
98 for(CallBackInterface* cb : vecCBObj) {
105 void TestClass_Skeleton::setA(int _int) {
111 void TestClass_Skeleton::___setA() {
113 string paramCls[] = { "int" };
116 void* paramObj[] = { ¶m1 };
117 rmiObj->getMethodParams(paramCls, numParam, paramObj);
122 void TestClass_Skeleton::setB(float _float) {
128 void TestClass_Skeleton::___setB() {
130 string paramCls[] = { "float" };
133 void* paramObj[] = { ¶m1 };
134 rmiObj->getMethodParams(paramCls, numParam, paramObj);
139 void TestClass_Skeleton::setC(string _string) {
145 void TestClass_Skeleton::___setC() {
147 string paramCls[] = { "string" };
150 void* paramObj[] = { ¶m1 };
151 rmiObj->getMethodParams(paramCls, numParam, paramObj);
156 string TestClass_Skeleton::sumArray(vector<string> newA) {
158 return tc->sumArray(newA);
162 void TestClass_Skeleton::___sumArray() {
164 string paramCls[] = { "string[]" };
166 vector<string> param1;
167 void* paramObj[] = { ¶m1 };
168 rmiObj->getMethodParams(paramCls, numParam, paramObj);
169 string retVal = sumArray(param1);
170 void* retObj = &retVal;
171 rmiObj->sendReturnObj(retObj, "string");
175 /*int64_t TestClass_Skeleton::sumArray(vector<int> newA) {
177 return tc->sumArray(newA);
181 /*int64_t TestClass_Skeleton::____sumArray() {
186 int TestClass_Skeleton::setAndGetA(int newA) {
188 return tc->setAndGetA(newA);
192 void TestClass_Skeleton::___setAndGetA() {
194 string paramCls[] = { "int" };
197 void* paramObj[] = { ¶m1 };
198 rmiObj->getMethodParams(paramCls, numParam, paramObj);
199 int retVal = setAndGetA(param1);
200 void* retObj = &retVal;
201 rmiObj->sendReturnObj(retObj, "int");
205 int TestClass_Skeleton::setACAndGetA(string newC, int newA) {
207 return tc->setACAndGetA(newC, newA);
211 void TestClass_Skeleton::___setACAndGetA() {
213 string paramCls[] = { "string", "int" };
217 void* paramObj[] = { ¶m1, ¶m2 };
218 rmiObj->getMethodParams(paramCls, numParam, paramObj);
219 int retVal = setACAndGetA(param1, param2);
220 void* retObj = &retVal;
221 rmiObj->sendReturnObj(retObj, "int");
225 void TestClass_Skeleton::registerCallback(CallBackInterface* _cb) {
227 tc->registerCallback(_cb);
231 void TestClass_Skeleton::___registerCallback() {
236 void TestClass_Skeleton::registerCallback(vector<CallBackInterface*> _cb) {
238 tc->registerCallback(_cb);
242 void TestClass_Skeleton::___regCB() {
244 string paramCls[] = { "int", "string", "int" };
249 void* paramObj[] = { ¶m1, ¶m2, ¶m3 };
250 rmiObj->getMethodParams(paramCls, numParam, paramObj);
251 // Instantiate IoTRMICall object
252 bool bResult = false;
253 rmiCall = new IoTRMICall(param1, param2.c_str(), param3, &bResult,
254 CallBack_CBStub::methodSignatures, CallBack_CBStub::size);
258 void TestClass_Skeleton::____registerCallback() {
260 string paramCls[] = { "int" };
263 void* paramObj[] = { &numStubs };
264 rmiObj->getMethodParams(paramCls, numParam, paramObj);
265 vector<CallBackInterface*> stub;
266 for (int objId = 0; objId < numStubs; objId++) {
267 CallBackInterface* cb = new CallBack_CBStub(rmiCall, objIdCnt);
269 vecCBObj.push_back(cb);
272 registerCallback(stub);
276 int TestClass_Skeleton::callBack() {
282 void TestClass_Skeleton::___callBack() {
284 int retVal = callBack();
285 void* retObj = &retVal;
286 rmiObj->sendReturnObj(retObj, "int");
290 int TestClass_Skeleton::___structSize() {
292 string paramCls[] = { "int" };
295 void* paramObj[] = { ¶m1 };
296 rmiObj->getMethodParams(paramCls, numParam, paramObj);
301 void TestClass_Skeleton::handleStruct(vector<data> vecData) {
303 tc->handleStruct(vecData);
307 void TestClass_Skeleton::___handleStruct(int structsize1) {
309 string paramCls[3*structsize1];
310 void* paramObj[3*structsize1];
311 int numParam = 3*structsize1;
312 // define array of everything
313 string param1[structsize1];
314 float param2[structsize1];
315 int param3[structsize1];
317 for(int i=0; i < structsize1; i++) {
318 paramCls[pos] = "string";
319 paramObj[pos++] = ¶m1[i];
320 paramCls[pos] = "float";
321 paramObj[pos++] = ¶m2[i];
322 paramCls[pos] = "int";
323 paramObj[pos++] = ¶m3[i];
325 rmiObj->getMethodParams(paramCls, numParam, paramObj);
326 vector<data> dat(structsize1);
328 for (int i=0; i < structsize1; i++) {
329 dat[i].name = param1[i];
330 dat[i].value = param2[i];
331 dat[i].year = param3[i];
337 void TestClass_Skeleton::___waitRequestInvokeMethod() {
340 // Loop continuously waiting for incoming bytes
343 rmiObj->getMethodBytes();
344 string methodSign = rmiObj->getSignature();
345 cout << "Method sign: " << methodSign << endl;
347 if (methodSign.compare("voidsetA(int)") == 0) {
349 } else if (methodSign.compare("voidsetB(float)") == 0) {
351 } else if (methodSign.compare("voidsetC(string)") == 0) {
353 } else if (methodSign.compare("sumArray(string[])") == 0) {
355 /*} else if (methodSign.compare("sumArray(int[])") == 0) {
357 } else if (methodSign.compare("intsetAndGetA(int)") == 0) {
359 } else if (methodSign.compare("intsetACAndGetA(string,int)") == 0) {
361 } else if (methodSign.compare("voidregisterCallBack(CallBackInterface)") == 0) {
363 } else if (methodSign.compare("voidregisterCallBack(CallBackInterface[])") == 0) {
364 ____registerCallback();
365 } else if (methodSign.compare("registercallback") == 0) {
367 } else if (methodSign.compare("intcallBack()") == 0) {
370 } else if (methodSign.compare("structsize") == 0) {
371 structsize1 = ___structSize();
372 } else if (methodSign.compare("handleStruct(StructJ[])") == 0) {
373 ___handleStruct(structsize1);
375 string error = "Signature unrecognized: " + string(methodSign);