GNU Radio 3.6.5 C++ API
|
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 3, 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., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef _GR_CIRCULAR_FILE_H_ 00024 #define _GR_CIRCULAR_FILE_H_ 00025 00026 #include <gr_core_api.h> 00027 00028 /* 00029 * writes input data into a circular buffer on disk. 00030 * 00031 * the file contains a fixed header: 00032 * 0x0000: int32 magic (0xEB021026) 00033 * 0x0004: int32 size in bytes of header (constant 4096) 00034 * 0x0008: int32 size in bytes of circular buffer (not including header) 00035 * 0x000C: int32 file offset to beginning of circular buffer 00036 * 0x0010: int32 byte offset from beginning of circular buffer to 00037 * current start of data 00038 * 00039 */ 00040 class GR_CORE_API gr_circular_file { 00041 int d_fd; 00042 int *d_header; 00043 unsigned char *d_buffer; 00044 int d_mapped_size; 00045 int d_bytes_read; 00046 00047 public: 00048 gr_circular_file (const char *filename, bool writable = false, int size = 0); 00049 ~gr_circular_file (); 00050 00051 bool write (void *data, int nbytes); 00052 00053 // returns # of bytes actually read or 0 if end of buffer, or -1 on error. 00054 int read (void *data, int nbytes); 00055 00056 // reset read pointer to beginning of buffer. 00057 void reset_read_pointer (); 00058 }; 00059 00060 #endif /* _GR_CIRCULAR_FILE_H_ */