diff --git a/src/app.cpp b/src/app.cpp index 75fda34..cc39b93 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -9,38 +9,35 @@ /** * \brief app constructor - * \param void + * \param void * \return instance of App */ -App::App(void) { +App::App(void) +{ cout << "created app" << endl; } /** * \brief app logic - * \param void + * \param void * \return void */ void App::app_logic(void) { cout << "app logic" << endl; - //Drive* tmp = new Drive("test"); - - searchDrives(&listDrives); //search for new drives and store them in list - filterIgnoredDrives(&listDrives); //filter out ignored drives - - addSMARTData(&listDrives); - - printDrives(&listDrives); //print currently attached drives + searchDrives(&vecDrives); //search for new drives and store them in list + filterIgnoredDrives(&vecDrives); //filter out ignored drives + addSMARTData(&vecDrives); //add S.M.A.R.T. Data to the drives + printDrives(&vecDrives); //print currently attached drives } /** * \brief search attached drives on /dev/sd* - * \param pointer of list *listDrives + * \param pointer of vector * pvecDrives * \return void */ -void App::searchDrives(list *listDrives) +void App::searchDrives(vector * pvecDrives) { cout << "search drives ..." << endl; char * cLine = NULL; @@ -58,7 +55,7 @@ void App::searchDrives(list *listDrives) if (string(cLine).find("/dev/sd") != string::npos) { Drive* tmpDrive = new Drive(string(cLine).substr (2,8)); - listDrives->push_back(*tmpDrive); + pvecDrives->push_back(*tmpDrive); } } fclose(outputfileHwinfo); @@ -66,10 +63,10 @@ void App::searchDrives(list *listDrives) /** * \brief filter out drives that are listed in "ignoreDrives.conf" - * \param pointer of list *listDrives + * \param pointer of vector * pvecDrives * \return void */ -void App::filterIgnoredDrives(list *listDrives) +void App::filterIgnoredDrives(vector * pvecDrives) { string sDelimiter = ":"; string sIgnoredDrivePath; @@ -101,11 +98,10 @@ void App::filterIgnoredDrives(list *listDrives) //loop through found entries in ingnore file for(auto row : vtlIgnoredDevices) { - //cout << get<0>(row) << " is " << get<1>(row) << endl; - list ::iterator it; - // loop through found drives - for (it = listDrives->begin(); it != listDrives->end(); ++it) + auto it = pvecDrives->begin(); + while (it != pvecDrives->end()) { + it++; string sUUID; if (!get<0>(row).compare(it->getPath())) //find same drive based on path { @@ -133,7 +129,7 @@ void App::filterIgnoredDrives(list *listDrives) } } fclose(outputfileBlkid); - //cout << "blkid uuid:" << sUUID << endl; + // cout << "blkid uuid:" << sUUID << endl; if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive { @@ -143,8 +139,9 @@ void App::filterIgnoredDrives(list *listDrives) else { // same uuid found than in ignore file --> ignore this drive - it = listDrives->erase(it); + it = pvecDrives->erase(it); } + } } } @@ -152,14 +149,14 @@ void App::filterIgnoredDrives(list *listDrives) /** * \brief print drives with all information - * \param pointer of list *listDrives + * \param pointer of vector * pvecDrives * \return void */ -void App::printDrives(list *listDrives) +void App::printDrives(vector * pvecDrives) { cout << "------------DRIVES---------------" << endl; - list ::iterator it; - for (it = listDrives->begin(); it != listDrives->end(); ++it) + vector ::iterator it; + for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) { cout << "Path: " << it->getPath() << endl; cout << "ModelFamily: " << it->getModelFamily() << endl; @@ -167,17 +164,24 @@ void App::printDrives(list *listDrives) cout << "Capacity: " << it->getCapacity() << endl; cout << "Serial: " << it->getSerial() << endl; cout << "PowerOnHours: " << it->getPowerOnHours() << endl; - cout << "PowerCycle: " << it->getPowerCycles() << endl; + cout << "PowerCycle: " << it->getPowerCycles() << endl; cout << "ErrorCount: " << it->getErrorCount() << endl; cout << endl; } cout << "---------------------------------" << endl; } -void App::addSMARTData(list *listDrives) { - list ::iterator it; - for (it = listDrives->begin(); it != listDrives->end(); ++it) +/** + * \brief add S.M.A.R.T data from SMART + * \param pointer of vector * pvecDrives + * \return void + */ +void App::addSMARTData(vector * pvecDrives) +{ + vector ::iterator it; + for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) { - SMART::readSMARTData(*it); + Drive* pTmpDrive = iterator_to_pointer::iterator > (it); + SMART::readSMARTData(pTmpDrive); } } \ No newline at end of file diff --git a/src/app.h b/src/app.h index 24a7cb5..f4e891d 100644 --- a/src/app.h +++ b/src/app.h @@ -12,9 +12,15 @@ #include "drive.h" #include "smart.h" -class App { -protected: +template +T* iterator_to_pointer(I i) +{ + return (&(*i)); +} +class App +{ +protected: public: App(void); @@ -22,15 +28,13 @@ public: private: - list listDrives; //stores all drive data + vector vecDrives; //stores all drive data - void searchDrives(list *listDrives); - void printDrives(list *listDrives); - void filterIgnoredDrives(list *listDrives); - void addSMARTData(list *listDrives); + void searchDrives(vector * pvecDrives); + void printDrives(vector * pvecDrives); + void filterIgnoredDrives(vector * pvecDrives); + void addSMARTData(vector * pvecDrives); }; - - #endif // APP_H_ \ No newline at end of file diff --git a/src/drive.cpp b/src/drive.cpp index 40957e1..aabc55b 100644 --- a/src/drive.cpp +++ b/src/drive.cpp @@ -7,7 +7,6 @@ #include "drive.h" - string Drive::getPath(void) { return sPath; @@ -47,6 +46,17 @@ uint32_t Drive::getPowerCycles(void) return u32PowerCycles; } +/** + * \brief set S.M.A.R.T. values in model + * \param string modelFamily + * \param string modelName + * \param string serial + * \param uint64_t capacity + * \param uint32_t errorCount + * \param uint32_t powerOnHours + * \param uint32_t powerCycle + * \return void + */ void Drive::setDriveSMARTData( string modelFamily, string modelName, string serial, @@ -55,7 +65,7 @@ void Drive::setDriveSMARTData( string modelFamily, uint32_t powerOnHours, uint32_t powerCycle) { - sModelFamily = modelFamily; + this->sModelFamily = modelFamily; sModelName = modelName; sSerial = serial; u64Capacity = capacity; diff --git a/src/drive.h b/src/drive.h index cc579c4..3b331be 100644 --- a/src/drive.h +++ b/src/drive.h @@ -10,12 +10,14 @@ #include "refurbishingHddTool.h" -class Drive { +class Drive +{ protected: public: - Drive(string path) { - sPath = path; + Drive(string path) + { + this->sPath = path; } string getPath(void); diff --git a/src/out.txt b/src/out.txt deleted file mode 100644 index c9040be..0000000 --- a/src/out.txt +++ /dev/null @@ -1,803 +0,0 @@ -{ - "json_format_version": [ - 1, - 0 - ], - "smartctl": { - "version": [ - 7, - 1 - ], - "svn_revision": "5022", - "platform_info": "x86_64-linux-5.6.4-1-default", - "build_info": "(SUSE RPM)", - "argv": [ - "smartctl", - "--json", - "-a", - "/dev/sdd" - ], - "exit_status": 0 - }, - "device": { - "name": "/dev/sdd", - "info_name": "/dev/sdd [SAT]", - "type": "sat", - "protocol": "ATA" - }, - "model_family": "Western Digital Caviar Green", - "model_name": "WDC WD15EADS-22P8B0", - "serial_number": "WD-WMAVU2708194", - "wwn": { - "naa": 5, - "oui": 5358, - "id": 28633198579 - }, - "firmware_version": "01.00A01", - "user_capacity": { - "blocks": 2930277168, - "bytes": 1500301910016 - }, - "logical_block_size": 512, - "physical_block_size": 512, - "in_smartctl_database": true, - "ata_version": { - "string": "ATA8-ACS (minor revision not indicated)", - "major_value": 510, - "minor_value": 0 - }, - "sata_version": { - "string": "SATA 2.6", - "value": 30 - }, - "interface_speed": { - "max": { - "sata_value": 6, - "string": "3.0 Gb/s", - "units_per_second": 30, - "bits_per_unit": 100000000 - } - }, - "local_time": { - "time_t": 1588412611, - "asctime": "Sat May 2 11:43:31 2020 CEST" - }, - "smart_status": { - "passed": true - }, - "ata_smart_data": { - "offline_data_collection": { - "status": { - "value": 130, - "string": "was completed without error", - "passed": true - }, - "completion_seconds": 31200 - }, - "self_test": { - "status": { - "value": 0, - "string": "completed without error", - "passed": true - }, - "polling_minutes": { - "short": 2, - "extended": 356, - "conveyance": 5 - } - }, - "capabilities": { - "values": [ - 123, - 3 - ], - "exec_offline_immediate_supported": true, - "offline_is_aborted_upon_new_cmd": false, - "offline_surface_scan_supported": true, - "self_tests_supported": true, - "conveyance_self_test_supported": true, - "selective_self_test_supported": true, - "attribute_autosave_enabled": true, - "error_logging_supported": true, - "gp_logging_supported": true - } - }, - "ata_sct_capabilities": { - "value": 12343, - "error_recovery_control_supported": false, - "feature_control_supported": true, - "data_table_supported": true - }, - "ata_smart_attributes": { - "revision": 16, - "table": [ - { - "id": 1, - "name": "Raw_Read_Error_Rate", - "value": 200, - "worst": 200, - "thresh": 51, - "when_failed": "", - "flags": { - "value": 47, - "string": "POSR-K ", - "prefailure": true, - "updated_online": true, - "performance": true, - "error_rate": true, - "event_count": false, - "auto_keep": true - }, - "raw": { - "value": 0, - "string": "0" - } - }, - { - "id": 3, - "name": "Spin_Up_Time", - "value": 183, - "worst": 178, - "thresh": 21, - "when_failed": "", - "flags": { - "value": 39, - "string": "POS--K ", - "prefailure": true, - "updated_online": true, - "performance": true, - "error_rate": false, - "event_count": false, - "auto_keep": true - }, - "raw": { - "value": 5850, - "string": "5850" - } - }, - { - "id": 4, - "name": "Start_Stop_Count", - "value": 100, - "worst": 100, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 50, - "string": "-O--CK ", - "prefailure": false, - "updated_online": true, - "performance": false, - "error_rate": false, - "event_count": true, - "auto_keep": true - }, - "raw": { - "value": 731, - "string": "731" - } - }, - { - "id": 5, - "name": "Reallocated_Sector_Ct", - "value": 200, - "worst": 200, - "thresh": 140, - "when_failed": "", - "flags": { - "value": 51, - "string": "PO--CK ", - "prefailure": true, - "updated_online": true, - "performance": false, - "error_rate": false, - "event_count": true, - "auto_keep": true - }, - "raw": { - "value": 0, - "string": "0" - } - }, - { - "id": 7, - "name": "Seek_Error_Rate", - "value": 100, - "worst": 253, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 46, - "string": "-OSR-K ", - "prefailure": false, - "updated_online": true, - "performance": true, - "error_rate": true, - "event_count": false, - "auto_keep": true - }, - "raw": { - "value": 0, - "string": "0" - } - }, - { - "id": 9, - "name": "Power_On_Hours", - "value": 99, - "worst": 99, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 50, - "string": "-O--CK ", - "prefailure": false, - "updated_online": true, - "performance": false, - "error_rate": false, - "event_count": true, - "auto_keep": true - }, - "raw": { - "value": 1227, - "string": "1227" - } - }, - { - "id": 10, - "name": "Spin_Retry_Count", - "value": 100, - "worst": 100, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 50, - "string": "-O--CK ", - "prefailure": false, - "updated_online": true, - "performance": false, - "error_rate": false, - "event_count": true, - "auto_keep": true - }, - "raw": { - "value": 0, - "string": "0" - } - }, - { - "id": 11, - "name": "Calibration_Retry_Count", - "value": 100, - "worst": 100, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 50, - "string": "-O--CK ", - "prefailure": false, - "updated_online": true, - "performance": false, - "error_rate": false, - "event_count": true, - "auto_keep": true - }, - "raw": { - "value": 0, - "string": "0" - } - }, - { - "id": 12, - "name": "Power_Cycle_Count", - "value": 100, - "worst": 100, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 50, - "string": "-O--CK ", - "prefailure": false, - "updated_online": true, - "performance": false, - "error_rate": false, - "event_count": true, - "auto_keep": true - }, - "raw": { - "value": 712, - "string": "712" - } - }, - { - "id": 192, - "name": "Power-Off_Retract_Count", - "value": 200, - "worst": 200, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 50, - "string": "-O--CK ", - "prefailure": false, - "updated_online": true, - "performance": false, - "error_rate": false, - "event_count": true, - "auto_keep": true - }, - "raw": { - "value": 351, - "string": "351" - } - }, - { - "id": 193, - "name": "Load_Cycle_Count", - "value": 193, - "worst": 193, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 50, - "string": "-O--CK ", - "prefailure": false, - "updated_online": true, - "performance": false, - "error_rate": false, - "event_count": true, - "auto_keep": true - }, - "raw": { - "value": 21656, - "string": "21656" - } - }, - { - "id": 194, - "name": "Temperature_Celsius", - "value": 120, - "worst": 86, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 34, - "string": "-O---K ", - "prefailure": false, - "updated_online": true, - "performance": false, - "error_rate": false, - "event_count": false, - "auto_keep": true - }, - "raw": { - "value": 30, - "string": "30" - } - }, - { - "id": 196, - "name": "Reallocated_Event_Count", - "value": 200, - "worst": 200, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 50, - "string": "-O--CK ", - "prefailure": false, - "updated_online": true, - "performance": false, - "error_rate": false, - "event_count": true, - "auto_keep": true - }, - "raw": { - "value": 0, - "string": "0" - } - }, - { - "id": 197, - "name": "Current_Pending_Sector", - "value": 200, - "worst": 200, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 50, - "string": "-O--CK ", - "prefailure": false, - "updated_online": true, - "performance": false, - "error_rate": false, - "event_count": true, - "auto_keep": true - }, - "raw": { - "value": 0, - "string": "0" - } - }, - { - "id": 198, - "name": "Offline_Uncorrectable", - "value": 200, - "worst": 200, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 48, - "string": "----CK ", - "prefailure": false, - "updated_online": false, - "performance": false, - "error_rate": false, - "event_count": true, - "auto_keep": true - }, - "raw": { - "value": 0, - "string": "0" - } - }, - { - "id": 199, - "name": "UDMA_CRC_Error_Count", - "value": 200, - "worst": 199, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 50, - "string": "-O--CK ", - "prefailure": false, - "updated_online": true, - "performance": false, - "error_rate": false, - "event_count": true, - "auto_keep": true - }, - "raw": { - "value": 332, - "string": "332" - } - }, - { - "id": 200, - "name": "Multi_Zone_Error_Rate", - "value": 200, - "worst": 200, - "thresh": 0, - "when_failed": "", - "flags": { - "value": 8, - "string": "---R-- ", - "prefailure": false, - "updated_online": false, - "performance": false, - "error_rate": true, - "event_count": false, - "auto_keep": false - }, - "raw": { - "value": 0, - "string": "0" - } - } - ] - }, - "power_on_time": { - "hours": 1227 - }, - "power_cycle_count": 712, - "temperature": { - "current": 30 - }, - "ata_smart_error_log": { - "summary": { - "revision": 1, - "count": 0 - } - }, - "ata_smart_self_test_log": { - "standard": { - "revision": 1, - "table": [ - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1191 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1170 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1155 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1141 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1127 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1112 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1100 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1087 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1074 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1060 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1047 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1034 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1021 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1005 - }, - { - "type": { - "value": 2, - "string": "Extended offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 1003 - }, - { - "type": { - "value": 2, - "string": "Extended offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 992 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 987 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 975 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 234 - }, - { - "type": { - "value": 1, - "string": "Short offline" - }, - "status": { - "value": 0, - "string": "Completed without error", - "passed": true - }, - "lifetime_hours": 230 - } - ], - "count": 20, - "error_count_total": 0, - "error_count_outdated": 0 - } - }, - "ata_smart_selective_self_test_log": { - "revision": 1, - "table": [ - { - "lba_min": 0, - "lba_max": 0, - "status": { - "value": 0, - "string": "Not_testing" - } - }, - { - "lba_min": 0, - "lba_max": 0, - "status": { - "value": 0, - "string": "Not_testing" - } - }, - { - "lba_min": 0, - "lba_max": 0, - "status": { - "value": 0, - "string": "Not_testing" - } - }, - { - "lba_min": 0, - "lba_max": 0, - "status": { - "value": 0, - "string": "Not_testing" - } - }, - { - "lba_min": 0, - "lba_max": 0, - "status": { - "value": 0, - "string": "Not_testing" - } - } - ], - "flags": { - "value": 0, - "remainder_scan_enabled": false - }, - "power_up_scan_resume_minutes": 0 - } -} diff --git a/src/reHDD b/src/reHDD index 5e9a669..3cedd21 100755 Binary files a/src/reHDD and b/src/reHDD differ diff --git a/src/smart.cpp b/src/smart.cpp index 0d54509..d0da3f5 100644 --- a/src/smart.cpp +++ b/src/smart.cpp @@ -15,18 +15,32 @@ uint32_t SMART::errorCount = 0U; uint32_t SMART::powerOnHours = 0U; uint32_t SMART::powerCycle = 0U; -void SMART::readSMARTData(Drive drive) +/** + * \brief get and set S.M.A.R.T. values in Drive + * \param pointer of Drive instance + * \return void + */ +void SMART::readSMARTData(Drive* drive) { + modelFamily.clear(); + modelName.clear(); + serial.clear(); + capacity = 0U; + errorCount = 0U; + powerOnHours = 0U; + powerCycle = 0U; + size_t len = 0; //lenght of found line char* cLine = NULL; //found line string sCMD = ("./smartctl --json -a "); - sCMD.append(drive.getPath()); + sCMD.append(drive->getPath()); const char* cpComand = sCMD.c_str(); FILE* outputfileSmart = popen(cpComand, "r"); - while ((getline(&cLine, &len, outputfileSmart)) != -1) { + while ((getline(&cLine, &len, outputfileSmart)) != -1) + { string sLine = string(cLine); SMART::parseModelFamily(sLine); @@ -38,97 +52,123 @@ void SMART::readSMARTData(Drive drive) SMART::parsePowerCycle(sLine); } fclose(outputfileSmart); - //drive.setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, spinUpCount); + drive->setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, powerCycle); //wirte data in drive } +/** + * \brief parse ModelFamiliy + * \param string output line of smartctl + * \return void + */ void SMART::parseModelFamily(string sLine) { string search("\"model_family\": "); size_t found = sLine.find(search); if (found!=string::npos) { - // cout << sLine; sLine.erase(0, sLine.find(": ") + 3); sLine.erase(sLine.length()-3, 3); - // modelFamily = sLine; - cout << "ModelFamily |" << sLine << "|" << endl; + modelFamily = sLine; } } +/** + * \brief parse ModelName + * \param string output line of smartctl + * \return void + */ void SMART::parseModelName(string sLine) { - string search("\"model_name\": "); + string search("\"model_name\": "); size_t found = sLine.find(search); if (found!=string::npos) { - // cout << sLine; sLine.erase(0, sLine.find(": ") + 3); sLine.erase(sLine.length()-3, 3); - // modelName = sLine; - cout << "ModelName |" << sLine << "|" << endl; + modelName = sLine; } } +/** + * \brief parse Serial + * \param string output line of smartctl + * \return void + */ void SMART::parseSerial(string sLine) { - string search("\"serial_number\": "); + string search("\"serial_number\": "); size_t found = sLine.find(search); if (found!=string::npos) { - // cout << sLine; sLine.erase(0, sLine.find(": ") + 3); sLine.erase(sLine.length()-3, 3); - // serial = sLine; - cout << "Serial |" << sLine << "|" << endl; + serial = sLine; } } +/** + * \brief parse Capacity + * \param string output line of smartctl + * \return void + */ void SMART::parseCapacity(string sLine) { - string search("\"bytes\": "); + string search("\"bytes\": "); size_t found = sLine.find(search); if (found!=string::npos) { - // cout << sLine; sLine.erase(0, sLine.find(": ") + 2); sLine.erase(sLine.length()-1, 1); - // capacity = sLine; - cout << "Capacity |" << sLine << "|" << endl; + capacity = stol(sLine); } } +/** + * \brief parse ErrorCount + * \param string output line of smartctl + * \return void + */ void SMART::parseErrorCount(string sLine) { - string search("\"error_count_total\": "); + string search("\"error_count_total\": "); size_t found = sLine.find(search); - if (found!=string::npos) { - //cout << sLine; + if (found!=string::npos) + { sLine.erase(0, sLine.find(": ")+2); sLine.erase(sLine.length()-2, 2); - errorCount = stoi(sLine); - cout << "ErrorCount |" << sLine << "|" << endl; + errorCount = stol(sLine); } } +/** + * \brief parse PowerOnHours + * \param string output line of smartctl + * \return void + */ void SMART::parsePowerOnHours(string sLine) { -string search("\"hours\": "); + string search("\"hours\": "); size_t found = sLine.find(search); - if (found!=string::npos) { - // cout << sLine; + if (found!=string::npos) + { sLine.erase(0, sLine.find(": ") + 2); sLine.erase(sLine.length()-1, 1); - // powerOnHours = stoi(sLine); - cout << "PowerOnHours |" << sLine << "|" << endl; + powerOnHours = stol(sLine); + } } +/** + * \brief parse PowerCycle + * \param string output line of smartctl + * \return void + */ void SMART::parsePowerCycle(string sLine) { -string search("\"power_cycle_count\": "); + string search("\"power_cycle_count\": "); size_t found = sLine.find(search); - if (found!=string::npos) { - // cout << sLine; - sLine.erase(0, sLine.find(": ") + 2); + if (found!=string::npos) + { + sLine.erase(0, sLine.find(": ") + 2); sLine.erase(sLine.length()-2, 2); - //spinUpCount = stoi(sLine); - cout << "PowerCycle |" << sLine << "|" << endl; + powerCycle = stol(sLine); + } } diff --git a/src/smart.h b/src/smart.h index 0c107a7..50ee1fa 100644 --- a/src/smart.h +++ b/src/smart.h @@ -12,14 +12,13 @@ #include "drive.h" -class SMART { +class SMART +{ protected: public: - - static void readSMARTData(Drive drive); - + static void readSMARTData(Drive* drive); private: SMART(void); @@ -39,9 +38,6 @@ private: static uint32_t errorCount; static uint32_t powerOnHours; static uint32_t powerCycle; - }; - - #endif // SMART_H_ \ No newline at end of file diff --git a/vcCodium.code-workspace b/vcCodium.code-workspace index 772c2aa..a924abd 100644 --- a/vcCodium.code-workspace +++ b/vcCodium.code-workspace @@ -10,7 +10,8 @@ "*.tcc": "cpp", "string": "cpp", "unordered_map": "cpp", - "string_view": "cpp" + "string_view": "cpp", + "ostream": "cpp" } } } \ No newline at end of file