added states for tasks
This commit is contained in:
parent
f4726bf08c
commit
c2ab7c1c7f
@ -12,6 +12,29 @@
|
|||||||
|
|
||||||
class Drive
|
class Drive
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum TaskState {NONE,
|
||||||
|
SHRED_SELECTED,
|
||||||
|
SHRED_ACTIVE,
|
||||||
|
SHRED_FINISHED,
|
||||||
|
DELETE_SELECTED,
|
||||||
|
DELETE_ACTIVE,
|
||||||
|
DELETE_FINISHED
|
||||||
|
} state;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
uint8_t u8TaskPercentage = 0U; //in percent for Shred (1 to 100) and Delete (1 OR 100)
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -42,18 +65,11 @@ public:
|
|||||||
string sPowerOnHoursToText();
|
string sPowerOnHoursToText();
|
||||||
string sPowerCyclesToText();
|
string sPowerCyclesToText();
|
||||||
|
|
||||||
|
void setTaskPercentage(uint8_t u8TaskPercentage);
|
||||||
|
uint8_t getTaskPercentage(void);
|
||||||
|
|
||||||
|
|
||||||
private:
|
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;
|
|
||||||
uint32_t u32ShredPercentage = 0U; //in percent
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#define WORSE_HOURS 19200 //mark drive if at this limit or beyond
|
#define WORSE_HOURS 19200 //mark drive if at this limit or beyond
|
||||||
#define WORSE_POWERUP 4000 //mark drive if at this limit or beyond
|
#define WORSE_POWERUP 4000 //mark drive if at this limit or beyond
|
||||||
|
|
||||||
|
#define SELECTED_DRIVE vecDrives.at(i32SelectedEntry)
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -58,11 +60,15 @@ private:
|
|||||||
static void searchDrives(vector <Drive>* pvecDrives);
|
static void searchDrives(vector <Drive>* pvecDrives);
|
||||||
static void printDrives(vector <Drive>* pvecDrives);
|
static void printDrives(vector <Drive>* pvecDrives);
|
||||||
static void filterIgnoredDrives(vector <Drive>* pvecDrives);
|
static void filterIgnoredDrives(vector <Drive>* pvecDrives);
|
||||||
|
static void filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives);
|
||||||
static void addSMARTData(vector <Drive>* pvecDrives);
|
static void addSMARTData(vector <Drive>* pvecDrives);
|
||||||
static void ThreadScannDevices();
|
static void ThreadScannDevices();
|
||||||
static void ThreadUserInput();
|
static void ThreadUserInput();
|
||||||
static void handleArrowKey(TUI::UserInput userInput);
|
static void handleArrowKey(TUI::UserInput userInput);
|
||||||
static void filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives);
|
static void handleEnter();
|
||||||
|
static void handleESC();
|
||||||
|
static void handleAbort();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,12 +23,21 @@ protected:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
enum UserInput { UpKey, DownKey, Abort, Shred, Delete, Enter, ESC, Undefined};
|
enum UserInput { UpKey, DownKey, Abort, Shred, Delete, Enter, ESC, Undefined};
|
||||||
|
struct MenuState
|
||||||
|
{
|
||||||
|
bool bAbort;
|
||||||
|
bool bShred;
|
||||||
|
bool bDelete;
|
||||||
|
bool bConfirmAbort;
|
||||||
|
bool bConfirmShred;
|
||||||
|
bool bConfirmDelete;
|
||||||
|
};
|
||||||
|
|
||||||
TUI(void);
|
TUI(void);
|
||||||
|
|
||||||
static void initTUI();
|
static void initTUI();
|
||||||
|
|
||||||
void updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry);
|
void updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry, struct MenuState menustate);
|
||||||
|
|
||||||
static enum UserInput readUserInput();
|
static enum UserInput readUserInput();
|
||||||
|
|
||||||
@ -40,14 +49,14 @@ private:
|
|||||||
WINDOW* detailview;
|
WINDOW* detailview;
|
||||||
WINDOW* overview;
|
WINDOW* overview;
|
||||||
WINDOW* systemview;
|
WINDOW* systemview;
|
||||||
|
WINDOW* menuview;
|
||||||
|
|
||||||
static void centerTitle(WINDOW *pwin, const char * title);
|
static void centerTitle(WINDOW *pwin, const char * title);
|
||||||
static WINDOW *createOverViewWindow( int iXSize, int iYSize);
|
static WINDOW *createOverViewWindow( int iXSize, int iYSize);
|
||||||
static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive drive);
|
static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive drive);
|
||||||
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,string sModelFamily, string sModelName, string sCapacity, bool bSelected);
|
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,string sModelFamily, string sModelName, string sCapacity, bool bSelected);
|
||||||
static WINDOW *createSystemStats(int iXSize, int iYSize, int iYStart);
|
static WINDOW *createSystemStats(int iXSize, int iYSize, int iYStart);
|
||||||
|
static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TUI_H_
|
#endif // TUI_H_
|
@ -49,10 +49,9 @@ void TUI::initTUI()
|
|||||||
init_pair(COLOR_AREA_DETAIL, COLOR_BLACK, COLOR_WHITE);
|
init_pair(COLOR_AREA_DETAIL, COLOR_BLACK, COLOR_WHITE);
|
||||||
|
|
||||||
mvprintw(0, 2, "reHDD - HDD refurbishing tool - GPL 3.0 ");
|
mvprintw(0, 2, "reHDD - HDD refurbishing tool - GPL 3.0 ");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TUI::updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry)
|
void TUI::updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry, struct MenuState menustate)
|
||||||
{
|
{
|
||||||
int stdscrX, stdscrY;
|
int stdscrX, stdscrY;
|
||||||
getmaxyx(stdscr, stdscrY, stdscrX);
|
getmaxyx(stdscr, stdscrY, stdscrX);
|
||||||
@ -68,6 +67,9 @@ void TUI::updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry)
|
|||||||
systemview=createSystemStats((int)(stdscrX/3), 10, (stdscrY-11));
|
systemview=createSystemStats((int)(stdscrX/3), 10, (stdscrY-11));
|
||||||
wrefresh(systemview);
|
wrefresh(systemview);
|
||||||
|
|
||||||
|
menuview=createMenuView(((stdscrX)-(int)(stdscrX/3)-7), 10, (int)(stdscrX/3)+5,(stdscrY-11), menustate);
|
||||||
|
wrefresh(menuview);
|
||||||
|
|
||||||
vector <Drive>::iterator it;
|
vector <Drive>::iterator it;
|
||||||
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
|
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
|
||||||
{
|
{
|
||||||
@ -80,7 +82,7 @@ void TUI::updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry)
|
|||||||
if(i32SelectedEntry == (it - pvecDrives->begin()))
|
if(i32SelectedEntry == (it - pvecDrives->begin()))
|
||||||
{
|
{
|
||||||
bSelectedEntry = true;
|
bSelectedEntry = true;
|
||||||
detailview=createDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-3), (int)(stdscrX/3)+5, pvecDrives->at((it - pvecDrives->begin())));
|
detailview=createDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-15), (int)(stdscrX/3)+5, pvecDrives->at((it - pvecDrives->begin())));
|
||||||
wrefresh(detailview);
|
wrefresh(detailview);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +245,8 @@ WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,
|
|||||||
return newWindow;
|
return newWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
WINDOW* TUI::createSystemStats(int iXSize, int iYSize, int iYStart){
|
WINDOW* TUI::createSystemStats(int iXSize, int iYSize, int iYStart)
|
||||||
|
{
|
||||||
|
|
||||||
WINDOW *newWindow;
|
WINDOW *newWindow;
|
||||||
newWindow = newwin(iYSize, iXSize, iYStart, 2);
|
newWindow = newwin(iYSize, iXSize, iYStart, 2);
|
||||||
@ -266,3 +269,46 @@ WINDOW *newWindow;
|
|||||||
keypad(newWindow, TRUE);
|
keypad(newWindow, TRUE);
|
||||||
return newWindow;
|
return newWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WINDOW* TUI::createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate)
|
||||||
|
{
|
||||||
|
|
||||||
|
WINDOW *newWindow;
|
||||||
|
newWindow = newwin(iYSize, iXSize, iYStart, iXStart);
|
||||||
|
|
||||||
|
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_OVERVIEW));
|
||||||
|
box(newWindow, ACS_VLINE, ACS_HLINE);
|
||||||
|
|
||||||
|
centerTitle(newWindow, "Controls");
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t u16Line = 2;
|
||||||
|
|
||||||
|
if(menustate.bAbort)
|
||||||
|
{
|
||||||
|
mvwaddstr(newWindow,u16Line++, 3, "Press A for Abort");
|
||||||
|
}
|
||||||
|
if(menustate.bShred)
|
||||||
|
{
|
||||||
|
mvwaddstr(newWindow,u16Line++, 3, "Press S for Shred");
|
||||||
|
}
|
||||||
|
if(menustate.bDelete)
|
||||||
|
{
|
||||||
|
mvwaddstr(newWindow,u16Line++, 3, "Press D for Delete");
|
||||||
|
}
|
||||||
|
if (menustate.bConfirmAbort)
|
||||||
|
{
|
||||||
|
mvwaddstr(newWindow,u16Line++, 3, "Press Enter to confirm Abort or ESC to return");
|
||||||
|
}
|
||||||
|
if (menustate.bConfirmShred)
|
||||||
|
{
|
||||||
|
mvwaddstr(newWindow,u16Line++, 3, "Press Enter to confirm Shred or ESC to return");
|
||||||
|
}
|
||||||
|
if (menustate.bConfirmDelete)
|
||||||
|
{
|
||||||
|
mvwaddstr(newWindow,u16Line++, 3, "Press Enter to confirm Delete or ESC to return");
|
||||||
|
}
|
||||||
|
|
||||||
|
keypad(newWindow, TRUE);
|
||||||
|
return newWindow;
|
||||||
|
}
|
||||||
|
@ -86,6 +86,19 @@ string Drive::sPowerCyclesToText()
|
|||||||
return to_string(getPowerCycles());
|
return to_string(getPowerCycles());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Drive::setTaskPercentage(uint8_t u8TaskPercentage)
|
||||||
|
{
|
||||||
|
if((u8TaskPercentage >= 0) && (u8TaskPercentage <= 100))
|
||||||
|
{
|
||||||
|
this->u8TaskPercentage = u8TaskPercentage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uint8_t Drive::getTaskPercentage(void)
|
||||||
|
{
|
||||||
|
return this->u8TaskPercentage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief set S.M.A.R.T. values in model
|
* \brief set S.M.A.R.T. values in model
|
||||||
* \param string modelFamily
|
* \param string modelFamily
|
||||||
|
@ -26,6 +26,8 @@ static int32_t i32SelectedEntry;
|
|||||||
|
|
||||||
static fd_set selectSet;
|
static fd_set selectSet;
|
||||||
|
|
||||||
|
static struct TUI::MenuState menustate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief app constructor
|
* \brief app constructor
|
||||||
* \param void
|
* \param void
|
||||||
@ -60,7 +62,6 @@ void reHDD::app_logic(void)
|
|||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
|
||||||
select(FD_SETSIZE, &selectSet, NULL, NULL, NULL);
|
select(FD_SETSIZE, &selectSet, NULL, NULL, NULL);
|
||||||
|
|
||||||
if( FD_ISSET(fdSearchDrives[0], &selectSet))
|
if( FD_ISSET(fdSearchDrives[0], &selectSet))
|
||||||
@ -74,9 +75,7 @@ void reHDD::app_logic(void)
|
|||||||
//printDrives(&vecDrives);
|
//printDrives(&vecDrives);
|
||||||
//TODO update UI
|
//TODO update UI
|
||||||
|
|
||||||
ui->updateTUI(&vecDrives, i32SelectedEntry);
|
ui->updateTUI(&vecDrives, i32SelectedEntry, menustate);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (FD_ISSET(fdWhipe[0], &selectSet))
|
else if (FD_ISSET(fdWhipe[0], &selectSet))
|
||||||
{
|
{
|
||||||
@ -115,27 +114,45 @@ void reHDD::ThreadUserInput()
|
|||||||
case TUI::UserInput::DownKey:
|
case TUI::UserInput::DownKey:
|
||||||
//cout << "Down" << endl;
|
//cout << "Down" << endl;
|
||||||
handleArrowKey(TUI::UserInput::DownKey);
|
handleArrowKey(TUI::UserInput::DownKey);
|
||||||
ui->updateTUI(&vecDrives, i32SelectedEntry);
|
ui->updateTUI(&vecDrives, i32SelectedEntry, menustate);
|
||||||
break;
|
break;
|
||||||
case TUI::UserInput::UpKey:
|
case TUI::UserInput::UpKey:
|
||||||
//cout << "Up" << endl;
|
//cout << "Up" << endl;
|
||||||
handleArrowKey(TUI::UserInput::UpKey);
|
handleArrowKey(TUI::UserInput::UpKey);
|
||||||
ui->updateTUI(&vecDrives, i32SelectedEntry);
|
ui->updateTUI(&vecDrives, i32SelectedEntry, menustate);
|
||||||
break;
|
break;
|
||||||
case TUI::UserInput::Undefined:
|
case TUI::UserInput::Undefined:
|
||||||
//cout << "Undefined" << endl;
|
//cout << "Undefined" << endl;
|
||||||
break;
|
break;
|
||||||
case TUI::UserInput::Abort:
|
case TUI::UserInput::Abort:
|
||||||
//cout << "Abort" << endl;
|
//cout << "Abort" << endl;
|
||||||
|
|
||||||
|
handleAbort();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case TUI::UserInput::Delete:
|
case TUI::UserInput::Delete:
|
||||||
//cout << "Delete" << endl;
|
//cout << "Delete" << endl;
|
||||||
|
|
||||||
|
if(SELECTED_DRIVE.state == Drive::NONE)
|
||||||
|
{
|
||||||
|
|
||||||
|
SELECTED_DRIVE.state = Drive::DELETE_SELECTED;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case TUI::UserInput::Shred:
|
case TUI::UserInput::Shred:
|
||||||
//cout << "Shred" << endl;
|
//cout << "Shred" << endl;
|
||||||
|
|
||||||
|
if(SELECTED_DRIVE.state == Drive::NONE)
|
||||||
|
{
|
||||||
|
|
||||||
|
SELECTED_DRIVE.state = Drive::SHRED_SELECTED;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case TUI::UserInput::Enter:
|
case TUI::UserInput::Enter:
|
||||||
//cout << "Enter" << endl;
|
//cout << "Enter" << endl;
|
||||||
|
handleEnter();
|
||||||
break;
|
break;
|
||||||
case TUI::UserInput::ESC:
|
case TUI::UserInput::ESC:
|
||||||
//cout << "ESC" << endl;
|
//cout << "ESC" << endl;
|
||||||
@ -161,13 +178,15 @@ void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecN
|
|||||||
{
|
{
|
||||||
bOldDriveIsOffline = false;
|
bOldDriveIsOffline = false;
|
||||||
// cout << "already online drive found: " << itOld->getPath() << endl;
|
// cout << "already online drive found: " << itOld->getPath() << endl;
|
||||||
|
itNew->state = itOld->state;
|
||||||
|
itNew->setTaskPercentage(itOld->getTaskPercentage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bOldDriveIsOffline == true)
|
if(bOldDriveIsOffline == true)
|
||||||
{
|
{
|
||||||
//cout << "offline drive found: " << itOld->getPath() << endl;
|
//cout << "offline drive found: " << itOld->getPath() << endl;
|
||||||
//TODO kill wipe thread
|
//TODO kill task thread if running
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,4 +375,66 @@ void reHDD::handleArrowKey(TUI::UserInput userInput)
|
|||||||
i32SelectedEntry = 0;
|
i32SelectedEntry = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_ACTIVE || SELECTED_DRIVE.state == Drive::TaskState::DELETE_ACTIVE)
|
||||||
|
{
|
||||||
|
//task for drive is running --> don´t show more task options
|
||||||
|
menustate.bAbort = true; //activate abort
|
||||||
|
menustate.bConfirmAbort = false;
|
||||||
|
menustate.bDelete = false;
|
||||||
|
menustate.bShred = false;
|
||||||
|
menustate.bConfirmDelete = false;
|
||||||
|
menustate.bConfirmShred = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//no task for drive is running --> show more task options
|
||||||
|
menustate.bAbort = false; //deactivate abort
|
||||||
|
menustate.bConfirmAbort = false;
|
||||||
|
menustate.bDelete = true;
|
||||||
|
menustate.bShred = true;
|
||||||
|
menustate.bConfirmDelete = false;
|
||||||
|
menustate.bConfirmShred = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void reHDD::handleEnter()
|
||||||
|
{
|
||||||
|
if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_SELECTED)
|
||||||
|
{
|
||||||
|
SELECTED_DRIVE.state = Drive::TaskState::SHRED_ACTIVE;
|
||||||
|
//TODO start shredding
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SELECTED_DRIVE.state == Drive::TaskState::DELETE_SELECTED)
|
||||||
|
{
|
||||||
|
SELECTED_DRIVE.state = Drive::TaskState::DELETE_ACTIVE;
|
||||||
|
//TODO start deleting
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void reHDD::handleESC()
|
||||||
|
{
|
||||||
|
if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_SELECTED)
|
||||||
|
{
|
||||||
|
SELECTED_DRIVE.state = Drive::TaskState::NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SELECTED_DRIVE.state == Drive::TaskState::DELETE_SELECTED)
|
||||||
|
{
|
||||||
|
SELECTED_DRIVE.state = Drive::TaskState::NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void reHDD::handleAbort()
|
||||||
|
{
|
||||||
|
if(SELECTED_DRIVE.state == Drive::SHRED_ACTIVE || SELECTED_DRIVE.state == Drive::DELETE_ACTIVE )
|
||||||
|
{
|
||||||
|
// TODO cancle shred or delete
|
||||||
|
SELECTED_DRIVE.state = Drive::NONE;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user