ls instead hwinfo; update UI even mutex is locked

This commit is contained in:
Hendrik Schutter 2020-09-20 00:12:18 +02:00
parent 04f46bb9d6
commit 66cfbb5da2
4 changed files with 30 additions and 23 deletions

View File

@ -10,8 +10,6 @@
#define REHDD_VERSION "bV0.1.0"
//#define DRYRUN
// Drive handling Settings
#define WORSE_HOURS 19200 //mark drive if at this limit or beyond
#define WORSE_POWERUP 10000 //mark drive if at this limit or beyond
@ -25,6 +23,11 @@
#define SOFTWARE_VERSION "alpha"
#define HARDWARE_VERSION "generic"
// Logic
//#define DRYRUN //don´t touch the drives
#define FROZEN_ALERT //show alert if drive is frozen
#define LOG_LEVEL_HIGH //log everything, like drive scann thread
#ifndef LOG_LEVEL_HIGH
#define LOG_LEVEL_LOW //log only user actions and tasks

View File

@ -60,7 +60,7 @@ private:
static WINDOW *createSystemStats(int iXSize, int iYSize, 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);
static WINDOW* createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial);
static WINDOW* createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial, string sProgress);
void displaySelectedDrive(Drive drive, int stdscrX, int stdscrY);

View File

@ -23,8 +23,6 @@ static uint8_t u8SelectedEntry;
static fd_set selectSet;
//static struct TUI::MenuState menustate;
/**
* \brief app constructor
* \param void
@ -61,23 +59,27 @@ void reHDD::app_logic(void)
FD_SET(fdShredInformPipe[0], &selectSet);
select(FD_SETSIZE, &selectSet, NULL, NULL, NULL);
mxScannDrives.lock();
if( FD_ISSET(fdNewDrivesInformPipe[0], &selectSet))
if(FD_ISSET(fdNewDrivesInformPipe[0], &selectSet))
{
mxScannDrives.lock();
char dummy;
read (fdNewDrivesInformPipe[0],&dummy,1);
filterNewDrives(&vecDrives, &vecNewDrives); //filter and copy to app logic vector
printDrives(&vecDrives);
mxScannDrives.unlock();
}
if (FD_ISSET(fdShredInformPipe[0], &selectSet))
if(FD_ISSET(fdShredInformPipe[0], &selectSet))
{
char dummy;
read (fdShredInformPipe[0],&dummy,1);
#ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("got progress signal from a shred task");
#endif
}
//mxScannDrives.lock();
ui->updateTUI(&vecDrives, u8SelectedEntry);
mxScannDrives.unlock();
//mxScannDrives.unlock();
} //endless loop
thDevices.join();
thUserInput.join();
@ -112,8 +114,6 @@ void reHDD::ThreadScannDevices()
}
}
void reHDD::ThreadCheckFrozenDrives()
{
while(true)
@ -127,7 +127,7 @@ void reHDD::ThreadCheckFrozenDrives()
}
}
mxScannDrives.unlock();
sleep(5); //sleep 5 sec
sleep(13); //sleep 13 sec
}
}
@ -284,18 +284,19 @@ void reHDD::searchDrives(vector <Drive>* pvecDrives)
char * cLine = NULL;
size_t len = 0;
FILE* outputfileHwinfo = popen("hwinfo --short --disk", "r");
FILE* outputfileHwinfo = popen("ls -1 /dev/sd*", "r");
if (outputfileHwinfo == NULL)
{
Logger::logThis()->error("Unable to scann attached drives");
exit(EXIT_FAILURE);
}
while ((getline(&cLine, &len, outputfileHwinfo)) != -1)
{
if (string(cLine).find("/dev/sd") != string::npos)
if (string(cLine).length() == 9)
{
Drive* tmpDrive = new Drive(string(cLine).substr (2,8));
Drive* tmpDrive = new Drive(string(cLine).substr(0, 8));
tmpDrive->state = Drive::NONE;
tmpDrive->bIsOffline = false;
pvecDrives->push_back(*tmpDrive);
@ -397,7 +398,7 @@ void reHDD::filterIgnoredDrives(vector <Drive>* pvecDrives)
void reHDD::printDrives(vector <Drive>* pvecDrives)
{
#ifdef LOG_LEVEL_HIGH
Logger::logThis()->info("------------DRIVES---------------");
Logger::logThis()->info("------------DRIVES START------------");
//cout << "------------DRIVES---------------" << endl;
vector <Drive>::iterator it;
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
@ -416,11 +417,9 @@ void reHDD::printDrives(vector <Drive>* pvecDrives)
ostringstream address;
address << (void const *)&pvecDrives->at(it - pvecDrives->begin());
Logger::logThis()->info(to_string(it - pvecDrives->begin()) + ": " + it->getPath() + " - " + it->getModelFamily() + " - " + it->getSerial() + " @" + address.str());
}
Logger::logThis()->info("---------------------------------");
Logger::logThis()->info("------------DRIVES END--------------");
//cout << "---------------------------------" << endl;
#endif
}

View File

@ -112,8 +112,11 @@ void TUI::updateTUI(vector <Drive>* pvecDrives, uint8_t u8SelectedEntry)
}
break;
case Drive::FROZEN:
dialog=createFrozenWarning(70, 16, ((stdscrX)-(int)(stdscrX/2)-35),(int)(stdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial());
#ifdef FROZEN_ALERT
stream << fixed << setprecision(2) << (it->getTaskPercentage());
dialog=createFrozenWarning(70, 16, ((stdscrX)-(int)(stdscrX/2)-35),(int)(stdscrY/2)-8, it->getPath(), it->getModelFamily(), it->getModelName(), it->getSerial(), stream.str() + "%");
wrefresh(dialog);
#endif
break;
default:
break;
@ -399,7 +402,7 @@ WINDOW* TUI::createDialog(int iXSize, int iYSize, int iXStart, int iYStart, stri
return newWindow;
}
WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial)
WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStart, string sPath, string sModelFamily, string sModelName, string sSerial, string sProgress)
{
WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, iYStart, iXStart);
@ -409,6 +412,7 @@ WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStar
string sHeader = "Drive " + sPath + " is frozen";
string sLine01 = "Please detach this drive and check it manually:";
string sShredState = "Shredding stopped after " + sProgress;
string sLinePath = "Path: " +sPath;
string sLineModelFamlily = "ModelFamily: " + sModelFamily;
string sLineModelName = "ModelName: " + sModelName;
@ -429,6 +433,7 @@ WINDOW* TUI::createFrozenWarning(int iXSize, int iYSize, int iXStart, int iYStar
u16Line++;
mvwaddstr(newWindow,u16Line++, 3, sLine02.c_str());
mvwaddstr(newWindow,u16Line++, 3, sLine03.c_str());
mvwaddstr(newWindow,u16Line++, 3, sShredState.c_str());
return newWindow;
}