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

Open Mash Cross Reference
mash/tcl/indiva/lib/ascp-service.tcl

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

  1 # ascp-service.tcl --

  2 #

  3 #       Service side of ASCP protocol.

  4 #

  5 # Copyright (c) 1998-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/indiva/lib/ascp-service.tcl,v 1.2 2002/07/11 19:32:55 weitsang Exp $

 32 
 33 import ASCP
 34 import MashTimer
 35 import MashSoftState
 36 
 37 Class ASCP/Service -superclass ASCP
 38 
 39 ASCP/Service instproc init { spec bw srv_inst } {
 40     $self next $spec $bw
 41     $self set srv_inst_ $srv_inst
 42 
 43     $self instvar client_
 44     $self announce_alive
 45     new MashTimer/ConstBW 2000 "$self announce_alive" $bw
 46     set client_ [new MashSoftState/Adaptive 1 16000 "$self exit" 8]
 47 
 48     $self set on_exit_callback_ ""
 49 }
 50 
 51 ASCP/Service instproc agent_type {} {
 52     return "s"
 53 }
 54 
 55 ASCP/Service instproc process_packet { addr packet } {
 56 
 57     $self instvar agent_ srv_inst_ client_
 58 
 59     # Ignore packets that are not for us.

 60     if { [$packet service_instance] != $srv_inst_ } {
 61         #delete $packet

 62         return
 63     }
 64 
 65     if { [$packet agent_type] == "c" } {
 66         switch -exact -- [$packet operation] {
 67             alive {
 68                 $self announce_alive
 69                 $client_ refresh
 70             }
 71             bye {
 72                 # client say bye bye.  

 73                 # We should not exit here, because there may be more than 1 client

 74                 # using our service.

 75             }
 76         }
 77     } else {
 78         # Duplicate server announcement.

 79         if { [string compare [$packet agent_id] [$self agent_id]] < 0 } {
 80             $self exit
 81         }
 82     }
 83     #delete $packet

 84 }
 85 
 86 
 87 ASCP/Service instproc announce_alive { } {
 88     set packet [new ASCPPacket]
 89     $packet agent_type [$self agent_type]
 90     $packet agent_id [$self agent_id]
 91     $packet service_instance [$self service_instance]
 92     $packet args [$self args]
 93     $packet operation "alive"
 94 
 95     $self announce [$packet to_string]
 96     delete $packet
 97 }
 98 
 99 
100 # 

101 # Callback when we failed to receive alive message from a client.

102 #

103 ASCP/Service instproc on_exit {callback} {
104     $self instvar on_exit_callback_
105     lappend on_exit_callback_ $callback
106 }
107 
108 
109 ASCP/Service instproc exit {} {
110     $self bye
111     $self instvar on_exit_callback_
112     foreach cb $on_exit_callback_ {
113         eval $cb
114     }
115     exit 0
116 }
117 
118 ASCP/Service instproc service_instance {} {
119     $self instvar srv_inst_
120     return $srv_inst_
121 }
122 
123 ASCP/Service instproc agent_id {} {
124     global argv0
125     return "[lindex [file split $argv0] end]:[pid]:${self}@[info hostname]:[$self control_port]"
126 }
127 
128 # vim:ts=8:sw=4:expandtab

129 

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