forked from localhorst/reHDD
shred thread
This commit is contained in:
@ -7,9 +7,9 @@
|
||||
|
||||
#include "../include/reHDD.h"
|
||||
|
||||
static int fdSearchDrives[2];//File descriptor for pipe that informs if new drives are found
|
||||
static int fdNewDrivesInformPipe[2];//File descriptor for pipe that informs if new drives are found
|
||||
|
||||
static int fdShred[2];//File descriptor for pipe that informs if a wipe thread signals
|
||||
static int fdShredInformPipe[2];//File descriptor for pipe that informs if a wipe thread signals
|
||||
|
||||
static std::mutex mxScannDrives;
|
||||
|
||||
@ -47,38 +47,42 @@ void reHDD::app_logic(void)
|
||||
ui = new TUI();
|
||||
ui->initTUI();
|
||||
|
||||
pipe(fdSearchDrives);
|
||||
pipe(fdShred);
|
||||
pipe(fdNewDrivesInformPipe);
|
||||
pipe(fdShredInformPipe);
|
||||
|
||||
|
||||
FD_ZERO(&selectSet);
|
||||
FD_SET(fdSearchDrives[0], &selectSet);
|
||||
FD_SET(fdShred[0], &selectSet);
|
||||
|
||||
thread thDevices(ThreadScannDevices); //start thread that scanns for drives
|
||||
thread thUserInput(ThreadUserInput); //start thread that reads user input
|
||||
|
||||
while(1)
|
||||
{
|
||||
FD_ZERO(&selectSet);
|
||||
FD_SET(fdNewDrivesInformPipe[0], &selectSet);
|
||||
FD_SET(fdShredInformPipe[0], &selectSet);
|
||||
|
||||
select(FD_SETSIZE, &selectSet, NULL, NULL, NULL);
|
||||
|
||||
if( FD_ISSET(fdSearchDrives[0], &selectSet))
|
||||
if( FD_ISSET(fdNewDrivesInformPipe[0], &selectSet))
|
||||
{
|
||||
char dummy;
|
||||
read (fdSearchDrives[0],&dummy,1);
|
||||
read (fdNewDrivesInformPipe[0],&dummy,1);
|
||||
mxScannDrives.lock();
|
||||
|
||||
filterNewDrives(&vecDrives, &vecNewDrives); //filter and copy to app logic vector
|
||||
mxScannDrives.unlock();
|
||||
//TODO update UI
|
||||
}
|
||||
|
||||
ui->updateTUI(&vecDrives, i32SelectedEntry);
|
||||
}
|
||||
else if (FD_ISSET(fdShred[0], &selectSet))
|
||||
if (FD_ISSET(fdShredInformPipe[0], &selectSet))
|
||||
{
|
||||
cout << "shred signal" << endl;
|
||||
//TODO update percantage & state
|
||||
//TODO update ui
|
||||
char dummy;
|
||||
read (fdShredInformPipe[0],&dummy,1);
|
||||
|
||||
checkShredComplete(&vecDrives);
|
||||
}
|
||||
|
||||
ui->updateTUI(&vecDrives, i32SelectedEntry);
|
||||
|
||||
} //endless loop
|
||||
thDevices.join();
|
||||
thUserInput.join();
|
||||
@ -95,7 +99,7 @@ void reHDD::ThreadScannDevices()
|
||||
filterIgnoredDrives(&vecNewDrives); //filter out ignored drives
|
||||
addSMARTData(&vecNewDrives); //add S.M.A.R.T. Data to the drives
|
||||
mxScannDrives.unlock();
|
||||
write (fdSearchDrives[1], "A",1);
|
||||
write(fdNewDrivesInformPipe[1], "A",1);
|
||||
sleep(5); //sleep 5 sec
|
||||
}
|
||||
}
|
||||
@ -157,6 +161,11 @@ void reHDD::ThreadUserInput()
|
||||
}
|
||||
}
|
||||
|
||||
void reHDD::ThreadShred()
|
||||
{
|
||||
Shred::shredDrive(&vecDrives.at(i32SelectedEntry), &fdShredInformPipe[1]);
|
||||
}
|
||||
|
||||
void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives)
|
||||
{
|
||||
|
||||
@ -171,9 +180,11 @@ void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecN
|
||||
if(itOld->getSerial() == itNew->getSerial())
|
||||
{
|
||||
bOldDriveIsOffline = false;
|
||||
// cout << "already online drive found: " << itOld->getPath() << endl;
|
||||
itNew->state = itOld->state;
|
||||
itNew->setTaskPercentage(itOld->getTaskPercentage());
|
||||
// copy old drive instance date in new instance
|
||||
itNew->state = itOld->state; //copy state
|
||||
itNew->setTaskPercentage(itOld->getTaskPercentage()); //copy percentage
|
||||
itNew->bWasDeleteted = itOld->bWasDeleteted; //copy finished task delete
|
||||
itNew->bWasShredded = itOld->bWasShredded; //copy finished task shred
|
||||
}
|
||||
}
|
||||
|
||||
@ -377,9 +388,7 @@ void reHDD::handleEnter()
|
||||
{
|
||||
SELECTED_DRIVE.state = Drive::TaskState::SHRED_ACTIVE;
|
||||
//task for drive is running --> don´t show more task options
|
||||
|
||||
//TODO start shredding
|
||||
Shred::shredDrive(&vecDrives.at(i32SelectedEntry));
|
||||
thread(ThreadShred).detach();
|
||||
}
|
||||
|
||||
if(SELECTED_DRIVE.state == Drive::TaskState::DELETE_SELECTED)
|
||||
@ -413,4 +422,19 @@ void reHDD::handleAbort()
|
||||
SELECTED_DRIVE.state = Drive::NONE;
|
||||
//task for drive is running --> remove selection
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void reHDD::checkShredComplete(vector <Drive>* pvecDrives)
|
||||
{
|
||||
vector <Drive>::iterator it;
|
||||
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
|
||||
{
|
||||
if(it->getTaskPercentage() == 100 )
|
||||
{
|
||||
it->bWasShredded = true; //mark this drive as shredded
|
||||
it->setTaskPercentage(0); //reset for an other shredding
|
||||
it->state = Drive::NONE; //reset for an other task#
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user