display used time to shred drive
This commit is contained in:
parent
818e78796d
commit
48bbad914f
|
@ -37,6 +37,7 @@ private:
|
|||
uint32_t u32PowerCycles = 0U;
|
||||
time_t u32Timestamp = 0U; //unix timestamp for detecting a frozen drive
|
||||
double d32TaskPercentage = 0U; //in percent for Shred (1 to 100)
|
||||
time_t u32TimestampTaskStart = 0U; //unix timestamp for duration of an action
|
||||
|
||||
private:
|
||||
void setTimestamp();
|
||||
|
@ -75,6 +76,9 @@ public:
|
|||
void setTaskPercentage(double d32TaskPercentage);
|
||||
double getTaskPercentage(void);
|
||||
|
||||
void setActionStartTimestamp();
|
||||
time_t getActionStartTimestamp();
|
||||
|
||||
};
|
||||
|
||||
#endif // DRIVE_H_
|
|
@ -29,7 +29,7 @@
|
|||
#endif
|
||||
|
||||
// Logic
|
||||
//#define DRYRUN //don´t touch the drives
|
||||
#define DRYRUN //don´t touch the drives
|
||||
#define FROZEN_ALERT //show alert if drive is frozen
|
||||
|
||||
//IPC pipes
|
||||
|
|
|
@ -56,7 +56,7 @@ private:
|
|||
static WINDOW *createOverViewWindow( int iXSize, int iYSize);
|
||||
static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive drive);
|
||||
static WINDOW *overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart);
|
||||
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, bool bSelected);
|
||||
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, string sTime, bool bSelected);
|
||||
static WINDOW *createSystemStats(int iXSize, int iYSize, int iXStart, int iYStart);
|
||||
static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate);
|
||||
static WINDOW *createDialog(int iXSize, int iYSize, int iXStart, int iYStart, string selectedTask, string optionA, string optionB);
|
||||
|
@ -65,5 +65,7 @@ private:
|
|||
|
||||
void displaySelectedDrive(Drive drive, int stdscrX, int stdscrY);
|
||||
|
||||
string calculateTimeDelta(time_t start, time_t end);
|
||||
|
||||
};
|
||||
#endif // TUI_H_
|
|
@ -52,10 +52,11 @@ string Drive::sCapacityToText()
|
|||
double dSize = (double) getCapacity();
|
||||
uint16_t u16UnitIndex = 0;
|
||||
const char* units[] = {"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};
|
||||
while (dSize >= 1000) { //using the marketing capacity
|
||||
dSize /= 1000;
|
||||
u16UnitIndex++;
|
||||
}
|
||||
while (dSize >= 1000) //using the marketing capacity
|
||||
{
|
||||
dSize /= 1000;
|
||||
u16UnitIndex++;
|
||||
}
|
||||
|
||||
sprintf(acBuffer, "%.*f %s", u16UnitIndex-3, dSize, units[u16UnitIndex]);
|
||||
return acBuffer;
|
||||
|
@ -139,6 +140,16 @@ void Drive::setTimestamp()
|
|||
time(&this->u32Timestamp);
|
||||
}
|
||||
|
||||
void Drive::setActionStartTimestamp()
|
||||
{
|
||||
time(&this->u32TimestampTaskStart);
|
||||
}
|
||||
|
||||
time_t Drive::getActionStartTimestamp()
|
||||
{
|
||||
return this->u32TimestampTaskStart;
|
||||
}
|
||||
|
||||
void Drive::checkFrozenDrive(void)
|
||||
{
|
||||
time_t u32localtime;
|
||||
|
|
|
@ -198,6 +198,7 @@ void reHDD::ThreadShred()
|
|||
{
|
||||
if (getSelectedDrive() != nullptr)
|
||||
{
|
||||
getSelectedDrive()->setActionStartTimestamp(); //save timestamp at start of shredding
|
||||
Shred* pShredTask = new Shred(); //create new shred task
|
||||
pShredTask->shredDrive(getSelectedDrive(), &fdShredInformPipe[1]); //start new shred task
|
||||
delete pShredTask; //delete shred task
|
||||
|
@ -209,6 +210,7 @@ void reHDD::ThreadDelete()
|
|||
{
|
||||
if (getSelectedDrive() != nullptr)
|
||||
{
|
||||
getSelectedDrive()->setActionStartTimestamp(); //save timestamp at start of deleting
|
||||
Delete::deleteDrive(getSelectedDrive()); //blocking, no thread
|
||||
getSelectedDrive()->state = Drive::TaskState::NONE; //delete finished
|
||||
getSelectedDrive()->bWasDeleteted = true;
|
||||
|
|
|
@ -43,8 +43,9 @@ Shred::~Shred()
|
|||
*/
|
||||
void Shred::shredDrive(Drive* drive, int* ipSignalFd)
|
||||
{
|
||||
|
||||
#ifdef DRYRUN
|
||||
for(int i = 0; i<=100; i++)
|
||||
for(int i = 0; i<=500; i++)
|
||||
{
|
||||
if(drive->state != Drive::SHRED_ACTIVE)
|
||||
{
|
||||
|
|
29
src/tui.cpp
29
src/tui.cpp
|
@ -77,6 +77,8 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
|
|||
string sModelName = it->getModelName();
|
||||
string sCapacity = it->sCapacityToText();
|
||||
string sState = " ";
|
||||
string sTime = " ";
|
||||
|
||||
|
||||
bool bSelectedEntry = false;
|
||||
|
||||
|
@ -94,6 +96,7 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
|
|||
}
|
||||
|
||||
stringstream stream;
|
||||
time_t u32localtime;
|
||||
|
||||
switch (it->state)
|
||||
{
|
||||
|
@ -101,10 +104,14 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
|
|||
|
||||
stream << fixed << setprecision(2) << (it->getTaskPercentage());
|
||||
sState = "Shredding: " + stream.str() + "%";
|
||||
break;
|
||||
|
||||
time(&u32localtime);
|
||||
sTime = this->calculateTimeDelta(it->getActionStartTimestamp(), u32localtime);
|
||||
break;
|
||||
case Drive::DELETE_ACTIVE:
|
||||
sState = "Deleting ...";
|
||||
time(&u32localtime);
|
||||
sTime = this->calculateTimeDelta(it->getActionStartTimestamp(), u32localtime);
|
||||
break;
|
||||
|
||||
case Drive::NONE:
|
||||
|
@ -134,7 +141,7 @@ void TUI::updateTUI(list <Drive>* plistDrives, uint8_t u8SelectedEntry)
|
|||
break;
|
||||
}
|
||||
|
||||
WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (u8Index) )+3, sModelFamily, sModelName, sCapacity, sState, bSelectedEntry);
|
||||
WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (u8Index) )+3, sModelFamily, sModelName, sCapacity, sState, sTime, bSelectedEntry);
|
||||
wrefresh(tmp);
|
||||
u8Index++;
|
||||
}//end loop though drives
|
||||
|
@ -288,7 +295,7 @@ WINDOW* TUI::overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart)
|
|||
return newWindow;
|
||||
}
|
||||
|
||||
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, bool bSelected)
|
||||
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, string sState, string sTime, bool bSelected)
|
||||
{
|
||||
WINDOW *newWindow;
|
||||
newWindow = newwin(iYSize, iXSize, iYStart, iXStart);
|
||||
|
@ -313,6 +320,7 @@ WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,
|
|||
mvwaddstr(newWindow,3, 1, sCapacity.c_str());
|
||||
|
||||
mvwaddstr(newWindow,2, iXSize-sState.length()-5, sState.c_str());
|
||||
mvwaddstr(newWindow,3, iXSize-sState.length()-5, sTime.c_str());
|
||||
|
||||
return newWindow;
|
||||
}
|
||||
|
@ -439,6 +447,21 @@ WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStar
|
|||
return newWindow;
|
||||
}
|
||||
|
||||
string TUI::calculateTimeDelta(time_t start, time_t end)
|
||||
{
|
||||
std::ostringstream out;
|
||||
|
||||
int hr=(int)((end - start)/3600);
|
||||
int min=((int)((end - start)/60))%60;
|
||||
int sec=(int)((end - start)%60);
|
||||
|
||||
char s[25];
|
||||
sprintf(s, "%02d:%02d:%02d", hr, min, sec);
|
||||
out << s;
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY)
|
||||
{
|
||||
struct MenuState menustate;
|
||||
|
|
Loading…
Reference in New Issue