Doing the same set of transformations for C++
[iot2.git] / iotjava / iotrmi / C++ / sample / CallBack_Stub.hpp
1 #ifndef _CALLBACK_STUB_HPP__
2 #define _CALLBACK_STUB_HPP__
3
4 #include <iostream>
5 #include "CallBackInterface.hpp"
6 #include "../IoTRMICall.hpp"
7
8 using namespace std;
9
10 class CallBack_Stub : public CallBackInterface {
11         public:
12                 CallBack_Stub();
13                 CallBack_Stub(int _port, const char* _address, int _rev, bool* _bResult);
14                 ~CallBack_Stub();
15
16                 int                             printInt();
17                 void                    setInt(int _i);
18
19                 const static int size = 2;
20                 const static string methodSignatures[size];
21
22         private:                
23
24                 IoTRMICall      *rmiCall;
25                 string          address;
26                 int             objectId = 0;   // Default value is 0
27 };
28
29
30 const string CallBack_Stub::methodSignatures[CallBack_Stub::size] = {
31
32         "intprintInt()",
33         "voidsetInt(int)"
34 };
35
36
37 // Constructor
38 CallBack_Stub::CallBack_Stub() {
39
40         address = "";
41         rmiCall = NULL;
42 }
43
44
45 CallBack_Stub::CallBack_Stub(int _port, const char* _address, int _rev, bool* _bResult) {
46
47         address = _address;
48         rmiCall = new IoTRMICall(_port, _address, _rev, _bResult);
49 }
50
51
52 CallBack_Stub::~CallBack_Stub() {
53
54         if (rmiCall != NULL) {
55                 delete rmiCall;
56                 rmiCall = NULL;
57         }
58 }
59
60
61 int CallBack_Stub::printInt() {
62
63         int numParam = 0;
64         int methodId = 0;
65         string retType = "int";
66         string paramCls[] = { };
67         void* paramObj[] = { };
68         int retVal = 0;
69         void* retObj = &retVal;
70         rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
71         return retVal;
72 }
73
74
75 void CallBack_Stub::setInt(int _i) {
76
77         int numParam = 1;
78         int methodId = 1;
79         string retType = "void";
80         string paramCls[] = { "int" };
81         void* paramObj[] = { &_i };
82         void* retObj = NULL;
83         rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
84 }
85
86 #endif