#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;
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);
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!");
}
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;
char* recvStr = new char[strLen];
// Receive and iterate until complete
+ //writeToFile("Receiving String! Size: " + to_string(strLen));
recvIter(recvStr, strLen);
string retVal(recvStr, strLen);
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);
writeToFile("=> Inserting IoTDeviceAddress into set...");
writeToFile("==> Now we have " + to_string(isetObject->size()) + " object(s)!");
// Set flag to true;
- isDriverObject = true;
+ //isDriverObject = true;
}
// 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();
}
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);
}
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));
- }
}
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);
}
invokeInitMethod();
break;
+ case CREATE_DRIVER_OBJECT:
+ createDriverObject();
+ break;
+
case END_SESSION:
// END of session
goto ENDLOOP;