GNU Radio 3.6.4.1 C++ API
file_meta_sink_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_BLOCKS_FILE_META_SINK_IMPL_H
24 #define INCLUDED_BLOCKS_FILE_META_SINK_IMPL_H
25 
26 #include <blocks/file_meta_sink.h>
27 #include <gruel/pmt.h>
28 #include <gruel/thread.h>
29 
30 using namespace pmt;
31 
32 namespace gr {
33  namespace blocks {
34 
36  {
37  private:
38  enum meta_state_t {
39  STATE_INLINE=0,
40  STATE_DETACHED
41  };
42 
43  size_t d_itemsize;
44  double d_samp_rate;
45  double d_relative_rate;
46  size_t d_max_seg_size;
47  size_t d_total_seg_size;
48  pmt_t d_header;
49  pmt_t d_extra;
50  size_t d_extra_size;
51  bool d_updated;
52  bool d_unbuffered;
53 
54  boost::mutex d_mutex;
55  FILE *d_new_fp, *d_new_hdr_fp;
56  FILE *d_fp, *d_hdr_fp;
57  meta_state_t d_state;
58 
59  protected:
60  void write_header(FILE *fp, pmt_t header, pmt_t extra);
61  void update_header(pmt_t key, pmt_t value);
62  void update_last_header();
63  void update_last_header_inline();
64  void update_last_header_detached();
65  void write_and_update();
66  void update_rx_time();
67 
68  bool _open(FILE **fp, const char *filename);
69 
70  public:
71  file_meta_sink_impl(size_t itemsize, const std::string &filename,
72  double samp_rate=1, double relative_rate=1,
73  gr_file_types type=GR_FILE_FLOAT, bool complex=true,
74  size_t max_segment_size=1000000,
75  const std::string &extra_dict="",
76  bool detached_header=false);
78 
79  bool open(const std::string &filename);
80  void close();
81  void do_update();
82 
83  void set_unbuffered(bool unbuffered)
84  {
85  d_unbuffered = unbuffered;
86  }
87 
88  int work(int noutput_items,
89  gr_vector_const_void_star &input_items,
90  gr_vector_void_star &output_items);
91  };
92 
93  } /* namespace blocks */
94 } /* namespace gr */
95 
96 #endif /* INCLUDED_BLOCKS_FILE_META_SINK_IMPL_H */