Restarted the production of the app
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
#include "CommService/CommService.hpp"
|
||||
#include "CommService/Message.hpp"
|
||||
#include <SimControl/SimControl.hpp>
|
||||
|
||||
|
||||
@@ -15,132 +13,15 @@
|
||||
namespace SimControl {
|
||||
|
||||
|
||||
SimControl::SimControl(const std::string &addr,const std::int16_t port)
|
||||
{
|
||||
|
||||
void SimControl::start()
|
||||
{
|
||||
startMainFunction_();
|
||||
startCommService_();
|
||||
}
|
||||
TCPClient_ = std::make_shared<DirectCommunication::DirectCommunicationClient>(port,addr);
|
||||
|
||||
void SimControl::stop()
|
||||
{
|
||||
stopCommService_();
|
||||
stopMainFunction_();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SimControl::startMainFunction_(){
|
||||
|
||||
if (isMainThreadRunning_ == true)
|
||||
{
|
||||
throw std::runtime_error("Main thread already running");
|
||||
}
|
||||
|
||||
|
||||
// MainFunctionThread_ = std::make_shared<typename Tp>(Args &&args...)e
|
||||
MainFunctionThread_ = std::make_unique<std::thread>(&SimControl::MainFunction_,this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SimControl::stopMainFunction_(){
|
||||
|
||||
std::int32_t timeout = 6000;
|
||||
stopMainThread_=true;
|
||||
|
||||
|
||||
while(isMainThreadRunning_ && timeout > 0)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
timeout-=100;
|
||||
}
|
||||
if (timeout <= 0)
|
||||
{
|
||||
throw std::runtime_error("can not stop main thread");
|
||||
}
|
||||
MainFunctionThread_->join();
|
||||
LOG_S(INFO)<< "stoped main function" ;
|
||||
|
||||
}
|
||||
|
||||
void SimControl::MainFunction_()
|
||||
{
|
||||
isMainThreadRunning_=true;
|
||||
LOG_S(INFO)<< "main thread is started";
|
||||
|
||||
while(!stopMainThread_)
|
||||
{
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
isMainThreadRunning_=false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SimControl::startCommService_(){
|
||||
|
||||
|
||||
if (isCommServiceThreadRunning_ == true)
|
||||
{
|
||||
throw std::runtime_error("Comm thread already running");
|
||||
}
|
||||
|
||||
|
||||
// MainFunctionThread_ = std::make_shared<typename Tp>(Args &&args...)e
|
||||
CommServiceThread = std::make_unique<std::thread>(&SimControl::CommServiceFunction_,this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SimControl::stopCommService_(){
|
||||
|
||||
std::int32_t timeout = 6000;
|
||||
stopCommServiceThread_ = true;
|
||||
|
||||
|
||||
while(isCommServiceThreadRunning_ && timeout > 0)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
timeout-=100;
|
||||
}
|
||||
if (timeout <= 0)
|
||||
{
|
||||
throw std::runtime_error("can not stop UDPService thread");
|
||||
}
|
||||
CommServiceThread->join();
|
||||
LOG_S(INFO) << "stoped CommService function" ;
|
||||
|
||||
}
|
||||
|
||||
void SimControl::CommServiceFunction_(){
|
||||
isCommServiceThreadRunning_ = true;
|
||||
LOG_S(INFO)<< "Comm thread is started";
|
||||
CommService_ = std::make_unique<CommService::CommService>("127.0.0.255","127.0.0.1",1,CommService::ID_SERVICE,"SimControl",8000);
|
||||
CommService_->connect();
|
||||
IncommingMessageQueue_ = CommService_->getReceivedMessageQueue();
|
||||
|
||||
while(!stopCommServiceThread_)
|
||||
{
|
||||
LOG_S(INFO)<< "received Messages" << IncommingMessageQueue_->size();
|
||||
LOG_S(INFO) << "out going Messages:" << OutgoingMessageQueue_->size();
|
||||
if (OutgoingMessageQueue_->size()> 0) {
|
||||
CommService_->publish(OutgoingMessageQueue_->pop().value());
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
|
||||
|
||||
}
|
||||
CommService_->stop();
|
||||
isCommServiceThreadRunning_=false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -33,11 +33,10 @@ int main()
|
||||
|
||||
SimControl::SimControl sc("127.0.0.255",8000);
|
||||
|
||||
sc.start();
|
||||
while (running) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
|
||||
}
|
||||
sc.stop();
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user