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;
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
);
66 set(smdata
->tasklist
, MUIA_List_Active
, entryid
);
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
);
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
))
96 struct TaskInfo
*ti
= NULL
;
98 if ((ti
= AllocVecPooled(pool
, sizeof(struct TaskInfo
))) != NULL
)
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
);
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
))
122 FreeVec(ti
->TINode
.ln_Name
);
123 FreeVecPooled(pool
, ti
);
128 AROS_UFH3(VOID
, TaskSelectedFunction
,
129 AROS_UFHA(struct Hook
*, h
, A0
),
130 AROS_UFHA(Object
*, obj
, A2
),
131 AROS_UFHA(APTR
, msg
, A1
))
135 struct SysMonData
*smdata
= h
->h_Data
;
136 struct TaskInfo
*ti
= NULL
;
138 DoMethod(smdata
->tasklist
, MUIM_List_GetEntry
, MUIV_List_GetEntry_Active
, &ti
);
142 smdata
->sm_TaskSelected
= ti
->Task
;
145 smdata
->sm_TaskSelected
= NULL
;
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
))
158 static TEXT bufprio
[8];
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
);
170 strings
[0] = (STRPTR
)_(MSG_TASK_NAME
);
171 strings
[1] = (STRPTR
)_(MSG_TASK_PRIORITY
);
172 strings
[2] = (STRPTR
)_(MSG_TASK_TYPE
);
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
));
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;
198 static VOID
DeInitTasks(struct SysMonData
*smdata
)
202 struct SysMonModule tasksmodule
=
205 .DeInit
= DeInitTasks
,