mirror of
https://github.com/ashaduri/gsmartcontrol.git
synced 2026-09-26 13:55:34 +00:00
Fixed compilation.
This commit is contained in:
@@ -39,7 +39,7 @@ target_sources(applib PRIVATE
|
||||
smartctl_executor.cpp
|
||||
smartctl_executor_gui.h
|
||||
smartctl_executor.h
|
||||
smartctl_output_type.h
|
||||
smartctl_parser_types.h
|
||||
smartctl_text_parser_helper.cpp
|
||||
smartctl_text_parser_helper.h
|
||||
smartctl_version_parser.cpp
|
||||
|
||||
@@ -243,7 +243,7 @@ std::string SelfTest::update(const std::shared_ptr<CommandExecutor>& smartctl_ex
|
||||
return error_msg;
|
||||
|
||||
AtaStorageAttribute::DiskType disk_type = drive_->get_is_hdd() ? AtaStorageAttribute::DiskType::Hdd : AtaStorageAttribute::DiskType::Ssd;
|
||||
auto parser = SmartctlParser::create(SmartctlOutputParserType::Text);
|
||||
auto parser = SmartctlParser::create(SmartctlParserType::Text);
|
||||
DBG_ASSERT_RETURN(parser, "Cannot create parser");
|
||||
|
||||
if (!parser->parse_full(output)) { // try to parse it
|
||||
|
||||
@@ -227,7 +227,7 @@ bool SmartctlAtaTextParser::parse_full(const std::string& full)
|
||||
add_property(p);
|
||||
}
|
||||
|
||||
if (!SmartctlVersionParser::check_parsed_version(SmartctlOutputParserType::Text, version)) {
|
||||
if (!SmartctlVersionParser::check_parsed_version(SmartctlParserType::Text, version)) {
|
||||
set_error_msg("Incompatible smartctl version.");
|
||||
debug_out_warn("app", DBG_FUNC_MSG << "Incompatible smartctl version. Returning.\n");
|
||||
return false;
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/******************************************************************************
|
||||
License: GNU General Public License v3.0 only
|
||||
Copyright:
|
||||
(C) 2022 Alexander Shaduri <ashaduri@gmail.com>
|
||||
******************************************************************************/
|
||||
/// \file
|
||||
/// \author Alexander Shaduri
|
||||
/// \ingroup applib
|
||||
/// \weakgroup applib
|
||||
/// @{
|
||||
|
||||
#ifndef SMARTCTL_OUTPUT_TYPE_H
|
||||
#define SMARTCTL_OUTPUT_TYPE_H
|
||||
|
||||
#include "local_glibmm.h"
|
||||
|
||||
#include "hz/enum_helper.h"
|
||||
|
||||
|
||||
enum class SmartctlOutputParserType {
|
||||
Auto,
|
||||
Json,
|
||||
Text,
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Helper structure for enum-related functions
|
||||
struct SmartctlOutputParserTypeExt
|
||||
: public hz::EnumHelper<
|
||||
SmartctlOutputParserType,
|
||||
SmartctlOutputParserTypeExt,
|
||||
Glib::ustring>
|
||||
{
|
||||
static constexpr inline SmartctlOutputParserType default_value = SmartctlOutputParserType::Auto;
|
||||
|
||||
static std::unordered_map<EnumType, std::pair<std::string, Glib::ustring>> build_enum_map()
|
||||
{
|
||||
return {
|
||||
{SmartctlOutputParserType::Auto, {"auto", _("Automatic")}},
|
||||
{SmartctlOutputParserType::Json, {"json", _("JSON")}},
|
||||
{SmartctlOutputParserType::Text, {"text", _("Text")}},
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/// @}
|
||||
@@ -20,14 +20,12 @@ Copyright:
|
||||
|
||||
|
||||
|
||||
std::unique_ptr<SmartctlParser> SmartctlParser::create(SmartctlOutputParserType type)
|
||||
std::unique_ptr<SmartctlParser> SmartctlParser::create(SmartctlParserType type)
|
||||
{
|
||||
switch(type) {
|
||||
case SmartctlOutputParserType::Auto:
|
||||
break;
|
||||
case SmartctlOutputParserType::Json:
|
||||
case SmartctlParserType::Json:
|
||||
return std::make_unique<SmartctlAtaJsonParser>();
|
||||
case SmartctlOutputParserType::Text:
|
||||
case SmartctlParserType::Text:
|
||||
return std::make_unique<SmartctlAtaTextParser>();
|
||||
}
|
||||
return nullptr;
|
||||
@@ -35,18 +33,18 @@ std::unique_ptr<SmartctlParser> SmartctlParser::create(SmartctlOutputParserType
|
||||
|
||||
|
||||
|
||||
std::optional<SmartctlOutputParserType> SmartctlParser::detect_output_type(const std::string& output) const
|
||||
{
|
||||
// std::optional<SmartctlParserType> SmartctlParser::detect_output_type(const std::string& output) const
|
||||
// {
|
||||
// Look for the first non-whitespace symbol
|
||||
auto first_symbol = std::find_if(output.begin(), output.end(), [&](char c) {
|
||||
return !std::isspace(c, std::locale::classic());
|
||||
});
|
||||
if (first_symbol != output.end() && *first_symbol == '-'
|
||||
// auto first_symbol = std::find_if(output.begin(), output.end(), [&](char c) {
|
||||
// return !std::isspace(c, std::locale::classic());
|
||||
// });
|
||||
// if (first_symbol != output.end() && *first_symbol == '-'
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@ Copyright:
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
// #include "leaf_ns.h"
|
||||
#include "ata_storage_property.h"
|
||||
#include "smartctl_output_type.h"
|
||||
#include "smartctl_parser_types.h"
|
||||
|
||||
|
||||
|
||||
@@ -51,12 +52,12 @@ class SmartctlParser {
|
||||
|
||||
/// Create an instance of this class.
|
||||
/// \return nullptr if no such class exists
|
||||
static std::unique_ptr<SmartctlParser> create(SmartctlOutputParserType type);
|
||||
static std::unique_ptr<SmartctlParser> create(SmartctlParserType type);
|
||||
|
||||
|
||||
/// Create an instance of this class.
|
||||
/// \return nullptr if no such class exists
|
||||
static std::unique_ptr<SmartctlParser> detect_and_parse(SmartctlOutputParserType type);
|
||||
// static std::unique_ptr<SmartctlParser> detect_and_parse(SmartctlParserType type);
|
||||
|
||||
|
||||
/// Parse full "smartctl -x" output.
|
||||
@@ -65,8 +66,7 @@ class SmartctlParser {
|
||||
|
||||
|
||||
/// Detect smartctl output type (text, json).
|
||||
/// Return
|
||||
[[nodiscard]] std::optional<SmartctlOutputParserType> detect_output_type(const std::string& output) const;
|
||||
// [[nodiscard]] leaf::result<SmartctlParserType> detect_output_type(const std::string& output) const;
|
||||
|
||||
|
||||
/// Get "full" data, as passed to parse_full().
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/******************************************************************************
|
||||
License: GNU General Public License v3.0 only
|
||||
Copyright:
|
||||
(C) 2022 Alexander Shaduri <ashaduri@gmail.com>
|
||||
******************************************************************************/
|
||||
/// \file
|
||||
/// \author Alexander Shaduri
|
||||
/// \ingroup applib
|
||||
/// \weakgroup applib
|
||||
/// @{
|
||||
|
||||
#ifndef SMARTCTL_PARSER_TYPES_H
|
||||
#define SMARTCTL_PARSER_TYPES_H
|
||||
|
||||
#include "local_glibmm.h"
|
||||
|
||||
#include "hz/enum_helper.h"
|
||||
|
||||
|
||||
|
||||
enum class SmartctlParserType {
|
||||
Json,
|
||||
Text,
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Helper structure for enum-related functions
|
||||
struct SmartctlParserTypeExt
|
||||
: public hz::EnumHelper<
|
||||
SmartctlParserType,
|
||||
SmartctlParserTypeExt,
|
||||
Glib::ustring>
|
||||
{
|
||||
static constexpr inline SmartctlParserType default_value = SmartctlParserType::Json;
|
||||
|
||||
static std::unordered_map<EnumType, std::pair<std::string, Glib::ustring>> build_enum_map()
|
||||
{
|
||||
return {
|
||||
{SmartctlParserType::Json, {"json", _("JSON")}},
|
||||
{SmartctlParserType::Text, {"text", _("Text")}},
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
enum class SmartctlParserSettingType {
|
||||
Auto,
|
||||
Json,
|
||||
Text,
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Helper structure for enum-related functions
|
||||
struct SmartctlParserSettingTypeExt
|
||||
: public hz::EnumHelper<
|
||||
SmartctlParserSettingType,
|
||||
SmartctlParserSettingTypeExt,
|
||||
Glib::ustring>
|
||||
{
|
||||
static constexpr inline SmartctlParserSettingType default_value = SmartctlParserSettingType::Auto;
|
||||
|
||||
static std::unordered_map<EnumType, std::pair<std::string, Glib::ustring>> build_enum_map()
|
||||
{
|
||||
return {
|
||||
{SmartctlParserSettingType::Auto, {"auto", _("Automatic")}},
|
||||
{SmartctlParserSettingType::Json, {"json", _("JSON")}},
|
||||
{SmartctlParserSettingType::Text, {"text", _("Text")}},
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/// @}
|
||||
@@ -53,15 +53,13 @@ std::optional<double> SmartctlVersionParser::get_numeric_version(const std::stri
|
||||
|
||||
|
||||
|
||||
bool SmartctlVersionParser::check_parsed_version(SmartctlOutputParserType parser_type, const std::string& version_only)
|
||||
bool SmartctlVersionParser::check_parsed_version(SmartctlParserType parser_type, const std::string& version_only)
|
||||
{
|
||||
if (auto numeric_version = get_numeric_version(version_only); numeric_version.has_value()) {
|
||||
switch(parser_type) {
|
||||
case SmartctlOutputParserType::Auto:
|
||||
return numeric_version.value() >= minimum_req_text_version || numeric_version.value() >= minimum_req_json_version;
|
||||
case SmartctlOutputParserType::Json:
|
||||
case SmartctlParserType::Json:
|
||||
return numeric_version.value() >= minimum_req_json_version;
|
||||
case SmartctlOutputParserType::Text:
|
||||
case SmartctlParserType::Text:
|
||||
return numeric_version.value() >= minimum_req_text_version;
|
||||
}
|
||||
}
|
||||
@@ -70,13 +68,13 @@ bool SmartctlVersionParser::check_parsed_version(SmartctlOutputParserType parser
|
||||
|
||||
|
||||
|
||||
std::optional<SmartctlOutputParserType> SmartctlVersionParser::detect_supported_parser_type(const std::string& version_only)
|
||||
std::optional<SmartctlParserType> SmartctlVersionParser::detect_supported_parser_type(const std::string& version_only)
|
||||
{
|
||||
if (check_parsed_version(SmartctlOutputParserType::Json, version_only)) {
|
||||
return SmartctlOutputParserType::Json;
|
||||
if (check_parsed_version(SmartctlParserType::Json, version_only)) {
|
||||
return SmartctlParserType::Json;
|
||||
}
|
||||
if (check_parsed_version(SmartctlOutputParserType::Text, version_only)) {
|
||||
return SmartctlOutputParserType::Text;
|
||||
if (check_parsed_version(SmartctlParserType::Text, version_only)) {
|
||||
return SmartctlParserType::Text;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ Copyright:
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
#include "smartctl_output_type.h"
|
||||
#include "smartctl_parser_types.h"
|
||||
|
||||
|
||||
|
||||
@@ -42,11 +42,11 @@ class SmartctlVersionParser {
|
||||
|
||||
|
||||
/// Check that the version of smartctl output can be parsed with a parser.
|
||||
static bool check_parsed_version(SmartctlOutputParserType parser_type, const std::string& version_only);
|
||||
static bool check_parsed_version(SmartctlParserType parser_type, const std::string& version_only);
|
||||
|
||||
|
||||
/// Detect smartctl parser type based on smartctl version
|
||||
static std::optional<SmartctlOutputParserType> detect_supported_parser_type(const std::string& version_only);
|
||||
static std::optional<SmartctlParserType> detect_supported_parser_type(const std::string& version_only);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -241,7 +241,7 @@ std::string StorageDevice::parse_basic_data(bool do_set_properties, bool emit_si
|
||||
disk_type = hdd_.value() ? AtaStorageAttribute::DiskType::Hdd : AtaStorageAttribute::DiskType::Ssd;
|
||||
}
|
||||
|
||||
auto parser = SmartctlParser::create(SmartctlOutputParserType::Text);
|
||||
auto parser = SmartctlParser::create(SmartctlParserType::Text);
|
||||
DBG_ASSERT_RETURN(parser, "Cannot create parser");
|
||||
|
||||
if (parser->parse_full(this->info_output_)) { // try to parse it
|
||||
@@ -308,7 +308,7 @@ std::string StorageDevice::parse_data()
|
||||
disk_type = hdd_.value() ? AtaStorageAttribute::DiskType::Hdd : AtaStorageAttribute::DiskType::Ssd;
|
||||
}
|
||||
|
||||
auto parser = SmartctlParser::create(SmartctlOutputParserType::Text);
|
||||
auto parser = SmartctlParser::create(SmartctlParserType::Text);
|
||||
DBG_ASSERT_RETURN(parser, "Cannot create parser");
|
||||
|
||||
if (parser->parse_full(this->full_output_)) { // try to parse it (parse only, set the properties after basic parsing).
|
||||
|
||||
Reference in New Issue
Block a user