started to use the UI

This commit is contained in:
2020-08-04 22:35:29 +02:00
parent 89f900c970
commit 9322ea65a7
9 changed files with 180 additions and 131 deletions

View File

@ -12,6 +12,8 @@ static int fdSearchDrives[2];//File descriptor for pipe that informs if new driv
static int fdUserInput[2];//File descriptor for pipe that informs if a user input occoures
static int fdWhipe[2];//File descriptor for pipe that informs if a wipe thread signals
static std::mutex mxScannDrives;
static vector <Drive> vecNewDrives; //store found drives that are updated every 5sec
@ -27,6 +29,8 @@ static fd_set selectSet;
reHDD::reHDD(void)
{
cout << "created app" << endl;
}
/**
@ -38,15 +42,19 @@ void reHDD::app_logic(void)
{
cout << "app logic" << endl;
ui = new TUI();
ui->initTUI();
pipe(fdSearchDrives);
pipe(fdWhipe);
FD_ZERO(&selectSet);
FD_SET(fdSearchDrives[0], &selectSet);
FD_SET(fdWhipe[0], &selectSet);
thread thDevices(ThreadScannDevices); //start thread that scanns for drives
while(1) {
select(FD_SETSIZE, &selectSet, NULL, NULL, NULL);
@ -55,46 +63,24 @@ void reHDD::app_logic(void)
char dummy;
read (fdSearchDrives[0],&dummy,1);
mxScannDrives.lock();
//replace with old list
// action if needed
filterNewDrives(&vecDrives, &vecNewDrives);
//printDrives(&vecDrives);
//TODO update UI
printDrives(&vecDrives);
ui->updateTUI(&vecDrives);
mxScannDrives.unlock();
}
}
// thDevices.join();
/*
size_t u64SelectedDriveIndex = 0U;
size_t u64DriveVecSize = (vecDrives.size());
cout << "Select drive to wipe:" << endl;
cin >> u64SelectedDriveIndex;
cout << "Selected drive index: " << u64SelectedDriveIndex << endl;
if(u64SelectedDriveIndex < (u64DriveVecSize)) {
// Wipe::wipeDrive(&vecDrives[u64SelectedDriveIndex]);
else if (FD_ISSET(fdWhipe[0], &selectSet)) {
cout << "Whipe signal" << endl;
}
*/
} //endless loop
thDevices.join();
}
void reHDD::ThreadScannDevices() {
while(true) {
cout << "Thread" << endl;
// cout << "Thread" << endl;
mxScannDrives.lock();
vecNewDrives.clear();
searchDrives(&vecNewDrives); //search for new drives and store them in list
@ -106,6 +92,7 @@ void reHDD::ThreadScannDevices() {
}
}
void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives) {
vector <Drive>::iterator itOld; //Iterator for current (old) drive list
@ -118,7 +105,7 @@ void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecN
{
if(itOld->getSerial() == itNew->getSerial()) {
bOldDriveIsOffline = false;
// cout << "already online drive found: " << itOld->getPath() << endl;
// cout << "already online drive found: " << itOld->getPath() << endl;
}
}
@ -143,7 +130,7 @@ void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecN
*/
void reHDD::searchDrives(vector <Drive>* pvecDrives)
{
cout << "search drives ..." << endl;
// cout << "search drives ..." << endl;
char * cLine = NULL;
size_t len = 0;