|
| 1 | +// SPDX-FileCopyrightText: 2026 Intel Corporation |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +#pragma once |
| 5 | + |
| 6 | +#include <chrono> |
| 7 | +#include <optional> |
| 8 | +#include <string> |
| 9 | + |
| 10 | +namespace tracker { |
| 11 | + |
| 12 | +/** |
| 13 | + * @brief Abstract interface for Manager REST API operations. |
| 14 | + * |
| 15 | + * Enables dependency injection and mock-based testing of components |
| 16 | + * that depend on the Manager API (e.g., ApiSceneLoader). |
| 17 | + */ |
| 18 | +class IManagerRestClient { |
| 19 | +public: |
| 20 | + virtual ~IManagerRestClient() = default; |
| 21 | + |
| 22 | + /** |
| 23 | + * @brief Authenticate with the Manager API. |
| 24 | + * |
| 25 | + * @param username API username |
| 26 | + * @param password API password |
| 27 | + * @throws std::runtime_error on connection failure, HTTP error, or auth rejection |
| 28 | + */ |
| 29 | + virtual void authenticate(const std::string& username, const std::string& password) = 0; |
| 30 | + |
| 31 | + /** |
| 32 | + * @brief Fetch all scenes from the Manager API. |
| 33 | + * |
| 34 | + * @return Raw JSON response body string |
| 35 | + * @throws std::runtime_error if not authenticated, connection fails, or HTTP error |
| 36 | + */ |
| 37 | + virtual std::string fetchScenes() = 0; |
| 38 | +}; |
| 39 | + |
| 40 | +/** |
| 41 | + * @brief HTTP client for Manager REST API. |
| 42 | + * |
| 43 | + * Handles authentication and scene fetching from the SceneScape Manager. |
| 44 | + * Supports HTTPS with CA certificate verification. |
| 45 | + */ |
| 46 | +class ManagerRestClient : public IManagerRestClient { |
| 47 | +public: |
| 48 | + /** |
| 49 | + * @brief Construct a Manager REST API client. |
| 50 | + * |
| 51 | + * @param url Manager API base URL (e.g., "https://web.scenescape.intel.com") |
| 52 | + * @param ca_cert_path Optional CA certificate path for HTTPS verification |
| 53 | + * @param connect_timeout TCP connect timeout (default: 10s) |
| 54 | + * @param read_timeout HTTP read timeout (default: 30s) |
| 55 | + */ |
| 56 | + ManagerRestClient(std::string url, std::optional<std::string> ca_cert_path = std::nullopt, |
| 57 | + std::chrono::milliseconds connect_timeout = std::chrono::seconds(10), |
| 58 | + std::chrono::milliseconds read_timeout = std::chrono::seconds(30)); |
| 59 | + |
| 60 | + void authenticate(const std::string& username, const std::string& password) override; |
| 61 | + std::string fetchScenes() override; |
| 62 | + |
| 63 | +private: |
| 64 | + std::string url_; |
| 65 | + std::optional<std::string> ca_cert_path_; |
| 66 | + std::string token_; |
| 67 | + std::chrono::milliseconds connect_timeout_; |
| 68 | + std::chrono::milliseconds read_timeout_; |
| 69 | +}; |
| 70 | + |
| 71 | +} // namespace tracker |
0 commit comments