stated to implement threading

This commit is contained in:
Hendrik Schutter 2020-08-03 22:40:07 +02:00
parent 8e4837a317
commit daa3a27edb
10 changed files with 264 additions and 10 deletions

View File

@ -46,6 +46,11 @@ private:
uint32_t u32ErrorCount = 0U;
uint32_t u32PowerOnHours = 0U; //in hours
uint32_t u32PowerCycles = 0U;
uint32_t u32ShredPercentage = 0U; //in percent
};
#endif // DRIVE_H_

View File

@ -15,12 +15,17 @@
#include <vector>
#include <time.h>
#include <chrono>
#include <curses.h>
#include <thread>
#include <unistd.h>
using namespace std;
#include "drive.h"
#include "smart.h"
#include "wipe.h"
//#include "tui.h"
//#include "tui_data.h"
template <typename T, typename I> T* iterator_to_pointer(I i)
{
@ -40,9 +45,16 @@ private:
vector <Drive> vecDrives; //stores all drive data
void searchDrives(vector <Drive>* pvecDrives);
void printDrives(vector <Drive>* pvecDrives);
void filterIgnoredDrives(vector <Drive>* pvecDrives);
void addSMARTData(vector <Drive>* pvecDrives);
static void ThreadDevices();
};

41
include/tui.h Normal file
View File

@ -0,0 +1,41 @@
/**
* @file tui.h
* @brief display user interface
* @author hendrik schutter
* @date 03.08.2020
*/
#ifndef TUI_H_
#define TUI_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
{
protected:
public:
TUI(void);
void initTUI();
void updateTUI(TUI_DATA data);
private:
void centerTitle(WINDOW *pwin, const char * title);
};
#endif // TUI_H_

45
include/tui_data.h Normal file
View File

@ -0,0 +1,45 @@
/**
* @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_

View File

@ -18,7 +18,7 @@ DCOMPILE_FLAGS = -D DEBUG
# Add additional include paths
INCLUDES = include
# General linker settings
LINK_FLAGS =
LINK_FLAGS = -lpthread
# Doc
DOCDIR = doc
#### END PROJECT SETTINGS ####

39
src/TUI/tui.cpp Normal file
View File

@ -0,0 +1,39 @@
/**
* @file tui.cpp
* @brief display user interface
* @author hendrik schutter
* @date 03.08.2020
*/
/*
#include "../include/reHDD.h"
*/
/**
* \brief wipe drive with shred
* \param pointer of Drive instance
* \return void
*/
/*
void TUI::initTUI()
{
initscr();
raw();
keypad(stdscr,TRUE);
if(has_colors() == TRUE) {
start_color();
} else {
printf("Your terminal does not support color\n");
exit(1);
}
clear();
curs_set(0);
init_color(COLOR_GRAY, 173, 170, 173);
}
void TUI::updateTUI(TUI_DATA data){
}*/

29
src/TUI/tui_data.cpp Normal file
View File

@ -0,0 +1,29 @@
/**
* @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)
{
}
*/

View File

@ -14,7 +14,7 @@
*/
int main(void)
{
cout << "refurbishingHddTool" << endl;
// cout << "refurbishingHddTool" << endl;
reHDD* app = new reHDD();
app->app_logic();

View File

@ -7,6 +7,9 @@
#include "../include/reHDD.h"
static int fd[2];//File descriptor for creating a pipe
/**
* \brief app constructor
* \param void
@ -26,10 +29,44 @@ void reHDD::app_logic(void)
{
cout << "app logic" << endl;
searchDrives(&vecDrives); //search for new drives and store them in list
filterIgnoredDrives(&vecDrives); //filter out ignored drives
addSMARTData(&vecDrives); //add S.M.A.R.T. Data to the drives
printDrives(&vecDrives); //print currently attached drives
thread thDevices(ThreadDevices);
//searchDrives(&vecDrives); //search for new drives and store them in list
//filterIgnoredDrives(&vecDrives); //filter out ignored drives
//addSMARTData(&vecDrives); //add S.M.A.R.T. Data to the drives
// printDrives(&vecDrives); //print currently attached drives
int result = pipe (fd);
while(1){
char ch;
result = read (fd[0],&ch,1);
if (result != 1) {
perror("read");
exit(3);
}
printf ("From Main Thread: %c\n", ch);
}
thDevices.join();
std::cout << std::endl;
/*
size_t u64SelectedDriveIndex = 0U;
size_t u64DriveVecSize = (vecDrives.size());
@ -39,18 +76,60 @@ void reHDD::app_logic(void)
cout << "Selected drive index: " << u64SelectedDriveIndex << endl;
if(u64SelectedDriveIndex < (u64DriveVecSize)) {
Wipe::wipeDrive(&vecDrives[u64SelectedDriveIndex]);
// Wipe::wipeDrive(&vecDrives[u64SelectedDriveIndex]);
}
*/
}
void reHDD::ThreadDevices(){
while(true){
cout << "Thread" << endl;
int result = write (fd[1], "A",1);
//cout << result << endl;
if (result != 1){
perror ("write error");
// exit (2);
}
sleep(5); //sleep 5 sec
}
}
/**
* \brief search attached drives on /dev/sd*
* \param pointer of vector <Drive>* pvecDrives
* \return void
*/
void reHDD::searchDrives(vector <Drive>* pvecDrives)
void reHDD::searchDrives(vector <Drive>* pvecDrives)
{
cout << "search drives ..." << endl;
char * cLine = NULL;
size_t len = 0;
@ -71,6 +150,8 @@ void reHDD::searchDrives(vector <Drive>* pvecDrives)
}
}
fclose(outputfileHwinfo);
}
/**

View File

@ -12,7 +12,9 @@
"unordered_map": "cpp",
"string_view": "cpp",
"ostream": "cpp",
"chrono": "cpp"
}
"chrono": "cpp",
"thread": "cpp"
},
"git.ignoreLimitWarning": true
}
}