IOPriorityPanel.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. htop - IOPriorityPanel.c
  3. (C) 2004-2012 Hisham H. Muhammad
  4. Released under the GNU GPLv2+, see the COPYING file
  5. in the source distribution for its full text.
  6. */
  7. #include "config.h" // IWYU pragma: keep
  8. #include "linux/IOPriorityPanel.h"
  9. #include <stdbool.h>
  10. #include <stddef.h>
  11. #include "FunctionBar.h"
  12. #include "ListItem.h"
  13. #include "Object.h"
  14. #include "XUtils.h"
  15. #include "IOPriority.h"
  16. Panel* IOPriorityPanel_new(IOPriority currPrio) {
  17. Panel* this = Panel_new(1, 1, 1, 1, Class(ListItem), true, FunctionBar_newEnterEsc("Set ", "Cancel "));
  18. Panel_setHeader(this, "IO Priority:");
  19. Panel_add(this, (Object*) ListItem_new("None (based on nice)", IOPriority_None));
  20. if (currPrio == IOPriority_None) {
  21. Panel_setSelected(this, 0);
  22. }
  23. static const struct {
  24. int klass;
  25. const char* name;
  26. } classes[] = {
  27. { .klass = IOPRIO_CLASS_RT, .name = "Realtime" },
  28. { .klass = IOPRIO_CLASS_BE, .name = "Best-effort" },
  29. { .klass = 0, .name = NULL }
  30. };
  31. for (int c = 0; classes[c].name; c++) {
  32. for (int i = 0; i < 8; i++) {
  33. char name[50];
  34. xSnprintf(name, sizeof(name), "%s %d %s", classes[c].name, i, i == 0 ? "(High)" : (i == 7 ? "(Low)" : ""));
  35. IOPriority ioprio = IOPriority_tuple(classes[c].klass, i);
  36. Panel_add(this, (Object*) ListItem_new(name, ioprio));
  37. if (currPrio == ioprio) {
  38. Panel_setSelected(this, Panel_size(this) - 1);
  39. }
  40. }
  41. }
  42. Panel_add(this, (Object*) ListItem_new("Idle", IOPriority_Idle));
  43. if (currPrio == IOPriority_Idle) {
  44. Panel_setSelected(this, Panel_size(this) - 1);
  45. }
  46. return this;
  47. }
  48. IOPriority IOPriorityPanel_getIOPriority(Panel* this) {
  49. const ListItem* selected = (ListItem*) Panel_getSelected(this);
  50. return selected ? selected->key : IOPriority_None;
  51. }