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

Open Mash Cross Reference
mash/archive/archive-file.h

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

  1 /*
  2  * archive-file.h --
  3  *
  4  *      Archive file type header
  5  *
  6  * Copyright (c) 1997-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
 22  * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  * @(#) $Header: /usr/mash/src/repository/mash/mash-1/archive/archive-file.h,v 1.14 2002/02/03 03:09:26 lim Exp $
 34  */
 35 
 36 #ifndef MASH_ARCHIVE_FILE_H
 37 #define MASH_ARCHIVE_FILE_H
 38 
 39 #include <tclcl.h>
 40 #include "misc/all-types.h"
 41 
 42 
 43 #define DATA_VERSION  "MDAT1.0"
 44 #define INDEX_VERSION "MIDX1.0"
 45 
 46 #define PROTO_SRM "SRM"
 47 #define PROTO_RTP "RTP"
 48 
 49 
 50 struct FileHeader {
 51         char version[16];       // DATA_VERSION & INDEX_VERSION
 52         char protocol[8];       // "RTP" or "SRM"
 53         char media[32];         // the media: "audio", "video", "mediaboard"...
 54         char cname[128];        // username@host.domain
 55         char name[128];         // the user's name
 56 
 57   // all of the following values are stored in network form, so require a
 58   //   ntohl() call when reading from the file
 59   // why???
 60         u_int32_t start_sec;    // start timestamp
 61         u_int32_t start_usec;
 62         u_int32_t end_sec;      // end timestamp
 63         u_int32_t end_usec;
 64 
 65         u_int32_t privateLen;   // length of any following private header
 66 };
 67 
 68 
 69 struct IndexRecord {
 70         u_int32_t sentTS_sec; // sender timestamp: depends on the media stream
 71         u_int32_t sentTS_usec;
 72         u_int32_t recvTS_sec; // timestamp when the packet was rcvd by the
 73         u_int32_t recvTS_usec;// recorder
 74         u_int32_t seqno;      // packet sequence number
 75         u_int32_t filePointer;// location of packet in the data file
 76 };
 77 
 78 
 79 void net2host(const FileHeader &hdrNet,  FileHeader &hdrHost);
 80 void host2net(const FileHeader &hdrHost, FileHeader &hdrNet);
 81 
 82 void net2host(const IndexRecord &idxNet,  IndexRecord &idxHost);
 83 void host2net(const IndexRecord &idxHost, IndexRecord &idxNet);
 84 
 85 
 86 class ArchiveFile : public TclObject {
 87 public:
 88         ArchiveFile() : channel_(NULL), headerSize_(0) { };
 89         ~ArchiveFile() {  Close(); }
 90         void Close() {
 91                 if (channel_!=NULL)
 92                         Tcl_Close(Tcl::instance().interp(), channel_);
 93                 channel_ = NULL;
 94                 headerSize_ = 0;
 95 
 96         }
 97 
 98         Bool IsOpen() { return ((channel_==NULL) ? FALSE : TRUE); }
 99         Bool Eof() { return ((Tcl_Eof(channel_)==0) ? FALSE : TRUE); }
100 
101         int Write(const FileHeader *hdr, const Byte *privateHdr=NULL);
102         int Read(FileHeader *hdr, Byte *privateHdr=NULL,
103                  u_int32_t privateLen=0);
104 
105         int Write(const Byte *buf, int toWrite) {
106                 return Tcl_Write(channel_, (char*) buf, toWrite);
107         }
108 
109         int Read(Byte *buf, int toRead) {
110                 return Tcl_Read(channel_, (char*) buf, toRead);
111         }
112 
113         int Seek(int offset, int seekMode) {
114                 return Tcl_Seek(channel_, offset, seekMode);
115         }
116 
117         int Tell() {
118                 return Tcl_Tell(channel_);
119         }
120 
121         int getHeaderSize() {
122                 if (headerSize_ == 0) {
123                         // we haven't read the header yet! so read it first
124                         FileHeader tmp;
125                         if (Read(&tmp) < 0) return 0;
126                 }
127                 return headerSize_;
128         }
129 
130         int Open(const char *filename, const char *mode, int permissions);
131         int open(int argc, const char * const *argv);
132         int close(int argc, const char * const *argv);
133         int header(int argc, const char * const *argv);
134         int private_header(int argc, const char * const *argv);
135 
136         static int ts2string(int argc, const char * const *argv);
137         char* get_name() { return filename_;}
138 private:
139         Tcl_Channel channel_;
140         u_int32_t headerSize_;
141         char filename_[100];  // For easier debugging
142 };
143 
144 
145 class DataFile : public ArchiveFile {
146 public:
147 };
148 
149 
150 class IndexFile : public ArchiveFile {
151 public:
152         int Write(const IndexRecord *idx) {
153                 return ArchiveFile::Write((const Byte *)idx,
154                                           sizeof(IndexRecord));
155         }
156         int Read(IndexRecord *idx) {
157                 return ArchiveFile::Read((Byte *)idx, sizeof(IndexRecord));
158         }
159 };
160 
161 
162 #endif /* MASH_ARCHIVE_FILE_H */
163 

~ [ 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.