1 # ui-switcher.tcl --
2 #
3 # This module handles the video switcher abstraction, a virtual base
4 # class for switching among media flows (sources).
5 #
6 # Copyright (c) 1993-2002 The Regents of the University of California.
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are met:
11 #
12 # A. Redistributions of source code must retain the above copyright notice,
13 # this list of conditions and the following disclaimer.
14 # B. Redistributions in binary form must reproduce the above copyright notice,
15 # this list of conditions and the following disclaimer in the documentation
16 # and/or other materials provided with the distribution.
17 # C. Neither the names of the copyright holders nor the names of its
18 # contributors may be used to endorse or promote products derived from this
19 # software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
25 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #
32 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/vic/ui-switcher.tcl,v 1.16 2002/02/28 03:34:04 chema Exp $
33
34
35 import Configuration
36
37 #
38 # This module handles the video switcher abstraction, a virtual base
39 # class for switching among media flows (sources). Generic objects are
40 # registered as switchable with a method to call back when switching
41 # occurs. By using a generic callback mechanism, this code is shared
42 # between the on screen windows and external video outputs.
43 # <p>
44 #
45 # Subclasses must fill in the following methods: <br>
46 # <dd> switch
47 # <dd> prev_active_src
48 # <dd> next_active_src
49 #
50 Class Switcher -configuration {
51 switchInterval 5
52 }
53
54 #
55 # Create a Switcher for the source, <i>src</i>.
56 #
57 Switcher instproc init src {
58 $self next
59 $self instvar src_ switch_list_
60 set src_ $src
61 Switcher set all_($self) 1
62 }
63
64 #
65 Switcher instproc destroy {} {
66 $self cancel_timer
67 Switcher unset all_($self)
68 $self next
69 }
70
71 #
72 # Enable switching.
73 #
74 Switcher instproc enable {} {
75 $self touch
76 }
77
78 #
79 # Returns true if this Switcher is switching. For example, a UserWindow
80 # is "enabled" if it is timer-switched or voice-switched.
81 #
82 Switcher instproc enabled {} {
83 $self instvar ts_
84 return [info exists ts_]
85 }
86
87 #
88 # Disable switching.
89 #
90 Switcher instproc disable {} {
91 $self instvar ts_
92 unset ts_
93 }
94
95 #
96 # Start the timer-base cycling of sources. Continue to switch to the
97 # next active source every <i>switchInterval</i> seconds, (an option in
98 # the resource database), until we <i>cancel_timer</i>.
99 #
100 Switcher public set_timer {} {
101 $self sched
102 }
103
104 #
105 # Cancel the timer-base cycling of sources.
106 #
107 Switcher instproc cancel_timer {} {
108 $self instvar timer_id_
109 if [info exists timer_id_] {
110 after cancel $timer_id_
111 unset timer_id_
112 }
113 }
114
115 #
116 # If the source, <i>src</i>, is selected in the switchable list, switch to it.
117 #
118 Switcher instproc switch_to src {
119 $self instvar src_ switch_list_
120 if { $src != $src_ && [lsearch $switch_list_ $src] != -1 } {
121 $self switch $src
122 set src_ $src
123 }
124 }
125
126 #
127 # Switch to the next active source.
128 #
129 Switcher instproc forward {} {
130 $self instvar src_
131 $self switch_to [$self next_active_src $src_]
132 }
133
134 #
135 # Switch to the previous active source.
136 #
137 Switcher instproc reverse {} {
138 $self instvar src_
139 $self switch_to [$self prev_active_src $src_]
140 }
141
142 Switcher set clock_ 1
143
144 #
145 # No longer used... <br>
146 # Increment the clock_ (essentially an ordering stamp) for use by the LRU algorithm.
147 #
148 Switcher instproc touch {} {
149 Switcher instvar clock_
150 $self instvar ts_
151 set ts_ $clock_
152 incr clock_
153 }
154
155 Switcher proc focus src {
156 Switcher instvar ignore_
157 if [info exists ignore_($src)] {
158 return
159 }
160
161 Switcher instvar all_ speaker_
162
163 #
164 # Remember the current speaker
165 #
166 set speaker_ $src
167
168 #
169 # This new version is not doing the LRU mechanism.
170 # Instead, find all switcher windows that are enabled and
171 # contains src in its switchable list, then switch all of them
172 #
173 foreach o [array names all_] {
174 if { [$o enabled] &&
175 [lsearch [$o set switch_list_] $src] != -1 } {
176 $o switch_to $src
177 }
178 }
179 }
180
181 #
182 # After <i>switchInterval</i> seconds, (an option in the resource database), expire the timer.
183 #
184 Switcher private sched {} {
185 $self instvar timer_id_
186 set ms [expr 1000 * [$self get_option switchInterval]]
187 set timer_id_ [after $ms "$self timeout"]
188 }
189
190 #
191 # When the timer expires, switch to the next active source and reset the timer.
192 #
193 Switcher private timeout {} {
194 $self instvar timer_id_
195 if [info exists timer_id_] {
196 $self forward
197 $self sched
198 }
199 }
200
201 #
202 # Rebuild the switchable menu for all existing switcher
203 # windows.
204 #
205 Switcher proc rebuild_switch_list_menu { } {
206 Switcher instvar all_
207 foreach o [array names all_] {
208 $o rebuild_switch_list_menu
209 }
210 }
211
212
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.