Cleaning up C++ slave.
[iot2.git] / iotjava / iotruntime / cpp / iotslave / IoTSlave.cpp
index e4d48641615895ed5514ee3e2e95c8e9e14244e6..e0ebcd8d8c784f13ba4c44ced08e07a5e5b9722e 100644 (file)
@@ -5,7 +5,6 @@
 
 IoTSlave::IoTSlave(string _serverAddress, int _serverPort, string _objectName) {
 
-       //isDriverObject = false;               // Default to false
        serverAddress = _serverAddress;
        serverPort = _serverPort;
        objectName = _objectName;
@@ -117,7 +116,7 @@ char* IoTSlave::recvFileIter(char* recvBuffer, int recvLen) {
 
 void IoTSlave::openFile(string fileName) {
 
-       log.open(FILEPATH + fileName + FILEEXT);
+       log.open(LOGFILEPATH + fileName + FILEEXT);
 }
 
 
@@ -203,6 +202,7 @@ void IoTSlave::instantiateMainObject() {
        objMainCls = create_object(params);
        writeToFile("Object created for " + mainObjectName);
        init_object(objMainCls);
+    // TODO: Maybe we want to change this into multithreading at some point
        //thread th1 (&IoTSlave::runInitObject, this, this);
        //th1.detach();
        //thread th1 (&IoTSlave::runInitObject, this, this);
@@ -246,9 +246,6 @@ void IoTSlave::instantiateSkelObject() {
 
        void* params[SKELPARAMSIZE];
        params[0] = objMainCls;
-       //string callbackAddress = LOCALHOST;
-       //params[1] = &callbackAddress;
-       //params[2] = &objectStubPort;
        params[1] = &objectStubPort;
        params[2] = &objectRegPort;
        writeToFile("Skeleton Object " + objectSkelClass + " created for " + objectClassName);
@@ -264,15 +261,10 @@ void IoTSlave::instantiateStubObject() {
        params[0] = &objectStubPort;
        params[1] = &objectRegPort;
        params[2] = &hostAddress;
-       //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);
        writeToFile("Success 1!");
        objStubCls = create_object(params);
@@ -316,7 +308,6 @@ 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;
@@ -349,7 +340,6 @@ 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);
@@ -373,7 +363,6 @@ void IoTSlave::unzipFile(string fileName) {
        // TODO: perhaps we need to replace this with libzip or zlib later      
        writeToFile("Unzipping file!");
        string chmodCmd = FILEPATH + fileName + SHELL;
-       //std::system(chmodCmd.c_str());
        thread th1 (std::system, chmodCmd.c_str());
        th1.detach();
        writeToFile("Finished unzipping file!");
@@ -399,9 +388,6 @@ string IoTSlave::recvFile() {
        fileStream.write(recvFil, fileLen);
        delete[] recvFil;
        fileStream.close();
-       // TODO: Experimental
-       //string chmodCmd = FILEPATH + fileName + SHELL;
-       //execv(chmodCmd.c_str(), 0);
        return fileName;
 }
 
@@ -472,8 +458,6 @@ void IoTSlave::getDeviceIoTSetObject() {
        isetObject->insert(objDeviceAddress);
        writeToFile("=> Inserting IoTDeviceAddress into set...");
        writeToFile("==> Now we have " + to_string(isetObject->size()) + " object(s)!");
-       // Set flag to true;
-       //isDriverObject = true;
 }
 
 
@@ -489,8 +473,6 @@ 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;
        }
 }
 
@@ -559,13 +541,6 @@ void IoTSlave::getIoTSetRelationObject() {
        writeToFile("=> Driver object registry port: " + to_string(objectRegPort));
        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);
-               writeToFile("==> Got a new port: " + to_string(port));
-       }
 }
 
 
@@ -700,6 +675,7 @@ void IoTSlave::commIoTMaster() {
                                break;
 
                        case GET_ZB_DEV_IOTSET_OBJECT:
+                           // TODO: Support ZigBee in the future
                                //getZBDevIoTSetObject();
                                break;