-
Notifications
You must be signed in to change notification settings - Fork 0
/
blkdetail_form.cpp
executable file
·134 lines (121 loc) · 3.58 KB
/
blkdetail_form.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "blkdetail_form.h"
#include "ui_blkdetail_form.h"
#include <QFile>
#include <QTextStream>
#include <QPainter>
#include <QPalette>
Blkdetail_form::Blkdetail_form(QWidget *parent, QString path) :
// QDialog(parent),
ui(new Ui::Blkdetail_form)
{
ui->setupUi(this);
/* 1. setup SpinBox */
QFile cp_file("/sys/kernel/debug/hmfs/"+path+"/info");
this->dirName = path;
if(!cp_file.open(QIODevice::ReadWrite)){
/* TODO: error prompt */
return;
}
QTextStream out(&cp_file);
out << "sit s" <<endl;
QTextStream in(&cp_file);
QString line = in.readLine();
QStringList list = line.split(": ");
ui->segno_spin->setMinimum(0);
ui->segno_spin->setMaximum(list[1].toInt());
cp_file.close();
/* 2. setup RenderArea*/
renderArea = new RenderArea;
renderArea->setFixedSize(100,100);
//renderArea->paint();
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(renderArea);
ui->groupBox->setLayout(vbox);
}
Blkdetail_form::~Blkdetail_form()
{
delete ui;
}
RenderArea::RenderArea(QWidget *parent) {
//qpen = new QPen();
//qbrush = new QBrush();
QPalette palette(RenderArea::palette());
palette.setColor(backgroundRole(), Qt::white);
setPalette(palette);
this->init = false;
}
void RenderArea::setInit(bool flag) {
this->init = flag;
}
void RenderArea::paintEvent (QPaintEvent *event){
if(!this->init) return;
//this->setMinimumSize(100,100);
//this->setMaximumSize(200,200);
this->setFixedSize(800,800);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QPen pen(Qt::black);
pen.setWidth(1);
painter.setPen(pen);
QBrush brush(Qt::black);
int x=10,y=5,w=24,h=24;
//TODO: config macro
for(int i=0, curY=y; i<16; i++, curY+=h){
for(int j=0, curX=x; j<32; j++, curX+=w){
QPainterPath path;
path.addRect(curX, curY, w, h);
brush.setColor(typeColor[blkType[i*32+j]]);
painter.fillPath(path, brush);
painter.drawPath(path);
}
}
//this->setInit(false);
}
RenderArea::~RenderArea() {
}
void Blkdetail_form::on_blkDetail_btn_clicked()
{
/* 1. get blk info */
QFile cp_file("/sys/kernel/debug/hmfs/" + dirName + "/info");
if(!cp_file.open(QIODevice::ReadWrite)){
/* TODO: error prompt */
return;
}
QTextStream out(&cp_file);
out << "ssa "<< ui->segno_spin->value() <<endl;
QTextStream in(&cp_file);
QString line = in.readLine();
QStringList list;
int curOfs;
while(!in.atEnd()) {
if(0==line.length()) {
line = in.readLine();
continue;
}
if(line.contains("--")) {
list = line.split(": "); //FORMAT: `-- [<segno>: <blkofs>] --`
if(list.count()<1) continue; //TODO error
list = list[1].split("]");
curOfs = list[0].toInt();
} else if(line.contains("type")) {
list = line.split(": ");
if(list.count()<1) continue; //TODO error
renderArea->blkType[curOfs] = list[1].toInt();
} else if(line.contains("v bit")) {
list = line.split(": ");
if(list.count()<1) continue; //TODO error
if( 0 == list[1].toInt()) {
renderArea->blkType[curOfs] = TYPE_INVALID;
}
}
line = in.readLine();
}
cp_file.close();
/* 2. visualized result */
this->renderArea->setInit(true);
this->renderArea->repaint();
}
void Blkdetail_form::on_segno_spin_editingFinished()
{
this->on_blkDetail_btn_clicked();
}