Removing callback port feature from master and slave
[iot2.git] / iotjava / iotruntime / cpp / iotslave / IoTSlave.cpp
index 82e53bd08e9d474ca1452c8e53efe305539398e8..89d99970f21ce52ec86ba529fc9761407e7432a6 100644 (file)
@@ -3,11 +3,9 @@
 
 #include "IoTSlave.hpp"
 
-#include "Lifxtest.cpp"
-
 IoTSlave::IoTSlave(string _serverAddress, int _serverPort, string _objectName) {
 
-       isDriverObject = false;         // Default to false
+       //isDriverObject = false;               // Default to false
        serverAddress = _serverAddress;
        serverPort = _serverPort;
        objectName = _objectName;
@@ -248,9 +246,8 @@ 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);
        // After this, this slave needs to be killed using "pkill IoTSlave" because it's waiting in an infinite while-loop
        objSkelCls = create_object(params);
@@ -262,16 +259,16 @@ void IoTSlave::instantiateStubObject() {
 
        void* params[STUBPARAMSIZE];
        params[0] = &objectStubPort;
-       params[1] = &hostAddress;
-       string callbackAddress = LOCALHOST;
-       params[2] = &callbackAddress;
+       params[1] = &objectRegPort;
+       params[2] = &hostAddress;
        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);
+       writeToFile("Success 2!");
 }
 
 
@@ -311,6 +308,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 +341,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 +416,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 +465,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;
 }
 
 
@@ -507,16 +507,18 @@ void IoTSlave::reinitializeIoTSetField() {
        // Collect IoTSet field first in a vector
        vecIoTSet.push_back(iotsetObject);
 
-       // Create object if this is for driver object
-       // Right now we assume that this needs only one object per device
-       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 +528,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);
 }
 
 
@@ -547,12 +549,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();
-       for (int i = 0; i < numOfPorts; i++) {
-               int port = recvInteger(); sendAck();
-               ports.push_back(port);
-               writeToFile("==> Got a new port: " + to_string(port));
-       }
 }
 
 
@@ -578,6 +574,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 +694,10 @@ void IoTSlave::commIoTMaster() {
                                invokeInitMethod();
                                break;
 
+                       case CREATE_DRIVER_OBJECT:
+                               createDriverObject();
+                               break;
+
                        case END_SESSION:
                                // END of session
                                goto ENDLOOP;