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