Modified and tested IoTMaster for IoTSet in C++; completed IoTMaster and IoTSlave...
[iot2.git] / iotjava / iotruntime / master / IoTMaster.java
index 5406e478d84fa20c75f44563a268bcbb009f52d2..154f36a5ad9811993c9512bcad92dfe35e8fe3a0 100644 (file)
@@ -19,6 +19,7 @@ import java.io.InputStreamReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.OutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.IOException;
@@ -27,6 +28,7 @@ import java.lang.Class;
 import java.lang.reflect.*;
 import java.net.Socket;
 import java.net.ServerSocket;
+import java.nio.ByteBuffer;
 import java.util.*;
 import static java.lang.Math.toIntExact;
 
@@ -83,11 +85,12 @@ public class IoTMaster {
        private static String STR_IOT_CODE_PATH;
        private static String STR_CONT_PATH;
        private static String STR_RUNTIME_DIR;
+       private static String STR_SLAVE_DIR;
        private static String STR_CLS_PATH;
        private static String STR_RMI_PATH;
        private static String STR_RMI_HOSTNAME;
        private static String STR_LOG_FILE_PATH;
-       private static String STR_SSH_USERNAME;
+       private static String STR_USERNAME;
        private static String STR_ROUTER_ADD;
        private static String STR_MONITORING_HOST;
        private static String STR_ZB_GATEWAY_ADDRESS;
@@ -97,6 +100,8 @@ public class IoTMaster {
        private static String STR_JVM_INIT_HEAP_SIZE;
        private static String STR_JVM_MAX_HEAP_SIZE;
        private static String STR_LANGUAGE;
+       private static String STR_SKEL_CLASS_SUFFIX;
+       private static String STR_STUB_CLASS_SUFFIX;
        private static boolean BOOL_VERBOSE;
 
        /**
@@ -108,6 +113,7 @@ public class IoTMaster {
        private static final String STR_CFG_FILE_EXT = ".config";
        private static final String STR_CLS_FILE_EXT = ".class";
        private static final String STR_JAR_FILE_EXT = ".jar";
+       private static final String STR_SO_FILE_EXT = ".so";
        private static final String STR_ZIP_FILE_EXT = ".zip";
        private static final String STR_TCP_PROTOCOL = "tcp";
        private static final String STR_UDP_PROTOCOL = "udp";
@@ -121,6 +127,11 @@ public class IoTMaster {
        private static final String STR_NO = "No";
        private static final String STR_JAVA = "Java";
        private static final String STR_CPP = "C++";
+       private static final String STR_SSH = "ssh";
+       private static final String STR_SCP = "scp";
+       private static final String STR_IOTSLAVE_CPP = "./IoTSlave.o";
+
+       private static int INT_SIZE = 4;        // send length in the size of integer (4 bytes)
 
        /**
         * Runtime class name constants - not to be configured by users
@@ -165,11 +176,12 @@ public class IoTMaster {
                STR_IOT_CODE_PATH = null;
                STR_CONT_PATH = null;
                STR_RUNTIME_DIR = null;
+               STR_SLAVE_DIR = null;
                STR_CLS_PATH = null;
                STR_RMI_PATH = null;
                STR_RMI_HOSTNAME = null;
                STR_LOG_FILE_PATH = null;
-               STR_SSH_USERNAME = null;
+               STR_USERNAME = null;
                STR_ROUTER_ADD = null;
                STR_MONITORING_HOST = null;
                STR_ZB_GATEWAY_ADDRESS = null;
@@ -223,11 +235,12 @@ public class IoTMaster {
                STR_IOT_CODE_PATH = prop.getProperty("IOT_CODE_PATH");
                STR_CONT_PATH = prop.getProperty("CONTROLLERS_CODE_PATH");
                STR_RUNTIME_DIR = prop.getProperty("RUNTIME_DIR");
+               STR_SLAVE_DIR = prop.getProperty("SLAVE_DIR");
                STR_CLS_PATH = prop.getProperty("CLASS_PATH");
                STR_RMI_PATH = prop.getProperty("RMI_PATH");
                STR_RMI_HOSTNAME = prop.getProperty("RMI_HOSTNAME");
                STR_LOG_FILE_PATH = prop.getProperty("LOG_FILE_PATH");
-               STR_SSH_USERNAME = prop.getProperty("SSH_USERNAME");
+               STR_USERNAME = prop.getProperty("USERNAME");
                STR_ROUTER_ADD = prop.getProperty("ROUTER_ADD");
                STR_MONITORING_HOST = prop.getProperty("MONITORING_HOST");
                STR_ZB_GATEWAY_ADDRESS = prop.getProperty("ZIGBEE_GATEWAY_ADDRESS");
@@ -237,6 +250,8 @@ public class IoTMaster {
                STR_JVM_INIT_HEAP_SIZE = prop.getProperty("JVM_INIT_HEAP_SIZE");
                STR_JVM_MAX_HEAP_SIZE = prop.getProperty("JVM_MAX_HEAP_SIZE");
                STR_LANGUAGE = prop.getProperty("LANGUAGE");
+               STR_SKEL_CLASS_SUFFIX = prop.getProperty("SKEL_CLASS_SUFFIX");
+               STR_STUB_CLASS_SUFFIX = prop.getProperty("STUB_CLASS_SUFFIX");
                if(prop.getProperty("VERBOSE").equals(STR_YES)) {
                        BOOL_VERBOSE = true;
                }
@@ -246,11 +261,12 @@ public class IoTMaster {
                RuntimeOutput.print("STR_IOT_CODE_PATH=" + STR_IOT_CODE_PATH, BOOL_VERBOSE);
                RuntimeOutput.print("STR_CONT_PATH=" + STR_CONT_PATH, BOOL_VERBOSE);
                RuntimeOutput.print("STR_RUNTIME_DIR=" + STR_RUNTIME_DIR, BOOL_VERBOSE);
+               RuntimeOutput.print("STR_SLAVE_DIR=" + STR_SLAVE_DIR, BOOL_VERBOSE);
                RuntimeOutput.print("STR_CLS_PATH=" + STR_CLS_PATH, BOOL_VERBOSE);
                RuntimeOutput.print("STR_RMI_PATH=" + STR_RMI_PATH, BOOL_VERBOSE);
                RuntimeOutput.print("STR_RMI_HOSTNAME=" + STR_RMI_HOSTNAME, BOOL_VERBOSE);
                RuntimeOutput.print("STR_LOG_FILE_PATH=" + STR_LOG_FILE_PATH, BOOL_VERBOSE);
-               RuntimeOutput.print("STR_SSH_USERNAME=" + STR_SSH_USERNAME, BOOL_VERBOSE);
+               RuntimeOutput.print("STR_USERNAME=" + STR_USERNAME, BOOL_VERBOSE);
                RuntimeOutput.print("STR_ROUTER_ADD=" + STR_ROUTER_ADD, BOOL_VERBOSE);
                RuntimeOutput.print("STR_MONITORING_HOST=" + STR_MONITORING_HOST, BOOL_VERBOSE);
                RuntimeOutput.print("STR_ZB_GATEWAY_ADDRESS=" + STR_ZB_GATEWAY_ADDRESS, BOOL_VERBOSE);
@@ -260,6 +276,8 @@ public class IoTMaster {
                RuntimeOutput.print("STR_JVM_INIT_HEAP_SIZE=" + STR_JVM_INIT_HEAP_SIZE, BOOL_VERBOSE);
                RuntimeOutput.print("STR_JVM_MAX_HEAP_SIZE=" + STR_JVM_MAX_HEAP_SIZE, BOOL_VERBOSE);
                RuntimeOutput.print("STR_LANGUAGE=" + STR_LANGUAGE, BOOL_VERBOSE);
+               RuntimeOutput.print("STR_SKEL_CLASS_SUFFIX=" + STR_SKEL_CLASS_SUFFIX, BOOL_VERBOSE);
+               RuntimeOutput.print("STR_STUB_CLASS_SUFFIX=" + STR_STUB_CLASS_SUFFIX, BOOL_VERBOSE);
                RuntimeOutput.print("BOOL_VERBOSE=" + BOOL_VERBOSE, BOOL_VERBOSE);
                RuntimeOutput.print("IoTMaster: Information extracted successfully!", BOOL_VERBOSE);
        }
@@ -340,14 +358,16 @@ public class IoTMaster {
         * @return  void
         */
        private void commMasterToSlave(Message msgSend, String strPurpose,
-               ObjectInputStream inStream, ObjectOutputStream outStream) 
+               InputStream _inStream, OutputStream _outStream)  
                        throws IOException, ClassNotFoundException {
 
                // Send message/command from master
+               ObjectOutputStream outStream = (ObjectOutputStream) _outStream;
                outStream.writeObject(msgSend);
                RuntimeOutput.print("IoTMaster: Send message: " + strPurpose, BOOL_VERBOSE);
 
                // Get reply from slave as acknowledgment
+               ObjectInputStream inStream = (ObjectInputStream) _inStream;
                Message msgReply = (Message) inStream.readObject();
                RuntimeOutput.print("IoTMaster: Reply message: " + msgReply.getMessage(), BOOL_VERBOSE);
        }
@@ -363,7 +383,7 @@ public class IoTMaster {
         * @return  void
         */
        private void instrumentIoTSetDevice(String strFieldIdentifier, String strObjName, String strFieldName, String strIoTSlaveObjectHostAdd,
-               ObjectInputStream inStream, ObjectOutputStream outStream) 
+               InputStream inStream, OutputStream outStream)  
                        throws IOException, ClassNotFoundException, InterruptedException {
 
                // Get information from the set
@@ -373,7 +393,7 @@ public class IoTMaster {
                        Message msgCrtIoTSet = new MessageCreateSetRelation(IoTCommCode.CREATE_NEW_IOTSET, strFieldName);
                        commMasterToSlave(msgCrtIoTSet, "Create new IoTSet for IoTDeviceAddress!", inStream, outStream);
                } else
-                       ;
+                       createNewIoTSetCpp(strFieldName, outStream, inStream);
                int iRows = listObject.size();
                RuntimeOutput.print("IoTMaster: Number of rows for IoTDeviceAddress: " + iRows, BOOL_VERBOSE);
                // Transfer the address
@@ -420,13 +440,14 @@ public class IoTMaster {
                                                strDeviceAddress, commHan.getComPort(strDeviceAddressKey), iDestDeviceDriverPort, bSrcPortWildCard, bDstPortWildCard);
                                commMasterToSlave(msgGetIoTSetObj, "Get IoTSet objects!", inStream, outStream);
                        } else
-                               ;
+                               getDeviceIoTSetObjectCpp(outStream, inStream, strDeviceAddress, commHan.getComPort(strDeviceAddressKey), iDestDeviceDriverPort, 
+                                       bSrcPortWildCard, bDstPortWildCard);
                }
                // Reinitialize IoTSet on device object
                if(STR_LANGUAGE.equals(STR_JAVA))
                        commMasterToSlave(new MessageSimple(IoTCommCode.REINITIALIZE_IOTSET_FIELD), "Reinitialize IoTSet fields!", inStream, outStream);
                else
