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

Open Mash Cross Reference
mash/tcl/applications/powerswitch-client/powersw-cl.tcl

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

  1 # powersw-cl.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/powerswitch-client/powersw-cl.tcl,v 1.9 2002/02/03 04:22:18 lim Exp $
 32 
 33 
 34 #
 35 # UI for talking to an PowerSwitchServer
 36 #
 37 Class PowerSwitchUI
 38 import CheckButton
 39 
 40 #
 41 # init method takes window and and address specificationx
 42 #
 43 PowerSwitchUI public init {w addrspec} {
 44 
 45     $self instvar al_ status_
 46 
 47     set status_(0) unknown
 48     set status_(1) unknown
 49 
 50     # if addrspec includes a name, turn it into IP addr
 51     set firstchar [string index $addrspec 0]
 52     if [string match \[a-zA-Z\] $firstchar] {
 53         set n [lindex [split $addrspec "/"] 0]
 54         set p [lindex [split $addrspec "/"] 1]
 55         set s [gethostbyname $n]
 56         if { $s == "" } {
 57             puts "cannot find address for '$n'"
 58             exit
 59         }
 60         set addrspec $s/$p
 61     }
 62 
 63     set al_ [new ALM/PowerSw/Client $addrspec $self]
 64 
 65     $self build_gui $w
 66     update
 67     # force an update
 68     $al_ announce refresh_settings
 69     update
 70     $self refresh_ui
 71 }
 72 
 73 #
 74 # destructor method
 75 #
 76 PowerSwitchUI public destroy {} {
 77     $self instvar al_
 78     delete $al_
 79     eval [list $self] next
 80 }
 81 
 82 PowerSwitchUI public print_status {} {
 83     $self instvar status_
 84 
 85     puts "0: $status_(0)"
 86     puts "1: $status_(1)"
 87     puts ""
 88 }
 89 
 90 PowerSwitchUI private build_gui {w} {
 91     $self instvar al_ status_ w_ btns_
 92 
 93     set w_ $w
 94     # build bottom informational label
 95     set il $w.infolabel
 96     frame $il -relief groove
 97     label $il.l -text "Power Ctrl"
 98     pack $il -side bottom -fill x -expand 1
 99     pack $il.l -in $il -side bottom
100 
101     set btns_(0) [new CheckButton $w.0 \
102             -command "$self invoke_button 0" -text "ON-AIR sign"]
103     set btns_(1) [new CheckButton $w.1 \
104             -command "$self invoke_button 1" -text "lamp"]
105     pack $w.0 $w.1 -side top
106 
107     bind . <q> exit
108 }
109 
110 
111 PowerSwitchUI private invoke_button {num} {
112 
113     $self instvar status_ al_ btns_
114 
115     if {[$btns_($num) get_val] == 0} {
116         $al_ announce "set_power $num off"
117     } else {
118         $al_ announce "set_power $num on"
119     }
120 }
121 
122 PowerSwitchUI private refresh_ui {} {
123     $self instvar status_ w_
124 
125     foreach i {0 1} {
126         if {$status_($i) == "on"} {
127             $w_.$i select
128         } else {
129             $w_.$i deselect
130         }
131     }
132 }
133 
134 
135 #--------------------------------------------------
136 
137 
138 import AnnounceListenManager
139 
140 #
141 # PowerSwitch interface
142 #
143 Class ALM/PowerSw/Client -superclass AnnounceListenManager
144 
145 
146 ALM/PowerSw/Client public init {addrspec parent {mtu 1500}} {
147     eval [list $self] next $addrspec $mtu
148 
149     $self instvar parent_
150     set parent_ $parent
151     $self ttl 16
152 }
153 
154 #
155 # receive (only) state updates of the form
156 # "0 <on|off|unknown> 1 <on|off|unknown>" ...
157 #
158 ALM/PowerSw/Client private recv_announcement {addr port data size} {
159     #puts "Msg: $addr/$port\[$size\]: $data"
160     $self instvar parent_
161 
162     # filter other client's msgs
163     switch [lindex $data 0] {
164         "set_power" {return}
165         "refresh_settings" {return}
166     }
167 
168     $parent_ array set status_ $data
169     $parent_ refresh_ui
170 }
171 
172 

~ [ 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.