FIX: fixed issue with locking
This commit is contained in:
@@ -46,7 +46,7 @@ COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_p
|
||||
|
||||
|
||||
COPY build/libs/OrderLibrary/libs/SimCore/libs/geographiclib/src/libGeographicLib.so.23 /usr/lib/
|
||||
COPY build/libs/KubeControl/libs/yaml-cpp/libyaml-cpp.so.0.8 /usr/lib/
|
||||
# COPY build/libs/KubeControl/libs/yaml-cpp/libyaml-cpp.so.0.8 /usr/lib/
|
||||
COPY build/libs/KubeControl/libs/curlpp/libcurlpp.so.1 /usr/lib/
|
||||
# COPY build/libs/EntityLibrary/libs/SimCore/libs/crossguid/libcrossguid.so.0 /usr/lib/
|
||||
# COPY build/libs/SimCore/libs/crossguid/libcrossguid.so.0 /usr/lib/
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace SimControl
|
||||
|
||||
void checkTracksTimeout();
|
||||
|
||||
const int TrackTimeoutTime = 12;
|
||||
const int TrackTimeoutTime = 6;
|
||||
|
||||
|
||||
};
|
||||
|
||||
Submodule libs/ixwebsocket updated: c5a02f1066...f29906c72f
@@ -54,17 +54,6 @@ namespace SimControl {
|
||||
PodController_ = std::make_unique<kubecontrol::PodController>("docs/config");
|
||||
}
|
||||
|
||||
// ExternalTCPServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(5000,ID_.getUUID());
|
||||
// ExternalTCPServer_->registerMessageCallback(std::bind(&SimControl::HandleTCPMessage,this,std::placeholders::_1));
|
||||
|
||||
|
||||
// TCPClient_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(30200,"192.168.252.6");
|
||||
// TCPClient_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(5555,"127.0.0.1");
|
||||
|
||||
// TCPClient_->registerMessageCallback(std::bind(&SimControl::HandleMessage,this,std::placeholders::_1));
|
||||
// TCPClient_->sendMessage("Hello Server");
|
||||
|
||||
|
||||
|
||||
WebsocketServer_ = std::make_shared<ix::WebSocketServer>(port,host);
|
||||
WebsocketServer_->setOnClientMessageCallback( [this](std::shared_ptr<ix::ConnectionState> connectionState, ix::WebSocket &websocket, const ix::WebSocketMessagePtr &msg)
|
||||
@@ -146,7 +135,7 @@ namespace SimControl {
|
||||
|
||||
void SimControl::HandleBroadcastMessage(std::string msg)
|
||||
{
|
||||
// LOG_S(INFO)<<msg;
|
||||
LOG_S(INFO)<<msg;
|
||||
|
||||
auto track = SimCore::SimTrack::unpack(msg);
|
||||
if (track != nullptr)
|
||||
@@ -155,6 +144,7 @@ namespace SimControl {
|
||||
|
||||
// LOG_S(INFO)<<"Track received";
|
||||
Tracklist_->addTrack(item);
|
||||
LOG_S(INFO)<<Tracklist_->getTracklistSize();
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +175,7 @@ namespace SimControl {
|
||||
|
||||
if (msg->type == ix::WebSocketMessageType::Open)
|
||||
{
|
||||
// LOG_S(INFO)<< "New connection" ;
|
||||
LOG_S(INFO)<< "New connection" ;
|
||||
|
||||
// A connection state object is available, and has a default id
|
||||
// You can subclass ConnectionState and pass an alternate factory
|
||||
@@ -206,15 +196,14 @@ namespace SimControl {
|
||||
{
|
||||
try {
|
||||
nlohmann::json j = nlohmann::json::parse(msg->str);
|
||||
|
||||
if (j["Data"] == "COP")
|
||||
{
|
||||
if (j["Type"] == "Request") {
|
||||
nlohmann::json response;
|
||||
response["Data"] = "COP";
|
||||
Tracklist_->getJsonTRackList(response);
|
||||
LOG_S(INFO)<<"Tracklist size: " << Tracklist_->getTracklistSize();
|
||||
|
||||
// LOG_S(INFO)<<response;
|
||||
websocket.send(response.dump());
|
||||
}else if(j["Type"] == "EntityTrackList")
|
||||
{
|
||||
@@ -223,7 +212,6 @@ namespace SimControl {
|
||||
{
|
||||
nlohmann::json response;
|
||||
this->getTrackListForEntity(j["ID"].get<std::string>(),response);
|
||||
|
||||
websocket.send(response.dump());
|
||||
}
|
||||
|
||||
@@ -399,9 +387,7 @@ namespace SimControl {
|
||||
{
|
||||
LOG_S(INFO)<< "Update Ship: "<< request["ID"];
|
||||
|
||||
// if (j["Type"] == ) {
|
||||
// statements
|
||||
// }
|
||||
|
||||
LOG_S(INFO)<< "Entity values:" << request;
|
||||
auto track = Tracklist_->getTrackBySringID(request["ID"].get<std::string>());
|
||||
Orders::MoveOrder moveOrder(track->getIdentifier());
|
||||
@@ -494,6 +480,7 @@ namespace SimControl {
|
||||
auto update = SimCore::TracklistUpdate::unpack(WHISPER::Message(response));
|
||||
if(update == nullptr)
|
||||
{
|
||||
LOG_S(INFO)<<"no update received";
|
||||
return;
|
||||
}
|
||||
try
|
||||
|
||||
@@ -20,20 +20,10 @@ namespace SimControl
|
||||
|
||||
void TrackList::addTrack(std::shared_ptr<SimControl::TrackItem> Track)
|
||||
{
|
||||
|
||||
std::lock_guard<std::mutex> lock(mx_);
|
||||
// LOG_S(INFO)<<markedAsDeletedTracks_.size();
|
||||
checkTracksTimeout();
|
||||
|
||||
|
||||
// auto it = markedAsDeletedTracks_.find(Track->getIdentifier().getUUID());
|
||||
// if (it == markedAsDeletedTracks_.end() )
|
||||
// {
|
||||
// auto [iterator, inserted] = TrackStore_.try_emplace(Track->getIdentifier().getUUID(),Track);
|
||||
// if (!inserted) { iterator->second = Track; }
|
||||
|
||||
// }
|
||||
|
||||
|
||||
auto [iterator, inserted] = TrackStore_.try_emplace(Track->getIdentifier().getUUID(),Track);
|
||||
if (!inserted)
|
||||
{
|
||||
@@ -41,10 +31,11 @@ namespace SimControl
|
||||
{
|
||||
iterator->second = Track;
|
||||
}
|
||||
}else {
|
||||
mx_.unlock();
|
||||
LOG_S(INFO)<< "Track added new Size:" << this->getTracklistSize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +46,7 @@ namespace SimControl
|
||||
for (std::map<std::string, std::shared_ptr<SimControl::TrackItem>>::iterator it=TrackStore_.begin(); it != TrackStore_.end();)
|
||||
{
|
||||
|
||||
if ((time(0) - it->second->getLastUpdateTimestamp())>= 6 )
|
||||
if ((time(0) - it->second->getLastUpdateTimestamp())>= TrackTimeoutTime )
|
||||
{
|
||||
it = TrackStore_.erase(it);
|
||||
}else {
|
||||
@@ -141,8 +132,9 @@ namespace SimControl
|
||||
size_t TrackList::getTracklistSize()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mx_);
|
||||
size_t size = this->TrackStore_.size();
|
||||
return size;
|
||||
|
||||
return this->TrackStore_.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "SimControl/SimControl.hpp"
|
||||
|
||||
#include "SimCore/Messages/SensorTrack.hpp"
|
||||
#include "nlohmann/json_fwd.hpp"
|
||||
#include <fstream>
|
||||
#include <future>
|
||||
@@ -95,7 +96,7 @@ void addTracksToTracklistUpdate(SimCore::TracklistUpdate *update, int amount)
|
||||
for(int i = 0; i < amount; i++)
|
||||
{
|
||||
std::string name = "test1-" + std::to_string(i);
|
||||
auto track = std::make_shared<SimCore::SimTrack>(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
|
||||
auto track = std::make_shared<SimCore::SensorTrack>(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
|
||||
SimCore::Position pos;
|
||||
double lat = fRand(-90, 90);
|
||||
double lon = fRand(-180, 180);
|
||||
|
||||
@@ -96,7 +96,9 @@ auto track = list.getTrackBySringID(ids[3]);
|
||||
|
||||
list.addTrack(std::make_shared<SimControl::TrackItem>(*track));
|
||||
// REQUIRE(list.getTracklistSize() == 24);
|
||||
LOG_S(INFO)<<"wait for 7500ms";
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(7500));
|
||||
LOG_S(INFO)<<"continue";
|
||||
LOG_S(INFO)<<"add saved track";
|
||||
list.addTrack(std::make_shared<SimControl::TrackItem>(*track));
|
||||
LOG_S(INFO)<<"added saved track";
|
||||
|
||||
Reference in New Issue
Block a user