#include <fstream>
#include <vector>
#include <thread>
+#include <cstdlib>
#include <dlfcn.h> // For dlopen, dlsym, etc.
-//#include "ObjectFactory.hpp"
-//#include "ISet.hpp"
#include "IoTSet.hpp"
#include "IoTDeviceAddress.hpp"
-//#include "IRelation.hpp"
#include "IoTRelation.hpp"
#include "Socket.cpp"
enum IoTCommCode {
ACKNOWLEDGED,
+ CREATE_DRIVER_OBJECT,
CREATE_OBJECT,
CREATE_MAIN_OBJECT,
CREATE_NEW_IOTSET,
REINITIALIZE_IOTSET_FIELD,
REINITIALIZE_IOTRELATION_FIELD,
TRANSFER_FILE,
-
+
};
typedef void init_t(void*);
-class IoTSlave {
+class IoTSlave final {
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 int STUBPARAMSIZE = 5; // 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
const static string DESTROYFUNCTION; // The destroy function in class
const static string INITFUNCTION; // The init function in class
const static string LOCALHOST; // String "localhost"
+ const static string SHELL; // String ".sh"
// Class properties
string serverAddress;
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
- 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
+ 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
+ void* irelFirstObject; // First object of IoTRelation
+ void* irelSecondObject; // Second object of IoTRelation
+ unordered_multimap<void*,void*>* irelObject; // Relation of object
+ IoTRelation<void*,void*>* iotrelObject; // IoTRelation of objects
+ vector<IoTRelation<void*,void*>*> vecIoTRel; // IoTRelation 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
- 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
int recvInteger();
void sendString(string strSend);
string recvString();
+ string recvFile();
+ void unzipFile(string fileName);
// Main loop
void sendAck();
bool recvEndTransfer();
void createObject(); // Create driver object
void createMainObject(); // Create main object
void createNewIoTSet();
+ void createNewIoTRelation();
void getDeviceIoTSetObject();
+ void getIoTRelationFirstObject();
+ void getIoTRelationSecondObject();
void reinitializeIoTSetField();
+ void reinitializeIoTRelationField();
void getIoTSetObject();
void invokeInitMethod();
+ void createDriverObject();
+ void transferFile();
private:
// Private helper functions
int* byteToInt(int* result, char* bytes);
char* intToByteArray(int i, char* bytes);
char* recvIter(char* recvBuffer, int recvLen);
+ char* recvFileIter(char* recvBuffer, int recvLen);
void* getObjectConverted(void* retObj, string object, string objectClass);
void openFile(string fileName);
void writeToFile(string logMsg);
void instantiateSkelObject();
void instantiateStubObject();
void runInitObject(IoTSlave* iotslave);
+ void getIoTSetRelationObject();
+ void createStub();
};
// Constant initialization
const string IoTSlave::DESTROYFUNCTION = "destroy";
const string IoTSlave::INITFUNCTION = "init";
const string IoTSlave::LOCALHOST = "localhost";
+const string IoTSlave::SHELL = ".sh";
#endif