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
4c24a9b4
Commit
4c24a9b4
authored
Mar 31, 2015
by
Hisham Muhammad
Browse files
Fixes to subclassing Process.
parent
5320bab2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Process.c
View file @
4c24a9b4
...
@@ -192,6 +192,15 @@ typedef struct Process_ {
...
@@ -192,6 +192,15 @@ typedef struct Process_ {
} Process;
} Process;
typedef void (*Process_WriteField)(Process*, RichString*, ProcessField);
typedef struct ProcessClass_ {
const ObjectClass super;
const Process_WriteField writeField;
} ProcessClass;
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
}*/
}*/
const
char
*
Process_fieldNames
[]
=
{
const
char
*
Process_fieldNames
[]
=
{
...
@@ -470,7 +479,7 @@ static inline void Process_outputRate(RichString* str, int attr, char* buffer, i
...
@@ -470,7 +479,7 @@ static inline void Process_outputRate(RichString* str, int attr, char* buffer, i
RichString_append
(
str
,
attr
,
buffer
);
RichString_append
(
str
,
attr
,
buffer
);
}
}
static
void
Process_writeField
(
Process
*
this
,
RichString
*
str
,
ProcessField
field
)
{
void
Process_writeField
(
Process
*
this
,
RichString
*
str
,
ProcessField
field
)
{
char
buffer
[
256
];
buffer
[
255
]
=
'\0'
;
char
buffer
[
256
];
buffer
[
255
]
=
'\0'
;
int
attr
=
CRT_colors
[
DEFAULT_COLOR
];
int
attr
=
CRT_colors
[
DEFAULT_COLOR
];
int
baseattr
=
CRT_colors
[
PROCESS_BASENAME
];
int
baseattr
=
CRT_colors
[
PROCESS_BASENAME
];
...
@@ -630,12 +639,12 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
...
@@ -630,12 +639,12 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
RichString_append
(
str
,
attr
,
buffer
);
RichString_append
(
str
,
attr
,
buffer
);
}
}
static
void
Process_display
(
Object
*
cast
,
RichString
*
out
)
{
void
Process_display
(
Object
*
cast
,
RichString
*
out
)
{
Process
*
this
=
(
Process
*
)
cast
;
Process
*
this
=
(
Process
*
)
cast
;
ProcessField
*
fields
=
this
->
pl
->
fields
;
ProcessField
*
fields
=
this
->
pl
->
fields
;
RichString_prune
(
out
);
RichString_prune
(
out
);
for
(
int
i
=
0
;
fields
[
i
];
i
++
)
for
(
int
i
=
0
;
fields
[
i
];
i
++
)
Process
_
writeField
(
this
,
out
,
fields
[
i
]);
As_
Process
(
this
)
->
writeField
(
this
,
out
,
fields
[
i
]);
if
(
this
->
pl
->
shadowOtherUsers
&&
(
int
)
this
->
st_uid
!=
Process_getuid
)
if
(
this
->
pl
->
shadowOtherUsers
&&
(
int
)
this
->
st_uid
!=
Process_getuid
)
RichString_setAttr
(
out
,
CRT_colors
[
PROCESS_SHADOW
]);
RichString_setAttr
(
out
,
CRT_colors
[
PROCESS_SHADOW
]);
if
(
this
->
tag
==
true
)
if
(
this
->
tag
==
true
)
...
@@ -651,11 +660,14 @@ void Process_done(Process* this) {
...
@@ -651,11 +660,14 @@ void Process_done(Process* this) {
#endif
#endif
}
}
ObjectClass
Process_class
=
{
ProcessClass
Process_class
=
{
.
extends
=
Class
(
Object
),
.
super
=
{
.
display
=
Process_display
,
.
extends
=
Class
(
Object
),
.
delete
=
Process_delete
,
.
display
=
Process_display
,
.
compare
=
Process_compare
.
delete
=
Process_delete
,
.
compare
=
Process_compare
},
.
writeField
=
Process_writeField
,
};
};
void
Process_init
(
Process
*
this
,
struct
ProcessList_
*
pl
)
{
void
Process_init
(
Process
*
this
,
struct
ProcessList_
*
pl
)
{
...
...
Process.h
View file @
4c24a9b4
...
@@ -171,6 +171,15 @@ typedef struct Process_ {
...
@@ -171,6 +171,15 @@ typedef struct Process_ {
}
Process
;
}
Process
;
typedef
void
(
*
Process_WriteField
)(
Process
*
,
RichString
*
,
ProcessField
);
typedef
struct
ProcessClass_
{
const
ObjectClass
super
;
const
Process_WriteField
writeField
;
}
ProcessClass
;
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
extern
const
char
*
Process_fieldNames
[];
extern
const
char
*
Process_fieldNames
[];
...
@@ -189,9 +198,13 @@ void Process_setupColumnWidths();
...
@@ -189,9 +198,13 @@ void Process_setupColumnWidths();
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
void
Process_writeField
(
Process
*
this
,
RichString
*
str
,
ProcessField
field
);
void
Process_display
(
Object
*
cast
,
RichString
*
out
);
void
Process_done
(
Process
*
this
);
void
Process_done
(
Process
*
this
);
extern
Object
Class
Process_class
;
extern
Process
Class
Process_class
;
void
Process_init
(
Process
*
this
,
struct
ProcessList_
*
pl
);
void
Process_init
(
Process
*
this
,
struct
ProcessList_
*
pl
);
...
...
htop.c
View file @
4c24a9b4
...
@@ -694,7 +694,7 @@ int main(int argc, char** argv) {
...
@@ -694,7 +694,7 @@ int main(int argc, char** argv) {
CRT_init
(
settings
->
delay
,
settings
->
colorScheme
);
CRT_init
(
settings
->
delay
,
settings
->
colorScheme
);
Panel
*
panel
=
Panel_new
(
0
,
headerHeight
,
COLS
,
LINES
-
headerHeight
-
2
,
false
,
&
Process_class
);
Panel
*
panel
=
Panel_new
(
0
,
headerHeight
,
COLS
,
LINES
-
headerHeight
-
2
,
false
,
(
ObjectClass
*
)
&
Process_class
);
ProcessList_setPanel
(
pl
,
panel
);
ProcessList_setPanel
(
pl
,
panel
);
FunctionBar
*
defaultBar
=
FunctionBar_new
(
defaultFunctions
,
NULL
,
NULL
);
FunctionBar
*
defaultBar
=
FunctionBar_new
(
defaultFunctions
,
NULL
,
NULL
);
...
...
linux/LinuxProcess.c
View file @
4c24a9b4
...
@@ -27,9 +27,19 @@ typedef struct LinuxProcess_ {
...
@@ -27,9 +27,19 @@ typedef struct LinuxProcess_ {
}*/
}*/
ProcessClass
LinuxProcess_class
=
{
.
super
=
{
.
extends
=
Class
(
Process
),
.
display
=
Process_display
,
.
delete
=
Process_delete
,
.
compare
=
LinuxProcess_compare
},
.
writeField
=
(
Process_WriteField
)
LinuxProcess_writeField
,
};
LinuxProcess
*
LinuxProcess_new
(
ProcessList
*
pl
)
{
LinuxProcess
*
LinuxProcess_new
(
ProcessList
*
pl
)
{
LinuxProcess
*
this
=
calloc
(
sizeof
(
LinuxProcess
),
1
);
LinuxProcess
*
this
=
calloc
(
sizeof
(
LinuxProcess
),
1
);
Object_setClass
(
this
,
Class
(
Process
));
Object_setClass
(
this
,
Class
(
Linux
Process
));
Process_init
(
&
this
->
super
,
pl
);
Process_init
(
&
this
->
super
,
pl
);
return
this
;
return
this
;
}
}
...
@@ -85,7 +95,8 @@ void LinuxProcess_writeField(LinuxProcess* this, RichString* str, ProcessField f
...
@@ -85,7 +95,8 @@ void LinuxProcess_writeField(LinuxProcess* this, RichString* str, ProcessField f
break
;
break
;
}
}
default:
default:
snprintf
(
buffer
,
n
,
"- "
);
Process_writeField
((
Process
*
)
this
,
str
,
field
);
return
;
}
}
RichString_append
(
str
,
attr
,
buffer
);
RichString_append
(
str
,
attr
,
buffer
);
}
}
...
@@ -104,6 +115,6 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
...
@@ -104,6 +115,6 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
case
IO_PRIORITY
:
case
IO_PRIORITY
:
return
LinuxProcess_effectiveIOPriority
(
p1
)
-
LinuxProcess_effectiveIOPriority
(
p2
);
return
LinuxProcess_effectiveIOPriority
(
p1
)
-
LinuxProcess_effectiveIOPriority
(
p2
);
default:
default:
return
(
p1
->
super
.
pid
-
p2
->
super
.
pid
);
return
Process_compare
(
v1
,
v2
);
}
}
}
}
linux/LinuxProcess.h
View file @
4c24a9b4
...
@@ -20,6 +20,8 @@ typedef struct LinuxProcess_ {
...
@@ -20,6 +20,8 @@ typedef struct LinuxProcess_ {
#define Process_delete LinuxProcess_delete
#define Process_delete LinuxProcess_delete
extern
ProcessClass
LinuxProcess_class
;
LinuxProcess
*
LinuxProcess_new
(
ProcessList
*
pl
);
LinuxProcess
*
LinuxProcess_new
(
ProcessList
*
pl
);
void
LinuxProcess_delete
(
Object
*
cast
);
void
LinuxProcess_delete
(
Object
*
cast
);
...
...
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