aboutsummaryrefslogtreecommitdiffstats
path: root/AffinityPanel.c
diff options
context:
space:
mode:
authorAmit Pundir <amit.pundir@linaro.org>2012-04-17 15:05:59 +0530
committerAmit Pundir <amit.pundir@linaro.org>2012-04-17 15:05:59 +0530
commit96a11754a6950bfe50784c0877cb64b1ed7d2b18 (patch)
treeb977131bbbb4c3bd8ade370aab2e4fc913440c04 /AffinityPanel.c
downloadandroid_external_htop-96a11754a6950bfe50784c0877cb64b1ed7d2b18.tar.gz
android_external_htop-96a11754a6950bfe50784c0877cb64b1ed7d2b18.tar.bz2
android_external_htop-96a11754a6950bfe50784c0877cb64b1ed7d2b18.zip
add original htop code
htop-0.9 downloaded from http://archive.ubuntu.com/ubuntu/pool/universe/h/htop/htop_0.9.orig.tar.gz Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Diffstat (limited to 'AffinityPanel.c')
-rw-r--r--AffinityPanel.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/AffinityPanel.c b/AffinityPanel.c
new file mode 100644
index 0000000..bcd99a3
--- /dev/null
+++ b/AffinityPanel.c
@@ -0,0 +1,49 @@
+
+#include "AffinityPanel.h"
+
+#include "Panel.h"
+#include "CheckItem.h"
+
+#include "debug.h"
+#include <assert.h>
+
+static HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) {
+ HandlerResult result = IGNORED;
+ CheckItem* selected = (CheckItem*) Panel_getSelected(this);
+ switch(ch) {
+ case KEY_MOUSE:
+ case ' ':
+ CheckItem_set(selected, ! (CheckItem_get(selected)) );
+ result = HANDLED;
+ break;
+ case 0x0a:
+ case 0x0d:
+ case KEY_ENTER:
+ result = BREAK_LOOP;
+ break;
+ }
+ return result;
+}
+
+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_size(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;
+}