From 9a92bfec454863b46091d04fa1edcb70e1914df2 Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Mon, 4 Apr 2011 16:46:28 +0000 Subject: [PATCH] Renamed "type" field (and all related stuff) of StorageDevice to detected_type. --- gsmartcontrol/TODO | 3 +- gsmartcontrol/src/applib/storage_detector.cpp | 2 +- .../src/applib/storage_detector_test.cpp | 2 +- gsmartcontrol/src/applib/storage_device.cpp | 26 ++++------ gsmartcontrol/src/applib/storage_device.h | 50 ++++++++++--------- gsmartcontrol/src/gsc_main_window_iconview.h | 2 +- 6 files changed, 40 insertions(+), 45 deletions(-) diff --git a/gsmartcontrol/TODO b/gsmartcontrol/TODO index 3e8e04e..5505cec 100644 --- a/gsmartcontrol/TODO +++ b/gsmartcontrol/TODO @@ -71,6 +71,7 @@ Add support for multiple drives behind devices. each one with optional smartctl parameters. Use :: as delimiter, as in device::-d_string::other_options. Show in UI as device (-d_string). + Preferences will match it as device::-d_string Rework drive properties UI: add properties for each multi-drive. @@ -106,8 +107,6 @@ Monitor: Periodically see if drives were added / removed (possibly use OS callbacks instead of polling?) -+Add a hint about "pd0" for Windows version. - If a drive is not recognized, suggest using -d (sat, sat,12, ...) Refer the user to http://sourceforge.net/apps/trac/smartmontools/wiki/Supported_USB-Devices diff --git a/gsmartcontrol/src/applib/storage_detector.cpp b/gsmartcontrol/src/applib/storage_detector.cpp index 0b723cd..812a25d 100644 --- a/gsmartcontrol/src/applib/storage_detector.cpp +++ b/gsmartcontrol/src/applib/storage_detector.cpp @@ -156,7 +156,7 @@ std::string StorageDetector::fetch_basic_data(std::vector& debug_out_dump("app", "Device information for " << drive->get_device() << ":\n" << "\tModel: " << drive->get_model_name() << "\n" - << "\tType: " << StorageDevice::get_type_readable_name(drive->get_type()) << "\n" + << "\tDetected type: " << StorageDevice::get_type_readable_name(drive->get_detected_type()) << "\n" << "\tSMART status: " << StorageDevice::get_status_name(drive->get_smart_status()) << "\n" ); diff --git a/gsmartcontrol/src/applib/storage_detector_test.cpp b/gsmartcontrol/src/applib/storage_detector_test.cpp index e3d7f2f..2f51d00 100644 --- a/gsmartcontrol/src/applib/storage_detector_test.cpp +++ b/gsmartcontrol/src/applib/storage_detector_test.cpp @@ -31,7 +31,7 @@ int main() } else { for (unsigned int i = 0; i < drives.size(); ++i) { std::cerr << drives[i]->get_device() << - " (" << StorageDevice::get_type_readable_name(drives[i]->get_type()) << ")\n"; + " (" << StorageDevice::get_type_readable_name(drives[i]->get_detected_type()) << ")\n"; } } diff --git a/gsmartcontrol/src/applib/storage_device.cpp b/gsmartcontrol/src/applib/storage_device.cpp index 6e56169..2e8666a 100644 --- a/gsmartcontrol/src/applib/storage_device.cpp +++ b/gsmartcontrol/src/applib/storage_device.cpp @@ -39,9 +39,9 @@ std::string StorageDevice::fetch_basic_data_and_parse(hz::intrusive_ptrset_type(type_scsi); + this->set_detected_type(detected_type_scsi); return this->fetch_basic_data_and_parse(smartctl_ex); // try again with scsi } @@ -75,13 +75,7 @@ std::string StorageDevice::parse_basic_data(bool do_set_properties, bool emit_si // detect type. note: we can't distinguish between sata and scsi (on linux, for -d ata switch). if (app_pcre_match("/this device: CD\\/DVD/mi", info_output_)) { - this->set_type(type_cddvd); - -// } else { -// std::string dev_base = get_device_base(); -// if (!dev_base.empty() && dev_base[0] == 'h') { // e.g. hda -// this->set_type(type_pata); -// } + this->set_detected_type(detected_type_cddvd); } // Note: We don't use SmartctlParser here, because this information @@ -167,7 +161,7 @@ std::string StorageDevice::fetch_data_and_parse(hz::intrusive_ptr sma // instead of -a, we use all the individual options -a encompasses, so that // an addition to default -a output won't affect us. - if (this->get_type() == type_scsi) { + if (this->get_detected_type() == detected_type_scsi) { // This doesn't do much yet, but just in case... // SCSI equivalent of -a: error_msg = execute_smartctl("-H -i -A -l error -l selftest", smartctl_ex, output); @@ -177,9 +171,9 @@ std::string StorageDevice::fetch_data_and_parse(hz::intrusive_ptr sma smartctl_ex, output, true); // set type to invalid if needed } // See notes above (in fetch_basic_data_and_parse()). - if (get_type() == type_invalid) { + if (get_detected_type() == detected_type_invalid) { debug_out_info("app", "The device seems to be of different type than auto-detected, trying again with scsi.\n"); - this->set_type(type_scsi); + this->set_detected_type(detected_type_scsi); return this->fetch_data_and_parse(smartctl_ex); // try again with scsi } @@ -454,10 +448,10 @@ std::string StorageDevice::get_device_options() const // If we have some special type, specify it on the command line (like "-d scsi"). // Note that the latter "-d" option overrides the former, so we're ok with multiple ones. - std::string type_arg = get_type_arg_name(this->get_type()); + std::string type_arg = get_type_arg_name(this->get_detected_type()); if (!type_arg.empty()) { - if (!config_options.empty()) { + if (!config_options.empty()) { config_options += " "; } config_options += "-d " + type_arg; @@ -531,9 +525,9 @@ std::string StorageDevice::execute_smartctl(const std::string& command_options, // This means that the old SCSI identify command isn't executed by default, // and there is no information about the device manufacturer/etc... in the output. // We detect this and set the device type to scsi to at least have _some_ info. - if (check_type && this->get_type() == type_unknown + if (check_type && this->get_detected_type() == detected_type_unknown // && this->get_type() == "" && app_pcre_match("/specify device type with the -d option/mi", output)) { - this->set_type(type_invalid); + this->set_detected_type(detected_type_invalid); } return smartctl_ex->get_error_msg(); diff --git a/gsmartcontrol/src/applib/storage_device.h b/gsmartcontrol/src/applib/storage_device.h index c06e32f..5ed564d 100644 --- a/gsmartcontrol/src/applib/storage_device.h +++ b/gsmartcontrol/src/applib/storage_device.h @@ -28,35 +28,35 @@ class StorageDevice : public hz::intrusive_ptr_referenced { // these may be used to force smartctl to a special type, as well as // to display the correct icon - enum type_t { - type_unknown, // unknown. will be autodetected by smartctl - type_invalid, // this is set by smartctl executor if it detects invalid type (but not if it's scsi). - type_cddvd, // unsupported by smartctl, only basic info is given. - type_scsi // this is used to force "-d scsi" to execute IDENTIFY command. + enum detected_type_t { + detected_type_unknown, // unknown. will be autodetected by smartctl + detected_type_invalid, // this is set by smartctl executor if it detects invalid type (but not if it's scsi). + detected_type_cddvd, // unsupported by smartctl, only basic info is given. + detected_type_scsi // this is used to force "-d scsi" to execute IDENTIFY command. }; // this gives a string which can be displayed in outputs - static std::string get_type_readable_name(type_t type) + static std::string get_type_readable_name(detected_type_t type) { switch (type) { - case type_unknown: return "unknown"; - case type_invalid: return "invalid"; - case type_cddvd: return "cd/dvd"; - case type_scsi: return "scsi"; + case detected_type_unknown: return "unknown"; + case detected_type_invalid: return "invalid"; + case detected_type_cddvd: return "cd/dvd"; + case detected_type_scsi: return "scsi"; } return "[internal_error]"; } // this gives a string which, if not empty, can be given as a parameter of "-d". - static std::string get_type_arg_name(type_t type) + static std::string get_type_arg_name(detected_type_t type) { switch (type) { - case type_unknown: return ""; - case type_invalid: return ""; - case type_cddvd: return ""; - case type_scsi: return "scsi"; + case detected_type_unknown: return ""; + case detected_type_invalid: return ""; + case detected_type_cddvd: return ""; + case detected_type_scsi: return "scsi"; } return ""; } @@ -84,7 +84,7 @@ class StorageDevice : public hz::intrusive_ptr_referenced { StorageDevice(const std::string& dev_or_vfile, bool is_virtual = false) { - type_ = type_unknown; + detected_type_ = detected_type_unknown; // force_type_ = false; is_virtual_ = is_virtual; is_manually_added_ = false; @@ -120,7 +120,7 @@ class StorageDevice : public hz::intrusive_ptr_referenced { fully_parsed_ = other.fully_parsed_; test_is_active_ = other.test_is_active_; - type_ = other.type_; + detected_type_ = other.detected_type_; smart_supported_ = other.smart_supported_; smart_enabled_ = other.smart_enabled_; aodc_status_ = other.aodc_status_; @@ -210,6 +210,7 @@ class StorageDevice : public hz::intrusive_ptr_referenced { } + /// Get device name without path. For example, "sda". std::string get_device_base() const { if (is_virtual_) @@ -241,14 +242,14 @@ class StorageDevice : public hz::intrusive_ptr_referenced { - void set_type(type_t t) + void set_detected_type(detected_type_t t) { - type_ = t; + detected_type_ = t; } - type_t get_type() const + detected_type_t get_detected_type() const { - return type_; + return detected_type_; } @@ -386,6 +387,7 @@ class StorageDevice : public hz::intrusive_ptr_referenced { std::string full_output_; // "smartctl --all" output std::string device_; // e.g. /dev/sda. empty if virtual. +// std::string type_; // // bool force_type_; // force "-d type" to smartctl, e.g. "-d scsi". DISCONTINUED, use per-device options. bool is_virtual_; // if true, then this is not a real device - merely a loaded description of it. @@ -399,7 +401,7 @@ class StorageDevice : public hz::intrusive_ptr_referenced { bool test_is_active_; // these are detected through info output - type_t type_; // e.g. type_ata + detected_type_t detected_type_; // e.g. type_unknown hz::OptionalValue smart_supported_; hz::OptionalValue smart_enabled_; mutable hz::OptionalValue aodc_status_; // cached aodc status. @@ -424,8 +426,8 @@ typedef hz::intrusive_ptr StorageDeviceRefPtr; // for sorting, hard drives first inline bool operator< (const StorageDeviceRefPtr& d1, const StorageDeviceRefPtr& d2) { - if (d1->get_type() != d2->get_type()) { - return (d1->get_type() == StorageDevice::type_unknown); // hard drives first + if (d1->get_detected_type() != d2->get_detected_type()) { + return (d1->get_detected_type() == StorageDevice::detected_type_unknown); // hard drives first } return d1->get_device_base() < d2->get_device_base(); } diff --git a/gsmartcontrol/src/gsc_main_window_iconview.h b/gsmartcontrol/src/gsc_main_window_iconview.h index e69e116..62a8733 100644 --- a/gsmartcontrol/src/gsc_main_window_iconview.h +++ b/gsmartcontrol/src/gsc_main_window_iconview.h @@ -243,7 +243,7 @@ class GscMainWindowIconView : public Gtk::IconView { Glib::RefPtr icon; - if (drive->get_type() == StorageDevice::type_cddvd) { + if (drive->get_detected_type() == StorageDevice::detected_type_cddvd) { icon = cddvd_icon; } else { icon = hd_icon;