# ---------------------------------------------------------------------- # TEST HARNESS for the P2P infrastructure # # This script drives the test setup and visualization for the P2P # infrastructure. It launches the authority server(s) and various # workers, and helps to visualize their interactions. # ---------------------------------------------------------------------- # Michael McLennan (mmclennan@purdue.edu) # ====================================================================== # Copyright (c) 2004-2012 HUBzero Foundation, LLC # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ====================================================================== package require Itcl # recognize other library files in this same directory set dir [file dirname [info script]] lappend auto_path $dir set time0 [clock seconds] set processes "" set nodes(all) "" set nodeRadius 15 option add *highlightBackground [. cget -background] option add *client*background gray option add *client*highlightBackground gray option add *client*troughColor darkGray # ====================================================================== # SHAPES # ====================================================================== itcl::class Shape { private variable _canvas "" ;# shape sits on this canvas private variable _ranges "" ;# list of time ranges for shape private common _shapesOnCanvas ;# maps canvas => list of shapes public variable command "" ;# command template used to create shape constructor {canvas args} { # add this shape to the list of shapes on this canvas lappend _shapesOnCanvas($canvas) $this set _canvas $canvas eval configure $args } destructor { # remove this shape from the list of shapes on the canvas set i [lsearch $_shapesOnCanvas($_canvas) $this] if {$i >= 0} { set _shapesOnCanvas($_canvas) \ [lreplace $_shapesOnCanvas($_canvas) $i $i] } } # ------------------------------------------------------------------ # METHOD: addRange # Declares that this shape exists during the given time range # between and . # ------------------------------------------------------------------ public method addRange {t0 t1} { # see if there's any overlap with existing ranges set ri0 -1 set ri1 -1 for {set i 0} {$i < [llength $_ranges]} {incr i} { set pair [lindex $_ranges $i] foreach {r0 r1} $pair break if {$r0 >= $t0 && $r0 <= $t1} { set ri0 $i } if {$r1 >= $t0 && $r1 <= $t1} { set ri1 $i } incr i } if {$ri0 < 0 && $ri1 < 1} { # doesn't overlap with anything -- insert in right place for {set i 0} {$i < [llength $_ranges]} {incr i} { set pair [lindex $_ranges $i] foreach {r0 r1} $pair break if {$t0 < $r0} break } set _ranges [linsert $_ranges $i [list $t0 $t1]] } elseif {$ri0 >= 0 && $ri1 >= 0} { # overlaps on both limits -- bridge the middle part set r0 [lindex [lindex $_ranges $ri0] 0] set r1 [lindex [lindex $_ranges $ri1] 1] set _ranges [lreplace $_ranges $ri0 $ri1 [list $r0 $r1]] } elseif {$ri0 >= 0} { # overlaps on the lower limit for {set i [expr {[llength $_ranges]-1}]} {$i >= 0} {incr i -1} { set pair [lindex $_ranges $i] foreach {r0 r1} $pair break if {$r0 > $t0 && $r1 < $t1} { # remove any ranges completely contained in this one set _ranges [lreplace $_ranges $i $i] } set _ranges [lreplace $_ranges $ri0 $ri1 [list $r0 $r1]] } set pair [lindex $_ranges $ri0] foreach {r0 r1} $pair break set _ranges [lreplace $_ranges $ri0 $ri0 [list $r0 $t1]] } else { # overlaps on the upper limit for {set i [expr {[llength $_ranges]-1}]} {$i >= 0} {incr i -1} { set pair [lindex $_ranges $i] foreach {r0 r1} $pair break if {$r0 > $t0 && $r1 < $t1} { # remove any ranges completely contained in this one set _ranges [lreplace $_ranges $i $i] } set _ranges [lreplace $_ranges $ri0 $ri1 [list $r0 $r1]] } set pair [lindex $_ranges $ri1] foreach {r0 r1} $pair break set _ranges [lreplace $_ranges $ri1 $ri1 [list $t0 $r1]] } } # ------------------------------------------------------------------ # METHOD: exists