Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
b192af00
Commit
b192af00
authored
Nov 27, 2014
by
Hisham Muhammad
Browse files
Decouple Header from Meter classes.
(Yes, that's dynamic typing!)
parent
cda6bdd5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Header.c
View file @
b192af00
...
@@ -8,15 +8,6 @@ in the source distribution for its full text.
...
@@ -8,15 +8,6 @@ in the source distribution for its full text.
#include "Header.h"
#include "Header.h"
#include "CRT.h"
#include "CRT.h"
#include "CPUMeter.h"
#include "MemoryMeter.h"
#include "SwapMeter.h"
#include "TasksMeter.h"
#include "LoadAverageMeter.h"
#include "UptimeMeter.h"
#include "BatteryMeter.h"
#include "ClockMeter.h"
#include "HostnameMeter.h"
#include "String.h"
#include "String.h"
#include <assert.h>
#include <assert.h>
...
@@ -138,23 +129,6 @@ MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side) {
...
@@ -138,23 +129,6 @@ MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side) {
return
meter
->
mode
;
return
meter
->
mode
;
}
}
void
Header_defaultMeters
(
Header
*
this
,
int
cpuCount
)
{
if
(
cpuCount
>
8
)
{
Vector_add
(
this
->
leftMeters
,
Meter_new
(
this
->
pl
,
0
,
(
MeterClass
*
)
Class
(
LeftCPUs2Meter
)));
Vector_add
(
this
->
rightMeters
,
Meter_new
(
this
->
pl
,
0
,
(
MeterClass
*
)
Class
(
RightCPUs2Meter
)));
}
else
if
(
cpuCount
>
4
)
{
Vector_add
(
this
->
leftMeters
,
Meter_new
(
this
->
pl
,
0
,
(
MeterClass
*
)
Class
(
LeftCPUsMeter
)));
Vector_add
(
this
->
rightMeters
,
Meter_new
(
this
->
pl
,
0
,
(
MeterClass
*
)
Class
(
RightCPUsMeter
)));
}
else
{
Vector_add
(
this
->
leftMeters
,
Meter_new
(
this
->
pl
,
0
,
(
MeterClass
*
)
Class
(
AllCPUsMeter
)));
}
Vector_add
(
this
->
leftMeters
,
Meter_new
(
this
->
pl
,
0
,
(
MeterClass
*
)
Class
(
MemoryMeter
)));
Vector_add
(
this
->
leftMeters
,
Meter_new
(
this
->
pl
,
0
,
(
MeterClass
*
)
Class
(
SwapMeter
)));
Vector_add
(
this
->
rightMeters
,
Meter_new
(
this
->
pl
,
0
,
(
MeterClass
*
)
Class
(
TasksMeter
)));
Vector_add
(
this
->
rightMeters
,
Meter_new
(
this
->
pl
,
0
,
(
MeterClass
*
)
Class
(
LoadAverageMeter
)));
Vector_add
(
this
->
rightMeters
,
Meter_new
(
this
->
pl
,
0
,
(
MeterClass
*
)
Class
(
UptimeMeter
)));
}
void
Header_reinit
(
Header
*
this
)
{
void
Header_reinit
(
Header
*
this
)
{
for
(
int
i
=
0
;
i
<
Vector_size
(
this
->
leftMeters
);
i
++
)
{
for
(
int
i
=
0
;
i
<
Vector_size
(
this
->
leftMeters
);
i
++
)
{
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
this
->
leftMeters
,
i
);
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
this
->
leftMeters
,
i
);
...
...
Header.h
View file @
b192af00
...
@@ -47,8 +47,6 @@ char* Header_readMeterName(Header* this, int i, HeaderSide side);
...
@@ -47,8 +47,6 @@ char* Header_readMeterName(Header* this, int i, HeaderSide side);
MeterModeId
Header_readMeterMode
(
Header
*
this
,
int
i
,
HeaderSide
side
);
MeterModeId
Header_readMeterMode
(
Header
*
this
,
int
i
,
HeaderSide
side
);
void
Header_defaultMeters
(
Header
*
this
,
int
cpuCount
);
void
Header_reinit
(
Header
*
this
);
void
Header_reinit
(
Header
*
this
);
void
Header_draw
(
const
Header
*
this
);
void
Header_draw
(
const
Header
*
this
);
...
...
Settings.c
View file @
b192af00
...
@@ -61,6 +61,23 @@ static void Settings_readMeterModes(Settings* this, char* line, HeaderSide side)
...
@@ -61,6 +61,23 @@ static void Settings_readMeterModes(Settings* this, char* line, HeaderSide side)
String_freeArray
(
ids
);
String_freeArray
(
ids
);
}
}
static
void
Settings_defaultMeters
(
Header
*
header
,
int
cpuCount
)
{
if
(
cpuCount
>
8
)
{
Header_createMeter
(
header
,
"LeftCPUs2"
,
LEFT_HEADER
);
Header_createMeter
(
header
,
"RightCPUs2"
,
RIGHT_HEADER
);
}
else
if
(
cpuCount
>
4
)
{
Header_createMeter
(
header
,
"LeftCPUs"
,
LEFT_HEADER
);
Header_createMeter
(
header
,
"RightCPUs"
,
RIGHT_HEADER
);
}
else
{
Header_createMeter
(
header
,
"AllCPUs"
,
LEFT_HEADER
);
}
Header_createMeter
(
header
,
"Memory"
,
LEFT_HEADER
);
Header_createMeter
(
header
,
"Swap"
,
LEFT_HEADER
);
Header_createMeter
(
header
,
"Tasks"
,
RIGHT_HEADER
);
Header_createMeter
(
header
,
"LoadAverage"
,
RIGHT_HEADER
);
Header_createMeter
(
header
,
"Uptime"
,
RIGHT_HEADER
);
}
static
bool
Settings_read
(
Settings
*
this
,
const
char
*
fileName
,
int
cpuCount
)
{
static
bool
Settings_read
(
Settings
*
this
,
const
char
*
fileName
,
int
cpuCount
)
{
FILE
*
fd
=
fopen
(
fileName
,
"r"
);
FILE
*
fd
=
fopen
(
fileName
,
"r"
);
if
(
!
fd
)
if
(
!
fd
)
...
@@ -153,7 +170,7 @@ static bool Settings_read(Settings* this, const char* fileName, int cpuCount) {
...
@@ -153,7 +170,7 @@ static bool Settings_read(Settings* this, const char* fileName, int cpuCount) {
}
}
fclose
(
fd
);
fclose
(
fd
);
if
(
!
readMeters
)
{
if
(
!
readMeters
)
{
Header
_defaultMeters
(
this
->
header
,
cpuCount
);
Settings
_defaultMeters
(
this
->
header
,
cpuCount
);
}
}
return
true
;
return
true
;
}
}
...
@@ -273,7 +290,7 @@ Settings* Settings_new(ProcessList* pl, Header* header, int cpuCount) {
...
@@ -273,7 +290,7 @@ Settings* Settings_new(ProcessList* pl, Header* header, int cpuCount) {
ok
=
Settings_read
(
this
,
systemSettings
,
cpuCount
);
ok
=
Settings_read
(
this
,
systemSettings
,
cpuCount
);
free
(
systemSettings
);
free
(
systemSettings
);
if
(
!
ok
)
{
if
(
!
ok
)
{
Header
_defaultMeters
(
this
->
header
,
cpuCount
);
Settings
_defaultMeters
(
this
->
header
,
cpuCount
);
pl
->
hideKernelThreads
=
true
;
pl
->
hideKernelThreads
=
true
;
pl
->
highlightMegabytes
=
true
;
pl
->
highlightMegabytes
=
true
;
pl
->
highlightThreads
=
false
;
pl
->
highlightThreads
=
false
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment