ADD: updated tracklist for simcontroll

This commit is contained in:
Henry Winkel
2024-02-15 17:52:50 +01:00
parent b932c4a917
commit 96b99afff9
11 changed files with 271 additions and 113 deletions

View File

@@ -56,7 +56,7 @@ class SimControl{
void startShip(std::string name);
void startNewShip(std::string Name, std::string lat, std::string lon, std::string height , std::string course, std::string speed);
void startNewShip(std::string Name, std::string lat, std::string lon, std::string height , std::string course, std::string speed, bool WaitTillRunning = true);
void updateShip(nlohmann::json request);
void deleteShip(nlohmann::json request);

View File

@@ -0,0 +1,65 @@
#pragma once
#include "SimCore/Messages/SimTrack.hpp"
#include "nlohmann/json_fwd.hpp"
#include <string>
namespace SimControl
{
class TrackItem : public SimCore::SimTrack
{
public:
/**
* @brief Construct a new Track Item object
*
* @param track
*/
TrackItem(SimCore::SimTrack track);
/**
* @brief mark track as deleteed
*
*/
void markAsDelete();
/**
* @brief
*
* @return true if is marked as deleted
* @return false if not
*/
bool isMarkedAsDelete();
/**
* @brief Get the Last Update Timestamp object
*
* @return std::chrono::time_point<std::chrono::system_clock>
*/
std::time_t getLastUpdateTimestamp();
/**
* @brief
*
* @return nlohmann::json
*/
nlohmann::json toJSON();
/**
* @brief
*
* @return std::string
*/
std::string toString();
private:
bool markedAsDeleted;
std::time_t lastReceiveTimestamp_;
};
}

View File

@@ -5,7 +5,7 @@
#include "nlohmann/json_fwd.hpp"
#include <SimCore/Identifier.hpp>
#include <SimCore/Messages/SimTrack.hpp>
#include <SimControl/TrackItem.hpp>
#include <cstddef>
#include <nlohmann/json.hpp>
#include <map>
@@ -13,17 +13,20 @@
#include <mutex>
#include <vector>
namespace SimControl
{
class TrackList
{
public:
TrackList();
void addTrack(std::shared_ptr<SimCore::SimTrack> Track);
std::shared_ptr<SimCore::SimTrack> getTrack(SimCore::Identifier);
void addTrack(std::shared_ptr<SimControl::TrackItem> Track);
std::shared_ptr<SimControl::TrackItem> getTrack(SimCore::Identifier);
void deleteTrack(std::string ID);
void deleteTrack(SimCore::Identifier);
@@ -36,13 +39,13 @@ namespace SimControl
private:
mutable std::mutex mx_;
std::map<std::string, std::shared_ptr<SimCore::SimTrack>> TrackStore_;
std::map<std::string, std::shared_ptr<SimControl::TrackItem>> TrackStore_;
std::map<std::string, std::time_t> markedAsDeletedTracks_;
// std::map<std::string, std::time_t> markedAsDeletedTracks_;
void checkTracksTimeout();
const int TrackTimeoutTime = 6;
const int TrackTimeoutTime = 12;
};