summaryrefslogtreecommitdiffstats
path: root/AffinityPanel.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2007-12-17 05:50:00 +0000
committerHisham Muhammad <hisham@gobolinux.org>2007-12-17 05:50:00 +0000
commita839c3f2ca5a11b2293ad0c588859d38aa98d194 (patch)
treef8c480ea87334ca6efce6f5fe49c9184f1ba2b46 /AffinityPanel.c
parent807df03671daa6d77b445c26f050381d231947ac (diff)
Adding affinity panel
Diffstat (limited to 'AffinityPanel.c')
-rw-r--r--AffinityPanel.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/AffinityPanel.c b/AffinityPanel.c
new file mode 100644
index 00000000..007b0590
--- /dev/null
+++ b/AffinityPanel.c
@@ -0,0 +1,48 @@
+
+#include "AffinityPanel.h"
+
+#include "Panel.h"
+#include "CheckItem.h"
+
+#include "debug.h"
+#include <assert.h>
+
+Panel* AffinityPanel_new(int processorCount, unsigned long mask) {
+ Panel* this = Panel_new(1, 1, 1, 1, CHECKITEM_CLASS, true, ListItem_compare);
+ this->eventHandler = AffinityPanel_eventHandler;
+
+ Panel_setHeader(this, "Use CPUs:");
+ for (int i = 0; i < processorCount; i++) {
+ char number[10];
+ snprintf(number, 9, "%d", i+1);
+ Panel_add(this, (Object*) CheckItem_new(String_copy(number), NULL, mask & (1 << i)));
+ }
+ return this;
+}
+
+unsigned long AffinityPanel_getAffinity(Panel* this) {
+ int size = Panel_getSize(this);
+ unsigned long mask = 0;
+ for (int i = 0; i < size; i++) {
+ if (CheckItem_get((CheckItem*)Panel_get(this, i)))
+ mask = mask | (1 << i);
+ }
+ return mask;
+}
+
+HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) {
+ HandlerResult result = IGNORED;
+ CheckItem* selected = (CheckItem*) Panel_getSelected(this);
+ switch(ch) {
+ case ' ':
+ CheckItem_set(selected, ! (CheckItem_get(selected)) );
+ result = HANDLED;
+ break;
+ case 0x0a:
+ case 0x0d:
+ case KEY_ENTER:
+ result = BREAK_LOOP;
+ break;
+ }
+ return result;
+}

© 2014-2024 Faster IT GmbH | imprint | privacy policy