2012-10-04 23:59:45 +00:00
|
|
|
/*
|
|
|
|
htop - IOPriorityPanel.c
|
|
|
|
(C) 2004-2012 Hisham H. Muhammad
|
2020-10-05 07:51:32 +00:00
|
|
|
Released under the GNU GPLv2, see the COPYING file
|
2012-10-04 23:59:45 +00:00
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
2021-04-29 18:13:36 +00:00
|
|
|
#include "linux/IOPriorityPanel.h"
|
2012-10-04 23:59:45 +00:00
|
|
|
|
2020-09-19 11:55:23 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include "FunctionBar.h"
|
|
|
|
#include "ListItem.h"
|
|
|
|
#include "Object.h"
|
2020-10-14 18:21:09 +00:00
|
|
|
#include "XUtils.h"
|
2021-04-29 18:13:36 +00:00
|
|
|
#include "IOPriority.h"
|
2020-09-19 18:22:34 +00:00
|
|
|
|
2012-10-04 23:59:45 +00:00
|
|
|
|
|
|
|
Panel* IOPriorityPanel_new(IOPriority currPrio) {
|
2021-01-02 22:51:53 +00:00
|
|
|
Panel* this = Panel_new(1, 1, 1, 1, Class(ListItem), true, FunctionBar_newEnterEsc("Set ", "Cancel "));
|
2012-10-04 23:59:45 +00:00
|
|
|
|
|
|
|
Panel_setHeader(this, "IO Priority:");
|
|
|
|
Panel_add(this, (Object*) ListItem_new("None (based on nice)", IOPriority_None));
|
2020-11-01 00:09:51 +00:00
|
|
|
if (currPrio == IOPriority_None) {
|
|
|
|
Panel_setSelected(this, 0);
|
|
|
|
}
|
2020-11-01 00:49:54 +00:00
|
|
|
static const struct {
|
|
|
|
int klass;
|
|
|
|
const char* name;
|
|
|
|
} classes[] = {
|
2012-10-04 23:59:45 +00:00
|
|
|
{ .klass = IOPRIO_CLASS_RT, .name = "Realtime" },
|
|
|
|
{ .klass = IOPRIO_CLASS_BE, .name = "Best-effort" },
|
|
|
|
{ .klass = 0, .name = NULL }
|
|
|
|
};
|
|
|
|
for (int c = 0; classes[c].name; c++) {
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
char name[50];
|
2020-11-26 19:42:38 +00:00
|
|
|
xSnprintf(name, sizeof(name), "%s %d %s", classes[c].name, i, i == 0 ? "(High)" : (i == 7 ? "(Low)" : ""));
|
2012-10-04 23:59:45 +00:00
|
|
|
IOPriority ioprio = IOPriority_tuple(classes[c].klass, i);
|
|
|
|
Panel_add(this, (Object*) ListItem_new(name, ioprio));
|
2020-11-01 00:09:51 +00:00
|
|
|
if (currPrio == ioprio) {
|
|
|
|
Panel_setSelected(this, Panel_size(this) - 1);
|
|
|
|
}
|
2012-10-04 23:59:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Panel_add(this, (Object*) ListItem_new("Idle", IOPriority_Idle));
|
2020-11-01 00:09:51 +00:00
|
|
|
if (currPrio == IOPriority_Idle) {
|
|
|
|
Panel_setSelected(this, Panel_size(this) - 1);
|
|
|
|
}
|
2012-10-04 23:59:45 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
IOPriority IOPriorityPanel_getIOPriority(Panel* this) {
|
2020-10-05 16:27:55 +00:00
|
|
|
const ListItem* selected = (ListItem*) Panel_getSelected(this);
|
|
|
|
return selected ? selected->key : IOPriority_None;
|
2012-10-04 23:59:45 +00:00
|
|
|
}
|