QuerySignal.st
author Claus Gittinger <cg@exept.de>
Tue, 23 Apr 1996 22:22:39 +0200
changeset 1275 2079f4776628
parent 1249 2d5d0edd3359
child 1292 89497fff7f87
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
420
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
     1
"
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
     3
	      All Rights Reserved
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
     4
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    11
"
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    12
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    13
Signal subclass:#QuerySignal
1248
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    14
	instanceVariableNames:''
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    15
	classVariableNames:''
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    16
	poolDictionaries:''
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    17
	category:'Kernel-Exceptions'
420
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    18
!
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    19
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    20
!QuerySignal class methodsFor:'documentation'!
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    21
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    22
copyright
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    23
"
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    24
 COPYRIGHT (c) 1995 by Claus Gittinger
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    25
	      All Rights Reserved
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    26
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    27
 This software is furnished under a license and may be used
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    28
 only in accordance with the terms of that license and with the
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    30
 be provided or otherwise made available to, or used by, any
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    31
 other person.  No title to or ownership of the software is
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    32
 hereby transferred.
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    33
"
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    34
!
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    35
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    36
documentation
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    37
"
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    38
    QuerySignals are like signals, except that they are not accepted
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    39
    by handlers for ordinary signals.
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    40
    I.e. a signal handler for a normal signal will not handle a query
580
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    41
    signal. Thus, these bypass anySignal handlers.
1248
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    42
    If unhandled, no error is raised, instead they are simply ignored
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    43
    (as opposed to normal signals, which raise an unhandled signal exception).
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    44
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    45
    Their main use is to implement up-Queries via signals even if intermediate
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    46
    errorSignal handlers are present (which is not possible with ordinary signals).
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    47
    Code deep down in the calling hierarchy can post such an up-Query to ask
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    48
    for some information in return or to pass some information upward. 
580
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    49
1248
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    50
    For example, the activityNotification mechanism is built on top of this:
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    51
    everyone can send such a notification which is either handled by someone
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    52
    up in the hierarchy (to show it in the windows info area) or simply
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    53
    ignored.
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    54
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    55
    Using QuerySignals for this (instead of regular Signals) helps in documenting
04639edf1064 commentary
Claus Gittinger <cg@exept.de>
parents: 691
diff changeset
    56
    the intended usage of those signals.
1275
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1249
diff changeset
    57
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1249
diff changeset
    58
    [see also:]
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1249
diff changeset
    59
        Signal SignalSet Exception
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1249
diff changeset
    60
        Object
580
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    61
"
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    62
!
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    63
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    64
examples 
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    65
"
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    66
    an up-query from a deeply nested operation to a higher level:
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    67
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    68
	|querySignal zero|
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    69
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    70
	zero := 0.
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    71
	querySignal := QuerySignal new.
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    72
	querySignal handle:[:ex |
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    73
	    ex proceedWith:true
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    74
	] do:[
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    75
	    'nexting'.
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    76
	    [
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    77
		[
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    78
		    Object errorSignal handle:[:ex |
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    79
			ex proceed
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    80
		    ] do:[
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    81
			[
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    82
			    1 // zero.  'a cought error'.
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    83
			    (querySignal raise) ifTrue:[
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    84
				Transcript showCr:'query says: ok'.
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    85
			     ] ifFalse:[
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    86
				Transcript showCr:'query says: no'
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    87
			     ]
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    88
			] value
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    89
		    ]
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    90
		] value
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    91
	    ] value
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    92
	]
420
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    93
"
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    94
! !
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    95
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    96
!QuerySignal methodsFor:'queries'!
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    97
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    98
accepts:aSignal
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    99
    "return true, if the receiver accepts the argument, aSignal.
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   100
     (i.e. the receiver is aSignal or a parent of it). False otherwise."
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   101
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   102
    |s|
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   103
421
claus
parents: 420
diff changeset
   104
    aSignal isQuerySignal ifFalse:[^ false].
420
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   105
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   106
    s := aSignal.
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   107
    [s notNil] whileTrue:[
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   108
	self == s ifTrue:[^ true].
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   109
	s := s parent
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   110
    ].
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   111
    ^ false
691
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   112
!
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   113
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   114
isQuerySignal
1249
2d5d0edd3359 commentary
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   115
    "return true, if this is a querySignal - always return true here"
2d5d0edd3359 commentary
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   116
691
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   117
    ^ true
1249
2d5d0edd3359 commentary
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   118
2d5d0edd3359 commentary
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   119
    "Modified: 22.4.1996 / 13:45:10 / cg"
420
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   120
! !
691
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   121
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   122
!QuerySignal class methodsFor:'documentation'!
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   123
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   124
version
1275
2079f4776628 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1249
diff changeset
   125
    ^ '$Header: /cvs/stx/stx/libbasic/QuerySignal.st,v 1.8 1996-04-23 20:22:39 cg Exp $'
691
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   126
! !