49 lines
1.9 KiB
C++
49 lines
1.9 KiB
C++
#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);
|
||
};
|