Adding class LabRoom for IoTRelation testing with C++ IoTSlave
[iot2.git] / benchmarks / drivers / Cpp / LabRoom / Room_Skeleton.hpp
1 #ifndef _ROOM_SKELETON_HPP__
2 #define _ROOM_SKELETON_HPP__
3 #include <iostream>
4 #include <fstream>
5 #include "Room.hpp"
6
7 #include <vector>
8 #include <set>
9 #include "IoTRMICall.hpp"
10 #include "IoTRMIObject.hpp"
11
12 using namespace std;
13
14 class Room_Skeleton : public Room
15 {
16         private:
17
18         Room *mainObj;
19         vector<int> ports;
20         string callbackAddress;
21         IoTRMIObject *rmiObj;
22
23         const static int object0Id = 0; //RoomSmart
24         static set<int> set0Allowed;
25         
26         ofstream log;
27         public:
28
29         Room_Skeleton(Room *_mainObj, string _callbackAddress, int _port) {
30                 bool _bResult = false;
31                 mainObj = _mainObj;
32                 callbackAddress = _callbackAddress;
33                 // Logging
34                 log.open("LightBulb_Skeleton_cpp.log");
35                 log << "Callback address: " << callbackAddress << endl;
36                 log << "Port: " << _port << endl;
37                 rmiObj = new IoTRMIObject(_port, &_bResult);
38                 log << "Established connection with slave! Wait request invoke now..." << endl;
39                 ___waitRequestInvokeMethod();
40         }
41
42         ~Room_Skeleton() {
43                 if (rmiObj != NULL) {
44                         delete rmiObj;
45                         rmiObj = NULL;
46                 }
47         }
48         
49         int getRoomID() {
50                 return mainObj->getRoomID();
51         }
52
53         void ___getRoomID() {
54                 string paramCls[] = {  };
55                 int numParam = 0;
56                 void* paramObj[] = {  };
57                 rmiObj->getMethodParams(paramCls, numParam, paramObj);
58                 int retVal = getRoomID();
59                 void* retObj = &retVal;
60                 rmiObj->sendReturnObj(retObj, "int");
61         }
62
63         void ___waitRequestInvokeMethod() {
64                 while (true) {
65                         log << "Getting into the while loop" << endl;
66                         rmiObj->getMethodBytes();
67                         log << "Getting method bytes now" << endl;
68                         log << "Method len: " << rmiObj->getMethodBytesLen() << endl;
69                         int _objectId = rmiObj->getObjectId();
70                         log << "Object Id: " << _objectId << endl;
71                         int methodId = rmiObj->getMethodId();
72                         log << "Method Id: " << methodId << endl;
73                         if (_objectId == object0Id) {
74                                 if (set0Allowed.find(methodId) == set0Allowed.end()) {
75                                         cerr << "Object with object Id: " << _objectId << "  is not allowed to access method: " << methodId << endl;
76                                         return;
77                                 }
78                         }
79                         else {
80                                 cerr << "Object Id: " << _objectId << " not recognized!" << endl;
81                                 return;
82                         }
83                         switch (methodId) {
84                                 case 0: ___getRoomID(); break;
85                                 default: 
86                                 cerr << "Method Id " << methodId << " not recognized!" << endl;
87                                 throw exception();
88                         }
89                 }
90         }
91
92 };
93 set<int> Room_Skeleton::set0Allowed { 0 };
94 #endif