Branch data Line data Source code
1 : : #ifndef RESTAPIPROVIDER_H
2 : : #define RESTAPIPROVIDER_H
3 : :
4 : : #include <string>
5 : : #include <atomic>
6 : : #include <mutex>
7 : : #include <thread>
8 : : #include <optional>
9 : :
10 : : class RestApiProvider {
11 : : public:
12 : : static RestApiProvider& Get();
13 : :
14 : : // Trigger an asynchronous request for the steering range
15 : : void RequestSteeringRange(int port);
16 : :
17 : : // Get the latest successfully retrieved range in degrees
18 : : // Returns 0.0 if no value has been retrieved yet
19 : : float GetFallbackRangeDeg() const;
20 : :
21 : : // Is a request currently in flight?
22 : : bool IsRequesting() const;
23 : :
24 : 122 : void ResetSteeringRange() {
25 : 122 : m_fallbackRangeDeg.store(0.0f);
26 : 122 : }
27 : :
28 : : private:
29 : 1 : RestApiProvider() = default;
30 : : ~RestApiProvider();
31 : :
32 : : void PerformRequest(int port);
33 : : float ParseSteeringLock(const std::string& json);
34 : :
35 : : friend class RestApiProviderTestAccess;
36 : :
37 : : std::atomic<bool> m_isRequesting{false};
38 : : std::atomic<float> m_fallbackRangeDeg{0.0f};
39 : :
40 : : mutable std::mutex m_threadMutex;
41 : : std::thread m_requestThread;
42 : : };
43 : :
44 : : #endif // RESTAPIPROVIDER_H
|