2 Copyright 2010-2013, The AROS Development Team. All rights reserved.
6 #include <proto/alib.h>
7 #include <proto/muimaster.h>
10 #include "sysmon_intern.h"
14 #define VERSION "$VER: SysMon 1.2 (28.02.2016) ©2011-2016 The AROS Development Team"
16 AROS_UFH3(VOID
, tasklistrefreshbuttonfunction
,
17 AROS_UFHA(struct Hook
*, h
, A0
),
18 AROS_UFHA(Object
*, object
, A2
),
19 AROS_UFHA(APTR
, msg
, A1
))
23 UpdateTasksInformation(h
->h_Data
);
28 BOOL
CreateApplication(struct SysMonData
* smdata
)
31 Object
* tasklistrefreshbutton
;
32 Object
* tasklistautorefreshcheckmark
;
33 Object
* cpuusagegroup
;
34 Object
* cpufreqgroup
;
36 LONG processorcount
= GetProcessorCount();
38 smdata
->tabs
[0] = _(MSG_TAB_TASKS
);
39 smdata
->tabs
[1] = _(MSG_TAB_CPU
);
40 smdata
->tabs
[2] = _(MSG_TAB_SYSTEM
);
41 smdata
->tabs
[3] = NULL
;
43 smdata
->tasklistconstructhook
.h_Entry
= (APTR
)TasksListConstructFunction
;
44 smdata
->tasklistconstructhook
.h_Data
= (APTR
)smdata
;
45 smdata
->tasklistdestructhook
.h_Entry
= (APTR
)TasksListDestructFunction
;
46 smdata
->tasklistdestructhook
.h_Data
= (APTR
)smdata
;
47 smdata
->tasklistdisplayhook
.h_Entry
= (APTR
)TasksListDisplayFunction
;
48 smdata
->taskselectedhook
.h_Entry
= (APTR
)TaskSelectedFunction
;
49 smdata
->taskselectedhook
.h_Data
= (APTR
)smdata
;
50 smdata
->tasklistrefreshbuttonhook
.h_Entry
= (APTR
)tasklistrefreshbuttonfunction
;
51 smdata
->tasklistrefreshbuttonhook
.h_Data
= (APTR
)smdata
;
53 smdata
->tasklistautorefresh
= (IPTR
)0;
55 smdata
->application
= ApplicationObject
,
56 MUIA_Application_Title
, __(MSG_APP_NAME
),
57 MUIA_Application_Version
, (IPTR
) VERSION
,
58 MUIA_Application_Author
, (IPTR
) "Krzysztof Smiechowicz",
59 MUIA_Application_Copyright
, (IPTR
)"©2011-2016, The AROS Development Team",
60 MUIA_Application_Base
, (IPTR
)"SYSMON",
61 MUIA_Application_Description
, __(MSG_APP_TITLE
),
63 smdata
->mainwindow
= WindowObject
,
64 MUIA_Window_Title
, __(MSG_WINDOW_TITLE
),
65 MUIA_Window_ID
, MAKE_ID('S','Y','S','M'),
66 MUIA_Window_Height
, MUIV_Window_Height_Visible(45),
67 MUIA_Window_Width
, MUIV_Window_Width_Visible(35),
69 RegisterGroup(smdata
->tabs
),
71 Child
, ListviewObject
,
72 MUIA_Listview_List
, smdata
->tasklist
= ListObject
,
74 MUIA_List_Format
, "MIW=50 BAR,BAR P=\033r,",
75 MUIA_List_ConstructHook
, &smdata
->tasklistconstructhook
,
76 MUIA_List_DestructHook
, &smdata
->tasklistdestructhook
,
77 MUIA_List_DisplayHook
, &smdata
->tasklistdisplayhook
,
78 MUIA_List_Title
, (IPTR
)TRUE
,
83 Child
, tasklistrefreshbutton
= MUI_MakeObject(MUIO_Button
, _(MSG_LIST_REFRESH
)),
85 Child
, Label(_(MSG_AUTO_REFRESH
)),
86 Child
, tasklistautorefreshcheckmark
= MUI_MakeObject(MUIO_Checkmark
, NULL
),
90 Child
, smdata
->tasklistinfo
= TextObject
,
92 MUIA_Font
, MUIV_Font_Tiny
,
93 MUIA_Text_PreParse
, (IPTR
)"\33r",
94 MUIA_Text_Contents
, (IPTR
)"0 ready, 0 waiting",
101 Child
, cpuusagegroup
= HGroup
, GroupFrameT(_(MSG_USAGE
)),
103 Child
, VGroup
, GroupFrameT(_(MSG_FREQUENCY
)),
104 Child
, cpufreqgroup
= ColGroup(3),
110 Child
, VGroup
, GroupFrameT(_(MSG_MEMORY_SIZE
)),
112 Child
, Label(_(MSG_TOTAL_RAM
)),
113 Child
, smdata
->memorysize
[MEMORY_RAM
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
114 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"2097152 Kb",
116 Child
, Label(_(MSG_CHIP_RAM
)),
117 Child
, smdata
->memorysize
[MEMORY_CHIP
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
118 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
120 Child
, Label(_(MSG_FAST_RAM
)),
121 Child
, smdata
->memorysize
[MEMORY_FAST
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
122 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
126 Child
, VGroup
, GroupFrameT(_(MSG_MEMORY_FREE
)),
128 Child
, Label(_(MSG_TOTAL_RAM
)),
129 Child
, smdata
->memoryfree
[MEMORY_RAM
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
130 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"2097152 Kb",
132 Child
, Label(_(MSG_CHIP_RAM
)),
133 Child
, smdata
->memoryfree
[MEMORY_CHIP
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
134 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
136 Child
, Label(_(MSG_FAST_RAM
)),
137 Child
, smdata
->memoryfree
[MEMORY_FAST
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
138 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
144 Child
, VGroup
, GroupFrameT(_(MSG_VIDEO_SIZE
)),
146 Child
, Label(_(MSG_VIDEO_RAM
)),
147 Child
, smdata
->memorysize
[MEMORY_VRAM
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
148 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
150 Child
, Label(_(MSG_GART_APER
)),
151 Child
, smdata
->memorysize
[MEMORY_GART
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
152 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
156 Child
, VGroup
, GroupFrameT(_(MSG_VIDEO_FREE
)),
158 Child
, Label(_(MSG_VIDEO_RAM
)),
159 Child
, smdata
->memoryfree
[MEMORY_VRAM
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
160 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
162 Child
, Label(_(MSG_GART_APER
)),
163 Child
, smdata
->memoryfree
[MEMORY_GART
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
164 MUIA_Text_PreParse
, (IPTR
)"\33r", MUIA_Text_Contents
, (IPTR
)"",
175 if (!smdata
->application
)
178 DoMethod(smdata
->mainwindow
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
179 smdata
->application
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
181 DoMethod(smdata
->tasklist
, MUIM_Notify
, MUIA_List_Active
, MUIV_EveryTime
,
182 smdata
->application
, 2, MUIM_CallHook
, (IPTR
)&smdata
->taskselectedhook
);
184 DoMethod(tasklistrefreshbutton
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
185 smdata
->application
, 2, MUIM_CallHook
, (IPTR
)&smdata
->tasklistrefreshbuttonhook
);
187 DoMethod(tasklistautorefreshcheckmark
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
188 tasklistrefreshbutton
, 3, MUIM_Set
, MUIA_Disabled
, MUIV_TriggerValue
);
190 DoMethod(tasklistautorefreshcheckmark
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
191 tasklistrefreshbutton
, 3, MUIM_WriteLong
, MUIV_TriggerValue
, &smdata
->tasklistautorefresh
);
193 /* Adding cpu usage gauges */
194 cpucolgroup
= ColGroup(processorcount
+ 1), End
;
196 smdata
->cpuusagegauges
= AllocVec(sizeof(Object
*) * processorcount
, MEMF_ANY
| MEMF_CLEAR
);
198 for (i
= 0; i
< processorcount
; i
++)
200 smdata
->cpuusagegauges
[i
] = GaugeObject
, GaugeFrame
, MUIA_Gauge_InfoText
, (IPTR
) " CPU XX : XXX% ",
201 MUIA_Gauge_Horiz
, FALSE
, MUIA_Gauge_Current
, 0,
202 MUIA_Gauge_Max
, 100, End
;
204 DoMethod(cpucolgroup
, OM_ADDMEMBER
, smdata
->cpuusagegauges
[i
]);
207 DoMethod(cpucolgroup
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
209 DoMethod(cpuusagegroup
, OM_ADDMEMBER
, cpucolgroup
);
211 /* Adding cpu frequency labels */
212 smdata
->cpufreqlabels
= AllocVec(sizeof(Object
*) * processorcount
, MEMF_ANY
| MEMF_CLEAR
);
213 smdata
->cpufreqvalues
= AllocVec(sizeof(Object
*) * processorcount
, MEMF_ANY
| MEMF_CLEAR
);
215 for (i
= 0; i
< processorcount
; i
++)
217 smdata
->cpufreqlabels
[i
] = TextObject
, MUIA_Text_PreParse
, "\33l",
218 MUIA_Text_Contents
, (IPTR
)"", End
;
219 smdata
->cpufreqvalues
[i
] = TextObject
, TextFrame
, MUIA_Background
, MUII_TextBack
,
220 MUIA_Text_PreParse
, (IPTR
)"\33l",
221 MUIA_Text_Contents
, (IPTR
)"", End
;
223 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, smdata
->cpufreqlabels
[i
]);
224 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, smdata
->cpufreqvalues
[i
]);
225 DoMethod(cpufreqgroup
, OM_ADDMEMBER
, (IPTR
)HVSpace
);
231 VOID
DisposeApplication(struct SysMonData
* smdata
)
233 MUI_DisposeObject(smdata
->application
);
235 FreeVec(smdata
->cpuusagegauges
);
236 FreeVec(smdata
->cpufreqlabels
);
237 FreeVec(smdata
->cpufreqvalues
);
240 VOID
DeInitModules(struct SysMonModule
** modules
, struct SysMonData
*smdata
, LONG lastinitedmodule
)
244 for (i
= lastinitedmodule
; i
>= 0; i
--)
245 modules
[i
]->DeInit(smdata
);
248 LONG
InitModules(struct SysMonModule
** modules
, struct SysMonData
*smdata
)
250 LONG lastinitedmodule
= -1;
252 while(modules
[lastinitedmodule
+ 1] != NULL
)
254 if (modules
[lastinitedmodule
+ 1]->Init(smdata
))
258 DeInitModules(modules
, smdata
, lastinitedmodule
);
264 return lastinitedmodule
;
270 ULONG itercounter
= 0;
271 struct SysMonData smdata
;
272 struct SysMonModule
* modules
[] = {&memorymodule
, &videomodule
, &processormodule
, &tasksmodule
, &timermodule
, NULL
};
273 LONG lastinitedmodule
= -1;
275 if ((lastinitedmodule
= InitModules(modules
, &smdata
)) == -1)
278 if (!CreateApplication(&smdata
))
281 UpdateProcessorStaticInformation(&smdata
);
282 UpdateProcessorInformation(&smdata
);
283 UpdateTasksInformation(&smdata
);
284 UpdateMemoryStaticInformation(&smdata
);
285 UpdateMemoryInformation(&smdata
);
286 UpdateVideoStaticInformation(&smdata
);
287 UpdateVideoInformation(&smdata
);
290 set(smdata
.mainwindow
, MUIA_Window_Open
, TRUE
);
292 while (DoMethod(smdata
.application
, MUIM_Application_NewInput
, &signals
) != MUIV_Application_ReturnID_Quit
)
296 signals
= Wait(signals
| SIGBREAKF_CTRL_C
| GetSIG_TIMER());
297 if (signals
& SIGBREAKF_CTRL_C
) break;
298 if (signals
& GetSIG_TIMER())
300 UpdateProcessorInformation(&smdata
);
302 if ((itercounter
% 4) == 0)
304 UpdateMemoryInformation(&smdata
);
305 UpdateVideoInformation(&smdata
);
307 if (smdata
.tasklistautorefresh
)
308 UpdateTasksInformation(&smdata
);
318 set(smdata
.mainwindow
, MUIA_Window_Open
, FALSE
);
320 DisposeApplication(&smdata
);
322 DeInitModules(modules
, &smdata
, lastinitedmodule
);