diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..8fe10ca --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "gdb", + "request": "launch", + "name": "Launch Program", + "target": "./build/SimControlApplication", + "cwd": "${workspaceRoot}", + "valuesFormatting": "parseText" + } + + ] +} \ No newline at end of file diff --git a/include/SimControl/SimControl.hpp b/include/SimControl/SimControl.hpp index f38e638..ae01a48 100644 --- a/include/SimControl/SimControl.hpp +++ b/include/SimControl/SimControl.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -21,15 +22,16 @@ namespace SimControl { class SimControl{ public: - SimControl(const std::string &addr,const std::int16_t port); - + SimControl( std::string addr, ushort port); + ~SimControl(); private: void MainFunction_(); + void HandleMessage(std::string msg); - std::shared_ptr TCPClient_; + std::unique_ptr TCPClient_; diff --git a/src/SimControl/SimControl.cpp b/src/SimControl/SimControl.cpp index cc393f3..97a2775 100644 --- a/src/SimControl/SimControl.cpp +++ b/src/SimControl/SimControl.cpp @@ -3,24 +3,34 @@ #include - -#include -#include #include #include -#include + namespace SimControl { - SimControl::SimControl(const std::string &addr,const std::int16_t port) + SimControl::SimControl( std::string addr, ushort port) { - TCPClient_ = std::make_shared(port,addr); + TCPClient_ = std::make_unique(port,addr); + TCPClient_->registerMessageCallback(std::bind(&SimControl::HandleMessage,this,std::placeholders::_1)); + TCPClient_->sendMessage("Hello Server"); } + SimControl::~SimControl() + { + TCPClient_ = nullptr; + } + + void SimControl::HandleMessage(std::string msg) + { + + LOG_S(INFO)< #include #include #include +#include /// variable for stopping the application bool running = true; @@ -30,14 +32,26 @@ int main() sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); + ushort port = 3500; + // SimControl::SimControl sc("127.0.0.1",5557); - SimControl::SimControl sc("127.0.0.255",8000); + + DirectCommunication::DirectCommunicationClient client(port,"127.0.0.1"); + + client.sendMessage("Hello Server"); while (running) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); + client.sendMessage("Hello Server"); + + std::string MessageString = client.getLatestMessage(); + LOG_S(INFO)<