Adding class LabRoom for IoTRelation testing with C++ IoTSlave
authorrtrimana <rtrimana@uci.edu>
Sat, 21 Jan 2017 00:43:24 +0000 (16:43 -0800)
committerrtrimana <rtrimana@uci.edu>
Sat, 21 Jan 2017 00:43:24 +0000 (16:43 -0800)
benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp [new file with mode: 0644]
benchmarks/Cpp/Lifxtest/RoomSmart_Stub.hpp [new file with mode: 0644]
benchmarks/drivers/Cpp/LabRoom/LabRoom.config [new file with mode: 0644]
benchmarks/drivers/Cpp/LabRoom/LabRoom.cpp [new file with mode: 0644]
benchmarks/drivers/Cpp/LabRoom/LabRoom.hpp [new file with mode: 0644]
benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.cpp [new file with mode: 0644]
benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.hpp [new file with mode: 0644]
benchmarks/virtuals/Room.hpp [new file with mode: 0644]
benchmarks/virtuals/RoomSmart.hpp [new file with mode: 0644]
localconfig/mysql/lab_room.config [new file with mode: 0644]
localconfig/mysql/roomLightRelation.config [new file with mode: 0644]

diff --git a/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp b/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp
new file mode 100644 (file)
index 0000000..7650e52
--- /dev/null
@@ -0,0 +1,17 @@
+#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;
+}
+
+
diff --git a/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.hpp b/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.hpp
new file mode 100644 (file)
index 0000000..b576cfc
--- /dev/null
@@ -0,0 +1,62 @@
+#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
diff --git a/benchmarks/drivers/Cpp/LabRoom/LabRoom.config b/benchmarks/drivers/Cpp/LabRoom/LabRoom.config
new file mode 100644 (file)
index 0000000..6d899b8
--- /dev/null
@@ -0,0 +1,8 @@
+# Skeleton/original interface
+INTERFACE_CLASS=Room
+# Stub
+INTERFACE_STUB_CLASS=RoomSmart
+
+# For C++ instrumentation
+FIELD_NUMBER=0
+
diff --git a/benchmarks/drivers/Cpp/LabRoom/LabRoom.cpp b/benchmarks/drivers/Cpp/LabRoom/LabRoom.cpp
new file mode 100644 (file)
index 0000000..6b79706
--- /dev/null
@@ -0,0 +1,31 @@
+#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;
+}
diff --git a/benchmarks/drivers/Cpp/LabRoom/LabRoom.hpp b/benchmarks/drivers/Cpp/LabRoom/LabRoom.hpp
new file mode 100644 (file)
index 0000000..2559fe7
--- /dev/null
@@ -0,0 +1,19 @@
+#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
diff --git a/benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.cpp b/benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.cpp
new file mode 100644 (file)
index 0000000..f46eae2
--- /dev/null
@@ -0,0 +1,18 @@
+#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;
+}
+
+
+
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
diff --git a/benchmarks/virtuals/Room.hpp b/benchmarks/virtuals/Room.hpp
new file mode 100644 (file)
index 0000000..2049313
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _ROOM_HPP__
+#define _ROOM_HPP__
+#include <iostream>
+
+using namespace std;
+
+class Room
+{
+       public:
+       virtual int getRoomID() = 0;
+};
+#endif
diff --git a/benchmarks/virtuals/RoomSmart.hpp b/benchmarks/virtuals/RoomSmart.hpp
new file mode 100644 (file)
index 0000000..7a9e845
--- /dev/null
@@ -0,0 +1,16 @@
+#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
diff --git a/localconfig/mysql/lab_room.config b/localconfig/mysql/lab_room.config
new file mode 100644 (file)
index 0000000..0749e75
--- /dev/null
@@ -0,0 +1,5 @@
+SELECT * FROM
+RoomSmart
+WHERE
+TYPE='LabRoom'
+;
diff --git a/localconfig/mysql/roomLightRelation.config b/localconfig/mysql/roomLightRelation.config
new file mode 100644 (file)
index 0000000..4711357
--- /dev/null
@@ -0,0 +1,8 @@
+SELECT RELATION FROM
+FIRST
+RoomSmart
+OTHER
+LightBulbTest
+WHERE
+TYPE_SOURCE LIKE 'LabRoom%' 
+;