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