2 ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
3 Copyright (C) 2004 beunited.org
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "ThreadBarMenu.h"
22 #include "PriorityMenu.h"
23 #include "ProcessController.h"
24 #include "ThreadBarMenuItem.h"
32 ThreadBarMenu::ThreadBarMenu(const char *title
, team_id team
, int32 threadCount
)
34 fThreadsRecCount(threadCount
+ EXTRA
),
37 SetFont(be_plain_font
);
38 fThreadsRec
= (ThreadRec
*) malloc(sizeof(ThreadRec
) * fThreadsRecCount
);
40 fRound
= 0; // for syslog
45 ThreadBarMenu::~ThreadBarMenu()
48 if (gCurrentThreadBarMenu
== this)
49 gCurrentThreadBarMenu
= NULL
;
57 while (k
< fThreadsRecCount
)
58 fThreadsRec
[k
++].thread
= -1;
64 ThreadBarMenu::Reset(team_id team
)
67 RemoveItems(0, CountItems(), true);
73 ThreadBarMenu::AttachedToWindow()
75 BMenu::AttachedToWindow();
80 ThreadBarMenu::Draw(BRect r
)
82 gCurrentThreadBarMenu
= this;
88 ThreadBarMenu::AddNew()
93 while (get_next_thread_info(fTeam
, &cookie
, &info
) == B_OK
) {
95 while (k
< fThreadsRecCount
&& fThreadsRec
[k
].thread
!= info
.thread
)
97 if (k
== fThreadsRecCount
) {
99 while (k
< lastk
&& fThreadsRec
[k
].thread
!= info
.thread
)
102 k
= fThreadsRecCount
; // flag that the search didn't work.
104 if (k
== fThreadsRecCount
) {
105 // printf("*** Thread %d %s/%s, user %Ld, kernel %Ld\n", info.thread, info.name, info.user_time, info.kernel_time);
106 // this is a new thread...
108 while (k
< fThreadsRecCount
&& !(fThreadsRec
[k
].thread
== -1 || fThreadsRec
[k
].last_round
+1 < fRound
))
110 if (k
== fThreadsRecCount
) {
111 fThreadsRecCount
+= EXTRA
;
112 fThreadsRec
= (ThreadRec
*) realloc(fThreadsRec
, sizeof(ThreadRec
)*fThreadsRecCount
);
114 while (lastk
< fThreadsRecCount
)
115 fThreadsRec
[lastk
++].thread
= -1;
117 fThreadsRec
[k
].thread
= info
.thread
;
118 BMessage
* kill_thread
= new BMessage('KlTh');
119 kill_thread
->AddInt32("thread", info
.thread
);
121 PriorityMenu
* prio
= new PriorityMenu(info
.thread
, info
.priority
);
122 prio
->SetFont(be_plain_font
);
123 ThreadBarMenuItem
* threadbarmenuitem
= new ThreadBarMenuItem(info
.name
, info
.thread
, prio
, kill_thread
);
124 threadbarmenuitem
->SetTarget(gPCView
);
125 AddItem(threadbarmenuitem
);
127 fThreadsRec
[k
].last_round
= fRound
;
134 ThreadBarMenu::Update()
139 ThreadBarMenuItem
*item
;
141 for (k
= 0; (item
= (ThreadBarMenuItem
*) ItemAt(k
)) != NULL
; k
++) {
143 item
->DrawBar(false);
144 if (item
->fKernel
< 0) {
147 } else if (del
>= 0) {
148 RemoveItems(del
, k
-del
, true);
154 RemoveItems(del
, k
-del
, true);