changed device model from struct to class
This commit is contained in:
parent
3547369a49
commit
9482030fc2
45
src/app.cpp
45
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 <struct drive> *listDrives
|
||||
* \return void
|
||||
*/
|
||||
void App::searchDrives(list <struct drive> *listDrives)
|
||||
void App::searchDrives(list <Drive> *listDrives)
|
||||
{
|
||||
cout << "search drives ..." << endl;
|
||||
char * cLine = NULL;
|
||||
@ -52,12 +54,11 @@ void App::searchDrives(list <struct drive> *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 <struct drive> *listDrives)
|
||||
* \param pointer of list <struct drive> *listDrives
|
||||
* \return void
|
||||
*/
|
||||
void App::filterIgnoredDrives(list <struct drive> *listDrives)
|
||||
void App::filterIgnoredDrives(list <Drive> *listDrives)
|
||||
{
|
||||
string sDelimiter = ":";
|
||||
string sIgnoredDrivePath;
|
||||
@ -101,18 +102,18 @@ void App::filterIgnoredDrives(list <struct drive> *listDrives)
|
||||
for(auto row : vtlIgnoredDevices)
|
||||
{
|
||||
//cout << get<0>(row) << " is " << get<1>(row) << endl;
|
||||
list <struct drive>::iterator it;
|
||||
list <Drive>::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 <struct drive> *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 <struct drive> *listDrives)
|
||||
* \param pointer of list <struct drive> *listDrives
|
||||
* \return void
|
||||
*/
|
||||
void App::printDrives(list <struct drive> *listDrives)
|
||||
void App::printDrives(list <Drive> *listDrives)
|
||||
{
|
||||
cout << "------------DRIVES---------------" << endl;
|
||||
list <struct drive>::iterator it;
|
||||
list <Drive>::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;
|
||||
|
@ -21,11 +21,11 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
list <struct drive> listDrives; //stores all drive data
|
||||
list <Drive> listDrives; //stores all drive data
|
||||
|
||||
void searchDrives(list <struct drive> *listDrives);
|
||||
void printDrives(list <struct drive> *listDrives);
|
||||
void filterIgnoredDrives(list <struct drive> *listDrives);
|
||||
void searchDrives(list <Drive> *listDrives);
|
||||
void printDrives(list <Drive> *listDrives);
|
||||
void filterIgnoredDrives(list <Drive> *listDrives);
|
||||
};
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
44
src/drive.h
44
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_
|
Binary file not shown.
@ -4,5 +4,9 @@
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
"settings": {
|
||||
"files.associations": {
|
||||
"iostream": "cpp"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user