diff --git a/src/app.cpp b/src/app.cpp index fd3ff36..d7fdc92 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -25,6 +25,8 @@ 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 printDrives(&listDrives); //print currently attached drives @@ -35,7 +37,7 @@ void App::app_logic(void) * \param pointer of list *listDrives * \return void */ -void App::searchDrives(list *listDrives) +void App::searchDrives(list *listDrives) { cout << "search drives ..." << endl; char * cLine = NULL; @@ -52,12 +54,11 @@ void App::searchDrives(list *listDrives) { if (string(cLine).find("/dev/sd") != string::npos) { - struct drive tmpDrive; - tmpDrive.u32ErrorCount = 0U; - tmpDrive.u32PowerOnHours = 0U; - tmpDrive.u32SpinUpCount = 0U; - tmpDrive.sPath = string(cLine).substr (2,8); - listDrives->push_back(tmpDrive); + //struct drive tmpDrive; + + Drive* tmpDrive = new Drive(string(cLine).substr (2,8)); + + listDrives->push_back(*tmpDrive); } } fclose(outputfileHwinfo); @@ -68,7 +69,7 @@ void App::searchDrives(list *listDrives) * \param pointer of list *listDrives * \return void */ -void App::filterIgnoredDrives(list *listDrives) +void App::filterIgnoredDrives(list *listDrives) { string sDelimiter = ":"; string sIgnoredDrivePath; @@ -101,18 +102,18 @@ void App::filterIgnoredDrives(list *listDrives) for(auto row : vtlIgnoredDevices) { //cout << get<0>(row) << " is " << get<1>(row) << endl; - list ::iterator it; + list ::iterator it; // loop through found drives for (it = listDrives->begin(); it != listDrives->end(); ++it) { string sUUID; - if (!get<0>(row).compare(it->sPath)) //find same drive based on path + if (!get<0>(row).compare(it->getPath())) //find same drive based on path { // cout << "Same drive path found" << endl; char * cLine = NULL; size_t len = 0; string sCMD = "./blkid "; - sCMD.append(it->sPath); + sCMD.append(it->getPath()); // cout << "cmd: " << sCMD << endl; FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive if (outputfileBlkid == NULL) @@ -136,7 +137,7 @@ void App::filterIgnoredDrives(list *listDrives) if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive { - cout << "[ERROR] different uuid found than in ignore file:" << it->sPath << endl; + cout << "[ERROR] different uuid found than in ignore file:" << it->getPath() << endl; exit(EXIT_FAILURE); // exit to prevent accidentally shred a system drive } else @@ -154,20 +155,20 @@ void App::filterIgnoredDrives(list *listDrives) * \param pointer of list *listDrives * \return void */ -void App::printDrives(list *listDrives) +void App::printDrives(list *listDrives) { cout << "------------DRIVES---------------" << endl; - list ::iterator it; + list ::iterator it; for (it = listDrives->begin(); it != listDrives->end(); ++it) { - cout << "Path: " << it->sPath << endl; - cout << "Model: " << it->sModel << endl; - cout << "Manufacturer: " << it->sManufacturer << endl; - cout << "Capacity: " << it->sCapacity << endl; - cout << "Serial: " << it->sSerial << endl; - cout << "PowerOnHours: " << it->u32PowerOnHours << endl; - cout << "SpinUpCount: " << it->u32SpinUpCount << endl; - cout << "ErrorCount: " << it->u32ErrorCount << endl; + cout << "Path: " << it->getPath() << endl; + cout << "Model: " << it->getModel() << endl; + cout << "Manufacturer: " << it->getManufacturer() << endl; + cout << "Capacity: " << it->getCapacity() << endl; + cout << "Serial: " << it->getSerial() << endl; + cout << "PowerOnHours: " << it->getPowerOnHours() << endl; + cout << "SpinUpCount: " << it->getSpinUpCount() << endl; + cout << "ErrorCount: " << it->getErrorCount() << endl; cout << endl; } cout << "---------------------------------" << endl; diff --git a/src/app.h b/src/app.h index 062ce73..c401972 100644 --- a/src/app.h +++ b/src/app.h @@ -21,11 +21,11 @@ public: private: - list listDrives; //stores all drive data + list listDrives; //stores all drive data - void searchDrives(list *listDrives); - void printDrives(list *listDrives); - void filterIgnoredDrives(list *listDrives); + void searchDrives(list *listDrives); + void printDrives(list *listDrives); + void filterIgnoredDrives(list *listDrives); }; diff --git a/src/drive.cpp b/src/drive.cpp index 95bd3d2..5339491 100644 --- a/src/drive.cpp +++ b/src/drive.cpp @@ -1,13 +1,49 @@ /** * @file drive.cpp - * @brief + * @brief represent physical drive * @author hendrik schutter - * @date + * @date 01.05.2020 */ #include "drive.h" -Drive::Drive(void) { - cout << "created drive" << endl; + +string Drive::getPath(void) +{ + return sPath; +} + +string Drive::getManufacturer(void) +{ + return sManufacturer; +} + +string Drive::getModel(void) +{ + return sModel; +} + +string Drive::getSerial(void) +{ + return sSerial; +} + +string Drive::getCapacity(void) +{ + return sCapacity; +} + +uint32_t Drive::getErrorCount(void) +{ + return u32ErrorCount; +} +uint32_t Drive::getPowerOnHours(void) +{ + return u32PowerOnHours; +} + +uint32_t Drive::getSpinUpCount(void) +{ + return u32SpinUpCount; } diff --git a/src/drive.h b/src/drive.h index 65bd343..c0bfd06 100644 --- a/src/drive.h +++ b/src/drive.h @@ -1,8 +1,8 @@ /** * @file drive.h - * @brief represent + * @brief represent physical drive * @author hendrik schutter - * @date 16.12.2017 + * @date 01.05.2020 */ #ifndef DRIVE_H_ @@ -10,9 +10,32 @@ #include "refurbishingHddTool.h" +class Drive { +protected: -struct drive -{ +public: + Drive(string path) { + sPath = path; + } + + string getPath(void); + string getManufacturer(void); + string getModel(void); + string getSerial(void); + string getCapacity(void); + uint32_t getErrorCount(void); + uint32_t getPowerOnHours(void); + uint32_t getSpinUpCount(void); + + void setDriveSMARTData( string manufacturer, + string model, + string serial, + string capacity, + uint32_t errorCount, + uint32_t powerOnHours, + uint32_t spinUpCount); + +private: string sPath; string sManufacturer; string sModel; @@ -21,20 +44,7 @@ struct drive uint32_t u32ErrorCount; uint32_t u32PowerOnHours; uint32_t u32SpinUpCount; -}; - - -class Drive { -protected: - - -public: - Drive(void); }; - - - - #endif // DRIVE_H_ \ No newline at end of file diff --git a/src/refurbishingHddTool b/src/refurbishingHddTool index f328664..6bb29a1 100755 Binary files a/src/refurbishingHddTool and b/src/refurbishingHddTool differ diff --git a/vcCodium.code-workspace b/vcCodium.code-workspace index 876a149..a921fa8 100644 --- a/vcCodium.code-workspace +++ b/vcCodium.code-workspace @@ -4,5 +4,9 @@ "path": "." } ], - "settings": {} + "settings": { + "files.associations": { + "iostream": "cpp" + } + } } \ No newline at end of file