changed device model from struct to class

This commit is contained in:
Hendrik Schutter 2020-05-01 22:18:01 +02:00
parent 3547369a49
commit 9482030fc2
6 changed files with 99 additions and 48 deletions

View File

@ -25,6 +25,8 @@ void App::app_logic(void)
{ {
cout << "app logic" << endl; cout << "app logic" << endl;
//Drive* tmp = new Drive("test");
searchDrives(&listDrives); //search for new drives and store them in list searchDrives(&listDrives); //search for new drives and store them in list
filterIgnoredDrives(&listDrives); //filter out ignored drives filterIgnoredDrives(&listDrives); //filter out ignored drives
printDrives(&listDrives); //print currently attached drives printDrives(&listDrives); //print currently attached drives
@ -35,7 +37,7 @@ void App::app_logic(void)
* \param pointer of list <struct drive> *listDrives * \param pointer of list <struct drive> *listDrives
* \return void * \return void
*/ */
void App::searchDrives(list <struct drive> *listDrives) void App::searchDrives(list <Drive> *listDrives)
{ {
cout << "search drives ..." << endl; cout << "search drives ..." << endl;
char * cLine = NULL; char * cLine = NULL;
@ -52,12 +54,11 @@ void App::searchDrives(list <struct drive> *listDrives)
{ {
if (string(cLine).find("/dev/sd") != string::npos) if (string(cLine).find("/dev/sd") != string::npos)
{ {
struct drive tmpDrive; //struct drive tmpDrive;
tmpDrive.u32ErrorCount = 0U;
tmpDrive.u32PowerOnHours = 0U; Drive* tmpDrive = new Drive(string(cLine).substr (2,8));
tmpDrive.u32SpinUpCount = 0U;
tmpDrive.sPath = string(cLine).substr (2,8); listDrives->push_back(*tmpDrive);
listDrives->push_back(tmpDrive);
} }
} }
fclose(outputfileHwinfo); fclose(outputfileHwinfo);
@ -68,7 +69,7 @@ void App::searchDrives(list <struct drive> *listDrives)
* \param pointer of list <struct drive> *listDrives * \param pointer of list <struct drive> *listDrives
* \return void * \return void
*/ */
void App::filterIgnoredDrives(list <struct drive> *listDrives) void App::filterIgnoredDrives(list <Drive> *listDrives)
{ {
string sDelimiter = ":"; string sDelimiter = ":";
string sIgnoredDrivePath; string sIgnoredDrivePath;
@ -101,18 +102,18 @@ void App::filterIgnoredDrives(list <struct drive> *listDrives)
for(auto row : vtlIgnoredDevices) for(auto row : vtlIgnoredDevices)
{ {
//cout << get<0>(row) << " is " << get<1>(row) << endl; //cout << get<0>(row) << " is " << get<1>(row) << endl;
list <struct drive>::iterator it; list <Drive>::iterator it;
// loop through found drives // loop through found drives
for (it = listDrives->begin(); it != listDrives->end(); ++it) for (it = listDrives->begin(); it != listDrives->end(); ++it)
{ {
string sUUID; 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; // cout << "Same drive path found" << endl;
char * cLine = NULL; char * cLine = NULL;
size_t len = 0; size_t len = 0;
string sCMD = "./blkid "; string sCMD = "./blkid ";
sCMD.append(it->sPath); sCMD.append(it->getPath());
// cout << "cmd: " << sCMD << endl; // cout << "cmd: " << sCMD << endl;
FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive
if (outputfileBlkid == NULL) if (outputfileBlkid == NULL)
@ -136,7 +137,7 @@ void App::filterIgnoredDrives(list <struct drive> *listDrives)
if (get<1>(row).compare(sUUID)) //compare uuid from ignore file and uuid from drive 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 exit(EXIT_FAILURE); // exit to prevent accidentally shred a system drive
} }
else else
@ -154,20 +155,20 @@ void App::filterIgnoredDrives(list <struct drive> *listDrives)
* \param pointer of list <struct drive> *listDrives * \param pointer of list <struct drive> *listDrives
* \return void * \return void
*/ */
void App::printDrives(list <struct drive> *listDrives) void App::printDrives(list <Drive> *listDrives)
{ {
cout << "------------DRIVES---------------" << endl; cout << "------------DRIVES---------------" << endl;
list <struct drive>::iterator it; list <Drive>::iterator it;
for (it = listDrives->begin(); it != listDrives->end(); ++it) for (it = listDrives->begin(); it != listDrives->end(); ++it)
{ {
cout << "Path: " << it->sPath << endl; cout << "Path: " << it->getPath() << endl;
cout << "Model: " << it->sModel << endl; cout << "Model: " << it->getModel() << endl;
cout << "Manufacturer: " << it->sManufacturer << endl; cout << "Manufacturer: " << it->getManufacturer() << endl;
cout << "Capacity: " << it->sCapacity << endl; cout << "Capacity: " << it->getCapacity() << endl;
cout << "Serial: " << it->sSerial << endl; cout << "Serial: " << it->getSerial() << endl;
cout << "PowerOnHours: " << it->u32PowerOnHours << endl; cout << "PowerOnHours: " << it->getPowerOnHours() << endl;
cout << "SpinUpCount: " << it->u32SpinUpCount << endl; cout << "SpinUpCount: " << it->getSpinUpCount() << endl;
cout << "ErrorCount: " << it->u32ErrorCount << endl; cout << "ErrorCount: " << it->getErrorCount() << endl;
cout << endl; cout << endl;
} }
cout << "---------------------------------" << endl; cout << "---------------------------------" << endl;

View File

@ -21,11 +21,11 @@ public:
private: private:
list <struct drive> listDrives; //stores all drive data list <Drive> listDrives; //stores all drive data
void searchDrives(list <struct drive> *listDrives); void searchDrives(list <Drive> *listDrives);
void printDrives(list <struct drive> *listDrives); void printDrives(list <Drive> *listDrives);
void filterIgnoredDrives(list <struct drive> *listDrives); void filterIgnoredDrives(list <Drive> *listDrives);
}; };

View File

@ -1,13 +1,49 @@
/** /**
* @file drive.cpp * @file drive.cpp
* @brief * @brief represent physical drive
* @author hendrik schutter * @author hendrik schutter
* @date * @date 01.05.2020
*/ */
#include "drive.h" #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;
} }

View File

@ -1,8 +1,8 @@
/** /**
* @file drive.h * @file drive.h
* @brief represent * @brief represent physical drive
* @author hendrik schutter * @author hendrik schutter
* @date 16.12.2017 * @date 01.05.2020
*/ */
#ifndef DRIVE_H_ #ifndef DRIVE_H_
@ -10,9 +10,32 @@
#include "refurbishingHddTool.h" #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 sPath;
string sManufacturer; string sManufacturer;
string sModel; string sModel;
@ -21,20 +44,7 @@ struct drive
uint32_t u32ErrorCount; uint32_t u32ErrorCount;
uint32_t u32PowerOnHours; uint32_t u32PowerOnHours;
uint32_t u32SpinUpCount; uint32_t u32SpinUpCount;
};
class Drive {
protected:
public:
Drive(void);
}; };
#endif // DRIVE_H_ #endif // DRIVE_H_

Binary file not shown.

View File

@ -4,5 +4,9 @@
"path": "." "path": "."
} }
], ],
"settings": {} "settings": {
"files.associations": {
"iostream": "cpp"
}
}
} }