Working C++ IoTSlave for both IoTSet and IoTRelation; threading works for C++ LifxLig...
authorrtrimana <rtrimana@uci.edu>
Mon, 23 Jan 2017 22:45:55 +0000 (14:45 -0800)
committerrtrimana <rtrimana@uci.edu>
Mon, 23 Jan 2017 22:45:55 +0000 (14:45 -0800)
20 files changed:
benchmarks/Cpp/Lifxtest/Lifxtest.config
benchmarks/Cpp/Lifxtest/Lifxtest.cpp
benchmarks/Cpp/Lifxtest/Lifxtest.hpp
benchmarks/Cpp/Lifxtest/LightBulbTest_Stub.cpp
benchmarks/Cpp/Lifxtest/LightBulbTest_Stub.hpp
benchmarks/Cpp/Lifxtest/Makefile
benchmarks/Cpp/Lifxtest/RoomSmart_Stub.cpp
benchmarks/Cpp/Lifxtest/RoomSmart_Stub.hpp
benchmarks/drivers/Cpp/LabRoom/LabRoom.cpp
benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.cpp
benchmarks/drivers/Cpp/LabRoom/Room_Skeleton.hpp
benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.cpp
benchmarks/drivers/Cpp/LifxLightBulb/LightBulb_Skeleton.cpp
benchmarks/drivers/Cpp/LifxLightBulb/LightBulb_Skeleton.hpp
benchmarks/drivers/Cpp/Makefile
iotjava/Makefile
iotjava/iotruntime/cpp/iotslave/IoTSlave.cpp
iotjava/iotruntime/cpp/iotslave/IoTSlave.hpp
iotjava/iotruntime/master/IoTMaster.java
iotjava/iotruntime/messages/IoTCommCode.java

index 39b3a38c489df49b46a1cd5ab3284ed79be9f5c5..a5c5a5c306dcb42ae2add35cf79fddb4ccf0caea 100644 (file)
@@ -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
index 53cb4257337430c7f0bc6dd2a96b3fab3fb891c9..7e93b4c2cc4e07c7995aafa08552e07358fa6cc9 100644 (file)
@@ -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<void*>* lifx_light_bulb
-       return new Lifxtest((IoTSet<void*>*) params[0]);
+       //return new Lifxtest((IoTSet<void*>*) params[0]);
+       return new Lifxtest((IoTSet<void*>*) params[0], (IoTSet<void*>*) params[1], (IoTRelation<void*,void*>*) 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<void*>* _lifx_light_bulb) {
 
        log.open("Lifxtest_object_cpp.log");
@@ -37,6 +43,19 @@ Lifxtest::Lifxtest(IoTSet<void*>* _lifx_light_bulb) {
        log << "lifx_light_bulb initialized!" << endl;
 }
 
+
+// Constructor with 2 IoTSet and 1 IoTRelation objects
+Lifxtest::Lifxtest(IoTSet<void*>* _lifx_light_bulb, IoTSet<void*>* _lab_room, IoTRelation<void*,void*>* _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<void*>* bulbSet = lifx_light_bulb->values();
        //for (unordered_set<void*>::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<void*>* bulbSet = lifx_light_bulb->values();
+       unordered_set<void*>* roomSet = lab_room->values();
+       unordered_multimap<void*,void*>* roomLightRel = roomLightRelation->values();
+       log << "Size of map: " << roomLightRel->size() << endl;
+       //for (unordered_set<void*>::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<void*>* lbSet = new IoTSet<void*>(setLb);
 
+       // Set of rooms
+       LabRoom *lr1 = new LabRoom();
+       LabRoom *lr2 = new LabRoom();
+       unordered_set<void*>* setLR = new unordered_set<void*>();
+       setLR->insert(lr1);
+       setLR->insert(lr2);
+       IoTSet<void*>* lrSet = new IoTSet<void*>(setLR);
+
+       pair<void*,void*>* pair1 = new pair<void*,void*>(lr1, llb1);
+       pair<void*,void*>* pair2 = new pair<void*,void*>(lr2, llb2);
+       unordered_multimap<void*,void*>* mmap = new unordered_multimap<void*,void*>();
+       mmap->insert(*pair1);
+       mmap->insert(*pair2);
+       IoTRelation<void*,void*>* rlRel = new IoTRelation<void*,void*>(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;
-}
-*/
+}*/
+
 
index eb8c15b47a2df1557175d62a6d77d47998943a66..c07484840da7ff7581ac736ec7e26cfd3b193d2d 100644 (file)
@@ -4,15 +4,20 @@
 #include <fstream>
 
 #include "IoTSet.hpp"
+#include "IoTRelation.hpp"
 #include "LightBulb.hpp"
 #include "LightBulbTest.hpp"
+#include "Room.hpp"
+#include "RoomSmart.hpp"
 
 
 class Lifxtest {
 
        private:
                // IoTSet
-               IoTSet<void*>* lifx_light_bulb;
+               IoTSet<void*>* lifx_light_bulb; // LightBulbTest
+               IoTSet<void*>* lab_room;                // RoomSmart
+               IoTRelation<void*,void*>* roomLightRelation;    // RoomSmart and LightBulbTest
 
                ofstream log;
 
@@ -20,6 +25,7 @@ class Lifxtest {
 
                Lifxtest();
                Lifxtest(IoTSet<void*>* _lifx_light_bulb);
+               Lifxtest(IoTSet<void*>* _lifx_light_bulb, IoTSet<void*>* _lab_room, IoTRelation<void*,void*>* _roomLightRelation);
                Lifxtest(void** args);
                ~Lifxtest();
                void init();
index 18fb7806f916c9e07de010bbf5ecd098d038b6f0..02e450bf056c8f0da04f8bce2d44ecceb71fce98 100644 (file)
@@ -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));
        }
 
