author | Claus Gittinger <cg@exept.de> |
Wed, 02 Feb 2000 13:39:00 +0100 | |
changeset 5227 | 73a2dc34cb42 |
parent 4908 | da25af8cd02a |
child 5871 | cf03b06e442e |
permissions | -rw-r--r-- |
420 | 1 |
" |
2 |
COPYRIGHT (c) 1995 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 |
||
13 |
Signal subclass:#QuerySignal |
|
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
14 |
instanceVariableNames:'defaultAnswer hasDefault' |
1248 | 15 |
classVariableNames:'' |
16 |
poolDictionaries:'' |
|
17 |
category:'Kernel-Exceptions' |
|
420 | 18 |
! |
19 |
||
1954 | 20 |
!QuerySignal class methodsFor:'documentation'! |
420 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
25 |
All Rights Reserved |
|
26 |
||
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
QuerySignals are like signals, except that they are not accepted |
|
39 |
by handlers for ordinary signals. |
|
40 |
I.e. a signal handler for a normal signal will not handle a query |
|
580 | 41 |
signal. Thus, these bypass anySignal handlers. |
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
42 |
|
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
43 |
However, if unhandled, no error is raised, instead they are simply ignored |
1954 | 44 |
and nil is returned from the raise |
1248 | 45 |
(as opposed to normal signals, which raise an unhandled signal exception). |
1363 | 46 |
QuerySignals are also ignored, if a handler exists, but rejects. |
1248 | 47 |
|
1954 | 48 |
Their main use is to implement upQueries via signals, that work even |
1363 | 49 |
if intermediate errorSignal handlers are present |
50 |
(which is not possible with ordinary signals, since errorSignal handlers |
|
51 |
would catch those signals). |
|
52 |
||
1248 | 53 |
Code deep down in the calling hierarchy can post such an up-Query to ask |
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
54 |
for some information or to pass some information upward. |
580 | 55 |
|
1248 | 56 |
For example, the activityNotification mechanism is built on top of this: |
57 |
everyone can send such a notification which is either handled by someone |
|
58 |
up in the hierarchy (to show it in the windows info area) or simply |
|
59 |
ignored. |
|
60 |
||
61 |
Using QuerySignals for this (instead of regular Signals) helps in documenting |
|
62 |
the intended usage of those signals. |
|
1275 | 63 |
|
1954 | 64 |
Another use of querySignals is to provide additional information to |
65 |
deeply nested methods, which is only required in the uncommon case; |
|
66 |
or if another parameter is required by some method, which was not planned |
|
67 |
for in the beginning, and you do not want to hand this value (via an |
|
68 |
additional argument) through all intermediate levels. |
|
69 |
A highly elegant solution to this problem is to provide a handler somewhere |
|
70 |
at the top of the calling hierarchy, and raise an upQuery from whereever |
|
71 |
that value is required. |
|
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
72 |
A concrete application can be found in the windowGroup-lastEvent |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
73 |
queries. If anyone is interested in the windowEvent which was responible for |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
74 |
being invoked, all he needs to do is to raise the lastEventQuerySignal, |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
75 |
which returns that event. |
1954 | 76 |
No intermediate methods are required to know anything about that. |
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
77 |
Another example is found in the way Metaclass asks for the nameSpace |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
78 |
when new classes are to be installed. A Browser may simply answer such |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
79 |
a query and provide a namespace (no need to pass that information down |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
80 |
the calling chain). |
1954 | 81 |
|
82 |
A final note (to C++ and Java fans): |
|
83 |
such upQueries are only possible, if the exception handling mechanism |
|
84 |
does not automatically unwind the stack for the handler invokation. |
|
85 |
Since the handler must be able to proceed the execution and return |
|
86 |
a value to the raiser .... |
|
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
87 |
... another demonstration of why ST's exception mechanisms are superior. |
1954 | 88 |
|
1275 | 89 |
[see also:] |
90 |
Signal SignalSet Exception |
|
91 |
Object |
|
1363 | 92 |
(``Exception handling and signals'': programming/exceptions.html) |
1292 | 93 |
|
94 |
[author:] |
|
95 |
Claus Gittinger |
|
580 | 96 |
" |
97 |
! |
|
98 |
||
99 |
examples |
|
100 |
" |
|
1379 | 101 |
an up-query from a deeply nested operation to a higher level: |
1316 | 102 |
[exBegin] |
1379 | 103 |
|querySignal zero| |
580 | 104 |
|
1379 | 105 |
zero := 0. |
106 |
querySignal := QuerySignal new. |
|
107 |
querySignal handle:[:ex | |
|
1422 | 108 |
Transcript showCR:'query'. |
1379 | 109 |
ex proceedWith:true |
110 |
] do:[ |
|
111 |
'nesting'. |
|
112 |
[ |
|
113 |
[ |
|
114 |
Object errorSignal handle:[:ex | |
|
1422 | 115 |
Transcript showCR:'some error: ' , ex errorString. |
1379 | 116 |
ex proceed |
117 |
] do:[ |
|
118 |
[ |
|
2689 | 119 |
1 // zero. 'an error which is caught in the handler'. |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
120 |
(querySignal query) == true ifTrue:[ |
1422 | 121 |
Transcript showCR:'query says: ok'. |
1379 | 122 |
] ifFalse:[ |
1422 | 123 |
Transcript showCR:'query says: no' |
1379 | 124 |
] |
125 |
] value |
|
126 |
] |
|
127 |
] value |
|
128 |
] value |
|
129 |
] |
|
130 |
[exEnd] |
|
1534
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
131 |
for lazy typists, a more compact interface is also provided |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
132 |
(which is also easier to read): |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
133 |
[exBegin] |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
134 |
|querySignal| |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
135 |
|
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
136 |
querySignal := QuerySignal new. |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
137 |
querySignal answer:true do:[ |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
138 |
'nesting'. |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
139 |
[ |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
140 |
[ |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
141 |
(querySignal query) == true ifTrue:[ |
1534
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
142 |
Transcript showCR:'query says: ok'. |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
143 |
] ifFalse:[ |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
144 |
Transcript showCR:'query says: no' |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
145 |
] |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
146 |
] value |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
147 |
] value |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
148 |
] |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
149 |
[exEnd] |
1379 | 150 |
an up-query from a deeply nested operation, for which there |
151 |
is no handler: |
|
152 |
(notice, this would not work with normal signals, which would raise |
|
153 |
another unhandled exception-exception; |
|
154 |
also notice the == check #raise's return value being true, |
|
155 |
instead of a simple ifTrue; this handles a nil-value from |
|
156 |
the unhandled query) |
|
157 |
[exBegin] |
|
158 |
|querySignal zero| |
|
159 |
||
160 |
zero := 0. |
|
161 |
querySignal := QuerySignal new. |
|
162 |
||
163 |
[ |
|
164 |
'nesting'. |
|
165 |
[ |
|
166 |
[ |
|
167 |
Object errorSignal handle:[:ex | |
|
1422 | 168 |
Transcript showCR:'some error: ' , ex errorString. |
1379 | 169 |
ex proceed |
170 |
] do:[ |
|
171 |
[ |
|
2689 | 172 |
1 // zero. 'an error which is caught in the handler'. |
1379 | 173 |
(querySignal raise) == true ifTrue:[ |
1422 | 174 |
Transcript showCR:'query says: ok'. |
1379 | 175 |
] ifFalse:[ |
1422 | 176 |
Transcript showCR:'query says: no' |
1379 | 177 |
] |
178 |
] value |
|
179 |
] |
|
180 |
] value |
|
181 |
] value |
|
182 |
] value |
|
183 |
[exEnd] |
|
184 |
counter-example, just to show that things would not work this way |
|
185 |
with regular signals: |
|
186 |
[exBegin] |
|
187 |
|signal| |
|
188 |
||
189 |
signal := Signal new. |
|
190 |
'nesting deeply'. |
|
191 |
[ |
|
192 |
[ |
|
1316 | 193 |
[ |
194 |
[ |
|
1379 | 195 |
[ |
196 |
(signal raise) == true ifTrue:[ |
|
1422 | 197 |
Transcript showCR:'query says: ok'. |
1379 | 198 |
] ifFalse:[ |
1422 | 199 |
Transcript showCR:'query says: no' |
1379 | 200 |
] |
201 |
] value |
|
1316 | 202 |
] value |
203 |
] value |
|
1379 | 204 |
] value |
205 |
] value |
|
206 |
[exEnd] |
|
207 |
||
208 |
except, by handling the unhandled exception |
|
209 |
(but we think, that querySignals are easier to use and |
|
210 |
better document the intent): |
|
211 |
[exBegin] |
|
212 |
|signal| |
|
213 |
||
214 |
signal := Signal new. |
|
215 |
'nesting deeply'. |
|
216 |
[ |
|
217 |
[ |
|
218 |
[ |
|
219 |
[ |
|
220 |
[ |
|
221 |
Signal noHandlerSignal handle:[:ex | |
|
222 |
ex proceedWith:nil |
|
223 |
] do:[ |
|
224 |
(signal raise) == true ifTrue:[ |
|
1422 | 225 |
Transcript showCR:'query says: ok'. |
1379 | 226 |
] ifFalse:[ |
1422 | 227 |
Transcript showCR:'query says: no' |
1379 | 228 |
] |
229 |
] |
|
230 |
] value |
|
231 |
] value |
|
232 |
] value |
|
233 |
] value |
|
234 |
] value |
|
235 |
[exEnd] |
|
420 | 236 |
" |
237 |
! ! |
|
238 |
||
2893 | 239 |
!QuerySignal methodsFor:'answering queries'! |
240 |
||
241 |
answer:someAnswer do:aBlock |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
242 |
"evaluate the argument, aBlock. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
243 |
If the receiver is queried during evaluation, answer with someAnswer. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
244 |
This is a wrapper for #handle:do: for lazy typists; no new functionality." |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
245 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
246 |
<exception: #handle> |
2893 | 247 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
248 |
"/ thisContext markForHandle. -- same as above pragma |
5227
73a2dc34cb42
#answer:do: now returns the evaluated blocks value
Claus Gittinger <cg@exept.de>
parents:
4908
diff
changeset
|
249 |
^ aBlock value. "the real logic is in Exception>>doRaise" |
2893 | 250 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
251 |
" |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
252 |
|q| |
2893 | 253 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
254 |
q := QuerySignal new. |
2893 | 255 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
256 |
q answer:true do:[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
257 |
Transcript showCR:'query answers: ' , (q query printString). |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
258 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
259 |
" |
2893 | 260 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
261 |
" |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
262 |
|q| |
2893 | 263 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
264 |
q := QuerySignal new. |
2893 | 265 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
266 |
q answer:false do:[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
267 |
Transcript showCR:'first query answers: ' , (q query printString). |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
268 |
q answer:true do:[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
269 |
Transcript showCR:'second query answers: ' , (q query printString). |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
270 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
271 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
272 |
" |
2893 | 273 |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
274 |
"Created: / 10.7.1996 / 15:08:20 / cg" |
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
275 |
"Modified: / 14.10.1996 / 16:59:18 / cg" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
276 |
"Modified: / 25.7.1999 / 23:34:02 / stefan" |
2893 | 277 |
! ! |
278 |
||
2037 | 279 |
!QuerySignal methodsFor:'initialization'! |
280 |
||
281 |
defaultAnswer:someValue |
|
282 |
"define the queries defaultAnswer to be someValue. |
|
283 |
This is the same as defining an appropriate handlerBlock." |
|
284 |
||
285 |
|handler| |
|
286 |
||
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
287 |
defaultAnswer := someValue. |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
288 |
hasDefault := true. |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
289 |
|
2037 | 290 |
"/ avoid creating a fullBlock, in the most common cases |
4514 | 291 |
"/ therefore, do not replace the code below by |
292 |
"/ handler := [:ex | ex proceedWith:someValue] |
|
293 |
"/ although it is semantically equivalent. |
|
294 |
||
2037 | 295 |
someValue == true ifTrue:[ |
296 |
handler := [:ex | ex proceedWith:true] |
|
297 |
] ifFalse:[ |
|
298 |
someValue == false ifTrue:[ |
|
299 |
handler := [:ex | ex proceedWith:false] |
|
300 |
] ifFalse:[ |
|
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
301 |
someValue isNil ifTrue:[ |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
302 |
handler := [:ex | ex proceedWith:nil] |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
303 |
] ifFalse:[ |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
304 |
handler := [:ex | ex proceedWith:someValue]. |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
305 |
] |
2037 | 306 |
] |
307 |
]. |
|
308 |
self handlerBlock:handler. |
|
309 |
||
310 |
" |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
311 |
QuerySignal new query |
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
312 |
(QuerySignal new defaultAnswer:true) query |
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
313 |
(QuerySignal new defaultAnswer:false) query |
2037 | 314 |
" |
315 |
||
316 |
" |
|
317 |
|sig rslt| |
|
318 |
||
319 |
sig := QuerySignal new. |
|
320 |
sig defaultAnswer:false. |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
321 |
rslt := sig query. |
2037 | 322 |
Transcript showCR:rslt. |
323 |
" |
|
324 |
||
325 |
" |
|
326 |
|sig rslt| |
|
327 |
||
328 |
sig := QuerySignal new. |
|
329 |
sig defaultAnswer:false. |
|
330 |
sig answer:true |
|
331 |
do:[ |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
332 |
rslt := sig query |
2037 | 333 |
]. |
334 |
Transcript showCR:rslt. |
|
335 |
" |
|
336 |
||
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
337 |
"Modified: / 3.1.1997 / 15:14:40 / cg" |
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
338 |
"Modified: / 2.3.1998 / 10:42:14 / stefan" |
2037 | 339 |
! ! |
340 |
||
420 | 341 |
!QuerySignal methodsFor:'queries'! |
342 |
||
343 |
accepts:aSignal |
|
344 |
"return true, if the receiver accepts the argument, aSignal. |
|
345 |
(i.e. the receiver is aSignal or a parent of it). False otherwise." |
|
346 |
||
347 |
|s| |
|
348 |
||
4527 | 349 |
self == aSignal ifTrue:[^ true]. |
421 | 350 |
aSignal isQuerySignal ifFalse:[^ false]. |
420 | 351 |
|
352 |
s := aSignal. |
|
353 |
[s notNil] whileTrue:[ |
|
4061
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
354 |
self == s ifTrue:[^ true]. |
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
355 |
s := s parent |
420 | 356 |
]. |
357 |
^ false |
|
4061
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
358 |
|
4438 | 359 |
"Modified: / 22.3.1999 / 12:45:32 / stefan" |
691 | 360 |
! |
361 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
362 |
handlerForSignal:signal context:theContext originator:originator |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
363 |
"answer the handler block for the signal from originator. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
364 |
The block is retrieved from aContext. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
365 |
Answer nil if the signal is not handled" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
366 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
367 |
|arg| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
368 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
369 |
theContext selector == #'answer:do:' ifTrue:[ |
4514 | 370 |
(self == signal or:[self accepts:signal]) ifTrue:[ |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
371 |
arg := theContext argAt:1. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
372 |
^ [:ex| ex proceedWith:arg]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
373 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
374 |
] ifFalse:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
375 |
^ super handlerForSignal:signal context:theContext originator:originator. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
376 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
377 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
378 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
379 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
380 |
"Created: / 25.7.1999 / 23:33:05 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
381 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
382 |
|
691 | 383 |
isQuerySignal |
1249 | 384 |
"return true, if this is a querySignal - always return true here" |
385 |
||
691 | 386 |
^ true |
1249 | 387 |
|
388 |
"Modified: 22.4.1996 / 13:45:10 / cg" |
|
2893 | 389 |
! |
1534
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
390 |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
391 |
query |
2893 | 392 |
"raise the query - return the handlers value, or the default |
4908 | 393 |
value, if there is no handler." |
1534
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
394 |
|
4514 | 395 |
^ self raiseRequest |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
396 |
! |
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
397 |
|
4908 | 398 |
queryWith:aParameter |
399 |
"raise the query passing a parameter |
|
400 |
- return the handlers value, or the default value, if there is no handler." |
|
401 |
||
402 |
^ self raiseRequestWith:aParameter |
|
403 |
! |
|
404 |
||
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
405 |
raise |
4061
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
406 |
"QuerySignals are proceedable by definition, |
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
407 |
so they should be raised with #query or #raiseRequest" |
1534
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
408 |
|
4061
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
409 |
self obsoleteMethodWarning:'use #query or #raiseRequest'. |
4514 | 410 |
^ self raiseRequest |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
411 |
|
4061
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
412 |
"Modified: / 18.3.1999 / 18:33:57 / stefan" |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
413 |
! |
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
414 |
|
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
415 |
raiseRequest |
4514 | 416 |
"raise the query - return the handlers value, or the default |
417 |
value, if there is no handler. |
|
418 |
Invoking the handler is exactly the functionality of Signal>>raiseRequest, |
|
419 |
but we can do it faster here, by avoiding the creation of a full-blown |
|
420 |
exception object." |
|
421 |
||
422 |
|con s| |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
423 |
|
4514 | 424 |
con := Context findFirstSpecialHandle:true raise:false. |
425 |
[con notNil] whileTrue:[ |
|
426 |
(s := con selector) == #'answer:do:' ifTrue:[ |
|
427 |
(s := con receiver) == self ifTrue:[ |
|
428 |
"/ '0' printCR. |
|
429 |
^ con argAt:1 |
|
430 |
]. |
|
431 |
(s accepts:self) ifTrue:[ |
|
432 |
"/ '*2' printCR. |
|
433 |
^ super raiseRequest |
|
434 |
]. |
|
435 |
] ifFalse:[ |
|
436 |
s == #'handle:do:' ifFalse:[ |
|
437 |
"/ '*1a ' print. con printCR. |
|
438 |
^ super raiseRequest |
|
439 |
]. |
|
440 |
(s := con receiver) == self ifTrue:[ |
|
441 |
"/ '*1b ' print. con printCR. |
|
442 |
^ super raiseRequest |
|
443 |
]. |
|
444 |
(s accepts:self) ifTrue:[ |
|
445 |
"/ '*1c ' print. con printCR. |
|
446 |
^ super raiseRequest |
|
447 |
] |
|
448 |
]. |
|
449 |
con := con findSpecialHandle:true raise:false. |
|
450 |
]. |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
451 |
|
4514 | 452 |
"/ no handler found - return the default value |
453 |
hasDefault == true ifTrue:[ |
|
454 |
"/ '3 ' print. self print. ' default: ' print. defaultAnswer printCR. |
|
455 |
^ defaultAnswer |
|
456 |
]. |
|
457 |
handlerBlock isNil ifTrue:[ |
|
458 |
"/ '4 ' print. self print. ' nil: ' printCR. |
|
459 |
^ nil |
|
460 |
]. |
|
461 |
"/ '*5 ' print. self print. ' handlerBlock' printCR. |
|
462 |
^ super raiseRequest |
|
463 |
||
464 |
"Modified: / 15.6.1998 / 21:27:37 / cg" |
|
465 |
"Modified: / 25.7.1999 / 23:35:11 / stefan" |
|
1534
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
466 |
! ! |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
467 |
|
1954 | 468 |
!QuerySignal class methodsFor:'documentation'! |
691 | 469 |
|
470 |
version |
|
5227
73a2dc34cb42
#answer:do: now returns the evaluated blocks value
Claus Gittinger <cg@exept.de>
parents:
4908
diff
changeset
|
471 |
^ '$Header: /cvs/stx/stx/libbasic/QuerySignal.st,v 1.34 2000-02-02 12:38:42 cg Exp $' |
691 | 472 |
! ! |