diff --git a/lib/xlpmg/Communicator.hpp b/lib/xlpmg/Communicator.hpp index 16bf9803..510c716c 100644 --- a/lib/xlpmg/Communicator.hpp +++ b/lib/xlpmg/Communicator.hpp @@ -14,6 +14,7 @@ #include #include #include +#include // time stamp #include @@ -222,6 +223,27 @@ namespace xlpmg return message; } + /// @brief Checks if the server responded with OK. + /// @return true if server responded + bool checkServerResponse() + { + char readBuffer[BUFF_SIZE_READ]; + memset(readBuffer, 0, BUFF_SIZE_READ); + sockValread = read(sockClient_fd, readBuffer, + BUFF_SIZE_READ - 1); // subtract 1 for the null + bool returnValue = true; + if(std::string(readBuffer).compare("OK") != 0) + returnValue = false; + + //DONE + sockValread = read(sockClient_fd, readBuffer, + BUFF_SIZE_READ - 1); // subtract 1 for the null + if(std::string(readBuffer).compare("DONE") != 0) + returnValue = false; + + return returnValue; + } + /// @brief Sends a message to the server. /// @param message String to send. int sendToServer(std::string message) @@ -253,7 +275,7 @@ namespace xlpmg logEvent(bytesSentStr.c_str(), DEBUG, true); } } - sleep(1); + send(sockClient_fd, "DONE", strlen("DONE"), MSG_NOSIGNAL); return 0; @@ -409,6 +431,7 @@ namespace xlpmg logEvent(bytesSentStr.c_str(), DEBUG, true); } } + send(new_socket, "DONE", 4, MSG_NOSIGNAL); } }; diff --git a/src/Server.cpp b/src/Server.cpp index c61a4718..c22423eb 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -68,6 +68,7 @@ int main(int i_argc, char *i_argv[]) { continue; } + json l_parsedData = json::parse(l_rawData); xlpmg::Message l_message = xlpmg::jsonToMessage(l_parsedData); xlpmg::MessageType l_type = l_message.type; @@ -89,7 +90,6 @@ int main(int i_argc, char *i_argv[]) else if (l_key == xlpmg::START_SIMULATION.key) { std::string l_config = l_parsedData.at(xlpmg::ARGS); - std::cout << m_simulationThread.joinable() << std::endl; if (!m_isSimulationRunning && !simulator->isPreparing()) { if (m_simulationThread.joinable()) @@ -179,6 +179,7 @@ int main(int i_argc, char *i_argv[]) l_writeFile.write((char *)&l_byteVector[0], l_byteVector.size()); l_writeFile.close(); simulator->setBathymetryFilePath(m_bathTempFile); + simulator->setPrepared(false); }else if (l_key == xlpmg::SET_DISPLACEMENT_DATA.key) { std::vector l_byteVector = l_args["bytes"]; @@ -186,6 +187,7 @@ int main(int i_argc, char *i_argv[]) l_writeFile.write((char *)&l_byteVector[0], l_byteVector.size()); l_writeFile.close(); simulator->setDisplacementFilePath(m_displTempFile); + simulator->setPrepared(false); } else if(l_key == xlpmg::PAUSE_SIMULATION.key) { diff --git a/src/Simulator.cpp b/src/Simulator.cpp index c511e36e..cb7039cb 100644 --- a/src/Simulator.cpp +++ b/src/Simulator.cpp @@ -271,7 +271,6 @@ void tsunami_lab::Simulator::constructSetup() m_displacementFilePath.c_str(), l_netCdfCustom, m_nx); - std::cout << "setup : " <