From 97db3fd3c9be0d324ea4a1a7f410c8d7ec45f055 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Mon, 23 Jan 2017 14:45:55 -0800 Subject: [PATCH] Working C++ IoTSlave for both IoTSet and IoTRelation; threading works for C++ LifxLightBulb driver in x86_64 binary but not in ARM version --- benchmarks/Cpp/Lifxtest/Lifxtest.config | 15 +- benchmarks/Cpp/Lifxtest/Lifxtest.cpp | 138 ++++++++++++++++-- benchmarks/Cpp/Lifxtest/Lifxtest.hpp | 8 +- .../Cpp/Lifxtest/LightBulbTest_Stub.cpp | 6 +- .../Cpp/Lifxtest/LightBulbTest_Stub.hpp | 18 ++- benchmarks/Cpp/Lifxtest/Makefile | 25 +++- benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp | 7 + benchmarks/Cpp/Lifxtest/RoomSmart_Stub.hpp | 8 +- benchmarks/drivers/Cpp/LabRoom/LabRoom.cpp | 9 ++ .../drivers/Cpp/LabRoom/Room_Skeleton.cpp | 7 + .../drivers/Cpp/LabRoom/Room_Skeleton.hpp | 8 +- .../Cpp/LifxLightBulb/LifxLightBulb.cpp | 41 +++--- .../Cpp/LifxLightBulb/LightBulb_Skeleton.cpp | 6 +- .../Cpp/LifxLightBulb/LightBulb_Skeleton.hpp | 8 +- benchmarks/drivers/Cpp/Makefile | 37 ++++- iotjava/Makefile | 1 - iotjava/iotruntime/cpp/iotslave/IoTSlave.cpp | 37 ++++- iotjava/iotruntime/cpp/iotslave/IoTSlave.hpp | 8 +- iotjava/iotruntime/master/IoTMaster.java | 116 ++++++++------- iotjava/iotruntime/messages/IoTCommCode.java | 1 + 20 files changed, 391 insertions(+), 113 deletions(-) diff --git a/benchmarks/Cpp/Lifxtest/Lifxtest.config b/benchmarks/Cpp/Lifxtest/Lifxtest.config index 39b3a38..a5c5a5c 100644 --- a/benchmarks/Cpp/Lifxtest/Lifxtest.config +++ b/benchmarks/Cpp/Lifxtest/Lifxtest.config @@ -1,7 +1,20 @@ ADDITIONAL_ZIP_FILE=No # For C++ instrumentation -FIELD_NUMBER=1 +FIELD_NUMBER=3 + +# Field lifx_light_bulb FIELD_0=lifx_light_bulb FIELD_CLASS_0=LightBulbTest FIELD_TYPE_0=IoTSet + +# Field lab_room +FIELD_1=lab_room +FIELD_CLASS_1=RoomSmart +FIELD_TYPE_1=IoTSet + +# Field roomLightRelation +FIELD_2=roomLightRelation +FIELD_CLASS_2=RoomSmart +FIELD_CLASS_REL_2=LightBulbTest +FIELD_TYPE_2=IoTRelation diff --git a/benchmarks/Cpp/Lifxtest/Lifxtest.cpp b/benchmarks/Cpp/Lifxtest/Lifxtest.cpp index 53cb425..7e93b4c 100644 --- a/benchmarks/Cpp/Lifxtest/Lifxtest.cpp +++ b/benchmarks/Cpp/Lifxtest/Lifxtest.cpp @@ -4,13 +4,15 @@ #include "Lifxtest.hpp" #include "LifxLightBulb.cpp" +#include "LabRoom.cpp" #include "Iterator.hpp" // External create, destroy, and init functions extern "C" void* createLifxtest(void** params) { // Arguments: IoTSet* lifx_light_bulb - return new Lifxtest((IoTSet*) params[0]); + //return new Lifxtest((IoTSet*) params[0]); + return new Lifxtest((IoTSet*) params[0], (IoTSet*) params[1], (IoTRelation*) params[2]); } @@ -25,11 +27,15 @@ extern "C" void initLifxtest(void* t) { lt->init(); } + +// Empty constructor (for testing) Lifxtest::Lifxtest() { log.open("Lifxtest_object_cpp.log"); log << "lifx_light_bulb initialized!" << endl; } + +// Constructor with only 1 IoTSet object (lifx_light_bulb) Lifxtest::Lifxtest(IoTSet* _lifx_light_bulb) { log.open("Lifxtest_object_cpp.log"); @@ -37,6 +43,19 @@ Lifxtest::Lifxtest(IoTSet* _lifx_light_bulb) { log << "lifx_light_bulb initialized!" << endl; } + +// Constructor with 2 IoTSet and 1 IoTRelation objects +Lifxtest::Lifxtest(IoTSet* _lifx_light_bulb, IoTSet* _lab_room, IoTRelation* _roomLightRelation) { + + log.open("Lifxtest_object_cpp.log"); + lifx_light_bulb = _lifx_light_bulb; + lab_room = _lab_room; + roomLightRelation = _roomLightRelation; + log << "lifx_light_bulb initialized!" << endl; +} + + +// Constructor with void** argument Lifxtest::Lifxtest(void** args) { log.open("Lifxtest_object_cpp.log"); @@ -49,7 +68,7 @@ Lifxtest::~Lifxtest() { } -void Lifxtest::init() { +/*void Lifxtest::init() { unordered_set* bulbSet = lifx_light_bulb->values(); //for (unordered_set::const_iterator itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) { @@ -63,19 +82,21 @@ void Lifxtest::init() { log << "Executing init!" << endl; this_thread::sleep_for (chrono::milliseconds(1000)); - for (int i = 0; i < 5; i++) { - lifx->turnOff(); + for (int i = 0; i < 10; i++) { + + lifx->init(); +// lifx->turnOff(); //cout << "Turning off!" << endl; log << "Turning off!" << endl; this_thread::sleep_for (chrono::milliseconds(1000)); - lifx->turnOn(); +// lifx->turnOn(); //cout << "Turning on!" << endl; log << "Turning on!" << i << endl; this_thread::sleep_for (chrono::milliseconds(1000)); } - - for (int i = 2500; i < 9000; i += 100) { +*/ +/* for (int i = 2500; i < 9000; i += 100) { //cout << "Adjusting Temp: " << i << endl; log << "Adjusting Temp: " << i << endl; lifx->setTemperature(i); @@ -107,11 +128,82 @@ void Lifxtest::init() { log << "End of iteration.. closing!" << endl; log.close(); - while(true) { } // Testing infinite loop - will need to do "pkill IoTSlave" -} + //while(true) { } // Testing infinite loop - will need to do "pkill IoTSlave" +}*/ + +void Lifxtest::init() { -/*int main(int argc, char *argv[]) + unordered_set* bulbSet = lifx_light_bulb->values(); + unordered_set* roomSet = lab_room->values(); + unordered_multimap* roomLightRel = roomLightRelation->values(); + log << "Size of map: " << roomLightRel->size() << endl; + //for (unordered_set::const_iterator itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) { + for (auto itr = roomSet->begin(); itr != roomSet->end(); ++itr) { + log << "Getting Room!" << endl; + //Room* rs = (Room*) *itr; + RoomSmart* rs = (RoomSmart*) *itr; + log << "Getting Room! ID: " << rs->getRoomID() << endl; + auto itrLight = roomLightRel->find(rs); + + if (itrLight == roomLightRel->end()) + log << "No match!" << endl; + //while (itrLight != roomLightRel->end()) { + else { + //LightBulb* lifx = (LightBulb*) itrLight->second; + log << "Getting LightBulb!" << endl; + LightBulbTest* lifx = (LightBulbTest*) itrLight->second; + log << "Executing init!" << endl; + lifx->init(); + for (int i = 0; i < 10; i++) { + lifx->turnOff(); + //cout << "Turning off!" << endl; + log << "Turning off!" << endl; + this_thread::sleep_for (chrono::milliseconds(1000)); + lifx->turnOn(); + //cout << "Turning on!" << endl; + log << "Turning on!" << i << endl; + this_thread::sleep_for (chrono::milliseconds(1000)); + } + for (int i = 2500; i < 9000; i += 100) { + //cout << "Adjusting Temp: " << i << endl; + log << "Adjusting Temp: " << i << endl; + lifx->setTemperature(i); + this_thread::sleep_for (chrono::milliseconds(100)); + } + + for (int i = 9000; i > 2500; i -= 100) { + //cout << "Adjusting Temp: " << i << endl; + log << "Adjusting Temp: " << i << endl; + lifx->setTemperature(i); + this_thread::sleep_for (chrono::milliseconds(100)); + } + + for (int i = 100; i > 0; i -= 10) { + //cout << "Adjusting Brightness: " << i << endl; + log << "Adjusting Brightness: " << i << endl; + lifx->setColor(lifx->getHue(), lifx->getSaturation(), i); + this_thread::sleep_for (chrono::milliseconds(500)); + } + + for (int i = 0; i < 100; i += 10) { + //cout << "Adjusting Brightness: " << i << endl; + log << "Adjusting Brightness: " << i << endl; + lifx->setColor(lifx->getHue(), lifx->getSaturation(), i); + this_thread::sleep_for (chrono::milliseconds(500)); + } + //++itrLight; + } + log << "End of one LightBulb!" << endl << endl; + } + + log << "End of iteration.. closing!" << endl; + log.close(); + //while(true) { } // Testing infinite loop - will need to do "pkill IoTSlave" +} + +/* +int main(int argc, char *argv[]) { // LightBulb #1 string macAddress1 = "D073D5128E300000"; @@ -138,10 +230,25 @@ void Lifxtest::init() { setLb->insert(llb2); IoTSet* lbSet = new IoTSet(setLb); + // Set of rooms + LabRoom *lr1 = new LabRoom(); + LabRoom *lr2 = new LabRoom(); + unordered_set* setLR = new unordered_set(); + setLR->insert(lr1); + setLR->insert(lr2); + IoTSet* lrSet = new IoTSet(setLR); + + pair* pair1 = new pair(lr1, llb1); + pair* pair2 = new pair(lr2, llb2); + unordered_multimap* mmap = new unordered_multimap(); + mmap->insert(*pair1); + mmap->insert(*pair2); + IoTRelation* rlRel = new IoTRelation(mmap); + //void* args[1]; //args[0] = (void*) lbSet; //Lifxtest *lt = new Lifxtest(args); - Lifxtest *lt = new Lifxtest(lbSet); + Lifxtest *lt = new Lifxtest(lbSet, lrSet, rlRel); lt->init(); //delete llb1; @@ -154,8 +261,13 @@ void Lifxtest::init() { delete setDevAddress2; delete setLb; delete lbSet; + delete lr1; + delete lr2; + delete lrSet; + delete pair1; + delete pair2; return 0; -} -*/ +}*/ + diff --git a/benchmarks/Cpp/Lifxtest/Lifxtest.hpp b/benchmarks/Cpp/Lifxtest/Lifxtest.hpp index eb8c15b..c074848 100644 --- a/benchmarks/Cpp/Lifxtest/Lifxtest.hpp +++ b/benchmarks/Cpp/Lifxtest/Lifxtest.hpp @@ -4,15 +4,20 @@ #include #include "IoTSet.hpp" +#include "IoTRelation.hpp" #include "LightBulb.hpp" #include "LightBulbTest.hpp" +#include "Room.hpp" +#include "RoomSmart.hpp" class Lifxtest { private: // IoTSet - IoTSet* lifx_light_bulb; + IoTSet* lifx_light_bulb; // LightBulbTest + IoTSet* lab_room; // RoomSmart + IoTRelation* roomLightRelation; // RoomSmart and LightBulbTest ofstream log; @@ -20,6 +25,7 @@ class Lifxtest { Lifxtest(); Lifxtest(IoTSet* _lifx_light_bulb); + Lifxtest(IoTSet* _lifx_light_bulb, IoTSet* _lab_room, IoTRelation* _roomLightRelation); Lifxtest(void** args); ~Lifxtest(); void init(); diff --git a/benchmarks/Cpp/Lifxtest/LightBulbTest_Stub.cpp b/benchmarks/Cpp/Lifxtest/LightBulbTest_Stub.cpp index 18fb780..02e450b 100644 --- a/benchmarks/Cpp/Lifxtest/LightBulbTest_Stub.cpp +++ b/benchmarks/Cpp/Lifxtest/LightBulbTest_Stub.cpp @@ -31,14 +31,14 @@ int main(int argc, char *argv[]) int rev = 0; bool result = false; LightBulbTest_Stub *lbs = new LightBulbTest_Stub(stubPort, skeletonAddress, callbackAddress, rev, &result, ports); - cout << "Successfully instantiated stub!" << endl; + //cout << "Successfully instantiated stub!" << endl; lbs->init(); for (int i = 0; i < 100; i++) { lbs->turnOff(); - cout << "Turning off!" << endl; + //cout << "Turning off!" << endl; this_thread::sleep_for (chrono::milliseconds(1000)); lbs->turnOn(); - cout << "Turning on!" << endl; + //cout << "Turning on!" << endl; this_thread::sleep_for (chrono::milliseconds(1000)); } diff --git a/benchmarks/Cpp/Lifxtest/LightBulbTest_Stub.hpp b/benchmarks/Cpp/Lifxtest/LightBulbTest_Stub.hpp index 3e20d5b..a855a73 100644 --- a/benchmarks/Cpp/Lifxtest/LightBulbTest_Stub.hpp +++ b/benchmarks/Cpp/Lifxtest/LightBulbTest_Stub.hpp @@ -26,7 +26,13 @@ class LightBulbTest_Stub : public LightBulbTest callbackAddress = _callbackAddress; ports = _ports; // Logging - log.open("LightBulbTest_Stub_cpp.log"); + int i=0; + string file = "LightBulbTest_Stub_cpp" + to_string(i) + ".log"; + while (ifstream(file.c_str())) { + i++; + file = "LightBulbTest_Stub_cpp" + to_string(i) + ".log"; + } + log.open(file); log << "Port: " << _port << endl; log << "Skeleton address: " << _skeletonAddress << endl; log << "Callback address: " << callbackAddress << endl; @@ -45,14 +51,17 @@ class LightBulbTest_Stub : public LightBulbTest } } - void turnOn() { + void turnOn() { + log << "Calling turnOn() in stub!" << endl; int methodId = 2; string retType = "void"; int numParam = 0; string paramCls[] = { }; void* paramObj[] = { }; void* retObj = NULL; + log << "About to remote call!" << endl; rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj); + log << "Remote call performed!" << endl; } double getBrightness() { @@ -67,14 +76,17 @@ class LightBulbTest_Stub : public LightBulbTest return retVal; } - void turnOff() { + void turnOff() { + log << "Calling turnOff() in stub!" << endl; int methodId = 1; string retType = "void"; int numParam = 0; string paramCls[] = { }; void* paramObj[] = { }; void* retObj = NULL; + log << "About to remote call!" << endl; rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj); + log << "Remote call performed!" << endl; } bool getState() { diff --git a/benchmarks/Cpp/Lifxtest/Makefile b/benchmarks/Cpp/Lifxtest/Makefile index 648fcca..b79627b 100755 --- a/benchmarks/Cpp/Lifxtest/Makefile +++ b/benchmarks/Cpp/Lifxtest/Makefile @@ -2,18 +2,23 @@ BASE = ../../.. include $(BASE)/common.mk -all: lifxtest +all: so-lifxtest-arm so-lightstub-arm so-roomstub-arm zip ARGS = -shared -fpic PHONY += lifxtest lifxtest: - $(G++) ./Lifxtest.cpp $(BASE)/iotjava/iotruntime/cpp/socket/Socket.cpp -o $(BIN_DIR)/Lifxtest/Lifxtest.o --std=c++11 -pthread -pg -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/ -I$(BASE)/benchmarks/drivers/Cpp/LifxLightBulb/ + $(G++) ./Lifxtest.cpp $(BASE)/iotjava/iotruntime/cpp/socket/Socket.cpp -o $(BIN_DIR)/Lifxtest/Lifxtest.o --std=c++11 -pthread -pg -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/ -I$(BASE)/benchmarks/drivers/Cpp/LifxLightBulb/ -I$(BASE)/benchmarks/drivers/Cpp/LabRoom/ cp ./Lifxtest.config $(BIN_DIR)/Lifxtest PHONY += so-lifxtest so-lifxtest: - $(G++) $(ARGS) ./Lifxtest.cpp $(BASE)/iotjava/iotruntime/cpp/socket/Socket.cpp -o $(BIN_DIR)/Lifxtest/Lifxtest.so --std=c++11 -pthread -pg -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/ -I$(BASE)/benchmarks/drivers/Cpp/LifxLightBulb/ + $(G++) $(ARGS) ./Lifxtest.cpp $(BASE)/iotjava/iotruntime/cpp/socket/Socket.cpp -o $(BIN_DIR)/Lifxtest/Lifxtest.so --std=c++11 -pthread -pg -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/ -I$(BASE)/benchmarks/drivers/Cpp/LifxLightBulb/ -I$(BASE)/benchmarks/drivers/Cpp/LabRoom/ + cp ./Lifxtest.config $(BIN_DIR)/Lifxtest + +PHONY += so-lifxtest-arm +so-lifxtest-arm: + $(ARM_G++) $(ARGS) ./Lifxtest.cpp $(BASE)/iotjava/iotruntime/cpp/socket/Socket.cpp -o $(BIN_DIR)/Lifxtest/Lifxtest.so --std=c++11 -pthread -pg -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/ -I$(BASE)/benchmarks/drivers/Cpp/LifxLightBulb/ -I$(BASE)/benchmarks/drivers/Cpp/LabRoom/ cp ./Lifxtest.config $(BIN_DIR)/Lifxtest PHONY += lightstub @@ -26,4 +31,18 @@ so-lightstub: $(G++) $(ARGS) ./LightBulbTest_Stub.cpp $(BASE)/iotjava/iotruntime/cpp/socket/Socket.cpp -o $(BIN_DIR)/Lifxtest/LightBulbTest_Stub.so --std=c++11 -pthread -pg -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/ cp ./Lifxtest.config $(BIN_DIR)/Lifxtest +PHONY += so-lightstub-arm +so-lightstub-arm: + $(ARM_G++) $(ARGS) ./LightBulbTest_Stub.cpp $(BASE)/iotjava/iotruntime/cpp/socket/Socket.cpp -o $(BIN_DIR)/Lifxtest/LightBulbTest_Stub.so --std=c++11 -pthread -pg -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/ + cp ./Lifxtest.config $(BIN_DIR)/Lifxtest + +PHONY += so-roomstub-arm +so-roomstub-arm: + $(ARM_G++) $(ARGS) ./RoomSmart_Stub.cpp $(BASE)/iotjava/iotruntime/cpp/socket/Socket.cpp -o $(BIN_DIR)/Lifxtest/RoomSmart_Stub.so --std=c++11 -pthread -pg -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/ + cp ./Lifxtest.config $(BIN_DIR)/Lifxtest + +PHONY += zip +zip: + cd $(BIN_DIR)/Lifxtest; zip -r Lifxtest.zip *.so + .PHONY: $(PHONY) diff --git a/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp b/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp index 7650e52..1ca3e53 100644 --- a/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp +++ b/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp @@ -15,3 +15,10 @@ extern "C" void destroyRoomSmart_Stub(void* t) { } +extern "C" void initRoomSmart_Stub(void* t) { + // TODO: We actually need init() in LabRoom class + // But, this is declared here just for the sake of consistency for Sentinel + // In this case, we need the symbol "init" when loading object handlers with .so files + //RoomSmart_Stub* rss = (RoomSmart_Stub*) t; + //rss->init(); +} diff --git a/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.hpp b/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.hpp index b576cfc..8c0f3cf 100644 --- a/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.hpp +++ b/benchmarks/Cpp/Lifxtest/RoomSmart_Stub.hpp @@ -25,7 +25,13 @@ class RoomSmart_Stub : public RoomSmart callbackAddress = _callbackAddress; ports = _ports; // Logging - log.open("RoomSmart_Stub_cpp.log"); + int i=0; + string file = "RoomSmart_Stub_cpp" + to_string(i) + ".log"; + while (ifstream(file.c_str())) { + i++; + file = "RoomSmart_Stub_cpp" + to_string(i) + ".log"; + } + log.open(file); log << "Port: " << _port << endl; log << "Skeleton address: " << _skeletonAddress << endl; log << "Callback address: " << callbackAddress << endl; diff --git a/benchmarks/drivers/Cpp/LabRoom/LabRoom.cpp b/benchmarks/drivers/Cpp/LabRoom/LabRoom.cpp index 6b79706..3107a50 100644 --- a/benchmarks/drivers/Cpp/LabRoom/LabRoom.cpp +++ b/benchmarks/drivers/Cpp/LabRoom/LabRoom.cpp @@ -16,6 +16,15 @@ extern "C" void destroyLabRoom(void* t) { } +extern "C" void initLabRoom(void* t) { + // TODO: We actually need init() in LabRoom class + // But, this is declared here just for the sake of consistency for Sentinel + // In this case, we need the symbol "init" when loading object handlers with .so files + //LabRoom* lr = (LabRoom*) t; + //lr->init(); +} + + // Constructor LabRoom::LabRoom() { diff --git a/benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.cpp b/benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.cpp index f46eae2..8782fde 100644 --- a/benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.cpp +++ b/benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.cpp @@ -15,4 +15,11 @@ extern "C" void destroyRoom_Skeleton(void* t) { } +extern "C" void initRoom_Skeleton(void* t) { + // TODO: We actually need init() in LabRoom class + // But, this is declared here just for the sake of consistency for Sentinel + // In this case, we need the symbol "init" when loading object handlers with .so files + //Room_Skeleton* rs = (Room_Skeleton*) t; + //rs->init(); +} diff --git a/benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.hpp b/benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.hpp index 1cb96d8..fd88f24 100644 --- a/benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.hpp +++ b/benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.hpp @@ -31,7 +31,13 @@ class Room_Skeleton : public Room mainObj = _mainObj; callbackAddress = _callbackAddress; // Logging - log.open("LightBulb_Skeleton_cpp.log"); + 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); diff --git a/benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.cpp b/benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.cpp index 07076db..fbb295b 100644 --- a/benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.cpp +++ b/benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.cpp @@ -76,7 +76,13 @@ LifxLightBulb::LifxLightBulb(IoTSet* _devAddress, string macAddress) { //cout << "MAC address is set. Value: "; IoTRMIUtil::printBytes(bulbMacAddress, 8, false); // Logging - log.open("LifxLightBulb_cpp.log"); + int i=0; + string file = "LifxLightBulb_cpp" + to_string(i) + ".log"; + while (ifstream(file.c_str())) { + i++; + file = "LifxLightBulb_cpp" + to_string(i) + ".log"; + } + log.open(file); log << "MAC address is " << macAddress << endl; // Initialize device address @@ -113,6 +119,7 @@ void LifxLightBulb::init() { if (didAlreadyInit.exchange(true)) return; + log << "lb_addresses has: " << lb_addresses->size() << endl; unordered_set::const_iterator itr = lb_addresses->begin(); IoTDeviceAddress* deviceAddress = (IoTDeviceAddress*) *itr; //cout << "Address: " << deviceAddress->getAddress() << endl; @@ -132,8 +139,8 @@ void LifxLightBulb::init() { // NOTE: "this" pointer is passed into the detached thread because it does not belong // to this object anymore so if it executes certain methods of "this" object, then it needs // the correct references to stuff - thread th1 (&LifxLightBulb::workerFunction, this, this); - th1.detach(); +// thread th1 (&LifxLightBulb::workerFunction, this, this); +// th1.detach(); //cout << "Initialized LifxLightBulb!" << endl; log << "Initialized LifxLightBulb!" << endl; @@ -1212,26 +1219,26 @@ void adjustBright(LifxLightBulb *llb) { /*int main(int argc, char *argv[]) { - string macAddress = "D073D5128E300000"; + string macAddress1 = "D073D5128E300000"; //string macAddress = "D073D50241DA0000"; - string devIPAddress = "192.168.2.126"; + string devIPAddress1 = "192.168.2.126"; //string devIPAddress = "192.168.2.232"; - //IoTDeviceAddress devAddress(devIPAddress, 12345, 56700, false, false); - IoTDeviceAddress* devAddress = new IoTDeviceAddress(devIPAddress, 12345, 56700, false, false); - unordered_set myset = { devAddress }; + IoTDeviceAddress* devAddress1 = new IoTDeviceAddress(devIPAddress1, 12345, 56700, false, false); + unordered_set* myset1 = new unordered_set(); + myset1->insert(devAddress1); - IoTSet setDevAddress(myset); - LifxLightBulb *llb = new LifxLightBulb(setDevAddress, macAddress); + IoTSet* setDevAddress1 = new IoTSet(myset1); + LifxLightBulb *llb1 = new LifxLightBulb(setDevAddress1, macAddress1); cout << "Generated LifxLightBulb object!" << endl; - llb->init(); - llb->turnOn(); - onOff(llb); - adjustTemp(llb); - adjustBright(llb); + llb1->init(); + llb1->turnOn(); + onOff(llb1); + adjustTemp(llb1); + adjustBright(llb1); // llb->turnOff(); - delete devAddress; - delete llb; +// delete devAddress1; +// delete llb1; return 0; }*/ diff --git a/benchmarks/drivers/Cpp/LifxLightBulb/LightBulb_Skeleton.cpp b/benchmarks/drivers/Cpp/LifxLightBulb/LightBulb_Skeleton.cpp index f12e77e..7a7d9f1 100644 --- a/benchmarks/drivers/Cpp/LifxLightBulb/LightBulb_Skeleton.cpp +++ b/benchmarks/drivers/Cpp/LifxLightBulb/LightBulb_Skeleton.cpp @@ -25,7 +25,7 @@ extern "C" void initLightBulb_Skeleton(void* t) { } -int main(int argc, char *argv[]) +/*int main(int argc, char *argv[]) { // LightBulb #1 string macAddress1 = "D073D5128E300000"; @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) string callbackAddress = "localhost"; int stubPort = 55179; LightBulb_Skeleton *lbs = new LightBulb_Skeleton(llb1, callbackAddress, stubPort); - cout << "Successfully instantiated object and its skeleton!" << endl; + //cout << "Successfully instantiated object and its skeleton!" << endl; return 0; -} +}*/ diff --git a/benchmarks/drivers/Cpp/LifxLightBulb/LightBulb_Skeleton.hpp b/benchmarks/drivers/Cpp/LifxLightBulb/LightBulb_Skeleton.hpp index 936ea21..be35d65 100644 --- a/benchmarks/drivers/Cpp/LifxLightBulb/LightBulb_Skeleton.hpp +++ b/benchmarks/drivers/Cpp/LifxLightBulb/LightBulb_Skeleton.hpp @@ -31,7 +31,13 @@ class LightBulb_Skeleton : public LightBulb mainObj = _mainObj; callbackAddress = _callbackAddress; // Logging - log.open("LightBulb_Skeleton_cpp.log"); + int i=0; + string file = "LightBulb_Skeleton_cpp" + to_string(i) + ".log"; + while (ifstream(file.c_str())) { + i++; + file = "LightBulb_Skeleton_cpp" + to_string(i) + ".log"; + } + log.open(file); log << "Callback address: " << callbackAddress << endl; log << "Port: " << _port << endl; rmiObj = new IoTRMIObject(_port, &_bResult); diff --git a/benchmarks/drivers/Cpp/Makefile b/benchmarks/drivers/Cpp/Makefile index 24d9caf..242ab67 100644 --- a/benchmarks/drivers/Cpp/Makefile +++ b/benchmarks/drivers/Cpp/Makefile @@ -2,22 +2,33 @@ BASE = ../../.. include $(BASE)/common.mk -all: light +all: so-light-arm so-lightskel-arm lightzip so-labroom-arm so-labroomskel-arm labroomzip ARGS = -shared -fpic # Compile # +# LightBulb PHONY += light light: cd LifxLightBulb/; $(G++) ./LifxLightBulb.cpp $(BASE)/../iotjava/iotruntime/cpp/socket/Socket.cpp -o ../$(BIN_DIR)/iotcode/LifxLightBulb/LifxLightBulb.o --std=c++11 -pthread -pg -I$(BASE)/../iotjava/iotruntime/cpp/ -I$(BASE)/../iotjava/iotruntime/cpp/socket/ -I$(BASE)/../iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/../iotjava/iotrmi/C++/ -I$(BASE)/../benchmarks/virtuals/ cp LifxLightBulb/LifxLightBulb.config $(BIN_DIR)/iotcode/LifxLightBulb +PHONY += light-arm +light-arm: + cd LifxLightBulb/; $(ARM_G++) ./LifxLightBulb.cpp $(BASE)/../iotjava/iotruntime/cpp/socket/Socket.cpp -o ../$(BIN_DIR)/iotcode/LifxLightBulb/LifxLightBulb.o --std=c++11 -pthread -pg -I$(BASE)/../iotjava/iotruntime/cpp/ -I$(BASE)/../iotjava/iotruntime/cpp/socket/ -I$(BASE)/../iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/../iotjava/iotrmi/C++/ -I$(BASE)/../benchmarks/virtuals/ + cp LifxLightBulb/LifxLightBulb.config $(BIN_DIR)/iotcode/LifxLightBulb + PHONY += so-light so-light: cd LifxLightBulb/; $(G++) $(ARGS) ./LifxLightBulb.cpp $(BASE)/../iotjava/iotruntime/cpp/socket/Socket.cpp -o ../$(BIN_DIR)/iotcode/LifxLightBulb/LifxLightBulb.so --std=c++11 -pthread -pg -I$(BASE)/../iotjava/iotruntime/cpp/ -I$(BASE)/../iotjava/iotruntime/cpp/socket/ -I$(BASE)/../iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/../iotjava/iotrmi/C++/ -I$(BASE)/../benchmarks/virtuals/ cp LifxLightBulb/LifxLightBulb.config $(BIN_DIR)/iotcode/LifxLightBulb +PHONY += so-light-arm +so-light-arm: + cd LifxLightBulb/; $(ARM_G++) $(ARGS) ./LifxLightBulb.cpp $(BASE)/../iotjava/iotruntime/cpp/socket/Socket.cpp -o ../$(BIN_DIR)/iotcode/LifxLightBulb/LifxLightBulb.so --std=c++11 -pthread -pg -I$(BASE)/../iotjava/iotruntime/cpp/ -I$(BASE)/../iotjava/iotruntime/cpp/socket/ -I$(BASE)/../iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/../iotjava/iotrmi/C++/ -I$(BASE)/../benchmarks/virtuals/ + cp LifxLightBulb/LifxLightBulb.config $(BIN_DIR)/iotcode/LifxLightBulb + PHONY += lightskel lightskel: cd LifxLightBulb/; $(G++) ./LightBulb_Skeleton.cpp $(BASE)/../iotjava/iotruntime/cpp/socket/Socket.cpp -o ../$(BIN_DIR)/iotcode/LifxLightBulb/LightBulb_Skeleton.o --std=c++11 -pthread -pg -I$(BASE)/../iotjava/iotruntime/cpp/ -I$(BASE)/../iotjava/iotruntime/cpp/socket/ -I$(BASE)/../iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/../iotjava/iotrmi/C++/ -I$(BASE)/../benchmarks/virtuals/ @@ -28,4 +39,28 @@ so-lightskel: cd LifxLightBulb/; $(G++) $(ARGS) ./LightBulb_Skeleton.cpp $(BASE)/../iotjava/iotruntime/cpp/socket/Socket.cpp -o ../$(BIN_DIR)/iotcode/LifxLightBulb/LightBulb_Skeleton.so --std=c++11 -pthread -pg -I$(BASE)/../iotjava/iotruntime/cpp/ -I$(BASE)/../iotjava/iotruntime/cpp/socket/ -I$(BASE)/../iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/../iotjava/iotrmi/C++/ -I$(BASE)/../benchmarks/virtuals/ cp LifxLightBulb/LifxLightBulb.config $(BIN_DIR)/iotcode/LifxLightBulb +PHONY += so-lightskel-arm +so-lightskel-arm: + cd LifxLightBulb/; $(ARM_G++) $(ARGS) ./LightBulb_Skeleton.cpp $(BASE)/../iotjava/iotruntime/cpp/socket/Socket.cpp -o ../$(BIN_DIR)/iotcode/LifxLightBulb/LightBulb_Skeleton.so --std=c++11 -pthread -pg -I$(BASE)/../iotjava/iotruntime/cpp/ -I$(BASE)/../iotjava/iotruntime/cpp/socket/ -I$(BASE)/../iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/../iotjava/iotrmi/C++/ -I$(BASE)/../benchmarks/virtuals/ + cp LifxLightBulb/LifxLightBulb.config $(BIN_DIR)/iotcode/LifxLightBulb + +PHONY += lightzip +lightzip: + cd $(BIN_DIR)/iotcode/LifxLightBulb/; zip -r LifxLightBulb.zip *.so + +# LabRoom +PHONY += so-labroom-arm +so-labroom-arm: + cd LabRoom/; $(ARM_G++) $(ARGS) ./LabRoom.cpp $(BASE)/../iotjava/iotruntime/cpp/socket/Socket.cpp -o ../$(BIN_DIR)/iotcode/LabRoom/LabRoom.so --std=c++11 -pthread -pg -I$(BASE)/../iotjava/iotruntime/cpp/ -I$(BASE)/../iotjava/iotruntime/cpp/socket/ -I$(BASE)/../iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/../iotjava/iotrmi/C++/ -I$(BASE)/../benchmarks/virtuals/ + cp LabRoom/LabRoom.config $(BIN_DIR)/iotcode/LabRoom + +PHONY += so-labroomskel-arm +so-labroomskel-arm: + cd LabRoom/; $(ARM_G++) $(ARGS) ./Room_Skeleton.cpp $(BASE)/../iotjava/iotruntime/cpp/socket/Socket.cpp -o ../$(BIN_DIR)/iotcode/LabRoom/Room_Skeleton.so --std=c++11 -pthread -pg -I$(BASE)/../iotjava/iotruntime/cpp/ -I$(BASE)/../iotjava/iotruntime/cpp/socket/ -I$(BASE)/../iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/../iotjava/iotrmi/C++/ -I$(BASE)/../benchmarks/virtuals/ + cp LabRoom/LabRoom.config $(BIN_DIR)/iotcode/LabRoom + +PHONY += labroomzip +labroomzip: + cd $(BIN_DIR)/iotcode/LabRoom/; zip -r LabRoom.zip *.so + .PHONY: $(PHONY) diff --git a/iotjava/Makefile b/iotjava/Makefile index 2e1b8f9..01795d0 100644 --- a/iotjava/Makefile +++ b/iotjava/Makefile @@ -117,7 +117,6 @@ compile: cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) TestClassCallbacks_Stub.java cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) TestClassInterface*.java cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) CallBackInterface*.java - cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) StubSkeletonMap.java # cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) TestClassComplete*.java # cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) CallBackInterface_CallbackSkeleton.java # cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) CallBackInterfaceWithCallBack_CallbackStub.java diff --git a/iotjava/iotruntime/cpp/iotslave/IoTSlave.cpp b/iotjava/iotruntime/cpp/iotslave/IoTSlave.cpp index 82e53bd..38dcf72 100644 --- a/iotjava/iotruntime/cpp/iotslave/IoTSlave.cpp +++ b/iotjava/iotruntime/cpp/iotslave/IoTSlave.cpp @@ -7,7 +7,7 @@ IoTSlave::IoTSlave(string _serverAddress, int _serverPort, string _objectName) { - isDriverObject = false; // Default to false + //isDriverObject = false; // Default to false serverAddress = _serverAddress; serverPort = _serverPort; objectName = _objectName; @@ -269,7 +269,7 @@ void IoTSlave::instantiateStubObject() { params[3] = &rev; bool result = false; params[4] = &result; - params[5] = &ports; + params[5] = ports; writeToFile("Stub Object " + objectStubClass + " created for " + objectClassName); objStubCls = create_object(params); } @@ -311,6 +311,7 @@ int IoTSlave::recvInteger() { char recvInt[sizeof(int)]; // Normally 4 bytes // Receive and iterate until complete + //writeToFile("Receiving Integer! Size: " + to_string(toBeReceived)); recvIter(recvInt, toBeReceived); int retVal = 0; @@ -343,6 +344,7 @@ string IoTSlave::recvString() { char* recvStr = new char[strLen]; // Receive and iterate until complete + //writeToFile("Receiving String! Size: " + to_string(strLen)); recvIter(recvStr, strLen); string retVal(recvStr, strLen); @@ -417,6 +419,7 @@ void IoTSlave::createObject() { objectStubPort = recvInteger(); sendAck(); writeToFile("=> Driver object stub port: " + to_string(objectStubPort)); int numOfArgs = recvInteger(); sendAck(); + writeToFile("=> Number of args: " + to_string(numOfArgs)); for (int i = 0; i < numOfArgs; i++) { string arg = recvString(); sendAck(); args.push_back(arg); @@ -465,7 +468,7 @@ void IoTSlave::getDeviceIoTSetObject() { writeToFile("=> Inserting IoTDeviceAddress into set..."); writeToFile("==> Now we have " + to_string(isetObject->size()) + " object(s)!"); // Set flag to true; - isDriverObject = true; + //isDriverObject = true; } @@ -481,6 +484,8 @@ void IoTSlave::createStub() { instantiateStubObject(); mapObjNameStub.insert(make_pair(objectName,objStubCls)); writeToFile("=> Map has: " + to_string(mapObjNameStub.size()) + " members"); + // vector for ports has been copied - now delete it + delete ports; } } @@ -509,14 +514,26 @@ void IoTSlave::reinitializeIoTSetField() { // Create object if this is for driver object // Right now we assume that this needs only one object per device - if (isDriverObject) { + /*if (isDriverObject) { // Instantiate driver object getObjectHandler(objectClassName); instantiateDriverObject(); // Instantiate skeleton object getObjectHandler(objectSkelClass); instantiateSkelObject(); - } + }*/ +} + + +// Instantiate driver object +void IoTSlave::createDriverObject() { + + // Instantiate driver object + getObjectHandler(objectClassName); + instantiateDriverObject(); + // Instantiate skeleton object + getObjectHandler(objectSkelClass); + instantiateSkelObject(); } @@ -526,7 +543,7 @@ void IoTSlave::createNewIoTRelation() { objectFieldName = recvString(); sendAck(); // Instantiating new IoTSet object irelObject = new unordered_multimap(); - writeToFile("Creating new IoTSet for field: " + objectFieldName); + writeToFile("Creating new IoTRelation for field: " + objectFieldName); } @@ -548,9 +565,10 @@ void IoTSlave::getIoTSetRelationObject() { objectStubPort = recvInteger(); sendAck(); writeToFile("=> Driver object stub port: " + to_string(objectStubPort)); int numOfPorts = recvInteger(); sendAck(); + ports = new vector(); for (int i = 0; i < numOfPorts; i++) { int port = recvInteger(); sendAck(); - ports.push_back(port); + ports->push_back(port); writeToFile("==> Got a new port: " + to_string(port)); } } @@ -578,6 +596,7 @@ void IoTSlave::getIoTRelationSecondObject() { irelSecondObject = objStubCls; writeToFile("=> Holding second stub object..."); pair* iotrelPair = new pair(irelFirstObject, irelSecondObject); + writeToFile("=> Creating a pair of stub objects and inserting into IoTRelation object..."); irelObject->insert(*iotrelPair); } @@ -697,6 +716,10 @@ void IoTSlave::commIoTMaster() { invokeInitMethod(); break; + case CREATE_DRIVER_OBJECT: + createDriverObject(); + break; + case END_SESSION: // END of session goto ENDLOOP; diff --git a/iotjava/iotruntime/cpp/iotslave/IoTSlave.hpp b/iotjava/iotruntime/cpp/iotslave/IoTSlave.hpp index e5ecdfc..6c96604 100644 --- a/iotjava/iotruntime/cpp/iotslave/IoTSlave.hpp +++ b/iotjava/iotruntime/cpp/iotslave/IoTSlave.hpp @@ -26,6 +26,7 @@ enum IoTCommCode { ACKNOWLEDGED, + CREATE_DRIVER_OBJECT, CREATE_OBJECT, CREATE_MAIN_OBJECT, CREATE_NEW_IOTSET, @@ -42,7 +43,7 @@ enum IoTCommCode { REINITIALIZE_IOTSET_FIELD, REINITIALIZE_IOTRELATION_FIELD, TRANSFER_FILE, - + }; @@ -83,7 +84,7 @@ class IoTSlave { string objectStubClass; // Need to send from Java IoTSlave: sMessage.getObjectStubInterfaceName() + STUB_CLASS_SUFFIX int objectRegPort; int objectStubPort; - vector ports; // Now used to contain callback ports + vector* ports; // Now used to contain callback ports string objectFieldName; // Field name that is going to be initialized with IoTSet or IoTRelation unordered_set* isetObject; // Set of object IoTSet* iotsetObject; // IoTSet of object @@ -98,7 +99,7 @@ class IoTSlave { ofstream log; // Log the messages vector args; // Hold the arguments for constructor (in string format) vector argClasses; // Hold the argument classes - bool isDriverObject; // Set to true if this is IoTSlave instance for a driver object + //bool isDriverObject; // Set to true if this is IoTSlave instance for a driver object void* objMainCls; // Main class handler, i.e. driver or controller object void* objSkelCls; // Skeleton handler void* objStubCls; // Stub handler @@ -137,6 +138,7 @@ class IoTSlave { void reinitializeIoTRelationField(); void getIoTSetObject(); void invokeInitMethod(); + void createDriverObject(); void transferFile(); private: diff --git a/iotjava/iotruntime/master/IoTMaster.java b/iotjava/iotruntime/master/IoTMaster.java index 154f36a..7578f3b 100644 --- a/iotjava/iotruntime/master/IoTMaster.java +++ b/iotjava/iotruntime/master/IoTMaster.java @@ -885,7 +885,7 @@ public class IoTMaster { RuntimeOutput.print("IoTMaster: Executing: " + strCmdSend, BOOL_VERBOSE); // Unzip file String strCmdUnzip = STR_SSH + " " + STR_USERNAME + strIoTSlaveObjectHostAdd + " cd " + - STR_SLAVE_DIR + " sudo unzip " + sFileName + ";"; + STR_SLAVE_DIR + " sudo unzip -o " + sFileName + ";"; runCommand(strCmdUnzip); RuntimeOutput.print("IoTMaster: Executing: " + strCmdUnzip, BOOL_VERBOSE); @@ -1051,9 +1051,10 @@ public class IoTMaster { if(STR_LANGUAGE.equals(STR_JAVA)) { ObjectOutputStream oStream = (ObjectOutputStream) outStream; oStream.writeObject(new MessageSimple(IoTCommCode.END_SESSION)); - } else // C++ side for now will be running continuously because it's an infinite loop (not in a separate thread) + } else { // C++ side for now will be running continuously because it's an infinite loop (not in a separate thread) + createDriverObjectCpp(outStream, inStream); //endSessionCpp(outStream); - ; + } // PROFILING result = System.currentTimeMillis()-start; @@ -1276,10 +1277,9 @@ public class IoTMaster { List listObject = objInitHand.getListObjectInitInfo(str); for (ObjectInitInfo objInitInfo : listObject) { // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO FILL IN IOTSET - getIoTSetRelationObjectCpp(objInitInfo.getIoTSlaveObjectHostAdd(), objInitInfo.getObjectName(), - objInitInfo.getObjectClassName(), objInitInfo.getObjectClassInterfaceName(), - objInitInfo.getObjectStubClassInterfaceName(), objInitInfo.getRMIRegistryPort(), objInitInfo.getRMIStubPort(), - objInitInfo.getRMICallbackPorts(), outStream, inStream); + getIoTSetRelationObjectCpp(IoTCommCode.GET_IOTSET_OBJECT, objInitInfo.getIoTSlaveObjectHostAdd(), objInitInfo.getObjectName(), + objInitInfo.getObjectClassName(), objInitInfo.getObjectClassInterfaceName(), objInitInfo.getObjectStubClassInterfaceName(), + objInitInfo.getRMIRegistryPort(), objInitInfo.getRMIStubPort(), objInitInfo.getRMICallbackPorts(), outStream, inStream); } // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO REINITIALIZE IOTSET FIELD reinitializeIoTSetFieldCpp(outStream, inStream); @@ -1292,16 +1292,14 @@ public class IoTMaster { Iterator it = listSecondObject.iterator(); for (ObjectInitInfo objInitInfo : listObject) { // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO FILL IN IOTRELATION (FIRST OBJECT) - getIoTSetRelationObjectCpp(objInitInfo.getIoTSlaveObjectHostAdd(), objInitInfo.getObjectName(), - objInitInfo.getObjectClassName(), objInitInfo.getObjectClassInterfaceName(), - objInitInfo.getObjectStubClassInterfaceName(), objInitInfo.getRMIRegistryPort(), objInitInfo.getRMIStubPort(), - objInitInfo.getRMICallbackPorts(), outStream, inStream); + getIoTSetRelationObjectCpp(IoTCommCode.GET_IOTRELATION_FIRST_OBJECT, objInitInfo.getIoTSlaveObjectHostAdd(), objInitInfo.getObjectName(), + objInitInfo.getObjectClassName(), objInitInfo.getObjectClassInterfaceName(), objInitInfo.getObjectStubClassInterfaceName(), + objInitInfo.getRMIRegistryPort(), objInitInfo.getRMIStubPort(), objInitInfo.getRMICallbackPorts(), outStream, inStream); ObjectInitInfo objSecObj = (ObjectInitInfo) it.next(); // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO FILL IN IOTRELATION (SECOND OBJECT) - getIoTSetRelationObjectCpp(objSecObj.getIoTSlaveObjectHostAdd(), objSecObj.getObjectName(), - objSecObj.getObjectClassName(), objSecObj.getObjectClassInterfaceName(), - objSecObj.getObjectStubClassInterfaceName(), objSecObj.getRMIRegistryPort(), objSecObj.getRMIStubPort(), - objSecObj.getRMICallbackPorts(), outStream, inStream); + getIoTSetRelationObjectCpp(IoTCommCode.GET_IOTRELATION_SECOND_OBJECT, objSecObj.getIoTSlaveObjectHostAdd(), objSecObj.getObjectName(), + objSecObj.getObjectClassName(), objSecObj.getObjectClassInterfaceName(), objSecObj.getObjectStubClassInterfaceName(), + objSecObj.getRMIRegistryPort(), objSecObj.getRMIStubPort(), objSecObj.getRMICallbackPorts(), outStream, inStream); } // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO REINITIALIZE IOTRELATION FIELD reinitializeIoTRelationFieldCpp(outStream, inStream); @@ -1456,21 +1454,21 @@ public class IoTMaster { sendString(sFileName, outStream); recvAck(inStream); File file = new File(sFilePath + sFileName); int iFileLen = toIntExact(file.length()); - RuntimeOutput.print("IoTSlave: Sending file " + sFileName + " with length " + iFileLen + " bytes...", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Sending file " + sFileName + " with length " + iFileLen + " bytes...", BOOL_VERBOSE); // Send file length sendInteger(iFileLen, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Sent file size!", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Sent file size!", BOOL_VERBOSE); byte[] bytFile = new byte[iFileLen]; InputStream inFileStream = new FileInputStream(file); - RuntimeOutput.print("IoTSlave: Opened file!", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Opened file!", BOOL_VERBOSE); OutputStream outFileStream = fileSocket.getOutputStream(); - RuntimeOutput.print("IoTSlave: Got output stream!", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Got output stream!", BOOL_VERBOSE); int iCount; while ((iCount = inFileStream.read(bytFile)) > 0) { outFileStream.write(bytFile, 0, iCount); } - RuntimeOutput.print("IoTSlave: File sent!", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: File sent!", BOOL_VERBOSE); recvAck(inStream); } @@ -1490,7 +1488,7 @@ public class IoTMaster { RuntimeOutput.print("IoTMaster: Executing: " + strCmdSend, BOOL_VERBOSE); // Unzip file String strCmdUnzip = STR_SSH + " " + STR_USERNAME + strIoTSlaveControllerHostAdd + " cd " + - STR_SLAVE_DIR + " sudo unzip " + sFileName + ";"; + STR_SLAVE_DIR + " sudo unzip -o " + sFileName + ";"; runCommand(strCmdUnzip); RuntimeOutput.print("IoTMaster: Executing: " + strCmdUnzip, BOOL_VERBOSE); } @@ -1674,7 +1672,7 @@ public class IoTMaster { sendCommCode(IoTCommCode.CREATE_MAIN_OBJECT, outStream, inStream); String strMainObjName = strObjControllerName; sendString(strMainObjName, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Create a main object: " + strMainObjName, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Create a main object: " + strMainObjName, BOOL_VERBOSE); } @@ -1723,27 +1721,27 @@ public class IoTMaster { OutputStream outStream, InputStream inStream) throws IOException { sendCommCode(IoTCommCode.CREATE_OBJECT, outStream, inStream); - RuntimeOutput.print("IoTSlave: Send request to create a driver object... ", BOOL_VERBOSE); - RuntimeOutput.print("IoTSlave: Driver object name: " + strObjName, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Send request to create a driver object... ", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Driver object name: " + strObjName, BOOL_VERBOSE); sendString(strObjName, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Driver object class name: " + strObjClassName, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Driver object class name: " + strObjClassName, BOOL_VERBOSE); sendString(strObjClassName, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Driver object interface name: " + strObjClassInterfaceName, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Driver object interface name: " + strObjClassInterfaceName, BOOL_VERBOSE); sendString(strObjStubClsIntfaceName, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Driver object skeleton class name: " + strObjClassInterfaceName + STR_SKEL_CLASS_SUFFIX, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Driver object skeleton class name: " + strObjClassInterfaceName + STR_SKEL_CLASS_SUFFIX, BOOL_VERBOSE); sendString(strObjClassInterfaceName + STR_SKEL_CLASS_SUFFIX, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Driver object registry port: " + iRMIRegistryPort, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Driver object registry port: " + iRMIRegistryPort, BOOL_VERBOSE); sendInteger(iRMIRegistryPort, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Driver object stub port: " + iRMIStubPort, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Driver object stub port: " + iRMIStubPort, BOOL_VERBOSE); sendInteger(iRMIStubPort, outStream); recvAck(inStream); int numOfArgs = arrFieldValues.length; - RuntimeOutput.print("IoTSlave: Send constructor arguments! Number of arguments: " + numOfArgs, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Send constructor arguments! Number of arguments: " + numOfArgs, BOOL_VERBOSE); sendInteger(numOfArgs, outStream); recvAck(inStream); for(Object obj : arrFieldValues) { String str = getObjectConverted(obj); sendString(str, outStream); recvAck(inStream); } - RuntimeOutput.print("IoTSlave: Send constructor argument classes!", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Send constructor argument classes!", BOOL_VERBOSE); for(Class cls : arrFieldClasses) { String str = getClassConverted(cls); sendString(str, outStream); recvAck(inStream); @@ -1757,8 +1755,8 @@ public class IoTMaster { public void createNewIoTSetCpp(String strObjFieldName, OutputStream outStream, InputStream inStream) throws IOException { sendCommCode(IoTCommCode.CREATE_NEW_IOTSET, outStream, inStream); - RuntimeOutput.print("IoTSlave: Creating new IoTSet...", BOOL_VERBOSE); - RuntimeOutput.print("IoTSlave: Send object field name: " + strObjFieldName, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Creating new IoTSet...", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Send object field name: " + strObjFieldName, BOOL_VERBOSE); sendString(strObjFieldName, outStream); recvAck(inStream); } @@ -1769,8 +1767,8 @@ public class IoTMaster { public void createNewIoTRelationCpp(String strObjFieldName, OutputStream outStream, InputStream inStream) throws IOException { sendCommCode(IoTCommCode.CREATE_NEW_IOTRELATION, outStream, inStream); - RuntimeOutput.print("IoTSlave: Creating new IoTRelation...", BOOL_VERBOSE); - RuntimeOutput.print("IoTSlave: Send object field name: " + strObjFieldName, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Creating new IoTRelation...", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Send object field name: " + strObjFieldName, BOOL_VERBOSE); sendString(strObjFieldName, outStream); recvAck(inStream); } @@ -1782,7 +1780,7 @@ public class IoTMaster { String strDeviceAddress, int iSourcePort, int iDestPort, boolean bSourceWildCard, boolean bDestWildCard) throws IOException { sendCommCode(IoTCommCode.GET_DEVICE_IOTSET_OBJECT, outStream, inStream); - RuntimeOutput.print("IoTSlave: Getting IoTDeviceAddress...", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Getting IoTDeviceAddress...", BOOL_VERBOSE); sendString(strDeviceAddress, outStream); recvAck(inStream); sendInteger(iSourcePort, outStream); recvAck(inStream); sendInteger(iDestPort, outStream); recvAck(inStream); @@ -1790,33 +1788,33 @@ public class IoTMaster { sendInteger(iSourceWildCard, outStream); recvAck(inStream); int iDestWildCard = (bDestWildCard ? 1 : 0); sendInteger(iDestWildCard, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Send device address: " + strDeviceAddress, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Send device address: " + strDeviceAddress, BOOL_VERBOSE); } /** * Get a IoTSet content object for C++ */ - public void getIoTSetRelationObjectCpp(String strIoTSlaveHostAddress, String strObjectName, String strObjectClassName, + public void getIoTSetRelationObjectCpp(IoTCommCode iotCommCode, String strIoTSlaveHostAddress, String strObjectName, String strObjectClassName, String strObjectClassInterfaceName, String strObjectStubClassInterfaceName, int iRMIRegistryPort, int iRMIStubPort, Integer[] iCallbackPorts, OutputStream outStream, InputStream inStream) throws IOException { - sendCommCode(IoTCommCode.GET_IOTSET_OBJECT, outStream, inStream); - RuntimeOutput.print("IoTSlave: Getting IoTSet object content...", BOOL_VERBOSE); + sendCommCode(iotCommCode, outStream, inStream); + RuntimeOutput.print("IoTMaster: Getting IoTSet object content...", BOOL_VERBOSE); // Send info - RuntimeOutput.print("IoTSlave: Send host address: " + strIoTSlaveHostAddress, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Send host address: " + strIoTSlaveHostAddress, BOOL_VERBOSE); sendString(strIoTSlaveHostAddress, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Driver object name: " + strObjectName, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Driver object name: " + strObjectName, BOOL_VERBOSE); sendString(strObjectName, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Driver object class name: " + strObjectClassName, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Driver object class name: " + strObjectClassName, BOOL_VERBOSE); sendString(strObjectClassName, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Driver object interface name: " + strObjectClassInterfaceName, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Driver object interface name: " + strObjectClassInterfaceName, BOOL_VERBOSE); sendString(strObjectClassInterfaceName, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Driver object stub class name: " + strObjectStubClassInterfaceName + STR_STUB_CLASS_SUFFIX, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Driver object stub class name: " + strObjectStubClassInterfaceName + STR_STUB_CLASS_SUFFIX, BOOL_VERBOSE); sendString(strObjectStubClassInterfaceName + STR_STUB_CLASS_SUFFIX, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Driver object registry port: " + iRMIRegistryPort, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Driver object registry port: " + iRMIRegistryPort, BOOL_VERBOSE); sendInteger(iRMIRegistryPort, outStream); recvAck(inStream); - RuntimeOutput.print("IoTSlave: Driver object stub port: " + iRMIStubPort, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Driver object stub port: " + iRMIStubPort, BOOL_VERBOSE); sendInteger(iRMIStubPort, outStream); recvAck(inStream); sendInteger(iCallbackPorts.length, outStream); recvAck(inStream); for(Integer i : iCallbackPorts) { @@ -1830,9 +1828,9 @@ public class IoTMaster { */ private void reinitializeIoTRelationFieldCpp(OutputStream outStream, InputStream inStream) throws IOException { - RuntimeOutput.print("IoTSlave: About to Reinitialize IoTRelation field!", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: About to Reinitialize IoTRelation field!", BOOL_VERBOSE); sendCommCode(IoTCommCode.REINITIALIZE_IOTRELATION_FIELD, outStream, inStream); - RuntimeOutput.print("IoTSlave: Reinitialize IoTRelation field!", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Reinitialize IoTRelation field!", BOOL_VERBOSE); } @@ -1841,9 +1839,19 @@ public class IoTMaster { */ private void reinitializeIoTSetFieldCpp(OutputStream outStream, InputStream inStream) throws IOException { - RuntimeOutput.print("IoTSlave: About to Reinitialize IoTSet field!", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: About to Reinitialize IoTSet field!", BOOL_VERBOSE); sendCommCode(IoTCommCode.REINITIALIZE_IOTSET_FIELD, outStream, inStream); - RuntimeOutput.print("IoTSlave: Reinitialize IoTSet field!", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Reinitialize IoTSet field!", BOOL_VERBOSE); + } + + + /** + * Create driver object for C++ + */ + private void createDriverObjectCpp(OutputStream outStream, InputStream inStream) throws IOException { + + sendCommCode(IoTCommCode.CREATE_DRIVER_OBJECT, outStream, inStream); + RuntimeOutput.print("IoTMaster: Send command to create driver object!", BOOL_VERBOSE); } @@ -1853,7 +1861,7 @@ public class IoTMaster { private void invokeInitMethodCpp(OutputStream outStream, InputStream inStream) throws IOException { sendCommCode(IoTCommCode.INVOKE_INIT_METHOD, outStream, inStream); - RuntimeOutput.print("IoTSlave: Invoke init method!", BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Invoke init method!", BOOL_VERBOSE); } @@ -1866,8 +1874,8 @@ public class IoTMaster { IoTCommCode endSessionCode = IoTCommCode.END_SESSION; int intCode = endSessionCode.ordinal(); sendInteger(intCode, outStream); - //RuntimeOutput.print("IoTSlave: Send request to create a main object: " + strObjName, BOOL_VERBOSE); - RuntimeOutput.print("IoTSlave: Send request to end session!", BOOL_VERBOSE); + //RuntimeOutput.print("IoTMaster: Send request to create a main object: " + strObjName, BOOL_VERBOSE); + RuntimeOutput.print("IoTMaster: Send request to end session!", BOOL_VERBOSE); } diff --git a/iotjava/iotruntime/messages/IoTCommCode.java b/iotjava/iotruntime/messages/IoTCommCode.java index fe97dec..7b0886c 100644 --- a/iotjava/iotruntime/messages/IoTCommCode.java +++ b/iotjava/iotruntime/messages/IoTCommCode.java @@ -12,6 +12,7 @@ package iotruntime.messages; public enum IoTCommCode { ACKNOWLEDGED, + CREATE_DRIVER_OBJECT, CREATE_OBJECT, CREATE_MAIN_OBJECT, CREATE_NEW_IOTSET, -- 2.34.1