-                       ;
+                       reinitializeIoTSetFieldCpp(outStream, inStream);
        }
 
 
@@ -441,7 +462,7 @@ public class IoTMaster {
         * @return  void
         */
        private void instrumentIoTSetZBDevice(Map.Entry<String,Object> map, String strObjName, String strFieldName, String strIoTSlaveObjectHostAdd,
-               ObjectInputStream inStream, ObjectOutputStream outStream) 
+               InputStream inStream, OutputStream outStream)  
                        throws IOException, ClassNotFoundException, InterruptedException {
 
                // Get information from the set
@@ -483,7 +504,7 @@ public class IoTMaster {
                        if(STR_LANGUAGE.equals(STR_JAVA)) {
                                Message msgGetIoTSetZBObj = new MessageGetSimpleDeviceObject(IoTCommCode.GET_ZB_DEV_IOTSET_OBJECT, strZBDevAddress);
                                commMasterToSlave(msgGetIoTSetZBObj, "Get IoTSet objects!", inStream, outStream);
-                       } else
+                       } else  // TODO: Implement IoTSet Zigbee for C++
                                ;
                }
                zbConfig.closeConnection();
@@ -502,7 +523,7 @@ public class IoTMaster {
         * @return  void
         */
        private void instrumentIoTSetAddress(String strFieldIdentifier, String strFieldName,
-               ObjectInputStream inStream, ObjectOutputStream outStream) 
+               InputStream inStream, OutputStream outStream)  
                        throws IOException, ClassNotFoundException, InterruptedException {
 
                // Get information from the set
@@ -524,7 +545,7 @@ public class IoTMaster {
                        if(STR_LANGUAGE.equals(STR_JAVA)) {
                                Message msgGetIoTSetAddObj = new MessageGetSimpleDeviceObject(IoTCommCode.GET_ADD_IOTSET_OBJECT, strAddress);
                                commMasterToSlave(msgGetIoTSetAddObj, "Get IoTSet objects!", inStream, outStream);
-                       } else
+                       } else  // TODO: Implement IoTSet Address for C++
                                ;
                }
                // Reinitialize IoTSet on device object
