2 #include "Room_Skeleton.hpp"
6 Room_Skeleton::Room_Skeleton(Room *_mainObj, int _portSend, int _portRecv) {
9 rmiComm = new IoTRMICommServer(_portSend, _portRecv, &_bResult);
10 IoTRMIUtil::mapSkel->insert(make_pair(_mainObj, this));
11 IoTRMIUtil::mapSkelId->insert(make_pair(_mainObj, objectId));
12 rmiComm->registerSkeleton(objectId, &methodReceived);
13 thread th1 (&Room_Skeleton::___waitRequestInvokeMethod, this, this);
17 Room_Skeleton::Room_Skeleton(Room *_mainObj, IoTRMIComm *_rmiComm, int _objectId) {
18 bool _bResult = false;
22 rmiComm->registerSkeleton(objectId, &methodReceived);
25 Room_Skeleton::~Room_Skeleton() {
26 if (rmiComm != NULL) {
32 bool Room_Skeleton::didInitWaitInvoke() {
33 return didAlreadyInitWaitInvoke;
36 int Room_Skeleton::getRoomID() {
37 return mainObj->getRoomID();
40 void Room_Skeleton::___getRoomID(Room_Skeleton* skel) {
41 char* localMethodBytes = new char[methodLen];
42 memcpy(localMethodBytes, skel->methodBytes, methodLen);
43 didGetMethodBytes.exchange(true);
44 string paramCls[] = { };
46 void* paramObj[] = { };
47 rmiComm->getMethodParams(paramCls, numParam, paramObj, localMethodBytes);
48 int retVal = getRoomID();
49 void* retObj = &retVal;
50 rmiComm->sendReturnObj(retObj, "int", localMethodBytes);
51 delete[] localMethodBytes;
54 void Room_Skeleton::___waitRequestInvokeMethod(Room_Skeleton* skel) {
55 skel->didAlreadyInitWaitInvoke = true;
57 if (!methodReceived) {
60 skel->methodBytes = skel->rmiComm->getMethodBytes();
61 skel->methodLen = skel->rmiComm->getMethodLength();
62 methodReceived = false;
63 int _objectId = skel->rmiComm->getObjectId(skel->methodBytes);
64 int methodId = skel->rmiComm->getMethodId(skel->methodBytes);
65 if (_objectId == objectId) {
66 if (set0Allowed.find(methodId) == set0Allowed.end()) {
67 cerr << "Object with object Id: " << _objectId << " is not allowed to access method: " << methodId << endl;
76 thread th0 (&Room_Skeleton::___getRoomID, skel, skel);
80 cerr << "Method Id " << methodId << " not recognized!" << endl;
86 extern "C" void* createRoom_Skeleton(void** params) {
87 // Args: *_mainObj, int _portSend, int _portRecv
88 return new Room_Skeleton((Room*) params[0], *((int*) params[1]), *((int*) params[2]));
91 extern "C" void destroyRoom_Skeleton(void* t) {
92 Room_Skeleton* obj = (Room_Skeleton*) t;
96 extern "C" void initRoom_Skeleton(void* t) {