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