1 # player.tcl --
2 #
3 # Record and playback urls for tracing purposes. Based on the
4 # mb TCL_Recorder / TCL_Player objects.
5 #
6 # Copyright (c) 1998-2002 The Regents of the University of California.
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are met:
11 #
12 # A. Redistributions of source code must retain the above copyright notice,
13 # this list of conditions and the following disclaimer.
14 # B. Redistributions in binary form must reproduce the above copyright notice,
15 # this list of conditions and the following disclaimer in the documentation
16 # and/or other materials provided with the distribution.
17 # C. Neither the names of the copyright holders nor the names of its
18 # contributors may be used to endorse or promote products derived from this
19 # software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
25 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #
32 # $Header: /usr/mash/src/repository/mash/mash-1/tcl/cache/player.tcl,v 1.4 2002/02/03 04:25:37 lim Exp $
33
34
35 Class WC_Recorder
36
37 WC_Recorder instproc init { logfname } {
38 $self instvar logf_ st_
39
40 set st_ [gettimeofday]
41 set logf_ [open $logfname "w+"]
42 }
43
44 WC_Recorder public record { url } {
45 $self instvar st_ logf_
46
47 puts $logf_ "[expr [gettimeofday] - $st_] $url"
48 flush $logf_
49 }
50
51 Class WC_Player
52
53 WC_Player instproc init { logfname target rt } {
54 $self instvar logf_ tgt_ isRealTime_
55 set logf_ [open $logfname "r+"]
56 set tgt_ $target
57 set isRealTime_ $rt
58 }
59
60 WC_Player instproc start {} {
61 $self instvar st_ now_ nextCmd_ nextURL_
62 set now_ 0
63 set nextURL_ ""
64 $self run_next
65 }
66
67 WC_Player instproc run_next { } {
68 $self instvar logf_ tgt_ nextURL_ now_ isRealTime_
69
70 # get the current URL
71 if { $nextURL_ != "" } {
72 $tgt_ get $nextURL_
73 }
74
75 # find the next URL to play
76 set u [gets $logf_ line]
77 if { $u == -1 } {
78 close $logf_
79 delete $self
80 return
81 }
82 set nextURL_ [lindex $line 1]
83
84 # schedule the next call to $tgt get
85 if $isRealTime_ {
86 set currTime $now_
87 set nexttime [expr int ([lindex $line 0] * 1000)]
88 set now_ $nexttime
89 after [expr $nexttime - $currTime] "$self run_next"
90 } else {
91 after idle "$self run_next"
92 }
93 }
94
95
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.