Adjustments in stubs and skeletons for callback in callback; using different ports...
[iot2.git] / iotjava / iotrmi / C++ / basics / TestClass.hpp
1 #ifndef _TESTCLASS_HPP__
2 #define _TESTCLASS_HPP__
3
4 #include <iostream>
5 #include <thread>
6 #include <chrono>
7 #include "TestClassInterface.hpp"
8 #include "CallBackInterfaceWithCallBack.hpp"
9 #include "Enum.hpp"
10 #include "Struct.hpp"
11
12 using namespace std;
13
14 class TestClass : public TestClassInterface {
15         public:
16                 TestClass();
17                 TestClass(int _int, float _float, string _string);
18
19                 char                            getByte(char in);
20                 short                           getShort(short in);
21                 int64_t                         getLong(int64_t in);
22                 float                           getFloat(float in);
23                 double                          getDouble(double in);
24                 bool                            getBoolean(bool in);
25                 char                            getChar(char in);
26
27                 vector<char>            getByteArray(vector<char> in);
28                 vector<short>           getShortArray(vector<short> in);
29                 vector<int64_t>         getLongArray(vector<int64_t> in);
30                 vector<float>           getFloatArray(vector<float> in);
31                 vector<double>          getDoubleArray(vector<double> in);
32                 vector<bool>            getBooleanArray(vector<bool> in);
33                 vector<char>            getCharArray(vector<char> in);
34
35                 vector<char>            getByteList(vector<char> in);
36                 vector<short>           getShortList(vector<short> in);
37                 vector<int64_t>         getLongList(vector<int64_t> in);
38                 vector<float>           getFloatList(vector<float> in);
39                 vector<double>          getDoubleList(vector<double> in);
40                 vector<bool>            getBooleanList(vector<bool> in);
41                 vector<char>            getCharList(vector<char> in);
42
43                 // Callbacks
44                 void                            registerCallback(CallBackInterfaceWithCallBack* _cb);
45                 void                            registerCallbackArray(vector<CallBackInterfaceWithCallBack*> _cb);
46                 void                            registerCallbackList(vector<CallBackInterfaceWithCallBack*> _cb);
47                 void                            registerCallbackComplex(int in, vector<CallBackInterfaceWithCallBack*> _cb, double db);
48                 int                                     callBack();
49                 vector<Enum>            handleCallbackEnum(vector<Enum> en, char c, vector<CallBackInterfaceWithCallBack*> _cb);
50
51                 // Enum
52                 Enum                            handleEnum(Enum en);
53                 vector<Enum>            handleEnumArray(vector<Enum> vecEn);
54                 vector<Enum>            handleEnumList(vector<Enum> vecEn);
55                 Enum                            handleEnumComplex(Enum en, int i, char c);
56                 vector<Enum>            handleEnumComplex2(vector<Enum> en, int i, char c);
57                 vector<Enum>            handleEnumTwo(vector<Enum> en1, vector<Enum> en2);
58                 vector<Enum>            handleEnumThree(vector<Enum> en1, vector<Enum> en2, vector<Struct> str1, vector<Struct> str2);
59
60                 // Struct
61                 Struct                          handleStruct(Struct str);
62                 vector<Struct>          handleStructArray(vector<Struct> vecStr);
63                 vector<Struct>          handleStructList(vector<Struct> vecStr);
64                 Struct                          handleStructComplex(int in, char c, Struct str);
65                 vector<Struct>          handleStructComplex2(int in, char c, vector<Struct> vecStr);
66                 vector<Struct>          handleStructTwo(vector<Struct> str1, vector<Struct> str2);
67                 vector<Struct>          handleStructThree(vector<Struct> str1, vector<Struct> str2, vector<Struct> str3);
68
69                 vector<Enum>            handleEnumStruct(vector<Enum> en, vector<Struct> str, char c);
70                 vector<Enum>            handleAll(vector<Enum> en, vector<Struct> str, char c, vector<CallBackInterfaceWithCallBack*> _cb);
71                 vector<Enum>            handleAllTwo(vector<Enum> en1, vector<Enum> en2, vector<Struct> str1, vector<Struct> str2, char c, 
72                                                                         vector<CallBackInterfaceWithCallBack*> _cb1, vector<CallBackInterfaceWithCallBack*> _cb2);
73
74                 int                                     getA();
75                 void                            setA(int _int);
76                 void                            setB(float _float);
77                 void                            setC(string _string);
78                 string                          sumArray(vector<string> newA);
79                 int                                     setAndGetA(int newA);
80                 int                                     setACAndGetA(string newC, int newA);
81
82         private:                
83                 int                                                                             intA;
84                 float                                                                   floatB;
85                 string                                                                  stringC;
86                 vector<CallBackInterfaceWithCallBack*>  cbvec;
87 };
88
89
90 TestClass::TestClass() {
91
92         intA = 1;
93         floatB = 2;
94         stringC = "345";
95         // cbvec doesn't need to be initialized again
96 }
97
98
99 TestClass::TestClass(int _int, float _float, string _string) {
100
101         intA = _int;
102         floatB = _float;
103         stringC = _string;
104         // cbvec doesn't need to be initialized again
105 }
106
107
108 void TestClass::registerCallback(CallBackInterfaceWithCallBack* _cb) {
109
110         cbvec.push_back(_cb);
111         cout << "Registering callback object!" << endl;
112 }
113
114
115 void TestClass::registerCallbackArray(vector<CallBackInterfaceWithCallBack*> _cb) {
116
117         for (CallBackInterfaceWithCallBack* cb : _cb) {
118                 cbvec.push_back(cb);
119                 cout << "Registering callback object in array!" << endl;
120         }
121 }
122
123
124 void TestClass::registerCallbackList(vector<CallBackInterfaceWithCallBack*> _cb) {
125
126         for (CallBackInterfaceWithCallBack* cb : _cb) {
127                 cbvec.push_back(cb);
128                 cout << "Registering callback object in list!" << endl;
129         }
130 }
131
132
133 void TestClass::registerCallbackComplex(int in, vector<CallBackInterfaceWithCallBack*> _cb, double db) {
134
135         for (CallBackInterfaceWithCallBack* cb : _cb) {
136                 cbvec.push_back(cb);
137                 cout << "Registering callback object in list!" << endl;
138         }
139
140         cout << "Integer: " << in << endl;
141         cout << "Double: " << db << endl;
142 }
143
144
145 int TestClass::callBack() {
146
147         int sum = 0;
148         for (CallBackInterfaceWithCallBack* cb : cbvec) {
149                 cb->needCallback(this);
150                 sum = sum + cb->printInt();
151         }
152
153         return sum;
154 }
155
156
157 // Single variables
158 char TestClass::getByte(char in) {
159
160         return in;
161 }
162
163
164 short TestClass::getShort(short in) {
165
166         return in;
167 }
168
169
170 int64_t TestClass::getLong(int64_t in) {
171
172         return in;
173 }
174
175
176 float TestClass::getFloat(float in) {
177
178         return in;
179 }
180
181
182 double TestClass::getDouble(double in) {
183
184         return in;
185 }
186
187
188 bool TestClass::getBoolean(bool in) {
189
190         return in;
191 }
192
193
194 char TestClass::getChar(char in) {
195
196         return in;
197 }
198
199
200 // Arrays
201 vector<char> TestClass::getByteArray(vector<char> in) {
202
203         return in;
204 }
205
206
207 vector<short> TestClass::getShortArray(vector<short> in) {
208
209         return in;
210 }
211
212
213 vector<int64_t> TestClass::getLongArray(vector<int64_t> in) {
214
215         return in;
216 }
217
218
219 vector<float> TestClass::getFloatArray(vector<float> in) {
220
221         return in;
222 }
223
224
225 vector<double> TestClass::getDoubleArray(vector<double> in) {
226
227         return in;
228 }
229
230
231 vector<bool> TestClass::getBooleanArray(vector<bool> in) {
232
233         return in;
234 }
235
236
237 vector<char> TestClass::getCharArray(vector<char> in) {
238
239         return in;
240 }
241
242 // List
243 vector<char> TestClass::getByteList(vector<char> in) {
244
245         return in;
246 }
247
248
249 vector<short> TestClass::getShortList(vector<short> in) {
250
251         return in;
252 }
253
254
255 vector<int64_t> TestClass::getLongList(vector<int64_t> in) {
256
257         return in;
258 }
259
260
261 vector<float> TestClass::getFloatList(vector<float> in) {
262
263         return in;
264 }
265
266
267 vector<double> TestClass::getDoubleList(vector<double> in) {
268
269         return in;
270 }
271
272
273 vector<bool> TestClass::getBooleanList(vector<bool> in) {
274
275         return in;
276 }
277
278
279 vector<char> TestClass::getCharList(vector<char> in) {
280
281         return in;
282 }
283
284
285 int TestClass::getA() {
286
287         return intA;
288 }
289
290
291 void TestClass::setA(int _int) {
292
293         intA = _int;
294 }
295
296
297 void TestClass::setB(float _float) {
298
299         floatB = _float;
300 }
301
302
303 void TestClass::setC(string _string) {
304
305         stringC = _string;
306 }
307
308
309 // Enum
310 Enum TestClass::handleEnum(Enum en) {
311
312         cout << "Enum: " << en << endl;
313         
314         return en;
315 }
316
317
318 vector<Enum> TestClass::handleEnumArray(vector<Enum> vecEn) {
319
320         for (Enum en : vecEn) {
321                 cout << "Enum: " << en << endl;
322         }
323         
324         return vecEn;
325 }
326
327
328 vector<Enum> TestClass::handleEnumList(vector<Enum> vecEn) {
329
330         for (Enum en : vecEn) {
331                 cout << "Enum: " << en << endl;
332         }
333         
334         return vecEn;
335 }
336
337
338 Enum TestClass::handleEnumComplex(Enum en, int i, char c) {
339
340         cout << "Enum: " << en << endl;
341         cout << "Integer: " << i << endl;
342         cout << "Char: " << c << endl;
343         
344         return en;
345 }
346
347
348 vector<Enum> TestClass::handleEnumComplex2(vector<Enum> vecEn, int in, char c) {
349
350         for (Enum en : vecEn) {
351                 cout << "Enum: " << en << endl;
352         }
353         cout << "Integer: " << in << endl;
354         cout << "Char: " << c << endl;
355         
356         return vecEn;
357 }
358
359
360 vector<Enum> TestClass::handleEnumTwo(vector<Enum> en1, vector<Enum> en2) {
361
362         for (Enum en : en1) {
363                 cout << "Enum1: " << en << endl;
364         }
365         for (Enum en : en2) {
366                 cout << "Enum2: " << en << endl;
367         }
368         
369         return en1;
370 }
371
372
373 vector<Enum> TestClass::handleEnumThree(vector<Enum> en1, vector<Enum> en2, vector<Struct> str1, vector<Struct> str2) {
374
375         for (Enum en : en1) {
376                 cout << "Enum1: " << en << endl;
377         }
378         for (Enum en : en2) {
379                 cout << "Enum2: " << en << endl;
380         }
381         
382         return en1;
383 }
384
385
386
387 // Struct
388 Struct TestClass::handleStruct(Struct str) {
389
390         cout << "Name: " << str.name << endl;
391         cout << "Value: " << str.value << endl;
392         cout << "Year: " << str.year << endl;
393
394         Struct test;
395         test.name = "Anonymous";
396         test.value = 1.33;
397         test.year = 2016;
398         str = test;
399
400         return str;
401 }
402
403
404 vector<Struct> TestClass::handleStructArray(vector<Struct> vecStr) {
405
406         for (Struct str : vecStr) {
407
408                 cout << "Name: " << str.name << endl;
409                 cout << "Value: " << str.value << endl;
410                 cout << "Year: " << str.year << endl;
411         }
412         Struct test;
413         test.name = "Anonymous";
414         test.value = 1.33;
415         test.year = 2016;
416         vecStr.push_back(test);
417
418         return vecStr;
419 }
420
421
422 vector<Struct> TestClass::handleStructList(vector<Struct> vecStr) {
423
424         for (Struct str : vecStr) {
425
426                 cout << "Name: " << str.name << endl;
427                 cout << "Value: " << str.value << endl;
428                 cout << "Year: " << str.year << endl;
429         }
430         Struct test;
431         test.name = "Trimananda";
432         test.value = 1.33;
433         test.year = 2016;
434         vecStr.push_back(test);
435
436         return vecStr;
437 }
438
439
440 vector<Struct> TestClass::handleStructTwo(vector<Struct> str1, vector<Struct> str2) {
441
442         for (Struct str : str1) {
443
444                 cout << "Name: " << str.name << endl;
445                 cout << "Value: " << str.value << endl;
446                 cout << "Year: " << str.year << endl;
447         }
448
449         return str2;
450 }
451
452
453 vector<Struct> TestClass::handleStructThree(vector<Struct> str1, vector<Struct> str2, vector<Struct> str3) {
454
455         for (Struct str : str1) {
456
457                 cout << "Name: " << str.name << endl;
458                 cout << "Value: " << str.value << endl;
459                 cout << "Year: " << str.year << endl;
460         }
461
462         return str2;
463 }
464
465
466 Struct TestClass::handleStructComplex(int in, char c, Struct str) {
467
468         cout << "Name: " << str.name << endl;
469         cout << "Value: " << str.value << endl;
470         cout << "Year: " << str.year << endl;
471
472         cout << "Integer: " << in << endl;
473         cout << "Char: " << c << endl;
474
475         Struct test;
476         test.name = "Anonymous";
477         test.value = 1.33;
478         test.year = 2016;
479         str = test;
480
481         return str;
482 }
483
484
485 vector<Struct> TestClass::handleStructComplex2(int in, char c, vector<Struct> vecStr) {
486
487         for (Struct str : vecStr) {
488                 cout << "Name: " << str.name << endl;
489                 cout << "Value: " << str.value << endl;
490                 cout << "Year: " << str.year << endl;
491         }
492
493         cout << "Integer: " << in << endl;
494         cout << "Char: " << c << endl;
495
496         return vecStr;
497 }
498
499
500 vector<Enum> TestClass::handleEnumStruct(vector<Enum> en, vector<Struct> str, char c) {
501
502         for (Struct st : str) {
503                 cout << "Name: " << st.name << endl;
504                 cout << "Value: " << st.value << endl;
505                 cout << "Year: " << st.year << endl;
506         }
507
508         cout << "Char: " << c << endl;
509
510         return en;
511 }
512
513
514 vector<Enum> TestClass::handleAll(vector<Enum> en, vector<Struct> str, char c, vector<CallBackInterfaceWithCallBack*> _cb) {
515
516         for (CallBackInterfaceWithCallBack* cb : _cb) {
517                 cbvec.push_back(cb);
518                 cout << "Registering callback object in array!" << endl;
519         }
520
521         for (Struct st : str) {
522                 cout << "Name: " << st.name << endl;
523                 cout << "Value: " << st.value << endl;
524                 cout << "Year: " << st.year << endl;
525         }
526
527         cout << "Char: " << c << endl;
528
529         return en;
530 }
531
532
533 vector<Enum> TestClass::handleAllTwo(vector<Enum> en1, vector<Enum> en2, vector<Struct> str1, vector<Struct> str2, char c, 
534                 vector<CallBackInterfaceWithCallBack*> _cb1, vector<CallBackInterfaceWithCallBack*> _cb2) {
535
536         for (CallBackInterfaceWithCallBack* cb : _cb1) {
537                 cbvec.push_back(cb);
538                 cout << "Registering callback object in array!" << endl;
539         }
540
541         for (Struct st : str1) {
542                 cout << "Name: " << st.name << endl;
543                 cout << "Value: " << st.value << endl;
544                 cout << "Year: " << st.year << endl;
545         }
546
547         cout << "Char: " << c << endl;
548
549         return en1;
550 }
551
552
553 vector<Enum> TestClass::handleCallbackEnum(vector<Enum> en, char c, vector<CallBackInterfaceWithCallBack*> _cb) {
554
555         for (CallBackInterfaceWithCallBack* cb : _cb) {
556                 cbvec.push_back(cb);
557                 cout << "Registering callback object in array!" << endl;
558         }
559
560         cout << "Char: " << c << endl;
561
562         return en;
563 }
564
565
566 string TestClass::sumArray(vector<string> newA) {
567
568         string sum = "";
569         int len = newA.size();
570         for(int c = 0; c < len; c++) {
571                 sum = sum + newA[c];
572         }
573         return sum;
574 }
575
576
577 int TestClass::setAndGetA(int newA) {
578
579         intA = newA;
580         return intA;
581 }
582
583
584 int TestClass::setACAndGetA(string newC, int newA) {
585
586         stringC = newC;
587         intA = newA;
588         return intA;
589 }
590
591 #endif
592