fix/atomic-drive-members #83

Merged
localhorst merged 2 commits from fix/atomic-drive-members into bugfix/ai-static-analysis 2025-12-10 21:21:16 +01:00
9 changed files with 185 additions and 67 deletions

View File

@ -14,7 +14,7 @@ class Drive
{ {
public: public:
enum TaskState enum class TaskState
{ {
NONE, NONE,
SHRED_SELECTED, SHRED_SELECTED,
@ -23,23 +23,28 @@ public:
DELETE_SELECTED, DELETE_SELECTED,
DELETE_ACTIVE, DELETE_ACTIVE,
FROZEN FROZEN
} state; };
enum ConnectionType enum class ConnectionType
{ {
UNKNOWN, UNKNOWN,
USB, USB,
SATA, SATA,
NVME NVME
} connectionType; };
struct struct ShredSpeed
{ {
time_t u32ShredTimeDelta; time_t u32ShredTimeDelta;
std::chrono::time_point<std::chrono::system_clock> chronoShredTimestamp; std::chrono::time_point<std::chrono::system_clock>
chronoShredTimestamp;
unsigned long ulWrittenBytes; unsigned long ulWrittenBytes;
unsigned long ulSpeedMetricBytesWritten; unsigned long ulSpeedMetricBytesWritten;
} sShredSpeed; };
std::atomic<TaskState> state;
std::atomic<ConnectionType> connectionType;
std::atomic<ShredSpeed> sShredSpeed;
bool bWasShredded = false; // all shred iterations done bool bWasShredded = false; // all shred iterations done
bool bWasShredStarted = false; // shred was atleast once started bool bWasShredStarted = false; // shred was atleast once started
@ -73,6 +78,18 @@ private:
protected: protected:
public: public:
// Copy constructor
Drive(const Drive &other);
// Copy assignment operator
Drive &operator=(const Drive &other);
// Move constructor
Drive(Drive &&other) noexcept;
// Move assignment operator
Drive &operator=(Drive &&other) noexcept;
Drive(std::string path) Drive(std::string path)
{ {
this->sPath = path; this->sPath = path;

View File

@ -56,6 +56,7 @@
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <signal.h> #include <signal.h>
#include <atomic>
#include "drive.h" #include "drive.h"
#include "smart.h" #include "smart.h"
#include "shred.h" #include "shred.h"

View File

@ -67,7 +67,7 @@ private:
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 *overwriteDetailViewWindow(int iXSize, int iYSize, int iXStart); static WINDOW *overwriteDetailViewWindow(int iXSize, int iYSize, int iXStart);
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, int iListIndex, std::string sModelFamily, std::string sSerial, std::string sCapacity, std::string sState, std::string sTime, std::string sSpeed, std::string sTemp, std::string sConnection, bool bSelected); static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, int iListIndex, std::string sModelFamily, std::string sSerial, std::string sCapacity, std::string sState, std::string sTime, std::string sSpeed, std::string sTemp, std::string sConnection, bool bSelected);
static WINDOW *createSystemStats(int iXSize, int iYSize, int iXStart, int iYStart); static WINDOW *createSystemStats(int iXSize, int iYSize, int iXStart, int iYStart);
@ -77,7 +77,7 @@ private:
static WINDOW *createSmartWarning(int iXSize, int iYSize, int iXStart, int iYStart, std::string sPath, uint32_t u32PowerOnHours, uint32_t u32PowerCycles, uint32_t u32ErrorCount, uint32_t u32Temperature); static WINDOW *createSmartWarning(int iXSize, int iYSize, int iXStart, int iYStart, std::string sPath, uint32_t u32PowerOnHours, uint32_t u32PowerCycles, uint32_t u32ErrorCount, uint32_t u32Temperature);
static WINDOW *createZeroChecksumWarning(int iXSize, int iYSize, int iXStart, int iYStart, std::string sPath, std::string sModelFamily, std::string sModelName, std::string sSerial, uint32_t u32Checksum); static WINDOW *createZeroChecksumWarning(int iXSize, int iYSize, int iXStart, int iYStart, std::string sPath, std::string sModelFamily, std::string sModelName, std::string sSerial, uint32_t u32Checksum);
void displaySelectedDrive(Drive drive, int stdscrX, int stdscrY); void displaySelectedDrive(Drive &drive, int stdscrX, int stdscrY);
std::string formatTimeDuration(time_t u32Duration); std::string formatTimeDuration(time_t u32Duration);
std::string formatSpeed(time_t u32ShredTimeDelta, unsigned long ulWrittenBytes); std::string formatSpeed(time_t u32ShredTimeDelta, unsigned long ulWrittenBytes);
static void vTruncateText(std::string *psText, uint16_t u16MaxLenght); static void vTruncateText(std::string *psText, uint16_t u16MaxLenght);

View File

@ -18,7 +18,7 @@ DCOMPILE_FLAGS = -D DEBUG
# Add additional include paths # Add additional include paths
INCLUDES = include INCLUDES = include
# General linker settings # General linker settings
LINK_FLAGS = -Llib -lpthread -lncurses -ltfng LINK_FLAGS = -Llib -lpthread -lncurses -ltfng -latomic
# Doc # Doc
DOCDIR = doc DOCDIR = doc

View File

@ -8,6 +8,94 @@
#include "../include/reHDD.h" #include "../include/reHDD.h"
using namespace std; using namespace std;
// Copy constructor
Drive::Drive(const Drive &other)
: state(other.state.load()),
connectionType(other.connectionType.load()),
sShredSpeed(other.sShredSpeed.load()),
bWasShredded(other.bWasShredded),
bWasShredStarted(other.bWasShredStarted),
bWasChecked(other.bWasChecked),
bWasDeleted(other.bWasDeleted),
bIsOffline(other.bIsOffline),
u32DriveChecksumAfterShredding(other.u32DriveChecksumAfterShredding),
sPath(other.sPath),
u32Timestamp(other.u32Timestamp),
d32TaskPercentage(other.d32TaskPercentage),
u32TimestampTaskStart(other.u32TimestampTaskStart),
u32TaskDuration(other.u32TaskDuration),
sSmartData(other.sSmartData)
{
}
// Copy assignment operator
Drive &Drive::operator=(const Drive &other)
{
if (this != &other)
{
state = other.state.load();
connectionType = other.connectionType.load();
sShredSpeed = other.sShredSpeed.load();
bWasShredded = other.bWasShredded;
bWasShredStarted = other.bWasShredStarted;
bWasChecked = other.bWasChecked;
bWasDeleted = other.bWasDeleted;
bIsOffline = other.bIsOffline;
u32DriveChecksumAfterShredding = other.u32DriveChecksumAfterShredding;
sPath = other.sPath;
u32Timestamp = other.u32Timestamp;
d32TaskPercentage = other.d32TaskPercentage;
u32TimestampTaskStart = other.u32TimestampTaskStart;
u32TaskDuration = other.u32TaskDuration;
sSmartData = other.sSmartData;
}
return *this;
}
// Move constructor
Drive::Drive(Drive &&other) noexcept
: state(other.state.load()),
connectionType(other.connectionType.load()),
sShredSpeed(other.sShredSpeed.load()),
bWasShredded(other.bWasShredded),
bWasShredStarted(other.bWasShredStarted),
bWasChecked(other.bWasChecked),
bWasDeleted(other.bWasDeleted),
bIsOffline(other.bIsOffline),
u32DriveChecksumAfterShredding(other.u32DriveChecksumAfterShredding),
sPath(std::move(other.sPath)),
u32Timestamp(other.u32Timestamp),
d32TaskPercentage(other.d32TaskPercentage),
u32TimestampTaskStart(other.u32TimestampTaskStart),
u32TaskDuration(other.u32TaskDuration),
sSmartData(std::move(other.sSmartData))
{
}
// Move assignment operator
Drive &Drive::operator=(Drive &&other) noexcept
{
if (this != &other)
{
state = other.state.load();
connectionType = other.connectionType.load();
sShredSpeed = other.sShredSpeed.load();
bWasShredded = other.bWasShredded;
bWasShredStarted = other.bWasShredStarted;
bWasChecked = other.bWasChecked;
bWasDeleted = other.bWasDeleted;
bIsOffline = other.bIsOffline;
u32DriveChecksumAfterShredding = other.u32DriveChecksumAfterShredding;
sPath = std::move(other.sPath);
u32Timestamp = other.u32Timestamp;
d32TaskPercentage = other.d32TaskPercentage;
u32TimestampTaskStart = other.u32TimestampTaskStart;
u32TaskDuration = other.u32TaskDuration;
sSmartData = std::move(other.sSmartData);
}
return *this;
}
string Drive::getPath(void) string Drive::getPath(void)
{ {
return sPath; return sPath;
@ -205,6 +293,6 @@ void Drive::checkFrozenDrive(void)
Logger::logThis()->warning("Drive Frozen: " + this->getModelName() + " " + this->getSerial()); Logger::logThis()->warning("Drive Frozen: " + this->getModelName() + " " + this->getSerial());
this->bWasDeleted = false; this->bWasDeleted = false;
this->bWasShredded = false; this->bWasShredded = false;
this->state = Drive::FROZEN; this->state = Drive::TaskState::FROZEN;
} }
} }

