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