merge threading to develop #21
@ -37,6 +37,8 @@ public:
|
||||
uint32_t powerOnHours,
|
||||
uint32_t powerCycles);
|
||||
|
||||
string sCapacityToText();
|
||||
|
||||
private:
|
||||
string sPath;
|
||||
string sModelFamily;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <mutex>
|
||||
#include <sys/select.h>
|
||||
#include<algorithm>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
using namespace std;
|
||||
@ -30,8 +31,8 @@ using namespace std;
|
||||
#include "drive.h"
|
||||
#include "smart.h"
|
||||
#include "wipe.h"
|
||||
//#include "tui.h"
|
||||
//#include "tui_data.h"
|
||||
#include "tui.h"
|
||||
|
||||
|
||||
template <typename T, typename I> T* iterator_to_pointer(I i)
|
||||
{
|
||||
@ -53,21 +54,14 @@ private:
|
||||
vector <Drive> vecDrives; //stores all drive data
|
||||
|
||||
static void searchDrives(vector <Drive>* pvecDrives);
|
||||
|
||||
static void printDrives(vector <Drive>* pvecDrives);
|
||||
|
||||
|
||||
static void filterIgnoredDrives(vector <Drive>* pvecDrives);
|
||||
|
||||
|
||||
static void addSMARTData(vector <Drive>* pvecDrives);
|
||||
|
||||
static void ThreadScannDevices();
|
||||
|
||||
|
||||
void filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives);
|
||||
|
||||
|
||||
TUI *ui;
|
||||
|
||||
|
||||
|
||||
|
@ -24,18 +24,23 @@ public:
|
||||
|
||||
TUI(void);
|
||||
|
||||
void initTUI();
|
||||
|
||||
void updateTUI(TUI_DATA data);
|
||||
|
||||
static void initTUI();
|
||||
|
||||
void updateTUI(vector <Drive>* pvecDrives);
|
||||
|
||||
private:
|
||||
static string sCpuUsage;
|
||||
static string sRamUsage;
|
||||
static string sLocalTime;
|
||||
|
||||
void centerTitle(WINDOW *pwin, const char * title);
|
||||
|
||||
|
||||
WINDOW *detailview;
|
||||
WINDOW *overview;
|
||||
vector <WINDOW *> vWinDriveEntries;
|
||||
|
||||
static void centerTitle(WINDOW *pwin, const char * title);
|
||||
static WINDOW *createOverViewWindow( int iXSize, int iYSize);
|
||||
static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart);
|
||||
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,string sModelFamily, string sModelName, string sCapacity);
|
||||
};
|
||||
|
||||
#endif // TUI_H_
|
@ -1,45 +0,0 @@
|
||||
/**
|
||||
* @file tui_data.h
|
||||
* @brief ui model data
|
||||
* @author hendrik schutter
|
||||
* @date 03.08.2020
|
||||
*/
|
||||
|
||||
#ifndef TUI_DATA_H_
|
||||
#define TUI_DATA_H_
|
||||
|
||||
#include "reHDD.h"
|
||||
|
||||
#define COLOR_AREA_STDSCR 1
|
||||
#define COLOR_AREA_OVERVIEW 2
|
||||
#define COLOR_AREA_ENTRY 3
|
||||
|
||||
#define COLOR_GRAY 8
|
||||
|
||||
|
||||
class TUI_DATA
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
|
||||
TUI_DATA(vector <Drive>* pvecDrives);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
|
||||
string sCpuUsage;
|
||||
string sRamUsage;
|
||||
string sLocalTime;
|
||||
|
||||
};
|
||||
|
||||
#endif // TUI_DATA_H_
|
2
makefile
2
makefile
@ -18,7 +18,7 @@ DCOMPILE_FLAGS = -D DEBUG
|
||||
# Add additional include paths
|
||||
INCLUDES = include
|
||||
# General linker settings
|
||||
LINK_FLAGS = -lpthread
|
||||
LINK_FLAGS = -lpthread -lncurses
|
||||
# Doc
|
||||
DOCDIR = doc
|
||||
#### END PROJECT SETTINGS ####
|
||||
|
135
src/TUI/tui.cpp
135
src/TUI/tui.cpp
@ -4,16 +4,23 @@
|
||||
* @author hendrik schutter
|
||||
* @date 03.08.2020
|
||||
*/
|
||||
/*
|
||||
#include "../include/reHDD.h"
|
||||
*/
|
||||
|
||||
#include "../../include/reHDD.h"
|
||||
|
||||
|
||||
TUI::TUI(void){
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief wipe drive with shred
|
||||
* \param pointer of Drive instance
|
||||
* \return void
|
||||
*/
|
||||
/*
|
||||
|
||||
void TUI::initTUI()
|
||||
{
|
||||
initscr();
|
||||
@ -30,10 +37,126 @@ void TUI::initTUI()
|
||||
init_color(COLOR_GRAY, 173, 170, 173);
|
||||
}
|
||||
|
||||
void TUI::updateTUI(TUI_DATA data){
|
||||
void TUI::updateTUI(vector <Drive>* pvecDrives) {
|
||||
|
||||
|
||||
werase(stdscr);
|
||||
|
||||
int stdscrX, stdscrY;
|
||||
getmaxyx(stdscr, stdscrY, stdscrX);
|
||||
|
||||
init_pair(COLOR_AREA_STDSCR,COLOR_WHITE, COLOR_BLUE);
|
||||
wbkgd(stdscr, COLOR_PAIR(COLOR_AREA_STDSCR));
|
||||
|
||||
mvprintw(0, 2, "reHDD - HDD refurbishing tool - Licensed under GPL 3.0 X:%d Y:%d",stdscrX,stdscrY);
|
||||
|
||||
refresh();
|
||||
|
||||
overview=createOverViewWindow((int)(stdscrX/3), (stdscrY-15));
|
||||
wrefresh(overview);
|
||||
|
||||
detailview=createDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-3), (int)(stdscrX/3)+5);
|
||||
wrefresh(detailview);
|
||||
|
||||
vWinDriveEntries.clear();
|
||||
|
||||
|
||||
int i = 0;
|
||||
|
||||
vector <Drive>::iterator it;
|
||||
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
|
||||
{
|
||||
|
||||
string sModelFamily = it->getModelFamily();
|
||||
string sModelName = it->getModelName();
|
||||
string sCapacity = it->sCapacityToText();
|
||||
|
||||
|
||||
|
||||
// WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity);
|
||||
|
||||
|
||||
WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (i) )+3, sModelFamily, sModelName, sCapacity);
|
||||
|
||||
}*/
|
||||
// vWinDriveEntries.push_back(tmp);
|
||||
wrefresh(tmp);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TUI::centerTitle(WINDOW *pwin, const char * title) {
|
||||
int x, maxX, stringSize;
|
||||
getmaxyx(pwin, maxX, maxX);
|
||||
stringSize = 4 + strlen(title);
|
||||
x = (maxX - stringSize)/2;
|
||||
mvwaddch(pwin, 0, x, ACS_RTEE);
|
||||
waddch(pwin, ' ');
|
||||
waddstr(pwin, title);
|
||||
waddch(pwin, ' ');
|
||||
waddch(pwin, ACS_LTEE);
|
||||
}
|
||||
|
||||
WINDOW* TUI::createOverViewWindow( int iXSize, int iYSize) {
|
||||
WINDOW *newWindow;
|
||||
newWindow = newwin(iYSize, iXSize, 2, 2);
|
||||
init_pair(COLOR_AREA_OVERVIEW, COLOR_BLACK, COLOR_GRAY);
|
||||
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_OVERVIEW));
|
||||
box(newWindow, ACS_VLINE, ACS_HLINE);
|
||||
|
||||
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
char buffer[80];
|
||||
|
||||
time (&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
|
||||
strftime(buffer,sizeof(buffer),"%d-%m-%Y %H:%M:%S",timeinfo);
|
||||
std::string str(buffer);
|
||||
|
||||
|
||||
centerTitle(newWindow, str.c_str());
|
||||
|
||||
return newWindow;
|
||||
}
|
||||
|
||||
|
||||
WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart) {
|
||||
WINDOW *newWindow;
|
||||
newWindow = newwin(iYSize, iXSize, 2, iXStart);
|
||||
init_pair(COLOR_AREA_OVERVIEW, COLOR_BLACK, COLOR_GRAY);
|
||||
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_OVERVIEW));
|
||||
box(newWindow, ACS_VLINE, ACS_HLINE);
|
||||
centerTitle(newWindow, "Selected Drive: xyz");
|
||||
|
||||
// mvaddstr(iXStart+1, 5, "Test");
|
||||
|
||||
return newWindow;
|
||||
}
|
||||
|
||||
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity) {
|
||||
WINDOW *newWindow;
|
||||
newWindow = newwin(iYSize, iXSize, iYStart, iXStart);
|
||||
init_pair(COLOR_AREA_ENTRY, COLOR_BLACK, COLOR_GRAY);
|
||||
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_ENTRY));
|
||||
box(newWindow, ACS_VLINE, ACS_HLINE);
|
||||
|
||||
attron(COLOR_PAIR(COLOR_AREA_ENTRY));
|
||||
mvaddstr(iYStart+1, 5, "Test");
|
||||
|
||||
//addstr("test");
|
||||
|
||||
|
||||
//cout << "X: " << sModelFamily << endl;
|
||||
|
||||
// mvaddstr(iYStart+2, 5, sModelName.c_str());
|
||||
//mvaddstr(iYStart+3, 5, sCapacity.c_str());
|
||||
|
||||
refresh();
|
||||
|
||||
return newWindow;
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* @file tui.cpp
|
||||
* @brief display user interface
|
||||
* @author hendrik schutter
|
||||
* @date 03.08.2020
|
||||
*/
|
||||
|
||||
//#include "../include/reHDD.h"
|
||||
|
||||
/*
|
||||
|
||||
TUI_DATA::TUI_DATA(vector <Drive>* pvecDrives)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
@ -46,6 +46,18 @@ uint32_t Drive::getPowerCycles(void)
|
||||
return u32PowerCycles;
|
||||
}
|
||||
|
||||
string Drive::sCapacityToText(){
|
||||
if(getCapacity() <= (999*1000000000U)){
|
||||
// Less or even 999 GB --> GB
|
||||
return to_string(getCapacity() / 1000000000U) + " GB";
|
||||
}
|
||||
else{
|
||||
// More 999 GB --> TB
|
||||
return to_string(getCapacity() / 1000000000000U) + " TB";
|
||||
}
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief set S.M.A.R.T. values in model
|
||||
* \param string modelFamily
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user