Perfecting IoTSlave for C++; Found one issue with SSH/Java process execution in which...
authorrtrimana <rtrimana@uci.edu>
Wed, 18 Jan 2017 20:02:08 +0000 (12:02 -0800)
committerrtrimana <rtrimana@uci.edu>
Wed, 18 Jan 2017 20:02:08 +0000 (12:02 -0800)
22 files changed:
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/drivers/Cpp/LifxLightBulb/LifxLightBulb.cpp
benchmarks/drivers/Cpp/LifxLightBulb/LifxLightBulb.hpp
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/cpp/iotslave/IoTSlave.java
iotjava/iotruntime/cpp/iotslave/LifxLightBulb.so
iotjava/iotruntime/cpp/iotslave/Lifxtest.so
iotjava/iotruntime/cpp/iotslave/LightBulbTest_Stub.so
iotjava/iotruntime/cpp/iotslave/LightBulb_Skeleton.so
iotjava/iotruntime/cpp/iotslave/Makefile
iotjava/iotruntime/cpp/iotslave/ObjectFactory.hpp
iotjava/iotruntime/cpp/setrelation/IoTRelation.hpp
iotjava/iotruntime/cpp/setrelation/IoTSet.hpp

index dbdfc824bfb0fca9bf36463444daef7e1adcffcd..53cb4257337430c7f0bc6dd2a96b3fab3fb891c9 100644 (file)
 #include "LifxLightBulb.cpp"
 #include "Iterator.hpp"
 
-Lifxtest::Lifxtest() {
 
+// 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]);
+}
+
+
+extern "C" void destroyLifxtest(void* t) {
+       Lifxtest* lt = (Lifxtest*) t;
+       delete lt;
+}
+
+
+extern "C" void initLifxtest(void* t) {
+       Lifxtest* lt = (Lifxtest*) t;
+       lt->init();
 }
 
-/*Lifxtest::Lifxtest(IoTSet<LightBulbTest*> _lifx_light_bulb) {
+Lifxtest::Lifxtest() {
+       log.open("Lifxtest_object_cpp.log");
+       log << "lifx_light_bulb initialized!" << endl;
+}
 
+Lifxtest::Lifxtest(IoTSet<void*>* _lifx_light_bulb) {
+
+       log.open("Lifxtest_object_cpp.log");
        lifx_light_bulb = _lifx_light_bulb;
-}*/
+       log << "lifx_light_bulb initialized!" << endl;
+}
 
 Lifxtest::Lifxtest(void** args) {
 
-       //lifx_light_bulb = *(IoTSet<LightBulbTest*>*) args[0];
-       lifx_light_bulb = *(IoTSet<LightBulb*>*) args[0];
+       log.open("Lifxtest_object_cpp.log");
+       lifx_light_bulb = (IoTSet<void*>*) args[0];
+       log << "lifx_light_bulb initialized!" << endl;
 }
 
