source: branches/uiuc_vtk_viewers/p2p/options.tcl @ 5285

Last change on this file since 5285 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 2.7 KB
Line 
1# ----------------------------------------------------------------------
2#  P2P: options
3#
4#  This code manages option settings within all of the programs in the
5#  peer to peer job management system.  Options are soft-coded
6#  parameters controlling things like how many peers each node should
7#  be connected to.
8# ----------------------------------------------------------------------
9#  Michael McLennan (mmclennan@purdue.edu)
10# ======================================================================
11#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
12#
13#  See the file "license.terms" for information on usage and
14#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15# ======================================================================
16package require Rappture
17
18namespace eval p2p {
19    variable options  ;# array of option settings for this program
20}
21
22# ======================================================================
23#  OPTIONS
24#  These options get the worker started, but new option settings
25#  some from the authority after this worker first connects.
26# ----------------------------------------------------------------------
27#  USAGE:  p2p::options register <name> <defaultValue>
28#  USAGE:  p2p::options set <name> <newValue>
29#  USAGE:  p2p::options get <name>
30#
31#  Use these commands to register and get/set various option settings
32#  used within these programs.  The option settings start with default
33#  values but can be overridden at any point, for example by the
34#  "authority" program.
35# ======================================================================
36proc p2p::options {op args} {
37    global options
38
39    switch -- $op {
40        register {
41            if {[llength $args] != 2} {
42                error "wrong # args: should be \"p2p::options register name default\""
43            }
44            set opt [lindex $args 0]
45            set def [lindex $args 1]
46            if {[info exists options($opt)]} {
47                error "option \"$opt\" is already registered"
48            }
49            set options($opt) $def
50        }
51        get {
52            if {[llength $args] != 1} {
53                error "wrong # args: should be \"p2p::options get name\""
54            }
55            set opt [lindex $args 0]
56            if {![info exists options($opt)]} {
57                error "option \"$opt\" is not defined"
58            }
59            return $options($opt)
60        }
61        set {
62            if {[llength $args] != 2} {
63                error "wrong # args: should be \"p2p::options set name default\""
64            }
65            set opt [lindex $args 0]
66            set val [lindex $args 1]
67            if {![info exists options($opt)]} {
68                error "option \"$opt\" is not defined"
69            }
70            set options($opt) $val
71        }
72    }
73}
Note: See TracBrowser for help on using the repository browser.