GNU Radio 3.6.4 C++ API
file_meta_source_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_SOURCE_IMPL_H
24 #define INCLUDED_BLOCKS_FILE_META_SOURCE_IMPL_H
25 
27 #include <gr_tags.h>
28 #include <gruel/pmt.h>
29 #include <gruel/thread.h>
30 
31 #include <blocks/file_meta_sink.h>
32 
33 using namespace pmt;
34 
35 namespace gr {
36  namespace blocks {
37 
39  {
40  private:
41  enum meta_state_t {
42  STATE_INLINE=0,
43  STATE_DETACHED
44  };
45 
46  size_t d_itemsize;
47  double d_samp_rate;
48  pmt_t d_time_stamp;
49  size_t d_seg_size;
50  bool d_updated;
51  bool d_repeat;
52 
53  gruel::mutex d_mutex;
54  FILE *d_new_fp, *d_new_hdr_fp;
55  FILE *d_fp, *d_hdr_fp;
56  meta_state_t d_state;
57 
58  std::vector<gr_tag_t> d_tags;
59 
60  protected:
61  bool _open(FILE **fp, const char *filename);
62  bool read_header(pmt_t &hdr, pmt_t &extras);
63  void parse_header(pmt_t hdr, uint64_t offset,
64  std::vector<gr_tag_t> &tags);
65  void parse_extras(pmt_t extras, uint64_t offset,
66  std::vector<gr_tag_t> &tags);
67 
68  public:
69  file_meta_source_impl(const std::string &filename,
70  bool repeat=false,
71  bool detached_header=false,
72  const std::string &hdr_filename="");
73 
75 
76  bool open(const std::string &filename,
77  const std::string &hdr_filename="");
78  void close();
79  void do_update();
80 
81  int work(int noutput_items,
82  gr_vector_const_void_star &input_items,
83  gr_vector_void_star &output_items);
84  };
85 
86  } /* namespace blocks */
87 } /* namespace gr */
88 
89 #endif /* INCLUDED_BLOCKS_FILE_META_SOURCE_IMPL_H */