Branch data Line data Source code
1 : : #ifndef FFBMETADATA_MANAGER_H
2 : : #define FFBMETADATA_MANAGER_H
3 : :
4 : : #include <string>
5 : : #include <cstring>
6 : : #include <atomic>
7 : : #include <mutex>
8 : : #include "VehicleUtils.h"
9 : : #include "utils/StringUtils.h"
10 : : #include "io/lmu_sm_interface/LmuSharedMemoryWrapper.h"
11 : :
12 : : class FFBMetadataManager {
13 : : public:
14 : : static constexpr int STR_BUF_64 = 64;
15 : :
16 [ + - + - : 3248 : FFBMetadataManager() = default;
+ - ]
17 : :
18 : : // Updates metadata. Returns true if vehicle class/name changed (meaning FFB should seed/initialize)
19 : : bool UpdateMetadata(const SharedMemoryObjectOut& data);
20 : :
21 : : // Low-level update.
22 : : // NOTE: This is a hot-path method called from the FFB thread.
23 : : // It is protected by g_engine_mutex in FFBEngine.
24 : : bool UpdateInternal(const char* vehicleClass, const char* vehicleName, const char* trackName);
25 : :
26 : 262 : void ResetWarnings() { m_warned_invalid_range = false; }
27 : :
28 : : // API methods for FFBEngine
29 : 525 : const char* GetVehicleName() const { return m_vehicle_name; }
30 : : const char* GetTrackName() const { return m_track_name; }
31 : 244 : const char* GetCurrentClassName() const { return m_current_class_name.c_str(); }
32 : 63466 : ParsedVehicleClass GetCurrentClass() const { return m_current_vclass; }
33 : 15815 : bool HasWarnedInvalidRange() const { return m_warned_invalid_range; }
34 : 290 : void SetWarnedInvalidRange(bool val) { m_warned_invalid_range = val; }
35 : :
36 : : // Internal state (Kept public for legacy test compatibility as per Approach A)
37 : : char m_vehicle_name[STR_BUF_64] = "Unknown";
38 : : char m_track_name[STR_BUF_64] = "Unknown";
39 : : std::string m_current_class_name = "";
40 : : ParsedVehicleClass m_current_vclass = ParsedVehicleClass::UNKNOWN;
41 : : std::atomic<bool> m_warned_invalid_range{false};
42 : : std::string m_last_handled_vehicle_name = "";
43 : : std::string m_last_logged_veh = "";
44 : :
45 : : private:
46 : : std::mutex m_mutex;
47 : : };
48 : :
49 : : #endif // FFBMETADATA_MANAGER_H
|