From 966645e8ff4976c14f779967399a8bbd95696d7c Mon Sep 17 00:00:00 2001 From: "ahrenholz@gmail.com" Date: Wed, 18 Dec 2013 18:10:19 +0000 Subject: [PATCH] added --(a)ddress and --(p)ort arguments to core-gui command-line added save/close buttons to plugins dialog updated man page/documentation with new arguments (Boeing r1816) --- trunk/doc/man/core-gui.1 | 8 +++- trunk/doc/usage.rst | 7 ++++ trunk/gui/core-gui.in | 24 ++++++++--- trunk/gui/core.tcl | 86 ++-------------------------------------- trunk/gui/filemgmt.tcl | 3 +- trunk/gui/plugins.tcl | 40 ++++++++++++++++++- 6 files changed, 74 insertions(+), 94 deletions(-) diff --git a/trunk/doc/man/core-gui.1 b/trunk/doc/man/core-gui.1 index cac6c95f..33765a2e 100644 --- a/trunk/doc/man/core-gui.1 +++ b/trunk/doc/man/core-gui.1 @@ -4,7 +4,7 @@ core-gui \- Common Open Research Emulator (CORE) graphical user interface .SH SYNOPSIS .B core-gui -[\fI-h|-v\fR] [\fI-b|-c \fR] [\fI-s\fR] [\fI\fR] +[\fI-h|-v\fR] [\fI-b|-c \fR] [\fI-s\fR] [\fI-a address\fR] [\fI-p port\fR] [\fI\fR] .SH DESCRIPTION Launches the CORE Tcl/Tk X11 GUI or starts an imn\-based emulation. .TP @@ -23,6 +23,12 @@ stop and clean up a batch mode session \-(\fB\-s\fR)tart start in execute mode, not edit mode .TP +\-(\fB\-a\fR)ddress +connect to the specified IP address (default 127.0.0.1) +.TP +\-(\fB\-p\fR)ort +connect to the specified TCP port (default 4038) +.TP (optional) load the specified imn scenario file .PP diff --git a/trunk/doc/usage.rst b/trunk/doc/usage.rst index cb798efc..a3456b80 100644 --- a/trunk/doc/usage.rst +++ b/trunk/doc/usage.rst @@ -88,6 +88,13 @@ The session number is printed in the terminal when batch mode is started. This s The GUI can be run as a normal user on Linux. For FreeBSD, the GUI should be run as root in order to start an emulation. +.. index:: port number + +The GUI can be connected to a different address or TCP port using +the ``--address`` and/or ``--port`` options. The defaults are shown below. +:: + core-gui --address 127.0.0.1 --port 4038 + .. _Toolbar: Toolbar diff --git a/trunk/gui/core-gui.in b/trunk/gui/core-gui.in index 714994fe..2c42c186 100755 --- a/trunk/gui/core-gui.in +++ b/trunk/gui/core-gui.in @@ -34,16 +34,19 @@ case $1 in -h | --help) echo "" - echo "Usage: `basename $0` [-h|-v] [-b|-c ] [-s] []" + echo "Usage: `basename $0` [-h|-v] [-b|-c ] [-s] [-a address] [-p port]" + echo " []" echo "" echo "Launches the CORE Tcl/Tk X11 GUI or starts an imn-based emulation." echo "" - echo " -(-h)elp show help message and exit" + echo " -(-h)elp show help message and exit" echo " -(-v)ersion show version number and exit" - echo " -(-b)atch batch mode (no X11 GUI)" + echo " -(-b)atch batch mode (no X11 GUI)" echo -n " -(-c)losebatch stop and clean up a batch mode " echo "session " - echo " -(-s)tart start in execute mode, not edit mode" + echo " -(-s)tart start in execute mode, not edit mode" + echo " -(-a)ddress connect to the specified IP address (default 127.0.0.1)" + echo " -(-p)port connect to the specified TCP port (default 4038)" echo " (optional) load the specified imn scenario file" echo "" echo "With no parameters, starts the GUI in edit mode with a blank canvas." @@ -154,10 +157,19 @@ case $1 in exec ${TCLBIN} $core "$@" ;; -s) - exec ${WISH} $core "--start $@" + shift + exec ${WISH} $core -- "--start" "$@" + ;; +-a) + shift + exec ${WISH} $core -- "--address" "$@" + ;; +-p) + shift + exec ${WISH} $core -- "--port" "$@" ;; *) - exec ${WISH} $core $@ + exec ${WISH} $core -- $@ ;; esac diff --git a/trunk/gui/core.tcl b/trunk/gui/core.tcl index d5110a78..c1407d69 100755 --- a/trunk/gui/core.tcl +++ b/trunk/gui/core.tcl @@ -31,49 +31,19 @@ # and Technology through the research contract #IP-2003-143. # -#****h* imunes/imunes.tcl -# NAME -# imunes.tcl -# FUNCTION -# Starts imunes in batch or interactive mode. Include procedures from -# external files and initializes global variables. -# -# imunes [-b|--batch] [filename] -# -# When starting the program in batch mode the option -b or --batch must -# be specified. -# -# When starting the program with defined filename, configuration for -# file "filename" is loaded to imunes. -#**** - if {[lindex $argv 0] == "-b" || [lindex $argv 0] == "--batch"} { set argv [lrange $argv 1 end] set execMode batch } elseif {[lindex $argv 0] == "-c" || [lindex $argv 0] == "--closebatch"} { set argv [lrange $argv 1 end] set execMode closebatch -} elseif {[lindex $argv 0] == "-a" || [lindex $argv 0] == "--addons"} { +} elseif {[lindex $argv 0] == "--addons"} { set argv [lrange $argv 1 end] set execMode addons } else { set execMode interactive } -# -# Include procedure definitions from external files. There must be -# some better way to accomplish the same goal, but that's how we do it -# for the moment. -# - -#****v* imunes.tcl/LIBDIR -# NAME -# LIBDIR -# FUNCTION -# The location of imunes library files. The LIBDIR variable -# will be automatically set to the proper value by the installation script. -#***** - set LIBDIR "" set SBINDIR "/usr/local/sbin" set CONFDIR "." @@ -136,61 +106,12 @@ source "$LIBDIR/exceptions.tcl" # # Global variables are initialized here # - -#****v* imunes.tcl/node_list -# NAME -# node_list -# FUNCTION -# Represents the list of all the nodes in the simulation. When starting -# the program this list is empty. -#***** - -#****v* imunes.tcl/link_list -# NAME -# link_list -# FUNCTION -# Represents the list of all the links in the simulation. When starting -# the program this list is empty. -#***** - -#****v* imunes.tcl/canvas_list -# NAME -# canvas_list -# FUNCTION -# Contains the list of all the canvases in the simulation. When starting -# the program this list is empty. -#***** - -#****v* imunes.tcl/prefs -# NAME -# prefs -# FUNCTION -# Contains the list of preferences. When starting a program -# this list is empty. -#***** - -#****v* imunes.tcl/eid -# NAME -# eid -- experiment id. -# FUNCTION -# The id of the current experiment. When starting a program this variable -# is set to e0. -#***** - set node_list {} set link_list {} set annotation_list {} set canvas_list {} set eid e0 set plot_list {} - -#****v* core.tcl/exec_servers -# NAME -# exec_servers -- array of CORE remote execution servers -# FUNCTION -#***** - -# IP port monitor_port active ssh username array set exec_servers {} loadServersConf ;# populate exec_servers @@ -202,6 +123,7 @@ set g_mrulist {} initDefaultPrefs loadDotFile loadPluginsConf +checkCommandLineAddressPort autoConnectPlugins @@ -225,12 +147,10 @@ if {$execMode == "interactive"} { puts " $e" } } - # end Boeing setOperMode edit fileOpenStartUp - # Boeing --start option foreach arg $argv { - if { $arg == "--start -s" || $arg == "--start" } { + if { $arg == "--start" } { global currentFile if { [file extension $currentFile] == ".xml" } { after 100; update; # yield to other events so XML file diff --git a/trunk/gui/filemgmt.tcl b/trunk/gui/filemgmt.tcl index 098930f3..75a3e30c 100755 --- a/trunk/gui/filemgmt.tcl +++ b/trunk/gui/filemgmt.tcl @@ -261,8 +261,7 @@ proc fileOpenStartUp {} { # Boeing foreach arg $argv { - if { $arg != "" && $arg != "--start -s" && $arg != "--start" && \ - $arg != "--batch -b" && $arg != "--batch" } { + if { $arg != "" && $arg != "--start" && $arg != "--batch" } { set currentFile [argAbsPathname $arg] openFile break diff --git a/trunk/gui/plugins.tcl b/trunk/gui/plugins.tcl index eafe9ed6..d2e205b2 100644 --- a/trunk/gui/plugins.tcl +++ b/trunk/gui/plugins.tcl @@ -120,8 +120,9 @@ proc popupPluginsConfig {} { # close button frame $wi.b -borderwidth 0 - button $wi.b.cancel -text "Close" -command "writePluginsConf; destroy $wi" - pack $wi.b.cancel -side right + button $wi.b.save -text "Save" -command "writePluginsConf; destroy $wi" + button $wi.b.cancel -text "Cancel" -command "destroy $wi" + pack $wi.b.cancel $wi.b.save -side right pack $wi.b -side bottom # uncomment to make modal @@ -1230,6 +1231,7 @@ proc pluginConnect { name cmd retry } { # connect, disconnect, or do nothing if { $cmd == "connect" && $snum != 1} { puts -nonewline "Connecting to $name ($ip:$port)..." + flush stdout set sock [openAPIChannel $ip $port $retry] if { "$sock" <= -1 } { return -1 };# user pressed cancel set snum 1 ;# status connected @@ -1561,3 +1563,37 @@ proc listToKeyValues { keyvalues } { return $r } +# parse command-line parameters for address/port to connect with +proc checkCommandLineAddressPort {} { + global argv g_plugins + set addr ""; set port "" + set addri [lsearch -regexp $argv "(^\[-\]\[-\]address$|^\[-\]a$)"] + #set addri [lsearch -exact $argv "--address"] + if { $addri > -1 } { + set argv [lreplace $argv $addri $addri] + set addr [lindex $argv $addri] + if { ![checkIPv4Addr $addr] } { + puts "error: invalid address '$addr'"; exit; + } + set argv [lreplace $argv $addri $addri] + } + + #set porti [lsearch -exact $argv "--port"] + set porti [lsearch -regexp $argv "(^\[-\]\[-\]port$|^\[-\]p$)"] + if { $porti > -1 } { + set argv [lreplace $argv $porti $porti] + set port [lindex $argv $porti] + if { $port == "" || ![string is integer $port] || $port > 65535 } { + puts "error: invalid port '$port'"; exit; + } + set argv [lreplace $argv $porti $porti] + } + # update the auto-connect plugin (core-daemon entry) + if { $addri > -1 || $porti > -1 } { + set key [lindex [getEmulPlugin "*"] 0] + set plugin_data $g_plugins($key) + if { $addri > -1 } { set plugin_data [lreplace $plugin_data 0 0 $addr] } + if { $porti > -1 } { set plugin_data [lreplace $plugin_data 1 1 $port] } + array set g_plugins [list $key $plugin_data] + } +}