1 # mob-edge.tcl --
2 #
3 # Implementation of an edge in a Mob Graph.
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/indiva/imgr/mob-edge.tcl,v 1.8 2002/07/04 18:39:16 weitsang Exp $
32
33 #-----------------------------------------------------------------------------
34 # Class:
35 # MobEdge
36 # Description:
37 # This represents an edge in the environment graph.
38 # Members:
39 # src -- the mob object where this edge is coming from.
40 # dest -- the mob object where this edge is going to.
41 # action -- the action associated with this mob. This should be a string
42 # that tells imgr which IMgrAction object should be used to send a flow
43 # from $src to $dest. For example, if "action" == "capture", then
44 # IMgrAction/Capture class will be used.
45 # cost -- the cost of going from $src to $dest. We assume cost is either
46 # 0, 1, or "very large" at the moment. A better cost model should
47 # be used.
48 #-----------------------------------------------------------------------------
49
50 Class MobEdge
51
52 #-----------------------------------------------------------------------------
53 # Method:
54 # MobEdge init
55 # Description:
56 # Initialized various members. Cost is initialized to 1.
57 #-----------------------------------------------------------------------------
58 MobEdge instproc init { src dest {action "none"}} {
59 $self instvar cost_ used_ action_ src_ dest_
60 set cost_ 1
61 set used_ 0
62 set action_ $action
63 set src_ $src
64 set dest_ $dest
65 }
66
67
68 #-----------------------------------------------------------------------------
69 # Method:
70 # MobEdge cost
71 # MobEdge action
72 # Description:
73 # Get or set the cost/action of this edge.
74 #-----------------------------------------------------------------------------
75 MobEdge instproc cost { args } {
76 $self instvar cost_
77 if {$args == ""} {
78 return $cost_
79 } else {
80 set cost_ $args
81 }
82 }
83
84 MobEdge instproc action {args} {
85 $self instvar action_
86 if {$args == ""} {
87 return $action_
88 } else {
89 set action_ $args
90 }
91 }
92
93
94 #-----------------------------------------------------------------------------
95 # Method:
96 # MobEdge busy
97 # MobEdge free
98 # Description:
99 # Mark this edge as busy or free, based on the type of the adjacent nodes.
100 # If $src is not share-readable, or $dest is not share-writable, then this
101 # edge is marked as busy, and cost_ is set to a large number. Otherwise,
102 # we set cost_ to 0 to promote sharing, and this edge is not marked as used.
103 #-----------------------------------------------------------------------------
104 MobEdge instproc busy { } {
105 $self instvar cost_ src_ dest_ used_
106 incr used_ 1
107 if {[$src_ share_readable] && [$dest_ share_writable]} {
108 set cost_ 0
109 } else {
110 set cost_ 99999
111 }
112 }
113
114
115 MobEdge instproc free { } {
116 $self instvar cost_ used_
117 incr used_ -1
118 if {$used_ == 0} {
119 set cost_ 1
120 }
121 }
122
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.