+
 Lifxtest::~Lifxtest() {
 }
 
 
 void Lifxtest::init() {
 
-       //unordered_set<LightBulbTest*>* bulbSet = lifx_light_bulb.values();
-       unordered_set<LightBulb*>* bulbSet = lifx_light_bulb.values();
-       //for(LightBulbTest* lifx : *bulbSet) {
-       for(LightBulb* lifx : *bulbSet) {
-
+       unordered_set<void*>* bulbSet = lifx_light_bulb->values();
+       //for (unordered_set<void*>::const_iterator itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) {
+       log << "Get into Lifxtest init()!" << endl;
+       for (auto itr = bulbSet->begin(); itr != bulbSet->end(); ++itr) {
+               log << "Iteration init()!" << endl;
+               //LightBulb* lifx = (LightBulb*) *itr;
+               LightBulbTest* lifx = (LightBulbTest*) *itr;
+               log << "Getting object!" << endl;
                lifx->init();
+               log << "Executing init!" << endl;
                this_thread::sleep_for (chrono::milliseconds(1000));
 
-               for (int i = 0; i < 1; i++) {
+               for (int i = 0; i < 5; i++) {
                        lifx->turnOff();
-                       cout << "Turning off!" << endl;
+                       //cout << "Turning off!" << endl;
+                       log << "Turning off!" << endl;
                        this_thread::sleep_for (chrono::milliseconds(1000));
                        lifx->turnOn();
-                       cout << "Turning on!" << endl;
+                       //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;
+               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;
+                       //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;
+                       //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;
+                       //cout << "Adjusting Brightness: " << i << endl;
+                       log << "Adjusting Brightness: " << i << endl;
                        lifx->setColor(lifx->getHue(), lifx->getSaturation(), i);
                        this_thread::sleep_for (chrono::milliseconds(500));
-               }*/
+               }
+               lifx->turnOff();
        }
+
+       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[])
+/*int main(int argc, char *argv[])
 {
        // LightBulb #1
        string macAddress1 = "D073D5128E300000";
        string devIPAddress1 = "192.168.2.126";
        IoTDeviceAddress* devAddress1 = new IoTDeviceAddress(devIPAddress1, 12345, 56700, false, false);
-       unordered_set<IoTDeviceAddress*>* myset1 = new unordered_set<IoTDeviceAddress*>();
+       unordered_set<void*>* myset1 = new unordered_set<void*>();
        myset1->insert(devAddress1);
-       IoTSet<IoTDeviceAddress*>* setDevAddress1 = new IoTSet<IoTDeviceAddress*>(*myset1);
+       IoTSet<void*>* setDevAddress1 = new IoTSet<void*>(myset1);
        LifxLightBulb *llb1 = new LifxLightBulb(setDevAddress1, macAddress1);
        //cout << "Generated LifxLightBulb object!" << endl;
 
@@ -87,20 +127,21 @@ int main(int argc, char *argv[])
        string macAddress2 = "D073D50241DA0000";
        string devIPAddress2 = "192.168.2.232";
        IoTDeviceAddress* devAddress2 = new IoTDeviceAddress(devIPAddress2, 12346, 56700, false, false);
-       unordered_set<IoTDeviceAddress*>* myset2 = new unordered_set<IoTDeviceAddress*>();
+       unordered_set<void*>* myset2 = new unordered_set<void*>();
        myset2->insert(devAddress2);
-       IoTSet<IoTDeviceAddress*>* setDevAddress2 = new IoTSet<IoTDeviceAddress*>(*myset2);
+       IoTSet<void*>* setDevAddress2 = new IoTSet<void*>(myset2);
        LifxLightBulb *llb2 = new LifxLightBulb(setDevAddress2, macAddress2);
 
        // Set of lightbulbs
-       unordered_set<LightBulb*>* setLb = new unordered_set<LightBulb*>();
+       unordered_set<void*>* setLb = new unordered_set<void*>();
        setLb->insert(llb1);
        setLb->insert(llb2);
-       IoTSet<LightBulb*>* lbSet = new IoTSet<LightBulb*>(*setLb);
+       IoTSet<void*>* lbSet = new IoTSet<void*>(setLb);
 
-       void* args[1];
-       args[0] = (void*) lbSet;
-       Lifxtest *lt = new Lifxtest(args);
+       //void* args[1];
+       //args[0] = (void*) lbSet;
+       //Lifxtest *lt = new Lifxtest(args);
+       Lifxtest *lt = new Lifxtest(lbSet);
        lt->init();
 
        //delete llb1;
@@ -113,10 +154,8 @@ int main(int argc, char *argv[])
        delete setDevAddress2;
        delete setLb;
        delete lbSet;
-       //delete llb1;
-       //delete llb2;
 
        return 0;
 }
-
+*/
 
index 0cdc745974eb865df63f66786587cba8e3624a49..eb8c15b47a2df1557175d62a6d77d47998943a66 100644 (file)
@@ -1,22 +1,25 @@
 #ifndef _LIFXTEST_HPP__
 #define _LIFXTEST_HPP__
 #include <iostream>
+#include <fstream>
 
 #include "IoTSet.hpp"
 #include "LightBulb.hpp"
 #include "LightBulbTest.hpp"
 
+
 class Lifxtest {
 
        private:
                // IoTSet
-               //IoTSet<LightBulbTest*> lifx_light_bulb;
-               IoTSet<LightBulb*> lifx_light_bulb;
+               IoTSet<void*>* lifx_light_bulb;
+
+               ofstream log;
 
        public:
 
                Lifxtest();
-               //Lifxtest(IoTSet<LightBulbTest*> _lifx_light_bulb);
+               Lifxtest(IoTSet<void*>* _lifx_light_bulb);
                Lifxtest(void** args);
                ~Lifxtest();
                void init();
index 4a046bcb030395614888516be7294b1c47b0e496..18fb7806f916c9e07de010bbf5ecd098d038b6f0 100644 (file)
@@ -1,11 +1,46 @@
 #include <iostream>
+#include <thread>
 #include "LightBulbTest_Stub.hpp"
 
-// External creator/destroyer
-/*extern "C" LightBulbTest_Stub* create(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {
-       return new LightBulbTest_Stub(_port, _skeletonAddress, _callbackAddress, _rev, _bResult, _ports);
+// External create, destroy, and init functions
+extern "C" void* createLightBulbTest_Stub(void** params) {
+       // Arguments: int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports
+       return new LightBulbTest_Stub(*((int*) params[0]), ((string*) params[1])->c_str(), *((string*) params[2]), *((int*) params[3]), (bool*) params[4], *((vector<int>*) params[5]));
 }
 
-extern "C" void destroy(LightBulbTest_Stub* t) {
-       delete t;
-}*/
+
+extern "C" void destroyLightBulbTest_Stub(void* t) {
+       LightBulbTest_Stub* lbs = (LightBulbTest_Stub*) t;
+       delete lbs;
+}
+
+
+extern "C" void initLightBulbTest_Stub(void* t) {
+       LightBulbTest_Stub* lbs = (LightBulbTest_Stub*) t;
+       lbs->init();
+}
+
+
+int main(int argc, char *argv[])
+{
+       int stubPort = 55179;
+       vector<int> ports;
+       ports.push_back(58551);
+       const char* skeletonAddress = "localhost";
+       string callbackAddress = "localhost";
+       int rev = 0;
+       bool result = false;
+       LightBulbTest_Stub *lbs = new LightBulbTest_Stub(stubPort, skeletonAddress, callbackAddress, rev, &result, ports);
+       cout << "Successfully instantiated stub!" << endl;
+       lbs->init();
+       for (int i = 0; i < 100; i++) {
+               lbs->turnOff();
+               cout << "Turning off!" << endl;
+               this_thread::sleep_for (chrono::milliseconds(1000));
+               lbs->turnOn();
+               cout << "Turning on!" << endl;
+               this_thread::sleep_for (chrono::milliseconds(1000));
+       }
+
+       return 0;
+}
index 5d0c9b0b321787cea37ff0c661cdef1198dd1acd..3e20d5bc533c8dfcdea49bd2b56489dc10d2c335 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _LIGHTBULBTEST_STUB_HPP__
 #define _LIGHTBULBTEST_STUB_HPP__
 #include <iostream>
+#include <fstream>
 #include "LightBulbTest.hpp"
 
 using namespace std;
@@ -14,7 +15,8 @@ class LightBulbTest_Stub : public LightBulbTest
        vector<int> ports;
 
        const static int objectId = 0;
-       
+
+       ofstream log;
 
        public:
 
@@ -23,7 +25,17 @@ class LightBulbTest_Stub : public LightBulbTest
        LightBulbTest_Stub(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {
                callbackAddress = _callbackAddress;
                ports = _ports;
+               // Logging
+               log.open("LightBulbTest_Stub_cpp.log");
+               log << "Port: " << _port << endl;
+               log << "Skeleton address: " << _skeletonAddress << endl;
+               log << "Callback address: " << callbackAddress << endl;
+               log << "Rev: " << _rev << endl;
+               log << "bResult: " << *_bResult << endl;
+               log << "Ports: " << _ports[0] << endl;
                rmiCall = new IoTRMICall(_port, _skeletonAddress, _rev, _bResult);
+               log << "Established connection with skeleton!" << endl;
+               //log.close();
        }
 
        ~LightBulbTest_Stub() {
@@ -99,14 +111,18 @@ class LightBulbTest_Stub : public LightBulbTest
                return retVal;
        }
 
-       void init() { 
+       void init() {
+               log << "Calling init() in stub!" << endl;
                int methodId = 0;
                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;
+               log.close();
        }
 
        void setTemperature(int _temperature) { 
@@ -145,6 +161,4 @@ class LightBulbTest_Stub : public LightBulbTest
 
 };
 
-//typedef LightBulbTest_Stub* create_t(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports);
-//typedef void destroy_t(LightBulbTest_Stub*);
 #endif
index 5f82d06bee03510d6a85634fb42a51cee57fb0c8..648fccac7d3663b97656f1080b4ed5c4f78a22bd 100755 (executable)
@@ -16,6 +16,11 @@ 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/
        cp ./Lifxtest.config $(BIN_DIR)/Lifxtest
 
+PHONY += lightstub
+lightstub:
+       $(G++) ./LightBulbTest_Stub.cpp $(BASE)/iotjava/iotruntime/cpp/socket/Socket.cpp -o $(BIN_DIR)/Lifxtest/LightBulbTest_Stub.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 ./Lifxtest.config $(BIN_DIR)/Lifxtest
+
 PHONY += so-lightstub
 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/
index af7b89292551c224159b9b63f26404cf3d762321..07076db9f9002d0711505b89e8ade62f17c12c21 100644 (file)
 
 using namespace std;
 
-// External creator/destroyer
-/*extern "C" LifxLightBulb* create(IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress) {
-       return new LifxLightBulb(_devAddress, macAddress);
+
+// External functions to create, destroy and initialize this class object
+extern "C" void* createLifxLightBulb(void** params) {
+       // Arguments: IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress
+       return new LifxLightBulb((IoTSet<void*>*) params[0], *((string*) params[1]));
+}
+
+
+extern "C" void destroyLifxLightBulb(void* t) {
+       LifxLightBulb* llb = (LifxLightBulb*) t;
+       delete llb;
+}
+
+
+extern "C" void initLifxLightBulb(void* t) {
+       LifxLightBulb* llb = (LifxLightBulb*) t;
+       llb->init();
 }
 
-extern "C" void destroy(LifxLightBulb* t) {
-       delete t;
-}*/
 
 // Constructor
 LifxLightBulb::LifxLightBulb() { 
@@ -48,7 +59,8 @@ LifxLightBulb::LifxLightBulb() {
 }
 
 
-LifxLightBulb::LifxLightBulb(IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress) {
+// Driver constructor always gets a pointer to device address, trailed by class arguments of generic type
+LifxLightBulb::LifxLightBulb(IoTSet<void*>* _devAddress, string macAddress) {
 
        // Initialize macAddress
        char tmpMacAddress[16];
@@ -61,12 +73,15 @@ LifxLightBulb::LifxLightBulb(IoTSet<IoTDeviceAddress*>* _devAddress, string macA
                tmpMacByte[1] = tmpMacAddress[i+1];
                bulbMacAddress[i/2] = (char) strtol(tmpMacByte, NULL, 16);
        }
-       cout << "MAC address is set. Value: ";
+       //cout << "MAC address is set. Value: ";
        IoTRMIUtil::printBytes(bulbMacAddress, 8, false);
+       // Logging
+       log.open("LifxLightBulb_cpp.log");
+       log << "MAC address is " << macAddress << endl;
 
        // Initialize device address
        lb_addresses = _devAddress;
-       cout << "Device address is set! " << endl;
+       //cout << "Device address is set! " << endl;
 }
 
 
@@ -78,9 +93,10 @@ LifxLightBulb::~LifxLightBulb() {
                delete communicationSocket;
                communicationSocket = NULL;             
        }
-       for(IoTDeviceAddress* dev : *lb_addresses) {
-               delete dev;
-               dev = NULL;
+       for(void* dev : *lb_addresses) {
+               IoTDeviceAddress* dv = (IoTDeviceAddress*) dev;
+               delete dv;
+               dv = NULL;
        }
        if (lb_addresses != NULL) {
 
@@ -97,16 +113,20 @@ void LifxLightBulb::init() {
        if (didAlreadyInit.exchange(true))
                return;
 
-       unordered_set<IoTDeviceAddress*>::const_iterator itr = lb_addresses->begin();
-       IoTDeviceAddress* deviceAddress = *itr;
-       cout << "Address: " << deviceAddress->getAddress() << endl;
+       unordered_set<void*>::const_iterator itr = lb_addresses->begin();
+       IoTDeviceAddress* deviceAddress = (IoTDeviceAddress*) *itr;
+       //cout << "Address: " << deviceAddress->getAddress() << endl;
+       log << "Address: " << deviceAddress->getAddress() << endl;
 
        // Create IoTUDP socket
        communicationSocket = new IoTUDP(deviceAddress);
 
-       cout << "Host address: " << communicationSocket->getHostAddress() << endl;
-       cout << "Source port: " << communicationSocket->getSourcePort() << endl;
-       cout << "Destination port: " << communicationSocket->getDestinationPort() << endl << endl;
+       //cout << "Host address: " << communicationSocket->getHostAddress() << endl;
+       //cout << "Source port: " << communicationSocket->getSourcePort() << endl;
+       //cout << "Destination port: " << communicationSocket->getDestinationPort() << endl << endl;
+       log << "Host address: " << communicationSocket->getHostAddress() << endl;
+       log << "Source port: " << communicationSocket->getSourcePort() << endl;
+       log << "Destination port: " << communicationSocket->getDestinationPort() << endl << endl;
 
        // Launch the worker function in a separate thread.
        //              NOTE: "this" pointer is passed into the detached thread because it does not belong
@@ -115,7 +135,9 @@ void LifxLightBulb::init() {
        thread th1 (&LifxLightBulb::workerFunction, this, this);
        th1.detach();
 
-       cout << "Initialized LifxLightBulb!" << endl;
+       //cout << "Initialized LifxLightBulb!" << endl;
+       log << "Initialized LifxLightBulb!" << endl;
+       log.close();
 }
 
 
@@ -317,15 +339,15 @@ void LifxLightBulb::receivedPacket(char* packetData) {
        }
 
        int type = recHeader.getType();
-       cout << "Received: " << type << endl;
+       //cout << "Received: " << type << endl;
 
        DeviceStateService* dat = NULL;
        switch (type) {
 
                case 3:
                        dat = parseDeviceStateServiceMessage(payloadBytes);
-                       cout << "Service: " << dat->getService();
-                       cout << "Port   : " << dat->getPort();
+                       //cout << "Service: " << dat->getService();
+                       //cout << "Port   : " << dat->getPort();
                        // Avoid memory leak - delete this object
                        delete dat;     
                        break;
@@ -344,7 +366,8 @@ void LifxLightBulb::receivedPacket(char* packetData) {
                        break;
 
                default:
-                       cout << "unknown packet Type" << endl;
+                       break;
+                       //cout << "unknown packet Type" << endl;
        }
        // Avoid memory leaks
        delete payloadBytes;
@@ -380,7 +403,7 @@ void LifxLightBulb::workerFunction(LifxLightBulb* llb) {
                        int64_t currentTime = (int64_t) time(NULL);
                        if ((currentTime - lastSentGetBulbVersionRequest) > llb->GET_BULB_VERSION_RESEND_WAIT_SECONDS) {
                                // Get the bulb version so we know what type of bulb this is.
-                               cout << "Sending version packet! " << endl;
+                               //cout << "Sending version packet! " << endl;
                                llb->sendGetVersionPacket();
                                lastSentGetBulbVersionRequest = currentTime;
                        }
@@ -1145,10 +1168,10 @@ void onOff(LifxLightBulb *llb) {
 
        for (int i = 0; i < 2; i++) {
                llb->turnOff();
-               cout << "Turning off!" << endl;
+               //cout << "Turning off!" << endl;
                this_thread::sleep_for (chrono::milliseconds(1000));
                llb->turnOn();
-               cout << "Turning on!" << endl;
+               //cout << "Turning on!" << endl;
                this_thread::sleep_for (chrono::milliseconds(1000));
        }
 }
@@ -1157,33 +1180,33 @@ void onOff(LifxLightBulb *llb) {
 void adjustTemp(LifxLightBulb *llb) {
 
        for (int i = 2500; i < 9000; i += 100) {
-               cout << "Adjusting Temp: " << i << endl;
+               //cout << "Adjusting Temp: " << i << endl;
                llb->setTemperature(i);
                this_thread::sleep_for (chrono::milliseconds(100));
        }
-       cout << "Adjusted temperature to 9000!" << endl;
+       //cout << "Adjusted temperature to 9000!" << endl;
        for (int i = 9000; i > 2500; i -= 100) {
-               cout << "Adjusting Temp: " << i << endl;
+               //cout << "Adjusting Temp: " << i << endl;
                llb->setTemperature(i);
                this_thread::sleep_for (chrono::milliseconds(100));
        }
-       cout << "Adjusted temperature to 2500!" << endl;
+       //cout << "Adjusted temperature to 2500!" << endl;
 }
 
 
 void adjustBright(LifxLightBulb *llb) {
        for (int i = 100; i > 0; i -= 10) {
-               cout << "Adjusting Brightness: " << i << endl;
+               //cout << "Adjusting Brightness: " << i << endl;
                llb->setColor(llb->getHue(), llb->getSaturation(), i);
                this_thread::sleep_for (chrono::milliseconds(100));
        }
-       cout << "Adjusted brightness to 0!" << endl;
+       //cout << "Adjusted brightness to 0!" << endl;
        for (int i = 0; i < 100; i += 10) {
-               cout << "Adjusting Brightness: " << i << endl;
+               //cout << "Adjusting Brightness: " << i << endl;
                llb->setColor(llb->getHue(), llb->getSaturation(), i);
                this_thread::sleep_for (chrono::milliseconds(100));
        }
-       cout << "Adjusting brightness to 100!" << endl;
+       //cout << "Adjusting brightness to 100!" << endl;
 }
 
 
index 7d23c22d14c6066c58f0468f582604686cf16951..ec1bcdb955a6bd04501d1ec6b2af232a9237793f 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _LIFXLIGHTBULB_HPP__
 #define _LIFXLIGHTBULB_HPP__
 #include <iostream>
+#include <fstream>
 #include <atomic>
 #include <mutex>
 #include <thread>
@@ -86,13 +87,16 @@ class LifxLightBulb : public LightBulb
                bool stateDidChange = false;
 
                // Device address
-               IoTSet<IoTDeviceAddress*>* lb_addresses;
+               IoTSet<void*>* lb_addresses;    // IoTSet<IoTDeviceAddress*>* lb_addresses
 
+               // Logging
+               ofstream log;
        public:
 
                // Constructor
                LifxLightBulb();
-               LifxLightBulb(IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress);
+               //LifxLightBulb(IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress);
+               LifxLightBulb(IoTSet<void*>* _devAddress, string macAddress);
                ~LifxLightBulb();
                // Initialize the lightbulb
                void init();
@@ -165,6 +169,4 @@ class LifxLightBulb : public LightBulb
                void handleLightStateMessageReceived(char* payloadData);
 };
 
-//typedef LifxLightBulb* create_t(IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress);
-//typedef void destroy_t(LifxLightBulb*);
 #endif
index aab1ac859ddd24bccf89e3d889c239c02183268b..f12e77ebd757f25dbd720707df755d9d3f530aae 100644 (file)
@@ -1,11 +1,48 @@
 #include <iostream>
 #include "LightBulb_Skeleton.hpp"
 
-// External creator/destroyer
-/*extern "C" LightBulb_Skeleton* create(LightBulb *_mainObj, string _callbackAddress, int _port) {
-       return new LightBulb_Skeleton(_mainObj, _callbackAddress, _port);
+#include <unordered_set>
+#include "IoTSet.hpp"
+#include "LifxLightBulb.cpp"
+#include "IoTDeviceAddress.hpp"
+
+// External create, destroy, and init functions
+extern "C" void* createLightBulb_Skeleton(void** params) {
+       // Arguments: LightBulb *_mainObj, string _callbackAddress, int _port
+       return new LightBulb_Skeleton((LightBulb*) params[0], *((string*) params[1]), *((int*) params[2]));
+}
+
+
+extern "C" void destroyLightBulb_Skeleton(void* t) {
+       LightBulb_Skeleton* lbs = (LightBulb_Skeleton*) t;
+       delete lbs;
 }
 
-extern "C" void destroy(LightBulb_Skeleton* t) {
-       delete t;
-}*/
+
+extern "C" void initLightBulb_Skeleton(void* t) {
+       LightBulb_Skeleton* lbs = (LightBulb_Skeleton*) t;
+       lbs->init();
+}
+
+
+int main(int argc, char *argv[])
+{
+       // LightBulb #1
+       string macAddress1 = "D073D5128E300000";
+       string devIPAddress1 = "192.168.2.126";
+       //string macAddress1 = "D073D50241DA0000";
+       //string devIPAddress1 = "192.168.2.232";
+       IoTDeviceAddress* devAddress1 = new IoTDeviceAddress(devIPAddress1, 43583, 56700, false, false);
+       unordered_set<void*>* myset1 = new unordered_set<void*>();
+       myset1->insert(devAddress1);
+       IoTSet<void*>* setDevAddress1 = new IoTSet<void*>(myset1);
+       LifxLightBulb *llb1 = new LifxLightBulb(setDevAddress1, macAddress1);
+       //cout << "Generated LifxLightBulb object!" << endl;
+
+       string callbackAddress = "localhost";
+       int stubPort = 55179;
+       LightBulb_Skeleton *lbs = new LightBulb_Skeleton(llb1, callbackAddress, stubPort);
+       cout << "Successfully instantiated object and its skeleton!" << endl;
+
+       return 0;
+}
index b70b21dd3e6c04b7a7f4bb24ba312101fd81ead7..936ea21f5c82c634f58c015b05452f89054641d4 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _LIGHTBULB_SKELETON_HPP__
 #define _LIGHTBULB_SKELETON_HPP__
 #include <iostream>
+#include <fstream>
 #include "LightBulb.hpp"
 
 #include <vector>
@@ -22,14 +23,19 @@ class LightBulb_Skeleton : public LightBulb
        const static int object0Id = 0; //LightBulbSmart
        static set<int> set0Allowed;
        
-
+       ofstream log;
        public:
 
        LightBulb_Skeleton(LightBulb *_mainObj, string _callbackAddress, int _port) {
                bool _bResult = false;
                mainObj = _mainObj;
                callbackAddress = _callbackAddress;
+               // Logging
+               log.open("LightBulb_Skeleton_cpp.log");
+               log << "Callback address: " << callbackAddress << endl;
+               log << "Port: " << _port << endl;
                rmiObj = new IoTRMIObject(_port, &_bResult);
+               log << "Established connection with slave! Wait request invoke now..." << endl;
                ___waitRequestInvokeMethod();
        }
 
@@ -288,9 +294,14 @@ class LightBulb_Skeleton : public LightBulb
 
        void ___waitRequestInvokeMethod() {
                while (true) {
+                       log << "Getting into the while loop" << endl;
                        rmiObj->getMethodBytes();
+                       log << "Getting method bytes now" << endl;
+                       log << "Method len: " << rmiObj->getMethodBytesLen() << endl;
                        int _objectId = rmiObj->getObjectId();
+                       log << "Object Id: " << _objectId << endl;
                        int methodId = rmiObj->getMethodId();
+                       log << "Method Id: " << methodId << endl;
                        if (_objectId == object0Id) {
                                if (set0Allowed.find(methodId) == set0Allowed.end()) {
                                        cerr << "Object with object Id: " << _objectId << "  is not allowed to access method: " << methodId << endl;
@@ -325,11 +336,10 @@ class LightBulb_Skeleton : public LightBulb
                                throw exception();
                        }
                }
+               log.close();
        }
 
 };
 set<int> LightBulb_Skeleton::set0Allowed { 2, 10, 1, 3, 11, 8, 12, 7, 13, 9, 6, 16, 17, 4, 0, 14, 15, 5 };
 
-//typedef LightBulb_Skeleton* create_t(LightBulb *_mainObj, string _callbackAddress, int _port);
-//typedef void destroy_t(LightBulb_Skeleton*);
 #endif
index 74221bc06fcd8151682a86166f59310c07474120..24d9caf20c782c54ef7ae1765756f323577c061d 100644 (file)
@@ -18,6 +18,11 @@ 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 += 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/
+       cp LifxLightBulb/LifxLightBulb.config $(BIN_DIR)/iotcode/LifxLightBulb
+
 PHONY += so-lightskel
 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/
index 310b859ad238a15a9d15f5ffc62e4d88a4eb5c9c..473dda14d6cf7f96547911b046cae01a132fd57d 100644 (file)
@@ -111,17 +111,18 @@ compile:
        cp ./iotrmi/C++/basics/* $(BIN_DIR)/iotpolicy/output_files/Cplus
        cd $(BIN_DIR)/iotpolicy/output_files; cp *.java ./Java
        cd $(BIN_DIR)/iotpolicy/output_files; cp *.hpp ./Cplus
-#      cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) TestClass_Skeleton.java
+       cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) TestClass_Skeleton.java
 #      cd $(BIN_DIR)/iotpolicy/output_files/Java; $(JAVAC) -cp .:..:../../../$(BIN_DIR) TestClassAdvanced_Stub.java
-#      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) 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) 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
 #      cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./TestClass_Skeleton.cpp -o ./TestClass_Skeleton.out --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
        #cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./TestClassAdvanced_Stub.cpp -o ./TestClassAdvanced_Stub.out --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
 #      cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./TestClassCallbacks_Stub.cpp -o ./TestClassCallbacks_Stub.out --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
-       cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./TestClass.hpp -o ./TestClass.out --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
+#      cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(G++) ./TestClass.hpp -o ./TestClass.out --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
        #cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(ARM_G++) ./TestClassInterface_Skeleton.cpp -o ./TestClassInterface_Skeleton.out --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
        #cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(ARM_G++) ./TestClassCallbacks_Stub.cpp -o ./TestClassCallbacks_Stub.out --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
        #cd $(BIN_DIR)/iotpolicy/output_files/Cplus; $(ARM_G++) ./TestClassComplete_Stub.hpp --std=c++11 -pthread -pg -I../../../../iotjava/iotrmi/C++/
index d950a0362f6a7503b0c525e39e83c825286a7374..2761fb1d8c63891f2085df7f657f3763dd0baa3f 100644 (file)
@@ -3,8 +3,11 @@
 
 #include "IoTSlave.hpp"
 
+#include "Lifxtest.cpp"
+
 IoTSlave::IoTSlave(string _serverAddress, int _serverPort, string _objectName) {
 
+       isDriverObject = false;         // Default to false
        serverAddress = _serverAddress;
        serverPort = _serverPort;
        objectName = _objectName;
@@ -20,6 +23,18 @@ IoTSlave::~IoTSlave() {
                delete socket;
                socket = NULL;
        }
+       /*if (objMainCls != NULL) {
+               delete objMainCls;
+               objMainCls = NULL;
+       }
+       if (objSkelCls != NULL) {
+               delete objSkelCls;
+               objSkelCls = NULL;
+       }*/
+       for (IoTSet<void*>* iotset : vecIoTSet) {
+               delete iotset;
+               iotset = NULL;
+       }
        closeFile();
 }
 
@@ -99,7 +114,7 @@ void IoTSlave::closeFile() {
 }
 
 
-void IoTSlave::instantiateObject(string objectClassName) {
+void IoTSlave::getObjectHandler(string objectClassName) {
 
        // Object handling
        string strObj = FILEPATH + objectClassName + SOEXT;
@@ -111,7 +126,8 @@ void IoTSlave::instantiateObject(string objectClassName) {
        }
        writeToFile("Object handled!");
        // Create handler
-       create_object = (create_t*) dlsym(handle, CREATEFUNCTION.c_str());
+       string createFunction = CREATEFUNCTION + objectClassName;
+       create_object = (create_t*) dlsym(handle, createFunction.c_str());
        const char* dlsym_error = dlerror();
     if (dlsym_error) {
         cerr << "Cannot load symbol create: " << dlsym_error << '\n';
@@ -120,7 +136,8 @@ void IoTSlave::instantiateObject(string objectClassName) {
     }
        writeToFile("Object factory created for " + objectClassName);
        // Destroy handler
-    destroy_object = (destroy_t*) dlsym(handle, DESTROYFUNCTION.c_str());
+       string destroyFunction = DESTROYFUNCTION + objectClassName;
+    destroy_object = (destroy_t*) dlsym(handle, destroyFunction.c_str());
     dlsym_error = dlerror();
     if (dlsym_error) {
         cerr << "Cannot load symbol destroy: " << dlsym_error << '\n';
@@ -128,6 +145,107 @@ void IoTSlave::instantiateObject(string objectClassName) {
         exit(1);
     }
        writeToFile("Object destroyer created for " + objectClassName);
+       // Create initializer
+       string initFunction = INITFUNCTION + objectClassName;
+    init_object = (init_t*) dlsym(handle, initFunction.c_str());
+    dlsym_error = dlerror();
+    if (dlsym_error) {
+        cerr << "Cannot load symbol init: " << dlsym_error << '\n';
+               writeToFile("Cannot load symbol init!");
+        exit(1);
+    }
+       writeToFile("Object initializer created for " + objectClassName);
+}
+
+
+// Run init_object function
+void IoTSlave::runInitObject(IoTSlave* iotslave) {
+
+       iotslave->init_object(iotslave->objMainCls);
+}
+
+
+// Instantiate main object!
+// Use handler obtained by getObjectHandler() and instantiate object!
+void IoTSlave::instantiateMainObject() {
+
+       // IoTDeviceAddress + other arguments
+       int paramSize = vecIoTSet.size();
+       void* params[paramSize];
+       for(int i=0; i<vecIoTSet.size(); i++) {
+               params[i] = vecIoTSet[i];       // Just the first object is taken in this case
+       }
+       writeToFile("Vector IoTSet size: " + to_string(vecIoTSet.size()));
+       objMainCls = create_object(params);
+       writeToFile("Object created for " + mainObjectName);
+       init_object(objMainCls);
+       //thread th1 (&IoTSlave::runInitObject, this, this);
+       //th1.detach();
+       //thread th1 (&IoTSlave::runInitObject, this, this);
+       //th1.join();
+       writeToFile("Initialized object " + mainObjectName);
+}
+
+
+// Instantiate driver object!
+// Use handler obtained by getObjectHandler() and instantiate object!
+void IoTSlave::instantiateDriverObject() {
+
+       // IoTDeviceAddress + other arguments
+       int paramSize = vecIoTSet.size() + args.size();
+       void* params[paramSize];
+       for(int i=0; i<vecIoTSet.size(); i++) {
+               params[i] = vecIoTSet[i];       // Just the first object is taken in this case
+       }
+       writeToFile("Vector IoTSet size: " + to_string(vecIoTSet.size()));
+       writeToFile("Arg size: " + to_string(args.size()));
+       int countArg = vecIoTSet.size();        // Start from after the address set
+       // Iterate over arguments
+       for(int i=0; i<args.size(); i++) {
+               params[countArg] = getObjectConverted(params[countArg], args[i], argClasses[i]);
+               countArg++; 
+       }
+       objMainCls = create_object(params);
+       // Delete unused object after conversion and instantiation
+       for(int i=1; i<paramSize; i++) {
+               if (argClasses[i-1].compare(STRINGCLASS) == 0) {                
+                       delete (string*) params[i];
+               } else if (argClasses[i-1].compare(INTCLASS) == 0)
+                       delete (int*) params[i];
+       }               
+       writeToFile("Object created for " + objectClassName);
+}
+
+
+// Use handler obtained by getObjectHandler() and instantiate skeleton object!
+void IoTSlave::instantiateSkelObject() {
+
+       void* params[SKELPARAMSIZE];
+       params[0] = objMainCls;
+       string callbackAddress = LOCALHOST;
+       params[1] = &callbackAddress;
+       params[2] = &objectStubPort;
+       writeToFile("Skeleton Object " + objectSkelClass + " created for " + objectClassName);
+       // After this, this slave needs to be killed using "pkill IoTSlave" because it's waiting in an infinite while-loop
+       objSkelCls = create_object(params);
+}
+
+
+// Use handler obtained by getObjectHandler() and instantiate stub object!
+void IoTSlave::instantiateStubObject() {
+
+       void* params[STUBPARAMSIZE];
+       params[0] = &objectStubPort;
+       params[1] = &hostAddress;
+       string callbackAddress = LOCALHOST;
+       params[2] = &callbackAddress;
+       int rev = 0;
+       params[3] = &rev;
+       bool result = false;
+       params[4] = &result;
+       params[5] = &ports;
+       writeToFile("Stub Object " + objectStubClass + " created for " + objectClassName);
+       objStubCls = create_object(params);
 }
 
 
@@ -212,45 +330,144 @@ string IoTSlave::recvString() {
 void IoTSlave::createObject() {
 
        writeToFile("Creating a driver object now...");
-       sendAck();
        // Receiving object info
        objectName = recvString(); sendAck();
-       writeToFile("Driver object name: " + objectName);
+       writeToFile("=> Driver object name: " + objectName);
        objectClassName = recvString(); sendAck();
-       writeToFile("Driver object class name: " + objectClassName);
+       writeToFile("=> Driver object class name: " + objectClassName);
        objectInterfaceName = recvString(); sendAck();
-       writeToFile("Driver object interface name: " + objectInterfaceName);
+       writeToFile("=> Driver object interface name: " + objectInterfaceName);
        objectSkelClass = recvString(); sendAck();
-       writeToFile("Driver object skeleton class name: " + objectSkelClass);
+       writeToFile("=> Driver object skeleton class name: " + objectSkelClass);
        objectRegPort = recvInteger(); sendAck();
-       writeToFile("Driver object registry port: " + to_string(objectRegPort));
+       writeToFile("=> Driver object registry port: " + to_string(objectRegPort));
        objectStubPort = recvInteger(); sendAck();
-       writeToFile("Driver object stub port: " + to_string(objectStubPort));
+       writeToFile("=> Driver object stub port: " + to_string(objectStubPort));
        int numOfArgs = recvInteger(); sendAck();
        for (int i = 0; i < numOfArgs; i++) {
                string arg = recvString(); sendAck();
                args.push_back(arg);
-               writeToFile("Got argument: " + arg);
+               writeToFile("==> Got argument: " + arg);
        }
        for (int i = 0; i < numOfArgs; i++) {
                string argClass = recvString(); sendAck();
-               args.push_back(argClass);
-               writeToFile("Got argument class: " + argClass);
+               argClasses.push_back(argClass);
+               writeToFile("==> Got argument class: " + argClass);
        }
        // We are just receiving object information here
        // Instantiation will be done when IoTDeviceAddress has been sent
-       //instantiateObject(objectClassName);
 }
 
 
+// Create a new IoTSet object to hold objects
 void IoTSlave::createNewIoTSet() {
 
-
+       objectFieldName = recvString(); sendAck();
+       // Instantiating new IoTSet object
+       isetObject = new unordered_set<void*>();
+       writeToFile("Creating new IoTSet for field: " + objectFieldName);
 }
 
 
+// Get IoTDeviceAddress object reference and put it inside IoTSet object
 void IoTSlave::getDeviceIoTSetObject() {
 
+       writeToFile("Getting IoTDeviceAddress... ");
+       // Get the IoTDeviceAddress info
+       hostAddress = recvString(); sendAck();
+       writeToFile("=> Host address: " + hostAddress);
+       int sourcePort = recvInteger(); sendAck();
+       writeToFile("=> Source port: " + to_string(sourcePort));
+       int destPort = recvInteger(); sendAck();
+       writeToFile("=> Destination port: " + to_string(destPort));
+       bool sourcePortWildCard = (bool) recvInteger(); sendAck();
+       writeToFile("=> Is source port wild card? " + to_string(sourcePortWildCard));
+       bool destPortWildCard = (bool) recvInteger(); sendAck();
+       writeToFile("=> Is destination port wild card? " + to_string(destPortWildCard));
+       // Create IoTDeviceAddress      
+       IoTDeviceAddress* objDeviceAddress = new IoTDeviceAddress(hostAddress, sourcePort, destPort, 
+               sourcePortWildCard, destPortWildCard);
+       // Insert it into isetObject!
+       isetObject->insert(objDeviceAddress);
+       writeToFile("=> Inserting IoTDeviceAddress into set...");
+       writeToFile("==> Now we have " + to_string(isetObject->size()) + " object(s)!");
+       // Set flag to true;
+       isDriverObject = true;
+}
+
+
+// Get IoTSet object content reference and put it inside IoTSet object
+// This is basically the stub objects
+void IoTSlave::getIoTSetObject() {
+
+       writeToFile("Getting IoTSet object... ");
+       // Get the IoTDeviceAddress info
+       hostAddress = recvString(); sendAck();
+       writeToFile("=> Host address: " + hostAddress);
+       objectName = recvString(); sendAck();
+       writeToFile("=> Driver object name: " + objectName);
+       objectClassName = recvString(); sendAck();
+       writeToFile("=> Driver object class name: " + objectClassName);
+       objectInterfaceName = recvString(); sendAck();
+       writeToFile("=> Driver object interface name: " + objectInterfaceName);
+       objectStubClass = recvString(); sendAck();
+       writeToFile("=> Driver object stub class name: " + objectStubClass);
+       objectRegPort = recvInteger(); sendAck();
+       writeToFile("=> Driver object registry port: " + to_string(objectRegPort));
+       objectStubPort = recvInteger(); sendAck();
+       writeToFile("=> Driver object stub port: " + to_string(objectStubPort));
+       int numOfPorts = recvInteger(); sendAck();
+       for (int i = 0; i < numOfPorts; i++) {
+               int port = recvInteger(); sendAck();
+               ports.push_back(port);
+               writeToFile("==> Got a new port: " + to_string(port));
+       }
+       // Create Stub object
+       unordered_map<string,void*>::const_iterator itr = mapObjNameStub.find(objectName);
+       if (itr != mapObjNameStub.end()) {      // Stub has been created earlier
+               writeToFile("=> Stub has been created! Getting back reference...");
+               objStubCls = itr->second;
+       } else {        // Instantiate a new stub and map it
+               writeToFile("=> Stub has not been created! Creating a new stub...");
+               getObjectHandler(objectStubClass);
+               instantiateStubObject();
+               mapObjNameStub.insert(make_pair(objectName,objStubCls));
+               writeToFile("=> Map has: " + to_string(mapObjNameStub.size()) + " members");
+       }
+       // Insert it into isetObject!
+       isetObject->insert(objStubCls);
+       writeToFile("=> Inserting stub object into set...");
+       writeToFile("==> Now we have " + to_string(isetObject->size()) + " object(s)!");
+}
+
+
+// Reinitialize IoTSet field!
+void IoTSlave::reinitializeIoTSetField() {
+
+       writeToFile("Reinitialize IoTSet field...");
+       iotsetObject = new IoTSet<void*>(isetObject);
+       // Collect IoTSet field first in a vector
+       vecIoTSet.push_back(iotsetObject);
+
+       // Create object if this is for driver object
+       if (isDriverObject) {
+               // Instantiate driver object
+               getObjectHandler(objectClassName);
+               instantiateDriverObject();
+               // Instantiate skeleton object
+               getObjectHandler(objectSkelClass);
+               instantiateSkelObject();
+       }
+}
+
+
+// Invoke init() method in main controller
+void IoTSlave::invokeInitMethod() {
+
+       writeToFile("Invoke init() method for: " + mainObjectName);
+       // Instantiate main controller object
+       getObjectHandler(mainObjectName);
+       instantiateMainObject();
 
 }
 
@@ -258,9 +475,10 @@ void IoTSlave::getDeviceIoTSetObject() {
 // Create a main object, e.g. Lifxtest
 void IoTSlave::createMainObject() {
 
-       writeToFile("Creating main object: " + objectName);
-       string mainObject = recvString();
-       sendAck();
+       mainObjectName = recvString(); sendAck();
+       writeToFile("Creating main object: " + mainObjectName);
+       // Just receive the name of the class object here
+       // We will instantiate the object after we get the set/relation objects
 }
 
 
@@ -286,9 +504,9 @@ void IoTSlave::commIoTMaster() {
        writeToFile("Starting main loop...");
        // Main iteration/loop
        while(true) {
-               IoTCommCode message = (IoTCommCode) recvInteger();
+               IoTCommCode message = (IoTCommCode) recvInteger(); sendAck();
                //writeToFile("Message: " + (int) message);
-
+               
                switch(message) {
 
                        case CREATE_OBJECT:
@@ -312,7 +530,7 @@ void IoTSlave::commIoTMaster() {
                                break;
 
                        case GET_IOTSET_OBJECT:
-                               //getIoTSetObject();
+                               getIoTSetObject();
                                break;
 
                        case GET_IOTRELATION_FIRST_OBJECT:
@@ -324,7 +542,7 @@ void IoTSlave::commIoTMaster() {
                                break;
 
                        case REINITIALIZE_IOTSET_FIELD:
-                               //reinitializeIoTSetField();
+                               reinitializeIoTSetField();
                                break;
 
                        case REINITIALIZE_IOTRELATION_FIELD:
@@ -344,7 +562,7 @@ void IoTSlave::commIoTMaster() {
                                break;
 
                        case INVOKE_INIT_METHOD:
-                               //invokeInitMethod();
+                               invokeInitMethod();
                                break;
 
                        case END_SESSION:
@@ -381,7 +599,6 @@ int main(int argc, char *argv[]) {
        int serverPort = atoi(servPort);
        string strObjName = argv[3];
        IoTSlave *iotSlave = new IoTSlave(serverAddress, serverPort, strObjName);
-       //iotSlave->sendInteger(123455);
        iotSlave->sendAck();
        iotSlave->commIoTMaster();
        
index f998a09c54ee931fd6ec6a28a3c5fb29a1a82cea..343a2c2ef7e9fcb3535bc693099b5e329e649018 100644 (file)
@@ -4,13 +4,15 @@
 #include <iostream>
 #include <fstream>
 #include <vector>
+#include <thread>
 
 #include <dlfcn.h>             // For dlopen, dlsym, etc.
 
-#include "ObjectFactory.hpp"
-#include "ISet.hpp"
+//#include "ObjectFactory.hpp"
+//#include "ISet.hpp"
 #include "IoTSet.hpp"
-#include "IRelation.hpp"
+#include "IoTDeviceAddress.hpp"
+//#include "IRelation.hpp"
 #include "IoTRelation.hpp"
 #include "Socket.cpp"
 
@@ -45,11 +47,21 @@ enum IoTCommCode {
 
 };
 
+
+// Defining generic function pointers for 
+// create, destroy, and init functions of each class object
+typedef void* create_t(void**);
+typedef void destroy_t(void*);
+typedef void init_t(void*);
+
+
 class IoTSlave {
 
        private:
                // Constants
                const static int RCVBUFSIZE = 1024;                     // Size of receive buffer
+               const static int SKELPARAMSIZE = 3;                     // Number of params for skeleton
+               const static int STUBPARAMSIZE = 6;                     // Number of params for stub
                const static string FILEPATH;                           // File path
                const static string FILEEXT;                            // File extension
                const static string SOEXT;                              // Shared object (.so) extension
@@ -57,25 +69,39 @@ class IoTSlave {
                const static string INTCLASS;                           // Int class
                const static string CREATEFUNCTION;                     // The create function in class
                const static string DESTROYFUNCTION;            // The destroy function in class
+               const static string INITFUNCTION;                       // The init function in class
+               const static string LOCALHOST;                          // String "localhost"
 
                // Class properties
                string serverAddress;
                int serverPort;
+               string hostAddress;
+               string mainObjectName;
                string objectName;
                string objectClassName;
                string objectInterfaceName;
                string objectSkelClass;         // Need to send from Java IoTSlave: sMessage.getObjectInterfaceName() + SKEL_CLASS_SUFFIX
+               string objectStubClass;         // Need to send from Java IoTSlave: sMessage.getObjectStubInterfaceName() + STUB_CLASS_SUFFIX
                int objectRegPort;
                int objectStubPort;
-               
-               void* object;                           // Handler of object
+               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
+               vector<IoTSet<void*>*> vecIoTSet;       // IoTSet of object
                TCPSocket* socket;
-               ofstream log;                           // Log the messages
-               vector<string> args;            // Hold the arguments for constructor (in string format)
-               vector<string> argClasses;      // Hold the argument classes
+               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
+               void* objMainCls;                                       // Main class handler, i.e. driver or controller object
+               void* objSkelCls;                                       // Skeleton handler
+               void* objStubCls;                                       // Stub handler
+               unordered_map<string, void*> mapObjNameStub;    // Mapping between object name and stub
                // Object handlers
                create_t* create_object;
                destroy_t* destroy_object;
+               init_t* init_object;
 
        public:
                // Constructors
@@ -97,6 +123,9 @@ class IoTSlave {
                void createMainObject();        // Create main object
                void createNewIoTSet();
                void getDeviceIoTSetObject();
+               void reinitializeIoTSetField();
+               void getIoTSetObject();
+               void invokeInitMethod();
 
        private:
                // Private helper functions
@@ -107,7 +136,12 @@ class IoTSlave {
                void openFile(string fileName);
                void writeToFile(string logMsg);
                void closeFile();
-               void instantiateObject(string objectClassName);
+               void getObjectHandler(string objectClassName);
+               void instantiateMainObject();
+               void instantiateDriverObject();
+               void instantiateSkelObject();
+               void instantiateStubObject();
+               void runInitObject(IoTSlave* iotslave);
 };
 
 // Constant initialization
@@ -118,5 +152,7 @@ const string IoTSlave::STRINGCLASS = "string";
 const string IoTSlave::INTCLASS = "int";
 const string IoTSlave::CREATEFUNCTION = "create";
 const string IoTSlave::DESTROYFUNCTION = "destroy";
+const string IoTSlave::INITFUNCTION = "init";
+const string IoTSlave::LOCALHOST = "localhost";
 
 #endif
index 98aa82853d787b0f881d97e2c3545813331a0281..61a39bc7abfc616a1eabcf85e0405d1c1bb93616 100644 (file)
@@ -12,6 +12,7 @@ public class IoTSlave {
 
        private static final String STR_LOCALHOST = "localhost";
        private static final String STR_IOTSLAVE_CPP = "./IoTSlave.o";
+       private static final String STR_IOTSLAVE_PATH = "~/tmp/iot2/iotjava/iotruntime/cpp/iotslave/";
        private static final String STR_ACK = "ACK";
        private static final String STR_END = "END";
        //private static final String STR_LOG_FILE_PATH = "./";
@@ -120,7 +121,8 @@ public class IoTSlave {
         */
        public static String constructCommand(String serverAddress, int serverPort, String strObjName) {
 
-               String strCommand = STR_IOTSLAVE_CPP + " " + serverAddress + " " + serverPort + " " + strObjName;
+               String strCommand = "ssh rtrimana@localhost cd " + STR_IOTSLAVE_PATH + "; " +
+                               STR_IOTSLAVE_CPP + " " + serverAddress + " " + serverPort + " " + strObjName;
                return strCommand;
        }
 
@@ -182,16 +184,36 @@ public class IoTSlave {
        }
 
 
+       /**
+        * Send communication code to C++
+        */
+       public void sendCommCode(IoTCommCode inpCommCode) throws IOException {
+
+
+               IoTCommCode commCode = inpCommCode;
+               int intCode = commCode.ordinal();
+               sendInteger(intCode); recvAck();
+       }
+
+
+       /**
+        * Create a main controller object for C++
+        */
+       public void createMainObjectCpp() throws IOException {
+
+               sendCommCode(IoTCommCode.CREATE_MAIN_OBJECT);
+               String strMainObjName = "Lifxtest";
+               sendString(strMainObjName); recvAck();
+               System.out.println("IoTSlave: Create a main object: " + strMainObjName);
+       }
+
+
        /**
         * Create a driver object for C++
         */
        public void createObjectCpp() throws IOException {
 
-               IoTCommCode commCode = null;
-               int intCode = 0;
-               commCode = IoTCommCode.CREATE_OBJECT;
-               intCode = commCode.ordinal();
-               sendInteger(intCode); recvAck();
+               sendCommCode(IoTCommCode.CREATE_OBJECT);
                String strDrvObjName = "LifxLightBulbLB2";
                String strDrvObjClsName = "LifxLightBulb";
                String strDrvObjIntfaceClsName = "LightBulb";
@@ -200,6 +222,7 @@ public class IoTSlave {
                int iStubPort = 55179;
                // TODO: On the actual slave we need to do conversion back to string before we send everything to C++ IoTSlave
                // TODO: Make it as array of string
+               //String[] arrCppArgs = { "D073D50241DA0000" };
                String[] arrCppArgs = { "D073D5128E300000" };
                String[] arrCppArgClasses = { "string" };
                System.out.println("IoTSlave: Send request to create a driver object... ");
@@ -229,20 +252,99 @@ public class IoTSlave {
 
 
        /**
-        * Send object fields
+        * Create new IoTSet for C++
+        */
+       //public void createNewIoTSetCpp() throws IOException {
+       public void createNewIoTSetCpp(String strObjFieldName) throws IOException {
+
+               sendCommCode(IoTCommCode.CREATE_NEW_IOTSET);
+               System.out.println("IoTSlave: Creating new IoTSet...");
+               //String strObjFieldName = "lb_addresses";
+               System.out.println("IoTSlave: Send object field name: " + strObjFieldName);
+               sendString(strObjFieldName); recvAck();
+       }
+
+
+       /**
+        * Get a IoTDeviceAddress object for C++
+        */
+       public void getDeviceIoTSetObjectCpp() throws IOException {
+
+               sendCommCode(IoTCommCode.GET_DEVICE_IOTSET_OBJECT);
+               System.out.println("IoTSlave: Getting IoTDeviceAddress...");
+               //String strHostAddress = "192.168.2.232";
+               String strHostAddress = "192.168.2.126";
+               sendString(strHostAddress); recvAck();
+               int iSourcePort = 43583;
+               sendInteger(iSourcePort); recvAck();
+               int iDestPort = 56700;
+               sendInteger(iDestPort); recvAck();
+               boolean bSourceWildCard = false;
+               int iSourceWildCard = (bSourceWildCard ? 1 : 0);
+               sendInteger(iSourceWildCard); recvAck();
+               boolean bDestWildCard = false;
+               int iDestWildCard = (bDestWildCard ? 1 : 0);
+               sendInteger(iDestWildCard); recvAck();
+               System.out.println("IoTSlave: Send host address: " + strHostAddress);
+       }
+
+
+       /**
+        * Get a IoTSet content object for C++
+        */
+       public void getIoTSetObjectCpp() throws IOException {
+
+               sendCommCode(IoTCommCode.GET_IOTSET_OBJECT);
+               System.out.println("IoTSlave: Getting IoTSet object content...");
+               String strHostAddress = "localhost";
+               String strDrvObjName = "LifxLightBulbLB2";
+               String strDrvObjClsName = "LifxLightBulb";
+               String strDrvObjIntfaceClsName = "LightBulb";
+               String strDrvObjStubClsName = "LightBulbTest_Stub";     // Send a complete name with "_Stub"
+               int iRegPort = 30313;
+               int iStubPort = 55179;
+               int[] callbackPorts = { 58551 };
+               // Send info
+               System.out.println("IoTSlave: Send host address: " + strHostAddress);
+               sendString(strHostAddress); recvAck();
+               System.out.println("IoTSlave: Driver object name: " + strDrvObjName);
+               sendString(strDrvObjName); recvAck();
+               System.out.println("IoTSlave: Driver object class name: " + strDrvObjClsName);
+               sendString(strDrvObjClsName); recvAck();
+               System.out.println("IoTSlave: Driver object interface name: " + strDrvObjIntfaceClsName);
+               sendString(strDrvObjIntfaceClsName); recvAck();
+               System.out.println("IoTSlave: Driver object skeleton class name: " + strDrvObjStubClsName);
+               sendString(strDrvObjStubClsName); recvAck();
+               System.out.println("IoTSlave: Driver object registry port: " + iRegPort);
+               sendInteger(iRegPort); recvAck();
+               System.out.println("IoTSlave: Driver object stub port: " + iStubPort);
+               sendInteger(iStubPort); recvAck();
+               sendInteger(callbackPorts.length); recvAck();
+               for(int i : callbackPorts) {
+                       sendInteger(i); recvAck();
+               }
+
+       }
+
+
+       /**
+        * Reinitialize IoTSet field for C++
         */
-       private void sendFieldsCpp() throws IOException {
+       private void reinitializeIoTSetFieldCpp() throws IOException {
 
-               
+               System.out.println("IoTSlave: About to Reinitialize IoTSet field!");
+               sendCommCode(IoTCommCode.REINITIALIZE_IOTSET_FIELD);
+               System.out.println("IoTSlave: Reinitialize IoTSet field!");
        }
 
 
        /**
-        * Send object field types
+        * Invoke init() for C++
         */
-       private void sendFieldTypesCpp() throws IOException {
+       private void invokeInitMethodCpp() throws IOException {
 
-               
+               sendCommCode(IoTCommCode.INVOKE_INIT_METHOD);
+               System.out.println("IoTSlave: Invoke init method!");
        }
 
 
@@ -276,27 +378,51 @@ public class IoTSlave {
                System.out.println("Sending back string: " + strRecv);
                iotSlave.sendString(strRecv);*/
 
+               // =========================================
+               // Create IoTSlave for controller object!
+               int iPortMain =12346;
+               String strAddressMain = "localhost";
+               String strObjNameMain = "Lifxtest";
+               IoTSlave iotSlaveMain = new IoTSlave();
+               iotSlaveMain.setServerSocketCpp(iPortMain);
+               // Run thread to spawn C++ IoTSlave
+               String strCmdMain = iotSlaveMain.constructCommand(strAddressMain, iPortMain, strObjNameMain);
+               iotSlaveMain.createCppThread(strCmdMain);
+               iotSlaveMain.connectCpp();
+               System.out.println("IoTSlave: Connection established with main!");
+               // First contact with C++ IoTSlave
+               System.out.println("IoTSlave: IoTSlave.o main is ready: " + iotSlaveMain.recvAck());
+
+               // =========================================
+               // Create IoTSlave for driver object!
                int iPort =12345;
                String strAddress = "localhost";
-               String strObjName = "Lifxtest";
-
+               String strObjName = "LifxLightBulbLB2";
                IoTSlave iotSlave = new IoTSlave();
                iotSlave.setServerSocketCpp(iPort);
-
                // Run thread to spawn C++ IoTSlave
-               String strCmd = IoTSlave.constructCommand(strAddress, 12345, strObjName);
+               String strCmd = IoTSlave.constructCommand(strAddress, iPort, strObjName);
                IoTSlave.createCppThread(strCmd);
                iotSlave.connectCpp();
                //RuntimeOutput.print("IoTSlave: Connection established!", BOOL_VERBOSE);
                System.out.println("IoTSlave: Connection established!");
                // First contact with C++ IoTSlave
                System.out.println("IoTSlave: IoTSlave.o is ready: " + iotSlave.recvAck());
-
                iotSlave.createObjectCpp();
-
-
-               iotSlave.endSessionCpp();
-
+               //iotSlave.createNewIoTSetCpp();
+               iotSlave.createNewIoTSetCpp("lb_addresses");
+               iotSlave.getDeviceIoTSetObjectCpp();
+               iotSlave.reinitializeIoTSetFieldCpp();
+               //iotSlave.endSessionCpp();
+
+               // =========================================
+               // Continue with main object
+               iotSlaveMain.createMainObjectCpp();
+               iotSlaveMain.createNewIoTSetCpp("lifx_light_bulb");
+               iotSlaveMain.getIoTSetObjectCpp();
+               iotSlaveMain.reinitializeIoTSetFieldCpp();
+               iotSlaveMain.invokeInitMethodCpp();
+               iotSlaveMain.endSessionCpp();
 
                // Send message to create a main object
                /*commCode = IoTCommCode.CREATE_MAIN_OBJECT;
index 8c4657d215d302a588579ca4a70e07fe87d773c0..209e8c031a306784b876114dc156dd34915e9f7f 100755 (executable)
Binary files a/iotjava/iotruntime/cpp/iotslave/LifxLightBulb.so and b/iotjava/iotruntime/cpp/iotslave/LifxLightBulb.so differ
index 9bf27d691b8dfdf78ca8b14982f961346d0fffca..8827d7da433464428833b47d460aa6f579acf40b 100755 (executable)
Binary files a/iotjava/iotruntime/cpp/iotslave/Lifxtest.so and b/iotjava/iotruntime/cpp/iotslave/Lifxtest.so differ
index 452ce3642c66c866bea9fee7a2b69794281b27d7..83d8d6dd99aa809b3ec0c1adfa6d44509675c5b1 100755 (executable)
Binary files a/iotjava/iotruntime/cpp/iotslave/LightBulbTest_Stub.so and b/iotjava/iotruntime/cpp/iotslave/LightBulbTest_Stub.so differ
index 0f0e8954d070051f2cfea67ac8f916e3492b1153..42ed05fbe4f3d456c5a891047fe52ad55c279d8c 100755 (executable)
Binary files a/iotjava/iotruntime/cpp/iotslave/LightBulb_Skeleton.so and b/iotjava/iotruntime/cpp/iotslave/LightBulb_Skeleton.so differ
index a42bda5b662ff7cfe37d7477b7f60c7a1ff955fe..48b8955449d7c38c523b564a9a99de5e958268aa 100755 (executable)
@@ -21,6 +21,10 @@ PHONY += run
 run:
        java IoTSlave
 
+PHONY += readlog
+readlog:
+       cat *.log
+
 PHONY += clean
 clean:
        rm -rf *.class
index ee547583ff57e57e452c40dc9822955880f87e80..4ed07a71115952ea6d752d1238d9686f814c6e71 100644 (file)
@@ -1,11 +1,30 @@
 #include "LifxLightBulb.cpp"
 #include "LightBulb_Skeleton.cpp"
 #include "LightBulbTest_Stub.cpp"
+#include "IoTSet.hpp"
 
 
-typedef void* create_t(string className, void** params);
-typedef void destroy_t(void*);
+//typedef void* create_t(string className, void** params);
+//typedef void destroy_t(void*);
 
+
+// Transferring members of IoTSet<void*> into IoTSet<IoTDeviceAddress*>
+IoTSet<IoTDeviceAddress*>* createDeviceAddressSet(unordered_set<void*>* iotSet) {
+
+       unordered_set<IoTDeviceAddress*>* devSet = new unordered_set<IoTDeviceAddress*>();
+       //for (auto itr = iotSet->begin(); itr != iotSet->end(); ++itr) {
+       for (unordered_set<void*>::const_iterator itr = iotSet->begin(); itr != iotSet->end(); ++itr) {
+               IoTDeviceAddress* deviceAddress = (IoTDeviceAddress*) *itr;
+               devSet->insert(deviceAddress);
+       }
+       IoTSet<IoTDeviceAddress*>* iotDevSet = new IoTSet<IoTDeviceAddress*>(devSet);
+
+       delete iotSet;
+       return iotDevSet;
+}
+
+
+/*
 // External creator/destroyer
 extern "C" void* create(string className, void** params) {
 
@@ -47,39 +66,5 @@ extern "C" void destroy(string className, void* ob) {
                }
        }
 }
-
-/*typedef LifxLightBulb* create_t(IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress);
-typedef void destroy_t(LifxLightBulb*);
-
-// External creator/destroyer
-extern "C" LifxLightBulb* create(IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress) {
-       return new LifxLightBulb(_devAddress, macAddress);
-}
-
-extern "C" void destroy(LifxLightBulb* t) {
-       delete t;
-}*/
-
-//typedef LightBulb_Skeleton* create_t(LightBulb *_mainObj, string _callbackAddress, int _port);
-//typedef void destroy_t(LightBulb_Skeleton*);
-
-/*extern "C" LightBulb_Skeleton* create(LightBulb *_mainObj, string _callbackAddress, int _port) {
-       return new LightBulb_Skeleton(_mainObj, _callbackAddress, _port);
-}
-
-extern "C" void destroy(LightBulb_Skeleton* t) {
-       delete t;
-}*/
-
-//typedef LightBulbTest_Stub* create_t(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports);
-//typedef void destroy_t(LightBulbTest_Stub*);
-
-/*extern "C" LightBulbTest_Stub* create(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {
-       return new LightBulbTest_Stub(_port, _skeletonAddress, _callbackAddress, _rev, _bResult, _ports);
-}
-
-extern "C" void destroy(LightBulbTest_Stub* t) {
-       delete t;
-}*/
-
+*/
 
index 77c8ff4e583d265516dbfa53ef5c33e475466e25..673abc42f61422f8525b652cce4748e43f853a35 100644 (file)
@@ -15,10 +15,11 @@ using namespace std;
 template <class K,class V>
 class IoTRelation {
        private:
-               unordered_multimap<K,V> rel;
+               const unordered_multimap<K,V>* rel;
        public:
                IoTRelation();
-               IoTRelation(unordered_multimap<K,V> const& s);
+               //IoTRelation(unordered_multimap<K,V> const& s);
+               IoTRelation(const unordered_multimap<K,V>* s);
                ~IoTRelation();
        public:
                typename unordered_multimap<K,V>::const_iterator find(const K& k);      // Find the object based on key
@@ -46,7 +47,8 @@ IoTRelation<K,V>::IoTRelation() {
  * Useful constructor
  */
 template <class K,class V>
-IoTRelation<K,V>::IoTRelation(const unordered_multimap<K,V>& r) {
+//IoTRelation<K,V>::IoTRelation(const unordered_multimap<K,V>& r) {
+IoTRelation<K,V>::IoTRelation(const unordered_multimap<K,V>* r) {
 
        rel = r;
 }
@@ -67,7 +69,7 @@ IoTRelation<K,V>::~IoTRelation() {
 template <class K,class V>
 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::find(const K& k) {
 
-       return rel.find(k);
+       return rel->find(k);
 }
 
 
@@ -77,7 +79,7 @@ typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::find(const K&
 template <class K,class V>
 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::begin() {
 
-       return rel.begin();
+       return rel->begin();
 }
 
 
@@ -87,7 +89,7 @@ typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::begin() {
 template <class K,class V>
 typename unordered_multimap<K,V>::const_iterator IoTRelation<K,V>::end() {
 
-       return rel.end();
+       return rel->end();
 }
 
 
@@ -99,7 +101,7 @@ std::pair<typename unordered_multimap<K,V>::const_iterator,
        typename unordered_multimap<K,V>::const_iterator> 
        IoTRelation<K,V>::equal_range(const K& k) {
 
-       return rel.equal_range(k);
+       return rel->equal_range(k);
 }
 
 
@@ -109,7 +111,7 @@ std::pair<typename unordered_multimap<K,V>::const_iterator,
 template <class K,class V>
 int IoTRelation<K,V>::size() {
 
-       return rel.size();
+       return rel->size();
 }
 
 
@@ -119,7 +121,7 @@ int IoTRelation<K,V>::size() {
 template <class K,class V>
 unordered_multimap<K,V> IoTRelation<K,V>::values() {
 
-       return new unordered_multimap<K,V>(rel);
+       return new unordered_multimap<K,V>(*rel);
 }
 #endif
 
index 78d8c63f2b49a8d7db1fcfb3aa7ddad4da6a55ad..60f34f757d4d3a40026c3add2a164bb4804343fe 100644 (file)
@@ -15,10 +15,10 @@ using namespace std;
 template <class T>
 class IoTSet {
        private:
-               unordered_set<T> set;
+               const unordered_set<T>* set;
        public:
                IoTSet();
-               IoTSet(unordered_set<T> const& s);
+               IoTSet(const unordered_set<T>* s);
                ~IoTSet();
        public:
                typename unordered_set<T>::const_iterator find(const T& k);     // Find the object
@@ -43,7 +43,7 @@ IoTSet<T>::IoTSet() {
  * Useful constructor
  */
 template <class T>
-IoTSet<T>::IoTSet(const unordered_set<T>& s) {
+IoTSet<T>::IoTSet(const unordered_set<T>* s) {
 
        set = s;
 }
@@ -64,7 +64,7 @@ IoTSet<T>::~IoTSet() {
 template <class T>
 typename unordered_set<T>::const_iterator IoTSet<T>::find(const T& k) {
 
-       return set.find(k);
+       return set->find(k);
 }
 
 
@@ -74,7 +74,7 @@ typename unordered_set<T>::const_iterator IoTSet<T>::find(const T& k) {
 template <class T>
 typename unordered_set<T>::const_iterator IoTSet<T>::begin() {
 
-       return set.begin();
+       return set->begin();
 }
 
 
@@ -84,7 +84,7 @@ typename unordered_set<T>::const_iterator IoTSet<T>::begin() {
 template <class T>
 typename unordered_set<T>::const_iterator IoTSet<T>::end() {
 
-       return set.end();
+       return set->end();
 }
 
 
@@ -94,7 +94,7 @@ typename unordered_set<T>::const_iterator IoTSet<T>::end() {
 template <class T>
 int IoTSet<T>::size() {
 
-       return set.size();
+       return set->size();
 }
 
 
@@ -104,7 +104,7 @@ int IoTSet<T>::size() {
 template <class T>
 unordered_set<T>* IoTSet<T>::values() {
 
-       return new unordered_set<T>(set);
+       return new unordered_set<T>(*set);
 }
 #endif