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 |
)
|
17487
|
152 |
(MenuItem
|
|
153 |
label: 'Operations'
|
|
154 |
submenuChannel: operationsMenu
|
|
155 |
)
|
17227
|
156 |
)
|
|
157 |
nil
|
|
158 |
nil
|
|
159 |
)
|
17487
|
160 |
|
|
161 |
"Modified: / 07-04-2017 / 14:21:44 / cg"
|
|
162 |
!
|
|
163 |
|
|
164 |
operationsMenu
|
|
165 |
"This resource specification was automatically generated
|
|
166 |
by the MenuEditor of ST/X."
|
|
167 |
|
|
168 |
"Do not manually edit this!! If it is corrupted,
|
|
169 |
the MenuEditor may not be able to read the specification."
|
|
170 |
|
|
171 |
|
|
172 |
"
|
|
173 |
MenuEditor new openOnClass:ExternalStreamMonitor andSelector:#filterMenu
|
|
174 |
(Menu new fromLiteralArrayEncoding:(ExternalStreamMonitor filterMenu)) startUp
|
|
175 |
"
|
|
176 |
|
|
177 |
<resource: #menu>
|
|
178 |
|
|
179 |
^
|
|
180 |
#(Menu
|
|
181 |
(
|
|
182 |
(MenuItem
|
|
183 |
label: 'Close'
|
|
184 |
itemValue: menuCloseSelected
|
|
185 |
)
|
|
186 |
(MenuItem
|
|
187 |
label: '-'
|
|
188 |
)
|
|
189 |
(MenuItem
|
|
190 |
label: 'Inspect'
|
|
191 |
itemValue: inspectStream
|
|
192 |
)
|
|
193 |
)
|
|
194 |
nil
|
|
195 |
nil
|
|
196 |
)
|
|
197 |
|
|
198 |
"Created: / 07-04-2017 / 14:22:18 / cg"
|
17227
|
199 |
! !
|
|
200 |
|
|
201 |
!ExternalStreamMonitor methodsFor:'aspects'!
|
|
202 |
|
|
203 |
filterConnectedSocketsOnlyHolder
|
|
204 |
filterConnectedSocketsOnlyHolder isNil ifTrue:[
|
|
205 |
filterConnectedSocketsOnlyHolder := false asValue.
|
|
206 |
filterConnectedSocketsOnlyHolder onChangeSend:#filterConnectedSocketsOnlyHolderChanged to:self.
|
|
207 |
].
|
|
208 |
^ filterConnectedSocketsOnlyHolder
|
|
209 |
!
|
|
210 |
|
|
211 |
filterOpenStreamsOnlyHolder
|
|
212 |
filterOpenStreamsOnlyHolder isNil ifTrue:[
|
|
213 |
filterOpenStreamsOnlyHolder := false asValue.
|
|
214 |
filterSocketsOnlyHolder onChangeSend:#filterOpenStreamsOnlyHolder to:self.
|
|
215 |
].
|
|
216 |
^ filterOpenStreamsOnlyHolder
|
|
217 |
!
|
|
218 |
|
|
219 |
filterSocketsOnlyHolder
|
|
220 |
filterSocketsOnlyHolder isNil ifTrue:[
|
|
221 |
filterSocketsOnlyHolder := false asValue.
|
|
222 |
filterSocketsOnlyHolder onChangeSend:#filterSocketsOnlyHolderChanged to:self.
|
|
223 |
].
|
|
224 |
^ filterSocketsOnlyHolder
|
|
225 |
! !
|
|
226 |
|
|
227 |
!ExternalStreamMonitor methodsFor:'drawing'!
|
|
228 |
|
|
229 |
titleLine
|
|
230 |
OperatingSystem isMSWINDOWSlike ifTrue:[
|
|
231 |
^ 'Type Global Handle Detail'.
|
|
232 |
] ifFalse:[
|
|
233 |
^ 'Type Global FD Detail'.
|
|
234 |
].
|
|
235 |
|
|
236 |
"
|
|
237 |
ExternalStreamMonitor open
|
|
238 |
"
|
|
239 |
|
|
240 |
"Modified: / 17.6.1998 / 14:52:48 / cg"
|
|
241 |
!
|
|
242 |
|
|
243 |
updateList
|
|
244 |
"update list of semaphores"
|
|
245 |
|
|
246 |
|newList|
|
|
247 |
|
|
248 |
shown ifTrue:[
|
|
249 |
newList := ExternalStream allSubInstances.
|
|
250 |
|
|
251 |
self filterSocketsOnlyHolder value ifTrue:[
|
|
252 |
newList := newList select:[:eachStream | eachStream isSocket].
|
|
253 |
].
|
|
254 |
self filterOpenStreamsOnlyHolder value ifTrue:[
|
|
255 |
newList := newList select:[:eachStream | eachStream isOpen].
|
|
256 |
].
|
|
257 |
self filterConnectedSocketsOnlyHolder value ifTrue:[
|
|
258 |
newList := newList select:[:eachStream | eachStream isSocket and:[eachStream isConnected]].
|
|
259 |
].
|
|
260 |
|
|
261 |
"sort by hashKey - will not always generate unique numbers,
|
|
262 |
but most of the time, this works ... for now"
|
|
263 |
|
|
264 |
newList sort:[:s1 :s2 |
|
|
265 |
s1 className < s2 className
|
|
266 |
or:[ s1 className = s2 className
|
|
267 |
and:[false]]
|
|
268 |
].
|
|
269 |
|
|
270 |
newList ~= streams ifTrue:[
|
|
271 |
self updateStatus:newList
|
|
272 |
].
|
|
273 |
].
|
|
274 |
self installDelayedUpdate.
|
|
275 |
!
|
|
276 |
|
|
277 |
updateStatus:newStreamsList
|
|
278 |
"update status display of semaphores"
|
|
279 |
|
|
280 |
|oldList list oldSelection newSelection|
|
|
281 |
|
|
282 |
shown ifTrue:[
|
|
283 |
oldList := listView list.
|
|
284 |
oldSelection := listView selection.
|
|
285 |
oldSelection notNil ifTrue:[
|
|
286 |
oldSelection := oldSelection collect:[:lineNr | streams at:(lineNr - self numberOfHeadlines) ].
|
|
287 |
newSelection := OrderedCollection new.
|
|
288 |
].
|
|
289 |
|
|
290 |
newStreamsList notNil ifTrue:[
|
|
291 |
streams := WeakArray withAll:newStreamsList.
|
|
292 |
].
|
|
293 |
streams notNil ifTrue:[
|
|
294 |
list := OrderedCollection new:(streams size + self numberOfHeadlines).
|
|
295 |
list add:self titleLine.
|
|
296 |
list add:(String new:self titleLine size withAll:$-).
|
|
297 |
|
|
298 |
streams validElementsDo:[:aStream |
|
|
299 |
|waiters waitersNames type globalNameOrNil handleString
|
|
300 |
isOpen handle detail color line|
|
|
301 |
|
|
302 |
"/ "/ need a copy - it may change while being enumerated
|
|
303 |
"/ [
|
|
304 |
"/ count := aSemaphore count.
|
|
305 |
"/ waiters := aSemaphore waitingProcesses copy.
|
|
306 |
"/ ] valueUninterruptably.
|
|
307 |
|
|
308 |
"/ str := '' writeStream.
|
|
309 |
"/ [
|
|
310 |
"/ waiters notNil ifTrue:[
|
|
311 |
"/ waiters do:[:aProcess |
|
|
312 |
"/ str nextPut:$[.
|
|
313 |
"/ aProcess id printOn:str.
|
|
314 |
"/ str nextPutAll:' '''.
|
|
315 |
"/ str nextPutAll:(aProcess name contractTo:40).
|
|
316 |
"/ str nextPutAll:'''<'.
|
|
317 |
"/ aProcess priority printOn:str.
|
|
318 |
"/ str nextPutAll:'>]'.
|
|
319 |
"/ str space.
|
|
320 |
"/ ].
|
|
321 |
"/ ]
|
|
322 |
"/ ] valueUninterruptably.
|
|
323 |
"/ waitersNames := str contents.
|
|
324 |
|
|
325 |
"/ (aSemaphore respondsTo:#name) ifTrue:[
|
|
326 |
"/ nm := aSemaphore name.
|
|
327 |
"/ nm isNil ifTrue:[
|
|
328 |
"/ nm := ''
|
|
329 |
"/ ]
|
|
330 |
"/ ] ifFalse:[
|
|
331 |
"/ nm := ''
|
|
332 |
"/ ].
|
|
333 |
type := aStream className.
|
|
334 |
|
|
335 |
globalNameOrNil := Smalltalk keyAtValue:aStream.
|
|
336 |
|
|
337 |
aStream isFileStream ifTrue:[
|
|
338 |
detail := aStream pathName.
|
|
339 |
] ifFalse:[
|
|
340 |
aStream isSocket ifTrue:[
|
17707
|
341 |
detail := ''.
|
17227
|
342 |
aStream getPeer notNil ifTrue:[
|
17707
|
343 |
detail := detail,(aStream getPeerName printString),(aStream getPeer printString).
|
|
344 |
].
|
|
345 |
aStream port notNil ifTrue:[
|
|
346 |
detail := detail,':',aStream port printString
|
|
347 |
].
|
17227
|
348 |
] ifFalse:[
|
|
349 |
].
|
|
350 |
].
|
|
351 |
|
|
352 |
OperatingSystem isMSWINDOWSlike ifTrue:[
|
|
353 |
aStream isOpen ifTrue:[
|
|
354 |
handle := aStream fileHandle.
|
17616
|
355 |
handle isInteger ifTrue:[
|
|
356 |
handleString := handle printString
|
|
357 |
] ifFalse:[
|
|
358 |
handleString := (handle address ? 0) hexPrintString
|
|
359 |
].
|
17227
|
360 |
].
|
|
361 |
handleString := (handleString ? '') leftPaddedTo:7
|
|
362 |
] ifFalse:[
|
|
363 |
aStream isOpen ifTrue:[
|
17622
|
364 |
[
|
|
365 |
] on:StreamError do:[
|
|
366 |
handleString := aStream fileDescriptor printString
|
|
367 |
].
|
17227
|
368 |
].
|
|
369 |
handleString := (handleString ? '') leftPaddedTo:3
|
|
370 |
].
|
|
371 |
|
|
372 |
line := (type contractTo:20) paddedTo:20.
|
|
373 |
line := line , ' ' , (((globalNameOrNil ? '') contractTo:25) paddedTo:25).
|
|
374 |
line := line , ' ' , handleString.
|
|
375 |
line := line , ' ' , (detail ? '').
|
|
376 |
|
|
377 |
isOpen := aStream isOpen.
|
|
378 |
|
|
379 |
"/ line := line
|
|
380 |
"/ , ' '
|
|
381 |
"/ , ((nm contractTo:25) paddedTo:25)
|
|
382 |
"/ , ' '
|
|
383 |
"/ , (count printStringLeftPaddedTo:3)
|
|
384 |
"/ , ' '
|
|
385 |
"/ , owner printString
|
|
386 |
"/ , ' '
|
|
387 |
"/ , (waiters size printStringLeftPaddedTo:3)
|
|
388 |
"/ , ' '
|
|
389 |
"/ , waitersNames.
|
|
390 |
|
|
391 |
isOpen ifFalse:[
|
|
392 |
color := Color red.
|
|
393 |
] ifTrue:[
|
|
394 |
color := Color blue.
|
|
395 |
].
|
|
396 |
line := line colorizeAllWith:color.
|
|
397 |
|
|
398 |
list add:line.
|
|
399 |
oldSelection notNil ifTrue:[
|
|
400 |
(oldSelection includesIdentical:aStream) ifTrue:[
|
|
401 |
newSelection add:list size.
|
|
402 |
]
|
|
403 |
]
|
|
404 |
].
|
|
405 |
].
|
|
406 |
"avoid flicker"
|
|
407 |
(oldList notNil and:[oldList size == list size]) ifTrue:[
|
|
408 |
list keysAndValuesDo:[:idx :entry |
|
|
409 |
(oldList at:idx) ~= entry ifTrue:[
|
|
410 |
listView at:idx put:entry
|
|
411 |
]
|
|
412 |
]
|
|
413 |
] ifFalse:[
|
|
414 |
listView setList:list.
|
|
415 |
"the first two entries cannot be selected"
|
|
416 |
listView attributeAt:1 put:#disabled.
|
|
417 |
listView attributeAt:2 put:#disabled.
|
|
418 |
].
|
|
419 |
newSelection notNil ifTrue:[
|
|
420 |
listView selectWithoutScroll:newSelection
|
|
421 |
].
|
|
422 |
listView flush
|
|
423 |
].
|
|
424 |
self installDelayedUpdate.
|
17622
|
425 |
|
17707
|
426 |
"Modified: / 11-10-2017 / 13:56:14 / cg"
|
17227
|
427 |
! !
|
|
428 |
|
|
429 |
!ExternalStreamMonitor methodsFor:'menu'!
|
|
430 |
|
|
431 |
selectedStreamsDo:aBlock
|
|
432 |
"evaluate aBlock on all selected streams"
|
|
433 |
|
|
434 |
self selectionIndicesDo:[:n |
|
|
435 |
|nr stream|
|
|
436 |
|
|
437 |
nr := n - self numberOfHeadlines.
|
|
438 |
nr notNil ifTrue:[
|
|
439 |
nr > 0 ifTrue:[
|
|
440 |
stream := streams at:nr.
|
|
441 |
(stream notNil and:[stream ~~ 0]) ifTrue:[
|
|
442 |
aBlock value:stream
|
|
443 |
]
|
|
444 |
]
|
|
445 |
]
|
|
446 |
].
|
|
447 |
!
|
|
448 |
|
|
449 |
statusMenu
|
|
450 |
"return a popUpMenu"
|
|
451 |
|
|
452 |
<resource: #programMenu>
|
|
453 |
|
|
454 |
|labels selectors m|
|
|
455 |
|
|
456 |
labels := resources array:#(
|
17487
|
457 |
'Close'
|
|
458 |
'-'
|
17227
|
459 |
'Inspect'
|
|
460 |
).
|
|
461 |
selectors := #(
|
17487
|
462 |
menuCloseSelected
|
|
463 |
nil
|
17227
|
464 |
inspectStream
|
|
465 |
).
|
|
466 |
|
|
467 |
updateProcess isNil ifTrue:[
|
17622
|
468 |
labels := labels,(resources array:#('-' 'Update' )).
|
|
469 |
selectors := selectors , #(nil updateView).
|
17227
|
470 |
].
|
|
471 |
|
|
472 |
m := PopUpMenu labels:labels
|
|
473 |
selectors:selectors.
|
|
474 |
|
|
475 |
|
|
476 |
listView hasSelection ifFalse:[
|
|
477 |
m disableAll:#(
|
17487
|
478 |
menuCloseSelected
|
17227
|
479 |
inspectStream
|
|
480 |
)
|
|
481 |
].
|
|
482 |
^ m
|
|
483 |
|
17622
|
484 |
"Modified: / 18-08-2017 / 14:34:12 / cg"
|
17227
|
485 |
! !
|
|
486 |
|
|
487 |
!ExternalStreamMonitor methodsFor:'queries'!
|
|
488 |
|
|
489 |
numberOfHeadlines
|
|
490 |
^ 2
|
|
491 |
! !
|
|
492 |
|
|
493 |
!ExternalStreamMonitor methodsFor:'user actions'!
|
|
494 |
|
|
495 |
doubleClicked
|
17487
|
496 |
"open an inspector on the selected stream"
|
17227
|
497 |
|
|
498 |
self inspectStream
|
|
499 |
|
17487
|
500 |
"Created: / 23-01-1997 / 03:22:04 / cg"
|
|
501 |
"Modified: / 31-01-1997 / 22:33:27 / cg"
|
|
502 |
"Modified (comment): / 07-04-2017 / 14:28:01 / cg"
|
17227
|
503 |
!
|
|
504 |
|
|
505 |
filterConnectedSocketsOnlyHolderChanged
|
|
506 |
self sensor pushUserEvent:#updateList for:self
|
|
507 |
!
|
|
508 |
|
|
509 |
filterOpenStreamsOnlyHolderChanged
|
|
510 |
self sensor pushUserEvent:#updateList for:self
|
|
511 |
!
|
|
512 |
|
|
513 |
filterSocketsOnlyHolderChanged
|
|
514 |
self sensor pushUserEvent:#updateList for:self
|
17487
|
515 |
!
|
|
516 |
|
|
517 |
inspectStream
|
|
518 |
"open an inspector on the selected stream(s)"
|
|
519 |
|
|
520 |
self selectedStreamsDo:[:eachStream | eachStream inspect]
|
|
521 |
|
|
522 |
"Modified (format): / 07-04-2017 / 14:27:45 / cg"
|
|
523 |
!
|
|
524 |
|
|
525 |
menuCloseSelected
|
|
526 |
"close the selected stream(s)"
|
|
527 |
|
|
528 |
self selectedStreamsDo:[:eachStream | eachStream close]
|
|
529 |
|
|
530 |
"Created: / 07-04-2017 / 14:26:04 / cg"
|
17227
|
531 |
! !
|
|
532 |
|
|
533 |
!ExternalStreamMonitor class methodsFor:'documentation'!
|
|
534 |
|
|
535 |
version
|
|
536 |
^ '$Header$'
|
|
537 |
!
|
|
538 |
|
|
539 |
version_CVS
|
|
540 |
^ '$Header$'
|
|
541 |
! !
|
|
542 |
|