Perfecting IoTSlave for C++; Found one issue with SSH/Java process execution in which...
[iot2.git] / iotjava / iotruntime / cpp / iotslave / IoTSlave.hpp
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