QDAirPortTestSystemBackend/src/vehicle/ControllableVehicles.h

49 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <string>
#include <memory>
#include <optional>
#include <shared_mutex>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "types/VehicleCommand.h"
#include "network/HTTPClient.h"
struct VehicleRegistryEntry {
std::string vehicleID;
std::string vehicleType; // WUREN/TEQIN/HANGKONG/PUTONG/JIUYUAN
};
class ControllableVehicles {
private:
ControllableVehicles();
ControllableVehicles(const ControllableVehicles&) = delete;
ControllableVehicles& operator=(const ControllableVehicles&) = delete;
~ControllableVehicles() = default;
// 运行时车辆类型注册表(由前端接口增量更新)
mutable std::shared_mutex mutex_;
std::unordered_map<std::string, std::string> vehicle_type_by_id_;
std::unordered_set<std::string> controllable_vehicle_ids_; // vehicleType == WUREN
std::unordered_set<std::string> managed_vehicle_ids_; // vehicleType in {WUREN, TEQIN}
std::unordered_set<std::string> selected_aircraft_ids_; // vehicleType == HANGKONG前端选择参与碰撞的航空器 flightNo/id
std::unique_ptr<HTTPClient> http_client_;
public:
static ControllableVehicles& getInstance();
// 增量更新车辆注册表(仅更新 entries 中出现的 vehicleID并同步可控车辆集合WUREN
void updateRegistry(const std::vector<VehicleRegistryEntry>& entries);
// 查询
std::optional<std::string> getVehicleType(const std::string& vehicleID) const;
std::unordered_set<std::string> getControllableVehicleIdsSnapshot() const;
std::unordered_set<std::string> getSelectedAircraftIdsSnapshot() const;
bool isControllable(const std::string& vehicleNo) const;
bool isManagedVehicle(const std::string& vehicleNo) const;
bool isSelectedAircraft(const std::string& aircraftId) const;
bool sendCommand(const std::string& vehicleNo, const VehicleCommand& command);
};