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 : : private:
25 : 1 : RestApiProvider() = default;
26 : : ~RestApiProvider();
27 : :
28 : : void PerformRequest(int port);
29 : : float ParseSteeringLock(const std::string& json);
30 : :
31 : : friend class RestApiProviderTestAccess;
32 : :
33 : : std::atomic<bool> m_isRequesting{false};
34 : : std::atomic<float> m_fallbackRangeDeg{0.0f};
35 : : mutable std::mutex m_threadMutex;
36 : : std::thread m_requestThread;
37 : : };
38 : :
39 : : #endif // RESTAPIPROVIDER_H
|