View File

@ -7,7 +7,6 @@
#include "../include/reHDD.h" #include "../include/reHDD.h"
bool Printer::instanceFlag = false; bool Printer::instanceFlag = false;
Printer *Printer::single = NULL; Printer *Printer::single = NULL;
@ -57,16 +56,16 @@ void Printer::print(Drive *drive)
switch (drive->connectionType) switch (drive->connectionType)
{ {
case Drive::USB: case Drive::ConnectionType::USB:
strncpy(msgQueueData.driveData.caDriveConnectionType, "usb", STR_BUFFER_SIZE); strncpy(msgQueueData.driveData.caDriveConnectionType, "usb", STR_BUFFER_SIZE);
break; break;
case Drive::SATA: case Drive::ConnectionType::SATA:
strncpy(msgQueueData.driveData.caDriveConnectionType, "sata", STR_BUFFER_SIZE); strncpy(msgQueueData.driveData.caDriveConnectionType, "sata", STR_BUFFER_SIZE);
break; break;
case Drive::NVME: case Drive::ConnectionType::NVME:
strncpy(msgQueueData.driveData.caDriveConnectionType, "nvme", STR_BUFFER_SIZE); strncpy(msgQueueData.driveData.caDriveConnectionType, "nvme", STR_BUFFER_SIZE);
break; break;
case Drive::UNKNOWN: case Drive::ConnectionType::UNKNOWN:
default: default:
strncpy(msgQueueData.driveData.caDriveConnectionType, "na", STR_BUFFER_SIZE); strncpy(msgQueueData.driveData.caDriveConnectionType, "na", STR_BUFFER_SIZE);
} }

