OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [gdbtk/] [library/] [download.itb] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Download class implementation for GDBtk.
2
# Copyright 1999 Cygnus Solutions
3
#
4
# This program is free software; you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License (GPL) as published by
6
# the Free Software Foundation; either version 2 of the License, or (at
7
# your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
 
14
 
15
# ----------------------------------------------------------------------
16
# Download window and associated procs
17
#
18
# ----------------------------------------------------------------------
19
 
20
body Download::constructor {args} {
21
  global gdb_pretty_name
22
  debug $args
23
  eval itk_initialize $args
24
  window_name "Download Status" "Download"
25
  add_hook download_progress_hook "$this update_download"
26
 
27
  label $itk_interior.dload -text "Downloading $filename to $gdb_pretty_name"
28
 
29
  label $itk_interior.stat
30
  set f [frame $itk_interior.f]
31
 
32
  set i 0
33
  while {$i <$num_sections} {
34
    tixMeter $f.meter$i -value 0 -text 0
35
    label $f.sec$i -text [lindex $section(names) $i] -anchor w
36
    label $f.num$i -text $bytes($i) -anchor e
37
    grid $f.sec$i $f.meter$i $f.num$i -padx 4 -pady 4 -sticky news
38
    incr i
39
  }
40
 
41
  grid $itk_interior.dload -padx 5 -pady 5
42
  grid $itk_interior.stat -padx 5 -pady 5
43
  grid $itk_interior.f -padx 5 -pady 5
44
 
45
  button $itk_interior.cancel -text Cancel -command "$this cancel" \
46
    -state active -width 10
47
  grid $itk_interior.cancel -padx 5 -pady 5
48
#  grid  $itk_interior
49
 
50
}
51
 
52
# ------------------------------------------------------------------
53
#  METHOD:  update_download - update the download meters
54
# ------------------------------------------------------------------
55
body Download::update_download { sec num tot } {
56
 
57
  # Loop through all the sections, marking each as either done or
58
  # updating its meter. This will mark all previous sections prior to
59
  # SEC as complete.
60
  foreach s $section(names) {
61
    set i $section($s)
62
 
63
    if {$s == $sec} {
64
      $itk_interior.f.meter$i config -value [expr {$num / $bytes($i)}] -text $num
65
      break
66
    } else {
67
      if {[expr {double([$itk_interior.f.meter$i cget -value])}] != 1.0} {
68
        $itk_interior.f.meter$i config -value 1.0 -text [expr {int($bytes($i))}]
69
      }
70
    }
71
  }
72
  ::update
73
}
74
 
75
# ------------------------------------------------------------------
76
#  METHOD:  done - notification that the download is really complete
77
# ------------------------------------------------------------------
78
body Download::done { {msg ""} } {
79
  bell
80
 
81
  if {$msg == ""} {
82
    # download finished
83
    set secs [expr {[clock seconds] - $::download_start_time}]
84
    if {$secs == 0} { incr secs }
85
    $itk_interior.cancel config -state disabled
86
    set bps [expr {8 * $total_bytes / $secs / 1000}]
87
    $itk_interior.stat config -text "$total_bytes bytes in $secs seconds ($bps kbps)"
88
 
89
    # set all indicators to FULL
90
    foreach sec $section(names) {
91
      set i $section($sec)
92
      $itk_interior.f.meter$i config -value 1.0 -text "DONE"
93
    }
94
  } else {
95
    # download failed
96
    if {$msg != "CANCEL"} {
97
      $itk_interior.stat config -text $msg
98
    }
99
  }
100
 
101
  # enable OK button
102
  $itk_interior.cancel config -state active -text OK -command "delete object $this"
103
  ::update
104
}
105
 
106
# ------------------------------------------------------------------
107
#  METHOD:  cancel - cancel the download
108
# ------------------------------------------------------------------
109
body Download::cancel {} {
110
  debug "canceling the download"
111
  set ::download_cancel_ok 1
112
}
113
 
114
# ------------------------------------------------------------------
115
#  DESTRUCTOR - destroy window containing widget
116
# ------------------------------------------------------------------
117
body Download::destructor {} {
118
  remove_hook download_progress_hook "$this update_download"
119
}
120
 
121
body Download::do_download_hooks {} {
122
  set ::download_timer(ok) 1
123
}
124
 
125
body Download::download_hash { section num } {
126
  global download_timer
127
  debug "sec=$section num=$num tot=$total_bytes ok=$::download_cancel_ok"
128
  ::update
129
  # Only run the timer at discrete times...
130
  if {[info exists download_timer(timer)]} {
131
    after cancel $download_timer(timer)
132
  }
133
 
134
  set download_timer(timer) [after 333 Download::do_download_hooks]
135
  if {![info exists download_timer(ok)] || $download_timer(ok)} {
136
    run_hooks download_progress_hook $section $num $total_bytes
137
    ::update
138
    unset download_timer(timer)
139
    set download_timer(ok) 0
140
  }
141
 
142
  return $::download_cancel_ok
143
}
144
 
