QuerySignal.st
author Claus Gittinger <cg@exept.de>
Mon, 22 Apr 1996 13:45:52 +0200
changeset 1249 2d5d0edd3359
parent 1248 04639edf1064
child 1275 2079f4776628
permissions -rw-r--r--
commentary
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.
580
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    57
"
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    58
!
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    59
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    60
examples 
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    61
"
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    62
    an up-query from a deeply nested operation to a higher level:
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    63
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    64
	|querySignal zero|
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    65
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    66
	zero := 0.
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    67
	querySignal := QuerySignal new.
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    68
	querySignal handle:[:ex |
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    69
	    ex proceedWith:true
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    70
	] do:[
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    71
	    'nexting'.
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    72
	    [
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    73
		[
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    74
		    Object errorSignal handle:[:ex |
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    75
			ex proceed
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    76
		    ] do:[
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    77
			[
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    78
			    1 // zero.  'a cought error'.
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    79
			    (querySignal raise) ifTrue:[
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    80
				Transcript showCr:'query says: ok'.
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    81
			     ] ifFalse:[
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    82
				Transcript showCr:'query says: no'
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    83
			     ]
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    84
			] value
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    85
		    ]
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    86
		] value
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    87
	    ] value
03852d320a48 commentary
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    88
	]
420
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    89
"
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    90
! !
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    91
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    92
!QuerySignal methodsFor:'queries'!
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    93
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    94
accepts:aSignal
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    95
    "return true, if the receiver accepts the argument, aSignal.
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    96
     (i.e. the receiver is aSignal or a parent of it). False otherwise."
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    97
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    98
    |s|
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
    99
421
claus
parents: 420
diff changeset
   100
    aSignal isQuerySignal ifFalse:[^ false].
420
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   101
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   102
    s := aSignal.
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   103
    [s notNil] whileTrue:[
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   104
	self == s ifTrue:[^ true].
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   105
	s := s parent
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   106
    ].
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   107
    ^ false
691
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   108
!
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   109
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   110
isQuerySignal
1249
2d5d0edd3359 commentary
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   111
    "return true, if this is a querySignal - always return true here"
2d5d0edd3359 commentary
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   112
691
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   113
    ^ true
1249
2d5d0edd3359 commentary
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   114
2d5d0edd3359 commentary
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   115
    "Modified: 22.4.1996 / 13:45:10 / cg"
420
081f7b2bb3b3 Initial revision
claus
parents:
diff changeset
   116
! !
691
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   117
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   118
!QuerySignal class methodsFor:'documentation'!
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   119
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   120
version
1249
2d5d0edd3359 commentary
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
   121
    ^ '$Header: /cvs/stx/stx/libbasic/QuerySignal.st,v 1.7 1996-04-22 11:45:15 cg Exp $'
691
55730898da50 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 580
diff changeset
   122
! !