Changeset 171


Ignore:
Timestamp:
Feb 13, 2006 6:37:25 AM (18 years ago)
Author:
mmc
Message:
  • Moved Rappture::result and Rappture::exec to the tcl library and cleaned up the installation.
  • Fixed the filexfer applet so that it is more robust, and can disconnect and reconnect to the Rappture application.
  • Added bindings to the postern so that it is easier to find.
Location:
trunk
Files:
8 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/gui/Makefile.in

    r158 r171  
    184184
    185185libraries:
     186        cd filexfer; make all
    186187
    187188doc:
     
    277278
    278279clean: 
     280        cd filexfer; make clean
    279281        -test -z "$(BINARIES)" || rm -f $(BINARIES)
    280282        -rm -f *.o core *.core
     
    338340        $(INSTALL_DATA) pkgIndex.tcl $(DESTDIR)$(pkglibdir)/pkgIndex.tcl
    339341        $(INSTALL_DATA) init.tcl $(DESTDIR)$(pkglibdir)/init.tcl
     342        $(mkinstalldirs) $(pkglibdir)/filexfer
     343        @for i in $(srcdir)/filexfer/filexfer.jar \
     344              $(srcdir)/filexfer/*.class; do \
     345            echo "Installing $$i" ; \
     346            $(INSTALL_DATA) $$i $(DESTDIR)$(pkglibdir)/filexfer ; \
     347        done;
    340348
    341349#========================================================================
  • trunk/gui/filexfer/filexfer.java

    r115 r171  
    2323    public PrintStream ostream;
    2424    public TextArea status;
    25     public int port;
    2625
    27     private Socket socket;
    28     private monitor mon;
    29 
    30     private String user;
    31     private String cookie;
     26    private monitor mon = null;
    3227
    3328    public void init() {
     29        int port = 0;
    3430        String portstr = getParameter("port");
    3531        if (portstr == null) {
     
    3935        }
    4036
     37        String user = "";
    4138        user = getParameter("user");
    4239        if (user == null)
    4340            user = "???";
    4441
     42        String cookie = "";
    4543        cookie = getParameter("cookie");
    4644        if (cookie == null)
    4745            cookie = "<missing>";
    48 
    49         String mesg="OK";
    50         try {
    51             socket = new Socket(getCodeBase().getHost(), port);
    52             istream = new BufferedReader(
    53                 new InputStreamReader(socket.getInputStream())
    54             );
    55             ostream = new PrintStream(socket.getOutputStream());
    56         }
    57         catch (UnknownHostException e) { mesg="Unknown host"; }
    58         catch (Exception e) { mesg="Can't connect to server"; }
    5946
    6047        String ipAddr = "";
     
    6855            ipAddr = "???";
    6956        }
    70 
    71         try {
    72             ostream.println("REGISTER "+user+" "+ipAddr+" "+cookie+" RAPPTURE");
    73         }
    74         catch (Exception e) { mesg="Can't talk to server"; }
    7557
    7658        GridBagLayout gridbag = new GridBagLayout();
     
    8870        gridbag.setConstraints(status, cons);
    8971        add(status);
    90         status.setText(mesg);
    9172
    92         if (mesg == "OK") {
    93             mon = new monitor(this);
    94             mon.start();
    95         }
     73        mon = new monitor(this, getCodeBase().getHost(), port,
     74            user, ipAddr, cookie);
     75        mon.start();
    9676    }
    9777
    9878    public void destroy() {
    99         try {
    100             ostream.println("UNREGISTER RAPPTURE");
    101             socket.close();
    102         }
    103         catch (Exception e) {
    104             status.append("\nUNREGISTER notice failed");
    105         }
     79        mon.disconnect();
    10680    }
    10781
    10882    public void start() {
    109         try {
    110             ostream.println("ACTIVATE RAPPTURE");
    111         }
    112         catch (Exception e) {
    113             status.append("\nACTIVATE notice failed");
    114         }
     83        mon.activate();
    11584    }
    11685
    11786    public void stop() {
    118         try {
    119             ostream.println("DEACTIVATE RAPPTURE");
    120         }
    121         catch (Exception e) {
    122             status.append("\nDEACTIVATE notice failed");
    123         }
     87        mon.deactivate();
    12488    }
    12589}
  • trunk/gui/filexfer/monitor.java

    r115 r171  
    2020public class monitor extends Thread {
    2121    private filexfer parent;
     22    private String hostName;
     23    private int hostPort;
     24    private String user;
     25    private String ipAddr;
     26    private String cookie;
    2227
    23     public monitor(filexfer parent) {
     28    private Socket socket = null;
     29    public BufferedReader istream;
     30    public PrintStream ostream;
     31
     32    private boolean run = true;
     33
     34    public monitor(filexfer parent, String hostName, int hostPort,
     35          String user, String ipAddr, String cookie) {
    2436        this.parent = parent;
     37        this.hostName = hostName;
     38        this.hostPort = hostPort;
     39        this.user = user;
     40        this.ipAddr = ipAddr;
     41        this.cookie = cookie;
    2542    }
    2643
    2744    public void run() {
    2845        String line = "";
    29         while (true) {
    30             try {
    31                 line = parent.istream.readLine();
    32                 if (line == null) {
    33                     parent.status.append("\nCLOSED");
    34                     stop();
     46        while (run) {
     47            if (socket == null) {
     48                if (!connect()) {
     49                    try {
     50                        // sleep a little, so we don't chew up CPU
     51                        sleep(5000);
     52                    }
     53                    catch (java.lang.InterruptedException e) {
     54                        // just move on
     55                    }
    3556                }
    36                 parent.status.append("\nread "+line);
    37 
    38                 if (line.startsWith("url ")) {
    39                     URL url = new URL("http",
    40                         parent.getCodeBase().getHost(),
    41                         parent.port, line.substring(4));
    42 
    43                     try {
    44                         parent.getAppletContext().showDocument(url,"_blank");
    45                         parent.status.append("\nlaunched "+url);
     57            } else {
     58                try {
     59                    line = istream.readLine();
     60                    if (line == null) {
     61                        parent.status.append("CLOSED\n");
     62                        socket.close();
     63                        socket = null;
     64                    } else {
     65                        handle(line);
    4666                    }
    47                     catch (Exception e) {
    48                         parent.status.append("\nBad URL "+url);
    49                     }
    50                 } else {
    51                     parent.status.append("huh? |"+line+"|");
    5267                }
    53             }
    54             catch (java.io.IOException e){
    55                 parent.status.append("\nI/O error: "+e.getMessage());
    56             }
    57             catch (Exception e) {
    58                 parent.status.append("\nInternal error: "+e.getMessage());
     68                catch (java.io.IOException e){
     69                    parent.status.append("I/O error: "+e.getMessage()+"\n");
     70                }
     71                catch (Exception e) {
     72                    parent.status.append("Internal error: "+e.getMessage()+"\n");
     73                }
    5974            }
    6075        }
    6176    }
     77
     78    public void disconnect() {
     79        if (socket != null) {
     80            try {
     81                ostream.println("UNREGISTER RAPPTURE");
     82            }
     83            catch (Exception e) {
     84                parent.status.append("UNREGISTER notice failed\n");
     85            }
     86            try {
     87                socket.close();
     88            }
     89            catch (Exception e) {
     90                parent.status.append("trouble closing socket\n");
     91            }
     92            socket = null;
     93        }
     94        run = false;
     95    }
     96
     97    public void activate() {
     98        if (socket != null) {
     99            try {
     100                ostream.println("ACTIVATE RAPPTURE");
     101            }
     102            catch (Exception e) {
     103                parent.status.append("ACTIVATE notice failed\n");
     104            }
     105        }
     106    }
     107
     108    public void deactivate() {
     109        if (socket != null) {
     110            try {
     111                ostream.println("DEACTIVATE RAPPTURE");
     112            }
     113            catch (Exception e) {
     114                parent.status.append("DEACTIVATE notice failed\n");
     115            }
     116        }
     117    }
     118
     119    public boolean connect() {
     120        try {
     121            socket = new Socket(hostName, hostPort);
     122            istream = new BufferedReader(
     123                new InputStreamReader(socket.getInputStream())
     124            );
     125            ostream = new PrintStream(socket.getOutputStream());
     126        }
     127        catch (UnknownHostException e) {
     128            parent.status.append("Can't connect: Unknown host "+hostName+"\n");
     129            socket = null;
     130            return false;
     131        }
     132        catch (Exception e) {
     133            socket = null;
     134            return false;
     135        }
     136
     137        try {
     138            ostream.println("REGISTER "+user+" "+ipAddr+" "+cookie+" RAPPTURE");
     139            ostream.println("ACTIVATE RAPPTURE");
     140            parent.status.append("Connected\n");
     141        }
     142        catch (Exception e) {
     143            parent.status.append("\nCan't talk to server");
     144        }
     145        return true;
     146    }
     147
     148    public void handle(String line) {
     149        parent.status.append("read "+line+"\n");
     150
     151        if (line.startsWith("url ")) {
     152            try {
     153                URL url = new URL("http",
     154                    hostName, hostPort, line.substring(4));
     155
     156                try {
     157                    parent.getAppletContext().showDocument(url,"_blank");
     158                    parent.status.append("launched "+url+"\n");
     159                }
     160                catch (Exception e) {
     161                    parent.status.append("Bad URL "+url+"\n");
     162                }
     163            }
     164            catch (Exception e) {
     165                parent.status.append("Malformed URL "+line.substring(4)+"\n");
     166            }
     167        } else {
     168            parent.status.append("huh? |"+line+"|\n");
     169        }
     170    }
    62171}
  • trunk/gui/init.tcl.in

    r158 r171  
    1414proc RapptureGUI_init {} {
    1515    global auto_path
    16     global rappture_library
    1716
    1817    package require BLT
    1918
    2019    set dir [file dirname [info script]]
    21    
    22     set rappture_library [file join $dir scripts]
    23     lappend auto_path $rappture_library
     20    lappend auto_path [file join $dir scripts]
    2421
    2522    set suffix [info sharedlibextension]
     
    2724    load $library RapptureGUI
    2825
    29     namespace eval Rappture {
     26    namespace eval RapptureGUI "
    3027        variable version @EXACT_VERSION@
    3128        variable patchlevel @PATCHLEVEL@
    32     }
     29        variable library $dir
     30    "
    3331
    3432    package provide RapptureGUI @VERSION@
  • trunk/gui/scripts/analyzer.tcl

    r170 r171  
    186186    pack $w.top.l -side left
    187187
     188    if {[Rappture::filexfer::enabled]} {
     189        itk_component add download {
     190            button $w.top.dl -text "Download..." \
     191                -command [itcl::code $this download]
     192        }
     193        pack $itk_component(download) -side right -padx {4 0}
     194        Rappture::Tooltip::for $itk_component(download) "Downloads the current result to a new web browser window on your desktop.  From there, you can easily print or save results.
     195
     196NOTE:  Your web browser must allow pop-ups from this site.  If your output does not appear, look for a 'pop-up blocked' message and enable pop-ups."
     197    }
     198
    188199    itk_component add resultselector {
    189200        Rappture::Combobox $w.top.sel -width 50 -editable no
     
    194205    pack $itk_component(resultselector) -side left -expand yes -fill x
    195206    bind $itk_component(resultselector) <<Value>> [itcl::code $this _fixResult]
    196 
    197     if {[Rappture::filexfer::enabled]} {
    198         itk_component add download {
    199             button $w.top.dl -text "Download..." \
    200                 -command [itcl::code $this download]
    201         }
    202         pack $itk_component(download) -side right -padx {4 0}
    203         Rappture::Tooltip::for $itk_component(download) "Downloads the current result to a new web browser window on your desktop.  From there, you can easily print or save results."
    204     }
    205207
    206208    itk_component add results {
  • trunk/gui/scripts/filexfer.tcl

    r115 r171  
    185185        close $fid
    186186
    187         set cid [lindex $clients(order) 0]
    188         if {$cid == ""} {
     187        set sent 0
     188        set access($filename) [bakeCookie]
     189        foreach cid $clients(order) {
     190            if {[info exists clients($cid)] && $clients($cid)} {
     191                catch {
     192                    puts $cid [format "url /spool/%s/%s?access=%s" \
     193                        $env(SESSION) $filename $access($filename)]
     194                }
     195                set sent 1
     196            }
     197        }
     198        if {!$sent} {
    189199            error "no clients"
    190200        }
    191 
    192         set access($filename) [bakeCookie]
    193         puts $cid "url /spool/$env(SESSION)/$filename?access=$access($filename)"
    194201    }
    195202}
     
    439446        #
    440447        set url [string trimleft $url /]
    441         set file [file join $Rappture::installdir filexfer $url]
     448        set file [file join $RapptureGUI::library filexfer $url]
    442449        response $cid file -path $file -connection $headers(Connection)
    443450    } else {
  • trunk/gui/scripts/postern.tcl

    r115 r171  
    132132
    133133    eval itk_initialize $args
     134
     135    # this makes it easier to find the magic spot
     136    bind $itk_component(hull) <Alt-Enter> [list $itk_component(hull) configure -background $itk_option(-activecolor)]
     137    bind $itk_component(hull) <Leave> [list $itk_component(hull) configure -background $itk_option(-background)]
    134138}
    135139
  • trunk/tcl/install.tcl

    r161 r171  
    5959foreach file {
    6060    ./scripts/library.tcl
    61     ../gui/scripts/exec.tcl
     61    ./scripts/exec.tcl
     62    ./scripts/result.tcl
    6263    ../gui/scripts/units.tcl
    63     ../gui/scripts/result.tcl
    6464} {
    6565    set target [file join $targetdir scripts [file tail $file]]
Note: See TracChangeset for help on using the changeset viewer.