Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

gr_circular_file.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2002 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  */
00022 
00023 #ifndef _GR_CIRCULAR_FILE_H_
00024 #define _GR_CIRCULAR_FILE_H_
00025 
00026 /*
00027  * writes input data into a circular buffer on disk.
00028  *
00029  * the file contains a fixed header:
00030  *   0x0000:    int32 magic (0xEB021026)
00031  *   0x0004:    int32 size in bytes of header (constant 4096)
00032  *   0x0008:    int32 size in bytes of circular buffer (not including header)
00033  *   0x000C:    int32 file offset to beginning of circular buffer
00034  *   0x0010:    int32 byte offset from beginning of circular buffer to 
00035  *                    current start of data
00036  *
00037  */
00038 class gr_circular_file {
00039   int            d_fd;
00040   int           *d_header;
00041   unsigned char *d_buffer;
00042   int            d_mapped_size;
00043   int            d_bytes_read;
00044 
00045 public:
00046   gr_circular_file (const char *filename, bool writable = false, int size = 0);
00047   ~gr_circular_file ();
00048 
00049   bool write (void *data, int nbytes);
00050 
00051   // returns # of bytes actually read or 0 if end of buffer, or -1 on error.
00052   int read (void *data, int nbytes);
00053 
00054   // reset read pointer to beginning of buffer.
00055   void reset_read_pointer ();
00056 };
00057 
00058 #endif /* _GR_CIRCULAR_FILE_H_ */

Generated on Sat Jul 8 17:04:51 2006 for GNU Radio 2.x by  doxygen 1.4.1