|
| 1 | +/** |
| 2 | + * @file hardware_tier.h |
| 3 | + * @brief Declares the hardware tier assessment public API. |
| 4 | + * |
| 5 | + * Provides functions for registering pluggable pipeline stages, |
| 6 | + * configuring DeviceConfig overrides, and performing hardware |
| 7 | + * tier assessments. |
| 8 | + * |
| 9 | + * @author Charliechen114514 |
| 10 | + * @date 2026-05-23 |
| 11 | + * @version 0.19 |
| 12 | + * @since 0.19 |
| 13 | + * @ingroup system_hardware_tier |
| 14 | + */ |
| 15 | +#pragma once |
| 16 | + |
| 17 | +#include "base/expected/expected.hpp" |
| 18 | +#include "base/export.h" |
| 19 | +#include "system/hardware_tier/hardware_tier_data.h" |
| 20 | + |
| 21 | +#include <memory> |
| 22 | +#include <string_view> |
| 23 | + |
| 24 | +namespace cf { |
| 25 | + |
| 26 | +class IHardwareCollector; |
| 27 | +class IHardwareScorer; |
| 28 | +class IHardwareAssessor; |
| 29 | +class IHardwarePolicy; |
| 30 | + |
| 31 | +// ───────────────────────────────────────────────────────── |
| 32 | +// Pipeline Registry |
| 33 | +// ───────────────────────────────────────────────────────── |
| 34 | + |
| 35 | +/** |
| 36 | + * @brief Registers a custom hardware data collector. |
| 37 | + * |
| 38 | + * Replaces the default collector. Must be called before the first |
| 39 | + * assessHardware() invocation. |
| 40 | + * |
| 41 | + * @param[in] collector Unique pointer to the collector implementation. |
| 42 | + * |
| 43 | + * @return void (replaces the registered collector). |
| 44 | + * |
| 45 | + * @since 0.19 |
| 46 | + * @ingroup system_hardware_tier |
| 47 | + */ |
| 48 | +CF_BASE_EXPORT void registerCollector(std::unique_ptr<IHardwareCollector> collector); |
| 49 | + |
| 50 | +/** |
| 51 | + * @brief Registers a custom scorer for a specific dimension. |
| 52 | + * |
| 53 | + * @param[in] dimension One of "cpu", "gpu", "memory", "display". |
| 54 | + * @param[in] scorer Unique pointer to the scorer implementation. |
| 55 | + * |
| 56 | + * @return void (replaces the registered scorer for the dimension). |
| 57 | + * |
| 58 | + * @since 0.19 |
| 59 | + * @ingroup system_hardware_tier |
| 60 | + */ |
| 61 | +CF_BASE_EXPORT void registerScorer(std::string_view dimension, |
| 62 | + std::unique_ptr<IHardwareScorer> scorer); |
| 63 | + |
| 64 | +/** |
| 65 | + * @brief Registers a custom assessor implementation. |
| 66 | + * |
| 67 | + * @param[in] assessor Unique pointer to the assessor implementation. |
| 68 | + * |
| 69 | + * @return void (replaces the registered assessor). |
| 70 | + * |
| 71 | + * @since 0.19 |
| 72 | + * @ingroup system_hardware_tier |
| 73 | + */ |
| 74 | +CF_BASE_EXPORT void registerAssessor(std::unique_ptr<IHardwareAssessor> assessor); |
| 75 | + |
| 76 | +/** |
| 77 | + * @brief Registers a custom policy implementation. |
| 78 | + * |
| 79 | + * @param[in] policy Unique pointer to the policy implementation. |
| 80 | + * |
| 81 | + * @return void (replaces the registered policy). |
| 82 | + * |
| 83 | + * @since 0.19 |
| 84 | + * @ingroup system_hardware_tier |
| 85 | + */ |
| 86 | +CF_BASE_EXPORT void registerPolicy(std::unique_ptr<IHardwarePolicy> policy); |
| 87 | + |
| 88 | +// ───────────────────────────────────────────────────────── |
| 89 | +// DeviceConfig Override |
| 90 | +// ───────────────────────────────────────────────────────── |
| 91 | + |
| 92 | +/** |
| 93 | + * @brief Sets a manual tier override from DeviceConfig. |
| 94 | + * |
| 95 | + * When set, the pipeline short-circuits: collection and scoring are |
| 96 | + * skipped, and the specified tier level is used directly. |
| 97 | + * |
| 98 | + * @param[in] level The tier level to enforce. |
| 99 | + * @param[in] reason Optional human-readable reason string. |
| 100 | + * |
| 101 | + * @return void (activates the tier override). |
| 102 | + * |
| 103 | + * @since 0.19 |
| 104 | + * @ingroup system_hardware_tier |
| 105 | + */ |
| 106 | +CF_BASE_EXPORT void setDeviceConfigOverride(HardwareTierLevel level, std::string reason = {}); |
| 107 | + |
| 108 | +/** |
| 109 | + * @brief Clears any active DeviceConfig override. |
| 110 | + * |
| 111 | + * @return void (restores normal pipeline behavior). |
| 112 | + * |
| 113 | + * @since 0.19 |
| 114 | + * @ingroup system_hardware_tier |
| 115 | + */ |
| 116 | +CF_BASE_EXPORT void clearDeviceConfigOverride(); |
| 117 | + |
| 118 | +// ───────────────────────────────────────────────────────── |
| 119 | +// Assessment API |
| 120 | +// ───────────────────────────────────────────────────────── |
| 121 | + |
| 122 | +/** |
| 123 | + * @brief Performs a complete hardware tier assessment. |
| 124 | + * |
| 125 | + * Executes the full pipeline: Collect -> Score -> Assess -> Policy. |
| 126 | + * If a DeviceConfig override is active, the pipeline short-circuits |
| 127 | + * and returns the overridden tier. |
| 128 | + * |
| 129 | + * The result is cached after the first successful call. Pass |
| 130 | + * force_refresh = true to re-run the pipeline. |
| 131 | + * |
| 132 | + * @param[in] force_refresh If true, forces re-running the pipeline. |
| 133 | + * |
| 134 | + * @return expected containing HardwareTierAssessment on success, |
| 135 | + * or HardwareTierError on failure. |
| 136 | + * |
| 137 | + * @since 0.19 |
| 138 | + * @ingroup system_hardware_tier |
| 139 | + */ |
| 140 | +CF_BASE_EXPORT expected<HardwareTierAssessment, HardwareTierError> |
| 141 | +assessHardware(bool force_refresh = false); |
| 142 | + |
| 143 | +/** |
| 144 | + * @brief Queries capability flags from the last assessment. |
| 145 | + * |
| 146 | + * Must be called after a successful assessHardware(). |
| 147 | + * |
| 148 | + * @return expected containing HardwareTierCapabilities on success, |
| 149 | + * or HardwareTierError if no assessment exists. |
| 150 | + * |
| 151 | + * @since 0.19 |
| 152 | + * @ingroup system_hardware_tier |
| 153 | + */ |
| 154 | +CF_BASE_EXPORT expected<HardwareTierCapabilities, HardwareTierError> getHardwareTierCapabilities(); |
| 155 | + |
| 156 | +} // namespace cf |
0 commit comments