View File

@ -133,7 +133,7 @@ void reHDD::ThreadCheckFrozenDrives()
mxDrives.lock(); mxDrives.lock();
for (auto it = begin(listDrives); it != end(listDrives); ++it) for (auto it = begin(listDrives); it != end(listDrives); ++it)
{ {
if (it->state == Drive::SHRED_ACTIVE) if (it->state == Drive::TaskState::SHRED_ACTIVE)
{ {
it->checkFrozenDrive(); it->checkFrozenDrive();
} }
@ -175,9 +175,9 @@ void reHDD::ThreadUserInput()
if (tmpSelectedDrive != nullptr) if (tmpSelectedDrive != nullptr)
{ {
if (tmpSelectedDrive->state == Drive::NONE) if (tmpSelectedDrive->state == Drive::TaskState::NONE)
{ {
tmpSelectedDrive->state = Drive::DELETE_SELECTED; tmpSelectedDrive->state = Drive::TaskState::DELETE_SELECTED;
} }
} }
@ -187,9 +187,9 @@ void reHDD::ThreadUserInput()
// cout << "Shred" << endl; // cout << "Shred" << endl;
if (tmpSelectedDrive != nullptr) if (tmpSelectedDrive != nullptr)
{ {
if (tmpSelectedDrive->state == Drive::NONE) if (tmpSelectedDrive->state == Drive::TaskState::NONE)
{ {
tmpSelectedDrive->state = Drive::SHRED_SELECTED; tmpSelectedDrive->state = Drive::TaskState::SHRED_SELECTED;
} }
} }
ui->updateTUI(&listDrives, u16SelectedEntry); ui->updateTUI(&listDrives, u16SelectedEntry);
@ -302,7 +302,7 @@ void reHDD::filterNewDrives(list<Drive> *plistOldDrives, list<Drive> *plistNewDr
{ {
// cout << "offline drive found: " << itOld->getPath() << endl; // cout << "offline drive found: " << itOld->getPath() << endl;
Logger::logThis()->warning("Mark offline drive found: " + itOld->getPath()); Logger::logThis()->warning("Mark offline drive found: " + itOld->getPath());
itOld->state = Drive::NONE; // clear state --> shred task will terminate itOld->state = Drive::TaskState::NONE; // clear state --> shred task will terminate
} }
} }
@ -340,27 +340,27 @@ void reHDD::searchDrives(std::list<Drive> *plistDrives)
continue; continue;
Drive tmpDrive("/dev/" + devName); Drive tmpDrive("/dev/" + devName);
tmpDrive.state = Drive::NONE; tmpDrive.state = Drive::TaskState::NONE;
tmpDrive.bIsOffline = false; tmpDrive.bIsOffline = false;
// Set connection type // Set connection type
if (transport == "sata") if (transport == "sata")
tmpDrive.connectionType = Drive::SATA; tmpDrive.connectionType = Drive::ConnectionType::SATA;
else if (transport == "usb") else if (transport == "usb")
tmpDrive.connectionType = Drive::USB; tmpDrive.connectionType = Drive::ConnectionType::USB;
else if (transport == "nvme") else if (transport == "nvme")
tmpDrive.connectionType = Drive::NVME; tmpDrive.connectionType = Drive::ConnectionType::NVME;
else else
tmpDrive.connectionType = Drive::UNKNOWN; tmpDrive.connectionType = Drive::ConnectionType::UNKNOWN;
plistDrives->push_back(tmpDrive); plistDrives->push_back(tmpDrive);
Logger::logThis()->info( Logger::logThis()->info(
"Drive found: " + tmpDrive.getPath() + "Drive found: " + tmpDrive.getPath() +
" (type: " + " (type: " +
(tmpDrive.connectionType == Drive::USB ? "USB" : tmpDrive.connectionType == Drive::SATA ? "SATA" (tmpDrive.connectionType == Drive::ConnectionType::USB ? "USB" : tmpDrive.connectionType == Drive::ConnectionType::SATA ? "SATA"
: tmpDrive.connectionType == Drive::NVME ? "NVME" : tmpDrive.connectionType == Drive::ConnectionType::NVME ? "NVME"
: "UNKNOWN") + : "UNKNOWN") +
")"); ")");
} }
@ -478,7 +478,7 @@ void reHDD::startShredAllDrives(list<Drive> *plistDrives)
mxDrives.lock(); mxDrives.lock();
for (it = plistDrives->begin(); it != plistDrives->end(); ++it) for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
{ {
if (it->state == Drive::NONE) if (it->state == Drive::TaskState::NONE)
{ {
Drive *pTmpDrive = iterator_to_pointer<Drive, std::list<Drive>::iterator>(it); Drive *pTmpDrive = iterator_to_pointer<Drive, std::list<Drive>::iterator>(it);
#ifdef LOG_LEVEL_HIGH #ifdef LOG_LEVEL_HIGH
@ -505,9 +505,9 @@ void reHDD::stopShredAllDrives(list<Drive> *plistDrives)
for (it = plistDrives->begin(); it != plistDrives->end(); ++it) for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
{ {
if (it->state == Drive::SHRED_ACTIVE || it->state == Drive::DELETE_ACTIVE) if (it->state == Drive::TaskState::SHRED_ACTIVE || it->state == Drive::TaskState::DELETE_ACTIVE)
{ {
it->state = Drive::NONE; it->state = Drive::TaskState::NONE;
Logger::logThis()->info("Abort-Shred-Signal for: " + it->getModelName() + "-" + it->getSerial()); Logger::logThis()->info("Abort-Shred-Signal for: " + it->getModelName() + "-" + it->getSerial());
// task for drive is running --> remove selection // task for drive is running --> remove selection
} }
@ -566,18 +566,20 @@ void reHDD::updateShredMetrics(list<Drive> *plistDrives)
list<Drive>::iterator it; list<Drive>::iterator it;
for (it = plistDrives->begin(); it != plistDrives->end(); ++it) for (it = plistDrives->begin(); it != plistDrives->end(); ++it)
{ {
if (it->state == Drive::SHRED_ACTIVE) if (it->state == Drive::TaskState::SHRED_ACTIVE)
{ {
Drive *pTmpDrive = iterator_to_pointer<Drive, std::list<Drive>::iterator>(it); Drive *pTmpDrive = iterator_to_pointer<Drive, std::list<Drive>::iterator>(it);
// set metrics for calculating shred speed // set metrics for calculating shred speed
std::chrono::time_point<std::chrono::system_clock> chronoCurrentTimestamp = std::chrono::system_clock::now(); std::chrono::time_point<std::chrono::system_clock> chronoCurrentTimestamp = std::chrono::system_clock::now();
time_t u32ShredTimeDelta = (chronoCurrentTimestamp - pTmpDrive->sShredSpeed.chronoShredTimestamp).count(); auto shredSpeed = pTmpDrive->sShredSpeed.load();
time_t u32ShredTimeDelta = (chronoCurrentTimestamp - shredSpeed.chronoShredTimestamp).count();
if (u32ShredTimeDelta > METRIC_THRESHOLD) if (u32ShredTimeDelta > METRIC_THRESHOLD)
{ {
pTmpDrive->sShredSpeed.u32ShredTimeDelta = u32ShredTimeDelta; shredSpeed.u32ShredTimeDelta = u32ShredTimeDelta;
pTmpDrive->sShredSpeed.chronoShredTimestamp = std::chrono::system_clock::now(); shredSpeed.chronoShredTimestamp = std::chrono::system_clock::now();
pTmpDrive->sShredSpeed.ulWrittenBytes = pTmpDrive->sShredSpeed.ulSpeedMetricBytesWritten; shredSpeed.ulWrittenBytes = shredSpeed.ulSpeedMetricBytesWritten;
pTmpDrive->sShredSpeed.ulSpeedMetricBytesWritten = 0U; shredSpeed.ulSpeedMetricBytesWritten = 0U;
pTmpDrive->sShredSpeed.store(shredSpeed);
} }
} }
} }
@ -675,9 +677,9 @@ void reHDD::handleAbort()
Drive *tmpSelectedDrive = getSelectedDrive(); Drive *tmpSelectedDrive = getSelectedDrive();
if (tmpSelectedDrive != nullptr) if (tmpSelectedDrive != nullptr)
{ {
if (tmpSelectedDrive->state == Drive::SHRED_ACTIVE || tmpSelectedDrive->state == Drive::DELETE_ACTIVE) if (tmpSelectedDrive->state == Drive::TaskState::SHRED_ACTIVE || tmpSelectedDrive->state == Drive::TaskState::DELETE_ACTIVE)
{ {
tmpSelectedDrive->state = Drive::NONE; tmpSelectedDrive->state = Drive::TaskState::NONE;
Logger::logThis()->info("Abort-Shred-Signal for: " + tmpSelectedDrive->getModelName() + "-" + tmpSelectedDrive->getSerial()); Logger::logThis()->info("Abort-Shred-Signal for: " + tmpSelectedDrive->getModelName() + "-" + tmpSelectedDrive->getSerial());
// task for drive is running --> remove selection // task for drive is running --> remove selection
} }

View File

@ -42,7 +42,7 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd)
#ifdef DRYRUN #ifdef DRYRUN
for (int i = 0; i <= 500; i++) for (int i = 0; i <= 500; i++)
{ {
if (drive->state != Drive::SHRED_ACTIVE) if (drive->state.load() != Drive::TaskState::SHRED_ACTIVE)
{ {
return 0; return 0;
} }
@ -202,9 +202,9 @@ int Shred::shredDrive(Drive *drive, int *ipSignalFd)
cleanup(); cleanup();
if ((drive->state == Drive::SHRED_ACTIVE) || (drive->state == Drive::CHECK_ACTIVE)) if ((drive->state.load() == Drive::TaskState::SHRED_ACTIVE) || (drive->state.load() == Drive::TaskState::CHECK_ACTIVE))
{ {
drive->state = Drive::NONE; drive->state = Drive::TaskState::NONE;
drive->setTaskPercentage(0.0); drive->setTaskPercentage(0.0);
Printer::getPrinter()->print(drive); Printer::getPrinter()->print(drive);
Logger::logThis()->info("Finished shred/check for: " + drive->getModelName() + "-" + drive->getSerial()); Logger::logThis()->info("Finished shred/check for: " + drive->getModelName() + "-" + drive->getSerial());
@ -286,7 +286,9 @@ unsigned int Shred::uiCalcChecksum(fileDescriptor file, Drive *drive, int *ipSig
ulDriveByteCounter += iReadBytes; ulDriveByteCounter += iReadBytes;
ulDriveByteOverallCount += iReadBytes; ulDriveByteOverallCount += iReadBytes;
d32Percent = this->calcProgress(); d32Percent = this->calcProgress();
drive->sShredSpeed.ulSpeedMetricBytesWritten += iReadBytes; auto shredSpeed = drive->sShredSpeed.load();
shredSpeed.ulSpeedMetricBytesWritten += iReadBytes;
drive->sShredSpeed.store(shredSpeed);
#ifdef LOG_LEVEL_HIGH #ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("Shred-Task (Checksum): ByteCount: " + to_string(ulDriveByteCounter) + " - progress: " + to_string(d32Percent) + " - Drive: " + drive->getSerial()); Logger::logThis()->info("Shred-Task (Checksum): ByteCount: " + to_string(ulDriveByteCounter) + " - progress: " + to_string(d32Percent) + " - Drive: " + drive->getSerial());

View File

@ -99,9 +99,9 @@ void TUI::updateTUI(list<Drive> *plistDrives, uint8_t u8SelectedEntry)
string sSpeed = " "; string sSpeed = " ";
string sTime = " "; string sTime = " ";
string sTemp = it->sTemperatureToText(); string sTemp = it->sTemperatureToText();
string sConnection = (it->connectionType == Drive::USB ? "USB" : it->connectionType == Drive::SATA ? "SATA" string sConnection = (it->connectionType == Drive::ConnectionType::USB ? "USB" : it->connectionType == Drive::ConnectionType::SATA ? "SATA"
: it->connectionType == Drive::NVME ? "NVME" : it->connectionType == Drive::ConnectionType::NVME ? "NVME"
: ""); : "");
bool bSelectedEntry = false; bool bSelectedEntry = false;
@ -122,30 +122,39 @@ void TUI::updateTUI(list<Drive> *plistDrives, uint8_t u8SelectedEntry)
switch (it->state) switch (it->state)
{ {
case Drive::SHRED_ACTIVE: case Drive::TaskState::SHRED_ACTIVE:
{
stream << fixed << setprecision(3) << (it->getTaskPercentage()); stream << fixed << setprecision(3) << (it->getTaskPercentage());
sState = "Shredding: " + stream.str() + "%"; sState = "Shredding: " + stream.str() + "%";
it->calculateTaskDuration(); it->calculateTaskDuration();
sTime = this->formatTimeDuration(it->getTaskDuration()); sTime = this->formatTimeDuration(it->getTaskDuration());
sSpeed = this->formatSpeed(it->sShredSpeed.u32ShredTimeDelta, it->sShredSpeed.ulWrittenBytes); auto shredSpeed = it->sShredSpeed.load();
sSpeed = this->formatSpeed(shredSpeed.u32ShredTimeDelta, shredSpeed.ulWrittenBytes);
break; break;
case Drive::CHECK_ACTIVE: }
case Drive::TaskState::CHECK_ACTIVE:
{
stream << fixed << setprecision(3) << (it->getTaskPercentage()); stream << fixed << setprecision(3) << (it->getTaskPercentage());
sState = "Checking: " + stream.str() + "%"; sState = "Checking: " + stream.str() + "%";
it->calculateTaskDuration(); it->calculateTaskDuration();
sTime = this->formatTimeDuration(it->getTaskDuration()); sTime = this->formatTimeDuration(it->getTaskDuration());
sSpeed = this->formatSpeed(it->sShredSpeed.u32ShredTimeDelta, it->sShredSpeed.ulWrittenBytes); auto shredSpeed = it->sShredSpeed.load();
sSpeed = this->formatSpeed(shredSpeed.u32ShredTimeDelta, shredSpeed.ulWrittenBytes);
break; break;
case Drive::DELETE_ACTIVE: }
case Drive::TaskState::DELETE_ACTIVE:
{
sState = "Deleting ..."; sState = "Deleting ...";
it->calculateTaskDuration(); it->calculateTaskDuration();
sTime = this->formatTimeDuration(it->getTaskDuration()); sTime = this->formatTimeDuration(it->getTaskDuration());
break; break;
case Drive::NONE: }
case Drive::SHRED_SELECTED: case Drive::TaskState::NONE:
case Drive::DELETE_SELECTED: case Drive::TaskState::SHRED_SELECTED:
case Drive::TaskState::DELETE_SELECTED:
{
if (it->bWasDeleted) if (it->bWasDeleted)
{ {
sState = "DELETED"; // mark drive as deleted previously sState = "DELETED"; // mark drive as deleted previously
@ -172,9 +181,9 @@ void TUI::updateTUI(list<Drive> *plistDrives, uint8_t u8SelectedEntry)
wrefresh(dialog); wrefresh(dialog);
} }
#endif #endif
break; break;
case Drive::FROZEN: }
case Drive::TaskState::FROZEN:
stream << fixed << setprecision(3) << (it->getTaskPercentage()); stream << fixed << setprecision(3) << (it->getTaskPercentage());
#ifdef FROZEN_ALERT #ifdef FROZEN_ALERT
if (bSelectedEntry) if (bSelectedEntry)
@ -290,7 +299,7 @@ WINDOW *TUI::createOverViewWindow(int iXSize, int iYSize)
return newWindow; return newWindow;
} }
WINDOW *TUI::createDetailViewWindow(int iXSize, int iYSize, int iXStart, Drive drive) WINDOW *TUI::createDetailViewWindow(int iXSize, int iYSize, int iXStart, Drive &drive)
{ {
WINDOW *newWindow; WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, 1, iXStart); newWindow = newwin(iYSize, iXSize, 1, iXStart);
@ -633,7 +642,7 @@ void TUI::vTruncateText(string *psText, uint16_t u16MaxLenght)
} }
} }
void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY) void TUI::displaySelectedDrive(Drive &drive, int stdscrX, int stdscrY)
{ {
struct MenuState menustate; struct MenuState menustate;
static bool dialogIsActive; static bool dialogIsActive;
@ -646,27 +655,27 @@ void TUI::displaySelectedDrive(Drive drive, int stdscrX, int stdscrY)
// set menustate based on drive state // set menustate based on drive state
switch (drive.state) switch (drive.state)
{ {
case Drive::NONE: // no task running or selected for this drive case Drive::TaskState::NONE: // no task running or selected for this drive
menustate.bShred = true; menustate.bShred = true;
menustate.bDelete = true; menustate.bDelete = true;
break; break;
case Drive::DELETE_ACTIVE: // delete task running for this drive case Drive::TaskState::DELETE_ACTIVE: // delete task running for this drive
menustate.bAbort = true; menustate.bAbort = true;
break; break;
case Drive::SHRED_ACTIVE: // shred task running for this drive case Drive::TaskState::SHRED_ACTIVE: // shred task running for this drive
menustate.bAbort = true; menustate.bAbort = true;
break; break;
case Drive::CHECK_ACTIVE: // check task running for this drive case Drive::TaskState::CHECK_ACTIVE: // check task running for this drive
menustate.bAbort = true; menustate.bAbort = true;
break; break;
case Drive::DELETE_SELECTED: // delete task selected for this drive case Drive::TaskState::DELETE_SELECTED: // delete task selected for this drive
menustate.bConfirmDelete = true; menustate.bConfirmDelete = true;
break; break;
case Drive::SHRED_SELECTED: // shred task selected for this drive case Drive::TaskState::SHRED_SELECTED: // shred task selected for this drive
menustate.bConfirmShred = true; menustate.bConfirmShred = true;
break; break;
default: default: