2 Copyright © 2017, The AROS Development Team. All rights reserved.
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
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
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
,
56 MUIA_Gauge_InfoText
, (IPTR
) CPU_DEFSTR
,
57 MUIA_Gauge_Horiz
, FALSE
, MUIA_Gauge_Current
, 0,
62 DoMethod(self
, OM_ADDMEMBER
, data
->pg_Gauges
[i
]);
65 DoMethod(self
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
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
)
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
;
100 D(bug("[SysMon:ProcGauge] %s()\n", __func__
));
102 switch (message
->opg_AttrID
)
104 case MUIA_ProcessorGrp_CPUCount
:
105 *store
= (IPTR
)data
->pg_CPUCount
;
109 case MUIA_ProcessorGrp_SingleMode
:
110 *store
= (IPTR
)FALSE
;
116 retval
= DoSuperMethodA(CLASS
, self
, (Msg
) message
);
121 IPTR
ProcessorGauge__MUIM_ProcessorGrp_Update(Class
*CLASS
, Object
*self
, Msg message
)
123 SETUP_PROCGAUGE_INST_DATA
;
127 D(bug("[SysMon:ProcGauge] %s()\n", __func__
));
129 for (i
= 0; i
< data
->pg_CPUCount
; i
++)
131 #if SIMULATE_USAGE_FREQ
134 usage
= (ds
.ds_Tick
* (i
+ 1)) % 100;
136 struct TagItem tags
[] =
138 { GCIT_SelectedProcessor
, (IPTR
)i
},
139 { GCIT_ProcessorLoad
, (IPTR
)&usage
},
140 { TAG_DONE
, TAG_DONE
}
145 usage
= ((usage
>> 16) * 1000) >> 16;
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
);
154 /*** Setup ******************************************************************/
155 PROCESSORGRP_CUSTOMCLASS
157 ProcessorGauge
, NULL
, MUIC_Group
, NULL
,
158 OM_NEW
, struct opSet
*,
160 OM_SET
, struct opSet
*,
161 OM_GET
, struct opGet
*,
162 MUIM_ProcessorGrp_Update
, Msg