Removing printing statements from C++ RMI library - this will cause SO files to get...
[iot2.git] / iotjava / iotrmi / C++ / basics / TestClassCallbacks_Stub.cpp
1 #include <iostream>
2 #include <string>
3 #include "TestClassComplete_Stub.hpp"
4 #include "CallBack.hpp"
5
6 #include "CallBackInterface_Skeleton.cpp"
7
8 using namespace std;
9
10
11 TestClassComplete_Stub::TestClassComplete_Stub(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {
12         callbackAddress = _callbackAddress;
13         ports = _ports;
14         rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev, _bResult);
15         set0Allowed.insert(-9998);
16         //thread th1 (&TestClassComplete_Stub::___initCallBack, this);
17         //th1.detach();
18         ___regCB();
19 }
20
21 TestClassComplete_Stub::TestClassComplete_Stub(IoTRMICall* _rmiCall, string _callbackAddress, int _objIdCnt, vector<int> _ports) {
22         callbackAddress = _callbackAddress;
23         rmiCall = _rmiCall;
24         objIdCnt = _objIdCnt;
25         set0Allowed.insert(-9998);
26         //thread th1 (&TestClassComplete_Stub::___initCallBack, this);
27         //th1.detach();
28         ___regCB();
29 }
30
31 TestClassComplete_Stub::~TestClassComplete_Stub() {
32         if (rmiCall != NULL) {
33                 delete rmiCall;
34                 rmiCall = NULL;
35         }
36         if (rmiObj != NULL) {
37                 delete rmiObj;
38                 rmiObj = NULL;
39         }
40         for(CallBackInterface* cb : vecCallbackObj) {
41                 delete cb;
42                 cb = NULL;
43         }
44 }
45
46 void TestClassComplete_Stub::registerCallback(CallBackInterface* _cb) { 
47         //CallBackInterface_CallbackSkeleton* skel0 = new CallBackInterface_CallbackSkeleton(_cb, callbackAddress, objIdCnt++);
48         CallBackInterface_Skeleton* skel0 = new CallBackInterface_Skeleton(_cb, callbackAddress, objIdCnt++);
49         vecCallbackObj.push_back(skel0);
50         int ___paramCB0 = 1;
51         int methodId = 1;
52         string retType = "void";
53         int numParam = 1;
54         string paramCls[] = { "int" };
55         void* paramObj[] = { &___paramCB0 };
56         void* retObj = NULL;
57         rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
58 }
59
60 void TestClassComplete_Stub::___regCB() {
61         int numParam = 3;
62         int methodId = -9999;
63         string retType = "void";
64         string paramCls[] = { "int*", "String", "int" };
65         int rev = 0;
66         void* paramObj[] = { &ports, &callbackAddress, &rev };
67         void* retObj = NULL;
68         rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
69 }
70
71 short TestClassComplete_Stub::getShort(short in) { 
72         int methodId = 0;
73         string retType = "short";
74         int numParam = 1;
75         string paramCls[] = { "short" };
76         void* paramObj[] = { &in };
77         short retVal = 0;
78         void* retObj = &retVal;
79         rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
80         return retVal;
81 }
82
83 int TestClassComplete_Stub::callBack() { 
84         int methodId = 2;
85         string retType = "int";
86         int numParam = 0;
87         string paramCls[] = {  };
88         void* paramObj[] = {  };
89         int retVal = 0;
90         void* retObj = &retVal;
91         rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
92         return retVal;
93 }
94
95
96 int main(int argc, char *argv[])
97 {
98
99         int port = 5010;
100         const char* address = "localhost";
101         //const char* address = "192.168.2.191";        // RPi2
102         //const char* skeletonAddress = "128.195.136.170";      // dc-9.calit2.uci.edu
103         const char* skeletonAddress = "128.195.204.132";
104         const char* callbackAddress = "128.195.204.132";        // dw-2.eecs.uci.edu (this machine)
105         //const char* skeletonAddress = "192.168.2.108";        // RPi1
106         //const char* callbackAddress = "192.168.2.191";        // RPi2
107         int rev = 0;
108         bool bResult = false;
109         vector<int> ports;
110         ports.push_back(12345);
111         ports.push_back(22346);
112         //ports.push_back(32344);
113         //ports.push_back(43212);
114
115         TestClassComplete *tcStub = new TestClassComplete_Stub(port, skeletonAddress, callbackAddress, rev, &bResult, ports);
116         cout << "==== CALLBACK ====" << endl;
117         CallBackInterface *cbSingle = new CallBack(2354);
118         tcStub->registerCallback(cbSingle);
119         cout << "Return value from callback: " << tcStub->callBack() << endl;
120
121         return 0;
122 }