2007-12-17 05:50:00 +00:00
|
|
|
|
2011-09-24 00:30:47 +00:00
|
|
|
#include "ProcessList.h"
|
2007-12-17 05:50:00 +00:00
|
|
|
#include "AffinityPanel.h"
|
|
|
|
#include "Panel.h"
|
|
|
|
#include "CheckItem.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) {
|
|
|
|
CheckItem* selected = (CheckItem*) Panel_getSelected(this);
|
|
|
|
switch(ch) {
|
2008-05-07 23:01:45 +00:00
|
|
|
case KEY_MOUSE:
|
2008-03-09 08:58:38 +00:00
|
|
|
case ' ':
|
|
|
|
CheckItem_set(selected, ! (CheckItem_get(selected)) );
|
2011-11-05 04:42:15 +00:00
|
|
|
return HANDLED;
|
2008-03-09 08:58:38 +00:00
|
|
|
case 0x0a:
|
|
|
|
case 0x0d:
|
|
|
|
case KEY_ENTER:
|
2011-11-05 04:42:15 +00:00
|
|
|
return BREAK_LOOP;
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
2011-11-05 04:42:15 +00:00
|
|
|
return IGNORED;
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
|
2011-09-24 00:30:47 +00:00
|
|
|
Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) {
|
2007-12-17 05:50:00 +00:00
|
|
|
Panel* this = Panel_new(1, 1, 1, 1, CHECKITEM_CLASS, true, ListItem_compare);
|
|
|
|
this->eventHandler = AffinityPanel_eventHandler;
|
|
|
|
|
|
|
|
Panel_setHeader(this, "Use CPUs:");
|
2011-09-24 00:30:47 +00:00
|
|
|
int curCpu = 0;
|
2011-03-22 20:37:08 +00:00
|
|
|
for (int i = 0; i < pl->cpuCount; i++) {
|
2007-12-17 05:50:00 +00:00
|
|
|
char number[10];
|
2011-09-08 02:48:53 +00:00
|
|
|
snprintf(number, 9, "%d", ProcessList_cpuId(pl, i));
|
2011-09-24 00:30:47 +00:00
|
|
|
bool mode;
|
|
|
|
if (curCpu < affinity->used && affinity->cpus[curCpu] == i) {
|
|
|
|
mode = true;
|
|
|
|
curCpu++;
|
|
|
|
} else {
|
|
|
|
mode = false;
|
|
|
|
}
|
2011-12-25 20:23:53 +00:00
|
|
|
Panel_add(this, (Object*) CheckItem_new(strdup(number), NULL, mode));
|
2007-12-17 05:50:00 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2011-09-24 00:30:47 +00:00
|
|
|
Affinity* AffinityPanel_getAffinity(Panel* this) {
|
|
|
|
Affinity* affinity = Affinity_new();
|
2009-06-02 04:51:23 +00:00
|
|
|
int size = Panel_size(this);
|
2007-12-17 05:50:00 +00:00
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
if (CheckItem_get((CheckItem*)Panel_get(this, i)))
|
2011-09-24 00:30:47 +00:00
|
|
|
Affinity_add(affinity, i);
|
2007-12-17 05:50:00 +00:00
|
|
|
}
|
2011-09-24 00:30:47 +00:00
|
|
|
return affinity;
|
2007-12-17 05:50:00 +00:00
|
|
|
}
|