--- /dev/null
+#include <iostream>
+#include <thread>
+#include "RoomSmart_Stub.hpp"
+
+// External create, destroy, and init functions
+extern "C" void* createRoomSmart_Stub(void** params) {
+ // Arguments: int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports
+ return new RoomSmart_Stub(*((int*) params[0]), ((string*) params[1])->c_str(), *((string*) params[2]), *((int*) params[3]), (bool*) params[4], *((vector<int>*) params[5]));
+}
+
+
+extern "C" void destroyRoomSmart_Stub(void* t) {
+ RoomSmart_Stub* rss = (RoomSmart_Stub*) t;
+ delete rss;
+}
+
+
--- /dev/null
+#ifndef _ROOMSMART_STUB_HPP__
+#define _ROOMSMART_STUB_HPP__
+#include <iostream>
+#include <fstream>
+#include "RoomSmart.hpp"
+
+using namespace std;
+
+class RoomSmart_Stub : public RoomSmart
+{
+ private:
+
+ IoTRMICall *rmiCall;
+ string callbackAddress;
+ vector<int> ports;
+
+ const static int objectId = 0;
+
+ ofstream log;
+ public:
+
+ RoomSmart_Stub() { }
+
+ RoomSmart_Stub(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {
+ callbackAddress = _callbackAddress;
+ ports = _ports;
+ // Logging
+ log.open("RoomSmart_Stub_cpp.log");
+ log << "Port: " << _port << endl;
+ log << "Skeleton address: " << _skeletonAddress << endl;
+ log << "Callback address: " << callbackAddress << endl;
+ log << "Rev: " << _rev << endl;
+ log << "bResult: " << *_bResult << endl;
+ log << "Ports: " << _ports[0] << endl;
+ rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev, _bResult);
+ log << "Established connection with skeleton!" << endl;
+ }
+
+ ~RoomSmart_Stub() {
+ if (rmiCall != NULL) {
+ delete rmiCall;
+ rmiCall = NULL;
+ }
+ }
+
+ int getRoomID() {
+ log << "Calling getRoomID() in stub!" << endl;
+ int methodId = 0;
+ string retType = "int";
+ int numParam = 0;
+ string paramCls[] = { };
+ void* paramObj[] = { };
+ int retVal = 0;
+ void* retObj = &retVal;
+ log << "About to remote call!" << endl;
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
+ log << "Remote call performed!" << endl;
+ return retVal;
+ }
+
+};
+#endif
--- /dev/null
+# Skeleton/original interface
+INTERFACE_CLASS=Room
+# Stub
+INTERFACE_STUB_CLASS=RoomSmart
+
+# For C++ instrumentation
+FIELD_NUMBER=0
+
--- /dev/null
+#include <iostream>
+#include "LabRoom.hpp"
+
+using namespace std;
+
+// External functions to create, destroy and initialize this class object
+extern "C" void* createLabRoom(void** params) {
+ // Arguments: IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress
+ return new LabRoom();
+}
+
+
+extern "C" void destroyLabRoom(void* t) {
+ LabRoom* lr = (LabRoom*) t;
+ delete lr;
+}
+
+
+// Constructor
+LabRoom::LabRoom() {
+
+}
+
+LabRoom::~LabRoom() {
+
+}
+
+int LabRoom::getRoomID() {
+
+ return 0;
+}
--- /dev/null
+#ifndef _LABROOM_HPP__
+#define _LABROOM_HPP__
+#include <iostream>
+#include <fstream>
+
+#include "Room.hpp"
+
+using namespace std;
+
+class LabRoom : public Room
+{
+
+ public:
+ LabRoom();
+ ~LabRoom();
+
+ int getRoomID();
+};
+#endif
--- /dev/null
+#include <iostream>
+#include "Room_Skeleton.hpp"
+
+
+// External create, destroy, and init functions
+extern "C" void* createRoom_Skeleton(void** params) {
+ // Arguments: Room *_mainObj, string _callbackAddress, int _port
+ return new Room_Skeleton((Room*) params[0], *((string*) params[1]), *((int*) params[2]));
+}
+
+
+extern "C" void destroyRoom_Skeleton(void* t) {
+ Room_Skeleton* rs = (Room_Skeleton*) t;
+ delete rs;
+}
+
+
+
--- /dev/null
+#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
--- /dev/null
+#ifndef _ROOM_HPP__
+#define _ROOM_HPP__
+#include <iostream>
+
+using namespace std;
+
+class Room
+{
+ public:
+ virtual int getRoomID() = 0;
+};
+#endif
--- /dev/null
+#ifndef _ROOMSMART_HPP__
+#define _ROOMSMART_HPP__
+#include <iostream>
+#include <vector>
+#include <set>
+#include "IoTRMICall.hpp"
+#include "IoTRMIObject.hpp"
+
+using namespace std;
+
+class RoomSmart
+{
+ public:
+ virtual int getRoomID() = 0;
+};
+#endif
--- /dev/null
+SELECT * FROM
+RoomSmart
+WHERE
+TYPE='LabRoom'
+;
--- /dev/null
+SELECT RELATION FROM
+FIRST
+RoomSmart
+OTHER
+LightBulbTest
+WHERE
+TYPE_SOURCE LIKE 'LabRoom%'
+;