2 Copyright 2010-2016, The AROS Development Team. All rights reserved.
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>
15 #include "sysmon_intern.h"
18 #include <aros/debug.h>
21 APTR TaskResBase
= NULL
;
23 /* Task information handling*/
32 VOID
UpdateTasksInformation(struct SysMonData
* smdata
)
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;
50 /* We are unlikely to disappear and this code still run... so don't disable yet */
51 if ((entryid
= DoMethod(smdata
->tasklist
, MUIM_List_InsertSingle
, smdata
->sm_Task
, MUIV_List_Insert_Bottom
)) == 0)
56 if (smdata
->sm_Task
== selected
)
58 set(smdata
->tasklist
, MUIA_List_Active
, entryid
);
61 systasklist
= LockTaskList(0);
62 while ((task
= NextTaskEntry(systasklist
, 0)) != NULL
)
64 D(bug("[SysMon] task %s state %d\n", task
->tc_Node
.ln_Name
, task
->tc_State
));
66 if (task
->tc_State
== TS_READY
)
68 smdata
->sm_TasksReady
++;
70 if (task
->tc_State
== TS_WAIT
)
72 smdata
->sm_TasksWaiting
++;
75 entryid
= DoMethod(smdata
->tasklist
, MUIM_List_InsertSingle
, task
, MUIV_List_Insert_Bottom
);
78 set(smdata
->tasklist
, MUIA_List_Active
, entryid
);
83 if (XGET(smdata
->tasklist
, MUIA_List_Active
) == 0)
84 smdata
->sm_TaskSelected
= NULL
;
86 /* Keep the "pre-refresh" view on List as much as possible */
87 LONG v
= (LONG
)firstvis
;
88 if (firstvis
+ XGET(smdata
->tasklist
, MUIA_List_Visible
) >= XGET(smdata
->tasklist
, MUIA_List_Entries
))
90 v
= XGET(smdata
->tasklist
, MUIA_List_Entries
) - XGET(smdata
->tasklist
, MUIA_List_Visible
);
94 set(smdata
->tasklist
, MUIA_List_First
, v
);
96 __sprintf(smdata
->tasklistinfobuf
, "%ld ready, %ld waiting", smdata
->sm_TasksReady
, smdata
->sm_TasksWaiting
);
97 set(smdata
->tasklistinfo
, MUIA_Text_Contents
, smdata
->tasklistinfobuf
);
98 set(smdata
->tasklist
, MUIA_List_Quiet
, FALSE
);
101 AROS_UFH3(struct TaskInfo
*, TasksListConstructFunction
,
102 AROS_UFHA(struct Hook
*, h
, A0
),
103 AROS_UFHA(APTR
, pool
, A2
),
104 AROS_UFHA(struct Task
*, curTask
, A1
))
108 struct TaskInfo
*ti
= NULL
;
110 if ((ti
= AllocVecPooled(pool
, sizeof(struct TaskInfo
))) != NULL
)
114 /* Cache values we need incase something happens to the task .. */
115 ti
->TINode
.ln_Type
= curTask
->tc_Node
.ln_Type
;
116 ti
->TINode
.ln_Pri
= (WORD
)curTask
->tc_Node
.ln_Pri
;
117 ti
->TINode
.ln_Name
= StrDup(curTask
->tc_Node
.ln_Name
);
119 AddTail(&((struct SysMonData
*)h
->h_Data
)->sm_TaskList
, &ti
->TINode
);
126 AROS_UFH3(VOID
, TasksListDestructFunction
,
127 AROS_UFHA(struct Hook
*, h
, A0
),
128 AROS_UFHA(APTR
, pool
, A2
),
129 AROS_UFHA(struct TaskInfo
*, ti
, A1
))
134 FreeVec(ti
->TINode
.ln_Name
);
135 FreeVecPooled(pool
, ti
);
140 AROS_UFH3(VOID
, TaskSelectedFunction
,
141 AROS_UFHA(struct Hook
*, h
, A0
),
142 AROS_UFHA(Object
*, obj
, A2
),
143 AROS_UFHA(APTR
, msg
, A1
))
147 struct SysMonData
*smdata
= h
->h_Data
;
148 struct TaskInfo
*ti
= NULL
;
150 DoMethod(smdata
->tasklist
, MUIM_List_GetEntry
, MUIV_List_GetEntry_Active
, &ti
);
154 smdata
->sm_TaskSelected
= ti
->Task
;
157 smdata
->sm_TaskSelected
= NULL
;
163 AROS_UFH3(VOID
, TasksListDisplayFunction
,
164 AROS_UFHA(struct Hook
*, h
, A0
),
165 AROS_UFHA(STRPTR
*, strings
, A2
),
166 AROS_UFHA(struct TaskInfo
*, ti
, A1
))
170 static TEXT bufprio
[8];
174 __sprintf(bufprio
, "%d", (LONG
)ti
->TINode
.ln_Pri
);
176 strings
[0] = ti
->TINode
.ln_Name
;
177 strings
[1] = bufprio
;
178 strings
[2] = ti
->TINode
.ln_Type
== NT_TASK
? (STRPTR
)_(MSG_TASK
) : (STRPTR
)_(MSG_PROCESS
);
182 strings
[0] = (STRPTR
)_(MSG_TASK_NAME
);
183 strings
[1] = (STRPTR
)_(MSG_TASK_PRIORITY
);
184 strings
[2] = (STRPTR
)_(MSG_TASK_TYPE
);
190 static BOOL
InitTasks(struct SysMonData
*smdata
)
192 TaskResBase
= OpenResource("task.resource");
193 if (TaskResBase
== NULL
)
195 FPuts(Output(), "Can't open task.resource\n");
199 smdata
->sm_Task
= FindTask(NULL
);
200 NewList(&smdata
->sm_TaskList
);
202 smdata
->tasklistinfobuf
= AllocVec(30, MEMF_PUBLIC
);
204 smdata
->sm_TaskSelected
= NULL
;
205 smdata
->sm_TaskTotalRuntime
= 0;
210 static VOID
DeInitTasks(struct SysMonData
*smdata
)
214 struct SysMonModule tasksmodule
=
217 .DeInit
= DeInitTasks
,