project cleanup
This commit is contained in:
40
src/app.h
40
src/app.h
@ -1,40 +0,0 @@
|
||||
/**
|
||||
* @file app.h
|
||||
* @brief app logic
|
||||
* @author hendrik schutter
|
||||
* @date 01.05.2020
|
||||
*/
|
||||
|
||||
#ifndef APP_H_
|
||||
#define APP_H_
|
||||
|
||||
#include "refurbishingHddTool.h"
|
||||
#include "drive.h"
|
||||
#include "smart.h"
|
||||
|
||||
template <typename T, typename I>
|
||||
T* iterator_to_pointer(I i)
|
||||
{
|
||||
return (&(*i));
|
||||
}
|
||||
|
||||
class App
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
App(void);
|
||||
void app_logic();
|
||||
|
||||
private:
|
||||
|
||||
vector <Drive> vecDrives; //stores all drive data
|
||||
|
||||
void searchDrives(vector <Drive>* pvecDrives);
|
||||
void printDrives(vector <Drive>* pvecDrives);
|
||||
void filterIgnoredDrives(vector <Drive>* pvecDrives);
|
||||
void addSMARTData(vector <Drive>* pvecDrives);
|
||||
};
|
||||
|
||||
|
||||
#endif // APP_H_
|
@ -1,11 +1,11 @@
|
||||
/**
|
||||
* @file drive.cpp
|
||||
* @brief represent physical drive
|
||||
* @author hendrik schutter
|
||||
* @date 01.05.2020
|
||||
* @file drive.cpp
|
||||
* @brief represent physical drive
|
||||
* @author hendrik schutter
|
||||
* @date 01.05.2020
|
||||
*/
|
||||
|
||||
#include "drive.h"
|
||||
#include "../include/reHDD.h"
|
||||
|
||||
string Drive::getPath(void)
|
||||
{
|
||||
|
51
src/drive.h
51
src/drive.h
@ -1,51 +0,0 @@
|
||||
/**
|
||||
* @file drive.h
|
||||
* @brief represent physical drive
|
||||
* @author hendrik schutter
|
||||
* @date 01.05.2020
|
||||
*/
|
||||
|
||||
#ifndef DRIVE_H_
|
||||
#define DRIVE_H_
|
||||
|
||||
#include "refurbishingHddTool.h"
|
||||
|
||||
class Drive
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
Drive(string path)
|
||||
{
|
||||
this->sPath = path;
|
||||
}
|
||||
|
||||
string getPath(void);
|
||||
string getModelFamily(void);
|
||||
string getModelName(void);
|
||||
string getSerial(void);
|
||||
uint64_t getCapacity(void); //in byte
|
||||
uint32_t getErrorCount(void);
|
||||
uint32_t getPowerOnHours(void); //in hours
|
||||
uint32_t getPowerCycles(void);
|
||||
|
||||
void setDriveSMARTData( string modelFamily,
|
||||
string modelName,
|
||||
string serial,
|
||||
uint64_t capacity,
|
||||
uint32_t errorCount,
|
||||
uint32_t powerOnHours,
|
||||
uint32_t powerCycles);
|
||||
|
||||
private:
|
||||
string sPath;
|
||||
string sModelFamily;
|
||||
string sModelName;
|
||||
string sSerial;
|
||||
uint64_t u64Capacity = 0U; //in byte
|
||||
uint32_t u32ErrorCount = 0U;
|
||||
uint32_t u32PowerOnHours = 0U; //in hours
|
||||
uint32_t u32PowerCycles = 0U;
|
||||
};
|
||||
|
||||
#endif // DRIVE_H_
|
BIN
src/hwinfo
BIN
src/hwinfo
Binary file not shown.
@ -1,3 +0,0 @@
|
||||
/dev/sda:508ef27d-5039-4e8b-9e2c-22d7528b7149
|
||||
/dev/sdb:07f4ad14-c4b6-46e7-9cdf-3cfa9841d53d
|
||||
/dev/sdc:4673974d-1af2-44fd-996b-a2d8e4c43d9a
|
@ -5,9 +5,7 @@
|
||||
* @date 01.05.2020
|
||||
*/
|
||||
|
||||
#include "refurbishingHddTool.h"
|
||||
#include "app.h"
|
||||
|
||||
#include "../include/reHDD.h"
|
||||
|
||||
/**
|
||||
* \brief app entry point
|
||||
@ -18,8 +16,7 @@ int main(void)
|
||||
{
|
||||
cout << "refurbishingHddTool" << endl;
|
||||
|
||||
App* app = new App();
|
||||
reHDD* app = new reHDD();
|
||||
app->app_logic();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
|
||||
deviceData getDeviceData(string path) {
|
||||
|
||||
|
||||
|
||||
struct deviceData hdd;
|
||||
|
||||
|
||||
|
||||
size_t len = 0; //lenght of found line
|
||||
char * cLine = NULL; //found line
|
||||
|
||||
string comand = ("./smartctl -a " + path);
|
||||
const char *cComand = comand.c_str();
|
||||
|
||||
FILE* outputfileSmart = popen(cComand, "r");
|
||||
|
||||
|
||||
|
||||
while ((getline(&cLine, &len, outputfileSmart)) != -1) {
|
||||
|
||||
|
||||
|
||||
string line = string(cLine);
|
||||
|
||||
cout << line << "XYZ\n";
|
||||
|
||||
string search ("Device Model:");
|
||||
|
||||
size_t found = line.find(search);
|
||||
|
||||
if (found!=string::npos) {
|
||||
|
||||
int lenght = line.length(); //lenght of line
|
||||
|
||||
|
||||
string str3 (":");
|
||||
found = line.find(str3);
|
||||
|
||||
cout << "Found1: " << found << endl;
|
||||
|
||||
for(int i = (found+1); i < lenght; i++) {
|
||||
|
||||
if(line[i] != ' ') {
|
||||
cout << i << endl;
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
string model = line.substr (found, lenght);
|
||||
|
||||
model = removeLastNewLine(model);
|
||||
|
||||
cout << model << endl;
|
||||
|
||||
return hdd;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fclose(outputfileSmart);
|
||||
|
||||
return hdd;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
string removeLastNewLine(string s) {
|
||||
if (!s.empty() && s[s.length()-1] == '\n') {
|
||||
s.erase(s.length()-1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
*/
|
17
src/makefile
17
src/makefile
@ -1,17 +0,0 @@
|
||||
reHDD: main.o app.o drive.o smart.o
|
||||
g++ -Wall -o reHDD main.o app.o drive.o smart.o
|
||||
|
||||
main.o: main.cpp
|
||||
g++ -c main.cpp
|
||||
|
||||
app.o: app.cpp
|
||||
g++ -c app.cpp
|
||||
|
||||
drive.o: drive.cpp
|
||||
g++ -c drive.cpp
|
||||
|
||||
smart.o: smart.cpp
|
||||
g++ -c smart.cpp
|
||||
|
||||
clean :
|
||||
rm reHDD main.o app.o drive.o smart.o
|
@ -1,18 +1,18 @@
|
||||
/**
|
||||
* @file app.cpp
|
||||
* @brief app logic
|
||||
* @author hendrik schutter
|
||||
* @date 01.05.2020
|
||||
* @file reHDD.cpp
|
||||
* @brief app logic
|
||||
* @author hendrik schutter
|
||||
* @date 01.05.2020
|
||||
*/
|
||||
|
||||
#include "app.h"
|
||||
#include "../include/reHDD.h"
|
||||
|
||||
/**
|
||||
* \brief app constructor
|
||||
* \param void
|
||||
* \return instance of App
|
||||
*/
|
||||
App::App(void)
|
||||
reHDD::reHDD(void)
|
||||
{
|
||||
cout << "created app" << endl;
|
||||
}
|
||||
@ -22,7 +22,7 @@ App::App(void)
|
||||
* \param void
|
||||
* \return void
|
||||
*/
|
||||
void App::app_logic(void)
|
||||
void reHDD::app_logic(void)
|
||||
{
|
||||
cout << "app logic" << endl;
|
||||
|
||||
@ -37,13 +37,13 @@ void App::app_logic(void)
|
||||
* \param pointer of vector <Drive>* pvecDrives
|
||||
* \return void
|
||||
*/
|
||||
void App::searchDrives(vector <Drive>* pvecDrives)
|
||||
void reHDD::searchDrives(vector <Drive>* pvecDrives)
|
||||
{
|
||||
cout << "search drives ..." << endl;
|
||||
char * cLine = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
FILE* outputfileHwinfo = popen("./hwinfo --short --disk", "r");
|
||||
FILE* outputfileHwinfo = popen("./bin_util/hwinfo --short --disk", "r");
|
||||
|
||||
if (outputfileHwinfo == NULL)
|
||||
{
|
||||
@ -66,7 +66,7 @@ void App::searchDrives(vector <Drive>* pvecDrives)
|
||||
* \param pointer of vector <Drive>* pvecDrives
|
||||
* \return void
|
||||
*/
|
||||
void App::filterIgnoredDrives(vector <Drive>* pvecDrives)
|
||||
void reHDD::filterIgnoredDrives(vector <Drive>* pvecDrives)
|
||||
{
|
||||
string sDelimiter = ":";
|
||||
string sIgnoredDrivePath;
|
||||
@ -108,7 +108,7 @@ void App::filterIgnoredDrives(vector <Drive>* pvecDrives)
|
||||
// cout << "Same drive path found" << endl;
|
||||
char * cLine = NULL;
|
||||
size_t len = 0;
|
||||
string sCMD = "./blkid ";
|
||||
string sCMD = "./bin_util/blkid ";
|
||||
sCMD.append(it->getPath());
|
||||
// cout << "cmd: " << sCMD << endl;
|
||||
FILE* outputfileBlkid = popen(sCMD.c_str(), "r"); //get UUID from drive
|
||||
@ -152,7 +152,7 @@ void App::filterIgnoredDrives(vector <Drive>* pvecDrives)
|
||||
* \param pointer of vector <Drive>* pvecDrives
|
||||
* \return void
|
||||
*/
|
||||
void App::printDrives(vector <Drive>* pvecDrives)
|
||||
void reHDD::printDrives(vector <Drive>* pvecDrives)
|
||||
{
|
||||
cout << "------------DRIVES---------------" << endl;
|
||||
vector <Drive>::iterator it;
|
||||
@ -176,7 +176,7 @@ void App::printDrives(vector <Drive>* pvecDrives)
|
||||
* \param pointer of vector <Drive>* pvecDrives
|
||||
* \return void
|
||||
*/
|
||||
void App::addSMARTData(vector <Drive>* pvecDrives)
|
||||
void reHDD::addSMARTData(vector <Drive>* pvecDrives)
|
||||
{
|
||||
vector <Drive>::iterator it;
|
||||
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
|
Binary file not shown.
@ -1,21 +0,0 @@
|
||||
/**
|
||||
* @file refurbishingHddTool.h
|
||||
* @brief represent
|
||||
* @author hendrik schutter
|
||||
* @date 01.05.2020
|
||||
*/
|
||||
|
||||
#ifndef REFURBISHING_HDD_TOOL_H_
|
||||
#define REFURBISHING_HDD_TOOL_H_
|
||||
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
#endif // REFURBISHING_HDD_TOOL_H_
|
@ -1,11 +1,11 @@
|
||||
/**
|
||||
* @file smart.cpp
|
||||
* @brief read S.M.A.R.T values
|
||||
* @author hendrik schutter
|
||||
* @date 01.05.2020
|
||||
* @file smart.cpp
|
||||
* @brief read S.M.A.R.T values
|
||||
* @author hendrik schutter
|
||||
* @date 01.05.2020
|
||||
*/
|
||||
|
||||
#include "smart.h"
|
||||
#include "../include/reHDD.h"
|
||||
|
||||
string SMART::modelFamily;
|
||||
string SMART::modelName;
|
||||
@ -33,7 +33,7 @@ void SMART::readSMARTData(Drive* drive)
|
||||
size_t len = 0; //lenght of found line
|
||||
char* cLine = NULL; //found line
|
||||
|
||||
string sCMD = ("./smartctl --json -a ");
|
||||
string sCMD = ("./bin_util/smartctl --json -a ");
|
||||
sCMD.append(drive->getPath());
|
||||
const char* cpComand = sCMD.c_str();
|
||||
|
||||
|
43
src/smart.h
43
src/smart.h
@ -1,43 +0,0 @@
|
||||
/**
|
||||
* @file smart.h
|
||||
* @brief read S.M.A.R.T values
|
||||
* @author hendrik schutter
|
||||
* @date 01.05.2020
|
||||
*/
|
||||
|
||||
#ifndef SMART_H_
|
||||
#define SMART_H_
|
||||
|
||||
#include "refurbishingHddTool.h"
|
||||
#include "drive.h"
|
||||
|
||||
|
||||
class SMART
|
||||
{
|
||||
protected:
|
||||
|
||||
|
||||
public:
|
||||
static void readSMARTData(Drive* drive);
|
||||
|
||||
private:
|
||||
SMART(void);
|
||||
|
||||
static void parseModelFamily(string sLine);
|
||||
static void parseModelName(string sLine);
|
||||
static void parseSerial(string sLine);
|
||||
static void parseCapacity(string sLine);
|
||||
static void parseErrorCount(string sLine);
|
||||
static void parsePowerOnHours(string sLine);
|
||||
static void parsePowerCycle(string sLine);
|
||||
|
||||
static string modelFamily;
|
||||
static string modelName;
|
||||
static string serial;
|
||||
static uint64_t capacity;
|
||||
static uint32_t errorCount;
|
||||
static uint32_t powerOnHours;
|
||||
static uint32_t powerCycle;
|
||||
};
|
||||
|
||||
#endif // SMART_H_
|
BIN
src/smartctl
BIN
src/smartctl
Binary file not shown.
Reference in New Issue
Block a user