From: rtrimana Date: Thu, 29 Mar 2018 22:04:34 +0000 (-0700) Subject: Cleaning up C++ slave. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iot2.git;a=commitdiff_plain;h=39563ab07eb793e7be02984f6ab5604f82bfc0c4 Cleaning up C++ slave. --- diff --git a/iotjava/Makefile b/iotjava/Makefile index 16d9e07..6ca70c7 100644 --- a/iotjava/Makefile +++ b/iotjava/Makefile @@ -3,7 +3,7 @@ BASE := .. include $(BASE)/common.mk -all: mkdir tree parser compiler rmi runtime installer +all: mkdir tree parser compiler rmi runtime runtime-cpp installer infra: runtime installer @@ -11,6 +11,11 @@ PHONY += mkdir mkdir: [ -d ../bin ] || mkdir ../bin +# C++ slave +PHONY += runtime-cpp +runtime-cpp: + cd iotruntime/cpp/iotslave; make cpp + # Parser compilation and run PHONY += tree tree: diff --git a/iotjava/iotruntime/cpp/iotslave/IoTCommCode.java b/iotjava/iotruntime/cpp/iotslave/IoTCommCode.java deleted file mode 100644 index 3c456cb..0000000 --- a/iotjava/iotruntime/cpp/iotslave/IoTCommCode.java +++ /dev/null @@ -1,30 +0,0 @@ -/** Class IoTCommCode is a place to keep all the necessary - * enumerations for communication - * - * @author Rahmadi Trimananda - * @version 1.0 - * @since 2016-02-19 - */ - -// Enumeration of master-slave communication codes -public enum IoTCommCode { - - ACKNOWLEDGED, - CREATE_OBJECT, - CREATE_MAIN_OBJECT, - CREATE_NEW_IOTSET, - CREATE_NEW_IOTRELATION, - END_TRANSFER, - END_SESSION, - GET_ADD_IOTSET_OBJECT, - GET_DEVICE_IOTSET_OBJECT, - GET_IOTSET_OBJECT, - GET_IOTRELATION_FIRST_OBJECT, - GET_IOTRELATION_SECOND_OBJECT, - GET_ZB_DEV_IOTSET_OBJECT, - INVOKE_INIT_METHOD, - REINITIALIZE_IOTSET_FIELD, - REINITIALIZE_IOTRELATION_FIELD, - TRANSFER_FILE, -} - diff --git a/iotjava/iotruntime/cpp/iotslave/IoTSlave.cpp b/iotjava/iotruntime/cpp/iotslave/IoTSlave.cpp index 89d9997..e0ebcd8 100644 --- a/iotjava/iotruntime/cpp/iotslave/IoTSlave.cpp +++ b/iotjava/iotruntime/cpp/iotslave/IoTSlave.cpp @@ -5,7 +5,6 @@ IoTSlave::IoTSlave(string _serverAddress, int _serverPort, string _objectName) { - //isDriverObject = false; // Default to false serverAddress = _serverAddress; serverPort = _serverPort; objectName = _objectName; @@ -117,7 +116,7 @@ char* IoTSlave::recvFileIter(char* recvBuffer, int recvLen) { void IoTSlave::openFile(string fileName) { - log.open(FILEPATH + fileName + FILEEXT); + log.open(LOGFILEPATH + fileName + FILEEXT); } @@ -203,6 +202,7 @@ void IoTSlave::instantiateMainObject() { objMainCls = create_object(params); writeToFile("Object created for " + mainObjectName); init_object(objMainCls); + // TODO: Maybe we want to change this into multithreading at some point //thread th1 (&IoTSlave::runInitObject, this, this); //th1.detach(); //thread th1 (&IoTSlave::runInitObject, this, this); @@ -308,7 +308,6 @@ 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; @@ -341,7 +340,6 @@ 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); @@ -365,7 +363,6 @@ void IoTSlave::unzipFile(string fileName) { // TODO: perhaps we need to replace this with libzip or zlib later writeToFile("Unzipping file!"); string chmodCmd = FILEPATH + fileName + SHELL; - //std::system(chmodCmd.c_str()); thread th1 (std::system, chmodCmd.c_str()); th1.detach(); writeToFile("Finished unzipping file!"); @@ -391,9 +388,6 @@ string IoTSlave::recvFile() { fileStream.write(recvFil, fileLen); delete[] recvFil; fileStream.close(); - // TODO: Experimental - //string chmodCmd = FILEPATH + fileName + SHELL; - //execv(chmodCmd.c_str(), 0); return fileName; } @@ -464,8 +458,6 @@ void IoTSlave::getDeviceIoTSetObject() { isetObject->insert(objDeviceAddress); writeToFile("=> Inserting IoTDeviceAddress into set..."); writeToFile("==> Now we have " + to_string(isetObject->size()) + " object(s)!"); - // Set flag to true; - //isDriverObject = true; } @@ -683,6 +675,7 @@ void IoTSlave::commIoTMaster() { break; case GET_ZB_DEV_IOTSET_OBJECT: + // TODO: Support ZigBee in the future //getZBDevIoTSetObject(); break; diff --git a/iotjava/iotruntime/cpp/iotslave/IoTSlave.hpp b/iotjava/iotruntime/cpp/iotslave/IoTSlave.hpp index 9024bce..bbac398 100644 --- a/iotjava/iotruntime/cpp/iotslave/IoTSlave.hpp +++ b/iotjava/iotruntime/cpp/iotslave/IoTSlave.hpp @@ -61,6 +61,7 @@ class IoTSlave final { const static int RCVBUFSIZE = 1024; // Size of receive buffer const static int SKELPARAMSIZE = 3; // Number of params for skeleton const static int STUBPARAMSIZE = 5; // Number of params for stub + const static string LOGFILEPATH; // Log file path const static string FILEPATH; // File path const static string FILEEXT; // File extension const static string SOEXT; // Shared object (.so) extension @@ -161,6 +162,7 @@ class IoTSlave final { }; // Constant initialization +const string IoTSlave::LOGFILEPATH = "../log/"; const string IoTSlave::FILEPATH = "./"; const string IoTSlave::FILEEXT = "_cpp.log"; const string IoTSlave::SOEXT = ".so"; diff --git a/iotjava/iotruntime/cpp/iotslave/IoTSlave.java b/iotjava/iotruntime/cpp/iotslave/IoTSlave.java deleted file mode 100644 index 02678c1..0000000 --- a/iotjava/iotruntime/cpp/iotslave/IoTSlave.java +++ /dev/null @@ -1,494 +0,0 @@ -import java.util.*; -import java.io.*; -import java.net.*; -import java.nio.*; -import static java.lang.Math.toIntExact; - -public class IoTSlave { - - private ServerSocket serverSocket; - private Socket socket; - private BufferedInputStream input; - private BufferedOutputStream output; - - private static final String STR_LOCALHOST = "localhost"; - private static final String STR_IOTSLAVE_CPP = "./IoTSlave.o"; - private static final String STR_IOTSLAVE_PATH = "~/tmp/iot2/iotjava/iotruntime/cpp/iotslave/"; - - //private static final String STR_LOG_FILE_PATH = "./"; - private static int INT_SIZE = 4; // send length in the size of integer (4 bytes) - - - public IoTSlave() { - - serverSocket = null; - socket = null; - input = null; - output = null; - } - - - /** - * Prepare server socket connection with C++ IoTSlave - */ - public void setServerSocketCpp(int iPort) { - - try { - serverSocket = new ServerSocket(iPort); - } - catch ( IOException e ) { - e.printStackTrace(); - } - } - - - /** - * A method to send files from IoTMaster - * - * @param filesocket File socket object - * @param sFileName File name - * @param lFLength File length - * @return void - */ - private void sendFile(Socket filesocket, String sFileName, long lFLength) throws IOException { - - File file = new File(sFileName); - byte[] bytFile = new byte[toIntExact(lFLength)]; - InputStream inFileStream = new FileInputStream(file); - - OutputStream outFileStream = filesocket.getOutputStream(); - int iCount; - while ((iCount = inFileStream.read(bytFile)) > 0) { - outFileStream.write(bytFile, 0, iCount); - } - filesocket.close(); - } - - - private void sendFile(String sFilePath, String sFileName) throws IOException { - - sendCommCode(IoTCommCode.TRANSFER_FILE); - // Send file name - sendString(sFileName); recvAck(); - File file = new File(sFilePath + sFileName); - int iFileLen = toIntExact(file.length()); - System.out.println("IoTSlave: Sending file " + sFileName + " with length " + iFileLen + " bytes..."); - // Send file length - sendInteger(iFileLen); recvAck(); - byte[] bytFile = new byte[iFileLen]; - InputStream inFileStream = new FileInputStream(file); - - OutputStream outFileStream = socket.getOutputStream(); - int iCount; - while ((iCount = inFileStream.read(bytFile)) > 0) { - outFileStream.write(bytFile, 0, iCount); - } - System.out.println("IoTSlave: File sent!"); - recvAck(); - } - - /** - * sendInteger() sends an integer in bytes - */ - public void sendInteger(int intSend) throws IOException { - - // 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() throws IOException { - - // 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() throws IOException { - - int strLen = recvInteger(); - // 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) throws IOException { - - // Transform String into bytes - byte[] strSendBytes = strSend.getBytes(); - int strLen = strSend.length(); - // Send the string length first - sendInteger(strLen); - // Send the byte array - output.write(strSendBytes, 0, strLen); - output.flush(); - } - - - /** - * Establish connection with C++ IoTSlave - */ - public void connectCpp() throws IOException { - - socket = serverSocket.accept(); - input = new BufferedInputStream(socket.getInputStream()); - output = new BufferedOutputStream(socket.getOutputStream()); - } - - - /** - * Construct a SSH command to run C++ program - */ - public static String constructCommand(String serverAddress, int serverPort, String strObjName) { - - String strCommand = "ssh rtrimana@localhost cd " + STR_IOTSLAVE_PATH + "; " + - STR_IOTSLAVE_CPP + " " + serverAddress + " " + serverPort + " " + strObjName; - return strCommand; - } - - - /** - * Create a new thread to start a new C++ process - */ - public static void createCppThread(String strCmd) { - - Thread thread = new Thread(new Runnable() { - public void run() { - try { - Runtime runtime = Runtime.getRuntime(); - Process process = runtime.exec(strCmd); - } catch(IOException ex) { - ex.printStackTrace(); - } - } - }); - thread.start(); - //RuntimeOutput.print("IoTSlave: Executing: " + strCmd, BOOL_VERBOSE); - System.out.println("IoTSlave: Executing: " + strCmd); - } - - - /** - * 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() throws IOException { - - int intAck = recvInteger(); - IoTCommCode codeAck = getCode(intAck); - if (codeAck == IoTCommCode.ACKNOWLEDGED) - return true; - return false; - - } - - - /** - * Send END - */ - public void sendEndTransfer() throws IOException { - - int endCode = IoTCommCode.END_TRANSFER.ordinal(); - sendInteger(endCode); - } - - - /** - * Send communication code to C++ - */ - public void sendCommCode(IoTCommCode inpCommCode) throws IOException { - - - IoTCommCode commCode = inpCommCode; - int intCode = commCode.ordinal(); - sendInteger(intCode); recvAck(); - } - - - /** - * Create a main controller object for C++ - */ - public void createMainObjectCpp() throws IOException { - - sendCommCode(IoTCommCode.CREATE_MAIN_OBJECT); - String strMainObjName = "Lifxtest"; - sendString(strMainObjName); recvAck(); - System.out.println("IoTSlave: Create a main object: " + strMainObjName); - } - - - /** - * Create a driver object for C++ - */ - public void createObjectCpp() throws IOException { - - sendCommCode(IoTCommCode.CREATE_OBJECT); - String strDrvObjName = "LifxLightBulbLB2"; - String strDrvObjClsName = "LifxLightBulb"; - String strDrvObjIntfaceClsName = "LightBulb"; - String strDrvObjSkelClsName = "LightBulb_Skeleton"; - int iRegPort = 30313; - int iStubPort = 55179; - // TODO: On the actual slave we need to do conversion back to string before we send everything to C++ IoTSlave - // TODO: Make it as array of string - //String[] arrCppArgs = { "D073D50241DA0000" }; - String[] arrCppArgs = { "D073D5128E300000" }; - String[] arrCppArgClasses = { "string" }; - System.out.println("IoTSlave: Send request to create a driver object... "); - System.out.println("IoTSlave: Driver object name: " + strDrvObjName); - sendString(strDrvObjName); recvAck(); - System.out.println("IoTSlave: Driver object class name: " + strDrvObjClsName); - sendString(strDrvObjClsName); recvAck(); - System.out.println("IoTSlave: Driver object interface name: " + strDrvObjIntfaceClsName); - sendString(strDrvObjIntfaceClsName); recvAck(); - System.out.println("IoTSlave: Driver object skeleton class name: " + strDrvObjSkelClsName); - sendString(strDrvObjSkelClsName); recvAck(); - System.out.println("IoTSlave: Driver object registry port: " + iRegPort); - sendInteger(iRegPort); recvAck(); - System.out.println("IoTSlave: Driver object stub port: " + iStubPort); - sendInteger(iStubPort); recvAck(); - int numOfArgs = arrCppArgs.length; - System.out.println("IoTSlave: Send constructor arguments! Number of arguments: " + numOfArgs); - sendInteger(numOfArgs); recvAck(); - for(String str : arrCppArgs) { - sendString(str); recvAck(); - } - System.out.println("IoTSlave: Send constructor argument classes!"); - for(String str : arrCppArgClasses) { - sendString(str); recvAck(); - } - } - - - /** - * Create new IoTSet for C++ - */ - //public void createNewIoTSetCpp() throws IOException { - public void createNewIoTSetCpp(String strObjFieldName) throws IOException { - - sendCommCode(IoTCommCode.CREATE_NEW_IOTSET); - System.out.println("IoTSlave: Creating new IoTSet..."); - //String strObjFieldName = "lb_addresses"; - System.out.println("IoTSlave: Send object field name: " + strObjFieldName); - sendString(strObjFieldName); recvAck(); - } - - - /** - * Get a IoTDeviceAddress object for C++ - */ - public void getDeviceIoTSetObjectCpp() throws IOException { - - sendCommCode(IoTCommCode.GET_DEVICE_IOTSET_OBJECT); - System.out.println("IoTSlave: Getting IoTDeviceAddress..."); - //String strHostAddress = "192.168.2.232"; - String strHostAddress = "192.168.2.126"; - sendString(strHostAddress); recvAck(); - int iSourcePort = 43583; - sendInteger(iSourcePort); recvAck(); - int iDestPort = 56700; - sendInteger(iDestPort); recvAck(); - boolean bSourceWildCard = false; - int iSourceWildCard = (bSourceWildCard ? 1 : 0); - sendInteger(iSourceWildCard); recvAck(); - boolean bDestWildCard = false; - int iDestWildCard = (bDestWildCard ? 1 : 0); - sendInteger(iDestWildCard); recvAck(); - System.out.println("IoTSlave: Send host address: " + strHostAddress); - } - - - /** - * Get a IoTSet content object for C++ - */ - public void getIoTSetObjectCpp() throws IOException { - - sendCommCode(IoTCommCode.GET_IOTSET_OBJECT); - System.out.println("IoTSlave: Getting IoTSet object content..."); - String strHostAddress = "localhost"; - String strDrvObjName = "LifxLightBulbLB2"; - String strDrvObjClsName = "LifxLightBulb"; - String strDrvObjIntfaceClsName = "LightBulb"; - String strDrvObjStubClsName = "LightBulbTest_Stub"; // Send a complete name with "_Stub" - int iRegPort = 30313; - int iStubPort = 55179; - int[] callbackPorts = { 58551 }; - // Send info - System.out.println("IoTSlave: Send host address: " + strHostAddress); - sendString(strHostAddress); recvAck(); - System.out.println("IoTSlave: Driver object name: " + strDrvObjName); - sendString(strDrvObjName); recvAck(); - System.out.println("IoTSlave: Driver object class name: " + strDrvObjClsName); - sendString(strDrvObjClsName); recvAck(); - System.out.println("IoTSlave: Driver object interface name: " + strDrvObjIntfaceClsName); - sendString(strDrvObjIntfaceClsName); recvAck(); - System.out.println("IoTSlave: Driver object skeleton class name: " + strDrvObjStubClsName); - sendString(strDrvObjStubClsName); recvAck(); - System.out.println("IoTSlave: Driver object registry port: " + iRegPort); - sendInteger(iRegPort); recvAck(); - System.out.println("IoTSlave: Driver object stub port: " + iStubPort); - sendInteger(iStubPort); recvAck(); - sendInteger(callbackPorts.length); recvAck(); - for(int i : callbackPorts) { - sendInteger(i); recvAck(); - } - - } - - - /** - * Reinitialize IoTSet field for C++ - */ - private void reinitializeIoTSetFieldCpp() throws IOException { - - System.out.println("IoTSlave: About to Reinitialize IoTSet field!"); - sendCommCode(IoTCommCode.REINITIALIZE_IOTSET_FIELD); - System.out.println("IoTSlave: Reinitialize IoTSet field!"); - } - - - /** - * Invoke init() for C++ - */ - private void invokeInitMethodCpp() throws IOException { - - sendCommCode(IoTCommCode.INVOKE_INIT_METHOD); - System.out.println("IoTSlave: Invoke init method!"); - } - - - /** - * End session for C++ - */ - public void endSessionCpp() throws IOException { - - // Send message to end session - IoTCommCode endSessionCode = IoTCommCode.END_SESSION; - int intCode = endSessionCode.ordinal(); - sendInteger(intCode); - //RuntimeOutput.print("IoTSlave: Send request to create a main object: " + strObjName, BOOL_VERBOSE); - System.out.println("IoTSlave: Send request to end session!"); - } - - - public static void main(String[] args) throws IOException, InterruptedException { - - /*int iPort = 12345; - IoTSlave iotSlave = new IoTSlave(); - iotSlave.setServerSocketCpp(iPort); - iotSlave.connectCpp(); - System.out.println("Connection established with client!"); - iotSlave.sendInteger(1234); - System.out.println("Integer sent!"); - System.out.println("Integer received: " + iotSlave.recvInteger()); - String strRecv = iotSlave.recvString(); - System.out.println("Received string: " + strRecv); - strRecv = strRecv + " - ACKNOWLEDGED!"; - System.out.println("Sending back string: " + strRecv); - iotSlave.sendString(strRecv);*/ - - // ========================================= - // Create IoTSlave for controller object! - int iPortMain =12346; - String strAddressMain = "localhost"; - String strObjNameMain = "Lifxtest"; - IoTSlave iotSlaveMain = new IoTSlave(); - iotSlaveMain.setServerSocketCpp(iPortMain); - // Run thread to spawn C++ IoTSlave - String strCmdMain = iotSlaveMain.constructCommand(strAddressMain, iPortMain, strObjNameMain); - iotSlaveMain.createCppThread(strCmdMain); - iotSlaveMain.connectCpp(); - System.out.println("IoTSlave: Connection established with main!"); - // First contact with C++ IoTSlave - System.out.println("IoTSlave: IoTSlave.o main is ready: " + iotSlaveMain.recvAck()); - //iotSlaveMain.sendFile("../", "Lifxtest.so"); - //iotSlaveMain.sendFile("../", "LightBulbTest_Stub.so"); - //iotSlaveMain.sendFile("../", "Lifxtest.zip"); - //iotSlaveMain.sendFile("../resources/", "Lifxtest.jar"); - //iotSlaveMain.sendFile("../", "unzip.zip"); - - - // ========================================= - // Create IoTSlave for driver object! - int iPort =12345; - String strAddress = "localhost"; - String strObjName = "LifxLightBulbLB2"; - IoTSlave iotSlave = new IoTSlave(); - iotSlave.setServerSocketCpp(iPort); - // Run thread to spawn C++ IoTSlave - String strCmd = IoTSlave.constructCommand(strAddress, iPort, strObjName); - IoTSlave.createCppThread(strCmd); - iotSlave.connectCpp(); - //RuntimeOutput.print("IoTSlave: Connection established!", BOOL_VERBOSE); - System.out.println("IoTSlave: Connection established!"); - // First contact with C++ IoTSlave - System.out.println("IoTSlave: IoTSlave.o is ready: " + iotSlave.recvAck()); - //iotSlave.sendFile("../", "LifxLightBulb.so"); - //iotSlave.sendFile("../", "LightBulb_Skeleton.so"); - //iotSlave.sendFile("../", "LifxLightBulb.zip"); - //iotSlave.sendFile("../", "unzip2.zip"); - iotSlave.createObjectCpp(); - //iotSlave.createNewIoTSetCpp(); - iotSlave.createNewIoTSetCpp("lb_addresses"); - iotSlave.getDeviceIoTSetObjectCpp(); - iotSlave.reinitializeIoTSetFieldCpp(); - //iotSlave.endSessionCpp(); - - // ========================================= - // Continue with main object - iotSlaveMain.createMainObjectCpp(); - iotSlaveMain.createNewIoTSetCpp("lifx_light_bulb"); - iotSlaveMain.getIoTSetObjectCpp(); - iotSlaveMain.reinitializeIoTSetFieldCpp(); - iotSlaveMain.invokeInitMethodCpp(); - iotSlaveMain.endSessionCpp(); - - // Send message to create a main object - /*commCode = IoTCommCode.CREATE_MAIN_OBJECT; - intCode = commCode.ordinal(); - iotSlave.sendInteger(intCode); - //RuntimeOutput.print("IoTSlave: Send request to create a main object: " + strObjName, BOOL_VERBOSE); - System.out.println("IoTSlave: Send request to create a main object: " + strObjName); - //RuntimeOutput.print("IoTSlave: IoTSlave.o is ready: " + strAck, BOOL_VERBOSE); - System.out.println("IoTSlave: IoTSlave.o is ready: " + strAck);*/ - - //Thread.sleep(1000); - - } -} diff --git a/iotjava/iotruntime/cpp/iotslave/LifxLightBulb.so b/iotjava/iotruntime/cpp/iotslave/LifxLightBulb.so deleted file mode 100755 index e69de29..0000000 diff --git a/iotjava/iotruntime/cpp/iotslave/Lifxtest.so b/iotjava/iotruntime/cpp/iotslave/Lifxtest.so deleted file mode 100755 index 8827d7d..0000000 Binary files a/iotjava/iotruntime/cpp/iotslave/Lifxtest.so and /dev/null differ diff --git a/iotjava/iotruntime/cpp/iotslave/LightBulbTest_Stub.so b/iotjava/iotruntime/cpp/iotslave/LightBulbTest_Stub.so deleted file mode 100755 index 83d8d6d..0000000 Binary files a/iotjava/iotruntime/cpp/iotslave/LightBulbTest_Stub.so and /dev/null differ diff --git a/iotjava/iotruntime/cpp/iotslave/LightBulb_Skeleton.so b/iotjava/iotruntime/cpp/iotslave/LightBulb_Skeleton.so deleted file mode 100755 index 42ed05f..0000000 Binary files a/iotjava/iotruntime/cpp/iotslave/LightBulb_Skeleton.so and /dev/null differ diff --git a/iotjava/iotruntime/cpp/iotslave/Makefile b/iotjava/iotruntime/cpp/iotslave/Makefile index 80cecbb..3391b1f 100755 --- a/iotjava/iotruntime/cpp/iotslave/Makefile +++ b/iotjava/iotruntime/cpp/iotslave/Makefile @@ -7,33 +7,19 @@ GCCFLAGS = -std=c++11 -pthread -pg INCLUDE = -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/ -I$(BASE)/iotjava/iotruntime/cpp/socket/ -I$(BASE)/iotjava/iotruntime/cpp/setrelation/ -I$(BASE)/iotjava/iotrmi/C++/ -I$(BASE)/benchmarks/virtuals/ -I$(BASE)/benchmarks/drivers/Cpp/LifxLightBulb -I$(BASE)/benchmarks/drivers/Cpp/LabRoom -I$(BASE)/benchmarks/Cpp/Lifxtest/ CCCLINKERFLAGS = -ldl -all: java cpp - -PHONY += java -java: - javac *.java +all: cpp PHONY += cpp cpp: $(G++) $(GCCFLAGS) -o IoTSlave.o IoTSlave.cpp $(INCLUDE) $(CCCLINKERFLAGS) cp IoTSlave.o $(BASE)/bin/iotruntime/slave/ + rm -rf IoTSlave.o PHONY += cpp-arm cpp-arm: $(ARM_G++) $(GCCFLAGS) -o IoTSlave.o IoTSlave.cpp $(INCLUDE) $(CCCLINKERFLAGS) cp IoTSlave.o $(BASE)/bin/iotruntime/slave/ - -PHONY += cpp-test -cpp-test: - $(G++) $(GCCFLAGS) -o SetRelationTest.o SetRelationTest.cpp $(INCLUDE) $(CCCLINKERFLAGS) - -PHONY += run -run: - java IoTSlave - -PHONY += readlog -readlog: - cat *.log + rm -rf IoTSlave.o PHONY += clean clean: @@ -43,8 +29,6 @@ clean: rm -rf gmon.out rm -rf *.zip rm -rf *.jar - #rm -rf *.so - pkill IoTSlave PHONY += kill kill: diff --git a/iotjava/iotruntime/cpp/iotslave/ObjectFactory.hpp b/iotjava/iotruntime/cpp/iotslave/ObjectFactory.hpp deleted file mode 100644 index 4ed07a7..0000000 --- a/iotjava/iotruntime/cpp/iotslave/ObjectFactory.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "LifxLightBulb.cpp" -#include "LightBulb_Skeleton.cpp" -#include "LightBulbTest_Stub.cpp" -#include "IoTSet.hpp" - - -//typedef void* create_t(string className, void** params); -//typedef void destroy_t(void*); - - -// Transferring members of IoTSet into IoTSet -IoTSet* createDeviceAddressSet(unordered_set* iotSet) { - - unordered_set* devSet = new unordered_set(); - //for (auto itr = iotSet->begin(); itr != iotSet->end(); ++itr) { - for (unordered_set::const_iterator itr = iotSet->begin(); itr != iotSet->end(); ++itr) { - IoTDeviceAddress* deviceAddress = (IoTDeviceAddress*) *itr; - devSet->insert(deviceAddress); - } - IoTSet* iotDevSet = new IoTSet(devSet); - - delete iotSet; - return iotDevSet; -} - - -/* -// External creator/destroyer -extern "C" void* create(string className, void** params) { - - if (className.compare("LifxLightBulb") == 0) { - // Arguments: IoTSet* _devAddress, string macAddress - // We pass in a pointer to string and then we pass in just the value for the class - return new LifxLightBulb((IoTSet*) params[0], *((string*) params[1])); - } else if (className.compare("LightBulb_Skeleton") == 0) { - // Arguments: LightBulb *_mainObj, string _callbackAddress, int _port - // We pass in pointers to string and integer, and read the values again - return new LightBulb_Skeleton((LightBulb*) params[0], *((string*) params[1]), *((int*) params[2])); - } else if (className.compare("LightBulbTest_Stub") == 0) { - // int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector _ports - // We pass in pointers to string and integer, and read the values again - return new LightBulbTest_Stub(*((int*) params[0]), (const char*) params[1], *((string*) params[2]), *((int*) params[3]), - (bool*) params[4], *((vector*) params[5])); - } else { // Class is not recognized - cerr << "ObjectFactory: Class is not recognized: " << className << endl; - exit(1); - } -} - -extern "C" void destroy(string className, void* ob) { - - if (ob != NULL) { // Check that this pointer is not NULL - - if (className.compare("LifxLightBulb") == 0) { - LifxLightBulb* obj = (LifxLightBulb*) ob; - delete obj; - } else if (className.compare("LightBulb_Skeleton") == 0) { - LightBulb_Skeleton* obj = (LightBulb_Skeleton*) ob; - delete obj; - } else if (className.compare("LightBulbTest_Stub") == 0) { - LightBulbTest_Stub* obj = (LightBulbTest_Stub*) ob; - delete obj; - } else { // Class is not recognized - cerr << "ObjectFactory: Class is not recognized: " << className << endl; - exit(1); - } - } -} -*/ - diff --git a/iotjava/iotruntime/cpp/iotslave/SetRelationTest.cpp b/iotjava/iotruntime/cpp/iotslave/SetRelationTest.cpp deleted file mode 100644 index 36769a5..0000000 --- a/iotjava/iotruntime/cpp/iotslave/SetRelationTest.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include "IoTSet.hpp" -#include "IoTRelation.hpp" - -using namespace std; - -int main () -{ - unordered_set myset = { "red","green","blue" }; - - IoTSet iotset(&myset); - - unordered_set::const_iterator got = iotset.find ("red"); - - if ( got == iotset.end() ) - cout << "not found in myset" << endl; - else - cout << *got << " is in myset" << endl; - - cout << "size: " << iotset.size() << endl; - - unordered_multimap mymap = { - {"mom","church"}, - {"mom","college"}, - {"dad","office"}, - {"bro","school"} }; - - unordered_set* retset = iotset.values(); - cout << "Returned set: " << retset->size() << endl; - retset->erase("red"); - cout << "Returned set: " << retset->size() << endl; - cout << "Original set: " << myset.size() << endl; - - //cout << "one of the values for 'mom' is: "; - //cout << mymap.find("mom")->second; - //cout << endl; - IoTRelation iotrel(&mymap); - - std::pair::const_iterator, - unordered_multimap::const_iterator> ret; - ret = iotrel.equal_range("mom"); - for (std::unordered_multimap::const_iterator it=ret.first; it!=ret.second; ++it) - cout << ' ' << it->second << endl; - - cout << "size: " << iotrel.size() << endl; - - return 0; -} diff --git a/iotjava/iotruntime/cpp/setrelation/IRelation.hpp b/iotjava/iotruntime/cpp/setrelation/IRelation.hpp deleted file mode 100644 index 17be572..0000000 --- a/iotjava/iotruntime/cpp/setrelation/IRelation.hpp +++ /dev/null @@ -1,142 +0,0 @@ -#ifndef _IRELATION_HPP__ -#define _IRELATION_HPP__ -#include -#include -#include - -using namespace std; - -/** This is the IoTRelation implementation for C++ - * - * @author Rahmadi Trimananda - * @version 1.0 - * @since 2016-09-06 - */ -template -class IRelation final { - private: - unordered_multimap* rel; - public: - IRelation(); - IRelation(unordered_multimap const* r); - ~IRelation(); - public: - typename unordered_multimap::const_iterator find(const K& k); // Find the object based on key - typename unordered_multimap::const_iterator insert(const pair& val); // Insert the object pair - bool empty(); // Test is empty? - typename unordered_multimap::const_iterator begin(); // Iterator - typename unordered_multimap::const_iterator end(); // Iterator - std::pair::const_iterator, - typename unordered_multimap::const_iterator> - equal_range(const K& k); // Equal range iterator - int size(); // Set size - unordered_multimap values(); // Return set contents -}; - - -/** - * Default constructor - */ -template -IRelation::IRelation() { - - rel = new unordered_multimap(); -} - - -/** - * Useful constructor - */ -template -IRelation::IRelation(const unordered_multimap* r) { - - rel = r; -} - - -/** - * Default destructor - */ -template -IRelation::~IRelation() { - - if (rel != NULL) - delete rel; -} - - -/** - * Find the object k in the set - */ -template -typename unordered_multimap::const_iterator IRelation::find(const K& k) { - - return rel->find(k); -} - - -/** - * Insert object k into the set - */ -template -typename unordered_multimap::const_iterator IRelation::insert(const pair& val) { - - return rel->insert(val); -} - - -/** - * Return the "begin" iterator - */ -template -typename unordered_multimap::const_iterator IRelation::begin() { - - return rel->begin(); -} - - -/** - * Return the "end" iterator - */ -template -typename unordered_multimap::const_iterator IRelation::end() { - - return rel->end(); -} - - -/** - * Return the "equal_range" iterator - */ -template -std::pair::const_iterator, - typename unordered_multimap::const_iterator> - IRelation::equal_range(const K& k) { - - return rel->equal_range(k); -} - - -/** - * Return the size of the set - */ -template -int IRelation::size() { - - return rel->size(); -} - - -/** - * Return a new copy of the set - */ -template -unordered_multimap IRelation::values() { - - return rel; -} -#endif - - - - diff --git a/iotjava/iotruntime/cpp/setrelation/ISet.hpp b/iotjava/iotruntime/cpp/setrelation/ISet.hpp deleted file mode 100644 index 5d8d295..0000000 --- a/iotjava/iotruntime/cpp/setrelation/ISet.hpp +++ /dev/null @@ -1,124 +0,0 @@ -#ifndef _ISET_HPP__ -#define _ISET_HPP__ -#include -#include -#include - -using namespace std; - -/** This is the IoTSet implementation for C++ - * - * @author Rahmadi Trimananda - * @version 1.0 - * @since 2016-09-06 - */ -template -class ISet final { - private: - unordered_set* set; - public: - ISet(); - ISet(unordered_set const* s); - ~ISet(); - public: - typename unordered_set::const_iterator find(const T& k); // Find the object - typename unordered_set::const_iterator insert(const T& k); // Insert the object - bool empty(); // Test is empty? - typename unordered_set::const_iterator begin(); // Iterator - typename unordered_set::const_iterator end(); // Iterator - int size(); // Set size - unordered_set* values(); // Return set contents -}; - - -/** - * Default constructor - */ -template -ISet::ISet() { - - set = new unordered_set(); -} - - -/** - * Useful constructor - */ -template -ISet::ISet(const unordered_set* s) { - - set = s; -} - - -/** - * Default destructor - */ -template -ISet::~ISet() { - - if (set != NULL) - delete set; -} - - -/** - * Find the object k in the set - */ -template -typename unordered_set::const_iterator ISet::find(const T& k) { - - return set->find(k); -} - - -/** - * Insert object k into the set - */ -template -typename unordered_set::const_iterator ISet::insert(const T& k) { - - return set->insert(k); -} - - -/** - * Return the "begin" iterator - */ -template -typename unordered_set::const_iterator ISet::begin() { - - return set->begin(); -} - - -/** - * Return the "end" iterator - */ -template -typename unordered_set::const_iterator ISet::end() { - - return set->end(); -} - - -/** - * Return the size of the set - */ -template -int ISet::size() { - - return set->size(); -} - - -/** - * Return a new copy of the set - */ -template -unordered_set* ISet::values() { - - return set; -} -#endif - diff --git a/iotjava/iotruntime/cpp/setrelation/Iterator.hpp b/iotjava/iotruntime/cpp/setrelation/Iterator.hpp deleted file mode 100644 index 2890af2..0000000 --- a/iotjava/iotruntime/cpp/setrelation/Iterator.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _ITERATOR_HPP__ -#define _ITERATOR_HPP__ - -#include "IoTDeviceAddress.hpp" -#include "LightBulbTest.hpp" - -namespace std -{ - template<> struct hash - { - size_t operator()(IoTDeviceAddress const& devAddress) const - { - return devAddress.hash(devAddress); - } - }; -} - - -bool operator==(const IoTDeviceAddress& lhs, const IoTDeviceAddress& rhs) { - return lhs.hash(lhs) == rhs.hash(rhs); -} - - -namespace std -{ - template<> struct hash - { - size_t operator()(LightBulbTest const& device) const - { - return device.hash(device); - } - }; -} - - -bool operator==(const LightBulbTest& lhs, const LightBulbTest& rhs) { - return lhs.hash(lhs) == rhs.hash(rhs); -} - -#endif