grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / system / SysMon / main.c
blobd73c587bbeed3763948766f4e08592b5d7beb698
1 /*
2 Copyright 2010-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/alib.h>
7 #include <proto/muimaster.h>
8 #include <dos/dos.h>
10 #include "sysmon_intern.h"
12 #include "locale.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))
21 AROS_USERFUNC_INIT
23 UpdateTasksInformation(h->h_Data);
25 AROS_USERFUNC_EXIT
28 BOOL CreateApplication(struct SysMonData * smdata)
30 Object * cpucolgroup;
31 Object * tasklistrefreshbutton;
32 Object * tasklistautorefreshcheckmark;
33 Object * cpuusagegroup;
34 Object * cpufreqgroup;
35 ULONG i;
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),
62 SubWindow,
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),
68 WindowContents,
69 RegisterGroup(smdata->tabs),
70 Child, VGroup,
71 Child, ListviewObject,
72 MUIA_Listview_List, smdata->tasklist = ListObject,
73 ReadListFrame,
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,
79 End,
80 End,
81 Child, ColGroup(2),
82 Child, VGroup,
83 Child, tasklistrefreshbutton = MUI_MakeObject(MUIO_Button, _(MSG_LIST_REFRESH)),
84 Child, ColGroup(2),
85 Child, Label(_(MSG_AUTO_REFRESH)),
86 Child, tasklistautorefreshcheckmark = MUI_MakeObject(MUIO_Checkmark, NULL),
87 End,
88 End,
89 Child, VGroup,
90 Child, smdata->tasklistinfo = TextObject,
91 NoFrame,
92 MUIA_Font, MUIV_Font_Tiny,
93 MUIA_Text_PreParse, (IPTR)"\33r",
94 MUIA_Text_Contents, (IPTR)"0 ready, 0 waiting",
95 End,
96 Child, HVSpace,
97 End,
98 End,
99 End,
100 Child, VGroup,
101 Child, cpuusagegroup = HGroup, GroupFrameT(_(MSG_USAGE)),
102 End,
103 Child, VGroup, GroupFrameT(_(MSG_FREQUENCY)),
104 Child, cpufreqgroup = ColGroup(3),
105 End,
106 End,
107 End,
108 Child, VGroup,
109 Child, ColGroup(2),
110 Child, VGroup, GroupFrameT(_(MSG_MEMORY_SIZE)),
111 Child, ColGroup(2),
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",
115 End,
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)"",
119 End,
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)"",
123 End,
124 End,
125 End,
126 Child, VGroup, GroupFrameT(_(MSG_MEMORY_FREE)),
127 Child, ColGroup(2),
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",
131 End,
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)"",
135 End,
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)"",
139 End,
140 End,
141 End,
142 End,
143 Child, ColGroup(2),
144 Child, VGroup, GroupFrameT(_(MSG_VIDEO_SIZE)),
145 Child, ColGroup(2),
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)"",
149 End,
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)"",
153 End,
154 End,
155 End,
156 Child, VGroup, GroupFrameT(_(MSG_VIDEO_FREE)),
157 Child, ColGroup(2),
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)"",
161 End,
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)"",
165 End,
166 End,
167 End,
168 End,
169 Child, HVSpace,
170 End,
171 End,
172 End,
173 End;
175 if (!smdata->application)
176 return FALSE;
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);
228 return TRUE;
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)
242 LONG i;
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))
255 lastinitedmodule++;
256 else
258 DeInitModules(modules, smdata, lastinitedmodule);
259 return -1;
264 return lastinitedmodule;
267 int main()
269 ULONG signals = 0;
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)
276 return 1;
278 if (!CreateApplication(&smdata))
279 return 1;
281 UpdateProcessorStaticInformation(&smdata);
282 UpdateProcessorInformation(&smdata);
283 UpdateTasksInformation(&smdata);
284 UpdateMemoryStaticInformation(&smdata);
285 UpdateMemoryInformation(&smdata);
286 UpdateVideoStaticInformation(&smdata);
287 UpdateVideoInformation(&smdata);
288 SignalMeAfter(250);
290 set(smdata.mainwindow, MUIA_Window_Open, TRUE);
292 while (DoMethod(smdata.application, MUIM_Application_NewInput, &signals) != MUIV_Application_ReturnID_Quit)
294 if (signals)
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);
311 itercounter++;
313 SignalMeAfter(250);
318 set(smdata.mainwindow, MUIA_Window_Open, FALSE);
320 DisposeApplication(&smdata);
322 DeInitModules(modules, &smdata, lastinitedmodule);
324 return 0;