aboutsummaryrefslogtreecommitdiffstats
path: root/AffinityPanel.c
blob: 73cf165fe964297ec836b8e13e241d031b215ba7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

#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 0x0a:
   case 0x0d:
   case KEY_ENTER:
   case ' ':
      CheckItem_set(selected, ! (CheckItem_get(selected)) );
      result = HANDLED;
   }
   return result;
}

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