URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [trunk/] [insight/] [gdb/] [gdbtcl/] [download.itb] - Rev 1765
Compare with Previous | Blame | View Log
# Download class implementation for GDBtk.# Copyright 1999 Cygnus Solutions## This program is free software; you can redistribute it and/or modify it# under the terms of the GNU General Public License (GPL) as published by# the Free Software Foundation; either version 2 of the License, or (at# your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# ----------------------------------------------------------------------# Download window and associated procs## ----------------------------------------------------------------------body Download::constructor {args} {global gdb_pretty_namedebug $argseval itk_initialize $argswindow_name "Download Status" "Download"add_hook download_progress_hook "$this update_download"label $itk_interior.dload -text "Downloading $filename to $gdb_pretty_name"label $itk_interior.statset f [frame $itk_interior.f]set i 0while {$i <$num_sections} {tixMeter $f.meter$i -value 0 -text 0label $f.sec$i -text [lindex $section(names) $i] -anchor wlabel $f.num$i -text $bytes($i) -anchor egrid $f.sec$i $f.meter$i $f.num$i -padx 4 -pady 4 -sticky newsincr i}grid $itk_interior.dload -padx 5 -pady 5grid $itk_interior.stat -padx 5 -pady 5grid $itk_interior.f -padx 5 -pady 5button $itk_interior.cancel -text Cancel -command "$this cancel" \-state active -width 10grid $itk_interior.cancel -padx 5 -pady 5# grid $itk_interior}# ------------------------------------------------------------------# METHOD: update_download - update the download meters# ------------------------------------------------------------------body Download::update_download { sec num tot } {# Loop through all the sections, marking each as either done or# updating its meter. This will mark all previous sections prior to# SEC as complete.foreach s $section(names) {set i $section($s)if {$s == $sec} {$itk_interior.f.meter$i config -value [expr {$num / $bytes($i)}] -text $numbreak} else {if {[expr {double([$itk_interior.f.meter$i cget -value])}] != 1.0} {$itk_interior.f.meter$i config -value 1.0 -text [expr {int($bytes($i))}]}}}::update}# ------------------------------------------------------------------# METHOD: done - notification that the download is really complete# ------------------------------------------------------------------body Download::done { {msg ""} } {bellif {$msg == ""} {# download finishedset secs [expr {[clock seconds] - $::download_start_time}]if {$secs == 0} { incr secs }$itk_interior.cancel config -state disabledset bps [expr {8 * $total_bytes / $secs / 1000}]$itk_interior.stat config -text "$total_bytes bytes in $secs seconds ($bps kbps)"# set all indicators to FULLforeach sec $section(names) {set i $section($sec)$itk_interior.f.meter$i config -value 1.0 -text "DONE"}} else {# download failedif {$msg != "CANCEL"} {$itk_interior.stat config -text $msg}}# enable OK button$itk_interior.cancel config -state active -text OK -command "delete object $this"::update}# ------------------------------------------------------------------# METHOD: cancel - cancel the download# ------------------------------------------------------------------body Download::cancel {} {debug "canceling the download"set ::download_cancel_ok 1}# ------------------------------------------------------------------# DESTRUCTOR - destroy window containing widget# ------------------------------------------------------------------body Download::destructor {} {remove_hook download_progress_hook "$this update_download"}body Download::do_download_hooks {} {set ::download_timer(ok) 1}body Download::download_hash { section num } {global download_timerdebug "sec=$section num=$num tot=$total_bytes ok=$::download_cancel_ok"::update# Only run the timer at discrete times...if {[info exists download_timer(timer)]} {after cancel $download_timer(timer)}set download_timer(timer) [after 333 Download::do_download_hooks]if {![info exists download_timer(ok)] || $download_timer(ok)} {run_hooks download_progress_hook $section $num $total_bytes::updateunset download_timer(timer)set download_timer(ok) 0}return $::download_cancel_ok}# Download the executable. Return zero for success, and non-zero for error.body Download::download_it { } {global gdb_exe_name gdb_downloading gdb_loadedglobal gdb_target_name gdb_pretty_nameglobal gdb_runningglobal tcl_platformdebug "exe=$gdb_exe_name downloading=$gdb_downloading"debug " loaded=$gdb_loaded target=$gdb_target_name running=$gdb_running"if {$gdb_downloading || $gdb_exe_name == ""} {return 0}set gdb_downloading 1set gdb_loaded 0# Make sure the source window has had time to be created::updategdbtk_busy# Only places that load files should do set_exe#set_exeswitch [set_target] {ERROR {# target command failedset gdb_downloading 0gdbtk_idlereturn 0}CANCELED {# command cancelled by userset gdb_downloading 0if {$gdb_running} {# Run the idle hooks (free the UI)gdbtk_updategdbtk_idle} else {gdbtk_idle}return 1}}if {[string compare $tcl_platform(platform) "windows"] == 0} {set f [ide_cygwin_path to_win32 $gdb_exe_name]} else {set f $gdb_exe_name}if {! [file exists $f]} {tk_messageBox -icon error -title GDB -type ok -modal task\-message "Request to download non-existent executable $gdb_exe_name"set gdb_downloading 0gdbtk_idlereturn 0}debug "downloading $gdb_exe_name"set target $gdb_target_name# get load info and total up number of bytesif {[catch {gdb_load_info $gdb_exe_name} val]} {set result "$gdb_exe_name: $val"tk_dialog .load_warn "" "$result" error 0 Okreturn 0}set i 0set total_bytes 0set section(names) {}foreach x $val {set s [lindex $x 0]lappend section(names) $sset section($s) $iset b [lindex $x 1]set bytes($i) [expr {double($b)}]incr total_bytes $bincr i}set num_sections $iset ::download_cancel_ok 0set ::download_start_time [clock seconds]if {[pref getd gdb/load/$target-verbose] == "1"} {# open a detailed download dialog windowset download_dialog [ManagedWin::open Download -transient -filename $gdb_exe_name]} else {# raise source windowsforeach src [ManagedWin::find SrcWin] {$src reveal$src toolbar downloading}set download_dialog ""}set download_error ""debug "starting load"::update idletasksif {[catch {gdb_cmd "load $gdb_exe_name"} errTxt]} {debug "load returned $errTxt"if {[regexp -nocase cancel $errTxt]} {set download_error "CANCEL"} else {set download_error $errTxt}set ::download_cancel_ok 1}debug "Done loading"set gdb_downloading 0if {$::download_cancel_ok} {set gdb_loaded 0if {$download_dialog != ""} {catch {$download_dialog done $download_error}}} else {set gdb_loaded 1if {$download_dialog != ""} {catch {$download_dialog done}}}foreach src [ManagedWin::find SrcWin] {if {$download_error == "CANCEL"} {$src download_progress CANCEL 1 1} else {$src download_progress DONE 0 $total_bytes $download_error}}set ::download_cancel_ok 0set download_dialog ""gdbtk_idlereturn 0}
