#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"
+#include "IoTRMIComm.hpp"
+#include "IoTRMICommClient.hpp"
+#include "IoTRMICommServer.hpp"
+
+#include <fstream>
using namespace std;
private:
Room *mainObj;
- vector<int> ports;
- string callbackAddress;
- IoTRMIObject *rmiObj;
-
- const static int object0Id = 0; //RoomSmart
+ IoTRMIComm *rmiComm;
+ char* methodBytes;
+ int methodLen;
+ int objectId = 4;
static set<int> set0Allowed;
-
+ // Synchronization variables
+ bool methodReceived = false;
+ bool didAlreadyInitWaitInvoke = false;
ofstream log;
- public:
- Room_Skeleton(Room *_mainObj, string _callbackAddress, int _port) {
- bool _bResult = false;
- mainObj = _mainObj;
- callbackAddress = _callbackAddress;
- // Logging
- int i=0;
- string file = "Room_Skeleton_cpp" + to_string(i) + ".log";
- while (ifstream(file.c_str())) {
- i++;
- file = "Room_Skeleton_cpp" + to_string(i) + ".log";
- }
- log.open(file);
- 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();
- }
- }
- }
+ public:
+ Room_Skeleton();
+ Room_Skeleton(Room*_mainObj, int _portSend, int _portRecv);
+ Room_Skeleton(Room*_mainObj, IoTRMIComm *rmiComm, int _objectId);
+ ~Room_Skeleton();
+ bool didInitWaitInvoke();
+ int getRoomID();
+ void ___getRoomID(Room_Skeleton* skel);
+ void ___waitRequestInvokeMethod(Room_Skeleton* skel);
};
set<int> Room_Skeleton::set0Allowed { 0 };
#endif