145
# Download the executable. Return zero for success, and non-zero for error.
146
body Download::download_it { } {
147
  global gdb_exe_name gdb_downloading gdb_loaded
148
  global gdb_target_name gdb_pretty_name
149
  global gdb_running
150
  global tcl_platform
151
 
152
  debug "exe=$gdb_exe_name downloading=$gdb_downloading"
153
  debug "    loaded=$gdb_loaded target=$gdb_target_name running=$gdb_running"
154
 
155
  if {$gdb_downloading || $gdb_exe_name == ""} {
156
    return 0
157
  }
158
 
159
  set gdb_downloading 1
160
  set gdb_loaded 0
161
  # Make sure the source window has had time to be created
162
  ::update
163
 
164
  gdbtk_busy
165
 
166
  # Only places that load files should do set_exe
167
  #set_exe
168
  switch [set_target] {
169
    ERROR {
170
      # target command failed
171
      set gdb_downloading 0
172
      gdbtk_idle
173
      return 0
174
    }
175
    CANCELED {
176
      # command cancelled by user
177
      set gdb_downloading 0
178
      if {$gdb_running} {
179
        # Run the idle hooks (free the UI)
180
        gdbtk_update
181
        gdbtk_idle
182
      } else {
183
        gdbtk_idle
184
      }
185
      return 1
186
    }
187
  }
188
 
189
  if {[string compare $tcl_platform(platform) "windows"] == 0} {
190
    set f [ide_cygwin_path to_win32 $gdb_exe_name]
191
  } else {
192
    set f $gdb_exe_name
193
  }
194
  if {! [file exists $f]} {
195
    tk_messageBox -icon error -title GDB -type ok -modal task\
196
      -message "Request to download non-existent executable $gdb_exe_name"
197
    set gdb_downloading 0
198
    gdbtk_idle
199
    return 0
200
  }
201
 
202
  debug "downloading $gdb_exe_name"
203
 
204
  set target $gdb_target_name
205
 
206
  # get load info and total up number of bytes
207
  if {[catch {gdb_load_info $gdb_exe_name} val]} {
208
    set result "$gdb_exe_name: $val"
209
    tk_dialog .load_warn "" "$result"  error 0 Ok
210
    return 0
211
  }
212
  set i 0
213
  set total_bytes 0
214
  set section(names) {}
215
  foreach x $val {
216
    set s [lindex $x 0]
217
    lappend section(names) $s
218
    set section($s) $i
219
    set b [lindex $x 1]
220
    set bytes($i) [expr {double($b)}]
221
    incr total_bytes $b
222
    incr i
223
  }
224
  set num_sections $i
225
 
226
  set ::download_cancel_ok 0
227
  set ::download_start_time [clock seconds]
228
 
229
 
230
  if {[pref getd gdb/load/$target-verbose] == "1"} {
231
    # open a detailed download dialog window
232
    set download_dialog [ManagedWin::open Download -transient -filename $gdb_exe_name]
233
  } else {
234
    # raise source windows
235
    foreach src [ManagedWin::find SrcWin] {
236
      $src reveal
237
      $src toolbar downloading
238
    }
239
    set download_dialog ""
240
  }
241
 
242
  set download_error ""
243
  debug "starting load"
244
  ::update idletasks
245
  if {[catch {gdb_cmd "load $gdb_exe_name"} errTxt]} {
246
    debug "load returned $errTxt"
247
    if {[regexp -nocase cancel $errTxt]} {
248
      set download_error "CANCEL"
249
    } else {
250
      set download_error $errTxt
251
    }
252
    set ::download_cancel_ok 1
253
  }
254
 
255
  debug "Done loading"
256
 
257
  set gdb_downloading 0
258
  if {$::download_cancel_ok} {
259
    set gdb_loaded 0
260
    if {$download_dialog != ""} {
261
      catch {$download_dialog done $download_error}
262
    }
263
  } else {
264
    set gdb_loaded 1
265
    if {$download_dialog != ""} {
266
      catch {$download_dialog done}
267
    }
268
  }
269
 
270
  foreach src [ManagedWin::find SrcWin] {
271
    if {$download_error == "CANCEL"} {
272
      $src download_progress CANCEL 1 1
273
    } else {
274
      $src download_progress DONE 0 $total_bytes $download_error
275
    }
276
  }
277
 
278
  set ::download_cancel_ok 0
279
  set download_dialog ""
280
 
281
  gdbtk_idle
282
  return 0
283
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.