grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / system / SysMon / tasks.c
blob850e4c7272b54679b48d0d9a9252f9288f845d28
1 /*
2 Copyright 2010-2016, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/execbase.h>
7 #include <resources/task.h>
8 #include <clib/alib_protos.h>
10 #include <proto/task.h>
11 #include <proto/dos.h>
13 #include "locale.h"
15 #include "sysmon_intern.h"
17 //#define DEBUG 1
18 #include <aros/debug.h>
21 APTR TaskResBase = NULL;
23 /* Task information handling*/
24 struct TaskInfo
26 struct Node TINode;
27 struct Task *Task;
28 ULONG TimeCurrent;
29 ULONG TimeLast;
32 VOID UpdateTasksInformation(struct SysMonData * smdata)
34 struct Task * task;
35 IPTR firstvis = 0, entryid = 0;
36 struct Task *selected = smdata->sm_TaskSelected;
37 struct TaskList *systasklist;
39 set(smdata->tasklist, MUIA_List_Quiet, TRUE);
41 get(smdata->tasklist, MUIA_List_First, &firstvis);
43 DoMethod(smdata->tasklist, MUIM_List_Clear);
45 smdata->sm_TasksWaiting = 0;
46 smdata->sm_TasksReady = 0;
47 smdata->sm_TaskTotalRuntime = 0;
49 systasklist = LockTaskList(0);
50 while ((task = NextTaskEntry(systasklist, 0)) != NULL)
52 D(bug("[SysMon] task %s state %d\n", task->tc_Node.ln_Name, task->tc_State));
54 if (task->tc_State == TS_READY)
56 smdata->sm_TasksReady++;
58 if (task->tc_State == TS_WAIT)
60 smdata->sm_TasksWaiting++;
63 entryid = DoMethod(smdata->tasklist, MUIM_List_InsertSingle, task, MUIV_List_Insert_Bottom);
64 if (task == selected)
66 set(smdata->tasklist, MUIA_List_Active, entryid);
69 UnLockTaskList(0);
71 if (XGET(smdata->tasklist, MUIA_List_Active) == 0)
72 smdata->sm_TaskSelected = NULL;
74 /* Keep the "pre-refresh" view on List as much as possible */
75 LONG v = (LONG)firstvis;
76 if (firstvis + XGET(smdata->tasklist, MUIA_List_Visible) >= XGET(smdata->tasklist, MUIA_List_Entries))
78 v = XGET(smdata->tasklist, MUIA_List_Entries) - XGET(smdata->tasklist, MUIA_List_Visible);
79 if (v < 0) v = 0;
82 set(smdata->tasklist, MUIA_List_First, v);
84 __sprintf(smdata->tasklistinfobuf, (STRPTR)__(MSG_TASK_READY_AND_WAIT), smdata->sm_TasksReady, smdata->sm_TasksWaiting);
85 set(smdata->tasklistinfo, MUIA_Text_Contents, smdata->tasklistinfobuf);
86 set(smdata->tasklist, MUIA_List_Quiet, FALSE);
89 AROS_UFH3(struct TaskInfo *, TasksListConstructFunction,
90 AROS_UFHA(struct Hook *, h, A0),
91 AROS_UFHA(APTR, pool, A2),
92 AROS_UFHA(struct Task *, curTask, A1))
94 AROS_USERFUNC_INIT
96 struct TaskInfo *ti = NULL;
98 if ((ti = AllocVecPooled(pool, sizeof(struct TaskInfo))) != NULL)
100 ti->Task = curTask;
102 /* Cache values we need incase something happens to the task .. */
103 ti->TINode.ln_Type = curTask->tc_Node.ln_Type;
104 ti->TINode.ln_Pri = (WORD)curTask->tc_Node.ln_Pri;
105 ti->TINode.ln_Name = StrDup(curTask->tc_Node.ln_Name);
107 AddTail(&((struct SysMonData *)h->h_Data)->sm_TaskList, &ti->TINode);
109 return ti;
111 AROS_USERFUNC_EXIT
114 AROS_UFH3(VOID, TasksListDestructFunction,
115 AROS_UFHA(struct Hook *, h, A0),
116 AROS_UFHA(APTR, pool, A2),
117 AROS_UFHA(struct TaskInfo *, ti, A1))
119 AROS_USERFUNC_INIT
121 Remove(&ti->TINode);
122 FreeVec(ti->TINode.ln_Name);
123 FreeVecPooled(pool, ti);
125 AROS_USERFUNC_EXIT
128 AROS_UFH3(VOID, TaskSelectedFunction,
129 AROS_UFHA(struct Hook *, h, A0),
130 AROS_UFHA(Object *, obj, A2),
131 AROS_UFHA(APTR, msg, A1))
133 AROS_USERFUNC_INIT
135 struct SysMonData *smdata = h->h_Data;
136 struct TaskInfo *ti = NULL;
138 DoMethod(smdata->tasklist, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &ti);
140 if (ti != NULL)
142 smdata->sm_TaskSelected = ti->Task;
144 else
145 smdata->sm_TaskSelected = NULL;
147 AROS_USERFUNC_EXIT
151 AROS_UFH3(VOID, TasksListDisplayFunction,
152 AROS_UFHA(struct Hook *, h, A0),
153 AROS_UFHA(STRPTR *, strings, A2),
154 AROS_UFHA(struct TaskInfo *, ti, A1))
156 AROS_USERFUNC_INIT
158 static TEXT bufprio[8];
160 if (ti)
162 __sprintf(bufprio, "%d", (LONG)ti->TINode.ln_Pri);
164 strings[0] = ti->TINode.ln_Name;
165 strings[1] = bufprio;
166 strings[2] = ti->TINode.ln_Type == NT_TASK ? (STRPTR)_(MSG_TASK) : (STRPTR)_(MSG_PROCESS);
168 else
170 strings[0] = (STRPTR)_(MSG_TASK_NAME);
171 strings[1] = (STRPTR)_(MSG_TASK_PRIORITY);
172 strings[2] = (STRPTR)_(MSG_TASK_TYPE);
175 AROS_USERFUNC_EXIT
178 static BOOL InitTasks(struct SysMonData *smdata)
180 TaskResBase = OpenResource("task.resource");
181 if (TaskResBase == NULL)
183 FPuts(Output(), (STRPTR)_(MSG_CANT_OPEN_TASK_RESOURCE));
184 return FALSE;
187 smdata->sm_Task = FindTask(NULL);
188 NewList(&smdata->sm_TaskList);
190 smdata->tasklistinfobuf = AllocVec(30, MEMF_PUBLIC);
192 smdata->sm_TaskSelected = NULL;
193 smdata->sm_TaskTotalRuntime = 0;
195 return TRUE;
198 static VOID DeInitTasks(struct SysMonData *smdata)
202 struct SysMonModule tasksmodule =
204 .Init = InitTasks,
205 .DeInit = DeInitTasks,