17227
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1997 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libtool' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
|
16 |
SystemStatusMonitor subclass:#ExternalStreamMonitor
|
|
17 |
instanceVariableNames:'semaphores streams filterOpenStreamsOnlyHolder
|
|
18 |
filterSocketsOnlyHolder filterConnectedSocketsOnlyHolder'
|
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Monitors-ST/X'
|
|
22 |
!
|
|
23 |
|
|
24 |
!ExternalStreamMonitor class methodsFor:'documentation'!
|
|
25 |
|
|
26 |
copyright
|
|
27 |
"
|
|
28 |
COPYRIGHT (c) 1997 by Claus Gittinger
|
|
29 |
All Rights Reserved
|
|
30 |
|
|
31 |
This software is furnished under a license and may be used
|
|
32 |
only in accordance with the terms of that license and with the
|
|
33 |
inclusion of the above copyright notice. This software may not
|
|
34 |
be provided or otherwise made available to, or used by, any
|
|
35 |
other person. No title to or ownership of the software is
|
|
36 |
hereby transferred.
|
|
37 |
"
|
|
38 |
|
|
39 |
|
|
40 |
!
|
|
41 |
|
|
42 |
documentation
|
|
43 |
"
|
17228
|
44 |
This view shows smalltalk's external stream instances - a debugging tool.
|
17227
|
45 |
|
|
46 |
[disclaimer:]
|
17228
|
47 |
this is based on one of the oldest tools in the system, written in the early 90's.
|
17227
|
48 |
It does in no way reflect the way GUIs are designed/written these days.
|
|
49 |
|
|
50 |
[see also:]
|
17228
|
51 |
Stream ExternalStream
|
17227
|
52 |
WindowGroup
|
|
53 |
ProcessMonitor
|
17228
|
54 |
SemaphoreMonitor
|
17227
|
55 |
|
|
56 |
[author:]
|
|
57 |
Claus Gittinger
|
|
58 |
|
|
59 |
[start with:]
|
17228
|
60 |
ExternalStreamMonitor open
|
17227
|
61 |
"
|
|
62 |
! !
|
|
63 |
|
|
64 |
!ExternalStreamMonitor class methodsFor:'defaults'!
|
|
65 |
|
|
66 |
defaultLabel
|
|
67 |
^ 'External Streams Monitor'
|
|
68 |
|
|
69 |
"Created: 23.1.1997 / 02:52:53 / cg"
|
|
70 |
! !
|
|
71 |
|
|
72 |
!ExternalStreamMonitor class methodsFor:'menu specs'!
|
|
73 |
|
|
74 |
filterMenu
|
|
75 |
"This resource specification was automatically generated
|
|
76 |
by the MenuEditor of ST/X."
|
|
77 |
|
|
78 |
"Do not manually edit this!! If it is corrupted,
|
|
79 |
the MenuEditor may not be able to read the specification."
|
|
80 |
|
|
81 |
|
|
82 |
"
|
|
83 |
MenuEditor new openOnClass:ExternalStreamMonitor andSelector:#filterMenu
|
|
84 |
(Menu new fromLiteralArrayEncoding:(ExternalStreamMonitor filterMenu)) startUp
|
|
85 |
"
|
|
86 |
|
|
87 |
<resource: #menu>
|
|
88 |
|
|
89 |
^
|
|
90 |
#(Menu
|
|
91 |
(
|
|
92 |
(MenuItem
|
|
93 |
label: 'Open Streams Only'
|
|
94 |
hideMenuOnActivated: false
|
|
95 |
indication: filterOpenStreamsOnlyHolder
|
|
96 |
)
|
|
97 |
(MenuItem
|
|
98 |
label: '-'
|
|
99 |
)
|
|
100 |
(MenuItem
|
|
101 |
label: 'Sockets Only'
|
|
102 |
hideMenuOnActivated: false
|
|
103 |
indication: filterSocketsOnlyHolder
|
|
104 |
)
|
|
105 |
(MenuItem
|
|
106 |
label: 'Connected Sockets Only'
|
|
107 |
hideMenuOnActivated: false
|
|
108 |
indication: filterConnectedSocketsOnlyHolder
|
|
109 |
)
|
|
110 |
)
|
|
111 |
nil
|
|
112 |
nil
|
|
113 |
)
|
|
114 |
!
|
|
115 |
|
|
116 |
mainMenu
|
|
117 |
"This resource specification was automatically generated
|
|
118 |
by the MenuEditor of ST/X."
|
|
119 |
|
|
120 |
"Do not manually edit this!! If it is corrupted,
|
|
121 |
the MenuEditor may not be able to read the specification."
|
|
122 |
|
|
123 |
|
|
124 |
"
|
|
125 |
MenuEditor new openOnClass:ExternalStreamMonitor andSelector:#mainMenu
|
|
126 |
(Menu new fromLiteralArrayEncoding:(ExternalStreamMonitor mainMenu)) startUp
|
|
127 |
"
|
|
128 |
|
|
129 |
<resource: #menu>
|
|
130 |
|
|
131 |
^
|
|
132 |
#(Menu
|
|
133 |
(
|
|
134 |
(MenuItem
|
|
135 |
label: 'File'
|
|
136 |
submenu:
|
|
137 |
(Menu
|
|
138 |
(
|
|
139 |
(MenuItem
|
|
140 |
label: 'Exit'
|
|
141 |
itemValue: closeRequestToTopView
|
|
142 |
)
|
|
143 |
)
|
|
144 |
nil
|
|
145 |
nil
|
|
146 |
)
|
|
147 |
)
|
|
148 |
(MenuItem
|
|
149 |
label: 'Filter'
|
|
150 |
submenuChannel: filterMenu
|
|
151 |
)
|
|
152 |
)
|
|
153 |
nil
|
|
154 |
nil
|
|
155 |
)
|
|
156 |
! !
|
|
157 |
|
|
158 |
!ExternalStreamMonitor methodsFor:'aspects'!
|
|
159 |
|
|
160 |
filterConnectedSocketsOnlyHolder
|
|
161 |
filterConnectedSocketsOnlyHolder isNil ifTrue:[
|
|
162 |
filterConnectedSocketsOnlyHolder := false asValue.
|
|
163 |
filterConnectedSocketsOnlyHolder onChangeSend:#filterConnectedSocketsOnlyHolderChanged to:self.
|
|
164 |
].
|
|
165 |
^ filterConnectedSocketsOnlyHolder
|
|
166 |
!
|
|
167 |
|
|
168 |
filterOpenStreamsOnlyHolder
|
|
169 |
filterOpenStreamsOnlyHolder isNil ifTrue:[
|
|
170 |
filterOpenStreamsOnlyHolder := false asValue.
|
|
171 |
filterSocketsOnlyHolder onChangeSend:#filterOpenStreamsOnlyHolder to:self.
|
|
172 |
].
|
|
173 |
^ filterOpenStreamsOnlyHolder
|
|
174 |
!
|
|
175 |
|
|
176 |
filterSocketsOnlyHolder
|
|
177 |
filterSocketsOnlyHolder isNil ifTrue:[
|
|
178 |
filterSocketsOnlyHolder := false asValue.
|
|
179 |
filterSocketsOnlyHolder onChangeSend:#filterSocketsOnlyHolderChanged to:self.
|
|
180 |
].
|
|
181 |
^ filterSocketsOnlyHolder
|
|
182 |
! !
|
|
183 |
|
|
184 |
!ExternalStreamMonitor methodsFor:'drawing'!
|
|
185 |
|
|
186 |
titleLine
|
|
187 |
OperatingSystem isMSWINDOWSlike ifTrue:[
|
|
188 |
^ 'Type Global Handle Detail'.
|
|
189 |
] ifFalse:[
|
|
190 |
^ 'Type Global FD Detail'.
|
|
191 |
].
|
|
192 |
|
|
193 |
"
|
|
194 |
ExternalStreamMonitor open
|
|
195 |
"
|
|
196 |
|
|
197 |
"Modified: / 17.6.1998 / 14:52:48 / cg"
|
|
198 |
!
|
|
199 |
|
|
200 |
updateList
|
|
201 |
"update list of semaphores"
|
|
202 |
|
|
203 |
|newList|
|
|
204 |
|
|
205 |
shown ifTrue:[
|
|
206 |
newList := ExternalStream allSubInstances.
|
|
207 |
|
|
208 |
self filterSocketsOnlyHolder value ifTrue:[
|
|
209 |
newList := newList select:[:eachStream | eachStream isSocket].
|
|
210 |
].
|
|
211 |
self filterOpenStreamsOnlyHolder value ifTrue:[
|
|
212 |
newList := newList select:[:eachStream | eachStream isOpen].
|
|
213 |
].
|
|
214 |
self filterConnectedSocketsOnlyHolder value ifTrue:[
|
|
215 |
newList := newList select:[:eachStream | eachStream isSocket and:[eachStream isConnected]].
|
|
216 |
].
|
|
217 |
|
|
218 |
"sort by hashKey - will not always generate unique numbers,
|
|
219 |
but most of the time, this works ... for now"
|
|
220 |
|
|
221 |
newList sort:[:s1 :s2 |
|
|
222 |
s1 className < s2 className
|
|
223 |
or:[ s1 className = s2 className
|
|
224 |
and:[false]]
|
|
225 |
].
|
|
226 |
|
|
227 |
newList ~= streams ifTrue:[
|
|
228 |
self updateStatus:newList
|
|
229 |
].
|
|
230 |
].
|
|
231 |
self installDelayedUpdate.
|
|
232 |
!
|
|
233 |
|
|
234 |
updateStatus:newStreamsList
|
|
235 |
"update status display of semaphores"
|
|
236 |
|
|
237 |
|oldList list oldSelection newSelection|
|
|
238 |
|
|
239 |
shown ifTrue:[
|
|
240 |
oldList := listView list.
|
|
241 |
oldSelection := listView selection.
|
|
242 |
oldSelection notNil ifTrue:[
|
|
243 |
oldSelection := oldSelection collect:[:lineNr | streams at:(lineNr - self numberOfHeadlines) ].
|
|
244 |
newSelection := OrderedCollection new.
|
|
245 |
].
|
|
246 |
|
|
247 |
newStreamsList notNil ifTrue:[
|
|
248 |
streams := WeakArray withAll:newStreamsList.
|
|
249 |
].
|
|
250 |
streams notNil ifTrue:[
|
|
251 |
list := OrderedCollection new:(streams size + self numberOfHeadlines).
|
|
252 |
list add:self titleLine.
|
|
253 |
list add:(String new:self titleLine size withAll:$-).
|
|
254 |
|
|
255 |
streams validElementsDo:[:aStream |
|
|
256 |
|waiters waitersNames type globalNameOrNil handleString
|
|
257 |
isOpen handle detail color line|
|
|
258 |
|
|
259 |
"/ "/ need a copy - it may change while being enumerated
|
|
260 |
"/ [
|
|
261 |
"/ count := aSemaphore count.
|
|
262 |
"/ waiters := aSemaphore waitingProcesses copy.
|
|
263 |
"/ ] valueUninterruptably.
|
|
264 |
|
|
265 |
"/ str := '' writeStream.
|
|
266 |
"/ [
|
|
267 |
"/ waiters notNil ifTrue:[
|
|
268 |
"/ waiters do:[:aProcess |
|
|
269 |
"/ str nextPut:$[.
|
|
270 |
"/ aProcess id printOn:str.
|
|
271 |
"/ str nextPutAll:' '''.
|
|
272 |
"/ str nextPutAll:(aProcess name contractTo:40).
|
|
273 |
"/ str nextPutAll:'''<'.
|
|
274 |
"/ aProcess priority printOn:str.
|
|
275 |
"/ str nextPutAll:'>]'.
|
|
276 |
"/ str space.
|
|
277 |
"/ ].
|
|
278 |
"/ ]
|
|
279 |
"/ ] valueUninterruptably.
|
|
280 |
"/ waitersNames := str contents.
|
|
281 |
|
|
282 |
"/ (aSemaphore respondsTo:#name) ifTrue:[
|
|
283 |
"/ nm := aSemaphore name.
|
|
284 |
"/ nm isNil ifTrue:[
|
|
285 |
"/ nm := ''
|
|
286 |
"/ ]
|
|
287 |
"/ ] ifFalse:[
|
|
288 |
"/ nm := ''
|
|
289 |
"/ ].
|
|
290 |
type := aStream className.
|
|
291 |
|
|
292 |
globalNameOrNil := Smalltalk keyAtValue:aStream.
|
|
293 |
|
|
294 |
aStream isFileStream ifTrue:[
|
|
295 |
detail := aStream pathName.
|
|
296 |
] ifFalse:[
|
|
297 |
aStream isSocket ifTrue:[
|
|
298 |
aStream getPeer notNil ifTrue:[
|
|
299 |
detail := aStream getPeerName printString,aStream getPeer printString.
|
|
300 |
]
|
|
301 |
] ifFalse:[
|
|
302 |
].
|
|
303 |
].
|
|
304 |
|
|
305 |
OperatingSystem isMSWINDOWSlike ifTrue:[
|
|
306 |
aStream isOpen ifTrue:[
|
|
307 |
handle := aStream fileHandle.
|
|
308 |
handleString := handle address hexPrintString
|
|
309 |
].
|
|
310 |
handleString := (handleString ? '') leftPaddedTo:7
|
|
311 |
] ifFalse:[
|
|
312 |
aStream isOpen ifTrue:[
|
|
313 |
handleString := aStream fileDescriptor printString
|
|
314 |
].
|
|
315 |
handleString := (handleString ? '') leftPaddedTo:3
|
|
316 |
].
|
|
317 |
|
|
318 |
line := (type contractTo:20) paddedTo:20.
|
|
319 |
line := line , ' ' , (((globalNameOrNil ? '') contractTo:25) paddedTo:25).
|
|
320 |
line := line , ' ' , handleString.
|
|
321 |
line := line , ' ' , (detail ? '').
|
|
322 |
|
|
323 |
isOpen := aStream isOpen.
|
|
324 |
|
|
325 |
"/ line := line
|
|
326 |
"/ , ' '
|
|
327 |
"/ , ((nm contractTo:25) paddedTo:25)
|
|
328 |
"/ , ' '
|
|
329 |
"/ , (count printStringLeftPaddedTo:3)
|
|
330 |
"/ , ' '
|
|
331 |
"/ , owner printString
|
|
332 |
"/ , ' '
|
|
333 |
"/ , (waiters size printStringLeftPaddedTo:3)
|
|
334 |
"/ , ' '
|
|
335 |
"/ , waitersNames.
|
|
336 |
|
|
337 |
isOpen ifFalse:[
|
|
338 |
color := Color red.
|
|
339 |
] ifTrue:[
|
|
340 |
color := Color blue.
|
|
341 |
].
|
|
342 |
line := line colorizeAllWith:color.
|
|
343 |
|
|
344 |
list add:line.
|
|
345 |
oldSelection notNil ifTrue:[
|
|
346 |
(oldSelection includesIdentical:aStream) ifTrue:[
|
|
347 |
newSelection add:list size.
|
|
348 |
]
|
|
349 |
]
|
|
350 |
].
|
|
351 |
].
|
|
352 |
"avoid flicker"
|
|
353 |
(oldList notNil and:[oldList size == list size]) ifTrue:[
|
|
354 |
list keysAndValuesDo:[:idx :entry |
|
|
355 |
(oldList at:idx) ~= entry ifTrue:[
|
|
356 |
listView at:idx put:entry
|
|
357 |
]
|
|
358 |
]
|
|
359 |
] ifFalse:[
|
|
360 |
listView setList:list.
|
|
361 |
"the first two entries cannot be selected"
|
|
362 |
listView attributeAt:1 put:#disabled.
|
|
363 |
listView attributeAt:2 put:#disabled.
|
|
364 |
].
|
|
365 |
newSelection notNil ifTrue:[
|
|
366 |
listView selectWithoutScroll:newSelection
|
|
367 |
].
|
|
368 |
listView flush
|
|
369 |
].
|
|
370 |
self installDelayedUpdate.
|
|
371 |
! !
|
|
372 |
|
|
373 |
!ExternalStreamMonitor methodsFor:'menu'!
|
|
374 |
|
|
375 |
debugWaiters
|
|
376 |
"open a debugger on the selected semaphores waiting processes"
|
|
377 |
|
|
378 |
self selectedSemaphoresDo:[:aSema |
|
|
379 |
aSema waitingProcesses do:[:aProcess |
|
|
380 |
DebugView openOn:aProcess
|
|
381 |
]
|
|
382 |
]
|
|
383 |
|
|
384 |
"Modified: / 23.1.1997 / 03:12:06 / cg"
|
|
385 |
"Created: / 17.6.1998 / 14:56:55 / cg"
|
|
386 |
!
|
|
387 |
|
|
388 |
inspectSemaphore
|
|
389 |
"open an inspector on the selected semaphores"
|
|
390 |
|
|
391 |
self selectedSemaphoresDo:[:aSema | aSema inspect]
|
|
392 |
|
|
393 |
"Modified: 23.1.1997 / 03:12:06 / cg"
|
|
394 |
"Created: 24.1.1997 / 23:11:50 / cg"
|
|
395 |
!
|
|
396 |
|
|
397 |
inspectStream
|
|
398 |
"open an inspector on the selected stream(s)"
|
|
399 |
|
|
400 |
self selectedStreamsDo:[:aSema | aSema inspect]
|
|
401 |
!
|
|
402 |
|
|
403 |
inspectWaiters
|
|
404 |
"open an inspector on the selected semaphores waiting processes"
|
|
405 |
|
|
406 |
self selectedSemaphoresDo:[:aSema |
|
|
407 |
aSema waitingProcesses do:[:aProcess |
|
|
408 |
aProcess inspect
|
|
409 |
]
|
|
410 |
]
|
|
411 |
|
|
412 |
"Modified: / 23.1.1997 / 03:12:06 / cg"
|
|
413 |
"Created: / 17.6.1998 / 14:17:41 / cg"
|
|
414 |
!
|
|
415 |
|
|
416 |
selectedStreamsDo:aBlock
|
|
417 |
"evaluate aBlock on all selected streams"
|
|
418 |
|
|
419 |
self selectionIndicesDo:[:n |
|
|
420 |
|nr stream|
|
|
421 |
|
|
422 |
nr := n - self numberOfHeadlines.
|
|
423 |
nr notNil ifTrue:[
|
|
424 |
nr > 0 ifTrue:[
|
|
425 |
stream := streams at:nr.
|
|
426 |
(stream notNil and:[stream ~~ 0]) ifTrue:[
|
|
427 |
aBlock value:stream
|
|
428 |
]
|
|
429 |
]
|
|
430 |
]
|
|
431 |
].
|
|
432 |
!
|
|
433 |
|
|
434 |
statusMenu
|
|
435 |
"return a popUpMenu"
|
|
436 |
|
|
437 |
<resource: #programMenu>
|
|
438 |
|
|
439 |
|labels selectors m|
|
|
440 |
|
|
441 |
labels := resources array:#(
|
|
442 |
'Inspect'
|
|
443 |
'Inspect Waiters'
|
|
444 |
'Debug Waiters'
|
|
445 |
).
|
|
446 |
selectors := #(
|
|
447 |
inspectStream
|
|
448 |
inspectWaiters
|
|
449 |
debugWaiters
|
|
450 |
).
|
|
451 |
|
|
452 |
updateProcess isNil ifTrue:[
|
|
453 |
labels := (resources array:#('Update' '-')) , labels.
|
|
454 |
selectors := #(updateView nil) , selectors
|
|
455 |
].
|
|
456 |
|
|
457 |
m := PopUpMenu labels:labels
|
|
458 |
selectors:selectors.
|
|
459 |
|
|
460 |
|
|
461 |
listView hasSelection ifFalse:[
|
|
462 |
m disableAll:#(
|
|
463 |
inspectStream
|
|
464 |
inspectWaiters
|
|
465 |
debugWaiters
|
|
466 |
)
|
|
467 |
].
|
|
468 |
^ m
|
|
469 |
|
|
470 |
"Modified: / 17.6.1998 / 14:17:05 / cg"
|
|
471 |
! !
|
|
472 |
|
|
473 |
!ExternalStreamMonitor methodsFor:'queries'!
|
|
474 |
|
|
475 |
numberOfHeadlines
|
|
476 |
^ 2
|
|
477 |
! !
|
|
478 |
|
|
479 |
!ExternalStreamMonitor methodsFor:'user actions'!
|
|
480 |
|
|
481 |
doubleClicked
|
|
482 |
"open an inspector on the selected semaphore"
|
|
483 |
|
|
484 |
self inspectStream
|
|
485 |
|
|
486 |
"Created: 23.1.1997 / 03:22:04 / cg"
|
|
487 |
"Modified: 31.1.1997 / 22:33:27 / cg"
|
|
488 |
!
|
|
489 |
|
|
490 |
filterConnectedSocketsOnlyHolderChanged
|
|
491 |
self sensor pushUserEvent:#updateList for:self
|
|
492 |
!
|
|
493 |
|
|
494 |
filterOpenStreamsOnlyHolderChanged
|
|
495 |
self sensor pushUserEvent:#updateList for:self
|
|
496 |
!
|
|
497 |
|
|
498 |
filterSocketsOnlyHolderChanged
|
|
499 |
self sensor pushUserEvent:#updateList for:self
|
|
500 |
! !
|
|
501 |
|
|
502 |
!ExternalStreamMonitor class methodsFor:'documentation'!
|
|
503 |
|
|
504 |
version
|
|
505 |
^ '$Header$'
|
|
506 |
!
|
|
507 |
|
|
508 |
version_CVS
|
|
509 |
^ '$Header$'
|
|
510 |
! !
|
|
511 |
|