Adding class LabRoom for IoTRelation testing with C++ IoTSlave
[iot2.git] / benchmarks / drivers / Cpp / LabRoom / Room_Skeleton.hpp
diff --git a/benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.hpp b/benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.hpp
new file mode 100644 (file)
index 0000000..1cb96d8
--- /dev/null
@@ -0,0 +1,94 @@
+#ifndef _ROOM_SKELETON_HPP__
+#define _ROOM_SKELETON_HPP__
+#include <iostream>
+#include <fstream>
+#include "Room.hpp"
+
+#include <vector>
+#include <set>
+#include "IoTRMICall.hpp"
+#include "IoTRMIObject.hpp"
+
+using namespace std;
+
+class Room_Skeleton : public Room
+{
+       private:
+
+       Room *mainObj;
+       vector<int> ports;
+       string callbackAddress;
+       IoTRMIObject *rmiObj;
+
+       const static int object0Id = 0; //RoomSmart
+       static set<int> set0Allowed;
+       
+       ofstream log;
+       public:
+
+       Room_Skeleton(Room *_mainObj, string _callbackAddress, int _port) {
+               bool _bResult = false;
+               mainObj = _mainObj;
+               callbackAddress = _callbackAddress;
+               // Logging
+               log.open("LightBulb_Skeleton_cpp.log");
+               log << "Callback address: " << callbackAddress << endl;
+               log << "Port: " << _port << endl;
+               rmiObj = new IoTRMIObject(_port, &_bResult);
+               log << "Established connection with slave! Wait request invoke now..." << endl;
+               ___waitRequestInvokeMethod();
+       }
+
+       ~Room_Skeleton() {
+               if (rmiObj != NULL) {
+                       delete rmiObj;
+                       rmiObj = NULL;
+               }
+       }
+       
+       int getRoomID() {
+               return mainObj->getRoomID();
+       }
+
+       void ___getRoomID() {
+               string paramCls[] = {  };
+               int numParam = 0;
+               void* paramObj[] = {  };
+               rmiObj->getMethodParams(paramCls, numParam, paramObj);
+               int retVal = getRoomID();
+               void* retObj = &retVal;
+               rmiObj->sendReturnObj(retObj, "int");
+       }
+
+       void ___waitRequestInvokeMethod() {
+               while (true) {
+                       log << "Getting into the while loop" << endl;
+                       rmiObj->getMethodBytes();
+                       log << "Getting method bytes now" << endl;
+                       log << "Method len: " << rmiObj->getMethodBytesLen() << endl;
+                       int _objectId = rmiObj->getObjectId();
+                       log << "Object Id: " << _objectId << endl;
+                       int methodId = rmiObj->getMethodId();
+                       log << "Method Id: " << methodId << endl;
+                       if (_objectId == object0Id) {
+                               if (set0Allowed.find(methodId) == set0Allowed.end()) {
+                                       cerr << "Object with object Id: " << _objectId << "  is not allowed to access method: " << methodId << endl;
+                                       return;
+                               }
+                       }
+                       else {
+                               cerr << "Object Id: " << _objectId << " not recognized!" << endl;
+                               return;
+                       }
+                       switch (methodId) {
+                               case 0: ___getRoomID(); break;
+                               default: 
+                               cerr << "Method Id " << methodId << " not recognized!" << endl;
+                               throw exception();
+                       }
+               }
+       }
+
+};
+set<int> Room_Skeleton::set0Allowed { 0 };
+#endif