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
;
108 case MUIA_ProcessorGrp_SingleMode
:
109 *store
= (IPTR
)FALSE
;
114 retval
= DoSuperMethodA(CLASS
, self
, (Msg
) message
);
119 IPTR
ProcessorGauge__MUIM_ProcessorGrp_Update(Class
*CLASS
, Object
*self
, Msg message
)
121 SETUP_PROCGAUGE_INST_DATA
;
125 D(bug("[SysMon:ProcGauge] %s()\n", __func__
));
127 for (i
= 0; i
< data
->pg_CPUCount
; i
++)
129 #if SIMULATE_USAGE_FREQ
132 usage
= (ds
.ds_Tick
* (i
+ 1)) % 100;
134 struct TagItem tags
[] =
136 { GCIT_SelectedProcessor
, (IPTR
)i
},
137 { GCIT_ProcessorLoad
, (IPTR
)&usage
},
138 { TAG_DONE
, TAG_DONE
}
143 usage
= ((usage
>> 16) * 1000) >> 16;
145 __sprintf(buffer
, "CPU %d\n%d.%d %%", i
, usage
/ 10, usage
% 10);
146 set(data
->pg_Gauges
[i
], MUIA_Gauge_Current
, usage
);
147 set(data
->pg_Gauges
[i
], MUIA_Gauge_InfoText
, (IPTR
)buffer
);
152 /*** Setup ******************************************************************/
153 PROCESSORGRP_CUSTOMCLASS
155 ProcessorGauge
, NULL
, MUIC_Group
, NULL
,
156 OM_NEW
, struct opSet
*,
158 OM_SET
, struct opSet
*,
159 OM_GET
, struct opGet
*,
160 MUIM_ProcessorGrp_Update
, Msg