index 3e20d5bc533c8dfcdea49bd2b56489dc10d2c335..a855a7308b939b0307c4fa50495d55a19a626ecd 100644 (file)
@@ -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() { 
index 648fccac7d3663b97656f1080b4ed5c4f78a22bd..b79627bbf63791c2e440044742628586ebc6965f 100755 (executable)
@@ -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)
index 7650e52aaf8e6cd1c60c5a9b2e1cfd47e38992e2..1ca3e53932a0f76db58eba8dce34e7927dbbb6e4 100644 (file)
@@ -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();
+}
index b576cfcd0e8b9e31782109409c9622d34c8ab475..8c0f3cfd32595702d39e75d37a68a11676463f5f 100644 (file)
@@ -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;
index 6b79706c6ce8393dfeadc8b048f23ac97f5f5494..3107a501d5321a18bc4bed995cb42be01b7250ca 100644 (file)
@@ -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() {
 
index f46eae235f72a44753335c004e65f638b473321b..8782fde485d1c072443ff89487753d35b58b4701 100644 (file)
@@ -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();
+}
 
index 1cb96d8289b0b10eaf318a79df9fd6922eab0672..fd88f24bb5d1055249e9d9358099f1c9d92c7e2f 100644 (file)
@@ -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);
index 07076db9f9002d0711505b89e8ade62f17c12c21..fbb295befb571ea8b9aaa2be62742e997177fd56 100644 (file)
@@ -76,7 +76,13 @@ LifxLightBulb::LifxLightBulb(IoTSet<void*>* _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<void*>::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<IoTDeviceAddress*> myset = { devAddress };
+       IoTDeviceAddress* devAddress1 = new IoTDeviceAddress(devIPAddress1, 12345, 56700, false, false);
+       unordered_set<void*>* myset1 = new unordered_set<void*>();
+       myset1->insert(devAddress1);
 
-       IoTSet<IoTDeviceAddress*> setDevAddress(myset);
-       LifxLightBulb *llb = new LifxLightBulb(setDevAddress, macAddress);
+       IoTSet<void*>* setDevAddress1 = new IoTSet<void*>(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;
 }*/
index f12e77ebd757f25dbd720707df755d9d3f530aae..7a7d9f1c19e7ba27779a578743e5dc3eff6e7c64 100644 (file)
@@ -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;
-}
+}*/
index 936ea21f5c82c634f58c015b05452f89054641d4..be35d65a00d38db55bfe7c39cf970252a6bc59a9 100644 (file)
@@ -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);
index 24d9caf20c782c54ef7ae1765756f323577c061d..242ab67e65046ccf47c4b96937bf76c1bdbc2143 100644 (file)
@@ -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)
index 2e1b8f92bdf8c37d6b5d9008026c2b1240d6b065..01795d08ddaa9b6bf48c64d29107b46c3086ff3c 100644 (file)
@@ -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
index 82e53bd08e9d474ca1452c8e53efe305539398e8..38dcf721e8e56f59a461a8e39992cbabed2e76de 100644 (file)
@@ -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<int> 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<void*,void*>();
-       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<int>();
        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<void*,void*>* iotrelPair = new pair<void*,void*>(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;
index e5ecdfc7e4bf225f94247faa15bf202cdf53a07c..6c966047672ab9199cab9826655c70083cc9e9c3 100644 (file)
@@ -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<int> ports;                      // Now used to contain callback ports
+               vector<int>* ports;                     // Now used to contain callback ports
                string objectFieldName;                                         // Field name that is going to be initialized with IoTSet or IoTRelation
                unordered_set<void*>* isetObject;                       // Set of object
                IoTSet<void*>* iotsetObject;                            // IoTSet of object
@@ -98,7 +99,7 @@ class IoTSlave {
                ofstream log;                                           // Log the messages
                vector<string> args;                            // Hold the arguments for constructor (in string format)
                vector<string> 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:
index 154f36a5ad9811993c9512bcad92dfe35e8fe3a0..7578f3b332b1450790f48e23f1735a886237af2b 100644 (file)
@@ -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<ObjectInitInfo> 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);
        }
 
 
index fe97dec0cd00158c693a3ae9336ca51d7a2e1c90..7b0886cc93118731e7c3478d3b8a4c41dfc9c7d9 100644 (file)
@@ -12,6 +12,7 @@ package iotruntime.messages;
 public enum IoTCommCode {
 
        ACKNOWLEDGED,
+       CREATE_DRIVER_OBJECT,
        CREATE_OBJECT,
        CREATE_MAIN_OBJECT,
        CREATE_NEW_IOTSET,