~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/applications/avswitch-server/avswitch-srvr.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # avswitch-srvr.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1996-2002 The Regents of the University of California.
  6 # All rights reserved.
  7 #
  8 # Redistribution and use in source and binary forms, with or without
  9 # modification, are permitted provided that the following conditions are met:
 10 #
 11 # A. Redistributions of source code must retain the above copyright notice,
 12 #    this list of conditions and the following disclaimer.
 13 # B. Redistributions in binary form must reproduce the above copyright notice,
 14 #    this list of conditions and the following disclaimer in the documentation
 15 #    and/or other materials provided with the distribution.
 16 # C. Neither the names of the copyright holders nor the names of its
 17 #    contributors may be used to endorse or promote products derived from this
 18 #    software without specific prior written permission.
 19 #
 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30 #
 31 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/applications/avswitch-server/avswitch-srvr.tcl,v 1.13 2002/02/03 04:21:37 lim Exp $
 32 
 33 
 34 import SerialChannel/AVSwitch-Knox-RS8x8 UDPServer Rendezvous
 35 
 36 
 37 #
 38 # a UI-less server that accepts RPC-like commands and
 39 # returns results for controlling an avswitch
 40 #
 41 Class AVSwitchServer
 42 
 43 AVSwitchServer public init {addrspec} {
 44     $self instvar avswitch_ al_ prev_vs_ addrspec_
 45 
 46     set addrspec_ $addrspec
 47     set avswitch_ [new SerialChannel/AVSwitch-Knox-RS8x8 1024]
 48     set al_ [new UDPServer/AVSwitch $addrspec $self]
 49     set prev_vs_ ""
 50     set raddr [$self get_option rendez]
 51     if {$raddr != ""} {
 52         $self start_rendezvous_ads $raddr
 53     }
 54 }
 55 
 56 AVSwitchServer public destroy {} {
 57     $self instvar al_ avswitch_ advertiser_
 58 
 59     delete $al_
 60     delete $avswitch_
 61     if {$raddr != ""} {
 62         delete advertiser_
 63     }
 64     eval [list $self] next
 65 }
 66 
 67 AVSwitchServer public set_routes {args} {
 68     $self instvar avswitch_
 69 
 70     set args [lindex $args 0]   ; # this is necessary 'cause param is "args"
 71     #puts "args: $args"
 72 
 73     if {[llength $args] != 3} {
 74         puts "bad \# of args to set-routes"
 75         return
 76     }
 77     set cmd [lindex $args 0]
 78     set out [lindex $args 1]
 79     set in [lindex $args 2]
 80 
 81     if {$out > 8 || $out < 1 || $in > 8 || $in < 1} {
 82         puts "bad values to set-routes"
 83         return
 84     }
 85 
 86     eval $avswitch_ $args
 87 }
 88 
 89 
 90 #
 91 AVSwitchServer public get_video_settings {} {
 92     $self instvar avswitch_
 93     return [$avswitch_ array get videoSettings_]
 94 }
 95 
 96 #
 97 AVSwitchServer public get_audio_settings {} {
 98     $self instvar avswitch_
 99     return [$avswitch_ array get audioSettings_]
100 }
101 
102 # start advertising mappings to rendezvous address `raddr'
103 AVSwitchServer public start_rendezvous_ads {raddr} {
104     $self instvar advertiser_ prev_vs_ addrspec_
105     array set voutlist "6 [gethostbyname diamond] 7 [gethostbyname heart] \
106             8 [gethostbyname club]"
107     array set vinlist "5 CoLab/cam1 6 CoLab/cam2 7 CoLab/cam3 8 CoLab/cam4"
108 
109     set vs [$self get_video_settings]
110     # if not parsed yet, try again later
111     if {[lsearch $vs 0] != -1} {
112         after 2000 "$self start_rendezvous_ads $raddr"
113         return
114     }
115     # check for a change in settings
116     if {$vs != $prev_vs_} {
117         set prev_vs_ $vs
118         if [info exists advertiser_] {delete $advertiser_}
119         set advertiser_ [new Rendezvous $raddr]
120         set msg ""
121         puts "advertising camera<->machine settings to $raddr"
122         foreach {vout vin} $vs {
123             if {$vin == 5 || $vin == 6 || $vin == 7 || $vin == 8} {
124                 if {$vout == 6 || $vout == 7 || $vout == 8} {
125                     append msg "camera: camName:$vinlist($vin)"
126                     append msg " videoIn:$voutlist($vout)\n"
127                 }
128             }
129         }
130         puts "$msg"
131         $advertiser_ start $msg
132 
133         set msg "will-provide: mash-object=AVSwitchServer ctrlspec=$addrspec_"
134         set uid [$self get_option uniqid]
135         if {$uid != ""} {set msg "$msg uniqid=$uid"}
136         $advertiser_ start $msg
137     }
138     after 5000 "$self start_rendezvous_ads $raddr"
139 }
140 
141 
142 #
143 #------------------------------------------------------------
144 #
145 
146 # AVSwitch RPC-style interface
147 #
148 Class UDPServer/AVSwitch -superclass UDPServer
149 
150 UDPServer/AVSwitch public init {addrspec parent} {
151     $self instvar parent_ pending_announce_
152     set parent_ $parent
153     set pending_announce_ -1
154 
155     eval [list $self] next $addrspec
156 }
157 
158 
159 UDPServer/AVSwitch private recv {addr port data size} {
160     puts "Msg: $addr\[$size\]: $data"
161 
162     $self instvar parent_ pending_announce_
163 
164     set theMethod [lindex $data 0]
165     switch $theMethod {
166         refresh_settings {[$parent_ set avswitch_] refresh_settings}
167         test_LEDs {[$parent_ set avswitch_] test_LEDs}
168         route_both -
169         route_audio -
170         route_video {$parent_ set_routes "$data"}
171     }
172     if {$pending_announce_ != -1} {
173         after cancel $pending_announce_
174     }
175     # have to wait for the update from the switch to be received & processed
176     set pending_announce_ [after 4000 $self announce_reply]
177 }
178 
179 UDPServer/AVSwitch private announce_reply {} {
180     $self instvar parent_ pending_announce_
181 
182     set av [$parent_ set avswitch_]
183     set v [$av array get videoSettings_]
184     set a [$av array get audioSettings_]
185     $self announce "v: $v ; a: $a"
186     after 10 $self announce [list "v: $v ; a: $a"]
187     after 40 $self announce [list "v: $v ; a: $a"]
188     set pending_announce_ -1
189 }
190 
191 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.