GNU Radio 3.6.5 C++ API

file_meta_sink_impl.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2012 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 INCLUDED_BLOCKS_FILE_META_SINK_IMPL_H
00024 #define INCLUDED_BLOCKS_FILE_META_SINK_IMPL_H
00025 
00026 #include <blocks/file_meta_sink.h>
00027 #include <gruel/pmt.h>
00028 #include <gruel/thread.h>
00029 
00030 using namespace pmt;
00031 
00032 namespace gr {
00033   namespace blocks {
00034 
00035     class file_meta_sink_impl : public file_meta_sink
00036     {
00037     private:
00038       enum meta_state_t {
00039         STATE_INLINE=0,
00040         STATE_DETACHED
00041       };
00042 
00043       size_t d_itemsize;
00044       double d_samp_rate;
00045       double d_relative_rate;
00046       size_t d_max_seg_size;
00047       size_t d_total_seg_size;
00048       pmt_t d_header;
00049       pmt_t d_extra;
00050       size_t d_extra_size;
00051       bool d_updated;
00052       bool d_unbuffered;
00053 
00054       boost::mutex d_mutex;
00055       FILE *d_new_fp, *d_new_hdr_fp;
00056       FILE *d_fp, *d_hdr_fp;
00057       meta_state_t d_state;
00058 
00059     protected:
00060       void write_header(FILE *fp, pmt_t header, pmt_t extra);
00061       void update_header(pmt_t key, pmt_t value);
00062       void update_last_header();
00063       void update_last_header_inline();
00064       void update_last_header_detached();
00065       void write_and_update();
00066       void update_rx_time();
00067 
00068       bool _open(FILE **fp, const char *filename);
00069 
00070     public:
00071       file_meta_sink_impl(size_t itemsize, const std::string &filename,
00072                           double samp_rate=1, double relative_rate=1,
00073                           gr_file_types type=GR_FILE_FLOAT, bool complex=true,
00074                           size_t max_segment_size=1000000,
00075                           const std::string &extra_dict="",
00076                           bool detached_header=false);
00077       ~file_meta_sink_impl();
00078 
00079       bool open(const std::string &filename);
00080       void close();
00081       void do_update();
00082 
00083       void set_unbuffered(bool unbuffered)
00084       {
00085         d_unbuffered = unbuffered;
00086       }
00087 
00088       int work(int noutput_items,
00089                gr_vector_const_void_star &input_items,
00090                gr_vector_void_star &output_items);
00091     };
00092 
00093   } /* namespace blocks */
00094 } /* namespace gr */
00095 
00096 #endif /* INCLUDED_BLOCKS_FILE_META_SINK_IMPL_H */