- Update stm32f7_discovery target description
[AROS.git] / workbench / system / SysMon / processor_gauge.c
blobecb662d3094cc1087de9e652111efcb0a816401a
1 /*
2 Copyright © 2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
7 #include <aros/debug.h>
9 #include <proto/utility.h>
10 #include <proto/intuition.h>
11 #include <proto/muimaster.h>
12 #include <proto/processor.h>
14 #include <clib/alib_protos.h>
16 #include <resources/processor.h>
18 #include "sysmon_intern.h"
20 #include "processor.h"
22 struct ProcessorGauge_DATA
24 IPTR pg_CPUCount;
25 Object **pg_Gauges;
28 #define SETUP_PROCGAUGE_INST_DATA struct ProcessorGauge_DATA *data = INST_DATA(CLASS, self)
30 Object *ProcessorGauge__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
32 ULONG processorcount = (ULONG)GetTagData(MUIA_ProcessorGrp_CPUCount, 1, message->ops_AttrList);
34 D(bug("[SysMon:ProcGauge] %s()\n", __func__));
36 self = (Object *) DoSuperNewTags(CLASS, self, NULL,
37 MUIA_Group_Columns, processorcount + 2,
38 TAG_MORE, (IPTR) message->ops_AttrList
41 if (self != NULL)
43 int i;
45 SETUP_PROCGAUGE_INST_DATA;
47 data->pg_CPUCount = processorcount;
48 data->pg_Gauges = AllocMem(sizeof(Object *) * processorcount, MEMF_ANY | MEMF_CLEAR);
50 DoMethod(self, OM_ADDMEMBER, (IPTR)HVSpace);
52 for (i = 0; i < processorcount; i++)
54 data->pg_Gauges[i] = GaugeObject,
55 GaugeFrame,
56 MUIA_Gauge_InfoText, (IPTR) CPU_DEFSTR,
57 MUIA_Gauge_Horiz, FALSE, MUIA_Gauge_Current, 0,
58 MUIA_Gauge_Max, 1000,
59 MUIA_UserData, i,
60 End;
62 DoMethod(self, OM_ADDMEMBER, data->pg_Gauges[i]);
65 DoMethod(self, OM_ADDMEMBER, (IPTR)HVSpace);
68 return self;
71 IPTR ProcessorGauge__OM_DISPOSE(Class *CLASS, Object *self, Msg message)
73 D(bug("[SysMon:ProcGauge] %s()\n", __func__));
75 return DoSuperMethodA(CLASS, self, message);
78 IPTR ProcessorGauge__OM_SET(Class *CLASS, Object *self, struct opSet *message)
80 // SETUP_PROCGAUGE_INST_DATA;
81 struct TagItem *tstate = message->ops_AttrList, *tag;
83 D(bug("[SysMon:ProcGauge] %s()\n", __func__));
85 while ((tag = NextTagItem((struct TagItem **)&tstate)) != NULL)
87 switch (tag->ti_Tag)
91 return DoSuperMethodA(CLASS, self, (Msg) message);
94 IPTR ProcessorGauge__OM_GET(Class *CLASS, Object *self, struct opGet *message)
96 SETUP_PROCGAUGE_INST_DATA;
97 IPTR *store = message->opg_Storage;
98 IPTR retval = 0;
100 D(bug("[SysMon:ProcGauge] %s()\n", __func__));
102 switch (message->opg_AttrID)
104 case MUIA_ProcessorGrp_CPUCount:
105 *store = (IPTR)data->pg_CPUCount;
106 retval = TRUE;
107 break;
109 case MUIA_ProcessorGrp_SingleMode:
110 *store = (IPTR)FALSE;
111 retval = TRUE;
112 break;
115 if (!retval)
116 retval = DoSuperMethodA(CLASS, self, (Msg) message);
118 return retval;
121 IPTR ProcessorGauge__MUIM_ProcessorGrp_Update(Class *CLASS, Object *self, Msg message)
123 SETUP_PROCGAUGE_INST_DATA;
124 TEXT buffer[128];
125 ULONG i, usage;
127 D(bug("[SysMon:ProcGauge] %s()\n", __func__));
129 for (i = 0; i < data->pg_CPUCount; i++)
131 #if SIMULATE_USAGE_FREQ
132 struct DateStamp ds;
133 DateStamp(&ds);
134 usage = (ds.ds_Tick * (i + 1)) % 100;
135 #else
136 struct TagItem tags [] =
138 { GCIT_SelectedProcessor, (IPTR)i },
139 { GCIT_ProcessorLoad, (IPTR)&usage },
140 { TAG_DONE, TAG_DONE }
143 usage = 0;
144 GetCPUInfo(tags);
145 usage = ((usage >> 16) * 1000) >> 16;
146 #endif
147 __sprintf(buffer, "CPU %d\n%d.%d %%", i, usage / 10, usage % 10);
148 set(data->pg_Gauges[i], MUIA_Gauge_Current, usage);
149 set(data->pg_Gauges[i], MUIA_Gauge_InfoText, (IPTR)buffer);
151 return 0;
154 /*** Setup ******************************************************************/
155 PROCESSORGRP_CUSTOMCLASS
157 ProcessorGauge, NULL, MUIC_Group, NULL,
158 OM_NEW, struct opSet *,
159 OM_DISPOSE, Msg,
160 OM_SET, struct opSet *,
161 OM_GET, struct opGet *,
162 MUIM_ProcessorGrp_Update, Msg