Skip to content

Commit

Permalink
Support parsing ATA Capabilities from JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashaduri committed Apr 19, 2024
1 parent 50d605b commit 6da27f7
Show file tree
Hide file tree
Showing 13 changed files with 537 additions and 49 deletions.
36 changes: 24 additions & 12 deletions src/applib/ata_storage_property.h
Expand Up @@ -248,6 +248,29 @@ class AtaStorageProperty {
[[nodiscard]] static std::string get_readable_section_name(Section s);


using ValueVariantType = std::variant<
std::monostate, ///< None
std::string, ///< Value (if it's a string)
int64_t, ///< Value (if it's an integer)
bool, ///< Value (if it's bool)
std::chrono::seconds, ///< Value in seconds (if it's time interval)
AtaStorageCapability, ///< Value (if it's a capability)
AtaStorageAttribute, ///< Value (if it's an attribute)
AtaStorageStatistic, ///< Value (if it's a statistic from devstat)
AtaStorageErrorBlock, ///< Value (if it's a error block)
AtaStorageSelftestEntry ///< Value (if it's a self-test entry)
>;


/// Constructor
AtaStorageProperty() = default;

/// Constructor
AtaStorageProperty(Section section_, ValueVariantType value_)
: section(section_), value(std::move(value_))
{ }


/// Get displayable value type name
[[nodiscard]] std::string get_storable_value_type_name() const;

Expand Down Expand Up @@ -297,18 +320,7 @@ class AtaStorageProperty {
std::string reported_value; ///< String representation of the value as reported
std::string readable_value; ///< User-friendly readable representation of value. if empty, use the other members.

std::variant<
std::monostate, ///< None
std::string, ///< Value (if it's a string)
int64_t, ///< Value (if it's an integer)
bool, ///< Value (if it's bool)
std::chrono::seconds, ///< Value in seconds (if it's time interval)
AtaStorageCapability, ///< Value (if it's a capability)
AtaStorageAttribute, ///< Value (if it's an attribute)
AtaStorageStatistic, ///< Value (if it's a statistic from devstat)
AtaStorageErrorBlock, ///< Value (if it's a error block)
AtaStorageSelftestEntry ///< Value (if it's a self-test entry)
> value;
ValueVariantType value; ///< Stored value

WarningLevel warning_level = WarningLevel::None; ///< Warning severity for this property
std::string warning_reason; // Warning reason (displayable)
Expand Down
2 changes: 1 addition & 1 deletion src/applib/ata_storage_property_descr.cpp
Expand Up @@ -1613,7 +1613,7 @@ bool ata_storage_property_autoset_description(AtaStorageProperty& p, AtaStorageA
|| auto_set(p, "ata_smart_data/self_test/status/_group", "Status of the last self-test run.")
|| auto_set(p, "ata_smart_data/offline_data_collection/_group", "Drive properties related to Offline Data Collection and self-tests.")
|| auto_set(p, "ata_smart_data/capabilities/_group", "Drive properties related to SMART handling.")
|| auto_set(p, "ata_smart_data/capabilities/error_logging_supported", "Drive properties related to error logging.")
|| auto_set(p, "ata_smart_data/capabilities/error_logging_supported/_group", "Drive properties related to error logging.")
|| auto_set(p, "ata_sct_capabilities/_group", "Drive properties related to temperature information.");
break;

Expand Down
2 changes: 1 addition & 1 deletion src/applib/selftest.cpp
Expand Up @@ -274,7 +274,7 @@ hz::ExpectedVoid<SelfTestError> SelfTest::update(const std::shared_ptr<CommandEx
for (const auto& e : property_repo.get_properties()) {
if (e.section != AtaStorageProperty::Section::Internal
|| !e.is_value_type<AtaStorageSelftestEntry>() || e.get_value<AtaStorageSelftestEntry>().test_num != 0
|| e.generic_name != "ata_smart_data/self_test/status/passed")
|| e.generic_name != "ata_smart_data/self_test/status/_merged")
continue;
p = e;
}
Expand Down

0 comments on commit 6da27f7

Please sign in to comment.