~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/archive/recorder/archive-record.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # archive-record.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1997-2002 The Regents of the University of California.
  6 # All rights reserved.
  7 #
  8 # Redistribution and use in source and binary forms, with or without
  9 # modification, are permitted provided that the following conditions are met:
 10 #
 11 # A. Redistributions of source code must retain the above copyright notice,
 12 #    this list of conditions and the following disclaimer.
 13 # B. Redistributions in binary form must reproduce the above copyright notice,
 14 #    this list of conditions and the following disclaimer in the documentation
 15 #    and/or other materials provided with the distribution.
 16 # C. Neither the names of the copyright holders nor the names of its
 17 #    contributors may be used to endorse or promote products derived from this
 18 #    software without specific prior written permission.
 19 #
 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30 #
 31 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/archive/recorder/archive-record.tcl,v 1.17 2002/02/03 04:25:13 lim Exp $
 32 
 33 
 34 import Observable
 35 
 36 # The ArchiveSession/Record class provides a shell for implementing session
 37 # classes for RTP and SRM recorder session classes.
 38 #
 39 # Note: This is an abstract base class. Do not create objects directly of
 40 # this class
 41 #
 42 # Any observer that is attached to objects of this class should define
 43 # methods corresponding to the following observable events:
 44 # new_stream:
 45 #      $session notify_observers new_stream <stream>
 46 # Invoked when the recording session detects a new source and creates a
 47 # new stream object for it. stream must be an object of a class that is
 48 # subclassed from ArchiveStream.
 49 # stream_done:
 50 #      $session notify_observers stream_done <stream>
 51 # Invoked when the recording session detects an existing source has
 52 # vanished. stream must be an object of a class that is subclassed from
 53 # ArchiveStream.
 54 # Status: Beta
 55 # Author: Yatin Chawathe and Angela Schuett
 56 
 57 Class ArchiveSession/Record -superclass Observable
 58 set classes [ArchiveStream info superclass]
 59 set objectIdx [lsearch $classes Observable]
 60 if { $objectIdx == -1 } {
 61         ArchiveStream superclass [concat Observable $classes]
 62 }
 63 
 64 ArchiveSession/Record instproc init { media } {
 65         $self next
 66         $self set stream_count_ 0
 67         $self media $media
 68 }
 69 
 70 ArchiveStream/Record public destroy {} {
 71         $self next
 72         # close and delete the data and index files from C, so that the end
 73         # timestamps can be written properly
 74 
 75 }
 76 
 77 ArchiveSession/Record instproc catalog { args } {
 78         $self instvar catalog_
 79         if { [llength $args]==0 } {
 80                 if [info exists catalog_] {
 81                         return $catalog_
 82                 } else {
 83                         return ""
 84                 }
 85         } else {
 86                 set catalog_ [lindex $args 0]
 87         }
 88 }
 89 
 90 # 1.  set directory [$session save_in] returns the name of the directory
 91 # in which stream data and index files are stored, if the directory has
 92 # previously been set, otherwise it returns an empty string.
 93 # 2. $session save_in $directory sets the directory name in which the
 94 # stream data and index files for this
 95 
 96 ArchiveSession/Record instproc save_in { args } {
 97         switch -exact -- [llength $args] {
 98                 0 {
 99                         if [info exists directory_] {
100                                 return $directory_
101                         } else {
102                                 return ""
103                         }
104                 }
105                 1 {
106                         $self set directory_ [lindex $args 0]
107                         return
108                 }
109                 default {
110                         error "too many arguments"
111                 }
112         }
113 }
114 
115 # 1.  set session_id [$session session_id] returns the session-id string
116 # if it has previously been set, otherwise it returns an empty string.
117 # 2.  $session session_id $session_id set the session-id associated with
118 # this session. session_id is simply a string that contains valid
119 # filename characters (directory separator characters are not
120 # permitted). The session-id is used as a prefix for data and index
121 # filenames.
122 
123 ArchiveSession/Record instproc session_id { args } {
124         switch -exact -- [llength $args] {
125                 0 {
126                         if [info exists session_id_] {
127                                 return $session_id_
128                         } else {
129                                 return ""
130                         }
131                 }
132                 1 {
133                         $self set session_id_ [lindex $args 0]
134                         return
135                 }
136                 default {
137                         error "too many arguments"
138                 }
139         }
140 }
141 
142 #   1.  set m [$session media] returns a string that represents the media
143 # associated with this session.
144 #  2.  $session media $m
145 #
146 # Set or query the media associated with this session. Please note that
147 # the media is automatically set by the init method of this class.
148 # Programmers should not invoke this method directly to set the media.
149 
150 ArchiveSession/Record instproc media { args } {
151         $self instvar media_
152         switch -exact -- [llength $args] {
153                 0 {
154                         if [info exists media_] {
155                                 return $media_
156                         } else {
157                                 return ""
158                         }
159                 }
160                 1 {
161                         $self set media_ [lindex $args 0]
162                         $class instvar media_count_
163                         if { ![info exists media_count_($media_)] } {
164                                 set media_count_($media_) 0
165                         }
166                         incr media_count_($media_)
167                         $self set media_count_ $media_count_($media_)
168                         return
169                 }
170                 default {
171                         error "too many arguments"
172                 }
173         }
174 }
175 
176 
177 # Return a filename that is guaranteed to be unique across all streams
178 # and all sessions that are part of this recorder process. The filename
179 # does not contain the ".dat" or ".idx" extension. The filename has the
180 # following format: dir/session_id-mediamedia_count-count
181 # where dir is the value returned by the save_in method, session_id is
182 # the value returned by the session_id method (if the session_id field
183 # is empty, that part of the filename, including the following hyphen,
184 # is eliminated), media is the value returned by the media method,
185 # media_count is a media-specific counter, so that two sessions with the
186 # same media will not collide on their filenames, and count is a
187 # session-specific counter, so different streams within a session have
188 # different filenames.
189 
190 ArchiveSession/Record instproc generate_filename { } {
191         $self instvar directory_ session_id_ media_ media_count_ stream_count_
192         set name ""
193         if { $session_id_!="" } {
194                 append name "${session_id_}-"
195         }
196         incr stream_count_
197         append name "${media_}${media_count_}-${stream_count_}"
198         return [file join $directory_ $name]
199 }
200 
201 ArchiveStream/Record instproc bind { session } {
202         $self set archive_session_ $session
203         if { [catch {
204                 set filename [$session generate_filename]
205                 set dataFile  [new ArchiveFile/Data]
206                 $dataFile open "${filename}.dat" "w"
207 
208                 set indexFile [new ArchiveFile/Index]
209                 $indexFile open "${filename}.idx" "w"
210                 $self write_to_catalog $session $filename
211                 $session notify_observers new_stream $self
212                 $self notify_observers filename "${filename}.dat \[.idx\]"
213                 $self datafile  $dataFile
214                 $self indexfile $indexFile
215         } error] } {
216                 return $error
217         }
218         return ""
219 }
220 
221 ArchiveStream/Record instproc write_to_catalog { session filename } {
222         set catalog [$session catalog]
223         if { $catalog=="" } return
224 
225         set dirname    [file dirname $filename]
226         set catalogdir [file dirname [$catalog filename]]
227         if { [string first $catalogdir $dirname]==0 } {
228                 # the save_in directory is a child of the catalog directory!
229                 # Let's use relative paths
230 
231                 set dirname [file split $dirname]
232                 set ignore [llength [file split $catalogdir]]
233 
234                 set dirname [lrange $dirname $ignore end]
235                 if { [llength $dirname]==0 } {
236                         set filename [file tail $filename]
237                 } else {
238                         set filename [eval file join $dirname \
239                                         [list [file tail $filename]]]
240                 }
241         }
242         $session instvar media_ media_count_
243         $catalog write_stream $self "$media_$media_count_" \
244                         "${filename}.dat" "${filename}.idx"
245 }
246 
247 
248 ArchiveStream/Record instproc session { } {
249         return [$self set archive_session_]
250 }
251 
252 
253 ArchiveStream/Record instproc media { } {
254         return [[$self set archive_session_] media]
255 }
256 
257 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.