3611bbffd49211c420813ec2c7403069d33c8325
[iot2.git] / iotjava / iotrmi / C++ / sample / TestClass_Stub.hpp
1 #include <iostream>
2 #include "../IoTRMICall.hpp"
3 #include "TestClassInterface.hpp"
4
5 using namespace std;
6
7 class TestClass_Stub : public TestClassInterface {
8         public:
9                 TestClass_Stub();
10                 TestClass_Stub(int _port, const char* _address, int _rev, bool* _bResult);
11                 ~TestClass_Stub();
12
13                 void                            setA(int _int);
14                 void                            setB(float _float);
15                 void                            setC(string _string);
16                 string                          sumArray(vector<string> newA);
17                 //int64_t                               sumArray(vector<int> newA);
18                 int                                     setAndGetA(int newA);
19                 int                                     setACAndGetA(string newC, int newA);
20                 //void                          registerCallback(CallBackInterface _cb);
21                 //int                           callBack();
22
23         private:                
24                 int                                     intA;
25                 float                           floatB;
26                 string                          stringC;
27                 //CallBackInterface cb;
28                 IoTRMICall                      *rmiCall;
29                 string                          address;
30                 //vector<int>                   ports;
31
32                 const static int size = 8;
33                 string methodSignatures[size] = {
34
35                         "voidsetA(int)",
36                         "voidsetB(float)",
37                         "voidsetC(string)",
38                         "sumArray(string[])",
39                         //"sumArray(int[])",
40                         "intsetAndGetA(int)",
41                         "intsetACAndGetA(string,int)",
42                         "intcallBack()",
43                         "voidregisterCallBack(CallBackInterface)"
44                 };
45 };
46
47
48 TestClass_Stub::TestClass_Stub() {
49
50         address = "";
51         rmiCall = NULL;
52 }
53
54
55 TestClass_Stub::TestClass_Stub(int _port, const char* _address, int _rev, bool* _bResult) {
56
57         address = _address;
58         rmiCall = new IoTRMICall(_port, _address, _rev, _bResult, methodSignatures, size);
59 }
60
61
62 TestClass_Stub::~TestClass_Stub() {
63
64         if (rmiCall != NULL) {
65                 delete rmiCall;
66                 rmiCall = NULL;
67         }
68 }
69
70
71 void TestClass_Stub::setA(int _int) {
72
73         int numParam = 1;
74         string sign = "voidsetA(int)";
75         string retType = "void";
76         string paramCls[] = { "int" };
77         void* paramObj[] = { &_int };
78         void* retObj = NULL;
79         rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
80 }
81
82
83 void TestClass_Stub::setB(float _float) {
84
85         int numParam = 1;
86         string sign = "voidsetB(float)";
87         string retType = "void";
88         string paramCls[] = { "float" };
89         void* paramObj[] = { &_float };
90         void* retObj = NULL;
91         rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
92 }
93
94
95 void TestClass_Stub::setC(string _string) {
96
97         int numParam = 1;
98         string sign = "voidsetC(string)";
99         string retType = "void";
100         string paramCls[] = { "string" };
101         void* paramObj[] = { &_string };
102         void* retObj = NULL;
103         rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
104 }
105
106
107 string TestClass_Stub::sumArray(vector<string> newA) {
108
109         int numParam = 1;
110         string sign = "sumArray(string[])";
111         string retType = "string";
112         string paramCls[] = { "string[]" };
113         void* paramObj[] = { &newA };
114         string retVal = "";
115         void* retObj = &retVal;
116         rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
117         return retVal;
118 }
119
120
121 /*int64_t TestClass_Stub::sumArray(vector<int> newA) {
122
123         int numParam = 1;
124         string sign = "sumArray(int[])";
125         string retType = "long";
126         string paramCls[] = { "int[]" };
127         void* paramObj[] = { &newA };
128         int64_t retVal = 0;
129         void* retObj = &retVal;
130         rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
131         return retVal;
132 }*/
133
134
135
136 int TestClass_Stub::setAndGetA(int newA) {
137
138         int numParam = 1;
139         string sign = "intsetAndGetA(int)";
140         string retType = "int";
141         string paramCls[] = { "int" };
142         void* paramObj[] = { &newA };
143         int retVal = 0;
144         void* retObj = &retVal;
145         rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
146         return retVal;
147 }
148
149
150 int TestClass_Stub::setACAndGetA(string newC, int newA) {
151
152         int numParam = 2;
153         string sign = "intsetACAndGetA(string,int)";
154         string retType = "int";
155         string paramCls[] = { "string", "int" };
156         void* paramObj[] = { &newC, &newA };
157         int retVal = 0;
158         void* retObj = &retVal;
159         rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
160         return retVal;
161 }
162
163
164 /*void TestClass_Stub::registerCallback(CallBackInterface _cb) {
165
166         cb = _cb;
167 }
168
169
170 int TestClass_Stub::callBack() {
171
172         return cb.printInt();
173 }*/
174