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
21 #include "TeamBarMenu.h"
22 #include "ThreadBarMenu.h"
23 #include "TeamBarMenuItem.h"
24 #include "NoiseBarMenuItem.h"
25 #include "ProcessController.h"
37 TeamBarMenu::TeamBarMenu(const char* title
, info_pack
* infos
, int32 teamCount
)
39 fTeamCount(teamCount
+EXTRA
),
42 SetFlags(Flags() | B_PULSE_NEEDED
);
43 fTeamList
= (team_id
*)malloc(sizeof(team_id
) * fTeamCount
);
45 for (k
= 0; k
< teamCount
; k
++) {
46 fTeamList
[k
] = infos
[k
].team_info
.team
;
48 while (k
< fTeamCount
) {
51 fRecycleCount
= EXTRA
;
52 fRecycleList
= (TRecycleItem
*)malloc(sizeof(TRecycleItem
) * fRecycleCount
);
53 SetFont(be_plain_font
);
54 gCurrentThreadBarMenu
= NULL
;
55 fLastTotalTime
= system_time();
56 AddItem(new NoiseBarMenuItem());
60 TeamBarMenu::~TeamBarMenu()
62 gCurrentThreadBarMenu
= NULL
;
69 TeamBarMenu::Draw(BRect updateRect
)
71 BMenu::Draw (updateRect
);
82 Window()->BeginViewTransaction();
84 // create the list of items to remove, for their team is gone. Update the old teams.
88 TeamBarMenuItem
*item
;
90 for (k
= 1; (item
= (TeamBarMenuItem
*)ItemAt(k
)) != NULL
; k
++) {
92 if (item
->fKernel
< 0) {
93 if (lastRecycle
== fRecycleCount
) {
94 fRecycleCount
+= EXTRA
;
95 fRecycleList
= (TRecycleItem
*)realloc(fRecycleList
,
96 sizeof(TRecycleItem
)*fRecycleCount
);
98 fRecycleList
[lastRecycle
].index
= k
;
99 fRecycleList
[lastRecycle
++].item
= item
;
101 if (lastRecycle
> 0) {
102 RemoveItems(fRecycleList
[0].index
, lastRecycle
, true);
106 total
+= item
->fUser
+ item
->fKernel
;
110 // Look new teams that have appeared. Create an item for them, or recycle from the list.
114 while (get_next_team_info(&cookie
, &infos
.team_info
) == B_OK
) {
116 while (j
< fTeamCount
&& infos
.team_info
.team
!= fTeamList
[j
])
118 if (infos
.team_info
.team
!= fTeamList
[j
]) {
122 while (j
< fTeamCount
&& fTeamList
[j
] != -1)
123 if (get_team_info(fTeamList
[j
], &info
) != B_OK
)
127 if (j
== fTeamCount
) {
129 fTeamList
= (team_id
*)realloc(fTeamList
, sizeof(team_id
) * fTeamCount
);
131 fTeamList
[j
] = infos
.team_info
.team
;
132 if (!get_team_name_and_icon(infos
, true)) {
133 // the team is already gone!
134 delete infos
.team_icon
;
137 if (!item
&& firstRecycle
< lastRecycle
) {
138 item
= fRecycleList
[firstRecycle
++].item
;
141 item
->Reset(infos
.team_name
, infos
.team_info
.team
, infos
.team_icon
, true);
143 BMessage
* kill_team
= new BMessage('KlTm');
144 kill_team
->AddInt32("team", infos
.team_info
.team
);
145 item
= new TeamBarMenuItem(new ThreadBarMenu(infos
.team_name
,
146 infos
.team_info
.team
, infos
.team_info
.thread_count
),
147 kill_team
, infos
.team_info
.team
, infos
.team_icon
, true);
148 item
->SetTarget(gPCView
);
152 if (item
->fKernel
>= 0) {
153 total
+= item
->fUser
+ item
->fKernel
;
166 // Delete the items that haven't been recycled.
167 if (firstRecycle
< lastRecycle
)
168 RemoveItems(IndexOf(fRecycleList
[firstRecycle
].item
), lastRecycle
- firstRecycle
, true);
173 fLastTotalTime
= system_time();
174 NoiseBarMenuItem
* noiseItem
;
175 if ((noiseItem
= (NoiseBarMenuItem
*)ItemAt(0)) != NULL
) {
176 noiseItem
->SetBusyWaiting(0);
178 noiseItem
->SetLost(total
);
180 noiseItem
->SetLost(0);
181 noiseItem
->DrawBar(false);
184 if (gCurrentThreadBarMenu
&& gCurrentThreadBarMenu
->LockLooperWithTimeout(25000) == B_OK
) {
185 gCurrentThreadBarMenu
->Window()->BeginViewTransaction();
186 gCurrentThreadBarMenu
->Update();
187 gCurrentThreadBarMenu
->Window()->EndViewTransaction();
188 gCurrentThreadBarMenu
->Window()->Flush();
189 gCurrentThreadBarMenu
->UnlockLooper();
192 Window()->EndViewTransaction();