@@ -681,7 +702,6 @@ public class IoTMaster {
                        System.out.println("DEBUG: InstrumentPolicySetDevice: Port number: " + commHan.getComPort(strDeviceAddressKey));
                        System.out.println("DEBUG: InstrumentPolicySetDevice: Device address: " + strDeviceAddressKey + "\n\n");
 
-
                        // Send routing policy to router for device drivers and devices
                        // ROUTING POLICY: RMI communication - RMI registry and stub ports
                        if((iDestDeviceDriverPort == -1) && (!strProtocol.equals(STR_NO_PROTOCOL))) {
@@ -773,8 +793,6 @@ public class IoTMaster {
                }
                // Get the object and the class names
                // Build objects for IoTSet and IoTRelation fields in the device object classes
-//             mapClassNameToCrim.put(strObjClassName + strFieldObjectID, crim);
-//             HashMap<String,Object> hmObjectFieldObjects = crim.getFieldObjects();
                RuntimeOutput.print("IoTMaster: Going to instrument for " + strObjClassName + " with objectID " + 
                        strFieldObjectID, BOOL_VERBOSE);
                for(Map.Entry<String,Object> map : hmObjectFieldObjects.entrySet()) {
@@ -812,13 +830,26 @@ public class IoTMaster {
        /**
         * A private method to send files to a Java slave driver
         *
+        * @params  serverSocket                                ServerSocket
+        * @params  _inStream                                   InputStream
+        * @params  _outStream                                  OutputStream
+        * @params  strObjName                                  String
+        * @params  strObjClassName                             String
+        * @params  strObjClassInterfaceName    String
+        * @params  strObjStubClsIntfaceName    String
+        * @params  strIoTSlaveObjectHostAdd    String
+        * @params  strFieldObjectID                    String
+        * @params  arrFieldValues                              Object[]
+        * @params  arrFieldClasses                             Class[]
         * @return  void
         */
-       private void sendFileToJavaSlaveDriver(ServerSocket serverSocket, ObjectInputStream inStream, ObjectOutputStream outStream,
+       private void sendFileToJavaSlaveDriver(ServerSocket serverSocket, InputStream _inStream, OutputStream _outStream,
                String strObjName, String strObjClassName, String strObjClassInterfaceName, String strObjStubClsIntfaceName,
                String strIoTSlaveObjectHostAdd, String strFieldObjectID, Object[] arrFieldValues, Class[] arrFieldClasses) 
                        throws IOException, ClassNotFoundException {
 
+               ObjectInputStream inStream = (ObjectInputStream) _inStream;
+               ObjectOutputStream outStream = (ObjectOutputStream) _outStream;
                // Create message to transfer file first
                String sFileName = strObjClassName + STR_JAR_FILE_EXT;
                String sPath = STR_IOT_CODE_PATH + strObjClassName + "/" + sFileName;
@@ -838,6 +869,57 @@ public class IoTMaster {
        }
 
 
+       /**
+        * A private method to send files to a Java slave driver
+        *
+        * @return  void
+        */
+       private void sendFileToCppSlaveDriver(String strObjClassName, String strIoTSlaveObjectHostAdd) 
+                       throws IOException, ClassNotFoundException {
+
+               // Create message to transfer file first
+               String sFileName = strObjClassName + STR_ZIP_FILE_EXT;
+               String sFile = STR_IOT_CODE_PATH + strObjClassName + "/" + sFileName;
+               String strCmdSend = STR_SCP + " " + sFile + " " + STR_USERNAME + strIoTSlaveObjectHostAdd + ":" + STR_SLAVE_DIR;
+               runCommand(strCmdSend);
+               RuntimeOutput.print("IoTMaster: Executing: " + strCmdSend, BOOL_VERBOSE);
+               // Unzip file
+               String strCmdUnzip = STR_SSH + " " + STR_USERNAME + strIoTSlaveObjectHostAdd + " cd " +
+                                       STR_SLAVE_DIR + " sudo unzip " + sFileName + ";";
+               runCommand(strCmdUnzip);
+               RuntimeOutput.print("IoTMaster: Executing: " + strCmdUnzip, BOOL_VERBOSE);
+
+       }
+
+
+       /**
+        * Construct command line for Java IoTSlave
+        *
+        * @return       String
+        */
+       private String getCmdJavaDriverIoTSlave(String strIoTMasterHostAdd, String strIoTSlaveObjectHostAdd, String strObjName) {
+
+               return STR_SSH + " " + STR_USERNAME + strIoTSlaveObjectHostAdd + " cd " + STR_RUNTIME_DIR + " sudo java " +
+                       STR_CLS_PATH + " " + STR_RMI_PATH + " " + STR_RMI_HOSTNAME +
+                       strIoTSlaveObjectHostAdd + " " + STR_IOT_SLAVE_CLS + " " + strIoTMasterHostAdd + " " +
+                       commHan.getComPort(strObjName) + " " + commHan.getRMIRegPort(strObjName) + " " +
+                       commHan.getRMIStubPort(strObjName) + " >& " + STR_LOG_FILE_PATH + strObjName + ".log &";
+       }
+
+
+       /**
+        * Construct command line for C++ IoTSlave
+        *
+        * @return       String
+        */
+       private String getCmdCppDriverIoTSlave(String strIoTMasterHostAdd, String strIoTSlaveObjectHostAdd, String strObjName) {
+
+               return STR_SSH + " " + STR_USERNAME + strIoTSlaveObjectHostAdd + " cd " +
+                                       STR_SLAVE_DIR + " sudo " + STR_IOTSLAVE_CPP + " " + strIoTMasterHostAdd + " " +
+                                       commHan.getComPort(strObjName) + " " + strObjName;
+       }
+
+
        /**
         * A private method to create an object on a specific machine
         *
@@ -867,18 +949,29 @@ public class IoTMaster {
                //           -Djava.rmi.server.codebase=file:./*.jar
                //           iotruntime.IoTSlave dw-1.eecs.uci.edu 46151 23829 42874 &
                // The In-Port for IoTMaster is the Out-Port for IoTSlave and vice versa
-               String strSSHCommand = STR_SSH_USERNAME + strIoTSlaveObjectHostAdd + " cd " + STR_RUNTIME_DIR + " sudo java " +
-                       STR_CLS_PATH + " " + STR_RMI_PATH + " " + STR_RMI_HOSTNAME +
-                       strIoTSlaveObjectHostAdd + " " + STR_IOT_SLAVE_CLS + " " + strIoTMasterHostAdd + " " +
-                       commHan.getComPort(strObjName) + " " + commHan.getRMIRegPort(strObjName) + " " +
-                       commHan.getRMIStubPort(strObjName) + " >& " + STR_LOG_FILE_PATH + strObjName + ".log &";
+               String strSSHCommand = null;
+               if(STR_LANGUAGE.equals(STR_JAVA))
+                       strSSHCommand = getCmdJavaDriverIoTSlave(strIoTMasterHostAdd, strIoTSlaveObjectHostAdd, strObjName);
+               else
+                       strSSHCommand = getCmdCppDriverIoTSlave(strIoTMasterHostAdd, strIoTSlaveObjectHostAdd, strObjName);
+
                RuntimeOutput.print(strSSHCommand, BOOL_VERBOSE);
                // Start a new thread to start a new JVM
                createThread(strSSHCommand);
                ServerSocket serverSocket = new ServerSocket(commHan.getComPort(strObjName));
                Socket socket = serverSocket.accept();
-               ObjectInputStream inStream = new ObjectInputStream(socket.getInputStream());
-               ObjectOutputStream outStream = new ObjectOutputStream(socket.getOutputStream());
+               //InputStream inStream = new ObjectInputStream(socket.getInputStream());
+               //OutputStream outStream = new ObjectOutputStream(socket.getOutputStream());
+               InputStream inStream = null;
+               OutputStream outStream = null;
+               if(STR_LANGUAGE.equals(STR_JAVA)) {
+                       inStream = new ObjectInputStream(socket.getInputStream());
+                       outStream = new ObjectOutputStream(socket.getOutputStream());
+               } else {        // At this point the language is certainly C++, otherwise would've complained above
+                       inStream = new BufferedInputStream(socket.getInputStream());
+                       outStream = new BufferedOutputStream(socket.getOutputStream());
+                       recvAck(inStream);
+               }
 
                // PROFILING
                result = System.currentTimeMillis()-start;
@@ -891,8 +984,12 @@ public class IoTMaster {
                        sendFileToJavaSlaveDriver(serverSocket, inStream, outStream, strObjName, 
                                strObjClassName, strObjClassInterfaceName, strObjStubClsIntfaceName,
                                strIoTSlaveObjectHostAdd, strFieldObjectID, arrFieldValues, arrFieldClasses);
-               } else
-                       ;
+               } else {
+                       sendFileToCppSlaveDriver(strObjClassName, strIoTSlaveObjectHostAdd);
+                       createObjectCpp(strObjName, strObjClassName, strObjClassInterfaceName, strIoTSlaveObjectHostAdd,
+                       commHan.getRMIRegPort(strObjName), commHan.getRMIStubPort(strObjName), arrFieldValues, arrFieldClasses,
+                       outStream, inStream);
+               }
 
                // PROFILING
                result = System.currentTimeMillis()-start;
@@ -903,8 +1000,7 @@ public class IoTMaster {
 
                // Instrument the class source code and look for IoTSet for device addresses
                // e.g. @config private IoTSet<IoTDeviceAddress> lb_addresses;
-               RuntimeOutput.print("IoTMaster: Instantiating for " + strObjClassName + " with objectID " + 
-                       strFieldObjectID, BOOL_VERBOSE);
+               RuntimeOutput.print("IoTMaster: Instantiating for " + strObjClassName + " with objectID " + strFieldObjectID, BOOL_VERBOSE);
                // Get the object and the class names
                // Build objects for IoTSet and IoTRelation fields in the device object classes
                Object crimObj = mapClassNameToCrim.get(strObjClassName + strFieldObjectID);
@@ -940,8 +1036,7 @@ public class IoTMaster {
                                                instrumentIoTSetAddress(strFieldIdentifier, strFieldName, inStream, outStream);
                                        }
                                } else {
-                                       String strErrMsg = "IoTMaster: Device driver object" +
-                                                                               " can only have IoTSet<IoTAddress>, IoTSet<IoTDeviceAddress>," +
+                                       String strErrMsg = "IoTMaster: Device driver object can only have IoTSet<IoTAddress>, IoTSet<IoTDeviceAddress>," +
                                                                                " or IoTSet<IoTZigbeeAddress>!";
                                        throw new Error(strErrMsg);
                                }
@@ -953,9 +1048,11 @@ public class IoTMaster {
                // End the session
                // TODO: Change this later
 
-               if(STR_LANGUAGE.equals(STR_JAVA))
-                       outStream.writeObject(new MessageSimple(IoTCommCode.END_SESSION));
-               else
+               if(STR_LANGUAGE.equals(STR_JAVA)) {
+                       ObjectOutputStream oStream = (ObjectOutputStream) outStream;
+                       oStream.writeObject(new MessageSimple(IoTCommCode.END_SESSION));
+               } else  // C++ side for now will be running continuously because it's an infinite loop (not in a separate thread)
+                       //endSessionCpp(outStream);
                        ;
 
                // PROFILING
@@ -1107,7 +1204,7 @@ public class IoTMaster {
         * @params  outStream                 ObjectOutputStream communication
         * @return      void
         */
-       private void initializeSetsAndRelationsJava(ObjectInputStream inStream, ObjectOutputStream outStream) 
+       private void initializeSetsAndRelationsJava(InputStream inStream, OutputStream outStream)  
                throws IOException, ClassNotFoundException {
                // Get list of fields
                List<String> strFields = objInitHand.getListOfFields();
@@ -1166,7 +1263,7 @@ public class IoTMaster {
         * @params  outStream                 ObjectOutputStream communication
         * @return      void
         */
-       private void initializeSetsAndRelationsCpp(ObjectInputStream inStream, ObjectOutputStream outStream) 
+       private void initializeSetsAndRelationsCpp(InputStream inStream, OutputStream outStream)  
                throws IOException, ClassNotFoundException {
                // Get list of fields
                List<String> strFields = objInitHand.getListOfFields();
@@ -1175,45 +1272,39 @@ public class IoTMaster {
                        IoTCommCode iotcommMsg = objInitHand.getFieldMessage(str);
                        if (iotcommMsg == IoTCommCode.CREATE_NEW_IOTSET) {
                                // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO CREATE IOTSET
-                               Message msgCrtIoTSet = new MessageCreateSetRelation(IoTCommCode.CREATE_NEW_IOTSET, str);
-                               commMasterToSlave(msgCrtIoTSet, "Create new IoTSet!", inStream, outStream);
+                               createNewIoTSetCpp(str, outStream, inStream);
                                List<ObjectInitInfo> listObject = objInitHand.getListObjectInitInfo(str);
                                for (ObjectInitInfo objInitInfo : listObject) {
                                        // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO FILL IN IOTSET
-                                       commMasterToSlave(new MessageGetObject(IoTCommCode.GET_IOTSET_OBJECT, objInitInfo.getIoTSlaveObjectHostAdd(),
-                                               objInitInfo.getObjectName(), objInitInfo.getObjectClassName(), objInitInfo.getObjectClassInterfaceName(), 
+                                       getIoTSetRelationObjectCpp(objInitInfo.getIoTSlaveObjectHostAdd(), objInitInfo.getObjectName(), 
+                                               objInitInfo.getObjectClassName(), objInitInfo.getObjectClassInterfaceName(), 
                                                objInitInfo.getObjectStubClassInterfaceName(), objInitInfo.getRMIRegistryPort(), objInitInfo.getRMIStubPort(),
-                                               objInitInfo.getRMICallbackPorts()), "Get IoTSet object!", inStream, outStream);
-
+                                               objInitInfo.getRMICallbackPorts(), outStream, inStream);
                                }
                                // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO REINITIALIZE IOTSET FIELD
-                               commMasterToSlave(new MessageSimple(IoTCommCode.REINITIALIZE_IOTSET_FIELD),
-                                       "Renitialize IoTSet field!", inStream, outStream);
+                               reinitializeIoTSetFieldCpp(outStream, inStream);
                        } else if (iotcommMsg == IoTCommCode.CREATE_NEW_IOTRELATION) {
                                // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO CREATE IOTRELATION
-                               Message msgCrtIoTRel = new MessageCreateSetRelation(IoTCommCode.CREATE_NEW_IOTRELATION, str);
-                               commMasterToSlave(msgCrtIoTRel, "Create new IoTRelation!", inStream, outStream);
+                               // TODO: createNewIoTRelation needs to be created here!
+                               createNewIoTRelationCpp(str, outStream, inStream);
                                List<ObjectInitInfo> listObject = objInitHand.getListObjectInitInfo(str);
                                List<ObjectInitInfo> listSecondObject = objInitHand.getSecondObjectInitInfo(str);
                                Iterator it = listSecondObject.iterator();
                                for (ObjectInitInfo objInitInfo : listObject) {
                                        // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO FILL IN IOTRELATION (FIRST OBJECT)
-                                       commMasterToSlave(new MessageGetObject(IoTCommCode.GET_IOTRELATION_FIRST_OBJECT, 
-                                               objInitInfo.getIoTSlaveObjectHostAdd(), objInitInfo.getObjectName(), objInitInfo.getObjectClassName(),
-                                               objInitInfo.getObjectClassInterfaceName(), objInitInfo.getObjectStubClassInterfaceName(),
-                                               objInitInfo.getRMIRegistryPort(), objInitInfo.getRMIStubPort(), objInitInfo.getRMICallbackPorts()), 
-                                               "Get IoTRelation first object!", inStream, outStream);
+                                       getIoTSetRelationObjectCpp(objInitInfo.getIoTSlaveObjectHostAdd(), objInitInfo.getObjectName(), 
+                                               objInitInfo.getObjectClassName(), objInitInfo.getObjectClassInterfaceName(), 
+                                               objInitInfo.getObjectStubClassInterfaceName(), objInitInfo.getRMIRegistryPort(), objInitInfo.getRMIStubPort(),
+                                               objInitInfo.getRMICallbackPorts(), outStream, inStream);
                                        ObjectInitInfo objSecObj = (ObjectInitInfo) it.next();
                                        // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO FILL IN IOTRELATION (SECOND OBJECT)
-                                       commMasterToSlave(new MessageGetObject(IoTCommCode.GET_IOTRELATION_SECOND_OBJECT,
-                                               objSecObj.getIoTSlaveObjectHostAdd(), objSecObj.getObjectName(), objSecObj.getObjectClassName(),
-                                               objSecObj.getObjectClassInterfaceName(), objSecObj.getObjectStubClassInterfaceName(),
-                                               objSecObj.getRMIRegistryPort(), objSecObj.getRMIStubPort(), objSecObj.getRMICallbackPorts()), 
-                                               "Get IoTRelation second object!", inStream, outStream);
+                                       getIoTSetRelationObjectCpp(objSecObj.getIoTSlaveObjectHostAdd(), objSecObj.getObjectName(), 
+                                               objSecObj.getObjectClassName(), objSecObj.getObjectClassInterfaceName(), 
+                                               objSecObj.getObjectStubClassInterfaceName(), objSecObj.getRMIRegistryPort(), objSecObj.getRMIStubPort(),
+                                               objSecObj.getRMICallbackPorts(), outStream, inStream);
                                }
                                // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO REINITIALIZE IOTRELATION FIELD
-                               commMasterToSlave(new MessageSimple(IoTCommCode.REINITIALIZE_IOTRELATION_FIELD),
-                                       "Renitialize IoTRelation field!", inStream, outStream);
+                               reinitializeIoTRelationFieldCpp(outStream, inStream);
                        }
                }
        }
@@ -1305,14 +1396,21 @@ public class IoTMaster {
                }
        }
 
+
        /**
         * A method to send files to Java IoTSlave
         *
+        * @params  strObjControllerName      String
+        * @params  serverSocket              ServerSocket
+        * @params  inStream                  ObjectInputStream communication
+        * @params  outStream                 ObjectOutputStream communication
         * @return       void
         */     
        private void sendFileToJavaSlave(String strObjControllerName, ServerSocket serverSocket, 
-                       ObjectInputStream inStream, ObjectOutputStream outStream) throws IOException, ClassNotFoundException {
+                       InputStream _inStream, OutputStream _outStream) throws IOException, ClassNotFoundException {
 
+               ObjectInputStream inStream = (ObjectInputStream) _inStream;
+               ObjectOutputStream outStream = (ObjectOutputStream) _outStream;
                // Send .jar file
                String strControllerJarName = strObjControllerName + STR_JAR_FILE_EXT;
                String strControllerJarNamePath = STR_CONT_PATH + strObjControllerName + "/" +
@@ -1343,6 +1441,436 @@ public class IoTMaster {
        }
 
 
+       /**
+        * A method to send files to C++ IoTSlave
+        *
+        * @return       void
+        * TODO: Need to look into this (as of now, file transferred retains the "data" format, 
+        * hence it is unreadable from outside world
+        */
+       private void sendFileToCppSlave(String sFilePath, String sFileName, Socket fileSocket, 
+                       InputStream inStream, OutputStream outStream) throws IOException {
+
+               sendCommCode(IoTCommCode.TRANSFER_FILE, outStream, inStream);
+               // Send file name
+               sendString(sFileName, outStream); recvAck(inStream);
+               File file = new File(sFilePath + sFileName);
+               int iFileLen = toIntExact(file.length());
+               RuntimeOutput.print("IoTSlave: Sending file " + sFileName + " with length " + iFileLen + " bytes...", BOOL_VERBOSE);
+               // Send file length
+               sendInteger(iFileLen, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Sent file size!", BOOL_VERBOSE);
+               byte[] bytFile = new byte[iFileLen];
+               InputStream inFileStream = new FileInputStream(file);
+               RuntimeOutput.print("IoTSlave: Opened file!", BOOL_VERBOSE);
+
+               OutputStream outFileStream = fileSocket.getOutputStream();
+               RuntimeOutput.print("IoTSlave: Got output stream!", BOOL_VERBOSE);
+               int iCount;
+               while ((iCount = inFileStream.read(bytFile)) > 0) {
+                       outFileStream.write(bytFile, 0, iCount);
+               }
+               RuntimeOutput.print("IoTSlave: File sent!", BOOL_VERBOSE);
+               recvAck(inStream);
+       }
+
+
+       /**
+        * A method to send files to C++ IoTSlave (now master using Process() to start 
+        * file transfer using scp)
+        *
+        * @return       void
+        */
+       private void sendFileToCppSlave(String sFilePath, String sFileName) throws IOException {
+
+               // Construct shell command to transfer file     
+               String sFile = sFilePath + sFileName;
+               String strCmdSend = STR_SCP + " " + sFile + " " + STR_USERNAME + strIoTSlaveControllerHostAdd + ":" + STR_SLAVE_DIR;
+               runCommand(strCmdSend);
+               RuntimeOutput.print("IoTMaster: Executing: " + strCmdSend, BOOL_VERBOSE);
+               // Unzip file
+               String strCmdUnzip = STR_SSH + " " + STR_USERNAME + strIoTSlaveControllerHostAdd + " cd " +
+                                       STR_SLAVE_DIR + " sudo unzip " + sFileName + ";";
+               runCommand(strCmdUnzip);
+               RuntimeOutput.print("IoTMaster: Executing: " + strCmdUnzip, BOOL_VERBOSE);
+       }
+
+
+       /**
+        * runCommand() method runs shell command
+        *
+        * @param   strCommand  String that contains command line
+        * @return  void
+        */
+       private void runCommand(String strCommand) {
+
+               try {
+                       Runtime runtime = Runtime.getRuntime();
+                       Process process = runtime.exec(strCommand);
+                       process.waitFor();
+               } catch (IOException ex) {
+                       System.out.println("RouterConfig: IOException: " + ex.getMessage());
+                       ex.printStackTrace();
+               } catch (InterruptedException ex) {
+                       System.out.println("RouterConfig: InterruptException: " + ex.getMessage());
+                       ex.printStackTrace();
+               }
+       }
+
+
+       /**
+        * Construct command line for Java IoTSlave
+        *
+        * @return       String
+        */
+       private String getCmdJavaIoTSlave(String strObjControllerName) {
+
+               return STR_SSH + " " + STR_USERNAME + strIoTSlaveControllerHostAdd + " cd " +
+                                       STR_RUNTIME_DIR + " sudo java " + STR_JVM_INIT_HEAP_SIZE + " " + 
+                                       STR_JVM_MAX_HEAP_SIZE + " " + STR_CLS_PATH + " " +
+                                       STR_RMI_PATH + " " + STR_IOT_SLAVE_CLS + " " + strIoTMasterHostAdd + " " +
+                                       commHan.getComPort(strObjControllerName) + " " +
+                                       commHan.getRMIRegPort(strObjControllerName) + " " +
+                                       commHan.getRMIStubPort(strObjControllerName) + " >& " +
+                                       STR_LOG_FILE_PATH + strObjControllerName + ".log &";
+       }
+
+
+       /**
+        * Construct command line for C++ IoTSlave
+        *
+        * @return       String
+        */
+       private String getCmdCppIoTSlave(String strObjControllerName) {
+
+               return STR_SSH + " " + STR_USERNAME + strIoTSlaveControllerHostAdd + " cd " +
+                                       STR_SLAVE_DIR + " sudo " + STR_IOTSLAVE_CPP + " " + strIoTMasterHostAdd + " " +
+                                       commHan.getComPort(strObjControllerName) + " " + strObjControllerName;
+       }
+
+
+       /**
+        * sendInteger() sends an integer in bytes
+        */
+       public void sendInteger(int intSend, OutputStream outStream) throws IOException {
+
+               BufferedOutputStream output = (BufferedOutputStream) outStream;
+               // Transform integer into bytes
+               ByteBuffer bb = ByteBuffer.allocate(INT_SIZE);
+               bb.putInt(intSend);
+               // Send the byte array
+               output.write(bb.array(), 0, INT_SIZE);
+               output.flush();
+       }
+
+
+       /**
+        * recvInteger() receives integer in bytes
+        */
+       public int recvInteger(InputStream inStream) throws IOException {
+
+               BufferedInputStream input = (BufferedInputStream) inStream;
+               // Wait until input is available
+               while(input.available() == 0);
+               // Read integer - 4 bytes
+               byte[] recvInt = new byte[INT_SIZE];
+               input.read(recvInt, 0, INT_SIZE);
+               int retVal = ByteBuffer.wrap(recvInt).getInt();
+
+               return retVal;
+       }
+
+
+       /**
+        * recvString() receives String in bytes
+        */
+       public String recvString(InputStream inStream) throws IOException {
+
+               BufferedInputStream input = (BufferedInputStream) inStream;
+               int strLen = recvInteger(inStream);
+               // Wait until input is available
+               while(input.available() == 0);
+               // Read String per strLen
+               byte[] recvStr = new byte[strLen];
+               input.read(recvStr, 0, strLen);
+               String retVal = new String(recvStr);
+
+               return retVal;
+       }
+
+
+       /**
+        * sendString() sends a String in bytes
+        */
+       public void sendString(String strSend, OutputStream outStream) throws IOException {
+
+               BufferedOutputStream output = (BufferedOutputStream) outStream;
+               // Transform String into bytes
+               byte[] strSendBytes = strSend.getBytes();
+               int strLen = strSend.length();
+               // Send the string length first
+               sendInteger(strLen, outStream);
+               // Send the byte array
+               output.write(strSendBytes, 0, strLen);
+               output.flush();
+       }
+
+
+       /**
+        * Convert integer to enum
+        */
+       public IoTCommCode getCode(int intCode) throws IOException {
+
+               IoTCommCode[] commCode = IoTCommCode.values();
+               IoTCommCode retCode = commCode[intCode];
+               return retCode;
+
+       }
+
+
+       /**
+        * Receive ACK
+        */
+       public boolean recvAck(InputStream inStream) throws IOException {
+
+               int intAck = recvInteger(inStream);
+               IoTCommCode codeAck = getCode(intAck);
+               if (codeAck == IoTCommCode.ACKNOWLEDGED)
+                       return true;
+               return false;
+
+       }
+
+
+       /**
+        * Send END
+        */
+       public void sendEndTransfer(OutputStream outStream) throws IOException {
+
+               int endCode = IoTCommCode.END_TRANSFER.ordinal();
+               sendInteger(endCode, outStream);
+       }
+
+
+       /**
+        * Send communication code to C++
+        */
+       public void sendCommCode(IoTCommCode inpCommCode, OutputStream outStream, InputStream inStream) throws IOException {
+
+
+               IoTCommCode commCode = inpCommCode;
+               int intCode = commCode.ordinal();
+               // TODO: delete this later
+               System.out.println("DEBUG: Sending " + commCode + " with ordinal: " + intCode);
+               sendInteger(intCode, outStream); recvAck(inStream);
+       }
+
+
+       /**
+        * Create a main controller object for C++
+        */
+       public void createMainObjectCpp(String strObjControllerName, OutputStream outStream, InputStream inStream) throws IOException {
+
+               sendCommCode(IoTCommCode.CREATE_MAIN_OBJECT, outStream, inStream);
+               String strMainObjName = strObjControllerName;
+               sendString(strMainObjName, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Create a main object: " + strMainObjName, BOOL_VERBOSE);
+       }
+
+
+       /**
+        * A helper function that converts Class into String
+        *
+        * @param  strDataType  String MySQL data type
+        * @return              Class
+        */
+       public String getClassConverted(Class<?> cls) {
+
+               if (cls == String.class) {
+                       return "string";
+               } else if (cls == int.class) {
+                       return "int";
+               } else {
+                       return null;
+               }
+       }
+
+
+       /**
+        * A helper function that converts Object into String for transfer to C++ slave
+        *
+        * @param  obj           Object to be converted
+        * @param  strClassType  String Java Class type
+        * @return               Object
+        */
+       public String getObjectConverted(Object obj) {
+
+               if (obj instanceof String) {
+                       return (String) obj;
+               } else if (obj instanceof Integer) {
+                       return Integer.toString((Integer) obj);
+               } else {
+                       return null;
+               }
+       }
+
+
+       /**
+        * Create a driver object for C++
+        */
+       public void createObjectCpp(String strObjName, String strObjClassName, String strObjClassInterfaceName, String strIoTSlaveObjectHostAdd, 
+               Integer iRMIRegistryPort, Integer iRMIStubPort, Object[] arrFieldValues, Class[] arrFieldClasses, 
+               OutputStream outStream, InputStream inStream) throws IOException {
+
+               sendCommCode(IoTCommCode.CREATE_OBJECT, outStream, inStream);
+               RuntimeOutput.print("IoTSlave: Send request to create a driver object... ", BOOL_VERBOSE);
+               RuntimeOutput.print("IoTSlave: Driver object name: " + strObjName, BOOL_VERBOSE);
+               sendString(strObjName, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Driver object class name: " + strObjClassName, BOOL_VERBOSE);
+               sendString(strObjClassName, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Driver object interface name: " + strObjClassInterfaceName, BOOL_VERBOSE);
+               sendString(strObjStubClsIntfaceName, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Driver object skeleton class name: " + strObjClassInterfaceName + STR_SKEL_CLASS_SUFFIX, BOOL_VERBOSE);
+               sendString(strObjClassInterfaceName + STR_SKEL_CLASS_SUFFIX, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Driver object registry port: " + iRMIRegistryPort, BOOL_VERBOSE);
+               sendInteger(iRMIRegistryPort, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Driver object stub port: " + iRMIStubPort, BOOL_VERBOSE);
+               sendInteger(iRMIStubPort, outStream); recvAck(inStream);
+               int numOfArgs = arrFieldValues.length;
+               RuntimeOutput.print("IoTSlave: Send constructor arguments! Number of arguments: " + numOfArgs, BOOL_VERBOSE);
+               sendInteger(numOfArgs, outStream); recvAck(inStream);
+               for(Object obj : arrFieldValues) {
+                       String str = getObjectConverted(obj);
+                       sendString(str, outStream); recvAck(inStream);
+               }
+               RuntimeOutput.print("IoTSlave: Send constructor argument classes!", BOOL_VERBOSE);
+               for(Class cls : arrFieldClasses) {
+                       String str = getClassConverted(cls);
+                       sendString(str, outStream); recvAck(inStream);
+               }
+       }
+
+
+       /**
+        * Create new IoTSet for C++
+        */
+       public void createNewIoTSetCpp(String strObjFieldName, OutputStream outStream, InputStream inStream) throws IOException {
+
+               sendCommCode(IoTCommCode.CREATE_NEW_IOTSET, outStream, inStream);
+               RuntimeOutput.print("IoTSlave: Creating new IoTSet...", BOOL_VERBOSE);
+               RuntimeOutput.print("IoTSlave: Send object field name: " + strObjFieldName, BOOL_VERBOSE);
+               sendString(strObjFieldName, outStream); recvAck(inStream);
+       }
+
+
+       /**
+        * Create new IoTRelation for C++
+        */
+       public void createNewIoTRelationCpp(String strObjFieldName, OutputStream outStream, InputStream inStream) throws IOException {
+
+               sendCommCode(IoTCommCode.CREATE_NEW_IOTRELATION, outStream, inStream);
+               RuntimeOutput.print("IoTSlave: Creating new IoTRelation...", BOOL_VERBOSE);
+               RuntimeOutput.print("IoTSlave: Send object field name: " + strObjFieldName, BOOL_VERBOSE);
+               sendString(strObjFieldName, outStream); recvAck(inStream);
+       }
+
+
+       /**
+        * Get a IoTDeviceAddress object for C++
+        */
+       public void getDeviceIoTSetObjectCpp(OutputStream outStream, InputStream inStream,
+                       String strDeviceAddress, int iSourcePort, int iDestPort, boolean bSourceWildCard, boolean bDestWildCard) throws IOException {
+
+               sendCommCode(IoTCommCode.GET_DEVICE_IOTSET_OBJECT, outStream, inStream);
+               RuntimeOutput.print("IoTSlave: Getting IoTDeviceAddress...", BOOL_VERBOSE);
+               sendString(strDeviceAddress, outStream); recvAck(inStream);
+               sendInteger(iSourcePort, outStream); recvAck(inStream);
+               sendInteger(iDestPort, outStream); recvAck(inStream);
+               int iSourceWildCard = (bSourceWildCard ? 1 : 0);
+               sendInteger(iSourceWildCard, outStream); recvAck(inStream);
+               int iDestWildCard = (bDestWildCard ? 1 : 0);
+               sendInteger(iDestWildCard, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Send device address: " + strDeviceAddress, BOOL_VERBOSE);
+       }
+
+
+       /**
+        * Get a IoTSet content object for C++
+        */
+       public void getIoTSetRelationObjectCpp(String strIoTSlaveHostAddress, String strObjectName, String strObjectClassName, 
+                       String strObjectClassInterfaceName, String strObjectStubClassInterfaceName, int iRMIRegistryPort, int iRMIStubPort, 
+                       Integer[] iCallbackPorts, OutputStream outStream, InputStream inStream) throws IOException {
+
+               sendCommCode(IoTCommCode.GET_IOTSET_OBJECT, outStream, inStream);
+               RuntimeOutput.print("IoTSlave: Getting IoTSet object content...", BOOL_VERBOSE);
+               // Send info
+               RuntimeOutput.print("IoTSlave: Send host address: " + strIoTSlaveHostAddress, BOOL_VERBOSE);
+               sendString(strIoTSlaveHostAddress, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Driver object name: " + strObjectName, BOOL_VERBOSE);
+               sendString(strObjectName, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Driver object class name: " + strObjectClassName, BOOL_VERBOSE);
+               sendString(strObjectClassName, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Driver object interface name: " + strObjectClassInterfaceName, BOOL_VERBOSE);
+               sendString(strObjectClassInterfaceName, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Driver object stub class name: " + strObjectStubClassInterfaceName + STR_STUB_CLASS_SUFFIX, BOOL_VERBOSE);
+               sendString(strObjectStubClassInterfaceName + STR_STUB_CLASS_SUFFIX, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Driver object registry port: " + iRMIRegistryPort, BOOL_VERBOSE);
+               sendInteger(iRMIRegistryPort, outStream); recvAck(inStream);
+               RuntimeOutput.print("IoTSlave: Driver object stub port: " + iRMIStubPort, BOOL_VERBOSE);
+               sendInteger(iRMIStubPort, outStream); recvAck(inStream);
+               sendInteger(iCallbackPorts.length, outStream); recvAck(inStream);
+               for(Integer i : iCallbackPorts) {
+                       sendInteger(i, outStream); recvAck(inStream);
+               }
+       }
+
+
+       /**
+        * Reinitialize IoTRelation field for C++
+        */
+       private void reinitializeIoTRelationFieldCpp(OutputStream outStream, InputStream inStream) throws IOException {
+
+               RuntimeOutput.print("IoTSlave: About to Reinitialize IoTRelation field!", BOOL_VERBOSE);
+               sendCommCode(IoTCommCode.REINITIALIZE_IOTRELATION_FIELD, outStream, inStream);
+               RuntimeOutput.print("IoTSlave: Reinitialize IoTRelation field!", BOOL_VERBOSE);
+       }
+
+
+       /**
+        * Reinitialize IoTSet field for C++
+        */
+       private void reinitializeIoTSetFieldCpp(OutputStream outStream, InputStream inStream) throws IOException {
+
+               RuntimeOutput.print("IoTSlave: About to Reinitialize IoTSet field!", BOOL_VERBOSE);
+               sendCommCode(IoTCommCode.REINITIALIZE_IOTSET_FIELD, outStream, inStream);
+               RuntimeOutput.print("IoTSlave: Reinitialize IoTSet field!", BOOL_VERBOSE);
+       }
+
+
+       /**
+        * Invoke init() for C++
+        */
+       private void invokeInitMethodCpp(OutputStream outStream, InputStream inStream) throws IOException {
+
+               sendCommCode(IoTCommCode.INVOKE_INIT_METHOD, outStream, inStream);
+               RuntimeOutput.print("IoTSlave: Invoke init method!", BOOL_VERBOSE);
+       }
+
+
+       /**
+        * End session for C++
+        */
+       public void endSessionCpp(OutputStream outStream) throws IOException {
+
+               // Send message to end session
+               IoTCommCode endSessionCode = IoTCommCode.END_SESSION;
+               int intCode = endSessionCode.ordinal();
+               sendInteger(intCode, outStream);
+               //RuntimeOutput.print("IoTSlave: Send request to create a main object: " + strObjName, BOOL_VERBOSE);
+               RuntimeOutput.print("IoTSlave: Send request to end session!", BOOL_VERBOSE);
+       }
+
+
        /**
         * A method to assign objects to multiple JVMs, including
         * the controller/device object that uses other objects
@@ -1387,22 +1915,29 @@ public class IoTMaster {
                                        strIoTSlaveControllerHostAdd, STR_TCP_PROTOCOL, commHan.getComPort(strObjControllerName));
 
                                // Construct ssh command line and create a controller thread for e.g. AcmeProximity
-                               String strSSHCommand = STR_SSH_USERNAME + strIoTSlaveControllerHostAdd + " cd " +
-                                       STR_RUNTIME_DIR + " sudo java " + STR_JVM_INIT_HEAP_SIZE + " " + 
-                                       STR_JVM_MAX_HEAP_SIZE + " " + STR_CLS_PATH + " " +
-                                       STR_RMI_PATH + " " + STR_IOT_SLAVE_CLS + " " + strIoTMasterHostAdd + " " +
-                                       commHan.getComPort(strObjControllerName) + " " +
-                                       commHan.getRMIRegPort(strObjControllerName) + " " +
-                                       commHan.getRMIStubPort(strObjControllerName) + " >& " +
-                                       STR_LOG_FILE_PATH + strObjControllerName + ".log &";
+                               String strSSHCommand = null;
+                               if(STR_LANGUAGE.equals(STR_JAVA))
+                                       strSSHCommand = getCmdJavaIoTSlave(strObjControllerName);
+                               else if(STR_LANGUAGE.equals(STR_CPP))
+                                       strSSHCommand = getCmdCppIoTSlave(strObjControllerName);
+                               else
+                                       throw new Error("IoTMaster: Language specification not recognized: " + STR_LANGUAGE);
                                RuntimeOutput.print(strSSHCommand, BOOL_VERBOSE);
                                createThread(strSSHCommand);
                                // Wait for connection
                                // Create a new socket for communication
                                ServerSocket serverSocket = new ServerSocket(commHan.getComPort(strObjControllerName));
                                Socket socket = serverSocket.accept();
-                               ObjectInputStream inStream = new ObjectInputStream(socket.getInputStream());
-                               ObjectOutputStream outStream = new ObjectOutputStream(socket.getOutputStream());
+                               InputStream inStream = null;
+                               OutputStream outStream = null;
+                               if(STR_LANGUAGE.equals(STR_JAVA)) {
+                                       inStream = new ObjectInputStream(socket.getInputStream());
+                                       outStream = new ObjectOutputStream(socket.getOutputStream());
+                               } else {        // At this point the language is certainly C++, otherwise would've complained above
+                                       inStream = new BufferedInputStream(socket.getInputStream());
+                                       outStream = new BufferedOutputStream(socket.getOutputStream());
+                                       recvAck(inStream);
+                               }
                                RuntimeOutput.print("IoTMaster: Communication established!", BOOL_VERBOSE);
 
                                // PROFILING
@@ -1422,10 +1957,12 @@ public class IoTMaster {
                                        // Create main controller/device object
                                        commMasterToSlave(new MessageCreateMainObject(IoTCommCode.CREATE_MAIN_OBJECT, strObjControllerName),
                                                "Create main object!", inStream, outStream);
-                               } else if(STR_LANGUAGE.equals(STR_CPP))
-                                       ;
-                               else
-                                       throw new Error("IoTMaster: Language specification not recognized: " + STR_LANGUAGE);
+                               } else {
+                                       String strControllerZipFile = strObjControllerName + STR_ZIP_FILE_EXT;
+                                       String strControllerFilePath = STR_CONT_PATH + strObjControllerName + "/";
+                                       sendFileToCppSlave(strControllerFilePath, strControllerZipFile);
+                                       createMainObjectCpp(strObjControllerName, outStream, inStream);
+                               }
 
                                // PROFILING
                                result = System.currentTimeMillis()-start;
@@ -1528,7 +2065,7 @@ public class IoTMaster {
                                if(STR_LANGUAGE.equals(STR_JAVA))
                                        initializeSetsAndRelationsJava(inStream, outStream);
                                else
-                                       ;
+                                       initializeSetsAndRelationsCpp(inStream, outStream);;
 
                                // PROFILING
                                result = System.currentTimeMillis()-start;
@@ -1536,15 +2073,15 @@ public class IoTMaster {
 
                                if(STR_LANGUAGE.equals(STR_JAVA))
                                        // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO EXECUTE INIT METHOD
-                                       commMasterToSlave(new MessageSimple(IoTCommCode.INVOKE_INIT_METHOD),
-                                               "Invoke init() method!", inStream, outStream);
+                                       commMasterToSlave(new MessageSimple(IoTCommCode.INVOKE_INIT_METHOD), "Invoke init() method!", inStream, outStream);
                                else
-                                       ;
+                                       invokeInitMethodCpp(outStream, inStream);
                                // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO END PROCESS
-                               if(STR_LANGUAGE.equals(STR_JAVA))
-                                       outStream.writeObject(new MessageSimple(IoTCommCode.END_SESSION));
-                               else
-                                       ;
+                               if(STR_LANGUAGE.equals(STR_JAVA)) {
+                                       ObjectOutputStream oStream = (ObjectOutputStream) outStream;
+                                       oStream.writeObject(new MessageSimple(IoTCommCode.END_SESSION));
+                               } else  // C++ side will wait until the program finishes, it's not generating a separate thread for now
+                                       //endSessionCpp(outStream);
                                outStream.close();
                                inStream.close();
                                socket.close();