1 # ui-apps.tcl --
2 #
3 # UserApplication is a base class used for deciding what programs may be
4 # launched from the Nsdr session directory tool.
5 #
6 # Copyright (c) 1997-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
33 # UserApplication is a base class used for deciding what programs
34 # may be launched from the Nsdr session directory tool. It's
35 # purpose it similar to that of Sdr plugins, but is much more
36 # general at the cost of added complexity.<p>
37 #
38 # For every class that is derived from UserApplication, one object
39 # is instantiated. Then, for every program that is received, the
40 # <i>match</i> method is invoked on each message in turn. This
41 # method should return a list of commands (suitable for passing to
42 # the tcl <i>exec</i> procedure) that might be run for this program.
43 # Typical applications will return a list with 0 or 1 elements
44 # (e.g., a class to match a video tool would return a single command
45 # for a session with a video stream and nothing for a session
46 # without a video stream). Lists are used for tools that might be
47 # run multiple times (with different arguments) on a single stream
48 # (e.g., a media independent recording tool or monitoring tool).<p>
49 #
50 # Simple defaults for various mash tools are in the file
51 # <a href=tcl/nsdr/user-apps.tcl.html>tcl/nsdr/user-apps.tcl</a>.
52 # Individual users can define new applications without modifying
53 # nsdr by putting them in a file ~/.nsdr/apps.tcl or some other
54 # file indicated with the -a command line argument to nsdr.
55 #
56 # The UserApplication class is also queried when a new session is
57 # created to determine various options that should be offered
58 # (e.g., valid media types, formats, etc...). When building a
59 # UserApplication subclass, you should also add calls to the
60 # <i>register_media</i>, <i>register_formats</i>,
61 # <i>register_protos</i>, and <i>register_attrs</i> methods so
62 # that appropriate options will be available for new sessions.
63 # See below for further documentation on these methods.
64 Class UserApplication
65
66 # Called at startup, instantiates one object of each class derived
67 # from the UserApplication base class.
68 UserApplication proc init_apps {} {
69 # source app files
70 set files [concat [$self get_option appFiles] \
71 [$self get_option extraAppFiles]]
72 foreach f $files {
73 catch {source $f}
74 }
75
76 $self set instances_ {}
77 foreach a [$self info subclass] {
78 new $a
79 }
80 }
81
82 #
83 UserApplication public init {} {
84 $class instvar instances_
85 lappend instances_ $self
86
87 #FIXME
88 UserApplication set mega_rport_ 10004
89 }
90
91 # Invokes the <i>match</i> method on every object that was created,
92 # collects and returns a list of all possible commands that are
93 # generated.
94 UserApplication proc get_apps {prog} {
95 set apps {}
96 foreach app [$self set instances_] {
97 if [catch {set cmds [$app match $prog]} m] {
98 puts stderr "warning: app match failed for [$app info class]: $m"
99 continue
100 }
101 set apps [concat $apps $cmds]
102 }
103 return $apps
104 }
105
106 # Overridden in every derived class to return a short name for the
107 # application that is being matched.
108 UserApplication private name {} {
109 $self warn "in UserApplication::name"
110 return "unknown app"
111 }
112
113 # See the description of the UserApplication class above. Should
114 # be overridden in every derived class.
115 UserApplication private match {prog} {
116 $self warn "in UserApplication::match"
117 return ""
118 }
119
120
121 UserApplication set media_ {}
122
123 # Make the media type <i>m</i> available as an option when creating
124 # new sessions.
125 UserApplication proc register_media {m} {
126 $self instvar media_
127 if {[lsearch -exact $media_ $m] == -1} {
128 lappend media_ $m
129 }
130 }
131
132 # Returns a list of all media types that have been registered.
133 UserApplication proc media {} {
134 $self instvar media_
135 return $media_
136 }
137
138 # Make all the arguments following <i>media</i> available as
139 # potential formats for streams of type <i>media</i> when
140 # creating new sessions.
141 UserApplication proc register_formats {media args} {
142 $self instvar formats_
143
144 if ![info exists formats_($media)] {
145 set formats_($media) {}
146 }
147
148 foreach fmt $args {
149 if {[lsearch -exact $formats_($media) $fmt ] == -1} {
150 lappend formats_($media) $fmt
151 }
152 }
153 }
154
155 # Returns a list of all formats registered for media type <i>media</i>.
156 UserApplication proc formats {media} {
157 $self instvar formats_
158 if ![info exists formats_($media)] { return "" }
159 return $formats_($media)
160 }
161
162 #
163 UserApplication proc register_protos {media args} {
164 $self instvar protos_
165 if ![info exists protos_($media)] {
166 set protos_($media) {}
167 }
168
169 foreach proto $args {
170 if {[lsearch -exact $protos_($media) $proto] == -1} {
171 lappend protos_($media) $proto
172 }
173 }
174 }
175
176 UserApplication proc protos {media} {
177 $self instvar protos_
178 if ![info exists protos_($media)] { return "" }
179 return $protos_($media)
180 }
181
182 # All arguments following <i>media</i> are potential attributes
183 # that may be set on streams of type <i>media</i>. Each
184 # attribute should be a list consisting of the attribute name
185 # and the default value (e.g., {scuba 1000}).
186 UserApplication proc register_attrs {media args} {
187 #FIXME could make this arbitrarily complex. what is correct?
188 $self instvar attrs_
189 if ![info exists attrs_($media)] {
190 set attrs_($media) {}
191 }
192
193 foreach attr $args {
194 if {[lsearch -exact $attrs_($media) $attr ] == -1} {
195 lappend attrs_($media) $attr
196 }
197 }
198 }
199
200 # Returns a list of all attributes registered for media type <i>media</i>
201 UserApplication proc attrs {media} {
202 $self instvar attrs_
203 if ![info exists attrs_($media)] { return "" }
204 return $attrs_($media)
205 }
206
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.